1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * 15 * Description: Provides hal uart \n 16 * 17 * History: \n 18 * 2023-02-17, Create file. \n 19 */ 20 #ifndef HAL_UART_H 21 #define HAL_UART_H 22 23 #include <stdint.h> 24 #include <stdbool.h> 25 #include "common_def.h" 26 #include "errcode.h" 27 #include "uart_porting.h" 28 29 #ifdef __cplusplus 30 #if __cplusplus 31 extern "C" { 32 #endif /* __cplusplus */ 33 #endif /* __cplusplus */ 34 35 /** 36 * @defgroup drivers_hal_uart_api UART API 37 * @ingroup drivers_hal_uart 38 * @{ 39 */ 40 41 /** 42 * @if Eng 43 * @brief Definition of UART pin configuration. 44 * @else 45 * @brief UART的PIN配置数据结构定义 46 * @endif 47 */ 48 typedef struct { 49 pin_t tx_pin; /*!< @if Eng Transmission PIN. 50 @else 发送引脚 @endif */ 51 pin_t rx_pin; /*!< @if Eng Reception PIN. 52 @else 接收引脚 @endif */ 53 pin_t cts_pin; /*!< @if Eng Clear to send PIN. 54 @else 发送就绪引脚 @endif */ 55 pin_t rts_pin; /*!< @if Eng Request to send PIN to use. 56 @else 接收就绪引脚 @endif */ 57 } hal_uart_pin_config_t; 58 59 /** 60 * @if Eng 61 * @brief Definition of UART data bit. 62 * @else 63 * @brief UART数据位定义 64 * @endif 65 */ 66 typedef enum hal_uart_data_bit { 67 UART_DATA_BIT_5, /*!< @if Eng UART data bit 5. 68 @else UART数据位为5-bit @endif */ 69 UART_DATA_BIT_6, /*!< @if Eng UART data bit 6. 70 @else UART数据位为6-bit @endif */ 71 UART_DATA_BIT_7, /*!< @if Eng UART data bit 7. 72 @else UART数据位为7-bit @endif */ 73 UART_DATA_BIT_8 /*!< @if Eng UART data bit 8. 74 @else UART数据位为8-bit @endif */ 75 } hal_uart_data_bit_t; 76 77 /** 78 * @if Eng 79 * @brief Definition of UART parity. 80 * @else 81 * @brief UART奇偶校验位定义 82 * @endif 83 */ 84 typedef enum hal_uart_parity { 85 UART_PARITY_NONE, /*!< @if Eng UART parity none. 86 @else UART无奇偶校验 @endif */ 87 UART_PARITY_ODD, /*!< @if Eng UART parity odd. 88 @else UART奇校验 @endif */ 89 UART_PARITY_EVEN /*!< @if Eng UART parity even. 90 @else UART偶校验 @endif */ 91 } hal_uart_parity_t; 92 93 /** 94 * @if Eng 95 * @brief Definition of UART stop bit. 96 * @else 97 * @brief UART停止位定义 98 * @endif 99 */ 100 typedef enum hal_uart_stop_bit { 101 UART_STOP_BIT_1, /*!< @if Eng UART stop bit 1. 102 @else UART停止位为1-bit @endif */ 103 UART_STOP_BIT_2 /*!< @if Eng UART stop bit 2. 104 @else UART停止位为2-bit @endif */ 105 } hal_uart_stop_bit_t; 106 107 /** 108 * @if Eng 109 * @brief Definition of Uart RX FIFO Level. 110 * @else 111 * @brief HAL层UART触发RX中断水线定义 112 * @endif 113 */ 114 typedef enum { 115 UART_FIFO_INT_RX_LEVEL_1_CHARACTER = 0, // only for uart v100 and v151 116 UART_FIFO_INT_RX_LEVEL_1_8 = 0, // only for uart v120 117 UART_FIFO_INT_RX_LEVEL_1_4 = 1, 118 UART_FIFO_INT_RX_LEVEL_1_2 = 2, 119 UART_FIFO_INT_RX_LEVEL_2_LESS_THAN_FULL = 3, // only for uart v100 and v151 120 UART_FIFO_INT_RX_LEVEL_3_4 = 3, 121 UART_FIFO_INT_RX_LEVEL_7_8 = 4, // only for uart v120 122 } uart_fifo_rx_int_lvl_t; 123 124 /** 125 * @if Eng 126 * @brief Definition of Uart TX FIFO Level. 127 * @else 128 * @brief HAL层UART触发TX中断水线定义 129 * @endif 130 */ 131 typedef enum { 132 UART_FIFO_INT_TX_LEVEL_EQ_0_CHARACTER = 0, // only for uart v100 and v151 133 UART_FIFO_INT_TX_LEVEL_1_8 = 0, // only for uart v120 134 UART_FIFO_INT_TX_LEVEL_EQ_2_CHARACTER = 1, // only for uart v100 and v151 135 UART_FIFO_INT_TX_LEVEL_1_4 = 2, 136 UART_FIFO_INT_TX_LEVEL_1_2 = 3, 137 UART_FIFO_INT_TX_LEVEL_3_4 = 4, // only for uart v120 138 UART_FIFO_INT_TX_LEVEL_7_8 = 5, // only for uart v120 139 } uart_fifo_tx_int_lvl_t; 140 141 /** 142 * @if Eng 143 * @brief Definition of the contorl ID of hal uart. 144 * @else 145 * @brief UART控制ID定义 146 * @endif 147 */ 148 typedef enum hal_uart_ctrl_id { 149 UART_CTRL_SET_ATTR = 0, /*!< @if Eng Set uart basic attribute. 150 @else 设置基础参数 @endif */ 151 UART_CTRL_GET_ATTR, /*!< @if Eng Get uart basic attribute. 152 @else 设置扩展参数 @endif */ 153 #if defined(CONFIG_UART_SUPPORT_TX_INT) 154 UART_CTRL_EN_TX_INT, /*!< @if Eng Enable the tx interrupt. 155 @else 使能TX中断 @endif */ 156 #endif 157 UART_CTRL_EN_RX_INT, /*!< @if Eng Enable the parity error interrupt. 158 @else 使能RX中断 @endif */ 159 UART_CTRL_EN_IDLE_INT, /*!< @if Eng Enable the RX IDLE interrupt. 160 @else 使能接收IDLE中断 @endif */ 161 UART_CTRL_EN_PARITY_ERR_INT, /*!< @if Eng Enable the frame error interrupt. 162 @else 使能奇偶校验错误中断 @endif */ 163 UART_CTRL_EN_FRAME_ERR_INT, /*!< @if Eng Enable the tx interrupt. 164 @else 使能帧错误中断 @endif */ 165 UART_CTRL_CHECK_TX_FIFO_FULL, /*!< @if Eng Check if tx fifo is full or not. 166 @else 判断TX FIFO是否为满 @endif */ 167 UART_CTRL_CHECK_TX_BUSY, /*!< @if Eng Check if tx data have been sended. 168 @else 判断是否正在发送数据 @endif */ 169 UART_CTRL_CHECK_RX_FIFO_EMPTY, /*!< @if Eng Check if rx fifo is full or not. 170 @else 判断RX FIFO是否为空 @endif */ 171 UART_CTRL_FIFO_ENABLE, /*!< @if Eng En(dis)able the fifo. 172 @else 使能FIFO @endif */ 173 UART_CTRL_SET_RX_FIFO_LEVEL, /*!< @if Eng Set rx fifo level. 174 @else 设置RX FIFO的Level @endif */ 175 UART_CTRL_SET_TX_FIFO_LEVEL, /*!< @if Eng Set tx fifo level. 176 @else 设置TX FIFO的Level @endif */ 177 UART_CTRL_GET_REG_ADDRS, /*!< @if Eng Get data register addr.for dma. 178 @else 获取寄存器地址 @endif */ 179 UART_CTRL_TX_DMA_PROCESS, /*!< @if Eng Process the DMA for TX. 180 @else 处理TX的DMA @endif */ 181 UART_CTRL_FLOW_CTRL, /*!< @if Eng Set flow ctrl. 182 @else 设置流控 @endif */ 183 UART_CTRL_RESTORE, /*!< @if Eng Restore the registers. 184 @else 恢复寄存器值 @endif */ 185 UART_CTRL_CHECK_UART_BUSY, /*!< @if Eng Check the uart is busy. 186 @else 查看uart bus状态是否在忙 @endif */ 187 UART_CTRL_GET_RX_FIFO_PASSNUM, /*!< @if Eng Get rx fifo level passnum. 188 @else 获取指定 uart 的 rx 水线可通过数目 @endif */ 189 #if defined(CONFIG_UART_SUPPORT_LPM) 190 UART_CTRL_SUSPEND, /*!< @if Eng Suspend the registers. 191 @else 挂起设备,保存寄存器值。 @endif */ 192 UART_CTRL_RESUME, /*!< @if Eng Restore the registers. 193 @else 恢复设备,重新配置寄存器值。 @endif */ 194 #endif /* CONFIG_UART_SUPPORT_LPM */ 195 #if defined(CONFIG_UART_SUPPORT_DMA) 196 UART_CTRL_GET_DMA_DATA_ADDR, 197 #endif 198 UART_CTRL_GET_RX_FIFO_THRESHOLD, /*!< @if Eng get uart rx fifo threshold. 199 @else 获取uart fifo的阈值 @endif */ 200 UART_CTRL_MAX, 201 UART_CTRL_ID_INVALID = 0xFF 202 } hal_uart_ctrl_id_t; 203 204 /** 205 * @if Eng 206 * @brief Definition of the event ID of hal uart. 207 * @else 208 * @brief HAL层UART事件ID的定义 209 * @endif 210 */ 211 typedef enum hal_uart_evt_id { 212 UART_EVT_RX_ISR = 1, /*!< @if Eng Rx isr triggered. 213 @else 接收中断触发 @endif */ 214 UART_EVT_TX_ISR, /*!< @if Eng Tx isr triggered. 215 @else TX中断被触发 @endif */ 216 UART_EVT_IDLE_ISR, /*!< @if Eng Rx timeout(idle) isr triggered. 217 @else IDLE中断被触发 @endif */ 218 UART_EVT_PARITY_ERR_ISR, /*!< @if Eng Parity error isr triggered. 219 @else 奇偶校验错误中断被触发 @endif */ 220 UART_EVT_FRAME_ERR_ISR, /*!< @if Eng Frame error isr triggered. 221 @else 帧错误中断被触发 @endif */ 222 UART_EVT_BREAK_ERR_ISR, /*!< @if Eng Break error isr triggered. 223 @else 线中止错误被触发 @endif */ 224 UART_EVT_OVERRUN_ERR_ISR, /*!< @if Eng Overrun error isr triggered. 225 @else 超载错误被触发 @endif */ 226 } hal_uart_evt_id_t; 227 228 /** 229 * @if Eng 230 * @brief Definition of the types of DMA. 231 * @else 232 * @brief DMA处理类型定义 233 * @endif 234 */ 235 typedef enum { 236 UART_DMA_PROCESS_PREPARE, /*!< @if Eng DMA process of prepare. 237 @else DMA准备处理 @endif */ 238 UART_DMA_PROCESS_FINISH, /*!< @if Eng DMA process of finish. 239 @else DMA完成处理 @endif */ 240 UART_DMA_PROCESS_INVALID = 0xFF 241 } hal_uart_dma_process_t; 242 243 /** 244 * @brief Definition of UART Flow Control. 245 */ 246 typedef enum { 247 UART_FLOW_CTRL_NONE = 0x0, 248 UART_FLOW_CTS = 0x1, 249 UART_FLOW_RTS = 0x2, 250 UART_FLOW_CTRL_RTS_CTS = UART_FLOW_CTS | UART_FLOW_RTS, 251 UART_FLOW_CTRL_SOFT = 0x4 252 } hal_uart_flow_ctrl_t; 253 254 /** 255 * @if Eng 256 * @brief Definition of UART attributes. 257 * @else 258 * @brief UART基础配置参数定义 259 * @endif 260 */ 261 typedef struct uart_attr { 262 uint32_t baud_rate; /*!< @if Eng UART baud rate 263 @else UART波特率 @endif */ 264 uint8_t data_bits; /*!< @if Eng UART data bits, For details see . 265 @else UART数据位,参考 @ref uart_data_bit_t @endif */ 266 uint8_t stop_bits; /*!< @if Eng UART stop bits, For details see . 267 @else UART数据位,参考 @ref uart_stop_bit_t @endif */ 268 uint8_t parity; /*!< @if Eng UART parity, For details see . 269 @else UART 奇偶校验位,参考 @ref uart_parity_t @endif */ 270 uint8_t flow_ctrl; /*!< @if Eng UART flow control, For details see @ref uart_flow_ctrl_t. 271 @else UART 流控,参考 @ref uart_flow_ctrl_t @endif */ 272 } hal_uart_attr_t; 273 274 /** 275 * @if Eng 276 * @brief Definition of UART extral attributes. 277 * @else 278 * @brief UART扩展配置参数定义 279 * @endif 280 */ 281 typedef struct uart_extra_attr { 282 bool tx_dma_enable; /*!< @if Eng false: tx not use dma @ref uapi_uart_write can be used. \n 283 true: tx use dma @ref uapi_uart_write_by_dma can be used. 284 @else false: TX没有使用DMA,使用 @ref uapi_uart_write 发送数据 \n 285 true: TX使用DMA,使用 @ref uapi_uart_write_by_dma 发送数据 @endif */ 286 uint8_t tx_int_threshold; /*!< @if Eng uart tx fifo level to trigger interrupt. 287 @else 触发中断的txfifo水线 @endif */ 288 bool rx_dma_enable; /*!< @if Eng false: rx not use dma @ref uapi_uart_write can be used. \n 289 true: rx use dma @ref uapi_uart_write_by_dma can be used. 290 @else false: RX没有使用DMA,使用 @ref uapi_uart_write 发送数据 \n 291 true: RX使用DMA,使用 @ref uapi_uart_write_by_dma 发送数据 @endif */ 292 uint8_t rx_int_threshold; /*!< @if Eng uart rx fifo level to trigger interrupt. 293 @else 触发中断的rxfifo水线 @endif */ 294 } hal_uart_extra_attr_t; 295 296 /** 297 * @if Eng 298 * @brief Callback of UART. 299 * @param [in] bus The uart bus. see @ref uart_bus_t 300 * @param [in] evt Event ID. 301 * @param [in] param Parameter of callback. 302 * @retval ERRCODE_SUCC Success. 303 * @retval Other Failure. For details, see @ref errcode_t 304 * @else 305 * @brief UART的回调函数 306 * @param [in] bus 串口号, 参考 @ref uart_bus_t 307 * @param [in] evt 事件ID. 308 * @param [in] param 传递到回调的参数 309 * @retval ERRCODE_SUCC 成功 310 * @retval Other 失败,参考 @ref errcode_t 311 * @endif 312 */ 313 typedef errcode_t (*hal_uart_callback_t)(uart_bus_t bus, hal_uart_evt_id_t evt, uintptr_t param); 314 315 /** 316 * @if Eng 317 * @brief Init device for hal uart. 318 * @param [in] bus The uart bus. see @ref uart_bus_t 319 * @param [in] callback Callback of the hal uart. 320 * @param [in] pins The PINs to use for UART TX, RX, RTS and CTS. 321 * @param [in] attr UART attributes. 322 * @param [in] flow_ctrl UART flow control type. 323 * @retval ERRCODE_SUCC Success. 324 * @retval Other Failure. For details, see @ref errcode_t 325 * @else 326 * @brief HAL层UART的初始化接口 327 * @param [in] bus 串口号, 参考 @ref uart_bus_t 328 * @param [in] callback 回调函数 329 * @param [in] pins UART的引脚,包括TX, RX, RTS 和 CTS 330 * @param [in] attr UART的基本配置参数 331 * @param [in] flow_ctrl UART流控类型 332 * @retval ERRCODE_SUCC 成功 333 * @retval Other 失败,参考 @ref errcode_t 334 * @endif 335 */ 336 typedef errcode_t (*hal_uart_init_t)(uart_bus_t bus, hal_uart_callback_t callback, const hal_uart_pin_config_t *pins, 337 const hal_uart_attr_t *attr, hal_uart_flow_ctrl_t flow_ctrl); 338 /** 339 * @if Eng 340 * @brief Deinit device for hal uart. 341 * @param [in] bus The uart bus. see @ref uart_bus_t 342 * @retval ERRCODE_SUCC Success. 343 * @retval Other Failure. For details, see @ref errcode_t 344 * @else 345 * @brief HAL层UART去初始化接口 346 * @param [in] bus 串口号, 参考 @ref uart_bus_t 347 * @retval ERRCODE_SUCC 成功 348 * @retval Other 失败,参考 @ref errcode_t 349 * @endif 350 */ 351 typedef errcode_t (*hal_uart_deinit_t)(uart_bus_t bus); 352 353 /** 354 * @if Eng 355 * @brief Control interface for hal uart. 356 * @param [in] bus The uart bus. see @ref uart_bus_t 357 * @param [in] id ID of the uart control. 358 * @param [in] param Parameter for callback. 359 * @retval ERRCODE_SUCC Success. 360 * @retval Other Failure. For details, see @ref errcode_t 361 * @else 362 * @brief HAL层UART控制接口 363 * @param [in] bus 串口号, 参考 @ref uart_bus_t 364 * @param [in] id UART控制请求ID 365 * @param [in] param 传递给控制回调的参数 366 * @retval ERRCODE_SUCC 成功 367 * @retval Other 失败,参考 @ref errcode_t 368 * @endif 369 */ 370 typedef errcode_t (*hal_uart_ctrl_t)(uart_bus_t bus, hal_uart_ctrl_id_t id, uintptr_t param); 371 372 /** 373 * @if Eng 374 * @brief Write interface for hal uart. 375 * @param [in] bus The uart bus. see @ref uart_bus_t 376 * @param [in] data Data buffer to write. 377 * @param [in] len Data len to write. 378 * @retval ERRCODE_SUCC Success. 379 * @retval Other Failure. For details, see @ref errcode_t 380 * @else 381 * @brief HAL层UART发送数据接口 382 * @param [in] bus 串口号, 参考 @ref uart_bus_t 383 * @param [in] data 要发送的数据Buffer 384 * @param [in] len 要发送的数据Buffer长度 385 * @retval ERRCODE_SUCC 成功 386 * @retval Other 失败,参考 @ref errcode_t 387 * @endif 388 */ 389 typedef errcode_t (*hal_uart_write_t)(uart_bus_t bus, const uint8_t *data, uint16_t len); 390 391 /** 392 * @if Eng 393 * @brief Read interface for hal uart. 394 * @param [in] bus The device pointer to manager the hal uart. 395 * @param [in] data Data buffer to read. 396 * @param [in] len Data len to read. 397 * @retval ERRCODE_SUCC Success. 398 * @retval Other Failure. For details, see @ref errcode_t 399 * @else 400 * @brief HAL层UART读取数据接口 401 * @param [in] bus 串口号, 参考 @ref uart_bus_t 402 * @param [in] data 用于存放读取数据的Buffer 403 * @param [in] len 用于存放读取数据的Buffer长度 404 * @retval ERRCODE_SUCC 成功 405 * @retval Other 失败,参考 @ref errcode_t 406 * @endif 407 */ 408 typedef int32_t (*hal_uart_read_t)(uart_bus_t bus, const uint8_t *data, uint16_t len); 409 410 /** 411 * @if Eng 412 * @brief Configuring DMA Transmission interface for hal uart. 413 * @param [in] bus The device pointer to manager the hal uart. 414 * @param [in] extra_attr High-level configuration of uart. see @ref hal_uart_extra_attr_t. 415 * @else 416 * @brief HAL层配置DMA传输接口 417 * @param [in] bus 串口号, 参考 @ref uart_bus_t 418 * @param [in] extra_attr UART的高级配置参数,参考 @ref hal_uart_extra_attr_t 。 419 * @endif 420 */ 421 typedef void (*hal_uart_dma_cfg_t)(uart_bus_t bus, const hal_uart_extra_attr_t *extra_attr); 422 423 /** 424 * @if Eng 425 * @brief Interface between uart driver and uart hal. 426 * @else 427 * @brief Driver层UART和HAL层UART的接口 428 * @endif 429 */ 430 typedef struct { 431 hal_uart_init_t init; /*!< @if Eng Init device interface. 432 @else HAL层UART的初始化接口 @endif */ 433 hal_uart_deinit_t deinit; /*!< @if Eng Deinit device interface. 434 @else HAL层UART去初始化接口 @endif */ 435 hal_uart_ctrl_t ctrl; /*!< @if Eng Control device interface. 436 @else HAL层UART控制接口 @endif */ 437 hal_uart_write_t write; /*!< @if Eng Write data interface. 438 @else HAL层UART发送数据接口 @endif */ 439 hal_uart_read_t read; /*!< @if Eng Read data interface. 440 @else HAL层UART读取数据接口 @endif */ 441 hal_uart_dma_cfg_t dma_cfg; /*!< @if Eng DMA config data interface. 442 @else HAL层配置DMA传输接口 @endif */ 443 } hal_uart_funcs_t; 444 445 /** 446 * @if Eng 447 * @brief Register @ref hal_uart_funcs_t into the g_hal_uarts_funcs. 448 * @param [in] bus The uart bus. see @ref uart_bus_t 449 * @param [in] funcs Interface between uart driver and uart hal. 450 * @retval ERRCODE_SUCC Success. 451 * @retval Other Failure. For details, see @ref errcode_t 452 * @else 453 * @brief 注册 @ref hal_uart_funcs_t 到 g_hal_uarts_funcs 454 * @param [in] bus 串口号, 参考 @ref uart_bus_t 455 * @param [in] funcs Driver层UART和HAL层UART的接口实例 456 * @retval ERRCODE_SUCC 成功 457 * @retval Other 失败,参考 @ref errcode_t 458 * @endif 459 */ 460 errcode_t hal_uart_register_funcs(uart_bus_t bus, hal_uart_funcs_t *funcs); 461 462 /** 463 * @if Eng 464 * @brief Unregister @ref hal_uart_funcs_t from the g_hal_uarts_funcs. 465 * @param [in] bus The uart bus. see @ref uart_bus_t 466 * @return ERRCODE_SUCC Success. 467 * @retval Other Failure. For details, see @ref errcode_t 468 * @else 469 * @brief 从g_hal_uarts_funcs注销 @ref hal_uart_funcs_t 470 * @param [in] bus 串口号, 参考 @ref uart_bus_t 471 * @return ERRCODE_SUCC 成功 472 * @retval Other 失败,参考 @ref errcode_t 473 * @endif 474 */ 475 errcode_t hal_uart_unregister_funcs(uart_bus_t bus); 476 477 /** 478 * @if Eng 479 * @brief Get the base address of sepecified UART. 480 * @param [in] bus The uart bus. see @ref uart_bus_t 481 * @return The base address of sepecified UART. 482 * @else 483 * @brief 获取指定UART的基地址。 484 * @param [in] bus 串口号, 参考 @ref uart_bus_t 。 485 * @return 指定UART的基地址。 486 * @endif 487 */ 488 uintptr_t hal_uart_base_addrs_get(uart_bus_t bus); 489 490 /** 491 * @if Eng 492 * @brief Init the UART which will set the base address of registers. 493 * @param [in] bus The uart bus. see @ref uart_bus_t 494 * @retval ERRCODE_SUCC Success. 495 * @retval Other Failure. For details, see @ref errcode_t 496 * @else 497 * @brief 初始化UART,设置寄存器的基地址 498 * @param [in] bus 串口号, 参考 @ref uart_bus_t 499 * @retval ERRCODE_SUCC 成功 500 * @retval Other 失败,参考 @ref errcode_t 501 * @endif 502 */ 503 errcode_t hal_uart_regs_init(uart_bus_t bus); 504 505 /** 506 * @if Eng 507 * @brief Get interface between uart driver and uart hal, see @ref hal_uart_funcs_t. 508 * @param [in] bus The uart bus. see @ref uart_bus_t 509 * @return Interface between uart driver and uart hal, see @ref hal_uart_funcs_t. 510 * @else 511 * @brief 获取Driver层UART和HAL层UART的接口实例,参考 @ref hal_uart_funcs_t. 512 * @param [in] bus 串口号, 参考 @ref uart_bus_t 513 * @return Driver层UART和HAL层UART的接口实例,参考 @ref hal_uart_funcs_t. 514 * @endif 515 */ 516 hal_uart_funcs_t *hal_uart_get_funcs(uart_bus_t bus); 517 518 /** 519 * @if Eng 520 * @brief UART set tx fifo level for triggering interrupt. 521 * @param bus The uart bus, see @ref uart_bus_t. 522 * @param level the fifo level value, see @ref uart_fifo_tx_int_lvl_t. 523 * @else 524 * @brief 设置uart触发中断的发送fifo阈值 525 * @param bus 串口号, 参考 @ref uart_bus_t 526 * @param level 触发中断的水线值 @ref uart_fifo_tx_int_lvl_t 527 * @endif 528 */ 529 errcode_t hal_uart_set_tx_fifo_int_level(uart_bus_t bus, uart_fifo_tx_int_lvl_t level); 530 531 /** 532 * @if Eng 533 * @brief UART set rx fifo level for triggering rx interrupt. 534 * @param bus The uart bus, see @ref uart_bus_t. 535 * @param level the fifo level value,see @ref uart_fifo_rx_int_lvl_t. 536 * @else 537 * @brief 设置uart触发接收中断的接收fifo阈值 538 * @param bus 串口号, 参考 @ref uart_bus_t 539 * @param level 触发中断的水线值 @ref uart_fifo_rx_int_lvl_t 。 540 * @endif 541 */ 542 errcode_t hal_uart_set_rx_fifo_int_level(uart_bus_t bus, uart_fifo_rx_int_lvl_t level); 543 544 /** 545 * @if Eng 546 * @brief Init device for hal uart. 547 * @param [in] bus The uart bus. see @ref uart_bus_t 548 * @param [in] callback Callback of the hal uart. 549 * @param [in] pins The PINs to use for UART TX, RX, RTS and CTS. 550 * @param [in] attr UART attributes. 551 * @param [in] flow_ctrl UART flow control type. 552 * @retval ERRCODE_SUCC Success. 553 * @retval Other Failure. For details, see @ref errcode_t 554 * @else 555 * @brief HAL层UART的初始化接口 556 * @param [in] bus 串口号, 参考 @ref uart_bus_t 557 * @param [in] callback 回调函数 558 * @param [in] pins UART的引脚,包括TX, RX, RTS 和 CTS 559 * @param [in] attr UART的基本配置参数 560 * @param [in] flow_ctrl UART流控类型 561 * @retval ERRCODE_SUCC 成功 562 * @retval Other 失败,参考 @ref errcode_t 563 * @endif 564 */ 565 errcode_t hal_uart_init(uart_bus_t bus, hal_uart_callback_t callback, const hal_uart_pin_config_t *pins, 566 const hal_uart_attr_t *attr, hal_uart_flow_ctrl_t flow_ctrl); 567 /** 568 * @if Eng 569 * @brief Deinit device for hal uart. 570 * @param [in] bus The uart bus. see @ref uart_bus_t 571 * @retval ERRCODE_SUCC Success. 572 * @retval Other Failure. For details, see @ref errcode_t 573 * @else 574 * @brief HAL层UART去初始化接口 575 * @param [in] bus 串口号, 参考 @ref uart_bus_t 576 * @retval ERRCODE_SUCC 成功 577 * @retval Other 失败,参考 @ref errcode_t 578 * @endif 579 */ 580 errcode_t hal_uart_deinit(uart_bus_t bus); 581 582 /** 583 * @if Eng 584 * @brief Control interface for hal uart. 585 * @param [in] bus The uart bus. see @ref uart_bus_t 586 * @param [in] id ID of the uart control. 587 * @param [in] param Parameter for callback. 588 * @retval ERRCODE_SUCC Success. 589 * @retval Other Failure. For details, see @ref errcode_t 590 * @else 591 * @brief HAL层UART控制接口 592 * @param [in] bus 串口号, 参考 @ref uart_bus_t 593 * @param [in] id UART控制请求ID 594 * @param [in] param 传递给控制回调的参数 595 * @retval ERRCODE_SUCC 成功 596 * @retval Other 失败,参考 @ref errcode_t 597 * @endif 598 */ 599 errcode_t hal_uart_ctrl(uart_bus_t bus, hal_uart_ctrl_id_t id, uintptr_t param); 600 601 /** 602 * @if Eng 603 * @brief Write interface for hal uart. 604 * @param [in] bus The uart bus. see @ref uart_bus_t 605 * @param [in] data Data buffer to write. 606 * @param [in] len Data len to write. 607 * @retval ERRCODE_SUCC Success. 608 * @retval Other Failure. For details, see @ref errcode_t 609 * @else 610 * @brief HAL层UART发送数据接口 611 * @param [in] bus 串口号, 参考 @ref uart_bus_t 612 * @param [in] data 要发送的数据Buffer 613 * @param [in] len 要发送的数据Buffer长度 614 * @retval ERRCODE_SUCC 成功 615 * @retval Other 失败,参考 @ref errcode_t 616 * @endif 617 */ 618 errcode_t hal_uart_write(uart_bus_t bus, const uint8_t *data, uint16_t len); 619 620 /** 621 * @if Eng 622 * @brief Read interface for hal uart. 623 * @param [in] bus The device pointer to manager the hal uart. 624 * @param [in] data Data buffer to read. 625 * @param [in] len Data len to read. 626 * @retval ERRCODE_SUCC Success. 627 * @retval Other Failure. For details, see @ref errcode_t 628 * @else 629 * @brief HAL层UART读取数据接口 630 * @param [in] bus 串口号, 参考 @ref uart_bus_t 631 * @param [in] data 用于存放读取数据的Buffer 632 * @param [in] len 用于存放读取数据的Buffer长度 633 * @retval ERRCODE_SUCC 成功 634 * @retval Other 失败,参考 @ref errcode_t 635 * @endif 636 */ 637 int32_t hal_uart_read(uart_bus_t bus, const uint8_t *data, uint16_t len); 638 639 /** 640 * @if Eng 641 * @brief Configuring DMA Transmission interface for hal uart. 642 * @param [in] bus The device pointer to manager the hal uart. 643 * @param [in] extra_attr High-level configuration of uart. see @ref hal_uart_extra_attr_t. 644 * @else 645 * @brief HAL层配置DMA传输接口 646 * @param [in] bus 串口号, 参考 @ref uart_bus_t 647 * @param [in] extra_attr UART的高级配置参数,参考 @ref hal_uart_extra_attr_t 。 648 * @endif 649 */ 650 void hal_uart_set_dma_config(uart_bus_t bus, const hal_uart_extra_attr_t *extra_attr); 651 652 /** 653 * @} 654 */ 655 656 #ifdef __cplusplus 657 #if __cplusplus 658 } 659 #endif /* __cplusplus */ 660 #endif /* __cplusplus */ 661 662 #endif 663