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

Function hpm_uart_control

bsp/hpmicro/libraries/drivers/drv_uart_v2.c:960–1102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

958#endif /* RT_SERIAL_USING_DMA */
959
960static rt_err_t hpm_uart_control(struct rt_serial_device *serial, int cmd, void *arg)
961{
962 RT_ASSERT(serial != RT_NULL);
963
964 rt_ubase_t ctrl_arg = (rt_ubase_t) arg;
965 uint8_t *tmp_buffer = NULL;
966 struct rt_serial_rx_fifo *rx_fifo = (struct rt_serial_rx_fifo*)serial->serial_rx;
967 struct rt_serial_tx_fifo *tx_fifo = (struct rt_serial_tx_fifo*)serial->serial_tx;
968 struct hpm_uart *uart = (struct hpm_uart *)serial->parent.user_data;
969
970 if(ctrl_arg & (RT_DEVICE_FLAG_RX_BLOCKING | RT_DEVICE_FLAG_RX_NON_BLOCKING))
971 {
972#ifdef RT_SERIAL_USING_DMA
973 if (uart->dma_flags & RT_DEVICE_FLAG_DMA_RX)
974 {
975 ctrl_arg = RT_DEVICE_FLAG_DMA_RX;
976 }
977 else
978#endif
979 {
980 ctrl_arg = RT_DEVICE_FLAG_INT_RX;
981 }
982 }
983 else if(ctrl_arg & (RT_DEVICE_FLAG_TX_BLOCKING | RT_DEVICE_FLAG_TX_NON_BLOCKING))
984 {
985#ifdef RT_SERIAL_USING_DMA
986 if (uart->dma_flags & RT_DEVICE_FLAG_DMA_TX)
987 {
988 ctrl_arg = RT_DEVICE_FLAG_DMA_TX;
989 }
990 else
991#endif
992 {
993 ctrl_arg = RT_DEVICE_FLAG_INT_TX;
994 }
995 }
996
997 switch (cmd) {
998 case RT_DEVICE_CTRL_CLR_INT:
999 if (ctrl_arg == RT_DEVICE_FLAG_INT_RX) {
1000 /* disable rx irq */
1001 uart_disable_irq(uart->uart_base, uart_intr_rx_data_avail_or_timeout);
1002 intc_m_disable_irq(uart->irq_num);
1003 }
1004 else if (ctrl_arg == RT_DEVICE_FLAG_INT_TX) {
1005 /* disable tx irq */
1006 uart_disable_irq(uart->uart_base, uart_intr_tx_slot_avail);
1007 intc_m_disable_irq(uart->irq_num);
1008 }
1009#ifdef RT_SERIAL_USING_DMA
1010 else if (ctrl_arg == RT_DEVICE_FLAG_DMA_TX) {
1011 dma_mgr_disable_chn_irq(&uart->tx_chn_ctx.resource, DMA_INTERRUPT_MASK_ALL);
1012 dma_abort_channel(uart->tx_chn_ctx.resource.base, uart->tx_chn_ctx.resource.channel);
1013 if (uart->tx_chn_ctx.ringbuf_ptr != RT_NULL) {
1014 rt_free(uart->tx_chn_ctx.ringbuf_ptr);
1015 uart->tx_chn_ctx.ringbuf_ptr = RT_NULL;
1016 }
1017 } else if (ctrl_arg == RT_DEVICE_FLAG_DMA_RX) {

Callers

nothing calls this directly

Calls 6

uart_enable_irqFunction · 0.85
rt_freeFunction · 0.85
rt_mallocFunction · 0.85
rt_ringbuffer_initFunction · 0.85
rt_ringbuffer_resetFunction · 0.85
hpm_uart_dma_configFunction · 0.85

Tested by

no test coverage detected