/***************************************************************************//** * @brief * Init LEUART. * * @details * This function will configure basic settings in order to operate in normal * asynchronous mode. Consider using LEUART_Reset() prior to this function if * state of configuration is not known, since only configuration settings * specified by @p init are set. * * Special control setup not covered by this function may be done either * before or after using this function (but normally before enabling) * by direct modification of the CTRL register. * * Notice that pins used by the LEUART module must be properly configured * by the user explicitly, in order for the LEUART to work as intended. * (When configuring pins, one should remember to consider the sequence of * configuration, in order to avoid unintended pulses/glitches on output * pins.) * * @note * Initializing requires synchronization into the low frequency domain. * If the same register is modified before a previous update has completed, * this function will stall until the previous synchronization has completed. * * @param[in] leuart * Pointer to LEUART peripheral register block. * * @param[in] init * Pointer to initialization structure used to configure basic async setup. ******************************************************************************/ void LEUART_Init(LEUART_TypeDef *leuart, LEUART_Init_TypeDef const *init) { /* Make sure the module exists on the selected chip */ EFM_ASSERT(LEUART_REF_VALID(leuart)); /* LF register about to be modified require sync. busy check */ LEUART_Sync(leuart, LEUART_SYNCBUSY_CMD); /* Ensure disabled while doing config */ leuart->CMD = LEUART_CMD_RXDIS | LEUART_CMD_TXDIS; /* Freeze registers to avoid stalling for LF synchronization */ LEUART_FreezeEnable(leuart, true); /* Configure databits and stopbits */ leuart->CTRL = (leuart->CTRL & ~(_LEUART_CTRL_PARITY_MASK | _LEUART_CTRL_STOPBITS_MASK)) | (uint32_t)(init->databits) | (uint32_t)(init->parity) | (uint32_t)(init->stopbits); /* Configure baudrate */ LEUART_BaudrateSet(leuart, init->refFreq, init->baudrate); /* Finally enable (as specified) */ leuart->CMD = (uint32_t)(init->enable); /* Unfreeze registers, pass new settings on to LEUART */ LEUART_FreezeEnable(leuart, false); }
/***************************************************************************//** * @brief * Reset LEUART to same state as after a HW reset. * * @param[in] leuart * Pointer to LEUART peripheral register block. ******************************************************************************/ void LEUART_Reset(LEUART_TypeDef *leuart) { /* Make sure the module exists on the selected chip */ EFM_ASSERT(LEUART_REF_VALID(leuart)); /* Freeze registers to avoid stalling for LF synchronization */ LEUART_FreezeEnable(leuart, true); /* Make sure disabled first, before resetting other registers */ leuart->CMD = LEUART_CMD_RXDIS | LEUART_CMD_TXDIS | LEUART_CMD_RXBLOCKDIS | LEUART_CMD_CLEARTX | LEUART_CMD_CLEARRX; leuart->CTRL = _LEUART_CTRL_RESETVALUE; leuart->CLKDIV = _LEUART_CLKDIV_RESETVALUE; leuart->STARTFRAME = _LEUART_STARTFRAME_RESETVALUE; leuart->SIGFRAME = _LEUART_SIGFRAME_RESETVALUE; leuart->IEN = _LEUART_IEN_RESETVALUE; leuart->IFC = _LEUART_IFC_MASK; leuart->PULSECTRL = _LEUART_PULSECTRL_RESETVALUE; #if defined(_LEUART_ROUTEPEN_MASK) leuart->ROUTEPEN = _LEUART_ROUTEPEN_RESETVALUE; leuart->ROUTELOC0 = _LEUART_ROUTELOC0_RESETVALUE; #else leuart->ROUTE = _LEUART_ROUTE_RESETVALUE; #endif /* Unfreeze registers, pass new settings on to LEUART */ LEUART_FreezeEnable(leuart, false); }
/***************************************************************************//** * @brief * Enable/disable LEUART receiver and/or transmitter. * * @details * Notice that this function does not do any configuration. Enabling should * normally be done after initialization is done (if not enabled as part * of init). * * @note * Enabling/disabling requires synchronization into the low frequency domain. * If the same register is modified before a previous update has completed, * this function will stall until the previous synchronization has completed. * * @param[in] leuart * Pointer to LEUART peripheral register block. * * @param[in] enable * Select status for receiver/transmitter. ******************************************************************************/ void LEUART_Enable(LEUART_TypeDef *leuart, LEUART_Enable_TypeDef enable) { uint32_t tmp; /* Make sure the module exists on the selected chip */ EFM_ASSERT(LEUART_REF_VALID(leuart)); /* Disable as specified */ tmp = ~((uint32_t)(enable)); tmp &= (_LEUART_CMD_RXEN_MASK | _LEUART_CMD_TXEN_MASK); tmp <<= 1; /* Enable as specified */ tmp |= (uint32_t)(enable); /* LF register about to be modified require sync. busy check */ LEUART_Sync(leuart, LEUART_SYNCBUSY_CMD); leuart->CMD = tmp; }