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 <mahesh.mahadevan@nxp.com>
pull/10067/head
Mahesh Mahadevan 2019-01-07 14:33:10 -06:00 committed by Cruz Monrreal II
parent 192040c0ae
commit 80006c8275
2 changed files with 28 additions and 14 deletions

View File

@ -18,6 +18,14 @@
#include "fsl_ctimer.h" #include "fsl_ctimer.h"
#include "PeripheralNames.h" #include "PeripheralNames.h"
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
#define CTIMER CTIMER0
#define CTIMER_IRQn CTIMER0_IRQn
#else
#define CTIMER CTIMER1
#define CTIMER_IRQn CTIMER1_IRQn
#endif
const ticker_info_t* us_ticker_get_info() const ticker_info_t* us_ticker_get_info()
{ {
static const ticker_info_t info = { static const ticker_info_t info = {
@ -47,13 +55,13 @@ void us_ticker_init(void) {
CTIMER_GetDefaultConfig(&config); CTIMER_GetDefaultConfig(&config);
config.prescale = prescale - 1; config.prescale = prescale - 1;
CTIMER_Init(CTIMER1, &config); CTIMER_Init(CTIMER, &config);
CTIMER_Reset(CTIMER1); CTIMER_Reset(CTIMER);
CTIMER_StartTimer(CTIMER1); CTIMER_StartTimer(CTIMER);
} }
NVIC_SetVector(CTIMER1_IRQn, (uint32_t)us_ticker_irq_handler); NVIC_SetVector(CTIMER_IRQn, (uint32_t)us_ticker_irq_handler);
NVIC_EnableIRQ(CTIMER1_IRQn); NVIC_EnableIRQ(CTIMER_IRQn);
CTIMER1->MCR &= ~1; CTIMER->MCR &= ~1;
us_ticker_inited = true; us_ticker_inited = true;
} }
@ -63,7 +71,7 @@ void us_ticker_init(void) {
* @return The current timer's counter value in ticks * @return The current timer's counter value in ticks
*/ */
uint32_t us_ticker_read(void) { uint32_t us_ticker_read(void) {
return CTIMER1->TC; return CTIMER->TC;
} }
/** Set interrupt for specified timestamp /** Set interrupt for specified timestamp
@ -80,32 +88,32 @@ void us_ticker_set_interrupt(timestamp_t timestamp) {
matchConfig.outPinInitState = true; matchConfig.outPinInitState = true;
matchConfig.enableInterrupt = true; matchConfig.enableInterrupt = true;
CTIMER_SetupMatch(CTIMER1, kCTIMER_Match_0, &matchConfig); CTIMER_SetupMatch(CTIMER, kCTIMER_Match_0, &matchConfig);
} }
/** Disable us ticker interrupt /** Disable us ticker interrupt
* *
*/ */
void us_ticker_disable_interrupt(void) { void us_ticker_disable_interrupt(void) {
CTIMER1->MCR &= ~1; CTIMER->MCR &= ~1;
} }
/** Clear us ticker interrupt /** Clear us ticker interrupt
* *
*/ */
void us_ticker_clear_interrupt(void) { void us_ticker_clear_interrupt(void) {
CTIMER1->IR = 1; CTIMER->IR = 1;
} }
void us_ticker_fire_interrupt(void) void us_ticker_fire_interrupt(void)
{ {
NVIC_SetPendingIRQ(CTIMER1_IRQn); NVIC_SetPendingIRQ(CTIMER_IRQn);
} }
void us_ticker_free(void) void us_ticker_free(void)
{ {
CTIMER_StopTimer(CTIMER1); CTIMER_StopTimer(CTIMER);
CTIMER1->MCR &= ~1; CTIMER->MCR &= ~1;
NVIC_DisableIRQ(CTIMER1_IRQn); NVIC_DisableIRQ(CTIMER_IRQn);
us_ticker_inited = false; us_ticker_inited = false;
} }

View File

@ -35,9 +35,15 @@ void rtc_setup_oscillator(void)
uint32_t us_ticker_get_clock() uint32_t us_ticker_get_clock()
{ {
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
/* Use 12 MHz clock us ticker timer */
CLOCK_AttachClk(kFRO_HF_to_CTIMER0);
return CLOCK_GetFreq(kCLOCK_CTmier0);;
#else
/* Use 12 MHz clock us ticker timer */ /* Use 12 MHz clock us ticker timer */
CLOCK_AttachClk(kFRO_HF_to_CTIMER1); CLOCK_AttachClk(kFRO_HF_to_CTIMER1);
return CLOCK_GetFreq(kCLOCK_CTmier1);; return CLOCK_GetFreq(kCLOCK_CTmier1);;
#endif
} }
void sdio_clock_setup(void) void sdio_clock_setup(void)