MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_hw_leuart_unit_init

Function rt_hw_leuart_unit_init

bsp/efm32/drv_leuart.c:787–973  ·  view source on GitHub ↗

/ * @brief * Initialize the specified LEUART unit * * @details * * @note * * @param[in] device * Pointer to device descriptor * * @param[in] unitNumber * Unit number * * @param[in] location * Pin location number * * @param[in] flag * Configuration flag * * @param[in] dmaChannel * DMA channel number for TX * * @param[in] console * Indicate if using as console * * @return * Pointer t

Source from the content-addressed store, hash-verified

785* Pointer to LEUART device
786******************************************************************************/
787static struct efm32_leuart_device_t *rt_hw_leuart_unit_init(
788 rt_device_t device,
789 rt_uint8_t unitNumber,
790 rt_uint8_t location,
791 rt_uint32_t flag,
792 rt_uint32_t dmaChannel,
793 rt_uint8_t config)
794{
795 struct efm32_leuart_device_t *leuart;
796 struct efm32_leuart_dma_mode_t *dma_mode;
797 DMA_CB_TypeDef *callback;
798 CMU_Clock_TypeDef leuartClock;
799 rt_uint32_t txDmaSelect;
800 GPIO_Port_TypeDef port_tx, port_rx, port_clk, port_cs;
801 rt_uint32_t pin_tx, pin_rx, pin_clk, pin_cs;
802 LEUART_Init_TypeDef init = LEUART_INIT_DEFAULT;
803 efm32_irq_hook_init_t hook;
804
805 do
806 {
807 /* Allocate device */
808 leuart = rt_malloc(sizeof(struct efm32_leuart_device_t));
809 if (leuart == RT_NULL)
810 {
811 leuart_debug("LEUART%d err: no mem\n", unitNumber);
812 break;
813 }
814 leuart->counter = 0;
815 leuart->unit = unitNumber;
816 leuart->state = config;
817 leuart->tx_mode = RT_NULL;
818 leuart->rx_mode = RT_NULL;
819
820 /* Allocate TX */
821 dma_mode = RT_NULL;
822 if (flag & RT_DEVICE_FLAG_DMA_TX)
823 {
824 leuart->tx_mode = dma_mode = rt_malloc(sizeof(struct efm32_leuart_dma_mode_t));
825 if (dma_mode == RT_NULL)
826 {
827 leuart_debug("LEUART%d err: no mem for DMA TX\n", unitNumber);
828 break;
829 }
830 dma_mode->dma_channel = dmaChannel;
831 }
832
833 /* Allocate RX */
834 if (flag & RT_DEVICE_FLAG_INT_RX)
835 {
836 leuart->rx_mode = rt_malloc(sizeof(struct efm32_leuart_int_mode_t));
837 if (leuart->rx_mode == RT_NULL)
838 {
839 leuart_debug("LEUART%d err: no mem for INT RX\n, unitNumber");
840 break;
841 }
842 }
843
844 /* Initialization */

Callers 1

rt_hw_leuart_initFunction · 0.85

Calls 9

rt_mallocFunction · 0.85
CMU_ClockDivSetFunction · 0.85
CMU_ClockEnableFunction · 0.85
GPIO_PinModeSetFunction · 0.85
efm32_irq_hook_registerFunction · 0.85
DMA_CfgChannelFunction · 0.85
DMA_CfgDescrFunction · 0.85
LEUART_InitFunction · 0.85
rt_freeFunction · 0.85

Tested by

no test coverage detected