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.

RTOS/CC2538: osal_start_timerEX not working

Part Number: CC2538

Tool/software: TI-RTOS

Hi I have an issue regarding timer in ZMesh i called this function in my init function "osal_start_timerEx( RFID_Coordinator_TaskID,RFID_DISP_TIMEOUT_EVNT,500 );" it works and i have written exactlay this call in event^RFID_DISP_TIMEOUT_EVNT condition in process_event task but it seems that event is not firing after first event. 

#define RFID_DISP_TIMEOUT_EVNT 0x0080 

no other macro with this bit.

  • If you expect to see RFID_DISP_TIMEOUT_EVNT to be triggered again and again, you should also put osal_start_timerEx( RFID_Coordinator_TaskID,RFID_DISP_TIMEOUT_EVNT,500 ) in RFID_DISP_TIMEOUT_EVNT.

  • yes i have put this in my event but still there is no change and also this event is not triggered first time somtimes very strange issue.
    can you tell me how i can monitor application events in TI XDS 2 pin cjtag?
    also there is no call to osal_start_timerEX anywhere in the code i have tripple checked it.
  • if (events & RFID_DISP_TIMEOUT_EVNT)
    {
    RFID_Uart_Write(USB_UART, "CHCK\r\n", strlen("CHCK\r\n"));
    osal_start_timerEx( RFID_Coordinator_TaskID,RFID_DISP_TIMEOUT_EVNT,500 );
    return (events ^ RFID_DISP_TIMEOUT_EVNT);
    }

    this is my event handler
  • Try to check return status of osal_start_timerEx in RFID_DISP_TIMEOUT_EVNT
  • timerStat = osal_start_timerEx( RFID_Coordinator_TaskID,RFID_DISP_TIMEOUT_EVNT,1000 );
    i have watched the value of timerStat and it is 0x00
  • Do you set a breakpoint in RFID_DISP_TIMEOUT_EVNT and check if it hits every one second.
  • yes i have set a break point at it and it works only once.
  • Can you please suggest me anything to debug this issue it was working fine in GenericApp example i have editet the GenericApp Application.
  • And I am using Custom Board.
  • I don’t think this is related to custom board.
  • #include "OSAL.h"
    #include "AF.h"
    #include "ZDApp.h"
    #include "ZDObject.h"
    #include "ZDProfile.h"

    #include "RFID_Coordinator.h"
    #include "DebugTrace.h"

    #if !defined( WIN32 ) || defined( ZBIT )
    #include "OnBoard.h"
    #endif

    /* HAL */
    #include "hal_lcd.h"
    #include "hal_led.h"
    #include "hal_key.h"
    #include "hal_uart.h"
    #include "RFID_Uart.h"
    #include "string.h"
    #include "MFRC522.h"
    #include "RFID_display.h"
    #include "stdio.h"

    /* RTOS */
    #if defined( IAR_ARMCM3_LM )
    #include "RTOS_App.h"
    #endif


    const cId_t RFID_Coordinator_ClusterList[RFID_Coordinator_MAX_CLUSTERS] =
    {
    RFID_Coordinator_CLUSTERID
    };

    const SimpleDescriptionFormat_t RFID_Coordinator_SimpleDesc =
    {
    RFID_Coordinator_ENDPOINT, // int Endpoint;
    RFID_Coordinator_PROFID, // uint16 AppProfId[2];
    RFID_Coordinator_DEVICEID, // uint16 AppDeviceId[2];
    RFID_Coordinator_DEVICE_VERSION, // int AppDevVer:4;
    RFID_Coordinator_FLAGS, // int AppFlags:4;
    RFID_Coordinator_MAX_CLUSTERS, // byte AppNumInClusters;
    (cId_t *)RFID_Coordinator_ClusterList, // byte *pAppInClusterList;
    RFID_Coordinator_MAX_CLUSTERS, // byte AppNumInClusters;
    (cId_t *)RFID_Coordinator_ClusterList // byte *pAppInClusterList;
    };

    // This is the Endpoint/Interface description. It is defined here, but
    // filled-in in RFID_Coordinator_Init(). Another way to go would be to fill
    // in the structure here and make it a "const" (in code space). The
    // way it's defined in this sample app it is define in RAM.
    endPointDesc_t RFID_Coordinator_epDesc;

    /*********************************************************************
    * EXTERNAL VARIABLES
    */

    /*********************************************************************
    * EXTERNAL FUNCTIONS
    */

    /*********************************************************************
    * LOCAL VARIABLES
    */
    byte RFID_Coordinator_TaskID; // Task ID for internal task/event processing
    // This variable will be received when
    // RFID_Coordinator_Init() is called.

    devStates_t RFID_Coordinator_NwkState;

    byte RFID_Coordinator_TransID; // This is the unique message ID (counter)

    afAddrType_t RFID_Coordinator_DstAddr;

    CardData emp;
    CardData opr;
    CardData mac;
    CardData unt;
    CardData bnd;

    uint8_t timerStat;


    // Number of recieved messages
    static uint16 rxMsgCount;



    /*********************************************************************
    * LOCAL FUNCTIONS
    */
    static void RFID_Coordinator_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg );
    static void RFID_Coordinator_MessageMSGCB( afIncomingMSGPacket_t *pckt );
    static void RFID_Coordinator_SendTheMessage( char theMessageData[] );

    #if defined( IAR_ARMCM3_LM )
    static void RFID_Coordinator_ProcessRtosMessage( void );
    #endif


    void RFID_Coordinator_Init( uint8 task_id )
    {
    RFID_Coordinator_TaskID = task_id;
    RFID_Coordinator_NwkState = DEV_INIT;
    RFID_Coordinator_TransID = 0;



    RFID_Coordinator_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
    RFID_Coordinator_DstAddr.endPoint = 0;
    RFID_Coordinator_DstAddr.addr.shortAddr = 0;

    RFID_Coordinator_epDesc.endPoint = RFID_Coordinator_ENDPOINT;
    RFID_Coordinator_epDesc.task_id = &RFID_Coordinator_TaskID;
    RFID_Coordinator_epDesc.simpleDesc
    = (SimpleDescriptionFormat_t *)&RFID_Coordinator_SimpleDesc;
    RFID_Coordinator_epDesc.latencyReq = noLatencyReqs;

    afRegister( &RFID_Coordinator_epDesc );


    RegisterForKeys( RFID_Coordinator_TaskID );



    ZDO_RegisterForZDOMsg( RFID_Coordinator_TaskID, End_Device_Bind_rsp );
    ZDO_RegisterForZDOMsg( RFID_Coordinator_TaskID, Match_Desc_rsp );

    #if defined( IAR_ARMCM3_LM )
    // Register this task with RTOS task initiator
    RTOS_RegisterApp( task_id, RFID_Coordinator_RTOS_MSG_EVT );
    #endif

    RFID_Uart_Init();
    RFID_display_Init();
    MFRC522_Init();

    timerStat = osal_start_timerEx( RFID_Coordinator_TaskID,RFID_DISP_TIMEOUT_EVNT,1000 );


    }


    uint16 RFID_Coordinator_ProcessEvent( uint8 task_id, uint16 events )
    {
    afIncomingMSGPacket_t *MSGpkt;
    afDataConfirm_t *afDataConfirm;

    // Data Confirmation message fields
    byte sentEP;
    ZStatus_t sentStatus;
    byte sentTransID; // This should match the value sent
    (void)task_id; // Intentionally unreferenced parameter

    if ( events & SYS_EVENT_MSG )
    {
    MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( RFID_Coordinator_TaskID );
    while ( MSGpkt )
    {
    switch ( MSGpkt->hdr.event )
    {
    case ZDO_CB_MSG:
    RFID_Coordinator_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
    break;

    case KEY_CHANGE:
    // RFID_Coordinator_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
    break;

    case AF_DATA_CONFIRM_CMD:
    // This message is received as a confirmation of a data packet sent.
    // The status is of ZStatus_t type [defined in ZComDef.h]
    // The message fields are defined in AF.h
    afDataConfirm = (afDataConfirm_t *)MSGpkt;

    sentEP = afDataConfirm->endpoint;
    (void)sentEP; // This info not used now
    sentTransID = afDataConfirm->transID;
    (void)sentTransID; // This info not used now

    sentStatus = afDataConfirm->hdr.status;
    // Action taken when confirmation is received.
    if ( sentStatus != ZSuccess )
    {
    // The data wasn't delivered -- Do something
    }
    break;

    case AF_INCOMING_MSG_CMD:
    RFID_Coordinator_MessageMSGCB( MSGpkt );
    break;

    case ZDO_STATE_CHANGE:
    RFID_Coordinator_NwkState = (devStates_t)(MSGpkt->hdr.status);
    if(RFID_Coordinator_NwkState == DEV_COORD_STARTING)
    {
    //RFID_Uart_Write(USB_UART, "Coordinator Starting \r\n",strlen("Coordinator Starting \r\n"));
    }
    if(RFID_Coordinator_NwkState == DEV_ZB_COORD)
    {
    //RFID_Uart_Write(USB_UART, "Coordinator Started \r\n",strlen("Coordinator Started \r\n"));
    }

    break;

    default:
    break;
    }

    // Release the memory
    osal_msg_deallocate( (uint8 *)MSGpkt );

    // Next
    MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( RFID_Coordinator_TaskID );
    }

    return (events ^ SYS_EVENT_MSG);
    }

    if (events & RFID_DISP_TIMEOUT_EVNT)
    {
    RFID_Uart_Write(USB_UART, "CHCK\r\n", strlen("CHCK\r\n"));
    timerStat = osal_start_timerEx( RFID_Coordinator_TaskID,RFID_DISP_TIMEOUT_EVNT,1000 );
    return (events ^ RFID_DISP_TIMEOUT_EVNT);


    #if defined( IAR_ARMCM3_LM )
    // Receive a message from the RTOS queue
    if ( events & RFID_Coordinator_RTOS_MSG_EVT )
    {
    // Process message from RTOS queue
    RFID_Coordinator_ProcessRtosMessage();

    // return unprocessed events
    return (events ^ RFID_Coordinator_RTOS_MSG_EVT);
    }
    #endif

    // Discard unknown events
    return 0;
    }

    /*********************************************************************
    * Event Generation Functions
    */

    /*********************************************************************
    * @fn RFID_Coordinator_ProcessZDOMsgs()
    *
    * @brief Process response messages
    *
    * @param none
    *
    * @return none
    */
    static void RFID_Coordinator_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg )
    {
    switch ( inMsg->clusterID )
    {
    case End_Device_Bind_rsp:
    if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess )
    {
    // Light LED
    HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
    }
    #if defined( BLINK_LEDS )
    else
    {
    // Flash LED to show failure
    HalLedSet ( HAL_LED_4, HAL_LED_MODE_FLASH );
    }
    #endif
    break;

    case Match_Desc_rsp:
    {
    ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg );
    if ( pRsp )
    {
    if ( pRsp->status == ZSuccess && pRsp->cnt )
    {
    RFID_Coordinator_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
    RFID_Coordinator_DstAddr.addr.shortAddr = pRsp->nwkAddr;
    // Take the first endpoint, Can be changed to search through endpoints
    RFID_Coordinator_DstAddr.endPoint = pRsp->epList[0];

    // Light LED
    HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
    }
    osal_mem_free( pRsp );
    }
    }
    break;
    }
    }



    static void RFID_Coordinator_MessageMSGCB( afIncomingMSGPacket_t *pkt )
    {
    switch ( pkt->clusterId )
    {
    case RFID_Coordinator_CLUSTERID:
    RFID_Uart_Write(USB_UART, "MSG: ", strlen("MSG: "));
    RFID_Uart_Write(USB_UART, (char*)pkt->cmd.Data, strlen((char*)pkt->cmd.Data));
    // rxMsgCount += 1; // Count this message
    // HalLedSet ( HAL_LED_4, HAL_LED_MODE_BLINK ); // Blink an LED
    //#if defined( LCD_SUPPORTED )
    // HalLcdWriteString( (char*)pkt->cmd.Data, HAL_LCD_LINE_1 );
    // HalLcdWriteStringValue( "Rcvd:", rxMsgCount, 10, HAL_LCD_LINE_2 );
    //#elif defined( WIN32 )
    // WPRINTSTR( pkt->cmd.Data );
    //#endif
    break;
    }
    }

    /*********************************************************************
    * @fn RFID_Coordinator_SendTheMessage
    *
    * @brief Send "the" message.
    *
    * @param none
    *
    * @return none
    */
    static void RFID_Coordinator_SendTheMessage( char theMessageData[] )
    {
    RFID_Coordinator_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
    RFID_Coordinator_DstAddr.addr.shortAddr = 0x0000;
    // Take the first endpoint, Can be changed to search through endpoints
    RFID_Coordinator_DstAddr.endPoint = RFID_Coordinator_ENDPOINT;
    // char theMessageData[] = "Hello World 6";

    RFID_Uart_Write(USB_UART, "Hello UART", strlen("Hello UART"));
    RFID_Uart_Write(USB_UART, "\r\n", 2);
    if ( AF_DataRequest( &RFID_Coordinator_DstAddr, &RFID_Coordinator_epDesc,
    RFID_Coordinator_CLUSTERID,
    (byte)osal_strlen( theMessageData ) + 1,
    (byte *)&theMessageData,
    &RFID_Coordinator_TransID,
    AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
    {
    RFID_display_Write("DB.inf.txt=\"OK Sending Msg..\"",strlen("DB.inf.txt=\"OK Sending Msg..\""));
    }
    else
    {
    RFID_display_Write("DB.inf.txt=\"Err Sending Msg..\"",strlen("DB.inf.txt=\"Err Sending Msg..\""));
    // Error occurred in request to send.
    }
    }

    void RFID_card_detect_cb()
    {
    char buff[50];

    //UARTprintf("Card Detected\r\n");
    if(card.buffer[0] == EMP_IDENTIFIER)
    {
    emp.c[0] = card.buffer[1];
    emp.c[1] = card.buffer[2];
    emp.c[2] = card.buffer[3];
    emp.c[3] = card.buffer[4];
    sprintf(buff,"DB.id.txt=\"%d\"",emp.n);
    RFID_display_Write(buff,strlen(buff));
    RFID_Coordinator_SendTheMessage(buff);

    }
    if(card.buffer[0] == OPR_IDENTIFIER)
    {
    opr.c[0] = card.buffer[1];
    opr.c[1] = card.buffer[2];
    opr.c[2] = card.buffer[3];
    opr.c[3] = card.buffer[4];
    sprintf(buff,"DB.opr.txt=\"%d\"",opr.n);
    RFID_display_Write(buff,strlen(buff));
    RFID_Coordinator_SendTheMessage(buff);
    }
    if(card.buffer[0] == JOB_IDENTIFIER)
    {
    bnd.c[0] = card.buffer[1];
    bnd.c[1] = card.buffer[2];
    bnd.c[2] = card.buffer[3];
    bnd.c[3] = card.buffer[4];
    sprintf(buff,"DB.cut.txt=\"%d\"",bnd.n);
    RFID_display_Write(buff,strlen(buff));
    RFID_Coordinator_SendTheMessage(buff);
    }
    if(card.buffer[0] == MAC_IDENTIFIER)
    {
    mac.c[0] = card.buffer[1];
    mac.c[1] = card.buffer[2];
    mac.c[2] = card.buffer[3];
    mac.c[3] = card.buffer[4];
    sprintf(buff,"DB.mac.txt=\"%d / %d\"",mac.n,unt.n);
    RFID_display_Write(buff,strlen(buff));
    RFID_Coordinator_SendTheMessage(buff);
    }
    if(card.buffer[0] == UNT_IDENTIFIER)
    {
    unt.c[0] = card.buffer[1];
    unt.c[1] = card.buffer[2];
    unt.c[2] = card.buffer[3];
    unt.c[3] = card.buffer[4];
    sprintf(buff,"DB.mac.txt=\"%d / %d\"",mac.n,unt.n);
    RFID_display_Write(buff,strlen(buff));
    RFID_Coordinator_SendTheMessage(buff);
    }

    }

    #if defined( IAR_ARMCM3_LM )
    /*********************************************************************
    * @fn RFID_Coordinator_ProcessRtosMessage
    *
    * @brief Receive message from RTOS queue, send response back.
    *
    * @param none
    *
    * @return none
    */
    static void RFID_Coordinator_ProcessRtosMessage( void )
    {
    osalQueue_t inMsg;

    if ( osal_queue_receive( OsalQueue, &inMsg, 0 ) == pdPASS )
    {
    uint8 cmndId = inMsg.cmnd;
    uint32 counter = osal_build_uint32( inMsg.cbuf, 4 );

    switch ( cmndId )
    {
    case CMD_INCR:
    counter += 1; /* Increment the incoming counter */
    /* Intentionally fall through next case */

    case CMD_ECHO:
    {
    userQueue_t outMsg;

    outMsg.resp = RSP_CODE | cmndId; /* Response ID */
    osal_buffer_uint32( outMsg.rbuf, counter ); /* Increment counter */
    osal_queue_send( UserQueue1, &outMsg, 0 ); /* Send back to UserTask */
    break;
    }

    default:
    break; /* Ignore unknown command */
    }
    }
    }
    #endif

    /*********************************************************************
    */
  • I suggest you to test original GenericApp example and check if GENERICAPP_SEND_MSG_EVT is triggered periodically.
  • yes i have tested that example and that was working properly but i dont know why this is not working.
    can you tell me that which compile option do I have to set/remove for normal operation and to remove LCD and other SmarRF06EB related code.
  • remove these flags:
    LCD_SUPPORTED=DEBUG
    Add these flags:
    HAL_LCD=FALSE
  • Hey YiKai Chen thank you for your help.
    I have removed All Compile Time MT Options and now my process event is not even firing at ZDO_STATE_CHANGE
    Please help.
  • Why do you remove all of them?
  • I have removed All of MT related options
  • i think MT is for ZNP type configurations??
  • One more thing that i have discovered that the ZDO_CHANGE_STATE is firing if i configure the app in Router mode.
  • MT related defines are not only used by ZNP. You shouldn’t remove them all.