Description: refactor

Reviewed-by: likailong
This commit is contained in:
Caoruihong 2020-12-16 17:21:23 +08:00
parent b295e8e28f
commit 1405111aa9
269 changed files with 6962 additions and 9592 deletions

0
.gitee/ISSUE_TEMPLATE.zh-CN.md Executable file → Normal file
View File

0
.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md Executable file → Normal file
View File

0
.gitignore vendored Executable file → Normal file
View File

0
arch_spec.md Executable file → Normal file
View File

View File

0
components/bounds_checking_function/LICENSE Executable file → Normal file
View File

0
components/bounds_checking_function/README.OpenSource Executable file → Normal file
View File

0
components/bounds_checking_function/README.en.md Executable file → Normal file
View File

0
components/bounds_checking_function/README.md Executable file → Normal file
View File

0
components/bounds_checking_function/include/securec.h Executable file → Normal file
View File

View File

0
components/bounds_checking_function/src/fscanf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/fwscanf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/gets_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/input.inl Executable file → Normal file
View File

0
components/bounds_checking_function/src/memcpy_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/memmove_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/memset_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/output.inl Executable file → Normal file
View File

0
components/bounds_checking_function/src/scanf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/secinput.h Executable file → Normal file
View File

0
components/bounds_checking_function/src/securecutil.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/securecutil.h Executable file → Normal file
View File

View File

View File

View File

View File

View File

0
components/bounds_checking_function/src/snprintf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/sprintf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/sscanf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/strcat_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/strcpy_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/strncat_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/strncpy_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/strtok_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/swprintf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/swscanf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/vfscanf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/vfwscanf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/vscanf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/vsnprintf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/vsprintf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/vsscanf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/vswprintf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/vswscanf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/vwscanf_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/wcscat_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/wcscpy_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/wcsncat_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/wcsncpy_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/wcstok_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/wmemcpy_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/wmemmove_s.c Executable file → Normal file
View File

0
components/bounds_checking_function/src/wscanf_s.c Executable file → Normal file
View File

0
components/cppsupport/los_cppsupport.c Executable file → Normal file
View File

0
components/cppsupport/los_cppsupport.h Executable file → Normal file
View File

4
components/cpup/los_cpup.c Executable file → Normal file
View File

@ -30,6 +30,8 @@
*/ */
#include "los_cpup.h" #include "los_cpup.h"
#include "securec.h"
#include "los_memory.h"
#include "los_debug.h" #include "los_debug.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
@ -37,7 +39,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __cplusplus */ #endif /* __cplusplus */
#if (LOSCFG_BASE_CORE_CPUP == YES) #if (LOSCFG_BASE_CORE_CPUP == 1)
/** /**
* @ingroup los_cpup * @ingroup los_cpup

0
components/cpup/los_cpup.h Executable file → Normal file
View File

View File

@ -1,11 +0,0 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
import("//build/lite/config/component/lite_component.gni")
lite_component("kal") {
features = [
"cmsis",
"posix",
#"kal", # kal is not supported now.
]
}

View File

@ -1,15 +0,0 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
import("//build/lite/config/component/lite_component.gni")
static_library("cmsis") {
sources = [ "cmsis_liteos.c" ]
include_dirs = [
"//kernel/liteos_m/kal",
"//third_party/bounds_checking_function/include",
]
defines = [ "LITEOS_WIFI_IOT_VERSION" ]
cflags = [ "-Wno-error" ]
}

0
kal/cmsis/cmsis_liteos.c Executable file → Normal file
View File

80
kal/cmsis/cmsis_liteos2.c Executable file → Normal file
View File

@ -30,24 +30,21 @@
*/ */
#include "cmsis_os.h" #include "cmsis_os.h"
#include "los_typedef.h"
#include "los_printf.h"
#include "los_event.h" #include "los_event.h"
#include "los_membox.h" #include "los_membox.h"
#include "los_memory.h" #include "los_memory.h"
#include "los_hwi.h" #include "los_interrupt.h"
#include "los_mux.h"
#include "los_queue.h"
#include "los_sem.h"
#include "los_swtmr.h"
#include "los_task.h"
#include "kal.h"
#include "los_debug.h"
#include "los_mux_pri.h"
#include "los_queue_pri.h"
#include "los_sem_pri.h"
#include "los_swtmr_pri.h"
#include "los_sys_pri.h"
#include "los_task_pri.h"
#include "los_tick_pri.h"
#include "string.h" #include "string.h"
#include "securec.h" #include "securec.h"
//#include "system_config.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
@ -659,7 +656,7 @@ uint32_t osThreadGetCount(void)
// ==== Generic Wait Functions ==== // ==== Generic Wait Functions ====
WEAK UINT32 LOS_HalDelay(UINT32 ticks) WEAK UINT32 HalDelay(UINT32 ticks)
{ {
UNUSED(ticks); UNUSED(ticks);
return LOS_ERRNO_TSK_DELAY_IN_INT; return LOS_ERRNO_TSK_DELAY_IN_INT;
@ -668,12 +665,12 @@ WEAK UINT32 LOS_HalDelay(UINT32 ticks)
osStatus_t osDelay(uint32_t ticks) osStatus_t osDelay(uint32_t ticks)
{ {
UINT32 uwRet = 0; UINT32 uwRet;
if (ticks == 0) { if (ticks == 0) {
return osOK; return osOK;
} }
if (osKernelGetState() != osKernelRunning) { if (osKernelGetState() != osKernelRunning) {
uwRet = LOS_HalDelay(ticks); uwRet = HalDelay(ticks);
} else { } else {
uwRet = LOS_TaskDelay(ticks); uwRet = LOS_TaskDelay(ticks);
} }
@ -706,41 +703,14 @@ osStatus_t osDelayUntil(uint32_t ticks)
} }
// ==== Timer Management Functions ==== // ==== Timer Management Functions ====
#if (LOSCFG_BASE_CORE_SWTMR == YES) #if (LOSCFG_BASE_CORE_SWTMR == 1)
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
#if 0
osTimerId_t osTimerExtNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr,
os_timer_rouses_type ucRouses, os_timer_align_type ucSensitive)
{
UNUSED(attr);
UINT16 usSwTmrID;
UINT8 mode;
if ((OS_INT_ACTIVE) || (NULL == func) || ((osTimerOnce != type) && (osTimerPeriodic != type))) {
return (osTimerId_t)NULL;
}
if (osTimerOnce == type) {
mode = LOS_SWTMR_MODE_NO_SELFDELETE;
} else {
mode = LOS_SWTMR_MODE_PERIOD;
}
if (LOS_OK != LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &usSwTmrID, (UINT32)(UINTPTR)argument, ucRouses, ucSensitive)) {
return (osTimerId_t)NULL;
}
return (osTimerId_t)OS_SWT_FROM_SID(usSwTmrID);
}
#endif
#endif
#if 1
osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)
{ {
UNUSED(attr); UNUSED(attr);
UINT16 usSwTmrID; UINT16 usSwTmrID;
UINT8 mode; UINT8 mode;
if ((OS_INT_ACTIVE) || (NULL == func) || ((osTimerOnce != type) && (osTimerPeriodic != type))) { if ((NULL == func) || ((osTimerOnce != type) && (osTimerPeriodic != type))) {
return (osTimerId_t)NULL; return (osTimerId_t)NULL;
} }
@ -749,7 +719,7 @@ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, c
} else { } else {
mode = LOS_SWTMR_MODE_PERIOD; mode = LOS_SWTMR_MODE_PERIOD;
} }
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES) #if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
if (LOS_OK != LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &usSwTmrID, (UINT32)(UINTPTR)argument, if (LOS_OK != LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &usSwTmrID, (UINT32)(UINTPTR)argument,
osTimerRousesAllow, osTimerAlignIgnore)) { osTimerRousesAllow, osTimerAlignIgnore)) {
return (osTimerId_t)NULL; return (osTimerId_t)NULL;
@ -762,7 +732,7 @@ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, c
return (osTimerId_t)OS_SWT_FROM_SID(usSwTmrID); return (osTimerId_t)OS_SWT_FROM_SID(usSwTmrID);
} }
#endif
osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks) osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
{ {
UINT32 uwRet; UINT32 uwRet;
@ -772,9 +742,11 @@ osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
return osErrorParameter; return osErrorParameter;
} }
UINTPTR intSave = LOS_IntLock();
pstSwtmr = (SWTMR_CTRL_S *)timer_id; pstSwtmr = (SWTMR_CTRL_S *)timer_id;
pstSwtmr->uwInterval = ticks; pstSwtmr->uwInterval = ticks;
uwRet = LOS_SwtmrStart(pstSwtmr->usTimerID); uwRet = LOS_SwtmrStart(pstSwtmr->usTimerID);
LOS_IntRestore(intSave);
if (LOS_OK == uwRet) { if (LOS_OK == uwRet) {
return osOK; return osOK;
} else if (LOS_ERRNO_SWTMR_ID_INVALID == uwRet) { } else if (LOS_ERRNO_SWTMR_ID_INVALID == uwRet) {
@ -797,10 +769,6 @@ osStatus_t osTimerStop(osTimerId_t timer_id)
UINT32 uwRet; UINT32 uwRet;
SWTMR_CTRL_S *pstSwtmr = (SWTMR_CTRL_S *)timer_id; SWTMR_CTRL_S *pstSwtmr = (SWTMR_CTRL_S *)timer_id;
if (OS_INT_ACTIVE) {
return osErrorISR;
}
if (NULL == pstSwtmr) { if (NULL == pstSwtmr) {
return osErrorParameter; return osErrorParameter;
} }
@ -818,7 +786,7 @@ osStatus_t osTimerStop(osTimerId_t timer_id)
uint32_t osTimerIsRunning(osTimerId_t timer_id) uint32_t osTimerIsRunning(osTimerId_t timer_id)
{ {
if ((OS_INT_ACTIVE) || (NULL == timer_id)) { if (NULL == timer_id) {
return 0; return 0;
} }
@ -831,10 +799,6 @@ osStatus_t osTimerDelete(osTimerId_t timer_id)
UINT32 uwRet; UINT32 uwRet;
SWTMR_CTRL_S *pstSwtmr = (SWTMR_CTRL_S *)timer_id; SWTMR_CTRL_S *pstSwtmr = (SWTMR_CTRL_S *)timer_id;
if (OS_INT_ACTIVE) {
return osErrorISR;
}
if (NULL == pstSwtmr) { if (NULL == pstSwtmr) {
return osErrorParameter; return osErrorParameter;
} }
@ -1014,7 +978,7 @@ osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id)
} }
// ==== Mutex Management Functions ==== // ==== Mutex Management Functions ====
#if (LOSCFG_BASE_IPC_MUX == YES) #if (LOSCFG_BASE_IPC_MUX == 1)
osMutexId_t osMutexNew(const osMutexAttr_t *attr) osMutexId_t osMutexNew(const osMutexAttr_t *attr)
{ {
UINT32 uwRet; UINT32 uwRet;
@ -1122,7 +1086,7 @@ osStatus_t osMutexDelete(osMutexId_t mutex_id)
#endif #endif
// ==== Semaphore Management Functions ==== // ==== Semaphore Management Functions ====
#if (LOSCFG_BASE_IPC_SEM == YES) #if (LOSCFG_BASE_IPC_SEM == 1)
osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)
{ {
@ -1241,7 +1205,7 @@ osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
// ==== Message Queue Management Functions ==== // ==== Message Queue Management Functions ====
#if (LOSCFG_BASE_IPC_QUEUE == YES) #if (LOSCFG_BASE_IPC_QUEUE == 1)
osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr) osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr)
{ {
UINT32 uwQueueID; UINT32 uwQueueID;

4
kal/cmsis/cmsis_os.h Executable file → Normal file
View File

@ -29,6 +29,9 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef CMSIS_OS_H_
#define CMSIS_OS_H_
#include "los_config.h" #include "los_config.h"
#if (CMSIS_OS_VER == 1) #if (CMSIS_OS_VER == 1)
@ -37,3 +40,4 @@
#include "cmsis_os2.h" #include "cmsis_os2.h"
#endif #endif
#endif /* CMSIS_OS_H_ */

8
kal/cmsis/cmsis_os2.h Executable file → Normal file
View File

@ -656,8 +656,8 @@ uint32_t osKernelGetSysTimerFreq (void);
/** /**
* @brief Creates an active thread. * @brief Creates an active thread.
* *
* The priority ranges from 9 to 38. Select a proper priority as required. * The task priority ranges from 9 (highest priority) to 38 (lowest priority). {@code LOSCFG_BASE_CORE_TSK_LIMIT} declared in target_config.h specifies the
* The maximum of tasks is LOSCFG_BASE_CORE_TSK_LIMIT(LOSCFG_BASE_CORE_TSK_LIMIT is defined in the traget_config.h). maximum number of tasks running in this system.
* @param func Indicates the entry of the thread callback function. * @param func Indicates the entry of the thread callback function.
* @param argument Indicates the pointer to the argument passed to the thread. * @param argument Indicates the pointer to the argument passed to the thread.
* @param attr Indicates the thread attributes. * @param attr Indicates the thread attributes.
@ -956,7 +956,7 @@ uint32_t osEventFlagsGet (osEventFlagsId_t ef_id);
/** /**
* @brief Waits for event flags to trigger. * @brief Waits for event flags to trigger.
* *
* When the specified flag of the event is set, the function returns immediately. Otherwise, the thread is blocked. * This function is blocked if the specified event flags are not set via {@code flags}.
* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew. * @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
* @param flags Indicates the event flags to trigger. * @param flags Indicates the event flags to trigger.
* @param options Indicates the configuration of the event flags to trigger. * @param options Indicates the configuration of the event flags to trigger.
@ -1054,7 +1054,7 @@ const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id);
* @brief Acquires a token of a semaphore object. * @brief Acquires a token of a semaphore object.
* *
* @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew. * @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew.
* @param timeout Indicates the timeout duration. This parameter is the number of ticks. * @param timeout Indicates the timeout duration, in ticks.
* @return Returns the CMSIS-RTOS running result. * @return Returns the CMSIS-RTOS running result.
* @since 1.0 * @since 1.0
* @version 1.0 * @version 1.0

6
kal/cmsis/hos_cmsis_adp.h Executable file → Normal file
View File

@ -33,7 +33,7 @@
#define HOS_CMSIS_ADP_H #define HOS_CMSIS_ADP_H
#include "cmsis_os.h" #include "cmsis_os.h"
#include "ohos_types.h" #include "los_compiler.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
@ -43,8 +43,8 @@ extern "C" {
typedef struct { typedef struct {
osSemaphoreAttr_t attr; osSemaphoreAttr_t attr;
uint32 maxCount; UINT32 maxCount;
uint32 initialCount; UINT32 initialCount;
} SemaphoreEx; } SemaphoreEx;
#ifdef __cplusplus #ifdef __cplusplus

80
kernel/src/mm/los_memstat.c → kal/kal.c Executable file → Normal file
View File

@ -29,65 +29,43 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "los_debug.h" #include "kal.h"
#include "los_interrupt.h" #include "los_swtmr.h"
typedef struct { #ifdef __cplusplus
UINT32 memUsed; #if __cplusplus
} TskMemUsedInfo; extern "C" {
#endif /* __cpluscplus */
#endif /* __cpluscplus */
LITE_OS_SEC_BSS_MINOR TskMemUsedInfo g_tskMemUsedInfo[LOSCFG_BASE_CORE_TSK_LIMIT + 1]; #if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
osTimerId_t osTimerExtNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr,
LITE_OS_SEC_TEXT_MINOR VOID OsTaskMemUsedInc(UINT32 usedSize, UINT32 taskID) osTimerRouses_t ucRouses, osTimerAlign_t ucSensitive)
{ {
if (taskID > LOSCFG_BASE_CORE_TSK_LIMIT) { UNUSED(attr);
return; UINT16 usSwTmrID;
UINT8 mode;
if ((OS_INT_ACTIVE) || (NULL == func) || ((osTimerOnce != type) && (osTimerPeriodic != type))) {
return (osTimerId_t)NULL;
} }
if (OS_INT_ACTIVE) { if (osTimerOnce == type) {
return; mode = LOS_SWTMR_MODE_NO_SELFDELETE;
} else {
mode = LOS_SWTMR_MODE_PERIOD;
} }
g_tskMemUsedInfo[taskID].memUsed += usedSize; if (LOS_OK != LOS_SwtmrCreate(1, mode, (SWTMR_PROC_FUNC)func, &usSwTmrID,
(UINT32)(UINTPTR)argument, ucRouses, ucSensitive)) {
return (osTimerId_t)NULL;
} }
LITE_OS_SEC_TEXT_MINOR VOID OsTaskMemUsedDec(UINT32 usedSize, UINT32 taskID) return (osTimerId_t)OS_SWT_FROM_SID(usSwTmrID);
{
if (taskID > LOSCFG_BASE_CORE_TSK_LIMIT) {
return;
} }
#endif
if (OS_INT_ACTIVE) { #ifdef __cplusplus
return; #if __cplusplus
}
if (g_tskMemUsedInfo[taskID].memUsed < usedSize) {
PRINT_INFO("mem used of current task '%s':0x%x, decrease size:0x%x\n",
g_losTask.runTask->taskName, g_tskMemUsedInfo[taskID].memUsed, usedSize);
return;
}
g_tskMemUsedInfo[taskID].memUsed -= usedSize;
}
LITE_OS_SEC_TEXT_MINOR UINT32 OsTaskMemUsage(UINT32 taskId)
{
if ((UINT32)taskId > LOSCFG_BASE_CORE_TSK_LIMIT) {
return LOS_NOK;
}
return g_tskMemUsedInfo[(UINT32)taskId].memUsed;
}
LITE_OS_SEC_TEXT_MINOR VOID OsTaskMemClear(UINT32 taskID)
{
if (taskID > LOSCFG_BASE_CORE_TSK_LIMIT) {
return;
}
if (g_tskMemUsedInfo[taskID].memUsed != 0) {
PRINT_INFO("mem used of task '%s' is:0x%x, not zero when task being deleted\n",
g_losTask.runTask->taskName, g_tskMemUsedInfo[taskID].memUsed);
}
g_tskMemUsedInfo[taskID].memUsed = 0;
return;
} }
#endif /* __cpluscplus */
#endif /* __cpluscplus */

78
kal/kal.h Normal file
View File

@ -0,0 +1,78 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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 _KAL_H
#define _KAL_H
#include "cmsis_os2.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
/**
* @brief Enumerates timer permissions.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** The timer is not allowed to wake up the RTOS. */
osTimerRousesIgnore = 0,
/** The timer is allowed to wake up the RTOS. */
osTimerRousesAllow = 1
} osTimerRouses_t;
/**
* @brief Enumerates timer alignment modes.
*
*/
typedef enum {
/** The timer ignores alignment. */
osTimerAlignIgnore = 0,
/** The timer allows alignment. */
osTimerAlignAllow = 1
} osTimerAlign_t;
osTimerId_t osTimerExtNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr,
osTimerRouses_t ucRouses, osTimerAlign_t ucSensitive);
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _KAL_H */

View File

@ -1,15 +0,0 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
import("//build/lite/config/component/lite_component.gni")
static_library("kal") {
sources = [ "kal.c" ]
include_dirs = [
"//kernel/liteos_m/kal",
"//third_party/bounds_checking_function/include",
]
defines = [ "LITEOS_WIFI_IOT_VERSION" ]
cflags = [ "-Werror" ]
}

View File

@ -1,220 +0,0 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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 "securec.h"
#include "hi_mem.h"
#include "los_task.h"
#include "los_swtmr.h"
#include "los_swtmr_pri.h"
#include "los_hwi.h"
#include "kal.h"
#ifdef __cplusplus
#define NULL 0L
#else
#ifndef NULL
#define NULL ((void *)0)
#endif
#endif
#define MS_PER_SECOND 1000
unsigned int KalThreadGetInfo(unsigned int threadId, ThreadInfo *info)
{
unsigned int ret;
if (info == NULL) {
return -1;
}
(void)memset_s(info, sizeof(ThreadInfo), 0, sizeof(ThreadInfo));
TSK_INFO_S *losTaskInfo = (TSK_INFO_S *)malloc(sizeof(TSK_INFO_S));
if (losTaskInfo == NULL) {
return -1;
}
(void)memset_s(losTaskInfo, sizeof(TSK_INFO_S), 0, sizeof(TSK_INFO_S));
ret = LOS_TaskInfoGet(threadId, losTaskInfo);
if (ret == LOS_OK) {
info->id = losTaskInfo->uwTaskID;
info->status = losTaskInfo->usTaskStatus;
info->priority = losTaskInfo->usTaskPrio;
info->taskSem = losTaskInfo->pTaskSem;
info->taskMutex = losTaskInfo->pTaskMux;
info->eventMask = losTaskInfo->uwEventMask;
info->stackSize = losTaskInfo->uwStackSize;
info->topOfStack = losTaskInfo->uwTopOfStack;
info->bottomOfStack = losTaskInfo->uwBottomOfStack;
info->mstatus = losTaskInfo->mstatus;
info->mepc = losTaskInfo->mepc;
info->tp = losTaskInfo->tp;
info->ra = losTaskInfo->ra;
info->sp = losTaskInfo->uwSP;
info->currUsed = losTaskInfo->uwCurrUsed;
info->peakUsed = losTaskInfo->uwPeakUsed;
info->overflowFlag = losTaskInfo->bOvf;
ret = memcpy_s(info->name, sizeof(info->name), losTaskInfo->acName, sizeof(info->name) - 1);
}
free(losTaskInfo);
return ret;
}
void KalDelayUs(unsigned int us)
{
unsigned int ticks;
if (us == 0) {
return;
}
ticks = LOS_MS2Tick(us / MS_PER_SECOND);
(void)LOS_TaskDelay(ticks);
}
KalTimerId KalTimerCreate(KalTimerProc func, KalTimerType type, void *arg, unsigned int ticks)
{
UINT16 swtmrId;
UINT8 mode;
if ((OS_INT_ACTIVE) || (NULL == func) || ((KAL_TIMER_ONCE != type) && (KAL_TIMER_PERIODIC != type))) {
return (KalTimerId)NULL;
}
if (KAL_TIMER_ONCE == type) {
mode = LOS_SWTMR_MODE_NO_SELFDELETE;
} else {
mode = LOS_SWTMR_MODE_PERIOD;
}
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
if (LOS_OK != LOS_SwtmrCreate(ticks, mode, (SWTMR_PROC_FUNC)func, &swtmrId, (UINT32)(UINTPTR)arg,
osTimerRousesAllow, osTimerAlignIgnore)) {
return (KalTimerId)NULL;
}
#else
if (LOS_OK != LOS_SwtmrCreate(ticks, mode, (SWTMR_PROC_FUNC)func, &swtmrId, (UINT32)(UINTPTR)arg)) {
return (KalTimerId)NULL;
}
#endif
return (KalTimerId)OS_SWT_FROM_SID(swtmrId);
}
KalErrCode KalTransRetCode(unsigned int ret)
{
if (LOS_OK == ret) {
return KAL_OK;
} else if (LOS_ERRNO_SWTMR_ID_INVALID == ret) {
return KAL_ERR_PARA;
} else {
return KAL_ERR_INNER;
}
}
KalErrCode KalTimerStart(KalTimerId timerId)
{
UINT32 ret;
SWTMR_CTRL_S *swtmr = NULL;
if (NULL == timerId) {
return KAL_ERR_PARA;
}
swtmr = (SWTMR_CTRL_S *)timerId;
ret = LOS_SwtmrStart(swtmr->usTimerID);
return KalTransRetCode(ret);
}
// support change while not running.
KalErrCode KalTimerChange(KalTimerId timerId, unsigned int ticks)
{
SWTMR_CTRL_S *swtmr = NULL;
if ((0 == ticks) || (NULL == timerId)) {
return KAL_ERR_PARA;
}
swtmr = (SWTMR_CTRL_S *)timerId;
if (OS_SWTMR_STATUS_TICKING == swtmr->ucState) {
return KAL_ERR_TIMER_STATE;
}
swtmr->uwInterval = ticks;
return KAL_OK;
}
KalErrCode KalTimerStop(KalTimerId timerId)
{
UINT32 ret;
SWTMR_CTRL_S *swtmr = NULL;
if (NULL == timerId) {
return KAL_ERR_PARA;
}
swtmr = (SWTMR_CTRL_S *)timerId;
ret = LOS_SwtmrStop(swtmr->usTimerID);
return KalTransRetCode(ret);
}
KalErrCode KalTimerDelete(KalTimerId timerId)
{
UINT32 ret;
SWTMR_CTRL_S *swtmr = NULL;
if (NULL == timerId) {
return KAL_ERR_PARA;
}
swtmr = (SWTMR_CTRL_S *)timerId;
ret = LOS_SwtmrDelete(swtmr->usTimerID);
return KalTransRetCode(ret);
}
unsigned int KalTimerIsRunning(KalTimerId timerId)
{
if ((OS_INT_ACTIVE) || (NULL == timerId)) {
return 0;
}
return (OS_SWTMR_STATUS_TICKING == ((SWTMR_CTRL_S *)timerId)->ucState);
}
unsigned int KalTickToMs(unsigned int ticks)
{
return LOS_Tick2MS(ticks);
}
unsigned int KalMsToTick(unsigned int millisec)
{
return LOS_MS2Tick(millisec);
}
KalErrCode KalGetMemInfo(MemInfo *pmemInfo)
{
hi_mdm_mem_info hiMemInfo;
hi_u32 hiRet;
if (NULL == pmemInfo) {
return KAL_ERR_PARA;
}
hiRet = hi_mem_get_sys_info(&hiMemInfo);
if (hiRet != 0) {
return KAL_ERR_INNER;
}
pmemInfo->total = hiMemInfo.total;
pmemInfo->used = hiMemInfo.used;
pmemInfo->free = hiMemInfo.free;
pmemInfo->freeNodeNum = hiMemInfo.free_node_num;
pmemInfo->usedNodeNum = hiMemInfo.used_node_num;
pmemInfo->maxFreeNodeSize = hiMemInfo.max_free_node_size;
pmemInfo->mallocFailCount = hiMemInfo.malloc_fail_count;
pmemInfo->peekSize = hiMemInfo.peek_size;
pmemInfo->totalLmp = hiMemInfo.total_lmp;
pmemInfo->usedLmp = hiMemInfo.used_lmp;
pmemInfo->freeLmp = hiMemInfo.free_lmp;
return KAL_OK;
}

View File

@ -1,182 +0,0 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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.
*/
/**
* @addtogroup KAL
* @{
*
* @brief Defines the kernel adaptation layer (KAL), which provides compatible interfaces across L0 and L1 systems.
*
*
* @since 1.0
* @version 1.0
*/
#ifndef KAL_H_
#define KAL_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Indicates the maximum length of a thread name.
*
* @since 1.0
* @version 1.0
*/
#define KAL_TASK_NAME_LEN 32
typedef void (*KalTimerProc)(void *arg);
typedef void *KalTimerId;
typedef enum {
KAL_TIMER_ONCE = 0, // /< One-shot timer.
KAL_TIMER_PERIODIC = 1 // /< Repeating timer.
} KalTimerType;
typedef enum {
KAL_OK = 0,
KAL_ERR_PARA = 1,
KAL_ERR_INNER = 2,
KAL_ERR_TIMER_STATE = 0x100,
} KalErrCode;
/**
* @brief Describes a thread.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
/** Thread name */
char name[KAL_TASK_NAME_LEN];
/** Thread ID */
unsigned int id;
/** Thread status */
unsigned short status;
/** Thread priority */
unsigned short priority;
/** Thread semaphore */
void *taskSem;
/** Thread mutex */
void *taskMutex;
/** Thread event */
unsigned int eventStru[3];
/** Thread event mask */
unsigned int eventMask;
/** Thread stack size */
unsigned int stackSize;
/** Thread stack top */
unsigned int topOfStack;
/** Thread stack bottom */
unsigned int bottomOfStack;
/** Thread current mstatus */
unsigned int mstatus;
/** Thread current mepc */
unsigned int mepc;
/** Thread current tp */
unsigned int tp;
/** Thread current ra */
unsigned int ra;
/** Thread stack pointer */
unsigned int sp;
/** Current stack space usage */
unsigned int currUsed;
/** Peak stack space usage */
unsigned int peakUsed;
/** Thread stack overflow flag */
unsigned int overflowFlag;
} ThreadInfo;
typedef struct {
/**< Total space of the memory pool. */
unsigned int total;
/**< Used space of the memory pool. */
unsigned int used;
/**< Free space of the memory pool. */
unsigned int free;
/**< Number of free nodes in the memory pool. */
unsigned int freeNodeNum;
/**< Number of used nodes in the memory pool. */
unsigned int usedNodeNum;
/**< Maximum size of the node in the free space of the memory pool. */
unsigned int maxFreeNodeSize;
/**< Number of memory application failures. */
unsigned int mallocFailCount;
/**< Peak memory usage of the memory pool. */
unsigned int peekSize;
/**< Total space of the little memory pool. */
unsigned int totalLmp;
/**< Used space of the little memory pool. */
unsigned int usedLmp;
/**< Free space of the little memory pool. */
unsigned int freeLmp;
} MemInfo;
/**
* @brief Obtains thread information.
*
* @param threadId Indicates the thread ID.
* @param info Indicates the pointer to the buffer for storing the obtained thread information.
* @return Returns <b>0</b> if the thread information is obtained; returns a negative value otherwise.
* @since 1.0
* @version 1.0
*/
unsigned int KalThreadGetInfo(unsigned int threadId, ThreadInfo *info);
/**
* @brief Delays a thread.
*
* The delay unit is microsecond. The actual delay precision can reach only the tick level.
*
* @param us Indicates the number of microseconds to delay. The actual delay precision is one tick.
* @since 1.0
* @version 1.0
*/
void KalDelayUs(unsigned int us);
KalTimerId KalTimerCreate(KalTimerProc func, KalTimerType type, void *arg, unsigned int ticks);
KalErrCode KalTimerStart(KalTimerId timerId);
KalErrCode KalTimerChange(KalTimerId timerId, unsigned int ticks);
KalErrCode KalTimerStop(KalTimerId timerId);
KalErrCode KalTimerDelete(KalTimerId timerId);
unsigned int KalTimerIsRunning(KalTimerId timerId);
unsigned int KalTickToMs(unsigned int ticks);
unsigned int KalMsToTick(unsigned int millisec);
KalErrCode KalGetMemInfo(MemInfo *pmemInfo);
#ifdef __cplusplus
}
#endif
#endif // KAL_H_
/* * @} */

View File

@ -1,20 +0,0 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
import("//build/lite/config/component/lite_component.gni")
static_library("posix") {
sources = [
"src/file.c",
"src/pthread.c",
"src/pthread_attr.c",
"src/time.c",
"src/version.c",
]
include_dirs = [ "include" ]
defines = [
"LIBC_VERSION_NUM=0x00010000",
"LIBC_VERSION_STR=\"1.0.0-liteos_m\"",
]
cflags = [ "-Werror" ]
}

0
kal/posix/include/README Executable file → Normal file
View File

0
kal/posix/include/version.h Executable file → Normal file
View File

0
kal/posix/src/file.c Executable file → Normal file
View File

12
kal/posix/src/pthread.c Executable file → Normal file
View File

@ -72,15 +72,19 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
return EINVAL; return EINVAL;
} }
taskInitParam.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
if (attr) { if (attr) {
if (attr->detachstate == PTHREAD_CREATE_DETACHED) { if (attr->detachstate == PTHREAD_CREATE_DETACHED) {
return ENOTSUP; return ENOTSUP;
} }
taskInitParam.usTaskPrio = (UINT16)attr->schedparam.sched_priority; if (attr->stackaddr_set) {
return ENOTSUP;
}
if (attr->stacksize_set) {
taskInitParam.uwStackSize = attr->stacksize; taskInitParam.uwStackSize = attr->stacksize;
} else { }
taskInitParam.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO; taskInitParam.usTaskPrio = (UINT16)attr->schedparam.sched_priority;
taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
} }
taskInitParam.pcName = malloc(PTHREAD_NAMELEN); taskInitParam.pcName = malloc(PTHREAD_NAMELEN);

0
kal/posix/src/pthread_attr.c Executable file → Normal file
View File

0
kal/posix/src/time.c Executable file → Normal file
View File

0
kal/posix/src/version.c Executable file → Normal file
View File

0
kernel/arch/arm/cortex-m3/keil/cmsis/ARMCM3.h Executable file → Normal file
View File

0
kernel/arch/arm/cortex-m3/keil/cmsis/core_cm3.h Executable file → Normal file
View File

0
kernel/arch/arm/cortex-m3/keil/cmsis/core_cmFunc.h Executable file → Normal file
View File

0
kernel/arch/arm/cortex-m3/keil/cmsis/core_cmInstr.h Executable file → Normal file
View File

View File

@ -0,0 +1,161 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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_ATOMIC_H
#define LOS_ATOMIC_H
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_atomic
* @brief Atomic exchange for 32-bit variable.
*
* @par Description:
* This API is used to implement the atomic exchange for 32-bit variable and return the previous value of the atomic variable.
* @attention
* <ul>The pointer v must not be NULL.</ul>
*
* @param v [IN] The variable pointer.
* @param val [IN] The exchange value.
*
* @retval #INT32 The previous value of the atomic variable
* @par Dependency:
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V100R001C00
*/
STATIC INLINE INT32 HalAtomicXchg32bits(volatile INT32 *v, INT32 val)
{
INT32 prevVal = 0;
UINT32 status = 0;
do {
__asm__ __volatile__("ldrex %0, [%3]\n"
"strex %1, %4, [%3]"
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
: "r"(v), "r"(val)
: "cc");
} while (__builtin_expect(status != 0, 0));
return prevVal;
}
/**
* @ingroup los_atomic
* @brief Atomic auto-decrement.
*
* @par Description:
* This API is used to implementating the atomic auto-decrement and return the result of auto-decrement.
* @attention
* <ul>
* <li>The pointer v must not be NULL.</li>
* <li>The value which v point to must not be INT_MIN to avoid overflow after reducing 1.</li>
* </ul>
*
* @param v [IN] The addSelf variable pointer.
*
* @retval #INT32 The return value of variable auto-decrement.
* @par Dependency:
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V100R001C00
*/
STATIC INLINE INT32 HalAtomicDecRet(volatile INT32 *v)
{
INT32 val = 0;
UINT32 status = 0;
do {
__asm__ __volatile__("ldrex %0, [%3]\n"
"sub %0, %0, #1\n"
"strex %1, %0, [%3]"
: "=&r"(val), "=&r"(status), "+m"(*v)
: "r"(v)
: "cc");
} while (__builtin_expect(status != 0, 0));
return val;
}
/**
* @ingroup los_atomic
* @brief Atomic exchange for 32-bit variable with compare.
*
* @par Description:
* This API is used to implement the atomic exchange for 32-bit variable, if the value of variable is equal to oldVal.
* @attention
* <ul>The pointer v must not be NULL.</ul>
*
* @param v [IN] The variable pointer.
* @param val [IN] The new value.
* @param oldVal [IN] The old value.
*
* @retval TRUE The previous value of the atomic variable is not equal to oldVal.
* @retval FALSE The previous value of the atomic variable is equal to oldVal.
* @par Dependency:
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V100R001C00
*/
STATIC INLINE BOOL HalAtomicCmpXchg32bits(volatile INT32 *v, INT32 val, INT32 oldVal)
{
INT32 prevVal = 0;
UINT32 status = 0;
do {
__asm__ __volatile__("1: ldrex %0, %2\n"
" mov %1, #0\n"
" cmp %0, %3\n"
" bne 2f\n"
" strex %1, %4, %2\n"
"2:"
: "=&r"(prevVal), "=&r"(status), "+Q"(*v)
: "r"(oldVal), "r"(val)
: "cc");
} while (__builtin_expect(status != 0, 0));
return prevVal != oldVal;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* LOS_ATOMIC_H */

View File

@ -29,42 +29,18 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** #ifndef _LOS_ARCH_CONTEXT_H
* @defgroup los_hw hardware #define _LOS_ARCH_CONTEXT_H
* @ingroup kernel
*/
#ifndef _LOS_HW_H #include "los_config.h"
#define _LOS_HW_H #include "los_compiler.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cpluscplus */
#endif /* __cplusplus */ #endif /* __cpluscplus */
/* *
* @ingroup los_hw
* The initialization value of stack space.
*/
#define EMPTY_STACK 0xCACA
/* *
* @ingroup los_hw
* Trigger a task.
*/
#define OsTaskTrap() __asm(" TRAP #31")
/* *
* @ingroup los_hw
* Check task schedule.
*/
#define LOS_CHECK_SCHEDULE ((!g_losTaskLock))
/* *
* @ingroup los_hw
* Define the type of a task context control block.
*/
typedef struct tagTskContext { typedef struct tagTskContext {
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ #if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U))) (defined(__FPU_USED) && (__FPU_USED == 1U)))
@ -126,69 +102,30 @@ typedef struct tagTskContext {
} TaskContext; } TaskContext;
/** /**
* @ingroup los_hw * @ingroup los_config
* @brief: Task stack initialization. * @brief: Task start running function.
* *
* @par Description: * @par Description:
* This API is used to initialize the task stack. * This API is used to start a task.
* *
* @attention: * @attention:
* <ul><li>None.</li></ul> * <ul><li>None.</li></ul>
* *
* @param taskID [IN] Type#UINT32: TaskID. * @param: None.
* @param stackSize [IN] Type#UINT32: Total size of the stack. *
* @param topStack [IN] Type#VOID *: Top of task's stack. * @retval None.
* *
* @retval: context Type#TaskContext *.
* @par Dependency: * @par Dependency:
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul> * <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
* @see None. * @see None.
*/ */
extern VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack); extern VOID HalStartToRun(VOID);
/**
* @ingroup los_hw
* @brief: Function to task exit.
*
* @par Description:
* This API is used to exit task.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param None.
*
* @retval: None.
* @par Dependency:
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
LITE_OS_SEC_TEXT_MINOR VOID OsTaskExit(VOID);
/* *
* @ingroup los_hw
* @brief: The M3 wait interrupt instruction.
*
* @par Description:
* This API is used to make CPU enter to power-save mode.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param None.
*
* @retval: None.
* @par Dependency:
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID OsEnterSleep(VOID);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cpluscplus */
#endif /* __cplusplus */ #endif /* __cpluscplus */
#endif /* _LOS_HW_H */ #endif /* _LOS_ARCH_CONTEXT_H */

View File

@ -34,6 +34,7 @@
#include "los_config.h" #include "los_config.h"
#include "los_compiler.h" #include "los_compiler.h"
#include "los_interrupt.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
@ -65,55 +66,6 @@ extern "C" {
#define OS_HWI_PRIO_LOWEST 7 #define OS_HWI_PRIO_LOWEST 7
#endif #endif
/* *
* @ingroup los_config
* Configuration item for interrupt with argument
*/
#ifndef OS_HWI_WITH_ARG
#define OS_HWI_WITH_ARG NO
#endif
/* *
* @ingroup los_hwi
* Define the type of a hardware interrupt number.
*/
typedef UINT32 HWI_HANDLE_T;
/* *
* @ingroup los_hwi
* Define the type of a hardware interrupt priority.
*/
typedef UINT16 HWI_PRIOR_T;
/* *
* @ingroup los_hwi
* Define the type of hardware interrupt mode configurations.
*/
typedef UINT16 HWI_MODE_T;
/* *
* @ingroup los_hwi
* Define the type of the parameter used for the hardware interrupt creation function. The function of this parameter varies among platforms.
*/
typedef UINT32 HWI_ARG_T;
/* *
* @ingroup los_hwi
* Define the type of a hardware interrupt handling function.
*/
#if (OS_HWI_WITH_ARG == YES)
typedef VOID (*HWI_PROC_FUNC)(VOID *parm);
typedef struct {
HWI_PROC_FUNC pfnHandler;
VOID *pParm;
} HWI_SLAVE_FUNC;
#else
typedef VOID (*HWI_PROC_FUNC)(void);
#endif
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
@ -125,19 +77,7 @@ typedef VOID (**HWI_VECTOR_FUNC)(void);
* @ingroup los_hwi * @ingroup los_hwi
* Count of interrupts. * Count of interrupts.
*/ */
extern UINT32 g_vuwIntCount; extern UINT32 g_intCount;
/* *
* @ingroup los_hwi
* An interrupt is active.
*/
#define OS_INT_ACTIVE (g_vuwIntCount > 0)
/* *
* @ingroup los_hwi
* An interrupt is inactive.
*/
#define OS_INT_INACTIVE (!(OS_INT_ACTIVE))
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
@ -375,7 +315,7 @@ extern UINT32 _BootVectors[];
*/ */
extern HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT]; extern HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT];
#if (OS_HWI_WITH_ARG == YES) #if (OS_HWI_WITH_ARG == 1)
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
* hardware interrupt Slave form mapping handling function array. * hardware interrupt Slave form mapping handling function array.
@ -388,7 +328,7 @@ extern HWI_SLAVE_FUNC g_hwiSlaveForm[OS_VECTOR_CNT];
*/ */
#define OsSetVectonr(num, vector, arg) \ #define OsSetVectonr(num, vector, arg) \
do { \ do { \
g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)OsInterrupt; \ g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalInterrupt; \
g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector; \ g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector; \
g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT].pParm = (VOID *)arg; \ g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT].pParm = (VOID *)arg; \
} while(0) } while(0)
@ -405,47 +345,11 @@ extern HWI_PROC_FUNC g_hwiSlaveForm[OS_VECTOR_CNT];
*/ */
#define OsSetVector(num, vector) \ #define OsSetVector(num, vector) \
do { \ do { \
g_hwiForm[num + OS_SYS_VECTOR_CNT] = OsInterrupt; \ g_hwiForm[num + OS_SYS_VECTOR_CNT] = HalInterrupt; \
g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT] = vector; \ g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT] = vector; \
} while(0) } while(0)
#endif #endif
/* *
* @ingroup los_hwi
* @brief Create a hardware interrupt.
*
* @par Description:
* This API is used to configure a hardware interrupt and register a hardware interrupt handling function.
*
* @attention
* <ul>
* <li>The hardware interrupt module is usable only when the configuration item for hardware interrupt tailoring is enabled.</li>
* <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range applicable for a Cortex-A7 platform is [32,95].</li>
* <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
* <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
* </ul>
*
* @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a Cortex-A7 platform is [32,95].
* @param hwiPrio [IN] Type#HWI_PRIOR_T: hardware interrupt priority. Ignore this parameter temporarily.
* @param mode [IN] Type#HWI_MODE_T: hardware interrupt mode. Ignore this parameter temporarily.
* @param handler [IN] Type#HWI_PROC_FUNC: interrupt handler used when a hardware interrupt is triggered.
* @param arg [IN] Type#HWI_ARG_T: input parameter of the interrupt handler used when a hardware interrupt is triggered.
*
* @retval #OS_ERRNO_HWI_PROC_FUNC_NULL 0x02000901: Null hardware interrupt handling function.
* @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
* @retval #OS_ERRNO_HWI_NO_MEMORY 0x02000903: Insufficient memory for hardware interrupt creation.
* @retval #OS_ERRNO_HWI_ALREADY_CREATED 0x02000904: The interrupt handler being created has already been created.
* @retval #LOS_OK 0 : The interrupt is successfully created.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
HWI_PRIOR_T hwiPrio,
HWI_MODE_T mode,
HWI_PROC_FUNC handler,
HWI_ARG_T arg);
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
* @brief: Hardware interrupt entry function. * @brief: Hardware interrupt entry function.
@ -463,7 +367,7 @@ extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul> * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None. * @see None.
*/ */
extern VOID OsInterrupt(VOID); extern VOID HalInterrupt(VOID);
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
@ -482,7 +386,7 @@ extern VOID OsInterrupt(VOID);
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul> * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None. * @see None.
*/ */
extern UINT32 OsIntNumGet(VOID); extern UINT32 HalIntNumGet(VOID);
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
@ -502,7 +406,7 @@ extern UINT32 OsIntNumGet(VOID);
></ul> ></ul>
* @see None. * @see None.
*/ */
extern VOID OsHwiDefaultHandler(VOID); extern VOID HalHwiDefaultHandler(VOID);
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
@ -541,186 +445,8 @@ extern VOID Reset_Handler(VOID);
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul> * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None. * @see None.
*/ */
extern VOID osPendSV(VOID); extern VOID HalPendSV(VOID);
/* *
* @ingroup los_hwi
* @brief Enable all interrupts.
*
* @par Description:
* <ul>
* <li>This API is used to enable all IRQ and FIQ interrupts in the CPSR.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval CPSR value obtained after all interrupts are enabled.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntRestore
*/
extern UINTPTR LOS_IntUnLock(VOID);
/* *
* @ingroup los_hwi
* @brief Disable all interrupts.
*
* @par Description:
* <ul>
* <li>This API is used to disable all IRQ and FIQ interrupts in the CPSR.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval CPSR value obtained before all interrupts are disabled.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntRestore
*/
extern UINTPTR LOS_IntLock(VOID);
/* *
* @ingroup los_hwi
* @brief Restore interrupts.
*
* @par Description:
* <ul>
* <li>This API is used to restore the CPSR value obtained before all interrupts are disabled.</li>
* </ul>
* @attention
* <ul>
* <li>This API can be called only after all interrupts are disabled, and the input parameter value should be the value returned by calling the all interrupt disabling API.</li>
* </ul>
*
* @param intSave [IN] CPSR value obtained before all interrupts are disabled.
*
* @retval None.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntLock
*/
extern VOID LOS_IntRestore(UINTPTR intSave);
/* *
* @ingroup los_hwi
* @brief Get value from xPSR register.
*
* @par Description:
* <ul>
* <li>This API is used to Get value from xPSR register.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param cntHi [IN] CpuTick High 4 byte
* @param cntLo [IN] CpuTick Low 4 byte
*
* @retval None.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntRestore
*/
extern VOID LOS_GetCpuCycle(UINT32 *cntHi, UINT32 *cntLo);
#if (LOSCFG_KERNEL_TICKLESS == YES)
/**
* @ingroup los_hwi
* @brief reconfig systick, and clear SysTick_IRQn.
*
* @par Description:
* <ul>
* <li>This API is used to reconfig systick, and clear SysTick_IRQn.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param cyclesPerTick [IN] Cycles Per Tick
*
* @retval None.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntRestore
*/
extern VOID LOS_SysTickReload(UINT32 cyclesPerTick);
#endif
/**
* @ingroup los_hwi
* @brief Get System cycle count.
*
* @par Description:
* <ul>
* <li>This API is used to Get System cycle count.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval: The value of the system cycle count.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntRestore
*/
extern UINT32 LOS_SysTickCurrCycleGet(VOID);
extern VOID LOS_GetSystickCycle(UINT32 *puwCntHi, UINT32 *puwCntLo);
/* *
* @ingroup los_hwi
* @brief Delete hardware interrupt.
*
* @par Description:
* This API is used to delete hardware interrupt.
*
* @attention
* <ul>
* <li>The hardware interrupt module is usable only when the configuration item for hardware interrupt tailoring is enabled.</li>
* <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range applicable for a Cortex-A7 platform is [32,95].</li>
* <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
* <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
* </ul>
*
* @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a Cortex-A7 platform is [32,95].
*
* @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
* @retval #LOS_OK 0 : The interrupt is successfully delete.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum);
typedef enum {
OS_SYS_NORMAL_SLEEP = 0,
OS_SYS_DEEP_SLEEP,
} LOS_SysSleepEnum;
VOID LOS_TickLock(VOID);
VOID LOS_TickUnlock(VOID);
BOOL LOS_GetSysSleepFlag(VOID);
VOID LOS_ClearSysSleepFlag(VOID);
VOID LOS_EnterSleep(LOS_SysSleepEnum sleep);
VOID LOS_SystemWakeup(UINT32 hwiIndex);
#define OS_EXC_IN_INIT 0 #define OS_EXC_IN_INIT 0
#define OS_EXC_IN_TASK 1 #define OS_EXC_IN_TASK 1
@ -818,9 +544,8 @@ typedef struct tagExcContext {
#endif #endif
}EXC_CONTEXT_S; }EXC_CONTEXT_S;
typedef UINT32 (*EXC_INFO_SAVE_CALLBACK)(UINT32, VOID*);
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *); typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr); VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
/** /**
* @ingroup los_hwi * @ingroup los_hwi
@ -841,33 +566,14 @@ VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_
*/ */
VOID OsExcInit(VOID); VOID OsExcInit(VOID);
extern VOID OsExcNMI(VOID); VOID HalExcNMI(VOID);
extern VOID OsExcHardFault(VOID); VOID HalExcHardFault(VOID);
extern VOID OsExcMemFault(VOID); VOID HalExcMemFault(VOID);
extern VOID OsExcBusFault(VOID); VOID HalExcBusFault(VOID);
extern VOID OsExcUsageFault(VOID); VOID HalExcUsageFault(VOID);
extern VOID OsExcSvcCall(VOID); VOID HalExcSvcCall(VOID);
extern UINT8 g_aucTaskArray[]; VOID HalHwiInit();
extern void OsBackTrace();
/**
*@ingroup los_exc
*@brief Kernel panic function.
*
*@par Description:
*Stack function that prints kernel panics.
*@attention After this function is called and stack information is printed, the system will fail to respond.
*@attention The input parameter can be NULL.
*@param fmt [IN] Type #char* : variadic argument.
*
*@retval #None.
*
*@par Dependency:
*los_interrupt.h: the header file that contains the API declaration.
*@see None.
*/
VOID LOS_Panic(const CHAR *fmt, ...);
/** /**
*@ingroup los_exc *@ingroup los_exc
@ -1022,22 +728,14 @@ typedef struct tagExcInfo {
} ExcInfo; } ExcInfo;
extern UINT32 g_curNestCount; extern UINT32 g_curNestCount;
extern UINT32 g_vuwIntCount; extern UINT32 g_intCount;
static VOID OsExcSave2DDR(VOID); static VOID OsExcSave2DDR(VOID);
VOID OsExcInfoDisplay(ExcInfo *exc); VOID OsExcInfoDisplay(ExcInfo *exc);
extern UINT8 g_uwExcTbl[32]; extern UINT8 g_uwExcTbl[32];
typedef enum {
OS_EXC_TYPE_CONTEXT = 0,
OS_EXC_TYPE_TSK = 1,
OS_EXC_TYPE_QUE = 2,
OS_EXC_TYPE_NVIC = 3,
OS_EXC_TYPE_TSK_SWITCH = 4,
OS_EXC_TYPE_MEM = 5,
OS_EXC_TYPE_MAX = 6
} ExcInfoType;
typedef struct tagExcInfoCallBackArray { typedef struct tagExcInfoCallBackArray {
ExcInfoType uwType; ExcInfoType uwType;
@ -1052,19 +750,19 @@ typedef struct tagExcInfoCallBackArray {
#define MAX_TSK_INFO_SIZE (8 + sizeof(TSK_INFO_S) * (LOSCFG_BASE_CORE_TSK_LIMIT + 1)) #define MAX_TSK_INFO_SIZE (8 + sizeof(TSK_INFO_S) * (LOSCFG_BASE_CORE_TSK_LIMIT + 1))
#define MAX_INT_INFO_SIZE (8 + 0x164) #define MAX_INT_INFO_SIZE (8 + 0x164)
#if (LOSCFG_BASE_IPC_QUEUE == YES) #if (LOSCFG_BASE_IPC_QUEUE == 1)
#define MAX_QUEUE_INFO_SIZE (8 + sizeof(QUEUE_INFO_S) * LOSCFG_BASE_IPC_QUEUE_LIMIT) #define MAX_QUEUE_INFO_SIZE (8 + sizeof(QUEUE_INFO_S) * LOSCFG_BASE_IPC_QUEUE_LIMIT)
#else #else
#define MAX_QUEUE_INFO_SIZE (0) #define MAX_QUEUE_INFO_SIZE (0)
#endif #endif
#if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == YES) #if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == 1)
#define MAX_SWITCH_INFO_SIZE (8 + (sizeof(UINT32) + sizeof(CHAR) * LOS_TASK_NAMELEN) * OS_TASK_SWITCH_INFO_COUNT) #define MAX_SWITCH_INFO_SIZE (8 + (sizeof(UINT32) + sizeof(CHAR) * LOS_TASK_NAMELEN) * OS_TASK_SWITCH_INFO_COUNT)
#else #else
#define MAX_SWITCH_INFO_SIZE (0) #define MAX_SWITCH_INFO_SIZE (0)
#endif #endif
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == YES) #if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == 1)
#define MAX_MEM_INFO_SIZE (8 + sizeof(MEM_INFO_S) * OS_SYS_MEM_NUM) #define MAX_MEM_INFO_SIZE (8 + sizeof(MEM_INFO_S) * OS_SYS_MEM_NUM)
#else #else
#define MAX_MEM_INFO_SIZE (0) #define MAX_MEM_INFO_SIZE (0)
@ -1072,8 +770,7 @@ typedef struct tagExcInfoCallBackArray {
#define MAX_EXC_MEM_SIZE ( 4 + MAX_SCENE_INFO_SIZE + MAX_TSK_INFO_SIZE + MAX_QUEUE_INFO_SIZE + MAX_INT_INFO_SIZE + MAX_SWITCH_INFO_SIZE + MAX_MEM_INFO_SIZE + 4) #define MAX_EXC_MEM_SIZE ( 4 + MAX_SCENE_INFO_SIZE + MAX_TSK_INFO_SIZE + MAX_QUEUE_INFO_SIZE + MAX_INT_INFO_SIZE + MAX_SWITCH_INFO_SIZE + MAX_MEM_INFO_SIZE + 4)
VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg);
VOID LOS_Reboot(VOID);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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_context.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cpluscplus */
#endif /* __cpluscplus */
UINT32 HalTickStart(OS_TICK_HANDLER handler);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#endif /* _LOS_ARCH_TIMER_H */

View File

@ -28,9 +28,13 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "los_config.h"
#include "los_task.h" #include "los_task.h"
#include "securec.h" #include "securec.h"
#include "los_interrupt.h"
#include "los_arch_context.h"
#include "los_arch_interrupt.h"
#include "los_arch_timer.h"
#include "ARMCM3.h" #include "ARMCM3.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
@ -39,20 +43,32 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/* **************************************************************************** /* ****************************************************************************
Function : OsTaskExit Function : HalArchInit
Description : Task exit function Description : arch init function
Input : None Input : None
Output : None Output : None
Return : None Return : None
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID OsTaskExit(VOID) LITE_OS_SEC_TEXT_INIT VOID HalArchInit()
{
HalHwiInit();
}
/* ****************************************************************************
Function : HalSysExit
Description : exit function
Input : None
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID HalSysExit(VOID)
{ {
LOS_IntLock(); LOS_IntLock();
for(;;); for(;;);
} }
/* **************************************************************************** /* ****************************************************************************
Function : OsTskStackInit Function : HalTskStackInit
Description : Task stack initialization function Description : Task stack initialization function
Input : taskID --- TaskID Input : taskID --- TaskID
stackSize --- Total size of the stack stackSize --- Total size of the stack
@ -60,7 +76,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTaskExit(VOID)
Output : None Output : None
Return : Context pointer Return : Context pointer
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack) LITE_OS_SEC_TEXT_INIT VOID *HalTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
{ {
TaskContext *context = NULL; TaskContext *context = NULL;
errno_t result; errno_t result;
@ -126,18 +142,27 @@ LITE_OS_SEC_TEXT_INIT VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID
context->uwR2 = 0x02020202L; context->uwR2 = 0x02020202L;
context->uwR3 = 0x03030303L; context->uwR3 = 0x03030303L;
context->uwR12 = 0x12121212L; context->uwR12 = 0x12121212L;
context->uwLR = (UINT32)(UINTPTR)OsTaskExit; context->uwLR = (UINT32)(UINTPTR)HalSysExit;
context->uwPC = (UINT32)(UINTPTR)OsTaskEntry; context->uwPC = (UINT32)(UINTPTR)OsTaskEntry;
context->uwxPSR = 0x01000000L; context->uwxPSR = 0x01000000L;
return (VOID *)context; return (VOID *)context;
} }
LITE_OS_SEC_TEXT_INIT VOID OsEnterSleep(VOID) void HalBackTrace()
{ {
__DSB();
__WFI(); }
__ISB();
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(OS_TICK_HANDLER handler)
{
UINT32 ret;
ret = HalTickStart(handler);
if (ret != LOS_OK) {
return ret;
}
HalStartToRun();
return LOS_OK; /* never return */
} }
#ifdef __cplusplus #ifdef __cplusplus

34
kernel/arch/arm/cortex-m3/keil/los_dispatch.S Executable file → Normal file
View File

@ -31,15 +31,14 @@
PRESERVE8 PRESERVE8
EXPORT LOS_IntLock EXPORT HalIntLock
EXPORT LOS_IntUnLock EXPORT HalIntUnLock
EXPORT LOS_IntRestore EXPORT HalIntRestore
EXPORT LOS_StartToRun EXPORT HalStartToRun
EXPORT osTaskSchedule EXPORT HalTaskSchedule
EXPORT osPendSV EXPORT HalPendSV
IMPORT g_losTask IMPORT g_losTask
IMPORT g_taskSwitchHook
IMPORT g_taskScheduled IMPORT g_taskScheduled
OS_NVIC_INT_CTRL EQU 0xE000ED04 OS_NVIC_INT_CTRL EQU 0xE000ED04
@ -52,7 +51,7 @@ OS_TASK_STATUS_RUNNING EQU 0x0010
THUMB THUMB
REQUIRE8 REQUIRE8
LOS_StartToRun HalStartToRun
LDR R4, =OS_NVIC_SYSPRI2 LDR R4, =OS_NVIC_SYSPRI2
LDR R5, =OS_NVIC_PENDSV_PRI LDR R5, =OS_NVIC_PENDSV_PRI
STR R5, [R4] STR R5, [R4]
@ -94,38 +93,31 @@ LOS_StartToRun
BX R6 BX R6
LOS_IntLock HalIntLock
MRS R0, PRIMASK MRS R0, PRIMASK
CPSID I CPSID I
BX LR BX LR
LOS_IntUnLock HalIntUnLock
MRS R0, PRIMASK MRS R0, PRIMASK
CPSIE I CPSIE I
BX LR BX LR
LOS_IntRestore HalIntRestore
MSR PRIMASK, R0 MSR PRIMASK, R0
BX LR BX LR
osTaskSchedule HalTaskSchedule
LDR R0, =OS_NVIC_INT_CTRL LDR R0, =OS_NVIC_INT_CTRL
LDR R1, =OS_NVIC_PENDSVSET LDR R1, =OS_NVIC_PENDSVSET
STR R1, [R0] STR R1, [R0]
BX LR BX LR
osPendSV HalPendSV
MRS R12, PRIMASK MRS R12, PRIMASK
CPSID I CPSID I
LDR R2, =g_taskSwitchHook HalTaskSwitch
LDR R2, [R2]
CBZ R2, TaskSwitch
PUSH {R12, LR}
BLX R2
POP {R12, LR}
TaskSwitch
MRS R0, PSP MRS R0, PSP
STMFD R0!, {R4-R12} STMFD R0!, {R4-R12}

View File

@ -33,16 +33,14 @@
AREA |.text|, CODE, READONLY AREA |.text|, CODE, READONLY
THUMB THUMB
EXPORT OsExcNMI EXPORT HalExcNMI
EXPORT OsExcHardFault EXPORT HalExcHardFault
EXPORT OsExcMemFault EXPORT HalExcMemFault
EXPORT OsExcBusFault EXPORT HalExcBusFault
EXPORT OsExcUsageFault EXPORT HalExcUsageFault
EXPORT OsExcSvcCall EXPORT HalExcSvcCall
IMPORT OsExcHandleEntry IMPORT HalExcHandleEntry
;IMPORT g_vuwLosFlag
;IMPORT g_curNestCount
IMPORT g_uwExcTbl IMPORT g_uwExcTbl
IMPORT g_taskScheduled IMPORT g_taskScheduled
@ -66,12 +64,12 @@ OS_NVIC_ACT_BASE EQU 0xE000E300
OS_NVIC_SHCSRS EQU 0xE000ED24 OS_NVIC_SHCSRS EQU 0xE000ED24
OS_NVIC_SHCSR_MASK EQU 0xC00 OS_NVIC_SHCSR_MASK EQU 0xC00
OsExcNMI HalExcNMI
MOV R0, #OS_EXC_CAUSE_NMI MOV R0, #OS_EXC_CAUSE_NMI
MOV R1, #0 MOV R1, #0
B osExcDispatch B osExcDispatch
OsExcHardFault HalExcHardFault
MOV R0, #OS_EXC_CAUSE_HARDFAULT MOV R0, #OS_EXC_CAUSE_HARDFAULT
LDR R2, =OS_NVIC_HFSR LDR R2, =OS_NVIC_HFSR
LDR R2, [R2] LDR R2, [R2]
@ -122,7 +120,7 @@ osHFExcCommonBMU
ORR R0, R0 ,R12 ORR R0, R0 ,R12
B osExcDispatch B osExcDispatch
OsExcSvcCall HalExcSvcCall
TST LR, #0x4 TST LR, #0x4
ITE EQ ITE EQ
MRSEQ R0, MSP MRSEQ R0, MSP
@ -132,7 +130,7 @@ OsExcSvcCall
MOV R1, #0 MOV R1, #0
B osExcDispatch B osExcDispatch
OsExcBusFault HalExcBusFault
LDR R0, =OS_NVIC_FSR LDR R0, =OS_NVIC_FSR
LDR R0, [R0] LDR R0, [R0]
@ -149,7 +147,7 @@ _ExcBusNoADDR
MOV R12,#0 MOV R12,#0
B osExcCommonBMU B osExcCommonBMU
OsExcMemFault HalExcMemFault
LDR R0, =OS_NVIC_FSR LDR R0, =OS_NVIC_FSR
LDR R0, [R0] LDR R0, [R0]
@ -166,7 +164,7 @@ _ExcMemNoADDR
MOV R12,#0 MOV R12,#0
B osExcCommonBMU B osExcCommonBMU
OsExcUsageFault HalExcUsageFault
LDR R0, =OS_NVIC_FSR LDR R0, =OS_NVIC_FSR
LDR R0, [R0] LDR R0, [R0]
@ -281,7 +279,7 @@ _handleEntry
MOV R3, R13 ; R13:the 4th param MOV R3, R13 ; R13:the 4th param
CPSID I CPSID I
CPSID F CPSID F
B OsExcHandleEntry B HalExcHandleEntry
NOP NOP
END END

170
kernel/arch/arm/cortex-m3/keil/los_interrupt.c Executable file → Normal file
View File

@ -29,12 +29,11 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "los_interrupt.h" #include "los_interrupt.h"
#include "los_context.h"
#include "los_arch_interrupt.h"
#include <stdarg.h> #include <stdarg.h>
#include "los_debug.h" #include "los_debug.h"
#include "los_task.h" #include "los_task.h"
#if (LOSCFG_KERNEL_TICKLESS == YES)
#include "los_tick.h"
#endif
#include "ARMCM3.h" #include "ARMCM3.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
@ -43,99 +42,79 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*lint -save -e40 -e522 -e533*/ /*lint -save -e40 -e522 -e533*/
__weak VOID SysTickHandler(VOID)
{
return;
}
UINT32 g_vuwIntCount = 0; UINT32 g_intCount = 0;
/*lint -restore*/ /*lint -restore*/
#ifdef __ICCARM__ #ifdef __ICCARM__
#pragma location = ".data.vector" #pragma location = ".data.vector"
#elif defined(__CC_ARM) || defined(__GNUC__) #elif defined(__CC_ARM) || defined(__GNUC__)
#pragma data_alignment=0x100
LITE_OS_SEC_VEC LITE_OS_SEC_VEC
#endif #endif
HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = { HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {0};
(HWI_PROC_FUNC)0, // [0] Top of Stack
(HWI_PROC_FUNC)Reset_Handler, // [1] reset
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [2] NMI Handler
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [3] Hard Fault Handler
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [4] MPU Fault Handler
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [5] Bus Fault Handler
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [6] Usage Fault Handler
(HWI_PROC_FUNC)0, // [7] Reserved
(HWI_PROC_FUNC)0, // [8] Reserved
(HWI_PROC_FUNC)0, // [9] Reserved
(HWI_PROC_FUNC)0, // [10] Reserved
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [11] SVCall Handler
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [12] Debug Monitor Handler
(HWI_PROC_FUNC)0, // [13] Reserved
(HWI_PROC_FUNC)osPendSV, // [14] PendSV Handler
(HWI_PROC_FUNC)SysTickHandler, // [15] SysTick Handler
};
#if (OS_HWI_WITH_ARG == 1)
#if (OS_HWI_WITH_ARG == YES)
HWI_SLAVE_FUNC g_hwiSlaveForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }}; HWI_SLAVE_FUNC g_hwiSlaveForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
#else #else
HWI_PROC_FUNC g_hwiSlaveForm[OS_VECTOR_CNT] = {0}; HWI_PROC_FUNC g_hwiSlaveForm[OS_VECTOR_CNT] = {0};
#endif #endif
/* **************************************************************************** /* ****************************************************************************
Function : OsIntNumGet Function : HalIntNumGet
Description : Get a interrupt number Description : Get a interrupt number
Input : None Input : None
Output : None Output : None
Return : Interrupt Indexes number Return : Interrupt Indexes number
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_MINOR UINT32 OsIntNumGet(VOID) LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
{ {
return __get_IPSR(); return __get_IPSR();
} }
inline UINT32 HalIsIntAcvive(VOID)
{
return (g_intCount > 0);
}
/* **************************************************************************** /* ****************************************************************************
Function : OsHwiDefaultHandler Function : HalHwiDefaultHandler
Description : default handler of the hardware interrupt Description : default handler of the hardware interrupt
Input : None Input : None
Output : None Output : None
Return : None Return : None
**************************************************************************** */ **************************************************************************** */
/*lint -e529*/ /*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID OsHwiDefaultHandler(VOID) LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
{ {
UINT32 irqNum = OsIntNumGet(); UINT32 irqNum = HalIntNumGet();
PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum); PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
while (1) {} while (1) {}
} }
/* **************************************************************************** /* ****************************************************************************
Function : OsInterrupt Function : HalInterrupt
Description : Hardware interrupt entry function Description : Hardware interrupt entry function
Input : None Input : None
Output : None Output : None
Return : None Return : None
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT VOID OsInterrupt(VOID) LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
{ {
UINT32 hwiIndex; UINT32 hwiIndex;
UINT32 intSave; UINT32 intSave;
#if (LOSCFG_KERNEL_RUNSTOP == YES) #if (LOSCFG_KERNEL_RUNSTOP == 1)
SCB->SCR &= (UINT32) ~((UINT32)SCB_SCR_SLEEPDEEP_Msk); SCB->SCR &= (UINT32) ~((UINT32)SCB_SCR_SLEEPDEEP_Msk);
#endif #endif
intSave = LOS_IntLock(); intSave = LOS_IntLock();
g_vuwIntCount++; g_intCount++;
LOS_IntRestore(intSave); LOS_IntRestore(intSave);
hwiIndex = OsIntNumGet(); hwiIndex = HalIntNumGet();
#if (LOSCFG_KERNEL_TICKLESS == YES)
osUpdateKernelTickCount(hwiIndex);
#endif
#if (OS_HWI_WITH_ARG == YES) #if (OS_HWI_WITH_ARG == 1)
if (g_hwiSlaveForm[hwiIndex].pfnHandler != 0) { if (g_hwiSlaveForm[hwiIndex].pfnHandler != 0) {
g_hwiSlaveForm[hwiIndex].pfnHandler((VOID *)g_hwiSlaveForm[hwiIndex].pParm); g_hwiSlaveForm[hwiIndex].pfnHandler((VOID *)g_hwiSlaveForm[hwiIndex].pParm);
} }
@ -145,12 +124,12 @@ LITE_OS_SEC_TEXT VOID OsInterrupt(VOID)
} }
#endif #endif
intSave = LOS_IntLock(); intSave = LOS_IntLock();
g_vuwIntCount--; g_intCount--;
LOS_IntRestore(intSave); LOS_IntRestore(intSave);
} }
/* **************************************************************************** /* ****************************************************************************
Function : LOS_HwiCreate Function : HalHwiCreate
Description : create hardware interrupt Description : create hardware interrupt
Input : hwiNum --- hwi num to create Input : hwiNum --- hwi num to create
hwiPrio --- priority of the hwi hwiPrio --- priority of the hwi
@ -160,7 +139,7 @@ LITE_OS_SEC_TEXT VOID OsInterrupt(VOID)
Output : None Output : None
Return : LOS_OK on success or error code on failure Return : LOS_OK on success or error code on failure
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum, LITE_OS_SEC_TEXT_INIT UINT32 HalHwiCreate(HWI_HANDLE_T hwiNum,
HWI_PRIOR_T hwiPrio, HWI_PRIOR_T hwiPrio,
HWI_MODE_T mode, HWI_MODE_T mode,
HWI_PROC_FUNC handler, HWI_PROC_FUNC handler,
@ -176,7 +155,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
return OS_ERRNO_HWI_NUM_INVALID; return OS_ERRNO_HWI_NUM_INVALID;
} }
if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)OsHwiDefaultHandler) { if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
return OS_ERRNO_HWI_ALREADY_CREATED; return OS_ERRNO_HWI_ALREADY_CREATED;
} }
@ -185,7 +164,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
} }
intSave = LOS_IntLock(); intSave = LOS_IntLock();
#if (OS_HWI_WITH_ARG == YES) #if (OS_HWI_WITH_ARG == 1)
OsSetVector(hwiNum, handler, arg); OsSetVector(hwiNum, handler, arg);
#else #else
OsSetVector(hwiNum, handler); OsSetVector(hwiNum, handler);
@ -199,13 +178,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
} }
/* **************************************************************************** /* ****************************************************************************
Function : LOS_HwiDelete Function : HalHwiDelete
Description : Delete hardware interrupt Description : Delete hardware interrupt
Input : hwiNum --- hwi num to delete Input : hwiNum --- hwi num to delete
Output : None Output : None
Return : LOS_OK on success or error code on failure Return : LOS_OK on success or error code on failure
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum) LITE_OS_SEC_TEXT_INIT UINT32 HalHwiDelete(HWI_HANDLE_T hwiNum)
{ {
UINT32 intSave; UINT32 intSave;
@ -217,7 +196,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum)
intSave = LOS_IntLock(); intSave = LOS_IntLock();
g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)OsHwiDefaultHandler; g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
LOS_IntRestore(intSave); LOS_IntRestore(intSave);
@ -235,9 +214,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum)
static ExcInfoArray g_excArray[OS_EXC_TYPE_MAX]; static ExcInfoArray g_excArray[OS_EXC_TYPE_MAX];
UINT32 g_curNestCount = 0; static ExcInfo g_excInfo = {0};
static ExcInfo g_excInfo;
static EVENT_CB_S g_excEvent;
UINT8 g_uwExcTbl[FAULT_STATUS_REG_BIT] = { UINT8 g_uwExcTbl[FAULT_STATUS_REG_BIT] = {
0, 0, 0, 0, 0, 0, OS_EXC_UF_DIVBYZERO, OS_EXC_UF_UNALIGNED, 0, 0, 0, 0, 0, 0, OS_EXC_UF_DIVBYZERO, OS_EXC_UF_UNALIGNED,
@ -246,16 +223,7 @@ UINT8 g_uwExcTbl[FAULT_STATUS_REG_BIT] = {
0, 0, 0, OS_EXC_MF_MSTKERR, OS_EXC_MF_MUNSTKERR, 0, OS_EXC_MF_DACCVIOL, OS_EXC_MF_IACCVIOL 0, 0, 0, OS_EXC_MF_MSTKERR, OS_EXC_MF_MUNSTKERR, 0, OS_EXC_MF_DACCVIOL, OS_EXC_MF_IACCVIOL
}; };
__attribute__((noinline)) VOID LOS_Panic(const CHAR *fmt, ...) UINT32 HalExcNvicDump(UINT32 index, UINT32 *excContent)
{
va_list ap;
va_start(ap,fmt);
PRINT_ERR(fmt, ap);
va_end(ap);
asm volatile ("swi 0");
}
UINT32 OsExcNvicDump(UINT32 index, UINT32 *excContent)
{ {
UINT32 *base = NULL; UINT32 *base = NULL;
UINT32 len = 0, i, j; UINT32 len = 0, i, j;
@ -286,9 +254,10 @@ UINT32 OsExcNvicDump(UINT32 index, UINT32 *excContent)
} }
PRINTK("\n"); PRINTK("\n");
} }
return 0;
} }
UINT32 OsExcContextDump(UINT32 index, UINT32 *excContent) UINT32 HalExcContextDump(UINT32 index, UINT32 *excContent)
{ {
(VOID)index; (VOID)index;
(VOID)excContent; (VOID)excContent;
@ -315,9 +284,10 @@ UINT32 OsExcContextDump(UINT32 index, UINT32 *excContent)
PRINTK("LR = 0x%x\n", g_excInfo.context->uwLR); PRINTK("LR = 0x%x\n", g_excInfo.context->uwLR);
PRINTK("PC = 0x%x\n", g_excInfo.context->uwPC); PRINTK("PC = 0x%x\n", g_excInfo.context->uwPC);
PRINTK("xPSR = 0x%x\n", g_excInfo.context->uwxPSR); PRINTK("xPSR = 0x%x\n", g_excInfo.context->uwxPSR);
return 0;
} }
VOID OsDumpMsg(VOID) VOID HalDumpMsg(VOID)
{ {
UINT32 index = 0; UINT32 index = 0;
for (index = 0; index < (OS_EXC_TYPE_MAX - 1); index++) { for (index = 0; index < (OS_EXC_TYPE_MAX - 1); index++) {
@ -328,21 +298,11 @@ VOID OsDumpMsg(VOID)
} }
} }
VOID OsExcNotify(VOID) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr)
{
UINT32 ret = LOS_EventWrite(&g_excEvent, OS_EXC_EVENT);
if (ret != LOS_OK) {
PRINT_ERR("event notify failed\n");
}
}
LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid,
EXC_CONTEXT_S *excBufAddr)
{ {
UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT;
g_curNestCount++; g_intCount++;
g_vuwIntCount++; g_excInfo.nestCnt++;
g_excInfo.nestCnt = g_curNestCount;
g_excInfo.type = excType & OS_NULL_SHORT; g_excInfo.type = excType & OS_NULL_SHORT;
@ -351,7 +311,6 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UI
} else { } else {
g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR;
} }
if (g_losTask.runTask != NULL) { if (g_losTask.runTask != NULL) {
if (tmpFlag & OS_EXC_FLAG_IN_HWI) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) {
g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.phase = OS_EXC_IN_HWI;
@ -364,25 +323,20 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UI
g_excInfo.phase = OS_EXC_IN_INIT; g_excInfo.phase = OS_EXC_IN_INIT;
g_excInfo.thrdPid = OS_NULL_INT; g_excInfo.thrdPid = OS_NULL_INT;
} }
if (excType & OS_EXC_FLAG_NO_FLOAT) { if (excType & OS_EXC_FLAG_NO_FLOAT) {
g_excInfo.context = (EXC_CONTEXT_S *)((CHAR *)excBufAddr - LOS_OFF_SET_OF(EXC_CONTEXT_S, uwR4)); g_excInfo.context = (EXC_CONTEXT_S *)((CHAR *)excBufAddr - LOS_OFF_SET_OF(EXC_CONTEXT_S, uwR4));
} else { } else {
g_excInfo.context = excBufAddr; g_excInfo.context = excBufAddr;
} }
HalDumpMsg();
OsDumpMsg(); HalSysExit();
OsExcNotify();
LOS_Reboot();
} }
VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg) VOID HalExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg)
{ {
ExcInfoArray *excInfo = NULL; ExcInfoArray *excInfo = NULL;
if ((type >= OS_EXC_TYPE_MAX) || (func == NULL)) { if ((type >= OS_EXC_TYPE_MAX) || (func == NULL)) {
PRINT_ERR("OsExcRegister ERROR!\n"); PRINT_ERR("HalExcRegister ERROR!\n");
return; return;
} }
excInfo = &(g_excArray[type]); excInfo = &(g_excArray[type]);
@ -392,33 +346,29 @@ VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg)
excInfo->uwValid = TRUE; excInfo->uwValid = TRUE;
} }
void OsBackTrace()
{
}
/* **************************************************************************** /* ****************************************************************************
Function : OsHwiInit Function : HalHwiInit
Description : initialization of the hardware interrupt Description : initialization of the hardware interrupt
Input : None Input : None
Output : None Output : None
Return : None Return : None
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID OsHwiInit() LITE_OS_SEC_TEXT_INIT VOID HalHwiInit()
{ {
UINT32 index; UINT32 index;
UINT32 ret; g_hwiForm[0] = 0; /* [0] Top of Stack */
g_hwiForm[1] = Reset_Handler; /* [1] reset */
for (index = OS_SYS_VECTOR_CNT; index < OS_VECTOR_CNT; index++) { for (index = 2; index < OS_VECTOR_CNT; index++) {
g_hwiForm[index] = (HWI_PROC_FUNC)OsHwiDefaultHandler; g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
} }
/* Exception handler register */ /* Exception handler register */
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = OsExcHardFault; g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = OsExcNMI; g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = OsExcMemFault; g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = OsExcBusFault; g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = OsExcUsageFault; g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = OsExcSvcCall; g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalExcSvcCall;
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
/* Interrupt vector table location */ /* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm; SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;
@ -431,15 +381,9 @@ LITE_OS_SEC_TEXT_INIT VOID OsHwiInit()
/* Enable DIV 0 and unaligned exception */ /* Enable DIV 0 and unaligned exception */
*(volatile UINT32 *)OS_NVIC_CCR |= DIV0FAULT; *(volatile UINT32 *)OS_NVIC_CCR |= DIV0FAULT;
/* Init Exception Event */ HalExcRegister(OS_EXC_TYPE_CONTEXT, (EXC_INFO_SAVE_CALLBACK)HalExcContextDump, NULL);
ret = LOS_EventInit(&g_excEvent); HalExcRegister(OS_EXC_TYPE_NVIC, (EXC_INFO_SAVE_CALLBACK)HalExcNvicDump, NULL);
if (ret != LOS_OK) {
PRINT_ERR("[EXC]init excepiton event failed!\n");
return;
}
OsExcRegister(OS_EXC_TYPE_CONTEXT, (EXC_INFO_SAVE_CALLBACK)OsExcContextDump, NULL);
OsExcRegister(OS_EXC_TYPE_NVIC, (EXC_INFO_SAVE_CALLBACK)OsExcNvicDump, NULL);
return; return;
} }

View File

@ -29,7 +29,7 @@
THUMB THUMB
IMPORT ||Image$$ARM_LIB_STACKHEAP$$ZI$$Limit|| IMPORT ||Image$$ARM_LIB_STACKHEAP$$ZI$$Limit||
IMPORT OsHwiDefaultHandler IMPORT HalHwiDefaultHandler
EXPORT _BootVectors EXPORT _BootVectors
EXPORT Reset_Handler EXPORT Reset_Handler
@ -37,8 +37,8 @@
_BootVectors _BootVectors
DCD ||Image$$ARM_LIB_STACKHEAP$$ZI$$Limit|| DCD ||Image$$ARM_LIB_STACKHEAP$$ZI$$Limit||
DCD Reset_Handler DCD Reset_Handler
DCD OsHwiDefaultHandler DCD HalHwiDefaultHandler
DCD OsHwiDefaultHandler DCD HalHwiDefaultHandler
Reset_Handler Reset_Handler

View File

@ -28,29 +28,28 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "los_config.h"
#include "los_tick.h" #include "los_tick.h"
#include "los_interrupt.h" #include "los_arch_interrupt.h"
#include "ARMCM3.h" #include "ARMCM3.h"
#include "los_timer.h"
#include "los_context.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
#endif /* __cpluscplus */ #endif /* __cpluscplus */
#endif /* __cpluscplus */ #endif /* __cpluscplus */
#define TICK_CHECK 0x4000000
#define CYCLE_CHECK 0xFFFFFFFFU
#define SHIFT_32_BIT 32
/* **************************************************************************** /* ****************************************************************************
Function : OsTickStart Function : HalTickStart
Description : Configure Tick Interrupt Start Description : Configure Tick Interrupt Start
Input : none Input : none
output : none output : none
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_INIT UINT32 OsTickStart(VOID) LITE_OS_SEC_TEXT_INIT UINT32 HalTickStart(OS_TICK_HANDLER *handler)
{ {
UINT32 ret; UINT32 ret;
@ -60,10 +59,10 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTickStart(VOID)
return LOS_ERRNO_TICK_CFG_INVALID; return LOS_ERRNO_TICK_CFG_INVALID;
} }
#if (OS_HWI_WITH_ARG == YES) #if (OS_HWI_WITH_ARG == 1)
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)OsTickHandler, NULL); OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
#else #else
OsSetVector(SysTick_IRQn, OsTickHandler); OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
#endif #endif
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND; g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
@ -77,32 +76,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTickStart(VOID)
return LOS_OK; return LOS_OK;
} }
#if (LOSCFG_KERNEL_TICKLESS == YES)
/* **************************************************************************** /* ****************************************************************************
Function : LOS_SysTickReload Function : HalSysTickCurrCycleGet
Description : reconfig systick, and clear SysTick_IRQn
Input : cyclesPerTick --- cycles Per Tick
output : none
return : none
**************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID LOS_SysTickReload(UINT32 cyclesPerTick)
{
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
NVIC_ClearPendingIRQ(SysTick_IRQn);
SysTick->LOAD = (UINT32)(cyclesPerTick - 1UL); /* set reload register */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
}
#endif
/* ****************************************************************************
Function : LOS_SysTickCurrCycleGet
Description : Get System cycle count Description : Get System cycle count
Input : none Input : none
output : none output : none
return : hwCycle --- the system cycle count return : hwCycle --- the system cycle count
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysTickCurrCycleGet(VOID) LITE_OS_SEC_TEXT_MINOR UINT32 HalSysTickCurrCycleGet(VOID)
{ {
UINT32 hwCycle; UINT32 hwCycle;
UINTPTR intSave; UINTPTR intSave;
@ -122,14 +103,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysTickCurrCycleGet(VOID)
} }
/* **************************************************************************** /* ****************************************************************************
Function : LOS_GetCpuCycle Function : HalGetCpuCycle
Description : Get System cycle count Description : Get System cycle count
Input : none Input : none
output : cntHi --- CpuTick High 4 byte output : cntHi --- CpuTick High 4 byte
cntLo --- CpuTick Low 4 byte cntLo --- CpuTick Low 4 byte
return : none return : none
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *cntHi, UINT32 *cntLo) LITE_OS_SEC_TEXT_MINOR VOID HalGetCpuCycle(UINT32 *cntHi, UINT32 *cntLo)
{ {
UINT64 swTick; UINT64 swTick;
UINT64 cycle; UINT64 cycle;
@ -158,14 +139,14 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *cntHi, UINT32 *cntLo)
} }
/* **************************************************************************** /* ****************************************************************************
Function : LOS_GetSystickCycle Function : HalGetSystickCycle
Description : Get Sys tick cycle count Description : Get Sys tick cycle count
Input : none Input : none
output : cntHi --- SysTick count High 4 byte output : cntHi --- SysTick count High 4 byte
cntLo --- SysTick count Low 4 byte cntLo --- SysTick count Low 4 byte
return : none return : none
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetSystickCycle(UINT32 *cntHi, UINT32 *cntLo) LITE_OS_SEC_TEXT_MINOR VOID HalGetSystickCycle(UINT32 *cntHi, UINT32 *cntLo)
{ {
UINT64 swTick; UINT64 swTick;
UINT64 cycle; UINT64 cycle;
@ -201,59 +182,46 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_GetSystickCycle(UINT32 *cntHi, UINT32 *cntLo)
return; return;
} }
#define MAX_HOUR 24
#define MAX_MINUTES 60
#define MAX_SECONDS 60
#define MILSEC 1000
#define RTC_WAKEUPCLOCK_RTCCLK 32768
#define RTC_WAKEUPCLOCK_RTCCLK_DIV 16
#define RTC_CALIBRATE_SLEEP_TIME 8
#define MACHINE_CYCLE_DEALAY_TIMES 4000
static BOOL g_sysSleepFlag = FALSE; static BOOL g_sysSleepFlag = FALSE;
VOID LOS_TickLock(VOID) VOID HalTickLock(VOID)
{ {
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
} }
VOID LOS_TickUnlock(VOID) VOID HalTickUnlock(VOID)
{ {
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
} }
BOOL LOS_GetSysSleepFlag(VOID) BOOL HalGetSysSleepFlag(VOID)
{ {
return g_sysSleepFlag; return g_sysSleepFlag;
} }
VOID LOS_ClearSysSleepFlag(VOID) VOID HalClearSysSleepFlag(VOID)
{ {
g_sysSleepFlag = FALSE; g_sysSleepFlag = FALSE;
} }
VOID LOS_EnterSleep(LOS_SysSleepEnum sleep) VOID HalEnterSleep(LOS_SysSleepEnum sleep)
{ {
__DSB(); __DSB();
__WFI(); __WFI();
__ISB(); __ISB();
} }
VOID LOS_SystemWakeup(UINT32 hwiIndex)
{
}
//extern unsigned int SystemCoreClock; //extern unsigned int SystemCoreClock;
void LOS_HalDelay(UINT32 ticks) void HalDelay(UINT32 ticks)
{ {
UINT32 delayTimes;
#if 0 #if 0
UINT32 delayTimes;
/* there are 4 machine cycle in loop */ /* there are 4 machine cycle in loop */
if ((ticks * (SystemCoreClock / MACHINE_CYCLE_DEALAY_TIMES)) >= 0xffffffff) { if ((ticks * (SystemCoreClock / MACHINE_CYCLE_DEALAY_TIMES)) >= 0xffffffff) {
delayTimes = 0xffffffff; delayTimes = 0xffffffff;
} else { } else {
delayTimes = ticks * (SystemCoreClock / MACHINE_CYCLE_DEALAY_TIMES); delayTimes = ticks * (SystemCoreClock / MACHINE_CYCLE_DEALAY_TIMES);
} }
while (delayTimes) { while (delayTimes) {
delayTimes = delayTimes - 1; delayTimes = delayTimes - 1;
} }

View File

@ -0,0 +1,161 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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_ATOMIC_H
#define LOS_ATOMIC_H
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_atomic
* @brief Atomic exchange for 32-bit variable.
*
* @par Description:
* This API is used to implement the atomic exchange for 32-bit variable and return the previous value of the atomic variable.
* @attention
* <ul>The pointer v must not be NULL.</ul>
*
* @param v [IN] The variable pointer.
* @param val [IN] The exchange value.
*
* @retval #INT32 The previous value of the atomic variable
* @par Dependency:
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V100R001C00
*/
STATIC INLINE INT32 HalAtomicXchg32bits(volatile INT32 *v, INT32 val)
{
INT32 prevVal = 0;
UINT32 status = 0;
do {
__asm__ __volatile__("ldrex %0, [%3]\n"
"strex %1, %4, [%3]"
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
: "r"(v), "r"(val)
: "cc");
} while (__builtin_expect(status != 0, 0));
return prevVal;
}
/**
* @ingroup los_atomic
* @brief Atomic auto-decrement.
*
* @par Description:
* This API is used to implementating the atomic auto-decrement and return the result of auto-decrement.
* @attention
* <ul>
* <li>The pointer v must not be NULL.</li>
* <li>The value which v point to must not be INT_MIN to avoid overflow after reducing 1.</li>
* </ul>
*
* @param v [IN] The addSelf variable pointer.
*
* @retval #INT32 The return value of variable auto-decrement.
* @par Dependency:
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V100R001C00
*/
STATIC INLINE INT32 HalAtomicDecRet(volatile INT32 *v)
{
INT32 val = 0;
UINT32 status = 0;
do {
__asm__ __volatile__("ldrex %0, [%3]\n"
"sub %0, %0, #1\n"
"strex %1, %0, [%3]"
: "=&r"(val), "=&r"(status), "+m"(*v)
: "r"(v)
: "cc");
} while (__builtin_expect(status != 0, 0));
return val;
}
/**
* @ingroup los_atomic
* @brief Atomic exchange for 32-bit variable with compare.
*
* @par Description:
* This API is used to implement the atomic exchange for 32-bit variable, if the value of variable is equal to oldVal.
* @attention
* <ul>The pointer v must not be NULL.</ul>
*
* @param v [IN] The variable pointer.
* @param val [IN] The new value.
* @param oldVal [IN] The old value.
*
* @retval TRUE The previous value of the atomic variable is not equal to oldVal.
* @retval FALSE The previous value of the atomic variable is equal to oldVal.
* @par Dependency:
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
* @see
* @since Huawei LiteOS V100R001C00
*/
STATIC INLINE BOOL HalAtomicCmpXchg32bits(volatile INT32 *v, INT32 val, INT32 oldVal)
{
INT32 prevVal = 0;
UINT32 status = 0;
do {
__asm__ __volatile__("1: ldrex %0, %2\n"
" mov %1, #0\n"
" cmp %0, %3\n"
" bne 2f\n"
" strex %1, %4, %2\n"
"2:"
: "=&r"(prevVal), "=&r"(status), "+Q"(*v)
: "r"(oldVal), "r"(val)
: "cc");
} while (__builtin_expect(status != 0, 0));
return prevVal != oldVal;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* LOS_ATOMIC_H */

View File

@ -29,42 +29,18 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** #ifndef _LOS_ARCH_CONTEXT_H
* @defgroup los_hw hardware #define _LOS_ARCH_CONTEXT_H
* @ingroup kernel
*/
#ifndef _LOS_HW_H #include "los_config.h"
#define _LOS_HW_H #include "los_compiler.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cpluscplus */
#endif /* __cplusplus */ #endif /* __cpluscplus */
/* *
* @ingroup los_hw
* The initialization value of stack space.
*/
#define EMPTY_STACK 0xCACA
/* *
* @ingroup los_hw
* Trigger a task.
*/
#define OsTaskTrap() __asm(" TRAP #31")
/* *
* @ingroup los_hw
* Check task schedule.
*/
#define LOS_CHECK_SCHEDULE ((!g_losTaskLock))
/* *
* @ingroup los_hw
* Define the type of a task context control block.
*/
typedef struct tagTskContext { typedef struct tagTskContext {
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ #if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U))) (defined(__FPU_USED) && (__FPU_USED == 1U)))
@ -126,69 +102,30 @@ typedef struct tagTskContext {
} TaskContext; } TaskContext;
/** /**
* @ingroup los_hw * @ingroup los_config
* @brief: Task stack initialization. * @brief: Task start running function.
* *
* @par Description: * @par Description:
* This API is used to initialize the task stack. * This API is used to start a task.
* *
* @attention: * @attention:
* <ul><li>None.</li></ul> * <ul><li>None.</li></ul>
* *
* @param taskID [IN] Type#UINT32: TaskID. * @param: None.
* @param stackSize [IN] Type#UINT32: Total size of the stack. *
* @param topStack [IN] Type#VOID *: Top of task's stack. * @retval None.
* *
* @retval: context Type#TaskContext *.
* @par Dependency: * @par Dependency:
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul> * <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
* @see None. * @see None.
*/ */
extern VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack); extern VOID HalStartToRun(VOID);
/**
* @ingroup los_hw
* @brief: Function to task exit.
*
* @par Description:
* This API is used to exit task.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param None.
*
* @retval: None.
* @par Dependency:
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
LITE_OS_SEC_TEXT_MINOR VOID OsTaskExit(VOID);
/* *
* @ingroup los_hw
* @brief: The M3 wait interrupt instruction.
*
* @par Description:
* This API is used to make CPU enter to power-save mode.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param None.
*
* @retval: None.
* @par Dependency:
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID OsEnterSleep(VOID);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cpluscplus */
#endif /* __cplusplus */ #endif /* __cpluscplus */
#endif /* _LOS_HW_H */ #endif /* _LOS_ARCH_CONTEXT_H */

View File

@ -34,6 +34,7 @@
#include "los_config.h" #include "los_config.h"
#include "los_compiler.h" #include "los_compiler.h"
#include "los_interrupt.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
@ -65,55 +66,6 @@ extern "C" {
#define OS_HWI_PRIO_LOWEST 7 #define OS_HWI_PRIO_LOWEST 7
#endif #endif
/* *
* @ingroup los_config
* Configuration item for interrupt with argument
*/
#ifndef OS_HWI_WITH_ARG
#define OS_HWI_WITH_ARG NO
#endif
/* *
* @ingroup los_hwi
* Define the type of a hardware interrupt number.
*/
typedef UINT32 HWI_HANDLE_T;
/* *
* @ingroup los_hwi
* Define the type of a hardware interrupt priority.
*/
typedef UINT16 HWI_PRIOR_T;
/* *
* @ingroup los_hwi
* Define the type of hardware interrupt mode configurations.
*/
typedef UINT16 HWI_MODE_T;
/* *
* @ingroup los_hwi
* Define the type of the parameter used for the hardware interrupt creation function. The function of this parameter varies among platforms.
*/
typedef UINT32 HWI_ARG_T;
/* *
* @ingroup los_hwi
* Define the type of a hardware interrupt handling function.
*/
#if (OS_HWI_WITH_ARG == YES)
typedef VOID (*HWI_PROC_FUNC)(VOID *parm);
typedef struct {
HWI_PROC_FUNC pfnHandler;
VOID *pParm;
} HWI_SLAVE_FUNC;
#else
typedef VOID (*HWI_PROC_FUNC)(void);
#endif
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
@ -125,19 +77,7 @@ typedef VOID (**HWI_VECTOR_FUNC)(void);
* @ingroup los_hwi * @ingroup los_hwi
* Count of interrupts. * Count of interrupts.
*/ */
extern UINT32 g_vuwIntCount; extern UINT32 g_intCount;
/* *
* @ingroup los_hwi
* An interrupt is active.
*/
#define OS_INT_ACTIVE (g_vuwIntCount > 0)
/* *
* @ingroup los_hwi
* An interrupt is inactive.
*/
#define OS_INT_INACTIVE (!(OS_INT_ACTIVE))
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
@ -375,7 +315,7 @@ extern UINT32 _BootVectors[];
*/ */
extern HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT]; extern HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT];
#if (OS_HWI_WITH_ARG == YES) #if (OS_HWI_WITH_ARG == 1)
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
* hardware interrupt Slave form mapping handling function array. * hardware interrupt Slave form mapping handling function array.
@ -388,7 +328,7 @@ extern HWI_SLAVE_FUNC g_hwiSlaveForm[OS_VECTOR_CNT];
*/ */
#define OsSetVectonr(num, vector, arg) \ #define OsSetVectonr(num, vector, arg) \
do { \ do { \
g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)OsInterrupt; \ g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalInterrupt; \
g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector; \ g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector; \
g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT].pParm = (VOID *)arg; \ g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT].pParm = (VOID *)arg; \
} while(0) } while(0)
@ -405,47 +345,11 @@ extern HWI_PROC_FUNC g_hwiSlaveForm[OS_VECTOR_CNT];
*/ */
#define OsSetVector(num, vector) \ #define OsSetVector(num, vector) \
do { \ do { \
g_hwiForm[num + OS_SYS_VECTOR_CNT] = OsInterrupt; \ g_hwiForm[num + OS_SYS_VECTOR_CNT] = HalInterrupt; \
g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT] = vector; \ g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT] = vector; \
} while(0) } while(0)
#endif #endif
/* *
* @ingroup los_hwi
* @brief Create a hardware interrupt.
*
* @par Description:
* This API is used to configure a hardware interrupt and register a hardware interrupt handling function.
*
* @attention
* <ul>
* <li>The hardware interrupt module is usable only when the configuration item for hardware interrupt tailoring is enabled.</li>
* <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range applicable for a Cortex-A7 platform is [32,95].</li>
* <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
* <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
* </ul>
*
* @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a Cortex-A7 platform is [32,95].
* @param hwiPrio [IN] Type#HWI_PRIOR_T: hardware interrupt priority. Ignore this parameter temporarily.
* @param mode [IN] Type#HWI_MODE_T: hardware interrupt mode. Ignore this parameter temporarily.
* @param handler [IN] Type#HWI_PROC_FUNC: interrupt handler used when a hardware interrupt is triggered.
* @param arg [IN] Type#HWI_ARG_T: input parameter of the interrupt handler used when a hardware interrupt is triggered.
*
* @retval #OS_ERRNO_HWI_PROC_FUNC_NULL 0x02000901: Null hardware interrupt handling function.
* @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
* @retval #OS_ERRNO_HWI_NO_MEMORY 0x02000903: Insufficient memory for hardware interrupt creation.
* @retval #OS_ERRNO_HWI_ALREADY_CREATED 0x02000904: The interrupt handler being created has already been created.
* @retval #LOS_OK 0 : The interrupt is successfully created.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
HWI_PRIOR_T hwiPrio,
HWI_MODE_T mode,
HWI_PROC_FUNC handler,
HWI_ARG_T arg);
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
* @brief: Hardware interrupt entry function. * @brief: Hardware interrupt entry function.
@ -463,7 +367,7 @@ extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul> * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None. * @see None.
*/ */
extern VOID OsInterrupt(VOID); extern VOID HalInterrupt(VOID);
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
@ -482,7 +386,7 @@ extern VOID OsInterrupt(VOID);
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul> * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None. * @see None.
*/ */
extern UINT32 OsIntNumGet(VOID); extern UINT32 HalIntNumGet(VOID);
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
@ -502,7 +406,7 @@ extern UINT32 OsIntNumGet(VOID);
></ul> ></ul>
* @see None. * @see None.
*/ */
extern VOID OsHwiDefaultHandler(VOID); extern VOID HalHwiDefaultHandler(VOID);
/* * /* *
* @ingroup los_hwi * @ingroup los_hwi
@ -541,186 +445,8 @@ extern VOID Reset_Handler(VOID);
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul> * <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None. * @see None.
*/ */
extern VOID osPendSV(VOID); extern VOID HalPendSV(VOID);
/* *
* @ingroup los_hwi
* @brief Enable all interrupts.
*
* @par Description:
* <ul>
* <li>This API is used to enable all IRQ and FIQ interrupts in the CPSR.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval CPSR value obtained after all interrupts are enabled.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntRestore
*/
extern UINTPTR LOS_IntUnLock(VOID);
/* *
* @ingroup los_hwi
* @brief Disable all interrupts.
*
* @par Description:
* <ul>
* <li>This API is used to disable all IRQ and FIQ interrupts in the CPSR.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval CPSR value obtained before all interrupts are disabled.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntRestore
*/
extern UINTPTR LOS_IntLock(VOID);
/* *
* @ingroup los_hwi
* @brief Restore interrupts.
*
* @par Description:
* <ul>
* <li>This API is used to restore the CPSR value obtained before all interrupts are disabled.</li>
* </ul>
* @attention
* <ul>
* <li>This API can be called only after all interrupts are disabled, and the input parameter value should be the value returned by calling the all interrupt disabling API.</li>
* </ul>
*
* @param intSave [IN] CPSR value obtained before all interrupts are disabled.
*
* @retval None.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntLock
*/
extern VOID LOS_IntRestore(UINTPTR intSave);
/* *
* @ingroup los_hwi
* @brief Get value from xPSR register.
*
* @par Description:
* <ul>
* <li>This API is used to Get value from xPSR register.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param cntHi [IN] CpuTick High 4 byte
* @param cntLo [IN] CpuTick Low 4 byte
*
* @retval None.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntRestore
*/
extern VOID LOS_GetCpuCycle(UINT32 *cntHi, UINT32 *cntLo);
#if (LOSCFG_KERNEL_TICKLESS == YES)
/**
* @ingroup los_hwi
* @brief reconfig systick, and clear SysTick_IRQn.
*
* @par Description:
* <ul>
* <li>This API is used to reconfig systick, and clear SysTick_IRQn.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param cyclesPerTick [IN] Cycles Per Tick
*
* @retval None.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntRestore
*/
extern VOID LOS_SysTickReload(UINT32 cyclesPerTick);
#endif
/**
* @ingroup los_hwi
* @brief Get System cycle count.
*
* @par Description:
* <ul>
* <li>This API is used to Get System cycle count.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval: The value of the system cycle count.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntRestore
*/
extern UINT32 LOS_SysTickCurrCycleGet(VOID);
extern VOID LOS_GetSystickCycle(UINT32 *puwCntHi, UINT32 *puwCntLo);
/* *
* @ingroup los_hwi
* @brief Delete hardware interrupt.
*
* @par Description:
* This API is used to delete hardware interrupt.
*
* @attention
* <ul>
* <li>The hardware interrupt module is usable only when the configuration item for hardware interrupt tailoring is enabled.</li>
* <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range applicable for a Cortex-A7 platform is [32,95].</li>
* <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
* <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
* </ul>
*
* @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a Cortex-A7 platform is [32,95].
*
* @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
* @retval #LOS_OK 0 : The interrupt is successfully delete.
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum);
typedef enum {
OS_SYS_NORMAL_SLEEP = 0,
OS_SYS_DEEP_SLEEP,
} LOS_SysSleepEnum;
VOID LOS_TickLock(VOID);
VOID LOS_TickUnlock(VOID);
BOOL LOS_GetSysSleepFlag(VOID);
VOID LOS_ClearSysSleepFlag(VOID);
VOID LOS_EnterSleep(LOS_SysSleepEnum sleep);
VOID LOS_SystemWakeup(UINT32 hwiIndex);
#define OS_EXC_IN_INIT 0 #define OS_EXC_IN_INIT 0
#define OS_EXC_IN_TASK 1 #define OS_EXC_IN_TASK 1
@ -818,9 +544,8 @@ typedef struct tagExcContext {
#endif #endif
}EXC_CONTEXT_S; }EXC_CONTEXT_S;
typedef UINT32 (*EXC_INFO_SAVE_CALLBACK)(UINT32, VOID*);
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *); typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr); VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
/** /**
* @ingroup los_hwi * @ingroup los_hwi
@ -841,33 +566,14 @@ VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_
*/ */
VOID OsExcInit(VOID); VOID OsExcInit(VOID);
extern VOID OsExcNMI(VOID); VOID HalExcNMI(VOID);
extern VOID OsExcHardFault(VOID); VOID HalExcHardFault(VOID);
extern VOID OsExcMemFault(VOID); VOID HalExcMemFault(VOID);
extern VOID OsExcBusFault(VOID); VOID HalExcBusFault(VOID);
extern VOID OsExcUsageFault(VOID); VOID HalExcUsageFault(VOID);
extern VOID OsExcSvcCall(VOID); VOID HalExcSvcCall(VOID);
extern UINT8 g_aucTaskArray[]; VOID HalHwiInit();
extern void OsBackTrace();
/**
*@ingroup los_exc
*@brief Kernel panic function.
*
*@par Description:
*Stack function that prints kernel panics.
*@attention After this function is called and stack information is printed, the system will fail to respond.
*@attention The input parameter can be NULL.
*@param fmt [IN] Type #char* : variadic argument.
*
*@retval #None.
*
*@par Dependency:
*los_interrupt.h: the header file that contains the API declaration.
*@see None.
*/
VOID LOS_Panic(const CHAR *fmt, ...);
/** /**
*@ingroup los_exc *@ingroup los_exc
@ -1022,22 +728,14 @@ typedef struct tagExcInfo {
} ExcInfo; } ExcInfo;
extern UINT32 g_curNestCount; extern UINT32 g_curNestCount;
extern UINT32 g_vuwIntCount; extern UINT32 g_intCount;
static VOID OsExcSave2DDR(VOID); static VOID OsExcSave2DDR(VOID);
VOID OsExcInfoDisplay(ExcInfo *exc); VOID OsExcInfoDisplay(ExcInfo *exc);
extern UINT8 g_uwExcTbl[32]; extern UINT8 g_uwExcTbl[32];
typedef enum {
OS_EXC_TYPE_CONTEXT = 0,
OS_EXC_TYPE_TSK = 1,
OS_EXC_TYPE_QUE = 2,
OS_EXC_TYPE_NVIC = 3,
OS_EXC_TYPE_TSK_SWITCH = 4,
OS_EXC_TYPE_MEM = 5,
OS_EXC_TYPE_MAX = 6
} ExcInfoType;
typedef struct tagExcInfoCallBackArray { typedef struct tagExcInfoCallBackArray {
ExcInfoType uwType; ExcInfoType uwType;
@ -1052,19 +750,19 @@ typedef struct tagExcInfoCallBackArray {
#define MAX_TSK_INFO_SIZE (8 + sizeof(TSK_INFO_S) * (LOSCFG_BASE_CORE_TSK_LIMIT + 1)) #define MAX_TSK_INFO_SIZE (8 + sizeof(TSK_INFO_S) * (LOSCFG_BASE_CORE_TSK_LIMIT + 1))
#define MAX_INT_INFO_SIZE (8 + 0x164) #define MAX_INT_INFO_SIZE (8 + 0x164)
#if (LOSCFG_BASE_IPC_QUEUE == YES) #if (LOSCFG_BASE_IPC_QUEUE == 1)
#define MAX_QUEUE_INFO_SIZE (8 + sizeof(QUEUE_INFO_S) * LOSCFG_BASE_IPC_QUEUE_LIMIT) #define MAX_QUEUE_INFO_SIZE (8 + sizeof(QUEUE_INFO_S) * LOSCFG_BASE_IPC_QUEUE_LIMIT)
#else #else
#define MAX_QUEUE_INFO_SIZE (0) #define MAX_QUEUE_INFO_SIZE (0)
#endif #endif
#if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == YES) #if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == 1)
#define MAX_SWITCH_INFO_SIZE (8 + (sizeof(UINT32) + sizeof(CHAR) * LOS_TASK_NAMELEN) * OS_TASK_SWITCH_INFO_COUNT) #define MAX_SWITCH_INFO_SIZE (8 + (sizeof(UINT32) + sizeof(CHAR) * LOS_TASK_NAMELEN) * OS_TASK_SWITCH_INFO_COUNT)
#else #else
#define MAX_SWITCH_INFO_SIZE (0) #define MAX_SWITCH_INFO_SIZE (0)
#endif #endif
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == YES) #if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == 1)
#define MAX_MEM_INFO_SIZE (8 + sizeof(MEM_INFO_S) * OS_SYS_MEM_NUM) #define MAX_MEM_INFO_SIZE (8 + sizeof(MEM_INFO_S) * OS_SYS_MEM_NUM)
#else #else
#define MAX_MEM_INFO_SIZE (0) #define MAX_MEM_INFO_SIZE (0)
@ -1072,8 +770,7 @@ typedef struct tagExcInfoCallBackArray {
#define MAX_EXC_MEM_SIZE ( 4 + MAX_SCENE_INFO_SIZE + MAX_TSK_INFO_SIZE + MAX_QUEUE_INFO_SIZE + MAX_INT_INFO_SIZE + MAX_SWITCH_INFO_SIZE + MAX_MEM_INFO_SIZE + 4) #define MAX_EXC_MEM_SIZE ( 4 + MAX_SCENE_INFO_SIZE + MAX_TSK_INFO_SIZE + MAX_QUEUE_INFO_SIZE + MAX_INT_INFO_SIZE + MAX_SWITCH_INFO_SIZE + MAX_MEM_INFO_SIZE + 4)
VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg);
VOID LOS_Reboot(VOID);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, 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_context.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cpluscplus */
#endif /* __cpluscplus */
UINT32 HalTickStart(OS_TICK_HANDLER handler);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#endif /* _LOS_ARCH_TIMER_H */

View File

@ -28,9 +28,14 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "los_config.h"
#include "los_task.h" #include "los_task.h"
#include "securec.h" #include "securec.h"
#include "los_interrupt.h"
#include "los_arch_context.h"
#include "los_arch_interrupt.h"
#include "los_arch_timer.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
@ -38,20 +43,32 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/* **************************************************************************** /* ****************************************************************************
Function : OsTaskExit Function : HalArchInit
Description : arch init function
Input : None
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID HalArchInit()
{
HalHwiInit();
}
/* ****************************************************************************
Function : HalSysExit
Description : Task exit function Description : Task exit function
Input : None Input : None
Output : None Output : None
Return : None Return : None
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID OsTaskExit(VOID) LITE_OS_SEC_TEXT_MINOR VOID HalSysExit(VOID)
{ {
LOS_IntLock(); LOS_IntLock();
for(;;); for(;;);
} }
/* **************************************************************************** /* ****************************************************************************
Function : OsTskStackInit Function : HalTskStackInit
Description : Task stack initialization function Description : Task stack initialization function
Input : taskID --- TaskID Input : taskID --- TaskID
stackSize --- Total size of the stack stackSize --- Total size of the stack
@ -59,7 +76,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTaskExit(VOID)
Output : None Output : None
Return : Context pointer Return : Context pointer
**************************************************************************** */ **************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack) LITE_OS_SEC_TEXT_INIT VOID *HalTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
{ {
TaskContext *context = NULL; TaskContext *context = NULL;
errno_t result; errno_t result;
@ -125,18 +142,27 @@ LITE_OS_SEC_TEXT_INIT VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID
context->uwR2 = 0x02020202L; context->uwR2 = 0x02020202L;
context->uwR3 = 0x03030303L; context->uwR3 = 0x03030303L;
context->uwR12 = 0x12121212L; context->uwR12 = 0x12121212L;
context->uwLR = (UINT32)(UINTPTR)OsTaskExit; context->uwLR = (UINT32)(UINTPTR)HalSysExit;
context->uwPC = (UINT32)(UINTPTR)OsTaskEntry; context->uwPC = (UINT32)(UINTPTR)OsTaskEntry;
context->uwxPSR = 0x01000000L; context->uwxPSR = 0x01000000L;
return (VOID *)context; return (VOID *)context;
} }
LITE_OS_SEC_TEXT_INIT VOID OsEnterSleep(VOID) void HalBackTrace()
{ {
__DSB();
__WFI(); }
__ISB();
LITE_OS_SEC_TEXT_INIT UINT32 HalStartSchedule(OS_TICK_HANDLER handler)
{
UINT32 ret;
ret = HalTickStart(handler);
if (ret != LOS_OK) {
return ret;
}
HalStartToRun();
return LOS_OK; /* never return */
} }
#ifdef __cplusplus #ifdef __cplusplus

34
kernel/arch/arm/cortex-m4/iar/los_dispatch.S Executable file → Normal file
View File

@ -31,15 +31,14 @@
PRESERVE8 PRESERVE8
EXPORT LOS_IntLock EXPORT HalIntLock
EXPORT LOS_IntUnLock EXPORT HalIntUnLock
EXPORT LOS_IntRestore EXPORT HalIntRestore
EXPORT LOS_StartToRun EXPORT HalStartToRun
EXPORT osTaskSchedule EXPORT HalTaskSchedule
EXPORT osPendSV EXPORT HalPendSV
IMPORT g_losTask IMPORT g_losTask
IMPORT g_taskSwitchHook
IMPORT g_taskScheduled IMPORT g_taskScheduled
OS_NVIC_INT_CTRL EQU 0xE000ED04 OS_NVIC_INT_CTRL EQU 0xE000ED04
@ -52,7 +51,7 @@ OS_TASK_STATUS_RUNNING EQU 0x0010
THUMB THUMB
REQUIRE8 REQUIRE8
LOS_StartToRun HalStartToRun
LDR R4, =OS_NVIC_SYSPRI2 LDR R4, =OS_NVIC_SYSPRI2
LDR R5, =OS_NVIC_PENDSV_PRI LDR R5, =OS_NVIC_PENDSV_PRI
STR R5, [R4] STR R5, [R4]
@ -93,38 +92,31 @@ LOS_StartToRun
BX R6 BX R6
LOS_IntLock HalIntLock
MRS R0, PRIMASK MRS R0, PRIMASK
CPSID I CPSID I
BX LR BX LR
LOS_IntUnLock HalIntUnLock
MRS R0, PRIMASK MRS R0, PRIMASK
CPSIE I CPSIE I
BX LR BX LR
LOS_IntRestore HalIntRestore
MSR PRIMASK, R0 MSR PRIMASK, R0
BX LR BX LR
osTaskSchedule HalTaskSchedule
LDR R0, =OS_NVIC_INT_CTRL LDR R0, =OS_NVIC_INT_CTRL
LDR R1, =OS_NVIC_PENDSVSET LDR R1, =OS_NVIC_PENDSVSET
STR R1, [R0] STR R1, [R0]
BX LR BX LR
osPendSV HalPendSV
MRS R12, PRIMASK MRS R12, PRIMASK
CPSID I CPSID I
LDR R2, =g_taskSwitchHook HalTaskSwitch
LDR R2, [R2]
CBZ R2, TaskSwitch
PUSH {R12, LR}
BLX R2
POP {R12, LR}
TaskSwitch
MRS R0, PSP MRS R0, PSP
STMFD R0!, {R4-R12} STMFD R0!, {R4-R12}

View File

@ -33,16 +33,14 @@
SECTION .text:CODE(2) SECTION .text:CODE(2)
THUMB THUMB
EXPORT OsExcNMI EXPORT HalExcNMI
EXPORT OsExcHardFault EXPORT HalExcHardFault
EXPORT OsExcMemFault EXPORT HalExcMemFault
EXPORT OsExcBusFault EXPORT HalExcBusFault
EXPORT OsExcUsageFault EXPORT HalExcUsageFault
EXPORT OsExcSvcCall EXPORT HalExcSvcCall
IMPORT OsExcHandleEntry IMPORT HalExcHandleEntry
IMPORT g_vuwLosFlag
IMPORT g_uwCurNestCount
IMPORT g_uwExcTbl IMPORT g_uwExcTbl
IMPORT g_taskScheduled IMPORT g_taskScheduled
@ -66,12 +64,12 @@ OS_NVIC_ACT_BASE EQU 0xE000E300
OS_NVIC_SHCSRS EQU 0xE000ED24 OS_NVIC_SHCSRS EQU 0xE000ED24
OS_NVIC_SHCSR_MASK EQU 0xC00 OS_NVIC_SHCSR_MASK EQU 0xC00
OsExcNMI HalExcNMI
MOV R0, #OS_EXC_CAUSE_NMI MOV R0, #OS_EXC_CAUSE_NMI
MOV R1, #0 MOV R1, #0
B osExcDispatch B osExcDispatch
OsExcHardFault HalExcHardFault
MOV R0, #OS_EXC_CAUSE_HARDFAULT MOV R0, #OS_EXC_CAUSE_HARDFAULT
LDR R2, =OS_NVIC_HFSR LDR R2, =OS_NVIC_HFSR
LDR R2, [R2] LDR R2, [R2]
@ -122,7 +120,7 @@ osHFExcCommonBMU
ORR R0, R0 ,R12 ORR R0, R0 ,R12
B osExcDispatch B osExcDispatch
OsExcSvcCall HalExcSvcCall
TST LR, #0x4 TST LR, #0x4
ITE EQ ITE EQ
MRSEQ R0, MSP MRSEQ R0, MSP
@ -132,7 +130,7 @@ OsExcSvcCall
MOV R1, #0 MOV R1, #0
B osExcDispatch B osExcDispatch
OsExcBusFault HalExcBusFault
LDR R0, =OS_NVIC_FSR LDR R0, =OS_NVIC_FSR
LDR R0, [R0] LDR R0, [R0]
@ -149,7 +147,7 @@ _ExcBusNoADDR
MOV R12,#0 MOV R12,#0
B osExcCommonBMU B osExcCommonBMU
OsExcMemFault HalExcMemFault
LDR R0, =OS_NVIC_FSR LDR R0, =OS_NVIC_FSR
LDR R0, [R0] LDR R0, [R0]
@ -166,7 +164,7 @@ _ExcMemNoADDR
MOV R12,#0 MOV R12,#0
B osExcCommonBMU B osExcCommonBMU
OsExcUsageFault HalExcUsageFault
LDR R0, =OS_NVIC_FSR LDR R0, =OS_NVIC_FSR
LDR R0, [R0] LDR R0, [R0]
@ -281,7 +279,7 @@ _handleEntry
MOV R3, R13 ; R13:the 4th param MOV R3, R13 ; R13:the 4th param
CPSID I CPSID I
CPSID F CPSID F
B OsExcHandleEntry B HalExcHandleEntry
NOP NOP
END END

Some files were not shown because too many files have changed in this diff Show More