I have successfully made an IAP write and read call to flash memory with a simple data type like char or int. Now I am trying to do the same with a structure that I have defined.
Currently, I simply initialize and set the variables within the structure, then I pass the address of the struct as the source address for the IAP call. Do I have to copy it into a specific RAM location first? I didn't have to do that when I simply wrote a string like "HELLO WORLD\n" to and from Flash. Here is my current code:
struct exercise{ char ex_name[30]; int pic_ID; // Picture reference ID int ex_info; // Exercise reference ID int goal_set; // Goal exercise variables int goal_weight; int goal_rep; int act_set; // Actual exercise variables int act_weight; int act_rep; }; struct day{ int numExercises; char name[15]; struct exercise* exercises[15]; }; struct workout{ int numDays; struct day* days[7]; };
All IAP calls return status code 0, and nothing is printed with the write command, meaning the information was not returned correctly.
// Set up a test workout in Flash void setUpTestWorkout() { struct exercise ex1, ex2, ex3; struct day day1; struct workout workout_send, workout_receive; char buffer[500], text[20]; unsigned int *source, *destination, i; unsigned int command_iap[5], result_iap[3]; unsigned long int enabled_interrupts; IAP iap_bypointer; // Set and initialize exercises strcpy(ex1.ex_name, "Bench Press"); ex1.pic_ID = PIC_CHEST; // Picture reference ID ex1.ex_info = EX_BENCHPRESS; // Exercise reference ID ex1.goal_set = 3; // Goal exercise variables ex1.goal_weight = 150; ex1.goal_rep = 10; ex1.act_set = 0; // Actual exercise variables ex1.act_weight = 0; ex1.act_rep = 0; strcpy(ex2.ex_name, "Closed Grip Press"); ex2.pic_ID = PIC_CHEST; // Picture reference ID ex2.ex_info = EX_BENCHPRESS; // Exercise reference ID ex2.goal_set = 3; // Goal exercise variables ex2.goal_weight = 100; ex2.goal_rep = 8; ex2.act_set = 0; // Actual exercise variables ex2.act_weight = 0; ex2.act_rep = 0; strcpy(ex3.ex_name, "Crunches"); ex3.pic_ID = PIC_CHEST; // Picture reference ID ex3.ex_info = EX_BENCHPRESS; // Exercise reference ID ex3.goal_set = 5; // Goal exercise variables ex3.goal_weight = 0; ex3.goal_rep = 20; ex3.act_set = 0; // Actual exercise variables ex3.act_weight = 0; ex3.act_rep = 0; // Set and initialize day day1.numExercises = 3; for(i=0; i<MAX_EXERCISES; i++) day1.exercises[i] = 0; strcpy(day1.name, "Chest"); day1.exercises[0] = &ex1; day1.exercises[1] = &ex2; day1.exercises[2] = &ex3; // Set and initialize workout for(i=0; i<MAX_DAYS; i++) workout_send.days[i] = 0; workout_send.numDays = 7; workout_send.days[0] = &day1; iap_bypointer = (IAP) 0x7FFFFFF1; // IAP function location clearScreen(); destination = (unsigned int*)0x00040000; // Dest Flash location source = (unsigned int*)&workout_send; // Source RAM location writeText("here1\n"); command_iap[0]=50; //prepare sectors 15-17 for erase call command_iap[1]=15; command_iap[2]=17; iap_bypointer(command_iap,result_iap); if(result_iap[0] != 0) writeText("error preparing\n"); writeText("here2\n"); command_iap[0]=52; //erase sectors 15-17 command_iap[1]=15; command_iap[2]=17; command_iap[3]=60000; iap_bypointer(command_iap,result_iap); if(result_iap[0] != 0) writeText("error erasing\n"); writeText("here3\n"); command_iap[0]=50; //prepare sector 15 for workout command_iap[1]=15; command_iap[2]=15; iap_bypointer(command_iap,result_iap); if(result_iap[0] != 0) writeText("error preparing sector 15\n"); writeText("here4\n"); // strcpy(text, "HELLO WORLD\n"); command_iap[0]=51; //copy RAM to flash command_iap[1]=(unsigned int) destination; // Flash destination command_iap[2]=(unsigned int) source; // RAM source command_iap[3]=256; command_iap[4]=60000; iap_bypointer(command_iap,result_iap); if(result_iap[0] != 0) writeText("error copying\n"); writeText("here5\n"); enabled_interrupts = VICIntEnable; //disable all interrupts VICIntEnClr = enabled_interrupts; memcpy(&workout_receive, destination, sizeof(struct workout)); //memcpy(buffer, destination, strlen(text)); VICIntEnable = enabled_interrupts; //restore interrupt enable register i2cMasterSendNI(TW_MR_DATA_ACK, (u08)strlen(buffer), (u08*)buffer); }