Other Parts Discussed in Thread: Z-STACK
This is a very simple test of z-stack: toggle the LED light every second. It works fine, till about after 10-15 toggles. then it stops responding. any idea where I did wrong? thanks in advance.
this is what I did:
void zclUartApp_Init( uint8 task_id )
{
UartApp_TaskID = task_id;
osal_start_timerEx(UartApp_TaskID, UARTAPP_SEND_MSG, 2000);
}
Event loop:
uint16 zcl_UartApp_event_loop( uint8 task_id, uint16 events )
{
unsigned char x[5];
if ( events & SYS_EVENT_MSG )
{
...
// Return unprocessed events
return ( events ^ SYS_EVENT_MSG );
}
if ( events & UARTAPP_SEND_MSG )
{
HalLedSet(HAL_LED_1,HAL_LED_MODE_TOGGLE);
osal_start_timerEx( UartApp_TaskID, UARTAPP_SEND_MSG,
UARTAPP_SEND_MSG_REPEAT );
return ( events ^ UARTAPP_SEND_MSG );
}
}
constants:
#define UARTAPP_SEND_MSG 0x0004 #define UARTAPP_SEND_MSG_REPEAT 1000
Initialization here:
const pTaskEventHandlerFn tasksArr[] = {
macEventLoop,
nwk_event_loop,
Hal_ProcessEvent,
#if defined( MT_TASK )
MT_ProcessEvent,
#endif
APS_event_loop,
ZDApp_event_loop,
zcl_event_loop,
zcl_UartApp_event_loop
};
const uint8 tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[0] );
uint16 *tasksEvents;
void osalInitTasks( void )
{
uint8 taskID = 0;
tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
macTaskInit( taskID++ );
nwk_init( taskID++ );
Hal_Init( taskID++ );
#if defined( MT_TASK )
MT_TaskInit( taskID++ );
#endif
APS_Init( taskID++ );
ZDApp_Init( taskID++ );
zcl_Init( taskID++ );
zclUartApp_Init( taskID );
}