From 3dceae52aab53d6ae4d3dae4e5b7370a299f51d1 Mon Sep 17 00:00:00 2001 From: bob_qu Date: Tue, 8 Mar 2022 20:17:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E7=8E=84=E9=93=81ck804e?= =?UTF-8?q?f=E6=9E=B6=E6=9E=84=E5=86=85=E6=A0=B8=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 合入原因:按照规划增加winnermicro w800芯片OH适配 需要新增CK804芯片架构支持代码 修改:在kernel/liteos_m、device/soc、device/board、vendor/hihope 仓下增加CK804芯片架构、芯片SDK、开发板和产品配置文件 影响:由于是新增芯片架构,与其他平台编译隔离,无副作用 Signed-off-by: bob_qu --- arch/BUILD.gn | 3 +- arch/csky/BUILD.gn | 6 +- arch/csky/ck804ef/gcc/BUILD.gn | 44 +++ arch/csky/ck804ef/gcc/los_arch_context.h | 108 ++++++ arch/csky/ck804ef/gcc/los_arch_interrupt.h | 371 +++++++++++++++++++++ arch/csky/ck804ef/gcc/los_arch_timer.h | 53 +++ arch/csky/ck804ef/gcc/los_context.c | 165 +++++++++ arch/csky/ck804ef/gcc/los_dispatch.S | 129 +++++++ arch/csky/ck804ef/gcc/los_interrupt.c | 173 ++++++++++ arch/csky/ck804ef/gcc/los_timer.c | 144 ++++++++ 10 files changed, 1194 insertions(+), 2 deletions(-) create mode 100755 arch/csky/ck804ef/gcc/BUILD.gn create mode 100755 arch/csky/ck804ef/gcc/los_arch_context.h create mode 100755 arch/csky/ck804ef/gcc/los_arch_interrupt.h create mode 100755 arch/csky/ck804ef/gcc/los_arch_timer.h create mode 100755 arch/csky/ck804ef/gcc/los_context.c create mode 100755 arch/csky/ck804ef/gcc/los_dispatch.S create mode 100755 arch/csky/ck804ef/gcc/los_interrupt.c create mode 100755 arch/csky/ck804ef/gcc/los_timer.c diff --git a/arch/BUILD.gn b/arch/BUILD.gn index f1bed67e..b027c2e1 100644 --- a/arch/BUILD.gn +++ b/arch/BUILD.gn @@ -39,7 +39,8 @@ module_group("arch") { "$board_cpu" == "cortex-m4" || "$board_cpu" == "cortex-m7" || "$board_cpu" == "cortex-m33" || "$board_cpu" == "cortex-m55") { modules += [ "arm" ] - } else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802") { + } else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802" || + "$board_cpu" == "ck804ef") { modules += [ "csky" ] } else if ("$board_cpu" == "") { if ("$board_arch" == "rv32imac" || "$board_arch" == "rv32imafdc") { diff --git a/arch/csky/BUILD.gn b/arch/csky/BUILD.gn index d0884ff5..caad3327 100644 --- a/arch/csky/BUILD.gn +++ b/arch/csky/BUILD.gn @@ -30,5 +30,9 @@ import("//kernel/liteos_m/liteos.gni") module_group("csky") { - modules = [ "v2/gcc" ] + if ("$board_cpu" == "ck804ef") { + modules = [ "$board_cpu/gcc" ] + } else { + modules = [ "v2/gcc" ] + } } diff --git a/arch/csky/ck804ef/gcc/BUILD.gn b/arch/csky/ck804ef/gcc/BUILD.gn new file mode 100755 index 00000000..2cddccf6 --- /dev/null +++ b/arch/csky/ck804ef/gcc/BUILD.gn @@ -0,0 +1,44 @@ +# 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. + +import("//kernel/liteos_m/liteos.gni") + +module_name = "arch" +kernel_module(module_name) { + sources = [ + "los_context.c", + "los_dispatch.S", + "los_interrupt.c", + "los_timer.c", + ] +} + +config("public") { + include_dirs = [ "." ] +} diff --git a/arch/csky/ck804ef/gcc/los_arch_context.h b/arch/csky/ck804ef/gcc/los_arch_context.h new file mode 100755 index 00000000..349ac82c --- /dev/null +++ b/arch/csky/ck804ef/gcc/los_arch_context.h @@ -0,0 +1,108 @@ +/* + * 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 _LOS_ARCH_CONTEXT_H +#define _LOS_ARCH_CONTEXT_H + +#include "los_config.h" +#include "los_compiler.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define OS_TRAP_STACK_SIZE 500 + +typedef struct TagTskContext { + UINT32 R0; + UINT32 R1; + UINT32 R2; + UINT32 R3; + UINT32 R4; + UINT32 R5; + UINT32 R6; + UINT32 R7; + UINT32 R8; + UINT32 R9; + UINT32 R10; + UINT32 R11; + UINT32 R12; + UINT32 R13; + UINT32 R15; + UINT32 R16; + UINT32 R17; + UINT32 R18; + UINT32 R19; + UINT32 R20; + UINT32 R21; + UINT32 R22; + UINT32 R23; + UINT32 R24; + UINT32 R25; + UINT32 R26; + UINT32 R27; + UINT32 R28; + UINT32 R29; + UINT32 R30; + UINT32 R31; + UINT32 VR0; + UINT32 VR1; + UINT32 VR2; + UINT32 VR3; + UINT32 VR4; + UINT32 VR5; + UINT32 VR6; + UINT32 VR7; + UINT32 VR8; + UINT32 VR9; + UINT32 VR10; + UINT32 VR11; + UINT32 VR12; + UINT32 VR13; + UINT32 VR14; + UINT32 VR15; + UINT32 EPSR; + UINT32 EPC; +} TaskContext; + +VOID HalStartToRun(VOID); +VOID HalTaskContextSwitch(VOID); +VOID HalIrqEndCheckNeedSched(VOID); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_ARCH_CONTEXT_H */ diff --git a/arch/csky/ck804ef/gcc/los_arch_interrupt.h b/arch/csky/ck804ef/gcc/los_arch_interrupt.h new file mode 100755 index 00000000..52db0682 --- /dev/null +++ b/arch/csky/ck804ef/gcc/los_arch_interrupt.h @@ -0,0 +1,371 @@ +/* + * 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 _LOS_ARCH_INTERRUPT_H +#define _LOS_ARCH_INTERRUPT_H + +#include "los_config.h" +#include "los_compiler.h" +#include "los_interrupt.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* * + * @ingroup los_arch_interrupt + * Maximum number of used hardware interrupts. + */ +#ifndef OS_HWI_MAX_NUM +#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT +#endif + +/* * + * @ingroup los_arch_interrupt + * Highest priority of a hardware interrupt. + */ +#ifndef OS_HWI_PRIO_HIGHEST +#define OS_HWI_PRIO_HIGHEST 0 +#endif + +/* * + * @ingroup los_arch_interrupt + * Lowest priority of a hardware interrupt. + */ +#ifndef OS_HWI_PRIO_LOWEST +#define OS_HWI_PRIO_LOWEST 3 +#endif + +/* * + * @ingroup los_arch_interrupt + * Define the type of a hardware interrupt vector table function. + */ +typedef VOID (**HWI_VECTOR_FUNC)(VOID); + +/* * + * @ingroup los_arch_interrupt + * Count of interrupts. + */ +extern volatile UINT32 g_intCount; + +/* * + * @ingroup los_arch_interrupt + * Count of C-sky system interrupt vector. + */ +#define OS_SYS_VECTOR_CNT 32 + +/* * + * @ingroup los_arch_interrupt + * Count of C-sky interrupt vector. + */ +#define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM) + +#define PSR_VEC_OFFSET 16U +#define VIC_REG_BASE 0xE000E100UL + +typedef struct { + UINT32 ISER[4U]; + UINT32 RESERVED0[12U]; + UINT32 IWER[4U]; + UINT32 RESERVED1[12U]; + UINT32 ICER[4U]; + UINT32 RESERVED2[12U]; + UINT32 IWDR[4U]; + UINT32 RESERVED3[12U]; + UINT32 ISPR[4U]; + UINT32 RESERVED4[12U]; + UINT32 ISSR[4U]; + UINT32 RESERVED5[12U]; + UINT32 ICPR[4U]; + UINT32 RESERVED6[12U]; + UINT32 ICSR[4U]; + UINT32 RESERVED7[12U]; + UINT32 IABR[4U]; + UINT32 RESERVED8[60U]; + UINT32 IPR[32U]; + UINT32 RESERVED9[480U]; + UINT32 ISR; + UINT32 IPTR; + UINT32 TSPEND; + UINT32 TSABR; + UINT32 TSPR; +} VIC_TYPE; + +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: Invalid interrupt number. + * + * Value: 0x02000900 + * + * Solution: Ensure that the interrupt number is valid. + */ +#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00) + +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: Null hardware interrupt handling function. + * + * Value: 0x02000901 + * + * Solution: Pass in a valid non-null hardware interrupt handling function. + */ +#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01) + +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation. + * + * Value: 0x02000902 + * + * Solution: Increase the configured maximum number of supported hardware interrupts. + */ +#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02) + +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: Insufficient memory for hardware interrupt initialization. + * + * Value: 0x02000903 + * + * Solution: Expand the configured memory. + */ +#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03) + +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: The interrupt has already been created. + * + * Value: 0x02000904 + * + * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. + */ +#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04) + +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: Invalid interrupt priority. + * + * Value: 0x02000905 + * + * Solution: Ensure that the interrupt priority is valid. + */ +#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05) + +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: Incorrect interrupt creation mode. + * + * Value: 0x02000906 + * + * Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST. + */ +#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06) + +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: The interrupt has already been created as a fast interrupt. + * + * Value: 0x02000907 + * + * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. + */ +#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07) + +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: Invalid interrupt number. + * + * Value: 0x02000900 + * + * Solution: Ensure that the interrupt number is valid. + */ +#define LOS_ERRNO_HWI_NUM_INVALID OS_ERRNO_HWI_NUM_INVALID + +#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) +/* * + * @ingroup los_arch_interrupt + * Set interrupt vector table. + */ +extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg); +#else +/* * + * @ingroup los_arch_interrupt + * Set interrupt vector table. + */ +extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector); +#endif + +/* * + * @ingroup los_arch_interrupt + * @brief: Hardware interrupt entry function. + * + * @par Description:This API is used as all hardware interrupt handling function entry. + * + * @attention:None. + * + * @param:None. + * + * @retval:None. + * @par Dependency:los_arch_interrupt.h: the header file that contains the API declaration. + * @see None. + */ +extern VOID HalInterrupt(VOID); + +/* * + * @ingroup los_arch_interrupt + * @brief: Get an interrupt number. + * + * @par Description:This API is used to get the current interrupt number. + * + * @attention:None. + * + * @param: None. + * + * @retval: Interrupt Indexes number. + * @par Dependency:los_arch_interrupt.h: the header file that contains the API declaration. + * @see None. + */ +extern UINT32 HalIntNumGet(VOID); + +/* * + * @ingroup los_arch_interrupt + * @brief: Default vector handling function. + * + * @par Description:This API is used to configure interrupt for null function. + * + * @attention:None. + * + * @param:None. + * + * @retval:None. + * @par Dependency:los_arch_interrupt.h: the header file that contains the API declaration. + * @see None. + */ +extern VOID HalHwiDefaultHandler(VOID); + +#define OS_EXC_IN_INIT 0 +#define OS_EXC_IN_TASK 1 +#define OS_EXC_IN_HWI 2 + +#define OS_VIC_INT_ENABLE_SIZE 0x4 +#define OS_VIC_INT_WAKER_SIZE 0x4 +#define OS_VIC_INT_ICER_SIZE 0x4 +#define OS_VIC_INT_ISPR_SIZE 0x4 +#define OS_VIC_INT_IABR_SIZE 0x4 +#define OS_VIC_INT_IPR_SIZE 0x4 +#define OS_VIC_INT_ISR_SIZE 0x4 +#define OS_VIC_INT_IPTR_SIZE 0x4 + +#define OS_EXC_FLAG_FAULTADDR_VALID 0x01 + +#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB + +/** + * @ingroup los_exc + * the struct of register files + * + * description: the register files that saved when exception triggered + * + * notes:the following register with prefix 'uw' correspond to the registers in the cpu data sheet. + */ +typedef struct TagExcContext { + UINT32 R0; + UINT32 R1; + UINT32 R2; + UINT32 R3; + UINT32 R4; + UINT32 R5; + UINT32 R6; + UINT32 R7; + UINT32 R8; + UINT32 R9; + UINT32 R10; + UINT32 R11; + UINT32 R12; + UINT32 R13; + UINT32 R14; + UINT32 R15; + UINT32 EPSR; + UINT32 EPC; +} EXC_CONTEXT_S; + +/* * + * @ingroup los_arch_interrupt + * @brief: Exception handler function. + * + * @par Description: + * This API is used to handle Exception. + * + * @attention:None. + * + * @param excBufAddr [IN] The address of stack pointer at which the error occurred. + * @param faultAddr [IN] The address at which the error occurred. + * + * @retval:None. + * @par Dependency:los_arch_interrupt.h: the header file that contains the API declaration. + * @see None. + */ +LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(EXC_CONTEXT_S *excBufAddr, UINT32 faultAddr); + +VOID IrqEntry(VOID); + +VOID HandleEntry(VOID); + +VOID HalHwiInit(VOID); + +/** + * @ingroup los_exc + * Exception information structure + * + * Description: Exception information saved when an exception is triggered on the Csky platform. + * + */ +typedef struct TagExcInfo { + UINT16 phase; + UINT16 type; + UINT32 faultAddr; + UINT32 thrdPid; + UINT16 nestCnt; + UINT16 reserved; + EXC_CONTEXT_S *context; +} ExcInfo; + +#define MAX_INT_INFO_SIZE (8 + 0x164) + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_ARCH_INTERRUPT_H */ diff --git a/arch/csky/ck804ef/gcc/los_arch_timer.h b/arch/csky/ck804ef/gcc/los_arch_timer.h new file mode 100755 index 00000000..2ebc4727 --- /dev/null +++ b/arch/csky/ck804ef/gcc/los_arch_timer.h @@ -0,0 +1,53 @@ +/* + * 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 _LOS_ARCH_TIMER_H +#define _LOS_ARCH_TIMER_H + +#include "los_config.h" +#include "los_compiler.h" +#include "los_timer.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +UINT32 HalTickStart(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_ARCH_TIMER_H */ diff --git a/arch/csky/ck804ef/gcc/los_context.c b/arch/csky/ck804ef/gcc/los_context.c new file mode 100755 index 00000000..1d1fae60 --- /dev/null +++ b/arch/csky/ck804ef/gcc/los_context.c @@ -0,0 +1,165 @@ +/* + * 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 +#include +#include "securec.h" +#include "los_arch_context.h" +#include "los_arch_interrupt.h" +#include "los_task.h" +#include "los_sched.h" +#include "los_interrupt.h" +#include "los_debug.h" +#include "los_context.h" + +STATIC volatile UINT32 g_sysNeedSched = FALSE; +#define ATTRIBUTE_ISR __attribute__((isr)) + +/* **************************************************************************** + Function : ArchInit + Description : arch init function + Input : None + Output : None + Return : None + **************************************************************************** */ +LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID) +{ +} + +/* **************************************************************************** + Function : ArchSysExit + Description : Task exit function + Input : None + Output : None + Return : None + **************************************************************************** */ +LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID) +{ + printf("\nArchSysExit\n"); + while (1) { + } +} + +/* **************************************************************************** + Function : ArchTskStackRegInit + Description : Task exit function + Input : None + Output : None + Return : None + **************************************************************************** */ +VOID ArchTskStackRegInit(TaskContext *context) +{ + context->R1 = 0x01010101L; + context->R2 = 0x02020202L; + context->R3 = 0x03030303L; + context->R4 = 0x04040404L; + context->R5 = 0x05050505L; + context->R6 = 0x06060606L; + context->R7 = 0x07070707L; + context->R8 = 0x08080808L; + context->R9 = 0x09090909L; + context->R10 = 0x10101010L; + context->R11 = 0x11111111L; + context->R12 = 0x12121212L; + context->R13 = 0x13131313L; + context->R15 = 0xfffffffeL; + context->R16 = 0x16161616L; + context->R17 = 0x17171717L; + context->R18 = 0x18181818L; + context->R19 = 0x19191919L; + context->R20 = 0x20202020L; + context->R21 = 0x21212121L; + context->R22 = 0x22222222L; + context->R23 = 0x23232323L; + context->R24 = 0x24242424L; + context->R25 = 0x25252525L; + context->R26 = 0x26262626L; + context->R27 = 0x27272727L; + context->R28 = 0x28282828L; + context->R29 = 0x29292929L; + context->R30 = 0x30303030L; + context->R31 = 0x31313131L; + context->VR0 = 0x12345678L; + context->VR1 = 0x12345678L; + context->VR2 = 0x12345678L; + context->VR3 = 0x12345678L; + context->VR4 = 0x12345678L; + context->VR5 = 0x12345678L; + context->VR6 = 0x12345678L; + context->VR7 = 0x12345678L; + context->VR8 = 0x12345678L; + context->VR9 = 0x12345678L; + context->VR10 = 0x12345678L; + context->VR11 = 0x12345678L; + context->VR12 = 0x12345678L; + context->VR13 = 0x12345678L; + context->VR14 = 0x12345678L; + context->VR15 = 0x12345678L; + context->EPSR = 0x80000340L; +} + +/* **************************************************************************** + Function : ArchTskStackInit + Description : Task stack initialization function + Input : taskID --- TaskID + stackSize --- Total size of the stack + topStack --- Top of task's stack + Output : None + Return : Context pointer + **************************************************************************** */ +LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack) +{ + TaskContext *context = NULL; + context = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext)); + context->R0 = taskID; + ArchTskStackRegInit(context); + context->EPC = (UINT32)OsTaskEntry; + return (VOID *)context; +} + +LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID) +{ + (VOID)LOS_IntLock(); + OsSchedStart(); + HalStartToRun(); + return LOS_OK; /* never return */ +} + + +VOID HalIrqEndCheckNeedSched(VOID) +{ +} +volatile int g_sysSchedCount = 0; +int *p_sysSchedCount = &g_sysSchedCount; +VOID ArchTaskSchedule(VOID) +{ + HalTaskContextSwitch(); +} + diff --git a/arch/csky/ck804ef/gcc/los_dispatch.S b/arch/csky/ck804ef/gcc/los_dispatch.S new file mode 100755 index 00000000..ef3ab99f --- /dev/null +++ b/arch/csky/ck804ef/gcc/los_dispatch.S @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2013-2020, 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 + +#define VIC_TSPDR 0XE000EC08 +#define OS_TASK_STATUS_RUNNING 0x0010 +#define VIC_TSPDR 0XE000EC08 + +.section .text +.align 2 +/******************************************************************** + * Functions: HalTaskContextSwitch + * + ********************************************************************/ +.global HalTaskContextSwitch +.type HalTaskContextSwitch, %function +HalTaskContextSwitch: + lrw r0, VIC_TSPDR + bgeni r1, 0 + stw r1, (r0) + nop + nop + nop + rts + +.type HalStartToRun, %function +.global HalStartToRun +HalStartToRun: + psrclr ie + lrw r4, g_losTask + ld.w r4, (r4) + ld.w sp, (r4) + + ldw r0, (sp, 192) + mtcr r0, epc + ldw r0, (sp, 188) + mtcr r0, epsr + + ldm r0-r13, (sp) + ldw r15, (sp, 56) + addi sp, 60 + ldm r16-r31, (sp) + addi sp, 64 + fldms vr0-vr15, (sp) + addi sp, 72 + + rte + +.align 2 +.type tspend_handler, %function +.global tspend_handler +tspend_handler: + + subi sp, 196 + stm r0-r13, (sp) + stw r15, (sp, 56) + addi r0, sp, 60 + stm r16-r31, (r0) + addi r0, 64 + fstms vr0-vr15, (r0) + mfcr r1, epsr + stw r1, (r0, 64) + mfcr r1, epc + stw r1, (r0, 68) + + jbsr OsSchedTaskSwitch + bez r0, ret_con + + lrw r2, g_losTask + ldw r0, (r2) + stw sp, (r0) + + lrw r3, g_losTask + 4 + ldw r0, (r3) + stw r0, (r2) + +#if 0 + lrw r4, g_sysSchedCount + ldw r3, (r4, 0) + subi r3, 1 + stw r3, (r4, 0) +#endif + + ldw sp, (r0) + + ret_con: + ldw r0, (sp, 192) + mtcr r0, epc + ldw r0, (sp, 188) + mtcr r0, epsr + + ldm r0-r13, (sp) + ldw r15, (sp, 56) + addi sp, 60 + ldm r16-r31, (sp) + addi sp, 64 + fldms vr0-vr15, (sp) + addi sp, 72 + + rte + diff --git a/arch/csky/ck804ef/gcc/los_interrupt.c b/arch/csky/ck804ef/gcc/los_interrupt.c new file mode 100755 index 00000000..6afbdea2 --- /dev/null +++ b/arch/csky/ck804ef/gcc/los_interrupt.c @@ -0,0 +1,173 @@ +/* + * 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 "los_interrupt.h" +#include +#include +#include "securec.h" +#include "los_context.h" +#include "los_arch_context.h" +#include "los_arch_interrupt.h" +#include "los_debug.h" +#include "los_hook.h" +#include "los_task.h" +#include "los_sched.h" +#include "los_memory.h" +#include "los_membox.h" + +#define INT_OFFSET 6 +#define PRI_OFF_PER_INT 8 +#define PRI_PER_REG 4 +#define PRI_OFF_IN_REG 6 +#define PRI_BITS 2 +#define PRI_HI 0 +#define PRI_LOW 7 +#define MASK_8_BITS 0xFF +#define MASK_32_BITS 0xFFFFFFFF +#define BYTES_OF_128_INT 4 + +#define OS_USER_HWI_MIN 0 +#define OS_USER_HWI_MAX (LOSCFG_PLATFORM_HWI_LIMIT - 1) +#define HWI_ALIGNSIZE 0x400 + +UINT32 volatile g_intCount = 0; +CHAR g_trapStackBase[OS_TRAP_STACK_SIZE]; + +STATIC VIC_TYPE *VIC_REG = (VIC_TYPE *)VIC_REG_BASE; + +UINT32 HwiNumValid(UINT32 num) +{ + return ((num) >= OS_USER_HWI_MIN) && ((num) <= OS_USER_HWI_MAX); +} + +UINT32 HalGetPsr(VOID) +{ + UINT32 intSave; + __asm__ volatile("mfcr %0, psr" : "=r" (intSave) : : "memory"); + return intSave; +} + +UINT32 HalSetVbr(UINT32 intSave) +{ + __asm__ volatile("mtcr %0, vbr" : : "r"(intSave) : "memory"); + return intSave; +} + +UINT32 ArchIntLock(VOID) +{ + UINT32 flags = __get_PSR(); + __disable_irq(); + return flags; +} + +UINT32 ArchIntUnLock(VOID) +{ + UINT32 flags = __get_PSR(); + __enable_irq(); + return flags; +} + +VOID ArchIntRestore(UINT32 intSave) +{ + __asm__ __volatile__( + "mtcr %0, psr \n" + : + :"r" (intSave) + :"memory" + ); +} + +UINT32 ArchIntLocked(VOID) +{ + UINT32 intSave; + __asm__ volatile("mfcr %0, psr" : "=r" (intSave) : : "memory"); + return !(intSave & (1 << INT_OFFSET)); +} + +UINT32 ArchIsIntActive(VOID) +{ + UINT32 intSave; + + intSave = LOS_IntLock(); + if (g_intCount > 0) { + LOS_IntRestore(intSave); + return 1; + } + LOS_IntRestore(intSave); + return 0; +} + +#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) + +/* * + * @ingroup los_hwi + * Set interrupt vector table. + */ +VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg) +{ + if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) { + csi_vic_set_vector(num, vector); + } +} +#else +/* * + * @ingroup los_hwi + * Set interrupt vector table. + */ +VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector) +{ + if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) { + csi_vic_set_vector(num, vector); + } +} +#endif + +int csi_kernel_intrpt_enter(void) +{ + UINT32 intSave; + intSave = LOS_IntLock(); + g_intCount++; + LOS_IntRestore(intSave); + return 0; +} +int csi_kernel_intrpt_exit(void) +{ + UINT32 intSave; + + intSave = LOS_IntLock(); + if (g_intCount > 0) { + g_intCount--; + } + HalIrqEndCheckNeedSched(); + LOS_IntRestore(intSave); + return 0; +} + diff --git a/arch/csky/ck804ef/gcc/los_timer.c b/arch/csky/ck804ef/gcc/los_timer.c new file mode 100755 index 00000000..f23ae50d --- /dev/null +++ b/arch/csky/ck804ef/gcc/los_timer.c @@ -0,0 +1,144 @@ +/* + * 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 "los_timer.h" +#include "los_config.h" +#include "los_tick.h" +#include "los_arch_interrupt.h" +#include "los_debug.h" + +typedef struct { + UINT32 CTRL; + UINT32 LOAD; + UINT32 VAL; + UINT32 CALIB; +} CORE_TIM_TYPE; + +#define CORE_TIM_BASE (0xE000E010UL) +#define SysTick ((CORE_TIM_TYPE *)CORE_TIM_BASE) + +STATIC VIC_TYPE *VIC_REG = (VIC_TYPE *)VIC_REG_BASE; + +#define CORETIM_ENABLE (1UL << 0) +#define CORETIM_INTMASK (1UL << 1) +#define CORETIM_SOURCE (1UL << 2) +#define CORETIM_MODE (1UL << 16) + +#define TIM_INT_NUM 25 + +STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler); +STATIC VOID SysTickReload(UINT64 nextResponseTime); +STATIC UINT64 SysTickCycleGet(UINT32 *period); +STATIC VOID SysTickLock(VOID); +STATIC VOID SysTickUnlock(VOID); + +STATIC ArchTickTimer g_archTickTimer = { + .freq = 0, + .irqNum = TIM_INT_NUM, + .init = SysTickStart, + .getCycle = SysTickCycleGet, + .reload = SysTickReload, + .lock = SysTickLock, + .unlock = SysTickUnlock, + .tickHandler = NULL, +}; + +/* **************************************************************************** +Function : HalTickStart +Description : Configure Tick Interrupt Start +Input : none +output : none +return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed +**************************************************************************** */ +STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler) +{ + ArchTickTimer *tick = &g_archTickTimer; + + tick->freq = OS_SYS_CLOCK; + + SysTick->LOAD = (OS_CYCLE_PER_TICK - 1); + SysTick->VAL = 0; + SysTick->CTRL |= (CORETIM_SOURCE | CORETIM_ENABLE | CORETIM_INTMASK); + + VIC_REG->IWER[0] = 0x1 << TIM_INT_NUM; + + return LOS_OK; +} + +STATIC VOID SysTickReload(UINT64 nextResponseTime) +{ + SysTick->CTRL &= ~CORETIM_ENABLE; + SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */ + SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ + SysTick->CTRL |= CORETIM_ENABLE; +} + +STATIC UINT64 SysTickCycleGet(UINT32 *period) +{ + UINT32 hwCycle; + UINT32 intSave = LOS_IntLock(); + *period = SysTick->LOAD; + hwCycle = *period - SysTick->VAL; + LOS_IntRestore(intSave); + return (UINT64)hwCycle; +} + +STATIC VOID SysTickLock(VOID) +{ + SysTick->CTRL &= ~CORETIM_ENABLE; +} + +STATIC VOID SysTickUnlock(VOID) +{ + SysTick->CTRL |= CORETIM_ENABLE; +} + +ArchTickTimer *ArchSysTickTimerGet(VOID) +{ + return &g_archTickTimer; +} + +VOID Wfi(VOID) +{ + __asm__ volatile("wait"); +} + +VOID Dsb(VOID) +{ + __asm__ volatile("sync" : : : "memory"); +} + +UINT32 ArchEnterSleep(VOID) +{ + Dsb(); + Wfi(); + return LOS_OK; +}