os_evt_wait_or(CHECK_EVENT_FLAGS, INFINITE_TIME); //Wait for an Event to occur rx_event = os_evt_get(); switch(rx_event) { case EVENT_INTERRUPT: if(chkflg) { dif = difftime(_gettime(), setalrm); if(!dif) *(tmp->flg) = 1; // on execution of this line (*tymval)--; if(*tymval == 0) chkflg = 0; } break;
the above code is a part of a task that sets a flag, whose address is passed in a structure using a mail box. dif is double. the alarm is generally set to 2 mins (120 secs) untill the dif > 1, things work well. when the dif = 1, the controller goes into hard fault.
i have read few articles and tried to follow the steps but could not come to any solution. www.ti.com/.../spma043.pdf
i use LPC17xx
"when the dif = 1, the controller goes into hard fault."
Don't you mean "when the dif == 0, the controller [...]"?
So tmp is a pointer? And it points to a struct having a field flg - that is also a pointer?
You do not show us your data types. Or how you send that mail. Or how you extract your pointer from that mail. You don't even show us if you verify that there actually exists any mails to retrieve.
when the dif = 1,... i m sry. it is, when the dif = 0.
// definitions uint8_t i, chkflg=0, *flg=0; uint16_t rx_event=0; time_t setalrm; double dif=1; typedef struct { time_t *alrm; uint8_t *flg; time_t *pval; }tym; tym *tmp; //fetching the mail os_mbx_wait(&MailAlrm, (void*)&tmp, 0xFFFF); setalrm = *(tmp->alrm) + _gettime(); tymval = tmp->pval;
this is what i send from a function
// definitions typedef struct { time_t *pty; uint8_t *pt; time_t *pval; }strct; strct tym; ... tym.pt = &drpflg; tym.pty = &gLoadedProtoVal.drpsync; tym.pval = &gDropSyncTym; if(os_mbx_check(&MailAlrm) != 0) os_mbx_send(&MailAlrm, (void*)&tym, 0xFFFF);
No - I can still not see any code that shows us how you initialize your data and send any mail. All we can see is that you like pointers and very short variable names.
Get yourself a Joseph Yiu type Hard Fault handler, dump out the core and processor registers at the fault, and look at the assembler view code that is faulting.
Determine what memory is being accessed, why that might be out-of-range, and if stack related if that is a result of exceeding it's size, or from corruption elsewhere.
If it's fetch related, check any flash wait states or caching settings.
View all questions in Keil forum