/***************************************************************************//** * @brief * Reset LETIMER to the same state that it was in after a hardware reset. * * @note * The ROUTE register is NOT reset by this function to allow for * a centralized setup of this feature. * * @param[in] letimer * A pointer to the LETIMER peripheral register block. ******************************************************************************/ void LETIMER_Reset(LETIMER_TypeDef *letimer) { #if defined(_LETIMER_FREEZE_MASK) /* Freeze registers to avoid stalling for LF synchronization. */ LETIMER_FreezeEnable(letimer, true); #endif /* Make sure disabled first, before resetting other registers. */ letimer->CMD = LETIMER_CMD_STOP | LETIMER_CMD_CLEAR | LETIMER_CMD_CTO0 | LETIMER_CMD_CTO1; letimer->CTRL = _LETIMER_CTRL_RESETVALUE; letimer->COMP0 = _LETIMER_COMP0_RESETVALUE; letimer->COMP1 = _LETIMER_COMP1_RESETVALUE; letimer->REP0 = _LETIMER_REP0_RESETVALUE; letimer->REP1 = _LETIMER_REP1_RESETVALUE; letimer->IEN = _LETIMER_IEN_RESETVALUE; LETIMER_IntClear(letimer, _LETIMER_IF_MASK); #if defined(_LETIMER_FREEZE_MASK) /* Unfreeze registers and pass new settings to LETIMER. */ LETIMER_FreezeEnable(letimer, false); #endif #if defined(_LETIMER_SYNCBUSY_MASK) while (LETIMER0->SYNCBUSY & _LETIMER_SYNCBUSY_MASK) { } #endif #if defined (LETIMER_EN_EN) letimer->EN_CLR = LETIMER_EN_EN; #endif }
/* * Function Name: ADC_setup * Description: Configures ADC0 */ void LEUART_Setup(void) { /* Enabling the required clocks */ CMU_ClockEnable(cmuClock_LFB, true); //Enable the clock input to LETIMER CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO); //Selecting the ULFRCO as the source clock CMU_ClockEnable(cmuClock_LEUART0, true); //Enable the clock input to LETIMER /* Defining the LEUART1 initialization data */ LEUART_Init_TypeDef leuart0Init = { .enable = leuartEnable, // Activate data reception on LEUn_TX pin. .refFreq = 0, // Inherit the clock frequency from the LEUART clock source .baudrate = LEUART0_BAUD, // Baudrate = 9600 bps .databits = LEUART0_Databits, // Each LEUART frame contains 8 databits .parity = LEUART0_Parity, // No parity bits in use .stopbits = LEUART0_Stopbits, // Setting the number of stop bits in a frame to 2 bitperiods }; LEUART_Init(LEUART0, &leuart0Init); // Route LEUART1 TX,RX pin to DMA location 0 LEUART0->ROUTE = LEUART_ROUTE_TXPEN | LEUART_ROUTE_RXPEN | LEUART_ROUTE_LOCATION_LOC0; // Enable GPIO for LEUART1. TX is on D4 GPIO_PinModeSet(gpioPortD, 4, gpioModePushPull, 0); // Enable GPIO for LEUART1. RX is on D5 GPIO_PinModeSet(gpioPortD, 5, gpioModeInputPull, 0); // Pull PD15(CTS pin of BLE module) to GRND GPIO_PinModeSet(gpioPortD, 15, gpioModePushPull, 0); } /* *Function name: LETIMER0_IRQHandler *Description : Interrupt Service Routine for LETIMER. */ void LETIMER0_IRQHandler(void) { LETIMER_IntClear(LETIMER0, LETIMER_IF_UF); //Clear LETIMER0 underflow (UF) and COMP1 flag. DMA_ActivateBasic(DMA_CHANNEL_ADC, true, false, (void *)ADC_Buffer, (void *)&(ADC0->SINGLEDATA), ADC_SAMPLES - 1); ADC_Setup(); // ADC start ADC_Start(ADC0, adcStartSingle); unblockSleepMode(EM2); blockSleepMode(EM1); trfComplete=false; }