Skip to content

Commit 4324258

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
add comments about TIMER modes and set TIMER2 off by default
1 parent 3ba635d commit 4324258

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/us_ticker.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@
2525
* with interrupt fired counter reaches 0.
2626
*
2727
* So 2 Timers are used to construct mbed OS HAL ticker.
28+
*
2829
* TIMER1 is for counting, and returns inverted binary when read from it
29-
* TIMER2 is for generate interrupts
30+
* TIMER1 will be kept in free-running mode (default, and not generate interrupts)
31+
*
32+
* TIMER2 is for generating interrupts
33+
* So TIMER2 is set to periodic mode, which start decrement counting form LOADVALUE generates interrupts at 0
34+
* and TIMER2 also set into one-shot mode, which counter halts when is reaches 0
3035
*/
36+
3137
static int us_ticker_inited = 0;
3238

3339
void us_ticker_init(void)
@@ -50,11 +56,9 @@ void us_ticker_init(void)
5056
US_TICKER_TIMER2->TimerControl |= 0x1 << CMSDK_DUALTIMER2_CTRL_PRESCALE_Pos; // set TIMER2 with 4 stages prescale
5157

5258
US_TICKER_TIMER2->TimerControl |= CMSDK_DUALTIMER2_CTRL_MODE_Msk; // set TIMER2 periodic mode
53-
5459
US_TICKER_TIMER2->TimerControl |= CMSDK_DUALTIMER2_CTRL_ONESHOOT_Msk; // set TIMER2 one-shot mode
5560

5661
US_TICKER_TIMER1->TimerControl |= CMSDK_DUALTIMER1_CTRL_EN_Msk; // enable TIMER1 counter
57-
US_TICKER_TIMER2->TimerControl |= CMSDK_DUALTIMER2_CTRL_EN_Msk; // enable TIMER2 counter
5862

5963
NVIC_SetVector(US_TICKER_TIMER_IRQn, (uint32_t)us_ticker_irq_handler);
6064
us_ticker_inited = 1;
@@ -76,7 +80,7 @@ uint32_t us_ticker_read()
7680
void us_ticker_set_interrupt(timestamp_t timestamp)
7781
{
7882
uint32_t delta = timestamp - us_ticker_read();
79-
US_TICKER_TIMER2->TimerControl &= ~CMSDK_DUALTIMER2_CTRL_EN_Msk; // disable TIMER2
83+
US_TICKER_TIMER2->TimerControl &= ~CMSDK_DUALTIMER2_CTRL_EN_Msk; // disable TIMER2
8084
US_TICKER_TIMER2->TimerLoad = delta; // Set TIMER2 load value
8185
US_TICKER_TIMER2->TimerControl |= CMSDK_DUALTIMER2_CTRL_INTEN_Msk; // enable TIMER2 interrupt
8286
US_TICKER_TIMER2->TimerControl |= CMSDK_DUALTIMER2_CTRL_EN_Msk; // enable TIMER2 counter
@@ -93,6 +97,7 @@ void us_ticker_fire_interrupt(void)
9397
void us_ticker_disable_interrupt(void)
9498
{
9599
US_TICKER_TIMER2->TimerControl &= ~CMSDK_DUALTIMER2_CTRL_INTEN_Msk;
100+
US_TICKER_TIMER2->TimerControl &= ~CMSDK_DUALTIMER2_CTRL_EN_Msk; // disable TIMER2
96101
NVIC_DisableIRQ(US_TICKER_TIMER_IRQn);
97102
}
98103

@@ -104,7 +109,7 @@ void us_ticker_clear_interrupt(void)
104109
const ticker_info_t *us_ticker_get_info(void)
105110
{
106111
static const ticker_info_t info = {
107-
1562500, // 4 stages prescale from 25MHz (dived by 16)
112+
1562500, // 4 stages prescaled from 25MHz (dived by 16)
108113
32 // 32 bit counter
109114
};
110115
return &info;

0 commit comments

Comments
 (0)