Skip to content

Commit 616fa49

Browse files
committed
LPC55S69: Add a ctimer for usticker to be used in the secure domain
CTIMER 0 is used for the secure domain and CTIMER 1 is used for the non-secure domain Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent 66eb3de commit 616fa49

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/us_ticker.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
#include "fsl_ctimer.h"
1919
#include "PeripheralNames.h"
2020

21+
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
22+
#define CTIMER CTIMER0
23+
#define CTIMER_IRQn CTIMER0_IRQn
24+
#else
25+
#define CTIMER CTIMER1
26+
#define CTIMER_IRQn CTIMER1_IRQn
27+
#endif
28+
2129
const ticker_info_t* us_ticker_get_info()
2230
{
2331
static const ticker_info_t info = {
@@ -47,13 +55,13 @@ void us_ticker_init(void) {
4755

4856
CTIMER_GetDefaultConfig(&config);
4957
config.prescale = prescale - 1;
50-
CTIMER_Init(CTIMER1, &config);
51-
CTIMER_Reset(CTIMER1);
52-
CTIMER_StartTimer(CTIMER1);
58+
CTIMER_Init(CTIMER, &config);
59+
CTIMER_Reset(CTIMER);
60+
CTIMER_StartTimer(CTIMER);
5361
}
54-
NVIC_SetVector(CTIMER1_IRQn, (uint32_t)us_ticker_irq_handler);
55-
NVIC_EnableIRQ(CTIMER1_IRQn);
56-
CTIMER1->MCR &= ~1;
62+
NVIC_SetVector(CTIMER_IRQn, (uint32_t)us_ticker_irq_handler);
63+
NVIC_EnableIRQ(CTIMER_IRQn);
64+
CTIMER->MCR &= ~1;
5765

5866
us_ticker_inited = true;
5967
}
@@ -63,7 +71,7 @@ void us_ticker_init(void) {
6371
* @return The current timer's counter value in ticks
6472
*/
6573
uint32_t us_ticker_read(void) {
66-
return CTIMER1->TC;
74+
return CTIMER->TC;
6775
}
6876

6977
/** Set interrupt for specified timestamp
@@ -80,32 +88,32 @@ void us_ticker_set_interrupt(timestamp_t timestamp) {
8088
matchConfig.outPinInitState = true;
8189
matchConfig.enableInterrupt = true;
8290

83-
CTIMER_SetupMatch(CTIMER1, kCTIMER_Match_0, &matchConfig);
91+
CTIMER_SetupMatch(CTIMER, kCTIMER_Match_0, &matchConfig);
8492
}
8593

8694
/** Disable us ticker interrupt
8795
*
8896
*/
8997
void us_ticker_disable_interrupt(void) {
90-
CTIMER1->MCR &= ~1;
98+
CTIMER->MCR &= ~1;
9199
}
92100

93101
/** Clear us ticker interrupt
94102
*
95103
*/
96104
void us_ticker_clear_interrupt(void) {
97-
CTIMER1->IR = 1;
105+
CTIMER->IR = 1;
98106
}
99107

100108
void us_ticker_fire_interrupt(void)
101109
{
102-
NVIC_SetPendingIRQ(CTIMER1_IRQn);
110+
NVIC_SetPendingIRQ(CTIMER_IRQn);
103111
}
104112

105113
void us_ticker_free(void)
106114
{
107-
CTIMER_StopTimer(CTIMER1);
108-
CTIMER1->MCR &= ~1;
109-
NVIC_DisableIRQ(CTIMER1_IRQn);
115+
CTIMER_StopTimer(CTIMER);
116+
CTIMER->MCR &= ~1;
117+
NVIC_DisableIRQ(CTIMER_IRQn);
110118
us_ticker_inited = false;
111119
}

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC55S69/TARGET_LPCXpresso/mbed_overrides.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ void rtc_setup_oscillator(void)
3535

3636
uint32_t us_ticker_get_clock()
3737
{
38+
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
39+
/* Use 12 MHz clock us ticker timer */
40+
CLOCK_AttachClk(kFRO_HF_to_CTIMER0);
41+
return CLOCK_GetFreq(kCLOCK_CTmier0);;
42+
#else
3843
/* Use 12 MHz clock us ticker timer */
3944
CLOCK_AttachClk(kFRO_HF_to_CTIMER1);
4045
return CLOCK_GetFreq(kCLOCK_CTmier1);;
46+
#endif
4147
}
4248

4349
void sdio_clock_setup(void)

0 commit comments

Comments
 (0)