1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved. 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 #ifndef _UART_H 16 #define _UART_H 17 18 #include <stdbool.h> // standard boolean definitions 19 #include <stdint.h> // standard integer functions 20 #include "reg_stdio_uart.h" // uart register 21 #include "reg_ipc_mutex.h" 22 #include "chip.h" 23 24 #define IPC_MUTEX_UART_OUTPUT (IPC_MUTEX_ID_UART0_OUTPUT + UART_INDEX) 25 26 /// 3-part macro to function/variable/enum string 27 #define M2STR_P3_I(p0,p1,p2) p0##p1##p2 28 #define M2STR_P3(p0,p1,p2) M2STR_P3_I(p0, p1, p2) 29 30 /// Replace WEAK function in startup.S 31 #define stdio_uart_isr M2STR_P3(UART, UART_INDEX, _IRQHandler) 32 33 typedef void (*stdio_uart_rx_func_t)(void); 34 35 extern int stdio_uart_inited; 36 37 // function declarations. 38 void stdio_uart_init(void); 39 uint32_t stdio_uart_baud_get(void); 40 void stdio_uart_baud_set(uint32_t baud); 41 void stdio_uart_format_get(uint32_t *bits, uint32_t *parity, uint32_t *stop); 42 void stdio_uart_format_set(uint32_t bits, uint32_t parity, uint32_t stop); 43 void stdio_uart_putc(char ch); 44 char stdio_uart_getc(void); 45 bool stdio_uart_tstc(void); 46 int stdio_uart_get_rx_count(void); 47 void register_stdio_uart_rx_function(stdio_uart_rx_func_t func); 48 void stdio_uart_isr(void); 49 50 #endif //_UART_H 51