/ * @brief * Open LEUART device * * @details * * @note * * @param[in] dev * Pointer to device descriptor * * @param[in] oflag * Device open flag * * @return * Error code ******************************************************************************/
| 121 | * Error code |
| 122 | ******************************************************************************/ |
| 123 | static rt_err_t rt_leuart_open(rt_device_t dev, rt_uint16_t oflag) |
| 124 | { |
| 125 | RT_ASSERT(dev != RT_NULL); |
| 126 | |
| 127 | struct efm32_leuart_device_t *leuart; |
| 128 | |
| 129 | leuart = (struct efm32_leuart_device_t *)(dev->user_data); |
| 130 | |
| 131 | if (dev->flag & RT_DEVICE_FLAG_INT_RX) |
| 132 | { |
| 133 | IRQn_Type rxIrq; |
| 134 | |
| 135 | //if (leuart->state & LEUART_STATE_CONSOLE) |
| 136 | { /* Allocate new RX buffer */ |
| 137 | struct efm32_leuart_int_mode_t *int_mode; |
| 138 | |
| 139 | int_mode = (struct efm32_leuart_int_mode_t *)(leuart->rx_mode); |
| 140 | |
| 141 | if ((int_mode->data_ptr = rt_malloc(LEUART_RX_BUFFER_SIZE)) == RT_NULL) |
| 142 | { |
| 143 | leuart_debug("LEUART%d err: no mem for RX BUF\n", leuart->unit); |
| 144 | return -RT_ENOMEM; |
| 145 | } |
| 146 | rt_memset(int_mode->data_ptr, 0, LEUART_RX_BUFFER_SIZE); |
| 147 | int_mode->data_size = LEUART_RX_BUFFER_SIZE; |
| 148 | int_mode->read_index = 0; |
| 149 | int_mode->save_index = 0; |
| 150 | } |
| 151 | |
| 152 | /* Enable RX interrupt */ |
| 153 | leuart->leuart_device->IEN = LEUART_IEN_RXDATAV; |
| 154 | |
| 155 | /* Enable IRQ */ |
| 156 | switch (leuart->unit) |
| 157 | { |
| 158 | case 0: |
| 159 | rxIrq = LEUART0_IRQn; |
| 160 | break; |
| 161 | #if (LEUART_COUNT > 1) |
| 162 | case 1: |
| 163 | rxIrq = LEUART1_IRQn; |
| 164 | break; |
| 165 | #endif |
| 166 | } |
| 167 | if (oflag != RT_DEVICE_OFLAG_WRONLY) |
| 168 | { |
| 169 | NVIC_ClearPendingIRQ(rxIrq); |
| 170 | NVIC_SetPriority(rxIrq, EFM32_IRQ_PRI_DEFAULT); |
| 171 | NVIC_EnableIRQ(rxIrq); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /* Clear Flag */ |
| 176 | leuart->leuart_device->IFC = _LEUART_IFC_MASK; |
| 177 | |
| 178 | if ((dev->flag & RT_DEVICE_FLAG_DMA_TX) && (oflag != RT_DEVICE_OFLAG_RDONLY)) |
| 179 | { |
| 180 | /* DMA IRQ is enabled by DMA_Init() */ |
nothing calls this directly
no test coverage detected