This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to create a new task in Z stack



Hai, 

                     i am using Thermoostat application, I need to create a task event loop in Zstack application , i tried to add a task, but  Pf handler in the OSAL_THEMOSTATSAMPLE file, i have added event loop function and  a task init , but handler is not calling task event loop function. Below con tains my code please assist me if i am wrong.

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
//Uart_Hal_Init();
APS_Init( taskID++ );
#if defined ( ZIGBEE_FRAGMENTATION )
APSF_Init( taskID++ );
#endif
ZDApp_Init( taskID++ );
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
ZDNwkMgr_Init( taskID++ );
#endif
zcl_Init( taskID++ );
zclSampleThermostat_Init( taskID++ );

GWIF_INIT( taskID ); // my event loop task .

}

// The order in this table must be identical to the task initialization calls below in osalInitTask.
const pTaskEventHandlerFn tasksArr[] = {
macEventLoop,
nwk_event_loop,
Hal_ProcessEvent,
#if defined( MT_TASK )
MT_ProcessEvent,
#endif
APS_event_loop,
#if defined ( ZIGBEE_FRAGMENTATION )
APSF_ProcessEvent,
#endif
ZDApp_event_loop,
#if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
ZDNwkMgr_event_loop,
#endif
zcl_event_loop,
zclSampleThermostat_event_loop,
GWIF_zcTask // my event loop task .
};

UINT16 GWIF_zcTask (byte u8task_id, UINT16 u16events)
{
     uint32 u32Status; 
    UINT8 *pu8Packet;
    UINT32 u32PacketLength; 
    UINT8 u8CmdID;
    UINT8 u8ResponseStatus;

    s32Status = SUCCESS;
    u8ResponseStatus = 0;
    u8CmdID = 0;

    while (1)
    {
            s32Status = zcCmdRspReceive(&pu8Packet,&u32PacketLength);

            if (SUCCESS (s32Status))
            {
               u8CmdID = pu8Packet [0];
             }

            switch ( u8CmdID )
            {
                     case HANDSHAKE_CMD_ID:
                     {
                           zcHandshakeCmdRspHandler( u8ResponseStatus );
                          break;
                     }

                    case SENSOR_CMD_ID:
                   {
                         zcSensorReportCmdRspHandler ( pu8Packet, u32PacketLength);
                         break;
                   }

          }
  }

return s32Status;

 }

my task is to read the pack from uart.

  • Try to refer to SampleSwitch OTA example and see how it does to add OTA task.
  • Hai, 

                          I refereed Simple Switch Example program, In the osal Sample Switch.c file zclOTA_event_loop registered for call back function , zclOTA_Init( taskID ) is initialised , and in Zcl_samplesw.c file event is registered  zclOTA_Register(zclSampleSw_TaskID); with  zclOTA_Register(zclSampleSw_TaskID);  TASKID and it will be called as event in zclSampleSw_event_loop( uint8 task_id, uint16 events ) . 

    My doubt is  zclOTA_event_loop function from where it will be called and where can i see the Function definition and if I add a event how can i register it, If any reference document is available  

  • zclOTA_event_loop is assigned to tasksArr and would be called in osal_run_system().
  • Yes , i know .. Ok i am not bothered about that task, fine , Can you suggest me how can i create a new task and what are the things to be registered
    to call my event loop. If any document is available Please share , so that i can refer it
  • There's no such document. As I suggested, you have to refer to OTA task to do accordingly.
  • Thanks, Ok .. i tried as you suggested i tried to understand how he registered .

    1) zclOTA_event_loop when it is called and what is definition of this , what are the tasks will run in this event loop.
    2) zclOTA_Init (tadkid); in this init which are the things initialise in this and where can i see the definition of the function.
    3) zclOTA_Register(zclSampleSw_TaskID); what this function do.

    when i tried to open the declarations or definitions of these function i could not open this . Please tell me where could i find it.
  • You can find those functions in zcl_OTA.c