From 1930ce70a773816f77672795a5a509a989d441ea Mon Sep 17 00:00:00 2001 From: SimonLi Date: Fri, 9 Apr 2021 11:14:45 +0800 Subject: [PATCH] IssueNo: #I3EPPI Description: platform directory refactoring Sig: kernel Feature or Bugfix: Feature Binary Source: No --- arm_virt/liteos_a/config/board/Makefile | 2 + .../config/board/amba_pl011/amba_pl011.c | 203 ++++++++++++++++++ .../config/board/amba_pl011/amba_pl011.h | 68 ++++++ 3 files changed, 273 insertions(+) create mode 100755 arm_virt/liteos_a/config/board/amba_pl011/amba_pl011.c create mode 100644 arm_virt/liteos_a/config/board/amba_pl011/amba_pl011.h diff --git a/arm_virt/liteos_a/config/board/Makefile b/arm_virt/liteos_a/config/board/Makefile index 3e547b6..026e09f 100755 --- a/arm_virt/liteos_a/config/board/Makefile +++ b/arm_virt/liteos_a/config/board/Makefile @@ -17,6 +17,8 @@ MODULE_NAME := bsp_config LOCAL_SRCS += $(wildcard *.c) +LOCAL_SRCS += $(wildcard amba_pl011/*.c) + ifeq ($(LOSCFG_SHELL), y) LOCAL_SRCS += $(wildcard extcmd/*.c) endif diff --git a/arm_virt/liteos_a/config/board/amba_pl011/amba_pl011.c b/arm_virt/liteos_a/config/board/amba_pl011/amba_pl011.c new file mode 100755 index 0000000..7978ec1 --- /dev/null +++ b/arm_virt/liteos_a/config/board/amba_pl011/amba_pl011.c @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "amba_pl011.h" +#include "los_event.h" +#include "los_task_pri.h" + +EVENT_CB_S g_stShellEvent; + +CHAR g_inputCmd[CMD_LENGTH]; +INT32 g_inputIdx = 0; +#ifdef LOSCFG_QUICK_START +__attribute__ ((section(".data"))) UINT32 g_uart_fputc_en = 0; +#else +__attribute__ ((section(".data"))) UINT32 g_uart_fputc_en = 1; +#endif + +#define REG32(addr) ((volatile UINT32 *)(UINTPTR)(addr)) +#define UARTREG(base, reg) (*REG32((base) + (reg))) +#define UART_FR_TXFF (0x1U << 5) + +STATIC VOID UartPutcReg(UINTPTR base, CHAR c) +{ + /* Spin while fifo is full */ + while (UARTREG(base, UART_FR) & UART_FR_TXFF) {} + UARTREG(base, UART_DR) = c; +} + +STATIC INLINE UINTPTR uart_to_ptr(UINTPTR n) +{ + (VOID)n; + return UART_REG_BASE; +} + +INT32 uart_putc(INT32 port, CHAR c) +{ + UINTPTR base = uart_to_ptr((UINT32)port); + UartPutcReg(base, c); + return 1; +} + +CHAR uart_fputc(CHAR c, VOID *f) +{ + (VOID)f; + if (g_uart_fputc_en == 1) { + if (c == '\n') { + (VOID)uart_putc(0, '\r'); + } + return (uart_putc(0, (c))); + } else { + return 0; + } +} + +LITE_OS_SEC_BSS STATIC SPIN_LOCK_INIT(g_uartOutputSpin); + +STATIC VOID UartPutStr(UINTPTR base, const CHAR *s, UINT32 len) +{ + UINT32 i; + + for (i = 0; i < len; i++) { + if (*(s + i) == '\n') { + UartPutcReg(base, '\r'); + } + UartPutcReg(base, *(s + i)); + } +} + +UINT32 UartPutsReg(UINTPTR base, const CHAR *s, UINT32 len, BOOL isLock) +{ + UINT32 intSave; + + if (g_uart_fputc_en == 0) { + return 0; + } + + if (isLock) { + LOS_SpinLockSave(&g_uartOutputSpin, &intSave); + UartPutStr(base, s, len); + LOS_SpinUnlockRestore(&g_uartOutputSpin, intSave); + } else { + UartPutStr(base, s, len); + } + + return len; +} + +VOID UartPuts(const CHAR *s, UINT32 len, BOOL isLock) +{ + UINTPTR base = uart_to_ptr(0); + (VOID)UartPutsReg(base, s, len, isLock); +} + +INT32 uart_puts(const CHAR *s, UINTPTR len, VOID *state) +{ + (VOID)state; + UINTPTR i; + + for (i = 0; i < len; i++) { + if (*(s + i) != '\0') { + if (*(s + i) == '\n') { + (VOID)uart_fputc('\r', NULL); + } + + (VOID)uart_fputc(*(s + i), NULL); + } + } + + return (INT32)len; +} + +VOID uart_handler(VOID) +{ + CHAR c; + UINTPTR base = uart_to_ptr(0); + + c = UARTREG(base, UART_DR); + + switch (c) { + case '\r': + case '\n': + if (g_inputIdx < CMD_LENGTH - 1) { + g_inputCmd[g_inputIdx++] = '\0'; + LOS_EventWrite(&g_stShellEvent, 0x1); + (VOID)uart_putc(0, '\r'); + (VOID)uart_putc(0, '\n'); + } + break; + case 0x8: /* backspace */ + case 0x7f: /* delete */ + if (g_inputIdx > 0) { + g_inputIdx--; + (VOID)uart_putc(0, '\b'); + (VOID)uart_putc(0, ' '); + (VOID)uart_putc(0, '\b'); + } + break; + default: + if (g_inputIdx < CMD_LENGTH - 1) { + (VOID)uart_putc(0, c); + g_inputCmd[g_inputIdx++] = c; + } + } +} + +VOID uart_early_init(VOID) +{ + /* enable uart transmit */ + UARTREG(UART_REG_BASE, UART_CR) = (1 << 8) | (1 << 0); +} + +VOID uart_init(VOID) +{ + UINT32 ret; + + /* uart interrupt priority should be the highest in interrupt preemption mode */ + ret = LOS_HwiCreate(NUM_HAL_INTERRUPT_UART, 0, 0, (HWI_PROC_FUNC)uart_handler, NULL); + if (ret != LOS_OK) { + PRINT_ERR("%s,%d, uart interrupt created error:%x\n", __FUNCTION__, __LINE__, ret); + } else { + /* clear all irqs */ + UARTREG(UART_REG_BASE, UART_ICR) = 0x3ff; + + /* set fifo trigger level */ + UARTREG(UART_REG_BASE, UART_IFLS) = 0; + + /* enable rx interrupt */ + UARTREG(UART_REG_BASE, UART_IMSC) = (1 << 4 | 1 << 6); + + /* enable receive */ + UARTREG(UART_REG_BASE, UART_CR) |= (1 << 9); + + HalIrqUnmask(NUM_HAL_INTERRUPT_UART); + } +} diff --git a/arm_virt/liteos_a/config/board/amba_pl011/amba_pl011.h b/arm_virt/liteos_a/config/board/amba_pl011/amba_pl011.h new file mode 100644 index 0000000..6de19de --- /dev/null +++ b/arm_virt/liteos_a/config/board/amba_pl011/amba_pl011.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _AMBA_PL011_UART_H +#define _AMBA_PL011_UART_H + +#include "los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define UART_DR 0x0 /* data register */ +#define UART_RSR 0x04 +#define UART_FR 0x18 /* flag register */ +#define UART_CLR 0x44 /* interrupt clear register */ +#define UART_CR 0x30 /* control register */ +#define UART_IBRD 0x24 /* interge baudrate register */ +#define UART_FBRD 0x28 /* decimal baudrate register */ +#define UART_LCR_H 0x2C +#define UART_IFLS 0x34 /* fifo register */ +#define UART_IMSC 0x38 /* interrupt mask register */ +#define UART_RIS 0x3C /* base interrupt state register */ +#define UART_MIS 0x40 /* mask interrupt state register */ +#define UART_ICR 0x44 +#define UART_DMACR 0x48 /* DMA control register */ + +#define CMD_LENGTH 128 + +extern CHAR g_inputCmd[CMD_LENGTH]; +extern INT32 g_inputIdx; + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +#endif -- Gitee