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 uart port template \n 16 * 17 * History: \n 18 * 2022-06-06, Create file. \n 19 */ 20 #ifndef UART_PORT_H 21 #define UART_PORT_H 22 #include <stdint.h> 23 #include "td_type.h" 24 #include "platform_core.h" 25 #include "std_def.h" 26 #include "debug_print.h" 27 28 #ifdef __cplusplus 29 #if __cplusplus 30 extern "C" { 31 #endif /* __cplusplus */ 32 #endif /* __cplusplus */ 33 34 /** 35 * @defgroup drivers_port_uart UART 36 * @ingroup drivers_port 37 * @{ 38 */ 39 40 #define UART_CLOCK_FRQ 24000000 41 42 #define UART_L_BAUDRATE 115200UL 43 #define UART_BUS_MAX_NUM UART_BUS_MAX_NUMBER 44 45 #define UART_SHADOW YES 46 #define UART_DLF_SIZE 6 47 #define UART_FIFO_ENABLED YES 48 49 /** 50 * @brief Base address list for all of the IPs. 51 */ 52 extern const uintptr_t g_uart_base_addrs[UART_BUS_MAX_NUM]; 53 54 /** 55 * @brief Register hal funcs objects into hal_uart module. 56 */ 57 void uart_port_register_hal_funcs(uart_bus_t bus); 58 59 uintptr_t uart_porting_base_addr_get(uart_bus_t bus); 60 /** 61 * @brief Get the bus clock of specified uart. 62 * @param [in] bus The uart bus. see @ref uart_bus_t 63 * @return The bus clock of specified uart. 64 */ 65 uint32_t uart_port_get_clock_value(uart_bus_t bus); 66 67 /** 68 * @brief set the bus clock of specified uart. 69 * @param [in] bus The uart bus. see @ref uart_bus_t 70 * @param [in] clock The bus clock of specified uart. 71 */ 72 void uart_port_set_clock_value(uart_bus_t bus, uint32_t clock); 73 74 /** 75 * @brief Config the pinmux of the uarts above. 76 */ 77 void uart_port_config_pinmux(uart_bus_t bus); 78 79 /** 80 * @brief Register the interrupt of uarts. 81 */ 82 void uart_port_register_irq(uart_bus_t bus); 83 84 /** 85 * @brief unRegister the interrupt of uarts. 86 */ 87 void uart_port_unregister_irq(uart_bus_t bus); 88 89 /** 90 * @brief Handler of UART0 IRQ. 91 */ 92 void irq_uart0_handler(void); 93 94 /** 95 * @brief Handler of UART1 IRQ. 96 */ 97 void irq_uart1_handler(void); 98 99 /** 100 * @brief Handler of UART2 IRQ. 101 */ 102 void irq_uart2_handler(void); 103 104 /** 105 * @brief Handler of UART3 IRQ. 106 */ 107 void irq_uart3_handler(void); 108 109 #if defined(CONFIG_UART_SUPPORT_DMA) 110 /** 111 * @brief Get the DMA destination handshaking select of uart transfer. 112 * @param [in] bus The uart bus. see @ref uart_bus_t 113 * @return The DMA destination handshaking select of uart transfer. 114 */ 115 uint8_t uart_port_get_dma_trans_dest_handshaking(uart_bus_t bus); 116 117 /** 118 * @brief Get the DMA source handshaking select of uart transfer. 119 * @param [in] bus The uart bus. see @ref uart_bus_t 120 * @return The DMA source handshaking select of uart transfer. 121 */ 122 uint8_t uart_port_get_dma_trans_src_handshaking(uart_bus_t bus); 123 #endif /* CONFIG_UART_SUPPORT_DMA */ 124 void hal_uart_clear_pending(uart_bus_t uart); 125 126 /** 127 * @brief Force trigger uart interrupt. 128 */ 129 void uart_port_set_pending_irq(uart_bus_t uart); 130 131 /** 132 * @brief uart lock. 133 * @param bus uart bus. 134 */ 135 uint32_t uart_porting_lock(uart_bus_t bus); 136 137 /** 138 * @brief uart unlock. 139 * @param bus uart bus. 140 * @param irq_sts irq status. 141 */ 142 void uart_porting_unlock(uart_bus_t bus, uint32_t irq_sts); 143 144 #ifdef LOG_SUPPORT 145 /** 146 * @brief hso uart init 147 * 148 * @param void 149 */ 150 void log_uart_port_init(void); 151 #endif 152 #ifdef ASIC_SMOKE_TEST 153 void uart2_init(uint32_t baud_rate); 154 #endif 155 156 /** 157 * @} 158 */ 159 160 #ifdef __cplusplus 161 #if __cplusplus 162 } 163 #endif /* __cplusplus */ 164 #endif /* __cplusplus */ 165 166 #endif