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.

CC2430 OSAL timer

Other Parts Discussed in Thread: CC2430, CC2530

I see the OSAL timer in Z stack 1.4.3-1.2.1 for CC2430 is the 8 bit timer. The timer tick for OSAL is 1ms. I also notice that there are two different timer update schemes: Interrupt enabled and poll enabled

 

1. poll enabled: poll in big loop of system tasks.  Hal_ProcessPoll() function in OSAL_Start_system will call HalTimerTick() to set the callback function to update sys clock

 

2. Int enabled:  in "HAL_ISR_FUNCTION" int vector, halProcessTimer4() will set the callback function to update sys clock

 

I think both way works, the first way is "fake" timer and it would delay the time for task process. the second should be more accurate but interrupt current task which could use timer as calibration.

 

I saw Z stack uses both in different version: depending on HAL_BOARD_INIT() is executed first(INT based) or InitBoard() is executed first(poll based) in ZMain.c

 

Is there anyone who can confirm my investigation is right or wrong. if it is right, which is the best way to configure timer?

 

 

thanks

 

Rui

 

  • Your observations are correct. If you use non-interrupt, 1ms clock "ticks" could be missed if an OSAL task takes longer than 1ms to execute, causing the OSAL time to slip. In applications that do not require somewhat accurate timing, this method avoids the overhead of timer ISR processing. It's left up to the application developer to decide whether they need to use interrupts.

  • thanks for your reply. Just want to make sure this INT will be "missed" or "delayed". I saw the interrupt register flag only being cleared in halProcessTimer4(). So I think it will be "delayed". Also I saw some thread said OSAL timer is based on MAC 320us timer. Is that only for CC2530. Because in CC2430 Z stack 1.4.3-1.2.1, I saw it used 8 bit timer HWtimer 4. not the 16 bit timer. Just try to make sure which timer triggers the OSAL timer

     

     

    Thanks

     

    Rui

  • I think the either method has significant shortcomings such that you should throw them both away and just implement the OSAL clock from the sleep timer tick - you'll never lose time because that thing is always ticking - even in PM2!

    /**************************************************************************************************
      Filename:       osal_clk.c
      Revised:        $Date: 2011-04-11 10:53:58 -0700 (Mon, 11 Apr 2011) $
      Revision:       $Revision: 25649 $

      Description:    A replacement for OSAL Clock definition and manipulation functions.

      Copyright 2011 Texas Instruments Incorporated. All rights reserved.

      IMPORTANT: Your use of this Software is limited to those specific rights
      granted under the terms of a software license agreement between the user
      who downloaded the software, his/her employer (which must be your employer)
      and Texas Instruments Incorporated (the "License").  You may not use this
      Software unless you agree to abide by the terms of the License. The License
      limits your use, and you acknowledge, that the Software may not be modified,
      copied or distributed unless embedded on a Texas Instruments microcontroller
      or used solely and exclusively in conjunction with a Texas Instruments radio
      frequency transceiver, which is integrated into your product.  Other than for
      the foregoing purpose, you may not use, reproduce, copy, prepare derivative
      works of, modify, distribute, perform, display or sell this Software and/or
      its documentation for any purpose.

      YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
      PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
      INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
      NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
      TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
      NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
      LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
      INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
      OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
      OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
      (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.

      Should you have any questions regarding your right to use this Software,
      contact Texas Instruments Incorporated at www.TI.com.
    **************************************************************************************************/

    /* ------------------------------------------------------------------------------------------------
     *                                          Includes
     * ------------------------------------------------------------------------------------------------
     */

    #include "comdef.h"
    #include "hal_z3d.h"
    #include "OSAL_Clock.h"


    /* ------------------------------------------------------------------------------------------------
     *                                           Macros
     * ------------------------------------------------------------------------------------------------
     */

    #define TS_ST_GET(STCNT) st (    \
      uint32 T32 = 0;                \
                                     \
      do {                           \
        (STCNT) = T32;               \
        /* Get the sleep timer count; ST0 must be read first. */\
        ((uint8 *) &(T32))[0] = ST0; \
        ((uint8 *) &(T32))[1] = ST1; \
        ((uint8 *) &(T32))[2] = ST2; \
      } while (T32 != (STCNT));      \
    )

    /* ------------------------------------------------------------------------------------------------
     *                                       Local  Variables
     * ------------------------------------------------------------------------------------------------
     */

    static uint32 stLast;
    static uint16 stRem;

    /**************************************************************************************************
     * @fn          osalTimeUpdate
     *
     * @brief       This function uses the free-running Sleep Timer ticks to update the 1-msec OSAL
     *              timers.
     *
     * input parameters
     *
     * @param       None.
     *
     * output parameters
     *
     * None.
     *
     * @return      None.
     **************************************************************************************************
     */

    void osalTimeUpdate(void)
    {
      static uint8 run;

      if (run == 0)
      {
        run = 1;
        TS_ST_GET(stLast);
        return;
      }

      uint32 stCurr;
      TS_ST_GET(stCurr);  // Get the free-running count of 30.5 usec timer ticks. 

      if (stCurr != stLast)
      {
        uint32 stTemp = stCurr;
        stCurr -= stLast;  // Calculate the elapsed ticks of the free-running timer.
        ((uint8 *)&stCurr)[3] = 0;  // Adjust for a carry on the 24-bit ST counter.
        stLast = stTemp;
        stCurr *= 125;
        stCurr += stRem;

        uint16 msecs = (uint16)(stCurr / 4096UL);
        stRem = (uint16)(stCurr - (4096UL * msecs));

        if (msecs)
        {
          osalTimerUpdate(msecs);
        }
      }
    }

  •  

     

    Another question is about the energy consumption: Hal_ProcessPoll() will be executed in every for loop, and most time there will be no INT happen(32M sys clock compared with 1ms OSAL INT). so whether it is a huge energy waste to keep on poll timer INT?

    Thanks

     

    Rui

  • Thanks very much, dirty Hary. Just want to know whether it is possible that I can integrate this code into the Z stack 1.4.3-1.2.1 in CC2430, what other changes I need to do. what timer register the Sleep timer will use?

     

    Also the Poll based timer will only be “delayed”, not “missed”, am I right?  At the very beginning of OSAL_Start_System() process, there is Hal_ProcessPoll(),which calls the HalTimerTick(), which calls halProcessTimer4(). Based on DN116, the TIMIF register is set by Timer4 INT/OSAL every 1ms and the only way to clear it is to set T4CH0IF=0 in HalTimerTick(), the code will be like:

     

        if (TIMIF & TIMIF_T4CH0IF)

        {

          T4CH0IF = 0;  //DN116

          halTimerSendCallBack (HAL_TIMER_2, HAL_TIMER_CHANNEL_A, HAL_TIMER_CH_MODE_OUTPUT_COMPARE);

    }

    For instance, if OSAL timer INT happens at 1ms, and my process will remain additional 2.5ms, this OSAL INT flag will be set as 1 for additional 2.5ms and be cleared at 3.5ms to 0, No timer miss will happen, am I right?

    I saw there are two ways to trigger INT, overflow or output compare. CC2430 uses output compare mode but I can not find the T4CC0n in CC2430. Only “#define TCHN_T4CCL    &(X_T4CC0)”, so what is the value for T4CC0n?

  • Hi,Dirty

    I do not understand the programmer where

    the stCurr *= 125;
        stCurr += stRem;

        uint16 msecs = (uint16)(stCurr / 4096UL);
        stRem = (uint16)(stCurr - (4096UL * msecs));

        if (msecs)
        {
          osalTimerUpdate(msecs);
        }

    why does stCurr multiply by 125?the stCurr *= 125;

    And why is stCurr divided by 4086UL?uint16 msecs = (uint16)(stCurr / 4096UL);

    Please tell me.Thanks in advance.

    Regards,

    stones

  • Hi,Rui

    Could I have your QQ?I am also interested in the stack timer.I think using QQ is more convinient.

    Regards,

    stones

  • Hi, Dirty Hary, If I want to integrate this code to Z stack 1.4.3-1.2.1, Which dir I should put into?(OSAL?), also this one is also interrupt based, Am I correct? If so, what is the advantage of using this one instead of traditional INT based 32M clock. (I assume both introduce the INT handler overhead).

     

    Thanks

     

    Rui