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 does OSAL's tick timer works?

Other Parts Discussed in Thread: CC2540

CC2540 & Peripheral:

Is the value returned from ll_McuPrecisionCount() incresed by interrupt or hardware?

If by interrupt,will the call of HAL_ENTER_CRITICAL_SECTION() affect the tick timer?

I wanna know as much as possible interrupt source in OSAL.

Please help me!

Any help welcome!

  • I am waitting for help...

    God bless you with determination,honesty and happiness.

  • As far as I can tell, this is all done using Timer 2 (the MAC timer) used for the radio.  The LL_T2_PERIOD_VALUE is 20000 which with a 32 MHz clock corresponds to 625 microseconds.  This means that there is a timer 2 overflow every 625 microseconds so examination of the overflow counter (which is apparently what ll_McuPrecisionCount does) returns the number of "ticks" where each tick is 625 microseconds.  There is no interrupt needed to increment the tick since this is done in hardware as part of Timer 2.  Note that the overflow counter is 24 bits so the tick count will rollover after 16,777,216 ticks (about 2.9 hours).

    So you can't break the Timer 2 counting by disabling interrupts.

    On the other hand, that same Timer 2 does have its overflow compare 1 register used to trigger an interrupt (TIMER2_OVF_COMPARE1) as well as an event (t2ovf_cmp1_event) and as far as I can tell the overflow compare is set to roughly the next connection event or advertising event (depending on current mode) so it would be unwise to disable interrupts for too long.  In general, there is no need to disable interrupts for very long nor even to run your own code in the OSAL event loop for very long.  If you want to do something that requires waiting, say for an external MCU, then you should yield back control to OSAL and just repeatedly set an OSAL event (so that other higher priority tasks can get time) or better yet coordinate with your MCU to use an interrupt so that OSAL can put the CC2540 to sleep and only wake up when the MCU is ready.

    OSAL itself just uses the sleep timer when putting the CC2540 to sleep and OSAL sets the time to wake up to be the shorter of the next radio event (connection interval or advertising event) or OSAL event (if you have an OSAL timer set, for example).  Of course, the CC2540 can also wake up earlier than this timer if there is an interrupt, say from an external MCU or some other device.