#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_clock.h"
#include "fsl_lptmr.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
/*!
* @brief Main function
*/
void LPTMR1_init(void);
uint32_t var;
int main(void)
{
char ch;
var=0;
/* Init board hardware. */
/* attach FRO 12M to FLEXCOMM4 (debug console) */
CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u);
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
/* attach TRACECLKDIV to TRACE */
CLOCK_SetClkDiv(kCLOCK_DivTraceClk, 2U);
CLOCK_AttachClk(kTRACE_DIV_to_TRACE);
BOARD_InitPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
LPTMR1_init();
PRINTF("hello world.\r\n");
while (1)
{
ch = GETCHAR();
PUTCHAR(ch);
}
}
const lptmr_config_t LPTMR1_config = {
.timerMode = kLPTMR_TimerModeTimeCounter,
.pinSelect = kLPTMR_PinSelectInput_0,
.pinPolarity = kLPTMR_PinPolarityActiveHigh,
.enableFreeRunning = false,
.bypassPrescaler = true,
.prescalerClockSource = kLPTMR_PrescalerClock_0,
.value = kLPTMR_Prescale_Glitch_3
};
#define LPTMR1_PERIPHERAL LPTMR1
#define LPTMR1_TICKS 100000
#define LPTMR1_IRQ_PRIORITY 00
void LPTMR1_init(void)
{
SYSCON->CLOCK_CTRL|=1<<3;
/* Initialize the LPTMR */
LPTMR_Init(LPTMR1_PERIPHERAL, &LPTMR1_config);
/* Set LPTMR period */
LPTMR_SetTimerPeriod(LPTMR1_PERIPHERAL, LPTMR1_TICKS);
/* Configure timer interrupt */
LPTMR_EnableInterrupts(LPTMR1_PERIPHERAL, kLPTMR_TimerInterruptEnable);
/* Interrupt vector LPTMR1_IRQn priority settings in the NVIC. */
NVIC_SetPriority(LPTMR1_IRQn, LPTMR1_IRQ_PRIORITY);
/* Enable interrupt LPTMR1_IRQn request in the NVIC. */
EnableIRQ(LPTMR1_IRQn);
/* Start the LPTMR timer */
LPTMR_StartTimer(LPTMR1_PERIPHERAL);
}
/* LPTMR1_IRQn interrupt handler */
void LPTMR1_IRQHandler(void) {
uint32_t intStatus;
/* Reading all interrupt flags of status register */
intStatus = LPTMR_GetStatusFlags(LPTMR1_PERIPHERAL);
LPTMR_ClearStatusFlags(LPTMR1_PERIPHERAL, intStatus);
/* Place your code here */
//lv_tick_inc(1);
var++;
/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F
Store immediate overlapping exception return operation might vector to incorrect interrupt. */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}