28#if HAL_USE_GPT || defined(__DOXYGEN__)
42#if KINETIS_GPT_USE_PIT0 || defined(__DOXYGEN__)
50#if KINETIS_GPT_USE_PIT1 || defined(__DOXYGEN__)
58#if KINETIS_GPT_USE_PIT2 || defined(__DOXYGEN__)
66#if KINETIS_GPT_USE_PIT3 || defined(__DOXYGEN__)
74#if KINETIS_HAS_PIT_COMMON_IRQ
79static const uint32_t
tif_flags[] = { LPIT_MSR_TIF0(1), LPIT_MSR_TIF1(1), LPIT_MSR_TIF2(1), LPIT_MSR_TIF3(1) };
80static const uint32_t
mier_flags[] = { LPIT_MIER_TIE0(1), LPIT_MIER_TIE1(1), LPIT_MIER_TIE2(1), LPIT_MIER_TIE3(1) };
98 gptp->
channel->TFLG |= PIT_TFLGn_TIF;
101 if (gptp->
state == GPT_ONESHOT) {
102 gptp->
state = GPT_READY;
112#if !KINETIS_HAS_PIT_COMMON_IRQ
114#if KINETIS_GPT_USE_PIT0
127#if KINETIS_GPT_USE_PIT1
140#if KINETIS_GPT_USE_PIT2
153#if KINETIS_GPT_USE_PIT3
174#if KINETIS_GPT_USE_PIT0
176 if(PIT->MSR & LPIT_MSR_TIF0(1))
182#if KINETIS_GPT_USE_PIT1
184 if(PIT->MSR & LPIT_MSR_TIF1(1))
190#if KINETIS_GPT_USE_PIT2
192 if(PIT->MSR & LPIT_MSR_TIF2(1))
198#if KINETIS_GPT_USE_PIT3
200 if(PIT->MSR & LPIT_MSR_TIF3(1))
222#if KINETIS_GPT_USE_PIT0
229 gptObjectInit(&
GPTD1);
232#if KINETIS_GPT_USE_PIT1
239 gptObjectInit(&
GPTD2);
242#if KINETIS_GPT_USE_PIT2
249 gptObjectInit(&
GPTD3);
252#if KINETIS_GPT_USE_PIT3
259 gptObjectInit(&
GPTD4);
273 if (gptp->
state == GPT_STOP) {
276 PCC->CLKCFG[PCC_LPIT0_INDEX] |= PCC_CLKCFG_CGC(1);
278 PCC->CLKCFG[PCC_LPIT0_INDEX] = (PCC->CLKCFG[PCC_LPIT0_INDEX] & ~PCC_CLKCFG_PCS_MASK) | PCC_CLKCFG_PCS(6);
281 SIM->SCGC6 |= SIM_SCGC6_PIT;
283 gptp->
clock = KINETIS_SPLL_DIV2_FREQENCY;
285#if !KINETIS_HAS_PIT_COMMON_IRQ
287#if KINETIS_GPT_USE_PIT0
288 if (&
GPTD1 == gptp) {
289 nvicEnableVector(PITChannel0_IRQn, KINETIS_GPT_PIT0_IRQ_PRIORITY);
292#if KINETIS_GPT_USE_PIT1
293 if (&
GPTD2 == gptp) {
294 nvicEnableVector(PITChannel1_IRQn, KINETIS_GPT_PIT1_IRQ_PRIORITY);
297#if KINETIS_GPT_USE_PIT2
298 if (&
GPTD3 == gptp) {
299 nvicEnableVector(PITChannel2_IRQn, KINETIS_GPT_PIT2_IRQ_PRIORITY);
302#if KINETIS_GPT_USE_PIT3
303 if (&
GPTD4 == gptp) {
304 nvicEnableVector(PITChannel3_IRQn, KINETIS_GPT_PIT3_IRQ_PRIORITY);
309 nvicEnableVector(PIT_IRQn, KINETIS_GPT_PIT_IRQ_PRIORITY);
317 "invalid frequency");
321 PIT->MCR |= LPIT_MCR_M_CEN(1);
337 if (gptp->
state == GPT_READY) {
339 PCC->CLKCFG[PCC_LPIT0_INDEX] &= ~PCC_CLKCFG_CGC(1);
350 SIM->SCGC6 &= ~SIM_SCGC6_PIT;
356 gptp->
channel->TFLG |= PIT_TFLGn_TIF;
359#if !KINETIS_HAS_PIT_COMMON_IRQ
361#if KINETIS_GPT_USE_PIT0
362 if (&
GPTD1 == gptp) {
363 nvicDisableVector(PITChannel0_IRQn);
366#if KINETIS_GPT_USE_PIT1
367 if (&
GPTD2 == gptp) {
368 nvicDisableVector(PITChannel1_IRQn);
371#if KINETIS_GPT_USE_PIT2
372 if (&
GPTD3 == gptp) {
373 nvicDisableVector(PITChannel2_IRQn);
376#if KINETIS_GPT_USE_PIT3
377 if (&
GPTD4 == gptp) {
378 nvicDisableVector(PITChannel3_IRQn);
384 nvicDisableVector(PIT_IRQn);
403 gpt_lld_change_interval(gptp, interval);
408 PIT->CHANNEL[gptp->
channelIndex].TCTRL |= LPIT_TCTRL_T_EN(1);
411 gptp->
channel->TFLG |= PIT_TFLGn_TIF;
414 gpt_lld_change_interval(gptp, interval);
417 gptp->
channel->TCTRL |= PIT_TCTRLn_TIE | PIT_TCTRLn_TEN;
459 PIT->CHANNEL[gptp->
channelIndex].TCTRL = LPIT_TCTRL_T_EN(1);
472 channel->TFLG |= PIT_TFLGn_TIF;
478 channel->TCTRL = PIT_TCTRLn_TEN;
481 while (!(
channel->TFLG & PIT_TFLGn_TIF))
void gpt_lld_start(GPTDriver *gptp)
Configures and activates the GPT peripheral.
void gpt_lld_polled_delay(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in one shot mode and waits for completion.
static void gpt_lld_serve_interrupt(GPTDriver *gptp)
Shared IRQ handler.
void gpt_lld_stop(GPTDriver *gptp)
Deactivates the GPT peripheral.
static const uint32_t mier_flags[]
struct PIT_CHANNEL * channel
Channel structure in PIT registers block.
GPTDriver GPTD1
GPTD1 driver identifier.
static uint8_t active_channels
GPTDriver GPTD3
GPTD3 driver identifier.
void gpt_lld_start_timer(GPTDriver *gptp, gptcnt_t interval)
Starts the timer in continuous mode.
GPTDriver GPTD2
GPTD2 driver identifier.
OSAL_IRQ_HANDLER(KINETIS_PIT0_IRQ_VECTOR)
PIT1 interrupt handler.
const GPTConfig * config
Current configuration data.
uint32_t gptcnt_t
GPT counter type.
gptfreq_t frequency
Timer clock in Hz.
GPTDriver GPTD4
GPTD4 driver identifier.
static const uint32_t tif_flags[]
void gpt_lld_stop_timer(GPTDriver *gptp)
Stops the timer.
gptstate_t state
Driver state.
void gpt_lld_init(void)
Low level GPT driver initialization.
GPT_DRIVER_EXT_FIELDS uint32_t clock
Timer base clock.
gptcallback_t callback
Timer callback pointer.
int32_t channelIndex
Channel index.
Structure representing a GPT driver.