void nrk_stack_check() { #ifdef NRK_STACK_CHECK unsigned int *stk ; // 2 bytes unsigned char *stkc; // 1 byte stk = (unsigned int *)nrk_cur_task_TCB->OSTCBStkBottom; /* Load stack pointer */ stkc = (unsigned char*)stk; if(*stkc != STK_CANARY_VAL) { #ifdef NRK_REPORT_ERRORS dump_stack_info(); #endif nrk_error_add( NRK_STACK_OVERFLOW ); *stkc=STK_CANARY_VAL; } stk = (unsigned int *)nrk_cur_task_TCB->OSTaskStkPtr; /* Load stack pointer */ stkc = (unsigned char*)stk; if(stkc > (unsigned char *)RAMEND ) { #ifdef NRK_REPORT_ERRORS dump_stack_info(); #endif nrk_error_add( NRK_INVALID_STACK_POINTER); } #endif }
void nrk_task_set_stk( nrk_task_type *task, NRK_STK stk_base[], uint16_t stk_size ) { if(stk_size<32) nrk_error_add(NRK_STACK_TOO_SMALL); /* Dalton Banks - changed cast from void* to NRK_STK* */ task->Ptos = (NRK_STK *) &stk_base[stk_size-1]; /* Dalton Banks - changed cast from void* to NRK_STK* */ task->Pbos = (NRK_STK *) &stk_base[0]; }
void nrk_idle_task() { volatile unsigned char *stkc; // unsigned int *stk ; // 2 bytes while(1) { nrk_stack_check(); if(_nrk_get_next_wakeup()<=NRK_SLEEP_WAKEUP_TIME) { _nrk_cpu_state=1; nrk_idle(); } else { #ifndef NRK_NO_POWER_DOWN // Allow last UART byte to get out nrk_spin_wait_us(10); _nrk_cpu_state=2; nrk_sleep(); #else nrk_idle(); #endif } #ifdef NRK_STACK_CHECK if(nrk_idle_task_stk[0]!=STK_CANARY_VAL) nrk_error_add(NRK_STACK_SMASH); #ifdef KERNEL_STK_ARRAY if(nrk_kernel_stk[0]!=STK_CANARY_VAL) nrk_error_add(NRK_STACK_SMASH); #else stkc=(unsigned char*)(NRK_KERNEL_STK_TOP-NRK_KERNEL_STACKSIZE); if(*stkc!=STK_CANARY_VAL) nrk_error_add(NRK_STACK_SMASH); #endif #endif } }
int8_t nrk_stack_check_pid(int8_t pid) { #ifdef NRK_STACK_CHECK unsigned int *stk ; // 2 bytes unsigned char *stkc; // 1 byte stk = (unsigned int *)nrk_task_TCB[pid].OSTCBStkBottom; /* Load stack pointer */ stkc = (unsigned char*)stk; if(*stkc != STK_CANARY_VAL) { *stkc=STK_CANARY_VAL; return NRK_ERROR; } stk = (unsigned int *)nrk_task_TCB[pid].OSTaskStkPtr; /* Load stack pointer */ stkc = (unsigned char*)stk; if(stkc > (unsigned char *)RAMEND ) { nrk_error_add( NRK_INVALID_STACK_POINTER); return NRK_ERROR; } #endif return NRK_OK; }