1d6aed566Sopenharmony_ci/* 2d6aed566Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3d6aed566Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4d6aed566Sopenharmony_ci * you may not use this file except in compliance with the License. 5d6aed566Sopenharmony_ci * You may obtain a copy of the License at 6d6aed566Sopenharmony_ci * 7d6aed566Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8d6aed566Sopenharmony_ci * 9d6aed566Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10d6aed566Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11d6aed566Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12d6aed566Sopenharmony_ci * See the License for the specific language governing permissions and 13d6aed566Sopenharmony_ci * limitations under the License. 14d6aed566Sopenharmony_ci */ 15d6aed566Sopenharmony_ci 16d6aed566Sopenharmony_ci#ifndef _UART_H 17d6aed566Sopenharmony_ci#define _UART_H 18d6aed566Sopenharmony_ci 19d6aed566Sopenharmony_ci#include "los_compiler.h" 20d6aed566Sopenharmony_ci#include "los_event.h" 21d6aed566Sopenharmony_ci#include "los_reg.h" 22d6aed566Sopenharmony_ci#include "soc.h" 23d6aed566Sopenharmony_ci 24d6aed566Sopenharmony_ci#define RISCV_UART0_Rx_IRQn (RISCV_SYS_MAX_IRQ + 10) 25d6aed566Sopenharmony_ci 26d6aed566Sopenharmony_ci// the UART control registers. 27d6aed566Sopenharmony_ci// some have different meanings for read vs write. 28d6aed566Sopenharmony_ci// see http://byterunner.com/16550.html 29d6aed566Sopenharmony_ci#define UART_RHR_OFFSET 0 /* receive holding register (for input bytes) */ 30d6aed566Sopenharmony_ci#define UART_THR_OFFSET 0 /* transmit holding register (for output bytes) */ 31d6aed566Sopenharmony_ci#define UART_DLL_OFFSET 0 /* Divisor Latch (Least Significant Byte) Register (LSB) */ 32d6aed566Sopenharmony_ci#define UART_IER_OFFSET 1 /* interrupt enable register */ 33d6aed566Sopenharmony_ci#define UART_DLM_OFFSET 1 /* Divisor Latch (Most Significant Byte) Register (MSB) */ 34d6aed566Sopenharmony_ci#define UART_FCR_OFFSET 2 /* FIFO control register */ 35d6aed566Sopenharmony_ci#define UART_ISR_OFFSET 2 /* interrupt status register */ 36d6aed566Sopenharmony_ci#define UART_LCR_OFFSET 3 /* line control register */ 37d6aed566Sopenharmony_ci#define UART_LSR_OFFSET 5 /* line status register */ 38d6aed566Sopenharmony_ci 39d6aed566Sopenharmony_ci#define UART_LCR_8N1 0x03 /* useful defaults for LCR */ 40d6aed566Sopenharmony_ci#define UART_LCR_DLAB 0x80 /* Divisor latch access bit */ 41d6aed566Sopenharmony_ci 42d6aed566Sopenharmony_ci#define UART_IER_RDI 0x01 /* Enable receiver data interrupt */ 43d6aed566Sopenharmony_ci#define UART_IER_THRI 0x02 /* Enable Transmitter holding register int. */ 44d6aed566Sopenharmony_ci 45d6aed566Sopenharmony_ci#define UART_FCR_FIFO_EN 0x01 /* FIFO Enable */ 46d6aed566Sopenharmony_ci#define UART_FCR_RXSR 0x02 /* Receiver soft reset */ 47d6aed566Sopenharmony_ci#define UART_FCR_TXSR 0x04 /* Transmitter soft reset */ 48d6aed566Sopenharmony_ci 49d6aed566Sopenharmony_ci#define UART_LSR_DR 0x01 /* Receiver data ready */ 50d6aed566Sopenharmony_ci#define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */ 51d6aed566Sopenharmony_ci 52d6aed566Sopenharmony_ci#define ReadUartReg(reg) GET_UINT8((UART0_BASE) + (reg)) 53d6aed566Sopenharmony_ci#define WriteUartReg(reg, v) WRITE_UINT8((v), (UART0_BASE) + (reg)) 54d6aed566Sopenharmony_ci 55d6aed566Sopenharmony_ci#ifdef __cplusplus 56d6aed566Sopenharmony_ci#if __cplusplus 57d6aed566Sopenharmony_ciextern "C" { 58d6aed566Sopenharmony_ci#endif 59d6aed566Sopenharmony_ci#endif 60d6aed566Sopenharmony_ci 61d6aed566Sopenharmony_ciextern INT32 UartPutc(INT32 c, VOID *file); 62d6aed566Sopenharmony_ciextern INT32 UartOut(INT32 c, VOID *file); 63d6aed566Sopenharmony_ci 64d6aed566Sopenharmony_ciextern VOID UartInit(VOID); 65d6aed566Sopenharmony_ciextern INT32 UartGetc(VOID); 66d6aed566Sopenharmony_ciextern VOID Uart0RxIrqRegister(VOID); 67d6aed566Sopenharmony_ci 68d6aed566Sopenharmony_ciextern EVENT_CB_S g_shellInputEvent; 69d6aed566Sopenharmony_ci 70d6aed566Sopenharmony_ci#ifdef __cplusplus 71d6aed566Sopenharmony_ci#if __cplusplus 72d6aed566Sopenharmony_ci} 73d6aed566Sopenharmony_ci#endif /* __cplusplus */ 74d6aed566Sopenharmony_ci#endif /* __cplusplus */ 75d6aed566Sopenharmony_ci#endif 76