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 16 #ifndef TEST_SUITE_UART_H 17 #define TEST_SUITE_UART_H 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 #include "common_def.h" 22 #include "uart.h" 23 #include "test_suite_channel.h" 24 25 #ifdef __cplusplus 26 #if __cplusplus 27 extern "C" { 28 #endif /* __cplusplus */ 29 #endif /* __cplusplus */ 30 31 typedef enum { 32 TEST_USB_SERIAL, 33 TEST_CHIP_UART 34 } test_uart_mode_t; 35 36 /** 37 * @defgroup test_common_testsuite_uart UART 38 * @ingroup test_common_testsuite 39 * @{ 40 */ 41 #ifdef SLEM_CARKEY 42 #define TEST_SUITE_UART_BAUD_RATE 921600 43 #else 44 #define TEST_SUITE_UART_BAUD_RATE 115200 45 #endif 46 #define NEWLINE "\r\n" 47 48 /** 49 * @if Eng 50 * @brief Initialize test suite UART. 51 * @else 52 * @brief 初始化测试套件的UART。 53 * @endif 54 */ 55 void test_suite_uart_init(void); 56 57 /** 58 * @if Eng 59 * @brief Deinitialize test suite UART. 60 * @else 61 * @brief 去初始化测试套件的UART。 62 * @endif 63 */ 64 void test_suite_uart_deinit(void); 65 66 /** 67 * @if Eng 68 * @brief reset the baud rate of test suite UART. 69 * @else 70 * @brief 重置测试套件的UART的波特率。 71 * @endif 72 */ 73 void test_suite_uart_reset_baud_rate(void); 74 75 /** 76 * @if Eng 77 * @brief Sends a single char over the Test Suite UART. 78 * @param [in] c char to send. 79 * @else 80 * @brief 通过测试套件指定的UART发送单字节。 81 * @param [in] c 要发送的单个字节。 82 * @endif 83 */ 84 void test_suite_uart_send_char(char c); 85 86 /** 87 * @if Eng 88 * @brief Sends a string over the Test Suite UART. 89 * @param [in] str string to send. 90 * @else 91 * @brief 通过测试套件指定的UART发送字符串。 92 * @param [in] str 要发送的字符串。 93 * @endif 94 */ 95 void test_suite_uart_send(const char *str); 96 97 /** 98 * @if Eng 99 * @brief Sends a formatted char* out of the Test Suite UART. 100 * @param [in] str string to send. 101 * @else 102 * @brief 通过测试套件指定的UART格式化发送字符串。 103 * @param [in] str 要发送的字符串。 104 * @endif 105 */ 106 void test_suite_uart_sendf(const char *str, ...); 107 108 /** 109 * @if Eng 110 * @brief Sends a string over the Test Suite UART and adds "\r\n" at the end. 111 * @param [in] str string to send. 112 * @else 113 * @brief 通过测试套件指定的UART发送字符串并且换行。 114 * @param [in] str 要发送的字符串。 115 * @endif 116 */ 117 void test_suite_uart_send_line(const char *str); 118 119 /** 120 * @if Eng 121 * @brief Gets test suite uart functions. 122 * @return test suite uart functions address. 123 * @else 124 * @brief 获取测试套件uart功能函数。 125 * @return 测试套件uart功能函数接口地址。 126 * @endif 127 */ 128 test_suite_channel_funcs_t *test_suite_uart_funcs_get(void); 129 130 /** 131 * @if Eng 132 * @brief Testsuite uart callback function. 133 * @param [in] buffer The data buffer that uart receive. 134 * @param [in] length The data length. 135 * @param [in] error The uart error flag. 136 * @else 137 * @brief 测试套件uart回调函数。 138 * @param [in] buffer 测试套件uart接收数据地址。 139 * @param [in] length 测试套件uart接收数据长度。 140 * @param [in] error 测试套件uart接收错误标志。 141 * @endif 142 */ 143 void test_suite_uart_rx_callback(const void *buffer, uint16_t length, bool error); 144 145 #ifdef CONFIG_DRIVERS_USB_SERIAL_GADGET 146 void test_suite_switch_serial_mode(test_uart_mode_t mode); 147 #endif 148 /** 149 * @} 150 */ 151 152 #ifdef __cplusplus 153 #if __cplusplus 154 } 155 #endif /* __cplusplus */ 156 #endif /* __cplusplus */ 157 158 #endif 159