1
1
/* mbed Microcontroller Library
2
- * Copyright (c) 2006-2018 ARM Limited
2
+ * Copyright (c) 2006-2019 ARM Limited
3
+ * SPDX-License-Identifier: Apache-2.0
3
4
*
4
5
* Licensed under the Apache License, Version 2.0 (the "License");
5
6
* you may not use this file except in compliance with the License.
16
17
#include <stddef.h>
17
18
#include "us_ticker_api.h"
18
19
#include "PeripheralNames.h"
19
- #define US_TICKER_TIMER1 CMSDK_DUALTIMER1
20
- #define US_TICKER_TIMER2 CMSDK_DUALTIMER2
20
+ #define US_TICKER_COUNTER CMSDK_DUALTIMER1
21
+ #define US_TICKER_INTERRUPT CMSDK_DUALTIMER2
21
22
#define US_TICKER_TIMER_IRQn DUALTIMER_IRQn
22
23
23
24
/** mbed OS HAL API defined us_ticker as an increment ticker
24
25
* MPS2 platform provided in SSE-200 are decrement tickers
25
26
* with interrupt fired counter reaches 0.
26
27
*
27
28
* So 2 Timers are used to construct mbed OS HAL ticker.
28
- *
29
+ *
29
30
* TIMER1 is for counting, and returns inverted binary when read from it
30
31
* TIMER1 will be kept in free-running mode (default, and not generate interrupts)
31
- *
32
+ *
32
33
* TIMER2 is for generating interrupts
33
34
* 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
35
+ * and TIMER2 also set into one-shot mode, which counter halts when is reaches 0
35
36
*/
36
-
37
+
37
38
static int us_ticker_inited = 0 ;
38
39
39
40
void us_ticker_init (void )
@@ -43,47 +44,47 @@ void us_ticker_init(void)
43
44
return ;
44
45
}
45
46
46
- US_TICKER_TIMER1 -> TimerControl = 0x0ul ; // disable TIMER1 and reset all control
47
- US_TICKER_TIMER2 -> TimerControl = 0x0ul ; // disable TIMER2 and reset all control
47
+ US_TICKER_COUNTER -> TimerControl = 0x0ul ; // disable TIMER1 and reset all control
48
+ US_TICKER_INTERRUPT -> TimerControl = 0x0ul ; // disable TIMER2 and reset all control
48
49
49
- US_TICKER_TIMER1 -> TimerLoad = 0xFFFFFFFFul ;
50
- US_TICKER_TIMER2 -> TimerLoad = 0xFFFFFFFFul ;
50
+ US_TICKER_COUNTER -> TimerLoad = 0xFFFFFFFFul ;
51
+ US_TICKER_INTERRUPT -> TimerLoad = 0xFFFFFFFFul ;
51
52
52
- US_TICKER_TIMER1 -> TimerControl |= CMSDK_DUALTIMER1_CTRL_SIZE_Msk ; // set TIMER1 to 32 bit counter
53
- US_TICKER_TIMER2 -> TimerControl |= CMSDK_DUALTIMER2_CTRL_SIZE_Msk ; // set TIMER2 to 32 bit counter
53
+ US_TICKER_COUNTER -> TimerControl |= CMSDK_DUALTIMER1_CTRL_SIZE_Msk ; // set TIMER1 to 32 bit counter
54
+ US_TICKER_INTERRUPT -> TimerControl |= CMSDK_DUALTIMER2_CTRL_SIZE_Msk ; // set TIMER2 to 32 bit counter
54
55
55
- US_TICKER_TIMER1 -> TimerControl |= 0x1 << CMSDK_DUALTIMER1_CTRL_PRESCALE_Pos ; // set TIMER1 with 4 stages prescale
56
- US_TICKER_TIMER2 -> TimerControl |= 0x1 << CMSDK_DUALTIMER2_CTRL_PRESCALE_Pos ; // set TIMER2 with 4 stages prescale
56
+ US_TICKER_COUNTER -> TimerControl |= 0x1 << CMSDK_DUALTIMER1_CTRL_PRESCALE_Pos ; // set TIMER1 with 4 stages prescale
57
+ US_TICKER_INTERRUPT -> TimerControl |= 0x1 << CMSDK_DUALTIMER2_CTRL_PRESCALE_Pos ; // set TIMER2 with 4 stages prescale
57
58
58
- US_TICKER_TIMER2 -> TimerControl |= CMSDK_DUALTIMER2_CTRL_MODE_Msk ; // set TIMER2 periodic mode
59
- US_TICKER_TIMER2 -> TimerControl |= CMSDK_DUALTIMER2_CTRL_ONESHOOT_Msk ; // set TIMER2 one-shot mode
59
+ US_TICKER_INTERRUPT -> TimerControl |= CMSDK_DUALTIMER2_CTRL_MODE_Msk ; // set TIMER2 periodic mode
60
+ US_TICKER_INTERRUPT -> TimerControl |= CMSDK_DUALTIMER2_CTRL_ONESHOOT_Msk ; // set TIMER2 one-shot mode
60
61
61
- US_TICKER_TIMER1 -> TimerControl |= CMSDK_DUALTIMER1_CTRL_EN_Msk ; // enable TIMER1 counter
62
+ US_TICKER_COUNTER -> TimerControl |= CMSDK_DUALTIMER1_CTRL_EN_Msk ; // enable TIMER1 counter
62
63
63
64
NVIC_SetVector (US_TICKER_TIMER_IRQn , (uint32_t )us_ticker_irq_handler );
64
65
us_ticker_inited = 1 ;
65
66
}
66
67
67
68
void us_ticker_free (void )
68
69
{
69
- US_TICKER_TIMER1 -> TimerControl &= ~CMSDK_DUALTIMER1_CTRL_EN_Msk ; // disable TIMER1
70
- US_TICKER_TIMER2 -> TimerControl &= ~CMSDK_DUALTIMER2_CTRL_EN_Msk ; // disable TIMER2
70
+ US_TICKER_COUNTER -> TimerControl &= ~CMSDK_DUALTIMER1_CTRL_EN_Msk ; // disable TIMER1
71
+ US_TICKER_INTERRUPT -> TimerControl &= ~CMSDK_DUALTIMER2_CTRL_EN_Msk ; // disable TIMER2
71
72
us_ticker_disable_interrupt ();
72
73
us_ticker_inited = 0 ;
73
74
}
74
75
75
76
uint32_t us_ticker_read ()
76
77
{
77
- return ~US_TICKER_TIMER1 -> TimerValue ;
78
+ return ~US_TICKER_COUNTER -> TimerValue ;
78
79
}
79
80
80
81
void us_ticker_set_interrupt (timestamp_t timestamp )
81
82
{
82
83
uint32_t delta = timestamp - us_ticker_read ();
83
- US_TICKER_TIMER2 -> TimerControl &= ~CMSDK_DUALTIMER2_CTRL_EN_Msk ; // disable TIMER2
84
- US_TICKER_TIMER2 -> TimerLoad = delta ; // Set TIMER2 load value
85
- US_TICKER_TIMER2 -> TimerControl |= CMSDK_DUALTIMER2_CTRL_INTEN_Msk ; // enable TIMER2 interrupt
86
- US_TICKER_TIMER2 -> TimerControl |= CMSDK_DUALTIMER2_CTRL_EN_Msk ; // enable TIMER2 counter
84
+ US_TICKER_INTERRUPT -> TimerControl &= ~CMSDK_DUALTIMER2_CTRL_EN_Msk ; // disable TIMER2
85
+ US_TICKER_INTERRUPT -> TimerLoad = delta ; // Set TIMER2 load value
86
+ US_TICKER_INTERRUPT -> TimerControl |= CMSDK_DUALTIMER2_CTRL_INTEN_Msk ; // enable TIMER2 interrupt
87
+ US_TICKER_INTERRUPT -> TimerControl |= CMSDK_DUALTIMER2_CTRL_EN_Msk ; // enable TIMER2 counter
87
88
NVIC_EnableIRQ (US_TICKER_TIMER_IRQn );
88
89
}
89
90
@@ -96,14 +97,14 @@ void us_ticker_fire_interrupt(void)
96
97
97
98
void us_ticker_disable_interrupt (void )
98
99
{
99
- US_TICKER_TIMER2 -> TimerControl &= ~CMSDK_DUALTIMER2_CTRL_INTEN_Msk ;
100
- US_TICKER_TIMER2 -> TimerControl &= ~CMSDK_DUALTIMER2_CTRL_EN_Msk ; // disable TIMER2
100
+ US_TICKER_INTERRUPT -> TimerControl &= ~CMSDK_DUALTIMER2_CTRL_INTEN_Msk ;
101
+ US_TICKER_INTERRUPT -> TimerControl &= ~CMSDK_DUALTIMER2_CTRL_EN_Msk ; // disable TIMER2
101
102
NVIC_DisableIRQ (US_TICKER_TIMER_IRQn );
102
103
}
103
104
104
105
void us_ticker_clear_interrupt (void )
105
106
{
106
- US_TICKER_TIMER2 -> TimerIntClr = CMSDK_DUALTIMER2_INTCLR_Msk ;
107
+ US_TICKER_INTERRUPT -> TimerIntClr = CMSDK_DUALTIMER2_INTCLR_Msk ;
107
108
}
108
109
109
110
const ticker_info_t * us_ticker_get_info (void )
0 commit comments