Hai friends this is my dought in arm7 programming. when i create a structure in my program it compiled sucessfully. But it is not working in the hardware. I am using ARM7 LPC 2138 and compiler is keil m4.21 and realview 4.13. So i checked it into the debugger. So when i open the debugger window the code is all ready in the running state.(That means the control not pointed to the main function). Checking by stoping the running the control is pointed to the SWI handler and the program not going forward. here is my code. please answer this
#include <LPC213X.H> #include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct employe { char status; char cab_status; char employe_id[12]; char employe_name[15]; struct employe *link; }emp; // #include "GPIO.h" // #include "bit.h" // #include "lcd.h" #define mem_full 0xff #define n_present 0x00 #define deleted 'D' char temp[50]; char add_database(struct employe **q,char *rfid,char *emp_name) { struct employe *temp_,*r; temp_=*q; if(*q==NULL) //if the database is empty creare a new node { temp_=malloc(sizeof(struct employe)); if(temp_!=NULL) { strcpy(temp_->employe_id,rfid); strcpy(temp_->employe_name,emp_name); temp_->status=deleted; temp_->cab_status=n_present; temp_->link=NULL; *q=temp_; } else if(temp_==NULL) { //return mem_full; } } else if(*q!='\0') { temp_=*q; //goto the last node while(temp_->link!=NULL) temp_=temp_->link; //add node at the end r=malloc(sizeof(struct employe)); if(r!=NULL) { strcpy(r->employe_id,rfid); strcpy(r->employe_name,emp_name); r->status=deleted; r->cab_status=n_present; r->link=NULL; temp_->link=r; } else if(r==NULL) { return mem_full; } } return 0; } int main() { struct employe *p; p=NULL; // //lcd pin configuration on p0.16 to p0.23 // pinsel(0,16); // pinsel(0,17); // pinsel(0,18); // pinsel(0,20); // pinsel(0,21); // pinsel(0,22); // pinsel(0,23); // outdir_p0(16); // outdir_p0(17); // outdir_p0(18); // outdir_p0(20); // outdir_p0(21); // outdir_p0(22); // outdir_p0(23); // //initialising lcd // lcd_ini(); // sprintf(temp,"\fWelcome"); // lcd_gotoxy(1,1); // lcd_puts(temp,1); // delay_ms(500); add_database(&p,"123456789","suresh"); while(1); }
I checked the same code for creating a linked list in GNU c and it worked sucessfully. what is the wrong thing in my program.
Have you configured the size of the heap? If not, the program will fail to allocate your record.
Thank you for your valuable information mr. Per Westermark. now i got differrent question Why we need to configure the heap area in this. If it is needed then how can we do the heap area configuration. is there any special cases regarding structure programming in embedded C. waiting for your reply.
"is there any special cases regarding structure programming in embedded C. waiting for your reply."
Yes, most definitely. One of the most important is "LACK OF RESOURCES".
You do not have a big PC with GB of memory, where the C runtime library can request memory when someone calls malloc().
So you use the Configuration Wizard to modify the startup file and specifies how much stack you need to reserve space for, and how much heap. Remember that every kB of memory allocated for heap is a kB of memory not available for the stack or for global variables.
thanks