Description: liteos-m refactoring

Reviewed-by: wangmihu, zhushengle
This commit is contained in:
likailong 2020-12-02 19:40:34 +08:00
parent f7d1409762
commit 72c4acf01e
160 changed files with 15478 additions and 13235 deletions

52
arch_spec.md Executable file
View File

@ -0,0 +1,52 @@
``
.
├── components --- 可选组件可裁剪依赖kernel
│   ├── cppsupport --- C++支持
│   └── cpup --- CPUP功能
├── kal --- 内核抽象层
│   ├── cmsis --- cmsis标准支持
│   └── posix --- posix标准支持
├── kernel --- 内核最小功能集支持
│   ├── arch --- 硬件架构相关
│   │   ├── arm --- arm32架构
│   │   │   └── cortex-m4 --- cortex-m4架构
│   │   │   └── iar ---
│   │   │   ├── los_atomic.h
│   │   │   ├── los_context.h
│   │   │   ├── los_interrupt.h
│   │   │   └── los_mpu.h
│   │   └── include
│   │   ├── los_arch_atomic.h --- 定义通用arch的原子操作
│   │   ├── los_arch_context.h --- 定义通用arch的上下文切换
│   │   ├── los_arch.h --- 定义通用arch初始化
│   │   └── los_arch_interrupt.h --- 定义通用arch中断
│   ├── include
│   │   ├── los_config.h --- 功能开关和配置参数
│   │   ├── los_event.h --- 事件
│   │   ├── los_liteos.h --- liteos最小功能集对外提供的头文件
│   │   ├── los_memory.h --- 堆内存管理
│   │   ├── los_mutex.h --- 互斥锁
│   │   ├── los_queue.h --- 队列
│   │   ├── los_scheduler.h --- 调度算法
│   │   ├── los_sem.h --- 信号量
│   │   ├── los_task.h --- 任务
│   │   └── los_timer.h --- 定时器
│   └── src
├── targets
│   └── targets
│   └── cortex-m4_stm32f429ig_fire-challenger_iar
│   ├── board
│   ├── dprintf.c
│   ├── Libraries
│   ├── main.c
│   ├── project
│   ├── target_config.h --- 板级配置功能开关和配置参数
│   └── Utilities
└── utils
├── include
│   ├── los_compiler.h --- 编译工具配置,类型定义
│   ├── los_debug.h --- debugprintf相关
│   ├── los_error.h --- 错误定义
│   └── los_list.h
└── src
```

View File

@ -1 +0,0 @@
../../../../../third_party/cmsis/CMSIS/RTOS2/Include/cmsis_os2.h

View File

@ -37,7 +37,7 @@
#ifndef _LOS_CPPSUPPORT_H
#define _LOS_CPPSUPPORT_H
#include "los_typedef.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus

View File

@ -29,12 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "string.h"
#include "securec.h"
#include "los_cpup_pri.h"
#include "los_task_pri.h"
#include "los_memory_pri.h"
#include "los_cpup.h"
#include "los_debug.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
@ -55,12 +51,23 @@ extern "C" {
*/
#define OS_THREAD_TYPE_HWI 1
#define OS_CPUP_RECORD_PERIOD (g_sysClock)
LITE_OS_SEC_BSS UINT16 g_cpupInitFlg = 0;
LITE_OS_SEC_BSS OsCpupCB *g_cpup = NULL;
LITE_OS_SEC_BSS UINT64 g_lastRecordTime;
LITE_OS_SEC_BSS UINT16 g_hisPos; /* <current Sampling point of historyTime */
extern VOID LOS_GetCpuCycle(UINT32 *cntHi, UINT32 *cntLo);
#define OS_CPUP_RECORD_PERIOD (g_sysClock)
LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT64 OsGetCurrentCyclesCount(VOID)
{
UINT32 high = 0;
UINT32 low = 0;
LOS_GetCpuCycle(&high, &low);
return (((UINT64)high << 32) + low); // 32 means bits of word
}
/*****************************************************************************
Function : OsCpupInit
Description: initialization of CPUP
@ -85,19 +92,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit()
return LOS_OK;
}
/*****************************************************************************
Function : OsGetCpuCycle
Description: get current cycles count
Input : None
Return : current cycles count
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR UINT64 OsGetCpuCycle(VOID)
{
UINT32 high = 0;
UINT32 low = 0;
LOS_GetCpuCycle(&high, &low);
return (((UINT64)high << 32) + low); // 32 means bits of word
}
/*****************************************************************************
Function : OsTskCycleStart
Description: start task to get cycles count in current task begining
@ -114,7 +108,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleStart(VOID)
taskID = g_losTask.newTask->taskID;
g_cpup[taskID].cpupID = taskID;
g_cpup[taskID].startTime = OsGetCpuCycle();
g_cpup[taskID].startTime = OsGetCurrentCyclesCount();
return;
}
@ -139,7 +133,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEnd(VOID)
return;
}
cpuCycle = OsGetCpuCycle();
cpuCycle = OsGetCurrentCyclesCount();
if (cpuCycle < g_cpup[taskID].startTime) {
cpuCycle += g_cyclesPerTick;
@ -167,7 +161,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEndStart(VOID)
}
taskID = g_losTask.runTask->taskID;
cpuCycle = OsGetCpuCycle();
cpuCycle = OsGetCurrentCyclesCount();
if (g_cpup[taskID].startTime != 0) {
if (cpuCycle < g_cpup[taskID].startTime) {

View File

@ -37,9 +37,7 @@
#ifndef _LOS_CPUP_H
#define _LOS_CPUP_H
#include "los_hwi.h"
#include "los_base.h"
#include "los_sys.h"
#include "los_interrupt.h"
#include "los_task.h"
#ifdef __cplusplus
@ -123,181 +121,65 @@ extern "C" {
/**
* @ingroup los_cpup
* Count the CPU usage structures of all tasks.
* Number of historical running time records
*/
typedef struct tagCpupInfo {
UINT16 usStatus; /**< save the cur task status */
UINT32 uwUsage; /**< Usage. The value range is [0,1000]. */
} CPUP_INFO_S;
/**
* @ingroup los_monitor
* Type of the CPU usage query.
*/
typedef enum {
SYS_CPU_USAGE = 0, /* system cpu occupancy rate */
TASK_CPU_USAGE, /* task cpu occupancy rate */
} CPUP_TYPE_E;
/**
* @ingroup los_monitor
* Mode of the CPU usage query.
*/
typedef enum {
CPUP_IN_10S = 0, /* cpu occupancy rate in 10s */
CPUP_IN_1S, /* cpu occupancy rate in 1s */
CPUP_LESS_THAN_1S, /* cpu occupancy rate less than 1s, if the input mode is none of them, it will be this. */
} CPUP_MODE_E;
#define OS_CPUP_HISTORY_RECORD_NUM 10
/**
* @ingroup los_cpup
* @brief Obtain the current CPU usage.
* Count the CPU usage structures of a task.
*/
typedef struct {
UINT32 cpupID; /**< Task ID */
UINT16 status; /**< Task status */
UINT64 allTime; /**< Total running time */
UINT64 startTime; /**< Time before a task is invoked */
UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM]; /**< Historical running time */
} OsCpupCB;
extern OsCpupCB *g_cpup;
/**
* @ingroup los_cpup
* @brief Initialization cpup.
*
* @par Description:
* This API is used to obtain the current CPU usage.
* This API is used to initialization cpup.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, error codes will be returned.</li>
* <li> The precision of the CPU usage can be adjusted by changing the value of the CPUP_PRECISION macro.</li>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #cpup [0,100], current CPU usage, of which the precision is adjustable.
* @retval UINT32 Initialization result.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_SysCpuUsage
* @see None.
*/
extern UINT32 LOS_SysCpuUsage(VOID);
extern UINT32 OsCpupInit(VOID);
/**
* @ingroup los_cpup
* @brief Obtain the historical CPU usage.
* @brief Start task to get cycles count in current task ending.
*
* @par Description:
* This API is used to obtain the historical CPU usage.
* This API is used to start task to get cycles count in current task ending.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
* <li>None.</li>
* </ul>
*
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s will be
* obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained. Other values
* indicate that the CPU usage in the period that is less than 1s will be obtained.
* @param None.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #cpup [0,100], historical CPU usage, of which the precision is adjustable.
* @retval None.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HistoryTaskCpuUsage
* @see None.
*/
extern UINT32 LOS_HistorySysCpuUsage(UINT16 mode);
extern VOID OsTskCycleEndStart(VOID);
/**
* @ingroup los_cpup
* @brief Obtain the CPU usage of a specified task.
*
* @par Description:
* This API is used to obtain the CPU usage of a task specified by a passed-in task ID.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
* <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
* the CPU usage fails to be obtained.</li>
* </ul>
*
* @param taskID [IN] UINT32. Task ID.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
* @retval #cpup [0,100], CPU usage of the specified task.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HistoryTaskCpuUsage
*/
extern UINT32 LOS_TaskCpuUsage(UINT32 taskID);
/**
* @ingroup los_cpup
* @brief Obtain the historical CPU usage of a specified task.
*
* @par Description:
* This API is used to obtain the historical CPU usage of a task specified by a passed-in task ID.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise,
* the CPU usage fails to be obtained.</li>
* <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
* the CPU usage fails to be obtained.</li>
* </ul>
*
* @param taskID [IN] UINT32. Task ID.
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
* will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
* Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
* @retval #cpup [0,100], CPU usage of the specified task.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HistorySysCpuUsage
*/
extern UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode);
/**
* @ingroup los_cpup
* @brief Obtain the CPU usage of all tasks.
*
* @par Description:
* This API is used to obtain the CPU usage of all tasks according to maximum number of threads.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
* <li>The input parameter pointer must not be NULL, Otherwise, the CPU usage fails to be obtained.</li>
* </ul>
*
* @param cpupInfo [OUT]Type. CPUP_INFO_S* Pointer to the task CPUP information structure to be obtained.
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
* will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
* Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #OS_ERRNO_CPUP_TASK_PTR_NULL 0x02001e01: The input parameter pointer is NULL.
* @retval #LOS_OK 0x00000000: The CPU usage of all tasks is successfully obtained.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_SysCpuUsage
*/
extern UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 mode);
/**
* @ingroup los_monitor
* @brief Obtain CPU usage history of certain task.
*
* @par Description:
* This API is used to obtain CPU usage history of certain task.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, -1 will be returned.</li>
* <li> Only in SYS_CPU_USAGE type, uwTaskID is invalid.</li>
* </ul>
*
* @param type [IN] cpup type, SYS_CPU_USAGE and TASK_CPU_USAGE
* @param mode [IN] mode,CPUP_IN_10S = usage in 10s,CPUP_IN_1S = usage in last 1s,
* CPUP_LESS_THAN_1S = less than 1s, if the inpuit mode is none of them, it will be as CPUP_LESS_THAN_1S.
* @param taskID [IN] task ID, Only in SYS_CPU_USAGE type, taskID is invalid
*
* @retval #OS_ERROR -1:CPU usage info obtain failed.
* @retval #LOS_OK 0:CPU usage info is successfully obtained.
* @par Dependency:
* <ul><li>los_monitor.h: the header file that contains the API declaration.</li></ul>
* @see LOS_CpupUsageMonitor
*/
extern UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E mode, UINT32 taskID);
#ifdef __cplusplus
#if __cplusplus

View File

@ -1,111 +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.
*/
#ifndef _LOS_CPUP_PRI_H
#define _LOS_CPUP_PRI_H
#include "los_cpup.h"
#include "los_tick_pri.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_cpup
* Number of historical running time records
*/
#define OS_CPUP_HISTORY_RECORD_NUM 10
/**
* @ingroup los_cpup
* Count the CPU usage structures of a task.
*/
typedef struct {
UINT32 cpupID; /**< Task ID */
UINT16 status; /**< Task status */
UINT64 allTime; /**< Total running time */
UINT64 startTime; /**< Time before a task is invoked */
UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM]; /**< Historical running time */
} OsCpupCB;
extern OsCpupCB *g_cpup;
/**
* @ingroup los_cpup
* @brief Initialization cpup.
*
* @par Description:
* This API is used to initialization cpup.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval UINT32 Initialization result.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsCpupInit(VOID);
/**
* @ingroup los_cpup
* @brief Start task to get cycles count in current task ending.
*
* @par Description:
* This API is used to start task to get cycles count in current task ending.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID OsTskCycleEndStart(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_CPUP_PRI_H */

View File

@ -1,28 +1,11 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
import("//build/lite/config/component/lite_component.gni")
static_library("kal") {
sources = [ "kal.c" ]
lite_component("kal") {
features = [
"cmsis",
"posix",
include_dirs = [
"//kernel/liteos_m/kal",
"//third_party/bounds_checking_function/include",
#"kal", # kal is not supported now.
]
defines = [ "LITEOS_WIFI_IOT_VERSION" ]
cflags = [ "-Werror" ]
}
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" ]
}

15
kal/cmsis/BUILD.gn Executable file
View File

@ -0,0 +1,15 @@
# 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" ]
}

View File

@ -656,6 +656,8 @@ uint32_t osKernelGetSysTimerFreq (void);
/**
* @brief Creates an active thread.
*
* The priority ranges from 9 to 38. Select a proper priority as required.
* The maximum of tasks is LOSCFG_BASE_CORE_TSK_LIMIT(LOSCFG_BASE_CORE_TSK_LIMIT is defined in the traget_config.h).
* @param func Indicates the entry of the thread callback function.
* @param argument Indicates the pointer to the argument passed to the thread.
* @param attr Indicates the thread attributes.
@ -819,6 +821,7 @@ osStatus_t osDelay (uint32_t ticks);
/**
* @brief Waits until a specified time arrives.
*
* This function handles the overflow of the system timer. Note that the maximum value of this parameter is (2^31 - 1) ticks.
* @param ticks Indicates the number of ticks converted from the absolute time.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
@ -832,6 +835,8 @@ osStatus_t osDelayUntil (uint32_t ticks);
/**
* @brief Creates and initializes a timer.
*
* This function creates a timer associated with the arguments callback function. The timer stays in the stopped state until OSTimerStart is used to start the timer.
* The timer precision is 1000 / LOSCFG_BASE_CORE_TICK_PER_SECOND ms(LOSCFG_BASE_CORE_TICK_PER_SECOND is defined in the traget_config.h).
* @param func Indicates the entry of the timer callback function.
* @param type Indicates the timer type.
* @param argument Indicates the pointer to the argument used in timer callback.
@ -951,6 +956,7 @@ uint32_t osEventFlagsGet (osEventFlagsId_t ef_id);
/**
* @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.
* @param ef_id Indicates the event flags ID, which is obtained using osEventFlagsNew.
* @param flags Indicates the event flags to trigger.
* @param options Indicates the configuration of the event flags to trigger.
@ -1048,7 +1054,7 @@ const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id);
* @brief Acquires a token of a semaphore object.
*
* @param semaphore_id Indicates the semaphore ID, which is obtained using osSemaphoreNew.
* @param timeout Indicates the timeout duration.
* @param timeout Indicates the timeout duration. This parameter is the number of ticks.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
* @version 1.0
@ -1128,7 +1134,7 @@ const char *osMessageQueueGetName (osMessageQueueId_t mq_id);
*
* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
* @param msg_ptr Indicates the pointer to the buffer for storing the message to be placed in the message queue.
* @param msg_prio Indicates the priority of the message to be placed in the message queue.
* @param msg_prio Indicates the priority of the message to be placed in the message queue. This parameter is not used.
* @param timeout Indicates the timeout duration.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0
@ -1141,7 +1147,7 @@ osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uin
*
* @param mq_id Indicates the message queue ID, which is obtained using osMessageQueueNew.
* @param msg_ptr Indicates the pointer to the buffer for storing the message to be retrieved from the message queue.
* @param msg_prio Indicates the pointer to the buffer for storing the priority of the message to be retrieved from the message queue. This parameter can be set to NULL.
* @param msg_prio Indicates the pointer to the buffer for storing the priority of the message to be retrieved from the message queue. This parameter is not used.
* @param timeout Indicates the timeout duration.
* @return Returns the CMSIS-RTOS running result.
* @since 1.0

View File

@ -33,7 +33,7 @@
#define HOS_CMSIS_ADP_H
#include "cmsis_os.h"
#include "hos_types.h"
#include "ohos_types.h"
#ifdef __cplusplus
#if __cplusplus

15
kal/kal/BUILD.gn Executable file
View File

@ -0,0 +1,15 @@
# 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" ]
}

20
kal/posix/BUILD.gn Executable file
View File

@ -0,0 +1,20 @@
# 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" ]
}

12
kal/posix/include/README Executable file
View File

@ -0,0 +1,12 @@
Root directory "//" refers to "/vendor/hisi/hi3861/hi3861".
We use header files from musl ("//platform/os/Huawei_LiteOS/components/lib/libc/musl/include").
Some posix apis are already defined in different places:
errno is defined in //build/libs/libc_base.o
malloc and free are defined in //build/libs/libc_base.o
pthread_mutex_* are defined in //build/libs/hi3861/release/no_mesh/liblitekernel_flash.a
semaphore is defined in //build/libs/hi3861/release/no_mesh/liblitekernel_flash.a
usleep is defined in //build/libs/hi3861/release/no_mesh/liblitekernel_flash.a
clock_* are defined in //build/libs/liblitekernel_base.o
printf is defined in //build/libs/liblitekernel_base.o
fcntl and socket apis are defined in //build/libs/liblwip.a

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2020, Huawei Technologies Co., Ltd. All rights reserved.
* 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,
@ -29,25 +29,18 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_HW_TICK_PRI_H
#define _LOS_HW_TICK_PRI_H
#include "los_typedef.h"
#ifndef VERSION_H_
#define VERSION_H_
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif
#define TICK_INTERRUPT_PRI 0x1
extern UINT32 g_cyclesPerTick;
const char *libc_get_version_string(void);
int libc_get_version(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif
#endif /* _LOS_HW_TICK_PRI_H */
#endif // VERSION_H_

View File

@ -29,36 +29,65 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_base_pri.h"
#include "los_sys_pri.h"
#include "los_task_pri.h"
#include "los_hwi.h"
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include "lwip/sockets.h"
#include "hks_client.h"
LITE_OS_SEC_TEXT UINT32 LOS_Align(UINT32 addr, UINT32 boundary)
#define RANDOM_DEV_FD LWIP_CONFIG_NUM_SOCKETS
#define RANDOM_DEV_PATH "/dev/random"
int open(const char *file, int oflag, ...)
{
if ((addr + (boundary - 1)) > addr) {
return (addr + (boundary - 1)) & ~(boundary - 1);
} else {
return addr & ~(boundary - 1);
if (strcmp(file, RANDOM_DEV_PATH) == 0) {
if (oflag != O_RDONLY) {
errno = EINVAL;
return -1;
}
return RANDOM_DEV_FD;
}
errno = ENOENT;
return -1;
}
LITE_OS_SEC_TEXT_MINOR VOID LOS_Msleep(UINT32 mSecs)
int close(int fd)
{
UINT32 interval;
if (OS_INT_ACTIVE) {
return;
if (fd == RANDOM_DEV_FD) {
return 0;
}
return closesocket(fd);
}
if (mSecs == 0) {
interval = 0;
} else {
interval = LOS_MS2Tick(mSecs);
if (interval == 0) {
interval = 1;
ssize_t read(int fd, void *buf, size_t nbytes)
{
if (fd == RANDOM_DEV_FD) {
if (nbytes == 0) {
return 0;
}
if (buf == NULL) {
errno = EINVAL;
return -1;
}
if (nbytes > 1024) {
nbytes = 1024; /* hks_generate_random: random_size must <= 1024 */
}
struct hks_blob key = {HKS_BLOB_TYPE_RAW, (uint8_t *)buf, nbytes};
if (hks_generate_random(&key) != 0) {
errno = EIO;
return -1;
}
return (ssize_t)nbytes;
}
return recv(fd, buf, nbytes, 0);
}
(VOID)LOS_TaskDelay(interval);
ssize_t write(int fd, const void *buf, size_t nbytes)
{
if (fd == RANDOM_DEV_FD) {
errno = EBADF; /* "/dev/random" is readonly */
return -1;
}
return send(fd, buf, nbytes, 0);
}

237
kal/posix/src/pthread.c Executable file
View File

@ -0,0 +1,237 @@
/*
* 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 <errno.h>
#include <pthread.h>
#include <unistd.h>
#include <securec.h>
#include "los_task.h"
#include "los_task_pri.h"
#define PTHREAD_NAMELEN 16
/* this is just an assertion: LOS_TASK_ARG_NUM >= 4 */
typedef char NULNAM[-!((LOS_TASK_ARG_NUM * 4) >= PTHREAD_NAMELEN)];
static void *_pthread_entry(UINT32 param1, UINT32 param2, UINT32 param3, UINT32 param4)
{
void *(*startRoutine)(void *) = (void *)(UINTPTR)param1;
void *param = (void *)(UINTPTR)param2;
(void)param3;
(void)param4;
int ret;
LosTaskCB *tcb = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
char *tmp = tcb->taskName;
tcb->taskName = (char *)tcb->args; /* args are reused as task name */
ret = strcpy_s(tcb->taskName, PTHREAD_NAMELEN, tmp);
if (ret != 0) {
free(tmp);
return NULL;
}
free(tmp);
return startRoutine(param);
}
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*startRoutine)(void *), void *arg)
{
TSK_INIT_PARAM_S taskInitParam = {0};
UINT32 taskID;
if ((thread == NULL) || (startRoutine == NULL)) {
return EINVAL;
}
if (attr) {
if (attr->detachstate == PTHREAD_CREATE_DETACHED) {
return ENOTSUP;
}
taskInitParam.usTaskPrio = (UINT16)attr->schedparam.sched_priority;
taskInitParam.uwStackSize = attr->stacksize;
} else {
taskInitParam.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
}
taskInitParam.pcName = malloc(PTHREAD_NAMELEN);
if (taskInitParam.pcName == NULL) {
return ENOMEM;
}
taskInitParam.pfnTaskEntry = _pthread_entry;
taskInitParam.auwArgs[0] = (UINT32)(UINTPTR)startRoutine;
taskInitParam.auwArgs[1] = (UINT32)(UINTPTR)arg;
if (LOS_TaskCreate(&taskID, &taskInitParam) != LOS_OK) {
free(taskInitParam.pcName);
return EINVAL;
}
/* set pthread default name */
(void)sprintf_s(taskInitParam.pcName, PTHREAD_NAMELEN, "pthread%u", taskID);
*thread = (pthread_t)taskID;
return ENOERR;
}
int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param)
{
if ((param == NULL) || (param->sched_priority > OS_TASK_PRIORITY_LOWEST)) {
return EINVAL;
}
/* Only support SCHED_RR policy now */
if (policy != SCHED_RR) {
return ENOTSUP;
}
if (LOS_TaskPriSet((UINT32)thread, (UINT16)param->sched_priority) != LOS_OK) {
return EINVAL;
}
return ENOERR;
}
int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param)
{
UINT32 prio;
if ((policy == NULL) || (param == NULL)) {
return EINVAL;
}
prio = LOS_TaskPriGet((UINT32)thread);
if (prio == OS_INVALID) {
return EINVAL;
}
*policy = SCHED_RR;
param->sched_priority = prio;
return ENOERR;
}
pthread_t pthread_self(void)
{
return (pthread_t)LOS_CurTaskIDGet();
}
int pthread_cancel(pthread_t thread)
{
(void)thread;
return ENOSYS;
}
static void *void_task(UINT32 param1, UINT32 param2, UINT32 param3, UINT32 param4)
{
(void)param1;
(void)param2;
(void)param3;
(void)param4;
return 0;
}
static void cleanup_task_resource(void)
{
TSK_INIT_PARAM_S taskInitParam = {0};
UINT32 taskID;
taskInitParam.pcName = "void";
taskInitParam.pfnTaskEntry = void_task;
taskInitParam.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE;
(void)LOS_TaskCreate(&taskID, &taskInitParam);
}
int pthread_join(pthread_t thread, void **retval)
{
UINT32 taskStatus;
if (retval) {
/* retrieve thread exit code is not supported currently */
return ENOTSUP;
}
if (thread == pthread_self()) {
return EDEADLK;
}
while (LOS_TaskStatusGet((UINT32)thread, &taskStatus) == LOS_OK) {
usleep(10000);
}
cleanup_task_resource();
return 0;
}
int pthread_detach(pthread_t thread)
{
(void)thread;
return ENOSYS;
}
void pthread_exit(void *retVal)
{
(void)retVal;
(void)LOS_TaskDelete(LOS_CurTaskIDGet());
}
int pthread_setname_np(pthread_t thread, const char *name)
{
char *taskName = LOS_TaskNameGet((UINT32)thread);
if (taskName == NULL) {
return EINVAL;
}
if (strnlen(name, PTHREAD_NAMELEN) >= PTHREAD_NAMELEN) {
return ERANGE;
}
(void)strcpy_s(taskName, PTHREAD_NAMELEN, name);
return 0;
}
int pthread_getname_np(pthread_t thread, char *buf, size_t buflen)
{
int ret;
const char *name = LOS_TaskNameGet((UINT32)thread);
if (name == NULL) {
return EINVAL;
}
if (buflen > strlen(name)) {
ret = strcpy_s(buf, buflen, name);
if (ret == 0) {
return 0;
}
}
return ERANGE;
}

233
kal/posix/src/pthread_attr.c Executable file
View File

@ -0,0 +1,233 @@
/*
* 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 <errno.h>
#include <pthread.h>
#define PTHREAD_STACK_MIN LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE
int pthread_attr_init(pthread_attr_t *attr)
{
if (attr == NULL) {
return EINVAL;
}
attr->detachstate = PTHREAD_CREATE_JOINABLE;
attr->schedpolicy = SCHED_RR;
attr->schedparam.sched_priority = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
attr->inheritsched = PTHREAD_INHERIT_SCHED;
attr->scope = PTHREAD_SCOPE_PROCESS;
attr->stackaddr_set = 0;
attr->stackaddr = NULL;
attr->stacksize_set = 1;
attr->stacksize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
return ENOERR;
}
int pthread_attr_destroy(pthread_attr_t *attr)
{
if (attr == NULL) {
return EINVAL;
}
/* Nothing to do here... */
return ENOERR;
}
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachState)
{
if ((attr != NULL) && ((detachState == PTHREAD_CREATE_JOINABLE) || (detachState == PTHREAD_CREATE_DETACHED))) {
attr->detachstate = (UINT32)detachState;
return ENOERR;
}
return EINVAL;
}
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachState)
{
if ((attr == NULL) || (detachState == NULL)) {
return EINVAL;
}
*detachState = (int)attr->detachstate;
return ENOERR;
}
int pthread_attr_setscope(pthread_attr_t *attr, int scope)
{
if (attr == NULL) {
return EINVAL;
}
if (scope == PTHREAD_SCOPE_PROCESS) {
attr->scope = (unsigned int)scope;
return ENOERR;
}
if (scope == PTHREAD_SCOPE_SYSTEM) {
return ENOTSUP;
}
return EINVAL;
}
int pthread_attr_getscope(const pthread_attr_t *attr, int *scope)
{
if ((attr == NULL) || (scope == NULL)) {
return EINVAL;
}
*scope = (int)attr->scope;
return ENOERR;
}
int pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit)
{
if ((attr != NULL) && ((inherit == PTHREAD_INHERIT_SCHED) || (inherit == PTHREAD_EXPLICIT_SCHED))) {
attr->inheritsched = (UINT32)inherit;
return ENOERR;
}
return EINVAL;
}
int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inherit)
{
if ((attr == NULL) || (inherit == NULL)) {
return EINVAL;
}
*inherit = (int)attr->inheritsched;
return ENOERR;
}
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
{
if ((attr != NULL) && (policy == SCHED_RR)) {
attr->schedpolicy = SCHED_RR;
return ENOERR;
}
return EINVAL;
}
int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
{
if ((attr == NULL) || (policy == NULL)) {
return EINVAL;
}
*policy = (int)attr->schedpolicy;
return ENOERR;
}
int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
{
if ((attr == NULL) || (param == NULL)) {
return EINVAL;
} else if ((param->sched_priority < 0) || (param->sched_priority > OS_TASK_PRIORITY_LOWEST)) {
return ENOTSUP;
}
attr->schedparam = *param;
return ENOERR;
}
int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
{
if ((attr == NULL) || (param == NULL)) {
return EINVAL;
}
*param = attr->schedparam;
return ENOERR;
}
/*
* Set starting address of stack. Whether this is at the start or end of
* the memory block allocated for the stack depends on whether the stack
* grows up or down.
*/
int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackAddr)
{
if (attr == NULL) {
return EINVAL;
}
attr->stackaddr_set = 1;
attr->stackaddr = stackAddr;
return ENOERR;
}
int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackAddr)
{
if (((attr != NULL) && (stackAddr != NULL)) && attr->stackaddr_set) {
*stackAddr = attr->stackaddr;
return ENOERR;
}
return EINVAL; /* Stack address not set, return EINVAL. */
}
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stackSize)
{
/* Reject inadequate stack sizes */
if ((attr == NULL) || (stackSize < PTHREAD_STACK_MIN)) {
return EINVAL;
}
attr->stacksize_set = 1;
attr->stacksize = stackSize;
return ENOERR;
}
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stackSize)
{
/* Reject attempts to get a stack size when one has not been set. */
if ((attr == NULL) || (stackSize == NULL) || (!attr->stacksize_set)) {
return EINVAL;
}
*stackSize = attr->stacksize;
return ENOERR;
}

254
kal/posix/src/time.c Executable file
View File

@ -0,0 +1,254 @@
/*
* 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 <errno.h>
#include <time.h>
#include <signal.h>
#include <unistd.h>
#include <los_swtmr.h>
#include <los_swtmr_pri.h>
#ifndef STATIC
#define STATIC static
#endif
#define OS_SYS_NS_PER_US 1000
#define OS_SYS_NS_PER_SECOND 1000000000
#define OS_SYS_US_PER_SECOND 1000000
#define OS_SYS_MS_PER_SECOND 1000
STATIC INLINE BOOL ValidTimerID(UINT16 swtmrID)
{
/* check timer id */
return (swtmrID < LOSCFG_BASE_CORE_SWTMR_LIMIT);
}
/* internal functions */
STATIC INLINE BOOL ValidTimeSpec(const struct timespec *tp)
{
/* Fail a NULL pointer */
if (tp == NULL) {
return FALSE;
}
/* Fail illegal nanosecond values */
if ((tp->tv_nsec < 0) || (tp->tv_nsec >= OS_SYS_NS_PER_SECOND) || (tp->tv_sec < 0)) {
return FALSE;
}
return TRUE;
}
STATIC INLINE UINT32 OsTimeSpec2Tick(const struct timespec *tp)
{
UINT64 tick, ns;
ns = (UINT64)tp->tv_sec * OS_SYS_NS_PER_SECOND + tp->tv_nsec;
/* Round up for ticks */
tick = (ns * LOSCFG_BASE_CORE_TICK_PER_SECOND + (OS_SYS_NS_PER_SECOND - 1)) / OS_SYS_NS_PER_SECOND;
if (tick > LOS_WAIT_FOREVER) {
tick = LOS_WAIT_FOREVER;
}
return (UINT32)tick;
}
STATIC INLINE VOID OsTick2TimeSpec(struct timespec *tp, UINT32 tick)
{
UINT64 ns = ((UINT64)tick * OS_SYS_NS_PER_SECOND) / LOSCFG_BASE_CORE_TICK_PER_SECOND;
tp->tv_sec = (time_t)(ns / OS_SYS_NS_PER_SECOND);
tp->tv_nsec = (long)(ns % OS_SYS_NS_PER_SECOND);
}
int nanosleep(const struct timespec *req, struct timespec *rem)
{
UINT64 us = (UINT64)req->tv_sec * OS_SYS_US_PER_SECOND + (req->tv_nsec + OS_SYS_NS_PER_US - 1) / OS_SYS_NS_PER_US;
if (us > 0xFFFFFFFFU) {
errno = EINVAL;
return -1;
}
if (usleep(us) == 0) {
if (rem) {
rem->tv_sec = rem->tv_nsec = 0;
}
return 0;
}
return -1;
}
int timer_create(clockid_t clockID, struct sigevent *restrict evp, timer_t *restrict timerID)
{
UINT32 ret;
UINT16 swtmrID;
if (!timerID || (clockID != CLOCK_REALTIME)) {
errno = EINVAL;
return -1;
}
if (!evp || evp->sigev_notify != SIGEV_THREAD || evp->sigev_notify_attributes) {
errno = ENOTSUP;
return -1;
}
ret = LOS_SwtmrCreate(1, LOS_SWTMR_MODE_ONCE, (SWTMR_PROC_FUNC)evp->sigev_notify_function,
&swtmrID, (UINT32)(UINTPTR)evp->sigev_value.sival_ptr);
if (ret != LOS_OK) {
errno = (ret == LOS_ERRNO_SWTMR_MAXSIZE) ? EAGAIN : EINVAL;
return -1;
}
*timerID = (timer_t)(UINTPTR)swtmrID;
return 0;
}
int timer_delete(timer_t timerID)
{
UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
if (!ValidTimerID(swtmrID)) {
errno = EINVAL;
return -1;
}
if (LOS_SwtmrDelete(swtmrID) != LOS_OK) {
errno = EINVAL;
return -1;
}
return 0;
}
int timer_settime(timer_t timerID, int flags,
const struct itimerspec *restrict value,
struct itimerspec *restrict oldValue)
{
UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
SWTMR_CTRL_S *swtmr = NULL;
UINT32 interval, expiry, ret;
if (flags != 0) {
/* flags not supported currently */
errno = ENOSYS;
return -1;
}
if (value == NULL || !ValidTimerID(swtmrID)) {
errno = EINVAL;
return -1;
}
if (!ValidTimeSpec(&value->it_value) || !ValidTimeSpec(&value->it_interval)) {
errno = EINVAL;
return -1;
}
expiry = OsTimeSpec2Tick(&value->it_value);
interval = OsTimeSpec2Tick(&value->it_interval);
/* if specified interval, it must be same with expiry due to the limitation of liteos-m */
if (interval && interval != expiry) {
errno = ENOTSUP;
return -1;
}
if (oldValue) {
(VOID)timer_gettime(timerID, oldValue);
}
ret = LOS_SwtmrStop(swtmrID);
if ((ret != LOS_OK) && (ret != LOS_ERRNO_SWTMR_NOT_STARTED)) {
errno = EINVAL;
return -1;
}
swtmr = OS_SWT_FROM_SID(swtmrID);
ret = LOS_SwtmrModify(swtmrID, expiry, (interval ? LOS_SWTMR_MODE_PERIOD : LOS_SWTMR_MODE_NO_SELFDELETE),
swtmr->pfnHandler, swtmr->uwArg);
if (ret != LOS_OK) {
errno = EINVAL;
return -1;
}
if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) {
/*
* 1) when expiry is 0, means timer should be stopped.
* 2) If timer is ticking, stopping timer is already done before.
* 3) If timer is created but not ticking, return 0 as well.
*/
return 0;
}
if (LOS_SwtmrStart(swtmr->usTimerID) != LOS_OK) {
errno = EINVAL;
return -1;
}
return 0;
}
int timer_gettime(timer_t timerID, struct itimerspec *value)
{
UINT32 tick = 0;
SWTMR_CTRL_S *swtmr = NULL;
UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
UINT32 ret;
if ((value == NULL) || !ValidTimerID(swtmrID)) {
errno = EINVAL;
return -1;
}
swtmr = OS_SWT_FROM_SID(swtmrID);
/* get expire time */
ret = LOS_SwtmrTimeGet(swtmr->usTimerID, &tick);
if ((ret != LOS_OK) && (ret != LOS_ERRNO_SWTMR_NOT_STARTED)) {
errno = EINVAL;
return -1;
}
OsTick2TimeSpec(&value->it_value, tick);
OsTick2TimeSpec(&value->it_interval, (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) ? 0 : swtmr->uwInterval);
return 0;
}
int timer_getoverrun(timer_t timerID)
{
UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
if (!ValidTimerID(swtmrID)) {
errno = EINVAL;
return -1;
}
errno = ENOSYS;
return -1;
}

View File

@ -29,26 +29,22 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_PRINTF_PRI_H
#define _LOS_PRINTF_PRI_H
#include <version.h>
#include "los_printf.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
VOID _dprintf(const CHAR *fmt, va_list ap);
INT32 __dprintf(const CHAR *fmt, va_list ap, VOID (*uart_fputc)(UINT32 n, VOID *cookie), CHAR *cookie);
#ifdef __cplusplus
#if __cplusplus
/**
* get libc version string.
* @return libc version string. the format is <major>.<minor>.<patch>[-<platform>[-<desc>]]
*/
const char *libc_get_version_string(void)
{
return LIBC_VERSION_STR;
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_PRINTF_PRI_H */
/**
* get libc version code.
* @return libc version code. the format is 0x00XXYYZZ, XX is major version, YY is minor version and ZZ is patch version
*/
int libc_get_version(void)
{
return LIBC_VERSION_NUM;
}

View File

@ -0,0 +1,276 @@
/**************************************************************************//**
* @file ARMCM3.h
* @brief CMSIS Core Peripheral Access Layer Header File for
* ARMCM3 Device Series
* @version V1.08
* @date 23. November 2012
*
* @note
*
******************************************************************************/
/* Copyright (c) 2011 - 2012 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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 ARMCM3_H
#define ARMCM3_H
#ifdef __cplusplus
extern "C" {
#endif
/* ------------------------- Interrupt Number Definition ------------------------ */
typedef enum IRQn
{
/* ------------------- Cortex-M3 Processor Exceptions Numbers ------------------- */
NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
HardFault_IRQn = -13, /*!< 3 HardFault Interrupt */
MemoryManagement_IRQn = -12, /*!< 4 Memory Management Interrupt */
BusFault_IRQn = -11, /*!< 5 Bus Fault Interrupt */
UsageFault_IRQn = -10, /*!< 6 Usage Fault Interrupt */
SVCall_IRQn = -5, /*!< 11 SV Call Interrupt */
DebugMonitor_IRQn = -4, /*!< 12 Debug Monitor Interrupt */
PendSV_IRQn = -2, /*!< 14 Pend SV Interrupt */
SysTick_IRQn = -1, /*!< 15 System Tick Interrupt */
/* ---------------------- ARMCM3 Specific Interrupt Numbers --------------------- */
WDT_IRQn = 0, /*!< Watchdog Timer Interrupt */
RTC_IRQn = 1, /*!< Real Time Clock Interrupt */
TIM0_IRQn = 2, /*!< Timer0 / Timer1 Interrupt */
TIM2_IRQn = 3, /*!< Timer2 / Timer3 Interrupt */
MCIA_IRQn = 4, /*!< MCIa Interrupt */
MCIB_IRQn = 5, /*!< MCIb Interrupt */
UART0_IRQn = 6, /*!< UART0 Interrupt */
UART1_IRQn = 7, /*!< UART1 Interrupt */
UART2_IRQn = 8, /*!< UART2 Interrupt */
UART4_IRQn = 9, /*!< UART4 Interrupt */
AACI_IRQn = 10, /*!< AACI / AC97 Interrupt */
CLCD_IRQn = 11, /*!< CLCD Combined Interrupt */
ENET_IRQn = 12, /*!< Ethernet Interrupt */
USBDC_IRQn = 13, /*!< USB Device Interrupt */
USBHC_IRQn = 14, /*!< USB Host Controller Interrupt */
CHLCD_IRQn = 15, /*!< Character LCD Interrupt */
FLEXRAY_IRQn = 16, /*!< Flexray Interrupt */
CAN_IRQn = 17, /*!< CAN Interrupt */
LIN_IRQn = 18, /*!< LIN Interrupt */
I2C_IRQn = 19, /*!< I2C ADC/DAC Interrupt */
CPU_CLCD_IRQn = 28, /*!< CPU CLCD Combined Interrupt */
UART3_IRQn = 30, /*!< UART3 Interrupt */
SPI_IRQn = 31, /*!< SPI Touchscreen Interrupt */
} IRQn_Type;
/* ================================================================================ */
/* ================ Processor and Core Peripheral Section ================ */
/* ================================================================================ */
/* -------- Configuration of the Cortex-M4 Processor and Core Peripherals ------- */
#define __CM3_REV 0x0201 /*!< Core revision r2p1 */
#define __MPU_PRESENT 1 /*!< MPU present or not */
#define __NVIC_PRIO_BITS 3 /*!< Number of Bits used for Priority Levels */
#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */
#include <core_cm3.h> /* Processor and core peripherals */
/* ================================================================================ */
/* ================ Device Specific Peripheral Section ================ */
/* ================================================================================ */
/* ------------------- Start of section using anonymous unions ------------------ */
#if defined(__CC_ARM)
#pragma push
#pragma anon_unions
#elif defined(__ICCARM__)
#pragma language=extended
#elif defined(__GNUC__)
/* anonymous unions are enabled by default */
#elif defined(__TMS470__)
/* anonymous unions are enabled by default */
#elif defined(__TASKING__)
#pragma warning 586
#else
#warning Not supported compiler type
#endif
/* ================================================================================ */
/* ================ CPU FPGA System (CPU_SYS) ================ */
/* ================================================================================ */
typedef struct
{
__I uint32_t ID; /* Offset: 0x000 (R/ ) Board and FPGA Identifier */
__IO uint32_t MEMCFG; /* Offset: 0x004 (R/W) Remap and Alias Memory Control */
__I uint32_t SW; /* Offset: 0x008 (R/ ) Switch States */
__IO uint32_t LED; /* Offset: 0x00C (R/W) LED Output States */
__I uint32_t TS; /* Offset: 0x010 (R/ ) Touchscreen Register */
__IO uint32_t CTRL1; /* Offset: 0x014 (R/W) Misc Control Functions */
uint32_t RESERVED0[2];
__IO uint32_t CLKCFG; /* Offset: 0x020 (R/W) System Clock Configuration */
__IO uint32_t WSCFG; /* Offset: 0x024 (R/W) Flash Waitstate Configuration */
__IO uint32_t CPUCFG; /* Offset: 0x028 (R/W) Processor Configuration */
uint32_t RESERVED1[3];
__IO uint32_t BASE; /* Offset: 0x038 (R/W) ROM Table base Address */
__IO uint32_t ID2; /* Offset: 0x03C (R/W) Secondary Identification Register */
} ARM_CPU_SYS_TypeDef;
/* ================================================================================ */
/* ================ DUT FPGA System (DUT_SYS) ================ */
/* ================================================================================ */
typedef struct
{
__I uint32_t ID; /* Offset: 0x000 (R/ ) Board and FPGA Identifier */
__IO uint32_t PERCFG; /* Offset: 0x004 (R/W) Peripheral Control Signals */
__I uint32_t SW; /* Offset: 0x008 (R/ ) Switch States */
__IO uint32_t LED; /* Offset: 0x00C (R/W) LED Output States */
__IO uint32_t SEG7; /* Offset: 0x010 (R/W) 7-segment LED Output States */
__I uint32_t CNT25MHz; /* Offset: 0x014 (R/ ) Freerunning counter incrementing at 25MHz */
__I uint32_t CNT100Hz; /* Offset: 0x018 (R/ ) Freerunning counter incrementing at 100Hz */
} ARM_DUT_SYS_TypeDef;
/* ================================================================================ */
/* ================ Timer (TIM) ================ */
/* ================================================================================ */
typedef struct
{
__IO uint32_t Timer1Load; /* Offset: 0x000 (R/W) Timer 1 Load */
__I uint32_t Timer1Value; /* Offset: 0x004 (R/ ) Timer 1 Counter Current Value */
__IO uint32_t Timer1Control; /* Offset: 0x008 (R/W) Timer 1 Control */
__O uint32_t Timer1IntClr; /* Offset: 0x00C ( /W) Timer 1 Interrupt Clear */
__I uint32_t Timer1RIS; /* Offset: 0x010 (R/ ) Timer 1 Raw Interrupt Status */
__I uint32_t Timer1MIS; /* Offset: 0x014 (R/ ) Timer 1 Masked Interrupt Status */
__IO uint32_t Timer1BGLoad; /* Offset: 0x018 (R/W) Background Load Register */
uint32_t RESERVED0[1];
__IO uint32_t Timer2Load; /* Offset: 0x020 (R/W) Timer 2 Load */
__I uint32_t Timer2Value; /* Offset: 0x024 (R/ ) Timer 2 Counter Current Value */
__IO uint32_t Timer2Control; /* Offset: 0x028 (R/W) Timer 2 Control */
__O uint32_t Timer2IntClr; /* Offset: 0x02C ( /W) Timer 2 Interrupt Clear */
__I uint32_t Timer2RIS; /* Offset: 0x030 (R/ ) Timer 2 Raw Interrupt Status */
__I uint32_t Timer2MIS; /* Offset: 0x034 (R/ ) Timer 2 Masked Interrupt Status */
__IO uint32_t Timer2BGLoad; /* Offset: 0x038 (R/W) Background Load Register */
} ARM_TIM_TypeDef;
/* ================================================================================ */
/* ============== Universal Asyncronous Receiver / Transmitter (UART) ============= */
/* ================================================================================ */
typedef struct
{
__IO uint32_t DR; /* Offset: 0x000 (R/W) Data */
union {
__I uint32_t RSR; /* Offset: 0x000 (R/ ) Receive Status */
__O uint32_t ECR; /* Offset: 0x000 ( /W) Error Clear */
};
uint32_t RESERVED0[4];
__IO uint32_t FR; /* Offset: 0x018 (R/W) Flags */
uint32_t RESERVED1[1];
__IO uint32_t ILPR; /* Offset: 0x020 (R/W) IrDA Low-power Counter */
__IO uint32_t IBRD; /* Offset: 0x024 (R/W) Interger Baud Rate */
__IO uint32_t FBRD; /* Offset: 0x028 (R/W) Fractional Baud Rate */
__IO uint32_t LCR_H; /* Offset: 0x02C (R/W) Line Control */
__IO uint32_t CR; /* Offset: 0x030 (R/W) Control */
__IO uint32_t IFLS; /* Offset: 0x034 (R/W) Interrupt FIFO Level Select */
__IO uint32_t IMSC; /* Offset: 0x038 (R/W) Interrupt Mask Set / Clear */
__IO uint32_t RIS; /* Offset: 0x03C (R/W) Raw Interrupt Status */
__IO uint32_t MIS; /* Offset: 0x040 (R/W) Masked Interrupt Status */
__O uint32_t ICR; /* Offset: 0x044 ( /W) Interrupt Clear */
__IO uint32_t DMACR; /* Offset: 0x048 (R/W) DMA Control */
} ARM_UART_TypeDef;
/* -------------------- End of section using anonymous unions ------------------- */
#if defined(__CC_ARM)
#pragma pop
#elif defined(__ICCARM__)
/* leave anonymous unions enabled */
#elif defined(__GNUC__)
/* anonymous unions are enabled by default */
#elif defined(__TMS470__)
/* anonymous unions are enabled by default */
#elif defined(__TASKING__)
#pragma warning restore
#else
#warning Not supported compiler type
#endif
/* ================================================================================ */
/* ================ Peripheral memory map ================ */
/* ================================================================================ */
/* -------------------------- CPU FPGA memory map ------------------------------- */
#define ARM_FLASH_BASE (0x00000000UL)
#define ARM_RAM_BASE (0x20000000UL)
#define ARM_RAM_FPGA_BASE (0x1EFF0000UL)
#define ARM_CPU_CFG_BASE (0xDFFF0000UL)
#define ARM_CPU_SYS_BASE (ARM_CPU_CFG_BASE + 0x00000)
#define ARM_UART3_BASE (ARM_CPU_CFG_BASE + 0x05000)
/* -------------------------- DUT FPGA memory map ------------------------------- */
#define ARM_APB_BASE (0x40000000UL)
#define ARM_AHB_BASE (0x4FF00000UL)
#define ARM_DMC_BASE (0x60000000UL)
#define ARM_SMC_BASE (0xA0000000UL)
#define ARM_TIM0_BASE (ARM_APB_BASE + 0x02000)
#define ARM_TIM2_BASE (ARM_APB_BASE + 0x03000)
#define ARM_DUT_SYS_BASE (ARM_APB_BASE + 0x04000)
#define ARM_UART0_BASE (ARM_APB_BASE + 0x06000)
#define ARM_UART1_BASE (ARM_APB_BASE + 0x07000)
#define ARM_UART2_BASE (ARM_APB_BASE + 0x08000)
#define ARM_UART4_BASE (ARM_APB_BASE + 0x09000)
/* ================================================================================ */
/* ================ Peripheral declaration ================ */
/* ================================================================================ */
/* -------------------------- CPU FPGA Peripherals ------------------------------ */
#define ARM_CPU_SYS ((ARM_CPU_SYS_TypeDef *) ARM_CPU_SYS_BASE)
#define ARM_UART3 (( ARM_UART_TypeDef *) ARM_UART3_BASE)
/* -------------------------- DUT FPGA Peripherals ------------------------------ */
#define ARM_DUT_SYS ((ARM_DUT_SYS_TypeDef *) ARM_DUT_SYS_BASE)
#define ARM_TIM0 (( ARM_TIM_TypeDef *) ARM_TIM0_BASE)
#define ARM_TIM2 (( ARM_TIM_TypeDef *) ARM_TIM2_BASE)
#define ARM_UART0 (( ARM_UART_TypeDef *) ARM_UART0_BASE)
#define ARM_UART1 (( ARM_UART_TypeDef *) ARM_UART1_BASE)
#define ARM_UART2 (( ARM_UART_TypeDef *) ARM_UART2_BASE)
#define ARM_UART4 (( ARM_UART_TypeDef *) ARM_UART4_BASE)
#ifdef __cplusplus
}
#endif
#endif /* ARMCM3_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,636 @@
/**************************************************************************//**
* @file core_cmFunc.h
* @brief CMSIS Cortex-M Core Function Access Header File
* @version V3.20
* @date 25. February 2013
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2013 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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 __CORE_CMFUNC_H
#define __CORE_CMFUNC_H
#include <stdint.h>
/* ########################### Core Function Access ########################### */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
@{
*/
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
/* ARM armcc specific functions */
#if (__ARMCC_VERSION < 400677)
#error "Please use ARM Compiler Toolchain V4.0.677 or later!"
#endif
/* intrinsic void __enable_irq(); */
/* intrinsic void __disable_irq(); */
/** \brief Get Control Register
This function returns the content of the Control Register.
\return Control Register value
*/
__STATIC_INLINE uint32_t __get_CONTROL(void)
{
register uint32_t __regControl __ASM("control");
return(__regControl);
}
/** \brief Set Control Register
This function writes the given value to the Control Register.
\param [in] control Control Register value to set
*/
__STATIC_INLINE void __set_CONTROL(uint32_t control)
{
register uint32_t __regControl __ASM("control");
__regControl = control;
}
/** \brief Get IPSR Register
This function returns the content of the IPSR Register.
\return IPSR Register value
*/
__STATIC_INLINE uint32_t __get_IPSR(void)
{
register uint32_t __regIPSR __ASM("ipsr");
return(__regIPSR);
}
/** \brief Get APSR Register
This function returns the content of the APSR Register.
\return APSR Register value
*/
__STATIC_INLINE uint32_t __get_APSR(void)
{
register uint32_t __regAPSR __ASM("apsr");
return(__regAPSR);
}
/** \brief Get xPSR Register
This function returns the content of the xPSR Register.
\return xPSR Register value
*/
__STATIC_INLINE uint32_t __get_xPSR(void)
{
register uint32_t __regXPSR __ASM("xpsr");
return(__regXPSR);
}
/** \brief Get Process Stack Pointer
This function returns the current value of the Process Stack Pointer (PSP).
\return PSP Register value
*/
__STATIC_INLINE uint32_t __get_PSP(void)
{
register uint32_t __regProcessStackPointer __ASM("psp");
return(__regProcessStackPointer);
}
/** \brief Set Process Stack Pointer
This function assigns the given value to the Process Stack Pointer (PSP).
\param [in] topOfProcStack Process Stack Pointer value to set
*/
__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
{
register uint32_t __regProcessStackPointer __ASM("psp");
__regProcessStackPointer = topOfProcStack;
}
/** \brief Get Main Stack Pointer
This function returns the current value of the Main Stack Pointer (MSP).
\return MSP Register value
*/
__STATIC_INLINE uint32_t __get_MSP(void)
{
register uint32_t __regMainStackPointer __ASM("msp");
return(__regMainStackPointer);
}
/** \brief Set Main Stack Pointer
This function assigns the given value to the Main Stack Pointer (MSP).
\param [in] topOfMainStack Main Stack Pointer value to set
*/
__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
{
register uint32_t __regMainStackPointer __ASM("msp");
__regMainStackPointer = topOfMainStack;
}
/** \brief Get Priority Mask
This function returns the current state of the priority mask bit from the Priority Mask Register.
\return Priority Mask value
*/
__STATIC_INLINE uint32_t __get_PRIMASK(void)
{
register uint32_t __regPriMask __ASM("primask");
return(__regPriMask);
}
/** \brief Set Priority Mask
This function assigns the given value to the Priority Mask Register.
\param [in] priMask Priority Mask
*/
__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
{
register uint32_t __regPriMask __ASM("primask");
__regPriMask = (priMask);
}
#if (__CORTEX_M >= 0x03)
/** \brief Enable FIQ
This function enables FIQ interrupts by clearing the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
#define __enable_fault_irq __enable_fiq
/** \brief Disable FIQ
This function disables FIQ interrupts by setting the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
#define __disable_fault_irq __disable_fiq
/** \brief Get Base Priority
This function returns the current value of the Base Priority register.
\return Base Priority register value
*/
__STATIC_INLINE uint32_t __get_BASEPRI(void)
{
register uint32_t __regBasePri __ASM("basepri");
return(__regBasePri);
}
/** \brief Set Base Priority
This function assigns the given value to the Base Priority register.
\param [in] basePri Base Priority value to set
*/
__STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
{
register uint32_t __regBasePri __ASM("basepri");
__regBasePri = (basePri & 0xff);
}
/** \brief Get Fault Mask
This function returns the current value of the Fault Mask register.
\return Fault Mask register value
*/
__STATIC_INLINE uint32_t __get_FAULTMASK(void)
{
register uint32_t __regFaultMask __ASM("faultmask");
return(__regFaultMask);
}
/** \brief Set Fault Mask
This function assigns the given value to the Fault Mask register.
\param [in] faultMask Fault Mask value to set
*/
__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
{
register uint32_t __regFaultMask __ASM("faultmask");
__regFaultMask = (faultMask & (uint32_t)1);
}
#endif /* (__CORTEX_M >= 0x03) */
#if (__CORTEX_M == 0x04)
/** \brief Get FPSCR
This function returns the current value of the Floating Point Status/Control register.
\return Floating Point Status/Control register value
*/
__STATIC_INLINE uint32_t __get_FPSCR(void)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
register uint32_t __regfpscr __ASM("fpscr");
return(__regfpscr);
#else
return(0);
#endif
}
/** \brief Set FPSCR
This function assigns the given value to the Floating Point Status/Control register.
\param [in] fpscr Floating Point Status/Control value to set
*/
__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
register uint32_t __regfpscr __ASM("fpscr");
__regfpscr = (fpscr);
#endif
}
#endif /* (__CORTEX_M == 0x04) */
#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
/* IAR iccarm specific functions */
#include <cmsis_iar.h>
#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
/* TI CCS specific functions */
#include <cmsis_ccs.h>
#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
/* GNU gcc specific functions */
/** \brief Enable IRQ Interrupts
This function enables IRQ interrupts by clearing the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
{
__ASM volatile ("cpsie i" : : : "memory");
}
/** \brief Disable IRQ Interrupts
This function disables IRQ interrupts by setting the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
{
__ASM volatile ("cpsid i" : : : "memory");
}
/** \brief Get Control Register
This function returns the content of the Control Register.
\return Control Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void)
{
uint32_t result;
__ASM volatile ("MRS %0, control" : "=r" (result) );
return(result);
}
/** \brief Set Control Register
This function writes the given value to the Control Register.
\param [in] control Control Register value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control)
{
__ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
}
/** \brief Get IPSR Register
This function returns the content of the IPSR Register.
\return IPSR Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void)
{
uint32_t result;
__ASM volatile ("MRS %0, ipsr" : "=r" (result) );
return(result);
}
/** \brief Get APSR Register
This function returns the content of the APSR Register.
\return APSR Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void)
{
uint32_t result;
__ASM volatile ("MRS %0, apsr" : "=r" (result) );
return(result);
}
/** \brief Get xPSR Register
This function returns the content of the xPSR Register.
\return xPSR Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void)
{
uint32_t result;
__ASM volatile ("MRS %0, xpsr" : "=r" (result) );
return(result);
}
/** \brief Get Process Stack Pointer
This function returns the current value of the Process Stack Pointer (PSP).
\return PSP Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void)
{
register uint32_t result;
__ASM volatile ("MRS %0, psp\n" : "=r" (result) );
return(result);
}
/** \brief Set Process Stack Pointer
This function assigns the given value to the Process Stack Pointer (PSP).
\param [in] topOfProcStack Process Stack Pointer value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
{
__ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp");
}
/** \brief Get Main Stack Pointer
This function returns the current value of the Main Stack Pointer (MSP).
\return MSP Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
{
register uint32_t result;
__ASM volatile ("MRS %0, msp\n" : "=r" (result) );
return(result);
}
/** \brief Set Main Stack Pointer
This function assigns the given value to the Main Stack Pointer (MSP).
\param [in] topOfMainStack Main Stack Pointer value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
{
__ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
}
/** \brief Get Priority Mask
This function returns the current state of the priority mask bit from the Priority Mask Register.
\return Priority Mask value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void)
{
uint32_t result;
__ASM volatile ("MRS %0, primask" : "=r" (result) );
return(result);
}
/** \brief Set Priority Mask
This function assigns the given value to the Priority Mask Register.
\param [in] priMask Priority Mask
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
{
__ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
}
#if (__CORTEX_M >= 0x03)
/** \brief Enable FIQ
This function enables FIQ interrupts by clearing the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void)
{
__ASM volatile ("cpsie f" : : : "memory");
}
/** \brief Disable FIQ
This function disables FIQ interrupts by setting the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void)
{
__ASM volatile ("cpsid f" : : : "memory");
}
/** \brief Get Base Priority
This function returns the current value of the Base Priority register.
\return Base Priority register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void)
{
uint32_t result;
__ASM volatile ("MRS %0, basepri_max" : "=r" (result) );
return(result);
}
/** \brief Set Base Priority
This function assigns the given value to the Base Priority register.
\param [in] basePri Base Priority value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value)
{
__ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory");
}
/** \brief Get Fault Mask
This function returns the current value of the Fault Mask register.
\return Fault Mask register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
{
uint32_t result;
__ASM volatile ("MRS %0, faultmask" : "=r" (result) );
return(result);
}
/** \brief Set Fault Mask
This function assigns the given value to the Fault Mask register.
\param [in] faultMask Fault Mask value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
{
__ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
}
#endif /* (__CORTEX_M >= 0x03) */
#if (__CORTEX_M == 0x04)
/** \brief Get FPSCR
This function returns the current value of the Floating Point Status/Control register.
\return Floating Point Status/Control register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
uint32_t result;
/* Empty asm statement works as a scheduling barrier */
__ASM volatile ("");
__ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
__ASM volatile ("");
return(result);
#else
return(0);
#endif
}
/** \brief Set FPSCR
This function assigns the given value to the Floating Point Status/Control register.
\param [in] fpscr Floating Point Status/Control value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
/* Empty asm statement works as a scheduling barrier */
__ASM volatile ("");
__ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc");
__ASM volatile ("");
#endif
}
#endif /* (__CORTEX_M == 0x04) */
#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
/* TASKING carm specific functions */
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all instrinsics,
* Including the CMSIS ones.
*/
#endif
/*@} end of CMSIS_Core_RegAccFunctions */
#endif /* __CORE_CMFUNC_H */

View File

@ -0,0 +1,688 @@
/**************************************************************************//**
* @file core_cmInstr.h
* @brief CMSIS Cortex-M Core Instruction Access Header File
* @version V3.20
* @date 05. March 2013
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2013 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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 __CORE_CMINSTR_H
#define __CORE_CMINSTR_H
#include <stdint.h>
/* ########################## Core Instruction Access ######################### */
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
Access to dedicated instructions
@{
*/
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
/* ARM armcc specific functions */
#if (__ARMCC_VERSION < 400677)
#error "Please use ARM Compiler Toolchain V4.0.677 or later!"
#endif
/** \brief No Operation
No Operation does nothing. This instruction can be used for code alignment purposes.
*/
#define __NOP __nop
/** \brief Wait For Interrupt
Wait For Interrupt is a hint instruction that suspends execution
until one of a number of events occurs.
*/
#define __WFI __wfi
/** \brief Wait For Event
Wait For Event is a hint instruction that permits the processor to enter
a low-power state until one of a number of events occurs.
*/
#define __WFE __wfe
/** \brief Send Event
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
*/
#define __SEV __sev
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or
memory, after the instruction has been completed.
*/
#define __ISB() __isb(0xF)
/** \brief Data Synchronization Barrier
This function acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
#define __DSB() __dsb(0xF)
/** \brief Data Memory Barrier
This function ensures the apparent order of the explicit memory operations before
and after the instruction, without ensuring their completion.
*/
#define __DMB() __dmb(0xF)
/** \brief Reverse byte order (32 bit)
This function reverses the byte order in integer value.
\param [in] value Value to reverse
\return Reversed value
*/
#define __REV __rev
/** \brief Reverse byte order (16 bit)
This function reverses the byte order in two unsigned short values.
\param [in] value Value to reverse
\return Reversed value
*/
#ifndef __NO_EMBEDDED_ASM
__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
{
rev16 r0, r0
bx lr
}
#endif
/** \brief Reverse byte order in signed short value
This function reverses the byte order in a signed short value with sign extension to integer.
\param [in] value Value to reverse
\return Reversed value
*/
#ifndef __NO_EMBEDDED_ASM
__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)
{
revsh r0, r0
bx lr
}
#endif
/** \brief Rotate Right in unsigned value (32 bit)
This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
\param [in] value Value to rotate
\param [in] value Number of Bits to rotate
\return Rotated value
*/
#define __ROR __ror
/** \brief Breakpoint
This function causes the processor to enter Debug state.
Debug tools can use this to investigate system state when the instruction at a particular address is reached.
\param [in] value is ignored by the processor.
If required, a debugger can use it to store additional information about the breakpoint.
*/
#define __BKPT(value) __breakpoint(value)
#if (__CORTEX_M >= 0x03)
/** \brief Reverse bit order of value
This function reverses the bit order of the given value.
\param [in] value Value to reverse
\return Reversed value
*/
#define __RBIT __rbit
/** \brief LDR Exclusive (8 bit)
This function performs a exclusive LDR command for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
/** \brief LDR Exclusive (16 bit)
This function performs a exclusive LDR command for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
/** \brief LDR Exclusive (32 bit)
This function performs a exclusive LDR command for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
/** \brief STR Exclusive (8 bit)
This function performs a exclusive STR command for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXB(value, ptr) __strex(value, ptr)
/** \brief STR Exclusive (16 bit)
This function performs a exclusive STR command for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXH(value, ptr) __strex(value, ptr)
/** \brief STR Exclusive (32 bit)
This function performs a exclusive STR command for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXW(value, ptr) __strex(value, ptr)
/** \brief Remove the exclusive lock
This function removes the exclusive lock which is created by LDREX.
*/
#define __CLREX __clrex
/** \brief Signed Saturate
This function saturates a signed value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (1..32)
\return Saturated value
*/
#define __SSAT __ssat
/** \brief Unsigned Saturate
This function saturates an unsigned value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (0..31)
\return Saturated value
*/
#define __USAT __usat
/** \brief Count leading zeros
This function counts the number of leading zeros of a data value.
\param [in] value Value to count the leading zeros
\return number of leading zeros in value
*/
#define __CLZ __clz
#endif /* (__CORTEX_M >= 0x03) */
#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
/* IAR iccarm specific functions */
#include <cmsis_iar.h>
#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
/* TI CCS specific functions */
#include <cmsis_ccs.h>
#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
/* GNU gcc specific functions */
/* Define macros for porting to both thumb1 and thumb2.
* For thumb1, use low register (r0-r7), specified by constrant "l"
* Otherwise, use general registers, specified by constrant "r" */
#if defined (__thumb__) && !defined (__thumb2__)
#define __CMSIS_GCC_OUT_REG(r) "=l" (r)
#define __CMSIS_GCC_USE_REG(r) "l" (r)
#else
#define __CMSIS_GCC_OUT_REG(r) "=r" (r)
#define __CMSIS_GCC_USE_REG(r) "r" (r)
#endif
/** \brief No Operation
No Operation does nothing. This instruction can be used for code alignment purposes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __NOP(void)
{
__ASM volatile ("nop");
}
/** \brief Wait For Interrupt
Wait For Interrupt is a hint instruction that suspends execution
until one of a number of events occurs.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFI(void)
{
__ASM volatile ("wfi");
}
/** \brief Wait For Event
Wait For Event is a hint instruction that permits the processor to enter
a low-power state until one of a number of events occurs.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFE(void)
{
__ASM volatile ("wfe");
}
/** \brief Send Event
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __SEV(void)
{
__ASM volatile ("sev");
}
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or
memory, after the instruction has been completed.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __ISB(void)
{
__ASM volatile ("isb");
}
/** \brief Data Synchronization Barrier
This function acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __DSB(void)
{
__ASM volatile ("dsb");
}
/** \brief Data Memory Barrier
This function ensures the apparent order of the explicit memory operations before
and after the instruction, without ensuring their completion.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __DMB(void)
{
__ASM volatile ("dmb");
}
/** \brief Reverse byte order (32 bit)
This function reverses the byte order in integer value.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV(uint32_t value)
{
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
return __builtin_bswap32(value);
#else
uint32_t result;
__ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
return(result);
#endif
}
/** \brief Reverse byte order (16 bit)
This function reverses the byte order in two unsigned short values.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV16(uint32_t value)
{
uint32_t result;
__ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
return(result);
}
/** \brief Reverse byte order in signed short value
This function reverses the byte order in a signed short value with sign extension to integer.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __REVSH(int32_t value)
{
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
return (short)__builtin_bswap16(value);
#else
uint32_t result;
__ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
return(result);
#endif
}
/** \brief Rotate Right in unsigned value (32 bit)
This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
\param [in] value Value to rotate
\param [in] value Number of Bits to rotate
\return Rotated value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
{
return (op1 >> op2) | (op1 << (32 - op2));
}
/** \brief Breakpoint
This function causes the processor to enter Debug state.
Debug tools can use this to investigate system state when the instruction at a particular address is reached.
\param [in] value is ignored by the processor.
If required, a debugger can use it to store additional information about the breakpoint.
*/
#define __BKPT(value) __ASM volatile ("bkpt "#value)
#if (__CORTEX_M >= 0x03)
/** \brief Reverse bit order of value
This function reverses the bit order of the given value.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
{
uint32_t result;
__ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
/** \brief LDR Exclusive (8 bit)
This function performs a exclusive LDR command for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr)
{
uint32_t result;
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
__ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
#else
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
accepted by assembler. So has to use following less efficient pattern.
*/
__ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
#endif
return(result);
}
/** \brief LDR Exclusive (16 bit)
This function performs a exclusive LDR command for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr)
{
uint32_t result;
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
__ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
#else
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
accepted by assembler. So has to use following less efficient pattern.
*/
__ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
#endif
return(result);
}
/** \brief LDR Exclusive (32 bit)
This function performs a exclusive LDR command for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr)
{
uint32_t result;
__ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
return(result);
}
/** \brief STR Exclusive (8 bit)
This function performs a exclusive STR command for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
{
uint32_t result;
__ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
return(result);
}
/** \brief STR Exclusive (16 bit)
This function performs a exclusive STR command for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
{
uint32_t result;
__ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
return(result);
}
/** \brief STR Exclusive (32 bit)
This function performs a exclusive STR command for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
{
uint32_t result;
__ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
return(result);
}
/** \brief Remove the exclusive lock
This function removes the exclusive lock which is created by LDREX.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __CLREX(void)
{
__ASM volatile ("clrex" ::: "memory");
}
/** \brief Signed Saturate
This function saturates a signed value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (1..32)
\return Saturated value
*/
#define __SSAT(ARG1,ARG2) \
({ \
uint32_t __RES, __ARG1 = (ARG1); \
__ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
__RES; \
})
/** \brief Unsigned Saturate
This function saturates an unsigned value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (0..31)
\return Saturated value
*/
#define __USAT(ARG1,ARG2) \
({ \
uint32_t __RES, __ARG1 = (ARG1); \
__ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
__RES; \
})
/** \brief Count leading zeros
This function counts the number of leading zeros of a data value.
\param [in] value Value to count the leading zeros
\return number of leading zeros in value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __CLZ(uint32_t value)
{
uint32_t result;
__ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
#endif /* (__CORTEX_M >= 0x03) */
#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
/* TASKING carm specific functions */
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
#endif
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
#endif /* __CORE_CMINSTR_H */

View File

@ -37,7 +37,6 @@
#ifndef _LOS_HW_H
#define _LOS_HW_H
#include "los_base.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {

View File

@ -0,0 +1,163 @@
;
; 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.
;
PRESERVE8
EXPORT LOS_IntLock
EXPORT LOS_IntUnLock
EXPORT LOS_IntRestore
EXPORT LOS_StartToRun
EXPORT osTaskSchedule
EXPORT osPendSV
IMPORT g_losTask
IMPORT g_taskSwitchHook
IMPORT g_taskScheduled
OS_NVIC_INT_CTRL EQU 0xE000ED04
OS_NVIC_SYSPRI2 EQU 0xE000ED20
OS_NVIC_PENDSV_PRI EQU 0xF0F00000
OS_NVIC_PENDSVSET EQU 0x10000000
OS_TASK_STATUS_RUNNING EQU 0x0010
AREA |.text|, CODE, READONLY
THUMB
REQUIRE8
LOS_StartToRun
LDR R4, =OS_NVIC_SYSPRI2
LDR R5, =OS_NVIC_PENDSV_PRI
STR R5, [R4]
LDR R0, =g_taskScheduled
MOV R1, #1
STR R1, [R0]
MOV R0, #2
MSR CONTROL, R0
LDR R0, =g_losTask
LDR R2, [R0, #4]
LDR R0, =g_losTask
STR R2, [R0]
LDR R3, =g_losTask
LDR R0, [R3]
LDRH R7, [R0 , #4]
MOV R8, #OS_TASK_STATUS_RUNNING
ORR R7, R7, R8
STRH R7, [R0 , #4]
LDR R12, [R0]
;ADD R12, R12, #100
ADD R12, R12, #36
LDMFD R12!, {R0-R7}
;ADD R12, R12, #72
MSR PSP, R12
;VPUSH S0;
;VPOP S0;
MOV LR, R5
;MSR xPSR, R7
CPSIE I
BX R6
LOS_IntLock
MRS R0, PRIMASK
CPSID I
BX LR
LOS_IntUnLock
MRS R0, PRIMASK
CPSIE I
BX LR
LOS_IntRestore
MSR PRIMASK, R0
BX LR
osTaskSchedule
LDR R0, =OS_NVIC_INT_CTRL
LDR R1, =OS_NVIC_PENDSVSET
STR R1, [R0]
BX LR
osPendSV
MRS R12, PRIMASK
CPSID I
LDR R2, =g_taskSwitchHook
LDR R2, [R2]
CBZ R2, TaskSwitch
PUSH {R12, LR}
BLX R2
POP {R12, LR}
TaskSwitch
MRS R0, PSP
STMFD R0!, {R4-R12}
;VSTMDB R0!, {D8-D15}
LDR R5, =g_losTask
LDR R6, [R5]
STR R0, [R6]
LDRH R7, [R6 , #4]
MOV R8,#OS_TASK_STATUS_RUNNING
BIC R7, R7, R8
STRH R7, [R6 , #4]
LDR R0, =g_losTask
LDR R0, [R0, #4]
STR R0, [R5]
LDRH R7, [R0 , #4]
MOV R8, #OS_TASK_STATUS_RUNNING
ORR R7, R7, R8
STRH R7, [R0 , #4]
LDR R1, [R0]
;VLDMIA R1!, {D8-D15}
LDMFD R1!, {R4-R12}
MSR PSP, R1
MSR PRIMASK, R12
BX LR
END

View File

@ -0,0 +1,149 @@
/*
* 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 "los_task.h"
#include "securec.h"
#include "ARMCM3.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* ****************************************************************************
Function : OsTaskExit
Description : Task exit function
Input : None
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID OsTaskExit(VOID)
{
LOS_IntLock();
for(;;);
}
/* ****************************************************************************
Function : OsTskStackInit
Description : Task stack initialization function
Input : taskID --- TaskID
stackSize --- Total size of the stack
topStack --- Top of task's stack
Output : None
Return : Context pointer
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
{
TaskContext *context = NULL;
errno_t result;
/* initialize the task stack, write magic num to stack top */
result = memset_s(topStack, stackSize, (INT32)(OS_TASK_STACK_INIT & 0xFF), stackSize);
if (result != EOK) {
printf("memset_s is failed:%s[%d]\r\n", __FUNCTION__, __LINE__);
}
*((UINT32 *)(topStack)) = OS_TASK_MAGIC_WORD;
context = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext));
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U)))
context->S16 = 0xAA000010;
context->S17 = 0xAA000011;
context->S18 = 0xAA000012;
context->S19 = 0xAA000013;
context->S20 = 0xAA000014;
context->S21 = 0xAA000015;
context->S22 = 0xAA000016;
context->S23 = 0xAA000017;
context->S24 = 0xAA000018;
context->S25 = 0xAA000019;
context->S26 = 0xAA00001A;
context->S27 = 0xAA00001B;
context->S28 = 0xAA00001C;
context->S29 = 0xAA00001D;
context->S30 = 0xAA00001E;
context->S31 = 0xAA00001F;
context->S0 = 0xAA000000;
context->S1 = 0xAA000001;
context->S2 = 0xAA000002;
context->S3 = 0xAA000003;
context->S4 = 0xAA000004;
context->S5 = 0xAA000005;
context->S6 = 0xAA000006;
context->S7 = 0xAA000007;
context->S8 = 0xAA000008;
context->S9 = 0xAA000009;
context->S10 = 0xAA00000A;
context->S11 = 0xAA00000B;
context->S12 = 0xAA00000C;
context->S13 = 0xAA00000D;
context->S14 = 0xAA00000E;
context->S15 = 0xAA00000F;
context->FPSCR = 0x00000000;
context->NO_NAME = 0xAA000011;
#endif
context->uwR4 = 0x04040404L;
context->uwR5 = 0x05050505L;
context->uwR6 = 0x06060606L;
context->uwR7 = 0x07070707L;
context->uwR8 = 0x08080808L;
context->uwR9 = 0x09090909L;
context->uwR10 = 0x10101010L;
context->uwR11 = 0x11111111L;
context->uwPriMask = 0;
context->uwR0 = taskID;
context->uwR1 = 0x01010101L;
context->uwR2 = 0x02020202L;
context->uwR3 = 0x03030303L;
context->uwR12 = 0x12121212L;
context->uwLR = (UINT32)(UINTPTR)OsTaskExit;
context->uwPC = (UINT32)(UINTPTR)OsTaskEntry;
context->uwxPSR = 0x01000000L;
return (VOID *)context;
}
LITE_OS_SEC_TEXT_INIT VOID OsEnterSleep(VOID)
{
__DSB();
__WFI();
__ISB();
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@ -0,0 +1,287 @@
;
; 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.
;
PRESERVE8
AREA |.text|, CODE, READONLY
THUMB
EXPORT OsExcNMI
EXPORT OsExcHardFault
EXPORT OsExcMemFault
EXPORT OsExcBusFault
EXPORT OsExcUsageFault
EXPORT OsExcSvcCall
IMPORT OsExcHandleEntry
;IMPORT g_vuwLosFlag
;IMPORT g_curNestCount
IMPORT g_uwExcTbl
IMPORT g_taskScheduled
OS_FLG_BGD_ACTIVE EQU 0x0002
OS_EXC_CAUSE_NMI EQU 16
OS_EXC_CAUSE_HARDFAULT EQU 17
HF_DEBUGEVT EQU 20
HF_VECTBL EQU 21
FLAG_ADDR_VALID EQU 0x10000
FLAG_HWI_ACTIVE EQU 0x20000
FLAG_NO_FLOAT EQU 0x10000000
OS_NVIC_FSR EQU 0xE000ED28 ;include BusFault/MemFault/UsageFault State Regeister
OS_NVIC_HFSR EQU 0xE000ED2C ;HardFault State Regeister
OS_NVIC_BFAR EQU 0xE000ED38
OS_NVIC_MMAR EQU 0xE000ED34
OS_NVIC_ACT_BASE EQU 0xE000E300
OS_NVIC_SHCSRS EQU 0xE000ED24
OS_NVIC_SHCSR_MASK EQU 0xC00
OsExcNMI
MOV R0, #OS_EXC_CAUSE_NMI
MOV R1, #0
B osExcDispatch
OsExcHardFault
MOV R0, #OS_EXC_CAUSE_HARDFAULT
LDR R2, =OS_NVIC_HFSR
LDR R2, [R2]
MOV R1, #HF_DEBUGEVT
ORR R0, R0, R1, LSL #0x8
TST R2, #0x80000000
BNE osExcDispatch ; DEBUGEVT
AND R0, R0 , #0x000000FF
MOV R1, #HF_VECTBL
ORR R0, R0, R1, LSL #0x8
TST R2, #0x00000002
BNE osExcDispatch ; VECTBL
;if not DEBUGEVT and VECTBL then is FORCED
AND R0, R0, #0x000000FF
LDR R2, =OS_NVIC_FSR
LDR R2, [R2]
TST R2, #0x8000 ; BFARVALID
BNE _HFBusFault ; BusFault
TST R2, #0x80 ; MMARVALID
BNE _HFMemFault ; MemFault
MOV R12,#0
B osHFExcCommonBMU
_HFBusFault
LDR R1, =OS_NVIC_BFAR
LDR R1, [R1]
MOV R12, #FLAG_ADDR_VALID
B osHFExcCommonBMU
_HFMemFault
LDR R1, =OS_NVIC_MMAR
LDR R1, [R1]
MOV R12, #FLAG_ADDR_VALID
osHFExcCommonBMU
CLZ R2, R2
LDR R3, =g_uwExcTbl
ADD R3, R3, R2
LDRB R2, [R3]
ORR R0, R0, R2, LSL #0x8
ORR R0, R0 ,R12
B osExcDispatch
OsExcSvcCall
TST LR, #0x4
ITE EQ
MRSEQ R0, MSP
MRSNE R0, PSP
LDR R1, [R0,#24]
LDRB R0, [R1,#-2]
MOV R1, #0
B osExcDispatch
OsExcBusFault
LDR R0, =OS_NVIC_FSR
LDR R0, [R0]
TST R0, #0x8000 ; BFARVALID
BEQ _ExcBusNoADDR
LDR R1, =OS_NVIC_BFAR
LDR R1, [R1]
MOV R12, #FLAG_ADDR_VALID
AND R0, R0, #0x1F00
B osExcCommonBMU
_ExcBusNoADDR
MOV R12,#0
B osExcCommonBMU
OsExcMemFault
LDR R0, =OS_NVIC_FSR
LDR R0, [R0]
TST R0, #0x80 ; MMARVALID
BEQ _ExcMemNoADDR
LDR R1, =OS_NVIC_MMAR
LDR R1, [R1]
MOV R12, #FLAG_ADDR_VALID
AND R0, R0, #0x1B
B osExcCommonBMU
_ExcMemNoADDR
MOV R12,#0
B osExcCommonBMU
OsExcUsageFault
LDR R0, =OS_NVIC_FSR
LDR R0, [R0]
MOV R1, #0x030F
LSL R1, R1, #16
AND R0, R0, R1
MOV R12, #0
osExcCommonBMU
CLZ R0, R0
LDR R3, =g_uwExcTbl
ADD R3, R3, R0
LDRB R0, [R3]
ORR R0, R0, R12
; R0 -- EXCCAUSE(bit 16 is 1 if EXCADDR valid), R1 -- EXCADDR
osExcDispatch
LDR R2, =OS_NVIC_ACT_BASE
MOV R12, #8 ; R12 is hwi check loop counter
_hwiActiveCheck
LDR R3, [R2] ; R3 store active hwi register when exc
CMP R3, #0
BEQ _hwiActiveCheckNext
; exc occured in IRQ
ORR R0, R0, #FLAG_HWI_ACTIVE
RBIT R2, R3
CLZ R2, R2
AND R12, R12, #1
ADD R2, R2, R12, LSL #5 ; calculate R2 (hwi number) as uwPid
_ExcInMSP
CMP LR, #0XFFFFFFED
BNE _NoFloatInMsp
ADD R3, R13, #104
PUSH {R3}
MRS R12, PRIMASK ; store message-->exc: disable int?
PUSH {R4-R12} ; store message-->exc: {R4-R12}
;VPUSH {D8-D15}
B _handleEntry
_NoFloatInMsp
ADD R3, R13, #32
PUSH {R3} ; save IRQ SP ; store message-->exc: MSP(R13)
MRS R12, PRIMASK ; store message-->exc: disable int?
PUSH {R4-R12} ; store message-->exc: {R4-R12}
ORR R0, R0, #FLAG_NO_FLOAT
B _handleEntry
_hwiActiveCheckNext
ADD R2, R2, #4 ; next NVIC ACT ADDR
SUBS R12, R12, #1
BNE _hwiActiveCheck
;/*NMI interrupt excption*/
LDR R2, =OS_NVIC_SHCSRS
LDRH R2,[R2]
LDR R3,=OS_NVIC_SHCSR_MASK
AND R2, R2,R3
CMP R2,#0
BNE _ExcInMSP
; exc occured in Task or Init or exc
; reserved for register info from task stack
LDR R2, =g_taskScheduled
LDR R2, [R2]
TST R2, #1 ; OS_FLG_BGD_ACTIVE
BEQ _ExcInMSP ; if exc occured in Init then branch
CMP LR, #0xFFFFFFED ;auto push floating registers
BNE _NoFloatInPsp
; exc occured in Task
MOV R2, R13
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
MRS R3, PSP
ADD R12, R3, #104
PUSH {R12} ; save task SP
MRS R12, PRIMASK
PUSH {R4-R12}
;VPUSH {D8-D15}
; copy auto saved task register
LDMFD R3!, {R4-R11} ; R4-R11 store PSP reg(auto push when exc in task)
;VLDMIA R3!, {D8-D15}
;VSTMDB R2!, {D8-D15}
STMFD R2!, {R4-R11}
B _handleEntry
_NoFloatInPsp
MOV R2, R13 ;no auto push floating registers
SUB R13, #32 ; add 8 Bytes reg(for STMFD)
MRS R3, PSP
ADD R12, R3, #32
PUSH {R12} ; save task SP
MRS R12, PRIMASK
PUSH {R4-R12}
LDMFD R3, {R4-R11} ; R4-R11 store PSP reg(auto push when exc in task)
STMFD R2!, {R4-R11}
ORR R0, R0, #FLAG_NO_FLOAT
_handleEntry
MOV R3, R13 ; R13:the 4th param
CPSID I
CPSID F
B OsExcHandleEntry
NOP
END

View File

@ -0,0 +1,267 @@
/*
* 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 "los_tick.h"
#include "los_interrupt.h"
#include "ARMCM3.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#define TICK_CHECK 0x4000000
#define CYCLE_CHECK 0xFFFFFFFFU
#define SHIFT_32_BIT 32
/* ****************************************************************************
Function : OsTickStart
Description : Configure Tick Interrupt Start
Input : none
output : none
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT UINT32 OsTickStart(VOID)
{
UINT32 ret;
if ((OS_SYS_CLOCK == 0) ||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
return LOS_ERRNO_TICK_CFG_INVALID;
}
#if (OS_HWI_WITH_ARG == YES)
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)OsTickHandler, NULL);
#else
OsSetVector(SysTick_IRQn, OsTickHandler);
#endif
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
g_ullTickCount = 0;
ret = SysTick_Config(g_cyclesPerTick);
if (ret == 1) {
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
}
return LOS_OK;
}
#if (LOSCFG_KERNEL_TICKLESS == YES)
/* ****************************************************************************
Function : LOS_SysTickReload
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
Input : none
output : none
return : hwCycle --- the system cycle count
**************************************************************************** */
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysTickCurrCycleGet(VOID)
{
UINT32 hwCycle;
UINTPTR intSave;
intSave = LOS_IntLock();
hwCycle = SysTick->VAL;
/* tick has come, but may interrupt environment, not counting the Tick interrupt response, to do +1 */
if ((SCB->ICSR & TICK_CHECK) != 0) {
hwCycle = SysTick->VAL;
hwCycle += g_cyclesPerTick;
}
LOS_IntRestore(intSave);
return hwCycle;
}
/* ****************************************************************************
Function : LOS_GetCpuCycle
Description : Get System cycle count
Input : none
output : cntHi --- CpuTick High 4 byte
cntLo --- CpuTick Low 4 byte
return : none
**************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *cntHi, UINT32 *cntLo)
{
UINT64 swTick;
UINT64 cycle;
UINT32 hwCycle;
UINTPTR intSave;
intSave = LOS_IntLock();
swTick = g_ullTickCount;
hwCycle = SysTick->VAL;
/* tick has come, but may interrupt environment, not counting the Tick interrupt response, to do +1 */
if ((SCB->ICSR & TICK_CHECK) != 0) {
hwCycle = SysTick->VAL;
swTick++;
}
cycle = (((swTick) * g_cyclesPerTick) + (g_cyclesPerTick - hwCycle));
*cntHi = cycle >> SHIFT_32_BIT;
*cntLo = cycle & CYCLE_CHECK;
LOS_IntRestore(intSave);
return;
}
/* ****************************************************************************
Function : LOS_GetSystickCycle
Description : Get Sys tick cycle count
Input : none
output : cntHi --- SysTick count High 4 byte
cntLo --- SysTick count Low 4 byte
return : none
**************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetSystickCycle(UINT32 *cntHi, UINT32 *cntLo)
{
UINT64 swTick;
UINT64 cycle;
UINT32 hwCycle;
UINTPTR intSave;
UINT32 systickLoad;
UINT32 systickCur;
intSave = LOS_IntLock();
swTick = g_ullTickCount;
systickLoad = SysTick->LOAD;
systickCur = SysTick->VAL;
if (systickLoad < systickCur) {
LOS_IntRestore(intSave);
return;
}
hwCycle = systickLoad - systickCur;
/* tick has come, but may interrupt environment, not counting the Tick interrupt response, to do +1 */
if ((SCB->ICSR & TICK_CHECK) != 0) {
hwCycle = systickLoad - systickCur;
swTick++;
}
cycle = hwCycle + swTick * systickLoad;
*cntHi = cycle >> SHIFT_32_BIT;
*cntLo = cycle & CYCLE_CHECK;
LOS_IntRestore(intSave);
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;
VOID LOS_TickLock(VOID)
{
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}
VOID LOS_TickUnlock(VOID)
{
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
}
BOOL LOS_GetSysSleepFlag(VOID)
{
return g_sysSleepFlag;
}
VOID LOS_ClearSysSleepFlag(VOID)
{
g_sysSleepFlag = FALSE;
}
VOID LOS_EnterSleep(LOS_SysSleepEnum sleep)
{
__DSB();
__WFI();
__ISB();
}
VOID LOS_SystemWakeup(UINT32 hwiIndex)
{
}
//extern unsigned int SystemCoreClock;
void LOS_HalDelay(UINT32 ticks)
{
UINT32 delayTimes;
#if 0
/* there are 4 machine cycle in loop */
if ((ticks * (SystemCoreClock / MACHINE_CYCLE_DEALAY_TIMES)) >= 0xffffffff) {
delayTimes = 0xffffffff;
} else {
delayTimes = ticks * (SystemCoreClock / MACHINE_CYCLE_DEALAY_TIMES);
}
while (delayTimes) {
delayTimes = delayTimes - 1;
}
#endif
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cpluscplus */
#endif /* __cpluscplus */

View File

@ -0,0 +1,450 @@
/*
* 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 "los_interrupt.h"
#include <stdarg.h>
#include "los_debug.h"
#include "los_task.h"
#if (LOSCFG_KERNEL_TICKLESS == YES)
#include "los_tick.h"
#endif
#include "ARMCM3.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/*lint -save -e40 -e522 -e533*/
__weak VOID SysTickHandler(VOID)
{
return;
}
UINT32 g_vuwIntCount = 0;
/*lint -restore*/
#ifdef __ICCARM__
#pragma location = ".data.vector"
#elif defined(__CC_ARM) || defined(__GNUC__)
LITE_OS_SEC_VEC
#endif
HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {
(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 == YES)
HWI_SLAVE_FUNC g_hwiSlaveForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
#else
HWI_PROC_FUNC g_hwiSlaveForm[OS_VECTOR_CNT] = {0};
#endif
/* ****************************************************************************
Function : OsIntNumGet
Description : Get a interrupt number
Input : None
Output : None
Return : Interrupt Indexes number
**************************************************************************** */
LITE_OS_SEC_TEXT_MINOR UINT32 OsIntNumGet(VOID)
{
return __get_IPSR();
}
/* ****************************************************************************
Function : OsHwiDefaultHandler
Description : default handler of the hardware interrupt
Input : None
Output : None
Return : None
**************************************************************************** */
/*lint -e529*/
LITE_OS_SEC_TEXT_MINOR VOID OsHwiDefaultHandler(VOID)
{
UINT32 irqNum = OsIntNumGet();
PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
while (1) {}
}
/* ****************************************************************************
Function : OsInterrupt
Description : Hardware interrupt entry function
Input : None
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT VOID OsInterrupt(VOID)
{
UINT32 hwiIndex;
UINT32 intSave;
#if (LOSCFG_KERNEL_RUNSTOP == YES)
SCB->SCR &= (UINT32) ~((UINT32)SCB_SCR_SLEEPDEEP_Msk);
#endif
intSave = LOS_IntLock();
g_vuwIntCount++;
LOS_IntRestore(intSave);
hwiIndex = OsIntNumGet();
#if (LOSCFG_KERNEL_TICKLESS == YES)
osUpdateKernelTickCount(hwiIndex);
#endif
#if (OS_HWI_WITH_ARG == YES)
if (g_hwiSlaveForm[hwiIndex].pfnHandler != 0) {
g_hwiSlaveForm[hwiIndex].pfnHandler((VOID *)g_hwiSlaveForm[hwiIndex].pParm);
}
#else
if (g_hwiSlaveForm[hwiIndex] != 0) {
g_hwiSlaveForm[hwiIndex]();
}
#endif
intSave = LOS_IntLock();
g_vuwIntCount--;
LOS_IntRestore(intSave);
}
/* ****************************************************************************
Function : LOS_HwiCreate
Description : create hardware interrupt
Input : hwiNum --- hwi num to create
hwiPrio --- priority of the hwi
mode --- unused
handler --- hwi handler
arg --- param of the hwi handler
Output : None
Return : LOS_OK on success or error code on failure
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
HWI_PRIOR_T hwiPrio,
HWI_MODE_T mode,
HWI_PROC_FUNC handler,
HWI_ARG_T arg)
{
UINTPTR intSave;
if (handler == NULL) {
return OS_ERRNO_HWI_PROC_FUNC_NULL;
}
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)OsHwiDefaultHandler) {
return OS_ERRNO_HWI_ALREADY_CREATED;
}
if (hwiPrio > OS_HWI_PRIO_LOWEST) {
return OS_ERRNO_HWI_PRIO_INVALID;
}
intSave = LOS_IntLock();
#if (OS_HWI_WITH_ARG == YES)
OsSetVector(hwiNum, handler, arg);
#else
OsSetVector(hwiNum, handler);
#endif
NVIC_EnableIRQ((IRQn_Type)hwiNum);
NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
LOS_IntRestore(intSave);
return LOS_OK;
}
/* ****************************************************************************
Function : LOS_HwiDelete
Description : Delete hardware interrupt
Input : hwiNum --- hwi num to delete
Output : None
Return : LOS_OK on success or error code on failure
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum)
{
UINT32 intSave;
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
NVIC_DisableIRQ((IRQn_Type)hwiNum);
intSave = LOS_IntLock();
g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)OsHwiDefaultHandler;
LOS_IntRestore(intSave);
return LOS_OK;
}
#define OS_NVIC_INT_CTRL_SIZE 4
#define OS_NVIC_SHCSR_SIZE 4
#define FAULT_STATUS_REG_BIT 32
#define USGFAULT (1 << 18)
#define BUSFAULT (1 << 17)
#define MEMFAULT (1 << 16)
#define DIV0FAULT (1 << 4)
#define HARDFAULT_IRQN (-13)
static ExcInfoArray g_excArray[OS_EXC_TYPE_MAX];
UINT32 g_curNestCount = 0;
static ExcInfo g_excInfo;
static EVENT_CB_S g_excEvent;
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, OS_EXC_UF_NOCP, OS_EXC_UF_INVPC, OS_EXC_UF_INVSTATE, OS_EXC_UF_UNDEFINSTR,
0, 0, 0, OS_EXC_BF_STKERR, OS_EXC_BF_UNSTKERR, OS_EXC_BF_IMPRECISERR, OS_EXC_BF_PRECISERR, OS_EXC_BF_IBUSERR,
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, ...)
{
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 len = 0,i,j;
#define OS_NR_NVIC_EXC_DUMP_Types 7
UINT32 rgNvicBases[OS_NR_NVIC_EXC_DUMP_Types] = {OS_NVIC_SETENA_BASE, OS_NVIC_SETPEND_BASE,
OS_NVIC_INT_ACT_BASE, OS_NVIC_PRI_BASE, OS_NVIC_EXCPRI_BASE, OS_NVIC_SHCSR, OS_NVIC_INT_CTRL};
UINT32 rgNvicLens[OS_NR_NVIC_EXC_DUMP_Types] = {OS_NVIC_INT_ENABLE_SIZE, OS_NVIC_INT_PEND_SIZE,
OS_NVIC_INT_ACT_SIZE, OS_NVIC_INT_PRI_SIZE, OS_NVIC_EXCPRI_SIZE, OS_NVIC_SHCSR_SIZE, OS_NVIC_INT_CTRL_SIZE};
char strRgEnable[] = "enable";
char strRgPending[] = "pending";
char strRgActive[] = "active";
char strRgPriority[] = "priority";
char strRgException[] = "exception";
char strRgShcsr[] = "shcsr";
char strRgIntCtrl[] = "control";
char *strRgs[] = {strRgEnable, strRgPending, strRgActive, strRgPriority, strRgException, strRgShcsr, strRgIntCtrl};
(VOID)index;
(VOID)excContent;
PRINTK("OS exception NVIC dump: \n");
for (i = 0; i < OS_NR_NVIC_EXC_DUMP_Types; i++) {
base = (UINT32 *)rgNvicBases[i];
len = rgNvicLens[i];
PRINTK("interrupt %s register, base address: 0x%x, size: 0x%x\n", strRgs[i], base, len);
len = (len >> 2);
for (j = 0; j < len; j++) {
PRINTK("0x%x ", *(base + j));
}
PRINTK("\n");
}
}
UINT32 OsExcContextDump(UINT32 index, UINT32 *excContent)
{
(VOID)index;
(VOID)excContent;
PRINTK("OS exception context dump:\n");
PRINTK("Phase = 0x%x\n", g_excInfo.phase);
PRINTK("Type = 0x%x\n", g_excInfo.type);
PRINTK("FaultAddr = 0x%x\n", g_excInfo.faultAddr);
PRINTK("ThrdPid = 0x%x\n", g_excInfo.thrdPid);
PRINTK("R0 = 0x%x\n", g_excInfo.context->uwR0);
PRINTK("R1 = 0x%x\n", g_excInfo.context->uwR1);
PRINTK("R2 = 0x%x\n", g_excInfo.context->uwR2);
PRINTK("R3 = 0x%x\n", g_excInfo.context->uwR3);
PRINTK("R4 = 0x%x\n", g_excInfo.context->uwR4);
PRINTK("R5 = 0x%x\n", g_excInfo.context->uwR5);
PRINTK("R6 = 0x%x\n", g_excInfo.context->uwR6);
PRINTK("R7 = 0x%x\n", g_excInfo.context->uwR7);
PRINTK("R8 = 0x%x\n", g_excInfo.context->uwR8);
PRINTK("R9 = 0x%x\n", g_excInfo.context->uwR9);
PRINTK("R10 = 0x%x\n", g_excInfo.context->uwR10);
PRINTK("R11 = 0x%x\n", g_excInfo.context->uwR11);
PRINTK("R12 = 0x%x\n", g_excInfo.context->uwR12);
PRINTK("PriMask = 0x%x\n", g_excInfo.context->uwPriMask);
PRINTK("SP = 0x%x\n", g_excInfo.context->uwSP);
PRINTK("LR = 0x%x\n", g_excInfo.context->uwLR);
PRINTK("PC = 0x%x\n", g_excInfo.context->uwPC);
PRINTK("xPSR = 0x%x\n", g_excInfo.context->uwxPSR);
}
VOID OsDumpMsg(VOID)
{
UINT32 index = 0;
for (index = 0; index < (OS_EXC_TYPE_MAX - 1); index++) {
if (g_excArray[index].uwValid == FALSE) {
continue;
}
g_excArray[index].pFnExcInfoCb(index, g_excArray[index].pArg);
}
}
VOID OsExcNotify(VOID)
{
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;
g_curNestCount++;
g_vuwIntCount++;
g_excInfo.nestCnt = g_curNestCount;
g_excInfo.type = excType & OS_NULL_SHORT;
if (tmpFlag & OS_EXC_FLAG_FAULTADDR_VALID) {
g_excInfo.faultAddr = faultAddr;
} else {
g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR;
}
if (g_losTask.runTask != NULL) {
if (tmpFlag & OS_EXC_FLAG_IN_HWI) {
g_excInfo.phase = OS_EXC_IN_HWI;
g_excInfo.thrdPid = pid;
} else {
g_excInfo.phase = OS_EXC_IN_TASK;
g_excInfo.thrdPid = g_losTask.runTask->taskID;
}
} else {
g_excInfo.phase = OS_EXC_IN_INIT;
g_excInfo.thrdPid = OS_NULL_INT;
}
if (excType & OS_EXC_FLAG_NO_FLOAT) {
g_excInfo.context = (EXC_CONTEXT_S *)((CHAR *)excBufAddr - LOS_OFF_SET_OF(EXC_CONTEXT_S, uwR4));
} else {
g_excInfo.context = excBufAddr;
}
OsDumpMsg();
OsExcNotify();
LOS_Reboot();
}
VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg)
{
ExcInfoArray *excInfo = NULL;
if ((type >= OS_EXC_TYPE_MAX) || (func == NULL)) {
PRINT_ERR("OsExcRegister ERROR!\n");
return;
}
excInfo = &(g_excArray[type]);
excInfo->uwType = type;
excInfo->pFnExcInfoCb = func;
excInfo->pArg = arg;
excInfo->uwValid = TRUE;
}
void OsBackTrace()
{
}
/* ****************************************************************************
Function : OsHwiInit
Description : initialization of the hardware interrupt
Input : None
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID OsHwiInit()
{
UINT32 index;
UINT32 ret;
for (index = OS_SYS_VECTOR_CNT; index < OS_VECTOR_CNT; index++) {
g_hwiForm[index] = (HWI_PROC_FUNC)OsHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = OsExcHardFault;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = OsExcNMI;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = OsExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = OsExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = OsExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = OsExcSvcCall;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;
#if (__CORTEX_M >= 0x03U) /* only for Cortex-M3 and above */
NVIC_SetPriorityGrouping(OS_NVIC_AIRCR_PRIGROUP);
#endif
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
/* Enable DIV 0 and unaligned exception */
*(volatile UINT32 *)OS_NVIC_CCR |= DIV0FAULT;
/* Init Exception Event */
ret = LOS_EventInit(&g_excEvent);
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;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@ -29,22 +29,17 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @defgroup los_hwi Hardware interrupt
* @ingroup kernel
*/
#ifndef _LOS_HWI_H
#define _LOS_HWI_H
#ifndef _LOS_EXC_H
#define _LOS_EXC_H
#include "los_base.h"
#include "los_sys.h"
#include "los_config.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* __cpluscplus */
#endif /* __cpluscplus */
/* *
* @ingroup los_hwi
@ -681,11 +676,10 @@ extern VOID LOS_SysTickReload(UINT32 cyclesPerTick);
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see LOS_IntRestore
*/
extern VOID LOS_GetCpuCycle(UINT32 *puwCntHi, UINT32 *puwCntLo);
extern VOID LOS_GetSystickCycle(UINT32 *puwCntHi, UINT32 *puwCntLo);
extern UINT32 LOS_SysTickCurrCycleGet(VOID);
extern VOID LOS_GetSystickCycle(UINT32 *puwCntHi, UINT32 *puwCntLo);
/* *
* @ingroup los_hwi
* @brief Delete hardware interrupt.
@ -728,12 +722,364 @@ VOID LOS_EnterSleep(LOS_SysSleepEnum sleep);
VOID LOS_SystemWakeup(UINT32 hwiIndex);
#define OS_EXC_IN_INIT 0
#define OS_EXC_IN_TASK 1
#define OS_EXC_IN_HWI 2
#define OS_EXC_MAX_BUF_LEN 25
#define OS_EXC_MAX_NEST_DEPTH 1
#define OS_NVIC_SHCSR 0xE000ED24
#define OS_NVIC_CCR 0xE000ED14
#define OS_NVIC_INT_ENABLE_SIZE 0x20
#define OS_NVIC_INT_PRI_SIZE 0xF0
#define OS_NVIC_EXCPRI_SIZE 0xC
#define OS_NVIC_INT_PEND_SIZE OS_NVIC_INT_ACT_SIZE
#define OS_NVIC_INT_ACT_SIZE OS_NVIC_INT_ENABLE_SIZE
#define OS_EXC_FLAG_NO_FLOAT 0x10000000
#define OS_EXC_FLAG_FAULTADDR_VALID 0x01
#define OS_EXC_FLAG_IN_HWI 0x02
#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB
#define OS_EXC_EVENT 0x00000001
/**
*@ingroup los_exc
* the struct of register files
*
* description: the register files that saved when exception triggered
*
* notes:the following register with prefix 'uw' correspond to the registers in the cpu data sheet.
*/
typedef struct tagExcContext {
//handler save
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
UINT32 S16;
UINT32 S17;
UINT32 S18;
UINT32 S19;
UINT32 S20;
UINT32 S21;
UINT32 S22;
UINT32 S23;
UINT32 S24;
UINT32 S25;
UINT32 S26;
UINT32 S27;
UINT32 S28;
UINT32 S29;
UINT32 S30;
UINT32 S31;
#endif
UINT32 uwR4;
UINT32 uwR5;
UINT32 uwR6;
UINT32 uwR7;
UINT32 uwR8;
UINT32 uwR9;
UINT32 uwR10;
UINT32 uwR11;
UINT32 uwPriMask;
//auto save
UINT32 uwSP;
UINT32 uwR0;
UINT32 uwR1;
UINT32 uwR2;
UINT32 uwR3;
UINT32 uwR12;
UINT32 uwLR;
UINT32 uwPC;
UINT32 uwxPSR;
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED) && (__FPU_USED== 1U)))
UINT32 S0;
UINT32 S1;
UINT32 S2;
UINT32 S3;
UINT32 S4;
UINT32 S5;
UINT32 S6;
UINT32 S7;
UINT32 S8;
UINT32 S9;
UINT32 S10;
UINT32 S11;
UINT32 S12;
UINT32 S13;
UINT32 S14;
UINT32 S15;
UINT32 FPSCR;
UINT32 NO_NAME;
#endif
}EXC_CONTEXT_S;
typedef UINT32 (*EXC_INFO_SAVE_CALLBACK)(UINT32, VOID*);
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
/**
* @ingroup los_hwi
* @brief: Exception initialization.
*
* @par Description:
* This API is used to configure the exception function vector table.
*
* @attention:
* <ul><li>None.</li></ul>
*
*@param uwArraySize [IN] Memory size of exception.
*
* @retval: None
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
VOID OsExcInit(VOID);
extern VOID OsExcNMI(VOID);
extern VOID OsExcHardFault(VOID);
extern VOID OsExcMemFault(VOID);
extern VOID OsExcBusFault(VOID);
extern VOID OsExcUsageFault(VOID);
extern VOID OsExcSvcCall(VOID);
extern UINT8 g_aucTaskArray[];
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
*Cortex-M3异常具体类型:线
*/
#define OS_EXC_BF_STKERR 1
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:线
*/
#define OS_EXC_BF_UNSTKERR 2
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:线访
*/
#define OS_EXC_BF_IMPRECISERR 3
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:线访
*/
#define OS_EXC_BF_PRECISERR 4
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:线访
*/
#define OS_EXC_BF_IBUSERR 5
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:
*/
#define OS_EXC_MF_MSTKERR 6
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:
*/
#define OS_EXC_MF_MUNSTKERR 7
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:访
*/
#define OS_EXC_MF_DACCVIOL 8
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:访
*/
#define OS_EXC_MF_IACCVIOL 9
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:
*/
#define OS_EXC_UF_DIVBYZERO 10
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:访
*/
#define OS_EXC_UF_UNALIGNED 11
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:
*/
#define OS_EXC_UF_NOCP 12
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:EXC_RETURN到PC
*/
#define OS_EXC_UF_INVPC 13
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:ARM状态
*/
#define OS_EXC_UF_INVSTATE 14
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:
*/
#define OS_EXC_UF_UNDEFINSTR 15
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:NMI中断
*/
#define OS_EXC_CAUSE_NMI 16
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:fault
*/
#define OS_EXC_CAUSE_HARDFAULT 17
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:退
*/
#define OS_EXC_CAUSE_TASK_EXIT 18
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:
*/
#define OS_EXC_CAUSE_FATAL_ERR 19
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:fault
*/
#define OS_EXC_CAUSE_DEBUGEVT 20
/**
*@ingroup los_exc
*Cortex-M3异常具体类型:fault
*/
#define OS_EXC_CAUSE_VECTBL 21
/**
*@ingroup los_exc
*
*
* :M4平台下的异常触发时保存的异常信息
*
*/
typedef struct tagExcInfo {
/**< 异常发生阶段: 0表示异常发生在初始化中1表示异常发生在任务中2表示异常发生在中断中 */
UINT16 phase;
/**< 异常类型,出异常时对照上面列出的1-19号 */
UINT16 type;
/**< 若为精确地址访问错误表示异常发生时的错误访问地址 */
UINT32 faultAddr;
/**< 在中断中发生异常表示中断号。在任务中发生异常表示任务id如果发生在初始化中则为0xffffffff */
UINT32 thrdPid;
/**< 异常嵌套个数,目前仅支持第一次进入异常时执行注册的钩子函数 */
UINT16 nestCnt;
/**< 保留 */
UINT16 reserved;
/**< 自动压栈浮点寄存器的异常发生时刻的硬件上下文 */
EXC_CONTEXT_S * context;
} ExcInfo;
extern UINT32 g_curNestCount;
extern UINT32 g_vuwIntCount;
static VOID OsExcSave2DDR(VOID);
VOID OsExcInfoDisplay(ExcInfo *exc);
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 {
ExcInfoType uwType;
UINT32 uwValid;
EXC_INFO_SAVE_CALLBACK pFnExcInfoCb;
VOID* pArg;
} ExcInfoArray;
#define MAX_SCENE_INFO_SIZE (8 + sizeof(ExcInfo) - 4 + sizeof(EXC_CONTEXT_S))
#define MAX_TSK_INFO_SIZE (8 + sizeof(TSK_INFO_S) * (LOSCFG_BASE_CORE_TSK_LIMIT + 1))
#define MAX_INT_INFO_SIZE (8 + 0x164)
#if (LOSCFG_BASE_IPC_QUEUE == YES)
#define MAX_QUEUE_INFO_SIZE (8 + sizeof(QUEUE_INFO_S) * LOSCFG_BASE_IPC_QUEUE_LIMIT)
#else
#define MAX_QUEUE_INFO_SIZE (0)
#endif
#if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == YES)
#define MAX_SWITCH_INFO_SIZE (8 + (sizeof(UINT32) + sizeof(CHAR) * LOS_TASK_NAMELEN) * OS_TASK_SWITCH_INFO_COUNT)
#else
#define MAX_SWITCH_INFO_SIZE (0)
#endif
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == YES)
#define MAX_MEM_INFO_SIZE (8 + sizeof(MEM_INFO_S) * OS_SYS_MEM_NUM)
#else
#define MAX_MEM_INFO_SIZE (0)
#endif
#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
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#endif /* _LOS_HWI_H */
#endif /* _LOS_EXC_H */

View File

@ -0,0 +1,54 @@
;/*----------------------------------------------------------------------------
;* Huawei - LiteOS
;*----------------------------------------------------------------------------
;* Name: LOS_VENDOR.S
;* Purpose: Thread scheduler
;* Rev.: V1.0.0
;*----------------------------------------------------------------------------
;*
;* Copyright (c) 2014, Huawei Technologies Co., Ltd.
;* All rights reserved.
;* Permission to use, copy, modify, and distribute this software for any
;* purpose with or without fee is hereby granted, provided that the above
;* copyright notice and this permission notice appear in all copies.
;*THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
;*WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
;*MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
;*ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
;*WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
;*ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
;*OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
;*---------------------------------------------------------------------------*/
PRESERVE8
AREA RESET, CODE, READONLY
THUMB
IMPORT ||Image$$ARM_LIB_STACKHEAP$$ZI$$Limit||
IMPORT OsHwiDefaultHandler
EXPORT _BootVectors
EXPORT Reset_Handler
_BootVectors
DCD ||Image$$ARM_LIB_STACKHEAP$$ZI$$Limit||
DCD Reset_Handler
DCD OsHwiDefaultHandler
DCD OsHwiDefaultHandler
Reset_Handler
CPSID I
IMPORT LOS_HardBootInit
BL LOS_HardBootInit
IMPORT __main
LDR R0, =__main
BX R0
ALIGN
END

View File

@ -0,0 +1,194 @@
/*
* 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.
*/
/**
* @defgroup los_hw hardware
* @ingroup kernel
*/
#ifndef _LOS_HW_H
#define _LOS_HW_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* *
* @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 {
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U)))
UINT32 S16;
UINT32 S17;
UINT32 S18;
UINT32 S19;
UINT32 S20;
UINT32 S21;
UINT32 S22;
UINT32 S23;
UINT32 S24;
UINT32 S25;
UINT32 S26;
UINT32 S27;
UINT32 S28;
UINT32 S29;
UINT32 S30;
UINT32 S31;
#endif
UINT32 uwR4;
UINT32 uwR5;
UINT32 uwR6;
UINT32 uwR7;
UINT32 uwR8;
UINT32 uwR9;
UINT32 uwR10;
UINT32 uwR11;
UINT32 uwPriMask;
UINT32 uwR0;
UINT32 uwR1;
UINT32 uwR2;
UINT32 uwR3;
UINT32 uwR12;
UINT32 uwLR;
UINT32 uwPC;
UINT32 uwxPSR;
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined(__FPU_USED) && (__FPU_USED == 1U)))
UINT32 S0;
UINT32 S1;
UINT32 S2;
UINT32 S3;
UINT32 S4;
UINT32 S5;
UINT32 S6;
UINT32 S7;
UINT32 S8;
UINT32 S9;
UINT32 S10;
UINT32 S11;
UINT32 S12;
UINT32 S13;
UINT32 S14;
UINT32 S15;
UINT32 FPSCR;
UINT32 NO_NAME;
#endif
} TaskContext;
/* *
* @ingroup los_hw
* @brief: Task stack initialization.
*
* @par Description:
* This API is used to initialize the task stack.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param taskID [IN] Type#UINT32: TaskID.
* @param stackSize [IN] Type#UINT32: Total size of the stack.
* @param topStack [IN] Type#VOID *: Top of task's stack.
*
* @retval: context Type#TaskContext *.
* @par Dependency:
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack);
/**
* @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
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_HW_H */

View File

@ -1,363 +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 <stdio.h>
#include "los_exc_pri.h"
#include "los_memcheck_pri.h"
#ifdef LOSCFG_LIB_LIBC
#include "string.h"
#endif
#include "securec.h"
#include "los_printf.h"
#include "los_config.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define EXC_INT_STATUS_LEN OS_NVIC_INT_ENABLE_SIZE + OS_NVIC_INT_PEND_SIZE + OS_NVIC_INT_ACT_SIZE + \
OS_NVIC_INT_PRI_SIZE + OS_NVIC_EXCPRI_SIZE + OS_NVIC_SHCSR_SIZE + OS_NVIC_INT_CTRL_SIZE
#define TASK_ARRAY_INIT_VALUE 0xff
#define FAULT_STATUS_REG_BIT 32
#define OS_NVIC_INT_CTRL_SIZE 4
#define OS_NVIC_SHCSR_SIZE 4
#define USGFAULT (1 << 18)
#define BUSFAULT (1 << 17)
#define MEMFAULT (1 << 16)
#define DIV0FAULT (1 << 4)
#define CORE_TYPE_CORTEX_M4 2
#define HARDFAULT_IRQN (-13)
static VOID *g_excContent;
UINT32 g_curNestCount = 0;
ExcInfo g_excInfo;
__attribute__((noinline)) VOID LOS_Panic(const CHAR *fmt, ...)
{
va_list ap;
va_start(ap,fmt);
PRINT_ERR(fmt, ap);
va_end(ap);
asm volatile ("swi 0");
}
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, OS_EXC_UF_NOCP, OS_EXC_UF_INVPC, OS_EXC_UF_INVSTATE, OS_EXC_UF_UNDEFINSTR,
0, 0, 0, OS_EXC_BF_STKERR, OS_EXC_BF_UNSTKERR, OS_EXC_BF_IMPRECISERR, OS_EXC_BF_PRECISERR, OS_EXC_BF_IBUSERR,
0, 0, 0, OS_EXC_MF_MSTKERR, OS_EXC_MF_MUNSTKERR, 0, OS_EXC_MF_DACCVIOL, OS_EXC_MF_IACCVIOL
};
UINT32 g_excArraySize = 0;
ExcInfoArray g_excArray[OS_EXC_TYPE_MAX - 1];
UINT32 g_LR_regs = 0;
UINT32 g_PC_regs = 0;
LITE_OS_SEC_TEXT_INIT VOID OsExcInfoDisplay(ExcInfo *exc)
{
PRINT_INFO("Phase = 0x%x\n", exc->phase);
PRINT_INFO("Type = 0x%x\n", exc->type);
PRINT_INFO("FaultAddr = 0x%x\n", exc->faultAddr);
PRINT_INFO("ThrdPid = 0x%x\n", exc->thrdPid);
PRINT_INFO("R0 = 0x%x\n", exc->context->uwR0);
PRINT_INFO("R1 = 0x%x\n", exc->context->uwR1);
PRINT_INFO("R2 = 0x%x\n", exc->context->uwR2);
PRINT_INFO("R3 = 0x%x\n", exc->context->uwR3);
PRINT_INFO("R4 = 0x%x\n", exc->context->uwR4);
PRINT_INFO("R5 = 0x%x\n", exc->context->uwR5);
PRINT_INFO("R6 = 0x%x\n", exc->context->uwR6);
PRINT_INFO("R7 = 0x%x\n", exc->context->uwR7);
PRINT_INFO("R8 = 0x%x\n", exc->context->uwR8);
PRINT_INFO("R9 = 0x%x\n", exc->context->uwR9);
PRINT_INFO("R10 = 0x%x\n", exc->context->uwR10);
PRINT_INFO("R11 = 0x%x\n", exc->context->uwR11);
PRINT_INFO("R12 = 0x%x\n", exc->context->uwR12);
PRINT_INFO("PriMask = 0x%x\n", exc->context->uwPriMask);
PRINT_INFO("SP = 0x%x\n", exc->context->uwSP);
PRINT_INFO("LR = 0x%x\n", exc->context->uwLR);
PRINT_INFO("PC = 0x%x\n", exc->context->uwPC);
PRINT_INFO("xPSR = 0x%x\n", exc->context->uwxPSR);
g_LR_regs = exc->context->uwLR;
g_PC_regs = exc->context->uwPC;
}
LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid,
EXC_CONTEXT_S *excBufAddr)
{
UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT;
g_curNestCount++;
g_vuwIntCount++;
g_excInfo.nestCnt = g_curNestCount;
g_excInfo.type = excType & OS_NULL_SHORT;
g_excContent = (UINT32 *)g_aucTaskArray;
if (tmpFlag & OS_EXC_FLAG_FAULTADDR_VALID) {
g_excInfo.faultAddr = faultAddr;
} else {
g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR;
}
if (g_losTask.runTask != NULL) {
if (tmpFlag & OS_EXC_FLAG_IN_HWI) {
g_excInfo.phase = OS_EXC_IN_HWI;
g_excInfo.thrdPid = pid;
} else {
g_excInfo.phase = OS_EXC_IN_TASK;
g_excInfo.thrdPid = g_losTask.runTask->taskID;
}
} else {
g_excInfo.phase = OS_EXC_IN_INIT;
g_excInfo.thrdPid = OS_NULL_INT;
}
if (excType & OS_EXC_FLAG_NO_FLOAT) {
g_excInfo.context = (EXC_CONTEXT_S *)((CHAR *)excBufAddr - LOS_OFF_SET_OF(EXC_CONTEXT_S, uwR4));
} else {
g_excInfo.context = excBufAddr;
}
OsExcSave2DDR();
OsExcInfoDisplay(&g_excInfo);
LOS_Reboot();
}
static VOID OsExcSaveIntStatus()
{
UINT32 ret;
UINT32 failCnt = 0;
*((UINT32 *)g_excContent) = OS_EXC_TYPE_NVIC;
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
*((UINT32 *)g_excContent) = EXC_INT_STATUS_LEN;
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_SETENA_BASE, OS_NVIC_INT_ENABLE_SIZE);
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_ENABLE_SIZE;
failCnt += (ret == EOK) ? 0 : 1;
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_SETPEND_BASE, OS_NVIC_INT_PEND_SIZE);
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_PEND_SIZE;
failCnt += (ret == EOK) ? 0 : 1;
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_INT_ACT_BASE, OS_NVIC_INT_ACT_SIZE);
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_ACT_SIZE;
failCnt += (ret == EOK) ? 0 : 1;
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_PRI_BASE, OS_NVIC_INT_PRI_SIZE);
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_PRI_SIZE;
failCnt += (ret == EOK) ? 0 : 1;
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_EXCPRI_BASE, OS_NVIC_EXCPRI_SIZE);
g_excContent = (UINT8 *)g_excContent + OS_NVIC_EXCPRI_SIZE;
failCnt += (ret == EOK) ? 0 : 1;
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_SHCSR, OS_NVIC_SHCSR_SIZE);
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
failCnt += (ret == EOK) ? 0 : 1;
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_INT_CTRL, OS_NVIC_INT_CTRL_SIZE);
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
failCnt += (ret == EOK) ? 0 : 1;
if (failCnt != 0) {
PRINT_ERR("OsExcSaveIntStatus copy register info failed, cnt:%d\n", failCnt);
}
return;
}
VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg)
{
ExcInfoArray *excInfo = NULL;
if ((type == 0) || (type >= OS_EXC_TYPE_MAX) || (func == NULL)) {
PRINT_ERR("OsExcRegister ERROR!\n");
return;
}
excInfo = &(g_excArray[type - 1]);
excInfo->uwType = type;
excInfo->pFnExcInfoCb = func;
excInfo->pArg = arg;
excInfo->uwValid = TRUE;
}
static VOID OsExcSaveSysInfo(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, UINT32 loop, UINT32 length, UINT32 index)
{
UINT32 ret;
UINT32 buffer[OS_EXC_MAX_BUF_LEN];
*((UINT32 *)g_excContent) = type;
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
*((UINT32 *)g_excContent) = length * (loop - index);
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
for (; index < loop; index++) {
(VOID)memset_s(buffer, sizeof(UINT32) * OS_EXC_MAX_BUF_LEN, 0, sizeof(UINT32) * OS_EXC_MAX_BUF_LEN);
ret = func(index, (VOID *)buffer);
if (ret == LOS_OK) {
if (memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (VOID *)buffer, length) != EOK) {
PRINT_ERR("OsExcSaveSysInfo copy buffer failed\n");
return;
}
g_excContent = (UINT8 *)g_excContent + length;
} else {
g_excContent = (UINT8 *)g_excContent + length;
}
}
}
static VOID OsExcSaveInfo(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg)
{
UINT32 length;
UINT32 index;
UINT32 loop;
UINT32 taskSwitchCount = 0;
TaskSwitchInfo *taskSwitchInfo = NULL;
if (arg == NULL) {
return;
}
switch (type) {
case OS_EXC_TYPE_TSK: /* save task info */
length = sizeof(TSK_INFO_S);
loop = *(UINT32 *)arg;
index = 0;
break;
case OS_EXC_TYPE_QUE: /* save queue info */
length = sizeof(QUEUE_INFO_S);
loop = *(UINT32 *)arg + 1;
index = 1;
break;
case OS_EXC_TYPE_NVIC:
(VOID)func(0, 0);
goto END;
case OS_EXC_TYPE_TSK_SWITCH: /* save task switch info */
// not necessary, just for macro int library
taskSwitchInfo = arg;
taskSwitchCount = taskSwitchInfo->cntInfo.maxCnt;
length = sizeof(UINT32) + sizeof(CHAR) * LOS_TASK_NAMELEN;
if (taskSwitchInfo->cntInfo.isFull) {
index = taskSwitchInfo->idx;
loop = index + taskSwitchCount;
} else {
index = 0;
loop = taskSwitchInfo->idx;
}
break;
case OS_EXC_TYPE_MEM: /* save mem info */
length = sizeof(MEM_INFO_S);
loop = *(UINT32 *)arg;
index = 0;
break;
default:
goto END;
}
OsExcSaveSysInfo(type, (EXC_INFO_SAVE_CALLBACK)func, loop, length, index);
END:
return;
}
static VOID OsExcSave2DDR(VOID)
{
UINT32 index = 0;
UINT32 ret;
UINT32 failCnt = 0;
ret = memset_s(g_aucTaskArray, MAX_EXC_MEM_SIZE, TASK_ARRAY_INIT_VALUE, g_excArraySize);
if (ret != EOK) {
PRINT_ERR("memset failed\n");
return;
}
/* define core type */
*((UINT32 *)g_excContent) = CORE_TYPE_CORTEX_M4; // 1 is cortex-M3, 2 is cortex-M4
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
/* save exception info */
*((UINT32 *)g_excContent) = OS_EXC_TYPE_CONTEXT;
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
*((UINT32 *)g_excContent) = sizeof(ExcInfo) - sizeof(UINT32) + sizeof(EXC_CONTEXT_S);
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
ret = memcpy_s((VOID *)g_excContent, MAX_EXC_MEM_SIZE, (VOID *)&g_excInfo, sizeof(ExcInfo) - sizeof(UINT32));
g_excContent = (UINT8 *)g_excContent + sizeof(ExcInfo) - sizeof(UINT32);
failCnt += (ret == EOK) ? 0 : 1;
ret = memcpy_s((VOID *)g_excContent, MAX_EXC_MEM_SIZE, g_excInfo.context, sizeof(EXC_CONTEXT_S));
g_excContent = (UINT8 *)g_excContent + sizeof(EXC_CONTEXT_S);
failCnt += (ret == EOK) ? 0 : 1;
if (failCnt != 0) {
PRINT_ERR("OsExcSave2DDR copy exc info failed, cnt:%d\n", failCnt);
}
for (index = 0; index < (OS_EXC_TYPE_MAX - 1); index++) {
if (g_excArray[index].uwValid == FALSE) {
continue;
}
OsExcSaveInfo(g_excArray[index].uwType, g_excArray[index].pFnExcInfoCb, g_excArray[index].pArg);
}
*((UINT32 *)g_excContent) = OS_EXC_TYPE_MAX;
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
return;
}
LITE_OS_SEC_TEXT_INIT VOID OsExcInit(UINT32 arraySize)
{
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = OsExcHardFault;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = OsExcNMI;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = OsExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = OsExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = OsExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = OsExcSvcCall;
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
/* Enable DIV 0 and unaligned exception */
*(volatile UINT32 *)OS_NVIC_CCR |= DIV0FAULT;
g_excArraySize = arraySize;
OsExcRegister(OS_EXC_TYPE_NVIC, (EXC_INFO_SAVE_CALLBACK)OsExcSaveIntStatus, NULL);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@ -1,265 +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.
*/
#ifndef _LOS_EXC_H
#define _LOS_EXC_H
#include "los_sys.h"
#include "los_config.h"
#include "los_base.h"
#include "los_task_pri.h"
#include "los_queue.h"
#include "los_memcheck.h"
#include "los_sys_pri.h"
#ifdef LOSCFG_LIB_LIBC
#include "string.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#define OS_EXC_IN_INIT 0
#define OS_EXC_IN_TASK 1
#define OS_EXC_IN_HWI 2
#define OS_EXC_MAX_BUF_LEN 25
#define OS_EXC_MAX_NEST_DEPTH 1
#define OS_NVIC_SHCSR 0xE000ED24
#define OS_NVIC_CCR 0xE000ED14
#define OS_NVIC_INT_ENABLE_SIZE 0x20
#define OS_NVIC_INT_PRI_SIZE 0xF0
#define OS_NVIC_EXCPRI_SIZE 0xC
#define OS_NVIC_INT_PEND_SIZE OS_NVIC_INT_ACT_SIZE
#define OS_NVIC_INT_ACT_SIZE OS_NVIC_INT_ENABLE_SIZE
#define OS_EXC_FLAG_NO_FLOAT 0x10000000
#define OS_EXC_FLAG_FAULTADDR_VALID 0x01
#define OS_EXC_FLAG_IN_HWI 0x02
#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB
/**
*@ingroup los_exc
* the struct of register files
*
* description: the register files that saved when exception triggered
*
* notes:the following register with prefix 'uw' correspond to the registers in the cpu data sheet.
*/
typedef struct tagExcContext {
//handler save
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
UINT32 S16;
UINT32 S17;
UINT32 S18;
UINT32 S19;
UINT32 S20;
UINT32 S21;
UINT32 S22;
UINT32 S23;
UINT32 S24;
UINT32 S25;
UINT32 S26;
UINT32 S27;
UINT32 S28;
UINT32 S29;
UINT32 S30;
UINT32 S31;
#endif
UINT32 uwR4;
UINT32 uwR5;
UINT32 uwR6;
UINT32 uwR7;
UINT32 uwR8;
UINT32 uwR9;
UINT32 uwR10;
UINT32 uwR11;
UINT32 uwPriMask;
//auto save
UINT32 uwSP;
UINT32 uwR0;
UINT32 uwR1;
UINT32 uwR2;
UINT32 uwR3;
UINT32 uwR12;
UINT32 uwLR;
UINT32 uwPC;
UINT32 uwxPSR;
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED) && (__FPU_USED== 1U)))
UINT32 S0;
UINT32 S1;
UINT32 S2;
UINT32 S3;
UINT32 S4;
UINT32 S5;
UINT32 S6;
UINT32 S7;
UINT32 S8;
UINT32 S9;
UINT32 S10;
UINT32 S11;
UINT32 S12;
UINT32 S13;
UINT32 S14;
UINT32 S15;
UINT32 FPSCR;
UINT32 NO_NAME;
#endif
}EXC_CONTEXT_S;
typedef UINT32 (*EXC_INFO_SAVE_CALLBACK)(UINT32, VOID*);
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
/**
* @ingroup los_hwi
* @brief: Exception initialization.
*
* @par Description:
* This API is used to configure the exception function vector table.
*
* @attention:
* <ul><li>None.</li></ul>
*
*@param uwArraySize [IN] Memory size of exception.
*
* @retval: None
* @par Dependency:
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
VOID OsExcInit(UINT32 uwArraySize);
extern VOID OsExcNMI(VOID);
extern VOID OsExcHardFault(VOID);
extern VOID OsExcMemFault(VOID);
extern VOID OsExcBusFault(VOID);
extern VOID OsExcUsageFault(VOID);
extern VOID OsExcSvcCall(VOID);
extern UINT8 g_aucTaskArray[];
inline 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_exc.h: the header file that contains the API declaration.
*@see None.
*/
VOID LOS_Panic(const CHAR *fmt, ...);
#define OS_EXC_BF_STKERR 1
#define OS_EXC_BF_UNSTKERR 2
#define OS_EXC_BF_IMPRECISERR 3
#define OS_EXC_BF_PRECISERR 4
#define OS_EXC_BF_IBUSERR 5
#define OS_EXC_MF_MSTKERR 6
#define OS_EXC_MF_MUNSTKERR 7
#define OS_EXC_MF_DACCVIOL 8
#define OS_EXC_MF_IACCVIOL 9
#define OS_EXC_UF_DIVBYZERO 10
#define OS_EXC_UF_UNALIGNED 11
#define OS_EXC_UF_NOCP 12
#define OS_EXC_UF_INVPC 13
#define OS_EXC_UF_INVSTATE 14
#define OS_EXC_UF_UNDEFINSTR 15
#define OS_EXC_CAUSE_NMI 16
#define OS_EXC_CAUSE_HARDFAULT 17
#define OS_EXC_CAUSE_TASK_EXIT 18
#define OS_EXC_CAUSE_FATAL_ERR 19
#define OS_EXC_CAUSE_DEBUGEVT 20
#define OS_EXC_CAUSE_VECTBL 21
typedef struct tagExcInfo {
UINT16 phase;
UINT16 type;
UINT32 faultAddr;
UINT32 thrdPid;
UINT16 nestCnt;
UINT16 reserved;
EXC_CONTEXT_S * context;
} ExcInfo;
extern UINT32 g_curNestCount;
extern UINT32 g_vuwIntCount;
static VOID OsExcSave2DDR(VOID);
VOID OsExcInfoDisplay(ExcInfo *exc);
extern TaskSwitchInfo g_taskSwitchInfo;
extern UINT8 g_uwExcTbl[32];
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#endif /* _LOS_EXC_H */

View File

@ -1,98 +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.
*/
#ifndef _LOS_EXC_PRI_H
#define _LOS_EXC_PRI_H
#include "los_exc.h"
#include "los_sys_pri.h"
#ifdef LOSCFG_LIB_LIBC
#include "string.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
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 {
ExcInfoType uwType;
UINT32 uwValid;
EXC_INFO_SAVE_CALLBACK pFnExcInfoCb;
VOID* pArg;
} ExcInfoArray;
#define MAX_SCENE_INFO_SIZE (8 + sizeof(ExcInfo) - 4 + sizeof(EXC_CONTEXT_S))
#define MAX_TSK_INFO_SIZE (8 + sizeof(TSK_INFO_S) * (LOSCFG_BASE_CORE_TSK_LIMIT + 1))
#define MAX_INT_INFO_SIZE (8 + 0x164)
#if (LOSCFG_BASE_IPC_QUEUE == YES)
#define MAX_QUEUE_INFO_SIZE (8 + sizeof(QUEUE_INFO_S) * LOSCFG_BASE_IPC_QUEUE_LIMIT)
#else
#define MAX_QUEUE_INFO_SIZE (0)
#endif
#if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == YES)
#define MAX_SWITCH_INFO_SIZE (8 + (sizeof(UINT32) + sizeof(CHAR) * LOS_TASK_NAMELEN) * OS_TASK_SWITCH_INFO_COUNT)
#else
#define MAX_SWITCH_INFO_SIZE (0)
#endif
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == YES)
#define MAX_MEM_INFO_SIZE (8 + sizeof(MEM_INFO_S) * OS_SYS_MEM_NUM)
#else
#define MAX_MEM_INFO_SIZE (0)
#endif
#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
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@ -29,10 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_task_pri.h"
#include "los_hw.h"
#include "los_task.h"
#include "securec.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {

View File

@ -29,12 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_tick_pri.h"
#include "los_base.h"
#include "los_task_pri.h"
#include "los_swtmr.h"
#include "los_hwi.h"
#include "los_tick.h"
#include "los_interrupt.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
@ -245,11 +241,11 @@ VOID LOS_EnterSleep(LOS_SysSleepEnum sleep)
VOID LOS_SystemWakeup(UINT32 hwiIndex)
{
}
extern unsigned int SystemCoreClock;
//extern unsigned int SystemCoreClock;
void LOS_HalDelay(UINT32 ticks)
{
UINT32 delayTimes;
#if 0
/* there are 4 machine cycle in loop */
if ((ticks * (SystemCoreClock / MACHINE_CYCLE_DEALAY_TIMES)) >= 0xffffffff) {
delayTimes = 0xffffffff;
@ -260,6 +256,7 @@ void LOS_HalDelay(UINT32 ticks)
while (delayTimes) {
delayTimes = delayTimes - 1;
}
#endif
}
#ifdef __cplusplus

View File

@ -28,15 +28,14 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_hwi.h"
#include "los_sr.h"
#include "los_printf.h"
#include "los_interrupt.h"
#include <stdarg.h>
#include "los_debug.h"
#include "los_task.h"
#if (LOSCFG_KERNEL_TICKLESS == YES)
#include "los_tickless_pri.h"
#include "los_tick.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
@ -48,7 +47,6 @@ __weak VOID SysTickHandler(VOID)
{
return;
}
UINT32 g_vuwIntCount = 0;
/*lint -restore*/
#ifdef __ICCARM__
@ -56,7 +54,6 @@ UINT32 g_vuwIntCount = 0;
#elif defined(__CC_ARM) || defined(__GNUC__)
LITE_OS_SEC_VEC
#endif
HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {
(HWI_PROC_FUNC)0, // [0] Top of Stack
(HWI_PROC_FUNC)Reset_Handler, // [1] reset
@ -75,6 +72,9 @@ HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {
(HWI_PROC_FUNC)osPendSV, // [14] PendSV Handler
(HWI_PROC_FUNC)SysTickHandler, // [15] SysTick Handler
};
#if (OS_HWI_WITH_ARG == YES)
HWI_SLAVE_FUNC g_hwiSlaveForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
#else
@ -149,29 +149,6 @@ LITE_OS_SEC_TEXT VOID OsInterrupt(VOID)
LOS_IntRestore(intSave);
}
/* ****************************************************************************
Function : OsHwiInit
Description : initialization of the hardware interrupt
Input : None
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID OsHwiInit()
{
UINT32 index;
for (index = OS_SYS_VECTOR_CNT; index < OS_VECTOR_CNT; index++) {
g_hwiForm[index] = (HWI_PROC_FUNC)OsHwiDefaultHandler;
}
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;
#if (__CORTEX_M >= 0x03U) /* only for Cortex-M3 and above */
NVIC_SetPriorityGrouping(OS_NVIC_AIRCR_PRIGROUP);
#endif
return;
}
/* ****************************************************************************
Function : LOS_HwiCreate
Description : create hardware interrupt
@ -247,10 +224,228 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum)
return LOS_OK;
}
#define OS_NVIC_INT_CTRL_SIZE 4
#define OS_NVIC_SHCSR_SIZE 4
#define FAULT_STATUS_REG_BIT 32
#define USGFAULT (1 << 18)
#define BUSFAULT (1 << 17)
#define MEMFAULT (1 << 16)
#define DIV0FAULT (1 << 4)
#define HARDFAULT_IRQN (-13)
static ExcInfoArray g_excArray[OS_EXC_TYPE_MAX];
UINT32 g_curNestCount = 0;
static ExcInfo g_excInfo;
static EVENT_CB_S g_excEvent;
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, OS_EXC_UF_NOCP, OS_EXC_UF_INVPC, OS_EXC_UF_INVSTATE, OS_EXC_UF_UNDEFINSTR,
0, 0, 0, OS_EXC_BF_STKERR, OS_EXC_BF_UNSTKERR, OS_EXC_BF_IMPRECISERR, OS_EXC_BF_PRECISERR, OS_EXC_BF_IBUSERR,
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, ...)
{
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 len = 0,i,j;
#define OS_NR_NVIC_EXC_DUMP_Types 7
UINT32 rgNvicBases[OS_NR_NVIC_EXC_DUMP_Types] = {OS_NVIC_SETENA_BASE, OS_NVIC_SETPEND_BASE,
OS_NVIC_INT_ACT_BASE, OS_NVIC_PRI_BASE, OS_NVIC_EXCPRI_BASE, OS_NVIC_SHCSR, OS_NVIC_INT_CTRL};
UINT32 rgNvicLens[OS_NR_NVIC_EXC_DUMP_Types] = {OS_NVIC_INT_ENABLE_SIZE, OS_NVIC_INT_PEND_SIZE,
OS_NVIC_INT_ACT_SIZE, OS_NVIC_INT_PRI_SIZE, OS_NVIC_EXCPRI_SIZE, OS_NVIC_SHCSR_SIZE, OS_NVIC_INT_CTRL_SIZE};
char strRgEnable[] = "enable";
char strRgPending[] = "pending";
char strRgActive[] = "active";
char strRgPriority[] = "priority";
char strRgException[] = "exception";
char strRgShcsr[] = "shcsr";
char strRgIntCtrl[] = "control";
char *strRgs[] = {strRgEnable, strRgPending, strRgActive, strRgPriority, strRgException, strRgShcsr, strRgIntCtrl};
(VOID)index;
(VOID)excContent;
PRINTK("OS exception NVIC dump: \n");
for (i = 0; i < OS_NR_NVIC_EXC_DUMP_Types; i++) {
base = (UINT32 *)rgNvicBases[i];
len = rgNvicLens[i];
PRINTK("interrupt %s register, base address: 0x%x, size: 0x%x\n", strRgs[i], base, len);
len = (len >> 2);
for (j = 0; j < len; j++) {
PRINTK("0x%x ", *(base + j));
}
PRINTK("\n");
}
}
UINT32 OsExcContextDump(UINT32 index, UINT32 *excContent)
{
(VOID)index;
(VOID)excContent;
PRINTK("OS exception context dump:\n");
PRINTK("Phase = 0x%x\n", g_excInfo.phase);
PRINTK("Type = 0x%x\n", g_excInfo.type);
PRINTK("FaultAddr = 0x%x\n", g_excInfo.faultAddr);
PRINTK("ThrdPid = 0x%x\n", g_excInfo.thrdPid);
PRINTK("R0 = 0x%x\n", g_excInfo.context->uwR0);
PRINTK("R1 = 0x%x\n", g_excInfo.context->uwR1);
PRINTK("R2 = 0x%x\n", g_excInfo.context->uwR2);
PRINTK("R3 = 0x%x\n", g_excInfo.context->uwR3);
PRINTK("R4 = 0x%x\n", g_excInfo.context->uwR4);
PRINTK("R5 = 0x%x\n", g_excInfo.context->uwR5);
PRINTK("R6 = 0x%x\n", g_excInfo.context->uwR6);
PRINTK("R7 = 0x%x\n", g_excInfo.context->uwR7);
PRINTK("R8 = 0x%x\n", g_excInfo.context->uwR8);
PRINTK("R9 = 0x%x\n", g_excInfo.context->uwR9);
PRINTK("R10 = 0x%x\n", g_excInfo.context->uwR10);
PRINTK("R11 = 0x%x\n", g_excInfo.context->uwR11);
PRINTK("R12 = 0x%x\n", g_excInfo.context->uwR12);
PRINTK("PriMask = 0x%x\n", g_excInfo.context->uwPriMask);
PRINTK("SP = 0x%x\n", g_excInfo.context->uwSP);
PRINTK("LR = 0x%x\n", g_excInfo.context->uwLR);
PRINTK("PC = 0x%x\n", g_excInfo.context->uwPC);
PRINTK("xPSR = 0x%x\n", g_excInfo.context->uwxPSR);
}
VOID OsDumpMsg(VOID)
{
UINT32 index = 0;
for (index = 0; index < (OS_EXC_TYPE_MAX - 1); index++) {
if (g_excArray[index].uwValid == FALSE) {
continue;
}
g_excArray[index].pFnExcInfoCb(index, g_excArray[index].pArg);
}
}
VOID OsExcNotify(VOID)
{
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;
g_curNestCount++;
g_vuwIntCount++;
g_excInfo.nestCnt = g_curNestCount;
g_excInfo.type = excType & OS_NULL_SHORT;
if (tmpFlag & OS_EXC_FLAG_FAULTADDR_VALID) {
g_excInfo.faultAddr = faultAddr;
} else {
g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR;
}
if (g_losTask.runTask != NULL) {
if (tmpFlag & OS_EXC_FLAG_IN_HWI) {
g_excInfo.phase = OS_EXC_IN_HWI;
g_excInfo.thrdPid = pid;
} else {
g_excInfo.phase = OS_EXC_IN_TASK;
g_excInfo.thrdPid = g_losTask.runTask->taskID;
}
} else {
g_excInfo.phase = OS_EXC_IN_INIT;
g_excInfo.thrdPid = OS_NULL_INT;
}
if (excType & OS_EXC_FLAG_NO_FLOAT) {
g_excInfo.context = (EXC_CONTEXT_S *)((CHAR *)excBufAddr - LOS_OFF_SET_OF(EXC_CONTEXT_S, uwR4));
} else {
g_excInfo.context = excBufAddr;
}
OsDumpMsg();
OsExcNotify();
LOS_Reboot();
}
VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg)
{
ExcInfoArray *excInfo = NULL;
if ((type >= OS_EXC_TYPE_MAX) || (func == NULL)) {
PRINT_ERR("OsExcRegister ERROR!\n");
return;
}
excInfo = &(g_excArray[type]);
excInfo->uwType = type;
excInfo->pFnExcInfoCb = func;
excInfo->pArg = arg;
excInfo->uwValid = TRUE;
}
void OsBackTrace()
{
}
/* ****************************************************************************
Function : OsHwiInit
Description : initialization of the hardware interrupt
Input : None
Output : None
Return : None
**************************************************************************** */
LITE_OS_SEC_TEXT_INIT VOID OsHwiInit()
{
UINT32 index;
UINT32 ret;
for (index = OS_SYS_VECTOR_CNT; index < OS_VECTOR_CNT; index++) {
g_hwiForm[index] = (HWI_PROC_FUNC)OsHwiDefaultHandler;
}
/* Exception handler register */
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = OsExcHardFault;
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = OsExcNMI;
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = OsExcMemFault;
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = OsExcBusFault;
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = OsExcUsageFault;
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = OsExcSvcCall;
/* Interrupt vector table location */
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;
#if (__CORTEX_M >= 0x03U) /* only for Cortex-M3 and above */
NVIC_SetPriorityGrouping(OS_NVIC_AIRCR_PRIGROUP);
#endif
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
/* Enable DIV 0 and unaligned exception */
*(volatile UINT32 *)OS_NVIC_CCR |= DIV0FAULT;
/* Init Exception Event */
ret = LOS_EventInit(&g_excEvent);
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;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

File diff suppressed because it is too large Load Diff

View File

@ -1,60 +0,0 @@
/*
* Copyright (c) 2013-2020, 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_EXC_H
#define _LOS_EXC_H
#include "los_hw.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
extern VOID LOS_Panic(const CHAR *fmt, ...);
extern VOID OsBackTrace(VOID);
extern VOID OsTaskBackTrace(UINT32 taskID);
STATIC INLINE UINTPTR GetFp(VOID)
{
UINTPTR fpSave = 0;
__asm__ __volatile__("mv %0, s0" : "=r"(fpSave));
return fpSave;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@ -1,123 +0,0 @@
/*
* Copyright (c) 2013-2020, 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_HW_H
#define _LOS_HW_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_hw
* The initialization value of stack space.
*/
#define EMPTY_STACK 0xCACA
/**
* @ingroup los_hw
* Check task schedule.
*/
#define LOS_CHECK_SCHEDULE ((!g_losTaskLock) && (!OS_INT_ACTIVE))
/**
* @ingroup los_hw
* @brief Wait for interrupt.
*
* @par Description:
* <ul>
* <li>This API is used to suspend execution until interrupt or a debug request occurs.</li>
* </ul>
* @attention None.
*
* @param None.
*
* @retval: None.
*
* @par Dependency:
* los_hw.h: the header file that contains the API declaration.
* @see None.
* @since Huawei LiteOS V200R002C00
*/
extern VOID wfi(VOID);
/**
* @ingroup los_hw
* @brief: mem fence function.
*
* @par Description:
* This API is used to fence for memory.
*
* @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.
* @since Huawei LiteOS V200R002C00
*/
extern VOID mb(VOID);
/**
* @ingroup los_hw
* @brief: mem fence function.
*
* @par Description:
* This API is same as mb, it just for adaptation.
*
* @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.
* @since Huawei LiteOS V200R002C00
*/
extern VOID dsb(VOID);
extern VOID LOS_GetCpuCycle(UINT32 *cntHi, UINT32 *cntLo);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_HW_H */

View File

@ -29,10 +29,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_HW_PRI_H
#define _LOS_HW_PRI_H
#ifndef _LOS_HW_H
#define _LOS_HW_H
#include "los_hw.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
@ -40,6 +40,18 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_hw
* The initialization value of stack space.
*/
#define EMPTY_STACK 0xCACA
/**
* @ingroup los_hw
* Check task schedule.
*/
#define LOS_CHECK_SCHEDULE ((!g_losTaskLock) && (!OS_INT_ACTIVE))
#define TP_INIT_VALUE 0x02020202L
#define SP_INIT_VALUE 0x03030303L
#define S11_INIT_VALUE 0x04040404L
@ -117,8 +129,67 @@ STATIC INLINE UINTPTR GetSP(VOID)
extern VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack);
extern VOID OsTaskScheduleCheck(VOID);
extern VOID OsDisableIRQ(VOID);
extern VOID OsEnableIRQ(VOID);
/**
* @ingroup los_hw
* @brief Wait for interrupt.
*
* @par Description:
* <ul>
* <li>This API is used to suspend execution until interrupt or a debug request occurs.</li>
* </ul>
* @attention None.
*
* @param None.
*
* @retval: None.
*
* @par Dependency:
* los_hw.h: the header file that contains the API declaration.
* @see None.
* @since Huawei LiteOS V200R002C00
*/
extern VOID wfi(VOID);
/**
* @ingroup los_hw
* @brief: mem fence function.
*
* @par Description:
* This API is used to fence for memory.
*
* @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.
* @since Huawei LiteOS V200R002C00
*/
extern VOID mb(VOID);
/**
* @ingroup los_hw
* @brief: mem fence function.
*
* @par Description:
* This API is same as mb, it just for adaptation.
*
* @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.
* @since Huawei LiteOS V200R002C00
*/
extern VOID dsb(VOID);
#ifdef __cplusplus
#if __cplusplus
@ -126,4 +197,4 @@ extern VOID OsEnableIRQ(VOID);
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_HW_PRI_H */
#endif /* _LOS_HW_H */

View File

@ -29,10 +29,11 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_exc.h"
#include "los_exc_pri.h"
#include "los_task_pri.h"
#include "los_printf_pri.h"
#include <stdio.h>
#include <stdarg.h>
#include "los_interrupt.h"
#include "los_task.h"
#include "los_debug.h"
#include "riscv_hal.h"
#ifdef __cplusplus
@ -41,8 +42,9 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
LosExcInfo g_excInfo;
static ExcInfoArray g_excArray[OS_EXC_TYPE_MAX];
LosExcInfo g_excInfo;
#define RISCV_EXC_TYPE_NUM 16
const CHAR g_excInformation[RISCV_EXC_TYPE_NUM][50] = {
{ "Instruction address misaligned!" },
@ -69,6 +71,150 @@ const CHAR g_excInformation[RISCV_EXC_TYPE_NUM][50] = {
#define FP_ALIGN(value) (((UINT32)(value) & (UINT32)(LOSCFG_STACK_POINT_ALIGN_SIZE - 1)) == 0)
#define FP_CHECK(value) (OsBackTraceFpCheck(value) && ((UINT32)(value) != FP_INIT_VALUE) && FP_ALIGN(value))
LITE_OS_SEC_BSS UINT32 g_intCount = 0;
LITE_OS_SEC_BSS UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM];
LITE_OS_SEC_DATA_INIT HWI_HANDLE_FORM_S g_hwiForm[OS_HWI_MAX_NUM] = {
{ .pfnHook = NULL, .uwParam = 0 }, // 0 User software interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 1 Supervisor software interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 2 Reserved
{ .pfnHook = OsHwiDefaultHandler, .uwParam = 0 }, // 3 Machine software interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 4 User timer interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 5 Supervisor timer interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 6 Reserved
{ .pfnHook = OsHwiDefaultHandler, .uwParam = 0 }, // 7 Machine timer interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 8 User external interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 9 Supervisor external interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 10 Reserved
{ .pfnHook = OsHwiDefaultHandler, .uwParam = 0 }, // 11 Machine external interrupt handler
{ .pfnHook = OsHwiDefaultHandler, .uwParam = 0 }, // 12 NMI handler
{ .pfnHook = NULL, .uwParam = 0 }, // 13 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 14 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 15 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 16 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 17 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 18 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 19 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 20 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 21 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 22 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 23 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 24 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 25 Reserved
};
LITE_OS_SEC_TEXT_INIT VOID OsHwiDefaultHandler(UINTPTR arg)
{
(VOID)arg;
PRINT_ERR("default handler\n");
while (1) {
}
}
LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID)
{
UINT32 index;
for (index = OS_RISCV_SYS_VECTOR_CNT; index < OS_HWI_MAX_NUM; index++) {
g_hwiForm[index].pfnHook = OsHwiDefaultHandler;
g_hwiForm[index].uwParam = 0;
}
}
typedef VOID (*HwiProcFunc)(UINTPTR);
LITE_OS_SEC_TEXT_INIT VOID OsHwiInterruptDone(HWI_HANDLE_T hwiNum)
{
g_intCount++;
HWI_HANDLE_FORM_S *hwiForm = &g_hwiForm[hwiNum];
HwiProcFunc func = (HwiProcFunc)(hwiForm->pfnHook);
func(hwiForm->uwParam);
++g_hwiFormCnt[hwiNum];
g_intCount--;
}
LITE_OS_SEC_TEXT UINT32 OsGetHwiFormCnt(HWI_HANDLE_T hwiNum)
{
if (hwiNum < OS_HWI_MAX_NUM) {
return g_hwiFormCnt[hwiNum];
}
return LOS_NOK;
}
LITE_OS_SEC_TEXT HWI_HANDLE_FORM_S *OsGetHwiForm(VOID)
{
return g_hwiForm;
}
/*****************************************************************************
Function : LOS_HwiCreate
Description : create hardware interrupt
Input : hwiNum --- hwi num to create
hwiPrio --- priority of the hwi
hwiMode --- hwi interrupt mode
hwiHandler --- hwi handler
irqParam --- param of the hwi handler
Output : None
Return : LOS_OK on success or error code on failure
*****************************************************************************/
LITE_OS_SEC_TEXT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
HWI_PRIOR_T hwiPrio,
HWI_MODE_T hwiMode,
HWI_PROC_FUNC hwiHandler,
HWI_IRQ_PARAM_S irqParam)
{
UINT32 intSave;
if (hwiHandler == NULL) {
return OS_ERRNO_HWI_PROC_FUNC_NULL;
}
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
if (g_hwiForm[hwiNum].pfnHook == NULL) {
return OS_ERRNO_HWI_NUM_INVALID;
} else if (g_hwiForm[hwiNum].pfnHook != OsHwiDefaultHandler) {
return OS_ERRNO_HWI_NUM_INVALID;
}
if ((hwiPrio < OS_HWI_PRIO_LOWEST) || (hwiPrio > OS_HWI_PRIO_HIGHEST)) {
return OS_ERRNO_HWI_PRIO_INVALID;
}
intSave = LOS_IntLock();
g_hwiForm[hwiNum].pfnHook = hwiHandler;
g_hwiForm[hwiNum].uwParam = irqParam;
if (hwiNum >= OS_RISCV_SYS_VECTOR_CNT) {
OsSetLocalInterPri(hwiNum, hwiPrio);
}
LOS_IntRestore(intSave);
return LOS_OK;
}
/*****************************************************************************
Function : LOS_HwiDelete
Description : Delete hardware interrupt
Input : hwiNum --- hwi num to delete
Return : LOS_OK on success or error code on failure
*****************************************************************************/
LITE_OS_SEC_TEXT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S irqParam)
{
UINT32 intSave;
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
intSave = LOS_IntLock();
g_hwiForm[hwiNum].pfnHook = OsHwiDefaultHandler;
g_hwiForm[hwiNum].uwParam = 0;
LOS_IntRestore(intSave);
return LOS_OK;
}
LITE_OS_SEC_TEXT VOID BackTraceSub(UINT32 fp)
{
UINT32 backFp = fp;
@ -259,6 +405,20 @@ SYSTEM_DEATH:
}
}
VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg)
{
ExcInfoArray *excInfo = NULL;
if ((type >= OS_EXC_TYPE_MAX) || (func == NULL)) {
PRINT_ERR("OsExcRegister ERROR!\n");
return;
}
excInfo = &(g_excArray[type]);
excInfo->uwType = type;
excInfo->pFnExcInfoCb = func;
excInfo->pArg = arg;
excInfo->uwValid = TRUE;
}
/* stack protector */
UINT32 __stack_chk_guard = 0xd00a0dff;

View File

@ -29,11 +29,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_hw.h"
#include "los_hw_pri.h"
#include "los_task_pri.h"
#include "los_context.h"
#include "los_interrupt.h"
#include "los_task.h"
#include "los_memory.h"
#include "los_priqueue_pri.h"
#include "soc.h"
#ifdef __cplusplus

View File

@ -29,9 +29,9 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_hw_tick_pri.h"
#include "los_hwi.h"
#include "los_tick_pri.h"
#include "los_tick.h"
#include "los_config.h"
#include "los_interrupt.h"
#include "riscv_hal.h"
#ifdef __cplusplus
@ -53,6 +53,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTickStart(VOID)
return LOS_OK;
}
/* ****************************************************************************
Function : LOS_GetCpuCycle
Description : Get System cycle count
Input : none
output : cntHi --- CpuTick High 4 byte
cntLo --- CpuTick Low 4 byte
return : none
**************************************************************************** */
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *cntHi, UINT32 *cntLo)
{
OsGetCpuCycle(cntHi, cntLo);

View File

@ -31,8 +31,9 @@
#ifndef _LOS_HWI_H
#define _LOS_HWI_H
#include "securec.h"
#include "los_printf.h"
#include "los_compiler.h"
#include "los_config.h"
#include "los_context.h"
#ifdef __cplusplus
#if __cplusplus
@ -97,6 +98,135 @@ typedef struct tagHwiHandleForm {
typedef UINTPTR HWI_IRQ_PARAM_S;
typedef struct {
UINT32 mcause;
UINT32 mtval;
UINT32 medeleg;
UINT32 gp;
TaskContext taskContext;
} LosExcContext;
typedef struct {
UINT16 nestCnt;
UINT16 type;
UINT32 thrID;
LosExcContext *context;
} LosExcInfo;
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 UINT32 (*EXC_INFO_SAVE_CALLBACK)(UINT32, VOID*);
typedef struct {
ExcInfoType uwType;
UINT32 uwValid;
EXC_INFO_SAVE_CALLBACK pFnExcInfoCb;
VOID* pArg;
} ExcInfoArray;
#define MAX_EXC_MEM_SIZE 0
/**
* @ingroup los_hwi
* Highest priority of a hardware interrupt.
*/
#define OS_HWI_PRIO_HIGHEST 7
/**
* @ingroup los_hwi
* Lowest priority of a hardware interrupt.
*/
#define OS_HWI_PRIO_LOWEST 1
/**
* @ingroup los_hwi
* Count of HimiDeer system interrupt vector.
*/
#define OS_RISCV_SYS_VECTOR_CNT (RISCV_SYS_MAX_IRQ + 1)
/**
* @ingroup los_hwi
* Count of HimiDeer local interrupt vector 0 - 5, enabled by CSR mie 26 -31 bit.
*/
#define OS_RISCV_MIE_IRQ_VECTOR_CNT 6
/**
* @ingroup los_hwi
* Count of HimiDeer local interrupt vector 6 - 31, enabled by custom CSR locie0 0 - 25 bit.
*/
#define OS_RISCV_CUSTOM_IRQ_VECTOR_CNT RISCV_PLIC_VECTOR_CNT
/**
* @ingroup los_hwi
* Count of HimiDeer local IRQ interrupt vector.
*/
#define OS_RISCV_LOCAL_IRQ_VECTOR_CNT (OS_RISCV_MIE_IRQ_VECTOR_CNT + OS_RISCV_SYS_VECTOR_CNT)
/**
* @ingroup los_hwi
* Count of himideer interrupt vector.
*/
#define OS_RISCV_VECTOR_CNT (OS_RISCV_SYS_VECTOR_CNT + OS_RISCV_CUSTOM_IRQ_VECTOR_CNT)
/**
* Maximum number of supported hardware devices that generate hardware interrupts.
* The maximum number of hardware devices that generate hardware interrupts supported by hi3518ev200 is 32.
*/
#define OS_HWI_MAX_NUM OS_RISCV_VECTOR_CNT
/**
* Maximum interrupt number.
*/
#define OS_HWI_MAX ((OS_HWI_MAX_NUM) - 1)
/**
* Minimum interrupt number.
*/
#define OS_HWI_MIN 0
/**
* Maximum usable interrupt number.
*/
#define OS_USER_HWI_MAX OS_HWI_MAX
/**
* Minimum usable interrupt number.
*/
#define OS_USER_HWI_MIN OS_HWI_MIN
extern HWI_HANDLE_FORM_S g_hwiForm[OS_HWI_MAX_NUM];
extern VOID OsHwiInit(VOID);
extern UINT32 OsGetHwiFormCnt(HWI_HANDLE_T hwiNum);
extern HWI_HANDLE_FORM_S *OsGetHwiForm(VOID);
extern VOID OsHwiInterruptDone(HWI_HANDLE_T hwiNum);
extern VOID OsHwiDefaultHandler(UINTPTR arg);
extern VOID BackTraceSub(UINT32 fp);
extern VOID OsDisableIRQ(VOID);
extern VOID OsEnableIRQ(VOID);
extern VOID LOS_Panic(const CHAR *fmt, ...);
extern VOID OsBackTrace(VOID);
extern VOID OsTaskBackTrace(UINT32 taskID);
extern VOID OsExcInit(VOID);
extern VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg);
STATIC INLINE UINTPTR GetFp(VOID)
{
UINTPTR fpSave = 0;
__asm__ __volatile__("mv %0, s0" : "=r"(fpSave));
return fpSave;
}
extern UINT32 g_intCount;
/**
@ -346,6 +476,29 @@ extern UINT32 LOS_IntLock(VOID);
*/
extern VOID LOS_IntRestore(UINT32 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);
/**
* @ingroup los_hwi
* @brief Delete hardware interrupt.

View File

@ -1,67 +0,0 @@
/*
* Copyright (c) 2013-2020, 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_EXC_PRI_H
#define _LOS_EXC_PRI_H
#include "los_typedef.h"
#include "los_hw_pri.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
extern VOID BackTraceSub(UINT32 fp);
typedef struct {
UINT32 mcause;
UINT32 mtval;
UINT32 medeleg;
UINT32 gp;
TaskContext taskContext;
} LosExcContext;
typedef struct {
UINT16 nestCnt;
UINT16 type;
UINT32 thrID;
LosExcContext *context;
} LosExcInfo;
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_EXC_PRI_H */

View File

@ -1,135 +0,0 @@
/*
* Copyright (c) 2013-2020, 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_HWI_PRI_H
#define _LOS_HWI_PRI_H
#include "soc.h"
#include "los_hwi.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_hwi
* The hwi form does not contain exceptions for cortex-A
*/
#define OS_HWI_FORM_EXC_NUM 0
#if OS_HWI_FORM_EXC_NUM != 0
#error "OS_HWI_FORM_EXC_NUM must be zero"
#endif
/**
* @ingroup los_hwi
* Highest priority of a hardware interrupt.
*/
#define OS_HWI_PRIO_HIGHEST 7
/**
* @ingroup los_hwi
* Lowest priority of a hardware interrupt.
*/
#define OS_HWI_PRIO_LOWEST 1
/**
* @ingroup los_hwi
* Count of HimiDeer system interrupt vector.
*/
#define OS_RISCV_SYS_VECTOR_CNT (RISCV_SYS_MAX_IRQ + 1)
/**
* @ingroup los_hwi
* Count of HimiDeer local interrupt vector 0 - 5, enabled by CSR mie 26 -31 bit.
*/
#define OS_RISCV_MIE_IRQ_VECTOR_CNT 6
/**
* @ingroup los_hwi
* Count of HimiDeer local interrupt vector 6 - 31, enabled by custom CSR locie0 0 - 25 bit.
*/
#define OS_RISCV_CUSTOM_IRQ_VECTOR_CNT RISCV_PLIC_VECTOR_CNT
/**
* @ingroup los_hwi
* Count of HimiDeer local IRQ interrupt vector.
*/
#define OS_RISCV_LOCAL_IRQ_VECTOR_CNT (OS_RISCV_MIE_IRQ_VECTOR_CNT + OS_RISCV_SYS_VECTOR_CNT)
/**
* @ingroup los_hwi
* Count of himideer interrupt vector.
*/
#define OS_RISCV_VECTOR_CNT (OS_RISCV_SYS_VECTOR_CNT + OS_RISCV_CUSTOM_IRQ_VECTOR_CNT)
/**
* Maximum number of supported hardware devices that generate hardware interrupts.
* The maximum number of hardware devices that generate hardware interrupts supported by hi3518ev200 is 32.
*/
#define OS_HWI_MAX_NUM OS_RISCV_VECTOR_CNT
/**
* Maximum interrupt number.
*/
#define OS_HWI_MAX ((OS_HWI_MAX_NUM) - 1)
/**
* Minimum interrupt number.
*/
#define OS_HWI_MIN 0
/**
* Maximum usable interrupt number.
*/
#define OS_USER_HWI_MAX OS_HWI_MAX
/**
* Minimum usable interrupt number.
*/
#define OS_USER_HWI_MIN OS_HWI_MIN
extern HWI_HANDLE_FORM_S g_hwiForm[OS_HWI_MAX_NUM];
extern VOID OsHwiInit(VOID);
extern UINT32 OsGetHwiFormCnt(HWI_HANDLE_T hwiNum);
extern HWI_HANDLE_FORM_S *OsGetHwiForm(VOID);
extern VOID OsHwiInterruptDone(HWI_HANDLE_T hwiNum);
extern VOID OsHwiDefaultHandler(UINTPTR arg);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_HWI_PRI_H */

View File

@ -1,191 +0,0 @@
/*
* Copyright (c) 2013-2020, 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 "los_base.h"
#include "los_hwi_pri.h"
#include "riscv_hal.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
LITE_OS_SEC_BSS UINT32 g_intCount = 0;
LITE_OS_SEC_BSS UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM];
LITE_OS_SEC_DATA_INIT HWI_HANDLE_FORM_S g_hwiForm[OS_HWI_MAX_NUM] = {
{ .pfnHook = NULL, .uwParam = 0 }, // 0 User software interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 1 Supervisor software interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 2 Reserved
{ .pfnHook = OsHwiDefaultHandler, .uwParam = 0 }, // 3 Machine software interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 4 User timer interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 5 Supervisor timer interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 6 Reserved
{ .pfnHook = OsHwiDefaultHandler, .uwParam = 0 }, // 7 Machine timer interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 8 User external interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 9 Supervisor external interrupt handler
{ .pfnHook = NULL, .uwParam = 0 }, // 10 Reserved
{ .pfnHook = OsHwiDefaultHandler, .uwParam = 0 }, // 11 Machine external interrupt handler
{ .pfnHook = OsHwiDefaultHandler, .uwParam = 0 }, // 12 NMI handler
{ .pfnHook = NULL, .uwParam = 0 }, // 13 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 14 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 15 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 16 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 17 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 18 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 19 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 20 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 21 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 22 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 23 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 24 Reserved
{ .pfnHook = NULL, .uwParam = 0 }, // 25 Reserved
};
LITE_OS_SEC_TEXT_INIT VOID OsHwiDefaultHandler(UINTPTR arg)
{
(VOID)arg;
PRINT_ERR("default handler\n");
while (1) {
}
}
LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID)
{
UINT32 index;
for (index = OS_RISCV_SYS_VECTOR_CNT; index < OS_HWI_MAX_NUM; index++) {
g_hwiForm[index].pfnHook = OsHwiDefaultHandler;
g_hwiForm[index].uwParam = 0;
}
}
typedef VOID (*HwiProcFunc)(UINTPTR);
LITE_OS_SEC_TEXT_INIT VOID OsHwiInterruptDone(HWI_HANDLE_T hwiNum)
{
g_intCount++;
HWI_HANDLE_FORM_S *hwiForm = &g_hwiForm[hwiNum];
HwiProcFunc func = (HwiProcFunc)(hwiForm->pfnHook);
func(hwiForm->uwParam);
++g_hwiFormCnt[hwiNum];
g_intCount--;
}
LITE_OS_SEC_TEXT UINT32 OsGetHwiFormCnt(HWI_HANDLE_T hwiNum)
{
if (hwiNum < OS_HWI_MAX_NUM) {
return g_hwiFormCnt[hwiNum];
}
return LOS_NOK;
}
LITE_OS_SEC_TEXT HWI_HANDLE_FORM_S *OsGetHwiForm(VOID)
{
return g_hwiForm;
}
/*****************************************************************************
Function : LOS_HwiCreate
Description : create hardware interrupt
Input : hwiNum --- hwi num to create
hwiPrio --- priority of the hwi
hwiMode --- hwi interrupt mode
hwiHandler --- hwi handler
irqParam --- param of the hwi handler
Output : None
Return : LOS_OK on success or error code on failure
*****************************************************************************/
LITE_OS_SEC_TEXT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
HWI_PRIOR_T hwiPrio,
HWI_MODE_T hwiMode,
HWI_PROC_FUNC hwiHandler,
HWI_IRQ_PARAM_S irqParam)
{
UINT32 intSave;
if (hwiHandler == NULL) {
return OS_ERRNO_HWI_PROC_FUNC_NULL;
}
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
if (g_hwiForm[hwiNum].pfnHook == NULL) {
return OS_ERRNO_HWI_NUM_INVALID;
} else if (g_hwiForm[hwiNum].pfnHook != OsHwiDefaultHandler) {
return OS_ERRNO_HWI_NUM_INVALID;
}
if ((hwiPrio < OS_HWI_PRIO_LOWEST) || (hwiPrio > OS_HWI_PRIO_HIGHEST)) {
return OS_ERRNO_HWI_PRIO_INVALID;
}
intSave = LOS_IntLock();
g_hwiForm[hwiNum].pfnHook = hwiHandler;
g_hwiForm[hwiNum].uwParam = irqParam;
if (hwiNum >= OS_RISCV_SYS_VECTOR_CNT) {
OsSetLocalInterPri(hwiNum, hwiPrio);
}
LOS_IntRestore(intSave);
return LOS_OK;
}
/*****************************************************************************
Function : LOS_HwiDelete
Description : Delete hardware interrupt
Input : hwiNum --- hwi num to delete
Return : LOS_OK on success or error code on failure
*****************************************************************************/
LITE_OS_SEC_TEXT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S irqParam)
{
UINT32 intSave;
if (hwiNum >= OS_HWI_MAX_NUM) {
return OS_ERRNO_HWI_NUM_INVALID;
}
intSave = LOS_IntLock();
g_hwiForm[hwiNum].pfnHook = OsHwiDefaultHandler;
g_hwiForm[hwiNum].uwParam = 0;
LOS_IntRestore(intSave);
return LOS_OK;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@ -1,390 +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 <string.h>
#include <stdint.h>
#include "securec.h"
#include "los_slab_pri.h"
#include "los_heap_pri.h"
#define LOW_BITS_MASK 31
#define NUM_BITS_IN_ONE_BYTE 32
#define NUMBITS_TO_NUMBYTES(numBits) (((numBits) + LOW_BITS_MASK) / 8)
VOID OsAtomicBitsetInit(struct AtomicBitset *set, UINT32 numBits)
{
set->numBits = numBits;
// Ignore the return code when matching CSEC rule 6.6(2).
(VOID)memset_s(set->words, NUMBITS_TO_NUMBYTES(numBits), 0, NUMBITS_TO_NUMBYTES(numBits));
// mark all high bits so that OsAtomicBitsetFindClearAndSet() is simpler
if (numBits & LOW_BITS_MASK) {
set->words[numBits / NUM_BITS_IN_ONE_BYTE] =
((UINT32)((INT32) - 1LL)) << (numBits & LOW_BITS_MASK);
}
}
inline UINT32 OsAtomicBitsetGetNumBits(const struct AtomicBitset *set)
{
return set->numBits;
}
/**************************************************************************
Function : OsAtomicBitsetGetBit
Description : get the specified bit in set
Input : set --- pointer to the bitset
num --- the num to fetch
Output : None
Return : LOS_OK on success or error code on failure
**************************************************************************/
BOOL OsAtomicBitsetGetBit(const struct AtomicBitset *set, UINT32 num)
{
/* any value is as good as the next */
if (num >= set->numBits) {
return FALSE;
}
return !!((set->words[num / NUM_BITS_IN_ONE_BYTE]) & (1UL << (num & LOW_BITS_MASK)));
}
/**************************************************************************
Function : OsAtomicBitsetClearBit
Description : clear the specified bit in set
Input : set --- pointer to the bitset
num --- the num to clear
Output : None
Return : None
**************************************************************************/
VOID OsAtomicBitsetClearBit(struct AtomicBitset *set, UINT32 num)
{
UINT32 *wordPtr = set->words + (num / NUM_BITS_IN_ONE_BYTE);
if (num >= set->numBits) {
return;
}
(*wordPtr) &= ~(1UL << (num & LOW_BITS_MASK));
}
/* find from the high bit to high bit return the address of the first available bit */
INT32 OsAtomicBitsetFindClearAndSet(struct AtomicBitset *set)
{
UINT32 idx;
UINT32 numWords = (set->numBits + LOW_BITS_MASK) / NUM_BITS_IN_ONE_BYTE;
UINT32 *wordPtr = set->words;
UINT32 tmpWord;
INT32 count = 0;
for (idx = 0; idx < numWords; idx++, wordPtr++) {
if (*wordPtr == 0xFFFFFFFF) {
continue;
}
tmpWord = ~(*wordPtr);
while (tmpWord) {
tmpWord = tmpWord >> 1UL;
count++;
}
*wordPtr |= (1UL << (count - 1));
return (INT32)(idx * NUM_BITS_IN_ONE_BYTE + count - 1);
}
return -1;
}
/* change the order of the output idx of OsAtomicBitsetFindClearAndSet to order of natural numbers */
INT32 OsAtomicBitsetIdxChgToNatural(struct AtomicBitset *bitset, INT32 index)
{
UINT32 ret;
UINT32 bit;
if (index < 0) {
return index;
}
bit = LOW_BITS_MASK + (index & ~LOW_BITS_MASK);
if (bit > bitset->numBits - 1) {
bit = bitset->numBits - 1;
}
ret = bit - (index & LOW_BITS_MASK);
return ret;
}
/**************************************************************************
Function : OsAtomicBitsetEmpty
Description : check whether bitset is empty
Input : bitset --- pointer to the bitset
Output : None
Return : LOS_OK on success or error code on failure
**************************************************************************/
BOOL OsAtomicBitsetEmpty(struct AtomicBitset *bitset)
{
UINT32 idx = 0;
for (idx = 0; idx < (bitset->numBits / NUM_BITS_IN_ONE_BYTE);) {
if (bitset->words[idx] != 0) {
return FALSE;
}
idx++;
}
if (bitset->numBits & LOW_BITS_MASK) {
if (bitset->words[idx] & ~(0xFFFFFFFF << (bitset->numBits & LOW_BITS_MASK))) {
return FALSE;
}
}
return TRUE;
}
/**************************************************************************
Function : OsSlabAllocatorNew
Description : create a new allocator
Input : pool --- pointer to the pool
itemSz --- alloc size
itemAlign --- aligned size
numItems --- item num
Output : None
Return : the pointer to a new allocator
**************************************************************************/
OsSlabAllocator* OsSlabAllocatorNew(VOID *pool, UINT32 itemSz, UINT32 itemAlign, UINT32 numItems)
{
OsSlabAllocator *allocator = NULL;
UINT32 bitSetSz;
UINT32 dataSz;
UINT32 itemSize;
/* calculate size */
bitSetSz = ATOMIC_BITSET_SZ(numItems);
bitSetSz = (bitSetSz + itemAlign - 1) & (~(itemAlign - 1));
itemSize = (itemSz + itemAlign - 1) & (~(itemAlign - 1));
dataSz = itemSize * numItems;
allocator = (OsSlabAllocator*)LOS_HeapAlloc(pool, sizeof(OsSlabAllocator) + bitSetSz + dataSz);
if (allocator != NULL) {
allocator->itemSz = itemSize;
allocator->bitset = (struct AtomicBitset *)(VOID *)((UINT8*)allocator + sizeof(OsSlabAllocator));
allocator->dataChunks = ((UINT8*)allocator->bitset) + bitSetSz;
OsAtomicBitsetInit(allocator->bitset, numItems);
}
return allocator;
}
/**************************************************************************
Function : OsSlabAllocatorDestroy
Description : free the specified allocator
Input : pool --- pointer to the pool
allocator --- pointer to the allocator
Output : None
Return : None
**************************************************************************/
VOID OsSlabAllocatorDestroy(VOID *pool, OsSlabAllocator *allocator)
{
(VOID)LOS_HeapFree(pool, allocator);
}
/**************************************************************************
Function : OsSlabAllocatorAlloc
Description : alloc one bit from the specified allocator
Input : allocator --- pointer to the allocator
Output : None
Return : NULL on failure or one bit from the specified allocator
**************************************************************************/
VOID* OsSlabAllocatorAlloc(OsSlabAllocator *allocator)
{
INT32 itemIdx = OsAtomicBitsetFindClearAndSet(allocator->bitset);
if (itemIdx < 0) {
return NULL;
}
return allocator->dataChunks + allocator->itemSz * itemIdx;
}
/**************************************************************************
Function : OsSlabAllocatorFree
Description : free the specified bit in the specified allocator
Input : allocator --- pointer to the allocator
ptr --- pointer to the mem chunk to be freed
Output : None
Return : TRUE or FALSE
**************************************************************************/
BOOL OsSlabAllocatorFree(OsSlabAllocator *allocator, VOID* ptr)
{
UINT8 *ptrTmp = (UINT8*)ptr;
UINT32 itemOffset = ptrTmp - allocator->dataChunks;
UINT32 itemIdx = itemOffset / allocator->itemSz;
// check for invalid inputs
if ((itemOffset % allocator->itemSz) || (itemIdx >= OsAtomicBitsetGetNumBits(allocator->bitset)) ||
!(OsAtomicBitsetGetBit(allocator->bitset, itemIdx))) {
return FALSE;
}
OsAtomicBitsetClearBit(allocator->bitset, itemIdx);
return TRUE;
}
/**************************************************************************
Function : OsSlabAllocatorGetNth
Description : get the specified data chunk from the allocator
Input : allocator --- pointer to the allocator
idx --- chunk num
Output : None
Return : NULL on failure or specified data chunk on success
**************************************************************************/
VOID* OsSlabAllocatorGetNth(OsSlabAllocator *allocator, UINT32 idx)
{
if (!OsAtomicBitsetGetBit(allocator->bitset, idx)) {
return NULL;
}
return allocator->dataChunks + allocator->itemSz * idx;
}
/**************************************************************************
Function : OsSlabAllocatorGetIdxP
Description : get the specified dataChunk from the specified allocator
Input : allocator --- pointer to the allocator
idx --- chunk num
Output : None
Return : the specified data Chunk from the specified allocator
**************************************************************************/
VOID* OsSlabAllocatorGetIdxP(OsSlabAllocator *allocator, UINT32 idx)
{
return allocator->dataChunks + allocator->itemSz * idx;
}
/**************************************************************************
Function : OsSlabAllocatorGetIndex
Description : get item index from the specified allocator
Input : allocator --- pointer to the allocator
ptr --- pointer to the mem chunk to get index
Output : None
Return : the item index from the specified allocator
**************************************************************************/
UINT32 OsSlabAllocatorGetIndex(OsSlabAllocator *allocator, VOID* ptr)
{
UINT8 *ptrTmp = (UINT8*)ptr;
UINT32 itemOffset = ptrTmp - allocator->dataChunks;
UINT32 itemIdx = itemOffset / allocator->itemSz;
if ((itemOffset % allocator->itemSz) ||
(itemIdx >= OsAtomicBitsetGetNumBits(allocator->bitset)) ||
!(OsAtomicBitsetGetBit(allocator->bitset, itemIdx))) {
return (UINT32)(-1);
}
return itemIdx;
}
/**************************************************************************
Function : OsSlabAllocatorGetNumItems
Description : get num bits of the specified allocator
Input : allocator --- pointer to the allocator
Output : None
Return : LOS_OK on success or error code on failure
**************************************************************************/
UINT32 OsSlabAllocatorGetNumItems(OsSlabAllocator *allocator)
{
return OsAtomicBitsetGetNumBits(allocator->bitset);
}
/**************************************************************************
Function : OsSlabAllocatorEmpty
Description : check whether the allocator is empty
Input : allocator --- pointer to the allocator
Output : None
Return : LOS_OK on success or error code on failure
**************************************************************************/
BOOL OsSlabAllocatorEmpty(OsSlabAllocator *allocator)
{
return OsAtomicBitsetEmpty(allocator->bitset);
}
/**************************************************************************
Function : OsSlabAllocatorGetUsedItemCnt
Description : get used num of the specified allocator
Input : allocator --- pointer to the allocator
Output : None
Return : used num of the specifiedd allocator
**************************************************************************/
UINT32 OsSlabAllocatorGetUsedItemCnt(OsSlabAllocator *allocator)
{
UINT32 used;
UINT32 idx;
struct AtomicBitset *bitset = allocator->bitset;
for (used = 0, idx = 0; idx < bitset->numBits; idx++) {
if (OsAtomicBitsetGetBit(bitset, idx)) {
used++;
}
}
return used;
}
/**************************************************************************
Function : OsSlabAllocatorGetSlabInfo
Description : get slab info from the specified allocator
Input : allocator --- pointer to the allocator
Output : pitemSz --- item size
itemCnt --- item count
curUsage --- current usage
Return : None
**************************************************************************/
VOID OsSlabAllocatorGetSlabInfo(OsSlabAllocator *allocator, UINT32 *pitemSz, UINT32 *itemCnt, UINT32 *curUsage)
{
*pitemSz = allocator->itemSz;
*itemCnt = OsAtomicBitsetGetNumBits(allocator->bitset);
*curUsage = OsSlabAllocatorGetUsedItemCnt(allocator);
}
/**************************************************************************
Function : OsSlabAllocatorCheck
Description : check whether ptr is in allocator
Input : allocator --- pointer to the allocator
ptr --- pointer to the mem chunk to check
Output : None
Return : TRUE or FALSE
**************************************************************************/
BOOL OsSlabAllocatorCheck(OsSlabAllocator *allocator, VOID* ptr)
{
UINT8 *ptrTmp = (UINT8*)ptr;
UINT32 itemOffset = ptrTmp - allocator->dataChunks;
UINT32 itemIdx = itemOffset / allocator->itemSz;
// check for invalid inputs
if ((itemOffset % allocator->itemSz) || (itemIdx >= OsAtomicBitsetGetNumBits(allocator->bitset)) ||
!(OsAtomicBitsetGetBit(allocator->bitset, itemIdx))) {
return FALSE;
}
return TRUE;
}

View File

@ -1,307 +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.
*/
#define _LOS_SLAB_MEM_C_
#include <los_printf.h>
#include <los_hwi.h>
#include <los_slab_pri.h>
VOID *OsSlabBlockHeadFill(OsSlabBlockNode *slabNode, UINT32 blkSz)
{
OS_SLAB_BLOCK_MAGIC_SET(slabNode);
OS_SLAB_BLOCK_SIZE_SET(slabNode, blkSz);
OS_SLAB_BLOCK_ID_SET(slabNode, 0); // now undefine how to use ID
return (VOID *)(slabNode + 1);
}
/*****************************************************************************
Function : OsSlabMemInit
Description : To initialize the slab memory management
Input : None
Output : None
Return : TRUE --- initialize OK, FALSE --- initialize false
*****************************************************************************/
BOOL OsSlabMemInit(VOID *pool)
{
struct LosSlabControlHeader *slabMemHead = OsSlabCtrlHdrGet(pool);
UINT32 idx = 0;
UINT32 tmp = 0;
UINT32 blkSz = 0;
UINT32 blkCnt = 0;
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
blkSz = (SLAB_MEM_CALSS_STEP_SIZE << idx);
blkCnt = SLAB_MEM_ALLOCATOR_SIZE / blkSz;
slabMemHead->slabClass[idx].blkSz = blkSz;
slabMemHead->slabClass[idx].blkCnt = blkCnt;
slabMemHead->slabClass[idx].blkUsedCnt = 0;
if (slabMemHead->slabClass[idx].alloc != NULL) {
PRINT_WARN("SlabMemAllocator[%d] inited before\n", idx);
tmp++;
} else {
slabMemHead->slabClass[idx].alloc =
OsSlabAllocatorNew(pool, blkSz + sizeof(OsSlabBlockNode), (UINT32)sizeof(VOID *), blkCnt);
}
}
return ((tmp == 0) ? TRUE : FALSE);
}
/*****************************************************************************
Function : OsSlabMemAlloc
Description : To alloc memory block
Input : pool --- pointer to the memory pool
size --- size of the memory we want to alloc
Output : None
Return : pointer :the address of the memory we alloced
*****************************************************************************/
VOID *OsSlabMemAlloc(VOID *pool, UINT32 size)
{
VOID *ret = NULL;
UINTPTR intSave;
struct LosSlabControlHeader *slabMem = OsSlabCtrlHdrGet(pool);
OsSlabMem *slabAlloc = NULL;
UINT32 idx;
if (size > (SLAB_MEM_CALSS_STEP_SIZE << (SLAB_MEM_COUNT - 1))) {
return NULL;
}
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
if (size <= slabMem->slabClass[idx].blkSz) {
intSave = LOS_IntLock();
if (slabMem->slabClass[idx].blkUsedCnt >= slabMem->slabClass[idx].blkCnt) {
LOS_IntRestore(intSave);
return NULL;
}
if (slabMem->slabClass[idx].alloc == NULL) {
LOS_IntRestore(intSave);
return NULL;
}
slabAlloc = &(slabMem->slabClass[idx]);
ret = OsSlabAllocatorAlloc(slabAlloc->alloc);
if (ret != NULL) {
/* alloc success */
ret = OsSlabBlockHeadFill((OsSlabBlockNode *)ret, slabMem->slabClass[idx].blkSz);
slabMem->slabClass[idx].blkUsedCnt++;
}
LOS_IntRestore(intSave);
return ret;
}
}
return NULL;
}
/*****************************************************************************
Function : OsSlabMemFree
Description : To free the memory block
Input : pool --- Pointer to the memory pool that contains the memory block to be allocated
ptr --- the pointer of heap memory we want to free
Output : None
Return : TRUE:success FALSE:error
*****************************************************************************/
BOOL OsSlabMemFree(VOID *pool, VOID* ptr)
{
UINTPTR intSave;
struct LosSlabControlHeader *slabMem = OsSlabCtrlHdrGet(pool);
BOOL ret = FALSE;
OsSlabMem *slabAlloc = NULL;
UINT32 idx;
OsSlabBlockNode *slabNode = OS_SLAB_BLOCK_HEAD_GET(ptr);
if (!OS_ALLOC_FROM_SLAB_CHECK(slabNode)) {
return FALSE;
}
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
if (slabMem->slabClass[idx].blkSz >= OS_SLAB_BLOCK_SIZE_GET(slabNode)) {
intSave = LOS_IntLock();
slabAlloc = &(slabMem->slabClass[idx]);
if (TRUE == OsSlabAllocatorFree(slabAlloc->alloc, slabNode)) {
ret = TRUE;
slabMem->slabClass[idx].blkUsedCnt--;
}
LOS_IntRestore(intSave);
return ret;
}
}
return FALSE;
}
/*****************************************************************************
Function : OsSlabMemDeinit
Description : deinitialize the slab memory ,set back to the original status
Input : pool --- Pointer to the memory pool
Output : None
Return : None
*****************************************************************************/
VOID OsSlabMemDeinit(VOID *pool)
{
UINT32 idx;
struct LosSlabControlHeader *slabMem = NULL;
OsSlabMem *slabAlloc = NULL;
UINT32 blkSz;
UINT32 blkCnt;
if (pool == NULL) {
return ;
}
slabMem = OsSlabCtrlHdrGet(pool);
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
blkSz = (SLAB_MEM_CALSS_STEP_SIZE << idx);
blkCnt = SLAB_MEM_ALLOCATOR_SIZE / blkSz;
slabMem->slabClass[idx].blkSz = blkSz;
slabMem->slabClass[idx].blkCnt = blkCnt;
if (slabMem->slabClass[idx].alloc != NULL) {
slabAlloc = &(slabMem->slabClass[idx]);
OsSlabAllocatorDestroy(pool, slabAlloc->alloc);
slabMem->slabClass[idx].alloc = NULL;
}
}
return ;
}
/**************************************************************************
Function : OsSlabMemCheck
Description : check slab memory
Input : pool --- pointer to the memory pool
ptr --- pointer to the memory chunk
Output : None
Return : LOS_OK on success or error code on failure
**************************************************************************/
UINT32 OsSlabMemCheck(VOID *pool, VOID* ptr)
{
UINTPTR intSave;
struct LosSlabControlHeader *slabMem = OsSlabCtrlHdrGet(pool);
UINT32 retBlkSz = (UINT32)-1;
OsSlabMem *slabAlloc = NULL;
UINT32 idx;
OsSlabBlockNode *slabNode = OS_SLAB_BLOCK_HEAD_GET(ptr);
if ((!OS_ALLOC_FROM_SLAB_CHECK(slabNode)) ||
slabMem->slabClass[SLAB_MEM_COUNT - 1].blkSz > (OS_SLAB_BLOCK_SIZE_GET(slabNode))) {
return retBlkSz;
}
intSave = LOS_IntLock();
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
slabAlloc = &(slabMem->slabClass[idx]);
if (OsSlabAllocatorCheck(slabAlloc->alloc, slabNode) == TRUE) {
retBlkSz = slabMem->slabClass[idx].blkSz;
}
}
LOS_IntRestore(intSave);
return retBlkSz;
}
/**************************************************************************
Function : OsSlabStatisticsGet
Description : collect slab statistics
Input : pool --- pointer to the memory pool
Output : status --- memory pool statistics
Return : LOS_OK on success or error code on failure
**************************************************************************/
UINT32 OsSlabStatisticsGet(VOID *pool, LosSlabStatus *status)
{
struct LosSlabControlHeader *slabMem = NULL;
OsSlabMem *slabAlloc = NULL;
UINT32 itemSz = 0;
UINT32 itemCnt = 0;
UINT32 curUsage = 0;
UINT32 totalUsage = 0;
UINT32 totalMem = 0;
UINT32 totalAllocCount = 0;
UINT32 totalFreeCount = 0;
UINT32 idx;
if ((status == NULL) || (pool == NULL)) {
return LOS_NOK;
}
slabMem = OsSlabCtrlHdrGet(pool);
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
slabAlloc = &(slabMem->slabClass[idx]);
OsSlabAllocatorGetSlabInfo(slabAlloc->alloc, &itemSz, &itemCnt, &curUsage);
totalUsage += (curUsage * itemSz);
totalMem += (itemCnt * itemSz);
totalAllocCount += slabMem->slabClass[idx].blkUsedCnt;
totalFreeCount += slabMem->slabClass[idx].blkCnt - slabMem->slabClass[idx].blkUsedCnt;
}
if (totalMem < totalUsage) {
return LOS_NOK;
}
status->totalSize = totalMem;
status->usedSize = totalUsage;
status->freeSize = status->totalSize - status->usedSize;
status->allocCount = totalAllocCount;
status->freeCount = totalFreeCount;
return LOS_OK;
}
/**************************************************************************
Function : OsSlabGetMaxFreeBlkSize
Description : get max free block size
Input : pool --- pointer to the memory pool
Output : None
Return : max free block size
**************************************************************************/
UINT32 OsSlabGetMaxFreeBlkSize(VOID *pool)
{
struct LosSlabControlHeader *slabMem = OsSlabCtrlHdrGet(pool);
OsSlabMem *slabAlloc = NULL;
UINT32 itemSz = 0;
UINT32 itemCnt = 0;
UINT32 curUsage = 0;
int idx;
for (idx = SLAB_MEM_COUNT - 1; idx >= 0; idx--) {
slabAlloc = &(slabMem->slabClass[idx]);
if (slabAlloc->alloc) {
OsSlabAllocatorGetSlabInfo(slabAlloc->alloc, &itemSz, &itemCnt, &curUsage);
if (curUsage != itemCnt) {
return itemSz;
}
}
}
return 0;
}

View File

@ -1,261 +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.
*/
/**
* @defgroup kernel Kernel
* @defgroup los_base Basic definitions
* @ingroup kernel
*/
#ifndef _LOS_BASE_H
#define _LOS_BASE_H
#include "los_builddef.h"
#include "los_typedef.h"
#include "los_config.h"
#include "los_list.h"
#include "los_errno.h"
#include "los_compiler.h"
#include "los_hwi.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define SIZE(a) (a)
#define LOS_ASSERT_COND(expression)
/**
* @ingroup los_base
* Define the timeout interval as LOS_NO_WAIT.
*/
#define LOS_NO_WAIT 0
/**
* @ingroup los_base
* Define the timeout interval as LOS_WAIT_FOREVER.
*/
#define LOS_WAIT_FOREVER 0xFFFFFFFF
/**
* @ingroup los_base
* Align the beginning of the object with the base address addr,
* with boundary bytes being the smallest unit of alignment.
*/
#ifndef ALIGN
#define ALIGN(addr, boundary) LOS_Align(addr, boundary)
#endif
/**
* @ingroup los_base
* Align the tail of the object with the base address addr, with size bytes being the smallest unit of alignment.
*/
#define TRUNCATE(addr, size) ((addr) & ~((size)-1))
/**
* @ingroup los_base
* Read a UINT8 value from addr and stroed in value.
*/
#define READ_UINT8(value, addr) ((value) = *((volatile UINT8 *)(addr)))
/**
* @ingroup los_base
* Read a UINT16 value from addr and stroed in addr.
*/
#define READ_UINT16(value, addr) ((value) = *((volatile UINT16 *)(addr)))
/**
* @ingroup los_base
* Read a UINT32 value from addr and stroed in value.
*/
#define READ_UINT32(value, addr) ((value) = *((volatile UINT32 *)(addr)))
/**
* @ingroup los_base
* Read a UINT64 value from addr and stroed in value.
*/
#define READ_UINT64(value, addr) ((value) = *((volatile UINT64 *)(addr)))
/**
* @ingroup los_base
* Get a UINT8 value from addr.
*/
#define GET_UINT8(addr) (*((volatile UINT8 *)(addr)))
/**
* @ingroup los_base
* Get a UINT16 value from addr.
*/
#define GET_UINT16(addr) (*((volatile UINT16 *)(addr)))
/**
* @ingroup los_base
* Get a UINT32 value from addr.
*/
#define GET_UINT32(addr) (*((volatile UINT32 *)(addr)))
/**
* @ingroup los_base
* Get a UINT64 value from addr.
*/
#define GET_UINT64(addr) (*((volatile UINT64 *)(addr)))
/**
* @ingroup los_base
* Write a UINT8 value to addr.
*/
#define WRITE_UINT8(value, addr) (*((volatile UINT8 *)(addr)) = (value))
/**
* @ingroup los_base
* Write a UINT16 value to addr.
*/
#define WRITE_UINT16(value, addr) (*((volatile UINT16 *)(addr)) = (value))
/**
* @ingroup los_base
* Write a UINT32 value to addr.
*/
#define WRITE_UINT32(value, addr) (*((volatile UINT32 *)(addr)) = (value))
/**
* @ingroup los_base
* Write a UINT64 addr to addr.
*/
#define WRITE_UINT64(value, addr) (*((volatile UINT64 *)(addr)) = (value))
#if PRINT_LEVEL < LOS_ERR_LEVEL
#define LOS_ASSERT(judge)
#else
#define LOS_ASSERT(judge) \
do { \
if ((judge) == 0) { \
(VOID)LOS_IntLock(); \
PRINT_ERR("ASSERT ERROR! %s, %d, %s\n", __FILE__, __LINE__, __func__); \
while (1) { } \
} \
} while (0)
#endif
/**
* @ingroup los_base
* @brief Align the value (addr) by some bytes (boundary) you specify.
*
* @par Description:
* This API is used to align the value (addr) by some bytes (boundary) you specify.
*
* @attention
* <ul>
* <li>the value of boundary usually is 4,8,16,32.</li>
* </ul>
*
* @param addr [IN] The variable what you want to align.
* @param boundary [IN] The align size what you want to align.
*
* @retval #UINT32 The variable what have been aligned.
* @par Dependency:
* <ul><li>los_base.h: the header file that contains the API declaration.</li></ul>
* @see
*/
extern UINT32 LOS_Align(UINT32 addr, UINT32 boundary);
/**
* @ingroup los_base
* @brief Sleep the current task.
*
* @par Description:
* This API is used to delay the execution of the current task. The task is able to be scheduled
* after it is delayed for a specified number of Ticks.
*
* @attention
* <ul>
* <li>The task fails to be delayed if it is being delayed during interrupt processing or it is locked.</li>
* <li>If 0 is passed in and the task scheduling is not locked,
* execute the next task in the queue of tasks with the priority of the current task.
* If no ready task with the priority of the current task is available,
* the task scheduling will not occur, and the current task continues to be executed.</li>
* <li>The parameter passed in can not be equal to LOS_WAIT_FOREVER(0xFFFFFFFF).
* If that happens, the task will not sleep 0xFFFFFFFF milliseconds or sleep forever but sleep 0xFFFFFFFF Ticks.</li>
* </ul>
*
* @param mSecs [IN] Type #UINT32 Number of MS for which the task is delayed.
*
* @retval None
* @par Dependency:
* <ul><li>los_base.h: the header file that contains the API declaration.</li></ul>
* @see None
*/
extern VOID LOS_Msleep(UINT32 mSecs);
/**
* @ingroup los_base
* @brief System kernel initialization function.
*
* @par Description:
* This API is used to start liteOS .
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param: None.
*
* @retval #LOS_OK 0:LiteOS start success.
*
* @par Dependency:
* <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
* @see
*/
extern UINT32 LOS_Start(VOID);
/**
* @ingroup los_base
* @brief System kernel initialization function.
*
* @par Description:
* This API is used to Initialize kernel ,configure all system modules.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param: None.
*
* @retval #LOS_OK 0:System kernel initialization success.
*
* @par Dependency:
* <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
* @see
*/
extern UINT32 LOS_KernelInit(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_BASE_H */

View File

@ -1,205 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: 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.
* ---------------------------------------------------------------------------
* Notice of Export Control Law
* ===============================================
* Huawei LiteOS may be subject to applicable export control laws and regulations, which might
* include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
* Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
* applicable export control laws and regulations.
*/
/**@defgroup los_builddef
* @ingroup kernel
*/
#ifndef _LOS_BUILDEF_H
#define _LOS_BUILDEF_H
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cpluscplus */
#endif /* __cpluscplus */
/**
* @ingroup los_builddef
* Define inline keyword
*/
#ifndef INLINE
#define INLINE static inline
#endif
/**
* @ingroup los_builddef
* Little endian
*/
#define OS_LITTLE_ENDIAN 0x1234
/**
* @ingroup los_builddef
* Big endian
*/
#define OS_BIG_ENDIAN 0x4321
/**
* @ingroup los_builddef
* Byte order
*/
#ifndef OS_BYTE_ORDER
#define OS_BYTE_ORDER OS_LITTLE_ENDIAN
#endif
/* Define OS code data sections */
/* The indicator function is inline */
/**
* @ingroup los_builddef
* Allow inline sections
*/
#ifndef LITE_OS_SEC_ALW_INLINE
#define LITE_OS_SEC_ALW_INLINE //__attribute__((always_inline))
#endif
/**
* @ingroup los_builddef
* Vector table section
*/
#ifndef LITE_OS_SEC_VEC
#define LITE_OS_SEC_VEC __attribute__ ((section(".vector")))
#endif
/**
* @ingroup los_builddef
* .Text section (Code section)
*/
#ifndef LITE_OS_SEC_TEXT
#define LITE_OS_SEC_TEXT //__attribute__((section(".sram.text")))
#endif
/**
* @ingroup los_builddef
* .Text.ddr section
*/
#ifndef LITE_OS_SEC_TEXT_MINOR
#define LITE_OS_SEC_TEXT_MINOR // __attribute__((section(".dyn.text")))
#endif
/**
* @ingroup los_builddef
* .Text.init section
*/
#ifndef LITE_OS_SEC_TEXT_INIT
#define LITE_OS_SEC_TEXT_INIT //__attribute__((section(".dyn.text")))
#endif
/**
* @ingroup los_builddef
* .Data section
*/
#ifndef LITE_OS_SEC_DATA
#define LITE_OS_SEC_DATA //__attribute__((section(".dyn.data")))
#endif
/**
* @ingroup los_builddef
* .Data.init section
*/
#ifndef LITE_OS_SEC_DATA_INIT
#define LITE_OS_SEC_DATA_INIT //__attribute__((section(".dyn.data")))
#endif
/**
* @ingroup los_builddef
* Not initialized variable section
*/
#ifndef LITE_OS_SEC_BSS
#define LITE_OS_SEC_BSS //__attribute__((section(".sym.bss")))
#endif
/**
* @ingroup los_builddef
* .bss.ddr section
*/
#ifndef LITE_OS_SEC_BSS_MINOR
#define LITE_OS_SEC_BSS_MINOR
#endif
/**
* @ingroup los_builddef
* .bss.init sections
*/
#ifndef LITE_OS_SEC_BSS_INIT
#define LITE_OS_SEC_BSS_INIT
#endif
#ifndef LITE_OS_SEC_TEXT_DATA
#define LITE_OS_SEC_TEXT_DATA //__attribute__((section(".dyn.data")))
#define LITE_OS_SEC_TEXT_BSS //__attribute__((section(".dyn.bss")))
#define LITE_OS_SEC_TEXT_RODATA //__attribute__((section(".dyn.rodata")))
#endif
#ifndef LITE_OS_SEC_SYMDATA
#define LITE_OS_SEC_SYMDATA //__attribute__((section(".sym.data")))
#endif
#ifndef LITE_OS_SEC_SYMBSS
#define LITE_OS_SEC_SYMBSS //__attribute__((section(".sym.bss")))
#endif
#ifndef LITE_OS_SEC_KEEP_DATA_DDR
#define LITE_OS_SEC_KEEP_DATA_DDR //__attribute__((section(".keep.data.ddr")))
#endif
#ifndef LITE_OS_SEC_KEEP_TEXT_DDR
#define LITE_OS_SEC_KEEP_TEXT_DDR //__attribute__((section(".keep.text.ddr")))
#endif
#ifndef LITE_OS_SEC_KEEP_DATA_SRAM
#define LITE_OS_SEC_KEEP_DATA_SRAM //__attribute__((section(".keep.data.sram")))
#endif
#ifndef LITE_OS_SEC_KEEP_TEXT_SRAM
#define LITE_OS_SEC_KEEP_TEXT_SRAM //__attribute__((section(".keep.text.sram")))
#endif
#ifndef LITE_OS_SEC_BSS_MINOR
#define LITE_OS_SEC_BSS_MINOR
#endif
#ifndef INCLUDE_pxTaskGetStackStart
#define INCLUDE_pxTaskGetStackStart 0
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#endif /* _LOS_BUILDEF_H */

View File

@ -1,143 +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.
*/
#ifndef _LOS_COMPILER_H
#define _LOS_COMPILER_H
/* for IAR Compiler */
#ifdef __ICCARM__
#include"iccarm_builtin.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* for IAR Compiler */
#ifdef __ICCARM__
#ifndef ASM
#define ASM __asm
#endif
#ifndef INLINE
#define INLINE inline
#endif
#ifndef STATIC_INLINE
#define STATIC_INLINE static inline
#endif
#ifndef USED
#define USED __root
#endif
#ifndef WEAK
#define WEAK __weak
#endif
#ifndef CLZ
#define CLZ __iar_builtin_CLZ
#endif
/* for ARM Compiler */
#elif defined(__CC_ARM)
#ifndef ASM
#define ASM __asm
#endif
#ifndef INLINE
#define INLINE __inline
#endif
#ifndef STATIC_INLINE
#define STATIC_INLINE static __inline
#endif
#ifndef USED
#define USED __attribute__((used))
#endif
#ifndef WEAK
#define WEAK __attribute__((weak))
#endif
#ifndef CLZ
#define CLZ __clz
#endif
#pragma anon_unions
/* for GNU Compiler */
#elif defined(__GNUC__)
#ifndef ASM
#define ASM __asm
#endif
#ifndef INLINE
#define INLINE inline
#endif
#ifndef STATIC
#define STATIC static
#endif
#ifndef STATIC_INLINE
#define STATIC_INLINE static inline
#endif
#ifndef USED
#define USED __attribute__((used))
#endif
#ifndef WEAK
#define WEAK __attribute__((weak))
#endif
#ifndef CLZ
#define CLZ __builtin_clz
#endif
#else
#error Unknown compiler.
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_COMPILER_H */

View File

@ -37,7 +37,6 @@
#ifndef _LOS_CONFIG_H
#define _LOS_CONFIG_H
#include "los_typedef.h"
#include "target_config.h"
#ifdef __cplusplus
@ -442,7 +441,7 @@ extern UINT32 g_sysMemAddrEnd;
* Configuration module tailoring of more mempry pool checking
*/
#ifndef LOSCFG_MEM_MUL_POOL
#define LOSCFG_MEM_MUL_POOL NO
#define LOSCFG_MEM_MUL_POOL YES
#endif
/**

View File

@ -1,308 +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.
*/
/**
* @defgroup los_cpup CPU usage
* @ingroup kernel
*/
#ifndef _LOS_CPUP_H
#define _LOS_CPUP_H
#include "los_hwi.h"
#include "los_base.h"
#include "los_sys.h"
#include "los_task.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_cpup
* CPU usage error code: The request for memory fails.
*
* Value: 0x02001e00
*
* Solution: Decrease the maximum number of tasks.
*/
#define LOS_ERRNO_CPUP_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x00)
/**
* @ingroup los_cpup
* CPU usage error code: The pointer to an input parameter is NULL.
*
* Value: 0x02001e01
*
* Solution: Check whether the pointer to the input parameter is usable.
*/
#define LOS_ERRNO_CPUP_TASK_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x01)
/**
* @ingroup los_cpup
* CPU usage error code: The CPU usage is not initialized.
*
* Value: 0x02001e02
*
* Solution: Check whether the CPU usage is initialized.
*/
#define LOS_ERRNO_CPUP_NO_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x02)
/**
* @ingroup los_cpup
* CPU usage error code: The number of threads is invalid.
*
* Value: 0x02001e03
*
* Solution: Check whether the number of threads is applicable for the current operation.
*/
#define LOS_ERRNO_CPUP_MAXNUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x03)
/**
* @ingroup los_cpup
* CPU usage error code: The target thread is not created.
*
* Value: 0x02001e04
*
* Solution: Check whether the target thread is created.
*/
#define LOS_ERRNO_CPUP_THREAD_NO_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x04)
/**
* @ingroup los_cpup
* CPU usage error code: The target task ID is invalid.
*
* Value: 0x02001e05
*
* Solution: Check whether the target task ID is applicable for the current operation.
*/
#define LOS_ERRNO_CPUP_TSK_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x05)
/**
* @ingroup los_cpup
* Sum of cpup with all tasks. It means the value of cpup is a permillage.
*/
#define LOS_CPUP_PRECISION 1000
/**
* @ingroup los_cpup
* Multiple of current cpup precision change to percent.
*/
#define LOS_CPUP_PRECISION_MULT (LOS_CPUP_PRECISION / 100)
/**
* @ingroup los_cpup
* Count the CPU usage structures of all tasks.
*/
typedef struct tagCpupInfo {
UINT16 usStatus; /**< save the cur task status */
UINT32 uwUsage; /**< Usage. The value range is [0,1000]. */
} CPUP_INFO_S;
/**
* @ingroup los_monitor
* Type of the CPU usage query.
*/
typedef enum {
SYS_CPU_USAGE = 0, /* system cpu occupancy rate */
TASK_CPU_USAGE, /* task cpu occupancy rate */
} CPUP_TYPE_E;
/**
* @ingroup los_monitor
* Mode of the CPU usage query.
*/
typedef enum {
CPUP_IN_10S = 0, /* cpu occupancy rate in 10s */
CPUP_IN_1S, /* cpu occupancy rate in 1s */
CPUP_LESS_THAN_1S, /* cpu occupancy rate less than 1s, if the input mode is none of them, it will be this. */
} CPUP_MODE_E;
/**
* @ingroup los_cpup
* @brief Obtain the current CPU usage.
*
* @par Description:
* This API is used to obtain the current CPU usage.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, error codes will be returned.</li>
* <li> The precision of the CPU usage can be adjusted by changing the value of the CPUP_PRECISION macro.</li>
* </ul>
*
* @param None.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #cpup [0,100], current CPU usage, of which the precision is adjustable.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_SysCpuUsage
*/
extern UINT32 LOS_SysCpuUsage(VOID);
/**
* @ingroup los_cpup
* @brief Obtain the historical CPU usage.
*
* @par Description:
* This API is used to obtain the historical CPU usage.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
* </ul>
*
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s will be
* obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained. Other values
* indicate that the CPU usage in the period that is less than 1s will be obtained.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #cpup [0,100], historical CPU usage, of which the precision is adjustable.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HistoryTaskCpuUsage
*/
extern UINT32 LOS_HistorySysCpuUsage(UINT16 mode);
/**
* @ingroup los_cpup
* @brief Obtain the CPU usage of a specified task.
*
* @par Description:
* This API is used to obtain the CPU usage of a task specified by a passed-in task ID.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
* <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
* the CPU usage fails to be obtained.</li>
* </ul>
*
* @param taskID [IN] UINT32. Task ID.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
* @retval #cpup [0,100], CPU usage of the specified task.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HistoryTaskCpuUsage
*/
extern UINT32 LOS_TaskCpuUsage(UINT32 taskID);
/**
* @ingroup los_cpup
* @brief Obtain the historical CPU usage of a specified task.
*
* @par Description:
* This API is used to obtain the historical CPU usage of a task specified by a passed-in task ID.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise,
* the CPU usage fails to be obtained.</li>
* <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
* the CPU usage fails to be obtained.</li>
* </ul>
*
* @param taskID [IN] UINT32. Task ID.
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
* will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
* Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
* @retval #cpup [0,100], CPU usage of the specified task.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HistorySysCpuUsage
*/
extern UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode);
/**
* @ingroup los_cpup
* @brief Obtain the CPU usage of all tasks.
*
* @par Description:
* This API is used to obtain the CPU usage of all tasks according to maximum number of threads.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
* <li>The input parameter pointer must not be NULL, Otherwise, the CPU usage fails to be obtained.</li>
* </ul>
*
* @param cpupInfo [OUT]Type. CPUP_INFO_S* Pointer to the task CPUP information structure to be obtained.
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
* will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
* Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
*
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
* @retval #OS_ERRNO_CPUP_TASK_PTR_NULL 0x02001e01: The input parameter pointer is NULL.
* @retval #LOS_OK 0x00000000: The CPU usage of all tasks is successfully obtained.
* @par Dependency:
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
* @see LOS_SysCpuUsage
*/
extern UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 mode);
/**
* @ingroup los_monitor
* @brief Obtain CPU usage history of certain task.
*
* @par Description:
* This API is used to obtain CPU usage history of certain task.
* @attention
* <ul>
* <li>This API can be called only after the CPU usage is initialized. Otherwise, -1 will be returned.</li>
* <li> Only in SYS_CPU_USAGE type, uwTaskID is invalid.</li>
* </ul>
*
* @param type [IN] cpup type, SYS_CPU_USAGE and TASK_CPU_USAGE
* @param mode [IN] mode,CPUP_IN_10S = usage in 10s,CPUP_IN_1S = usage in last 1s,
* CPUP_LESS_THAN_1S = less than 1s, if the inpuit mode is none of them, it will be as CPUP_LESS_THAN_1S.
* @param taskID [IN] task ID, Only in SYS_CPU_USAGE type, taskID is invalid
*
* @retval #OS_ERROR -1:CPU usage info obtain failed.
* @retval #LOS_OK 0:CPU usage info is successfully obtained.
* @par Dependency:
* <ul><li>los_monitor.h: the header file that contains the API declaration.</li></ul>
* @see LOS_CpupUsageMonitor
*/
extern UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E mode, UINT32 taskID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_CPUP_H */

View File

@ -1,115 +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.
*/
/**
* @defgroup los_errno Error code
* @ingroup kernel
*/
#ifndef _LOS_ERRNO_H
#define _LOS_ERRNO_H
#include "los_typedef.h"
#include "los_err.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_errno
* OS error code flag.
*/
#define LOS_ERRNO_OS_ID ((UINT32)0x00 << 16)
/**
* @ingroup los_errno
* Define the error level as informative.
*/
#define LOS_ERRTYPE_NORMAL ((UINT32)0x00 << 24)
/**
* @ingroup los_errno
* Define the error level as warning.
*/
#define LOS_ERRTYPE_WARN ((UINT32)0x01 << 24)
/**
* @ingroup los_errno
* Define the error level as critical.
*/
#define LOS_ERRTYPE_ERROR ((UINT32)0x02 << 24)
/**
* @ingroup los_errno
* Define the error level as fatal.
*/
#define LOS_ERRTYPE_FATAL ((UINT32)0x03 << 24)
/**
* @ingroup los_errno
* Define fatal OS errors.
*/
#define LOS_ERRNO_OS_FATAL(moduleID, errno) \
(LOS_ERRTYPE_FATAL | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
/**
* @ingroup los_errno
* Define critical OS errors.
*/
#define LOS_ERRNO_OS_ERROR(moduleID, errno) \
(LOS_ERRTYPE_ERROR | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
/**
* @ingroup los_errno
* Define warning OS errors.
*/
#define LOS_ERRNO_OS_WARN(moduleID, errno) \
(LOS_ERRTYPE_WARN | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
/**
* @ingroup los_errno
* Define informative OS errors.
*/
#define LOS_ERRNO_OS_NORMAL(moduleID, errno) \
(LOS_ERRTYPE_NORMAL | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ERRNO_H */

View File

@ -37,7 +37,6 @@
#ifndef _LOS_EVENT_H
#define _LOS_EVENT_H
#include "los_base.h"
#include "los_list.h"
#ifdef __cplusplus
@ -321,6 +320,9 @@ extern UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events);
*/
extern UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB);
extern UINT32 OsEventReadOnce(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeOut);
extern UINT32 OsEventWriteOnce(PEVENT_CB_S eventCB, UINT32 events);
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -1,232 +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.
*/
/**
* @defgroup los_heap Heap
* @ingroup kernel
*/
#ifndef _LOS_HEAP_H
#define _LOS_HEAP_H
#include <los_typedef.h>
#include "los_base.h"
#if (LOSCFG_KERNEL_MEM_SLAB == YES)
#include "los_slab.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define IS_ALIGNED(value) ((((UINT32)(value)) & ((UINT32)((value) - 1))) == 0)
#define OS_MEM_ALIGN(value, align) (((UINT32)(UINTPTR)(value) + (UINT32)((align) - 1)) & \
(~(UINT32)((align) - 1)))
#define OS_MEM_ALIGN_FLAG 0x80000000
#define OS_MEM_SET_ALIGN_FLAG(align) ((align) = ((align) | OS_MEM_ALIGN_FLAG))
#define OS_MEM_GET_ALIGN_FLAG(align) ((align) & OS_MEM_ALIGN_FLAG)
#define OS_MEM_GET_ALIGN_GAPSIZE(align) ((align) & (~OS_MEM_ALIGN_FLAG))
#define RAM_HEAP_SIZE ((OS_SYS_MEM_SIZE) & (~7))
#define RAM_HEAP_START (OS_SYS_MEM_ADDR)
#ifdef CONFIG_DDR_HEAP
#define DDR_HEAP_INIT() LOS_HeapInit((VOID *)DDR_HEAP_START, DDR_HEAP_SIZE)
#define DDR_HEAP_ALLOC(sz) LOS_HeapAllocAlign((VOID *)DDR_HEAP_START, \
OS_MEM_ALIGN(sz, DCACHE_LINE_SIZE), DCACHE_LINE_SIZE)
#define DDR_HEAP_FREE(p) LOS_HeapFree((VOID *)DDR_HEAP_START, p)
#endif
/* extra 2 blocks is for idle and extra temparary task */
#define TASK_BLOCK_NUM (LOSCFG_BASE_CORE_TSK_LIMIT + 2)
#if (LOSCFG_KERNEL_MEM_STATISTICS == YES)
#define TASKID_BITS 7
/* 2 bits for used and align flag, 30 bits left */
#define SIZE_BITS (30 - TASKID_BITS)
#if (SIZE_BITS <= 0)
#error task id bits too big!
#endif
#if (TASK_BLOCK_NUM > ((1 << TASKID_BITS) - 1))
#error task id bits too small!
#endif
#endif
struct LOS_HEAP_NODE {
struct LOS_HEAP_NODE* pstPrev;
#if (LOSCFG_KERNEL_MEM_STATISTICS == YES)
UINT32 uwSize : SIZE_BITS;
UINT32 taskID : TASKID_BITS;
#else
UINT32 uwSize : 30;
#endif
UINT32 uwUsed : 1;
UINT32 uwAlign : 1;
UINT8 ucData[0]; /*lint !e43*/
};
/**
* @ingroup los_heap
* @brief Initialization heap memory.
*
* @par Description:
* This API is used to initialization heap memory.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param pool [IN/OUT] A pointer pointed to the memory pool.
* @param size [IN] Size of heap memory.
*
* @retval TRUE Initialization success.
* @retval FALSE Initialization failed.
* @par Dependency:
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern BOOL LOS_HeapInit(VOID *pool, UINT32 size);
/**
* @ingroup los_heap
* @brief Alloc memory block from heap memory.
*
* @par Description:
* This API is used to alloc memory block from heap memory.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param pool [IN/OUT] A pointer pointed to the memory pool.
* @param size [IN] Size of heap memory.
*
* @retval VOID*
* @par Dependency:
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HeapFree
*/
extern VOID* LOS_HeapAlloc(VOID *pool, UINT32 size);
/**
* @ingroup los_heap
* @brief Alloc aligned memory block from heap memory.
*
* @par Description:
* This API is used to alloc aligned memory block from heap memory.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param pool [IN/OUT] A pointer pointed to the memory pool.
* @param size [IN] Size of heap memory.
* @param boundary [IN] Boundary the heap needs align
*
* @retval VOID*
* @par Dependency:
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HeapFree
*/
extern VOID* LOS_HeapAllocAlign(VOID *pool, UINT32 size, UINT32 boundary);
/**
* @ingroup los_heap
* @brief Free memory block from heap memory.
*
* @par Description:
* This API is used to free memory block from heap memory.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param pool [IN/OUT] A pointer pointed to the memory pool.
* @param ptr [IN] Point to be freed.
*
* @retval BOOL TRUE free success FALSE free failed
* @par Dependency:
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
* @see LOS_HeapAlloc
*/
extern BOOL LOS_HeapFree(VOID *pool, VOID* ptr);
/**
* @ingroup los_memory
* @brief Get the memory info from Heap.
*
* @par Description:
* This API is used to get the memory info from Heap.
* @attention
* <ul>
* <li>None.</li>
* </ul>
* @param None.
*
* @retval UINT32 Max size of heap memory being used.
*
* @par Dependency:
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
#if (LOSCFG_HEAP_MEMORY_PEAK_STATISTICS == YES)
extern UINT32 LOS_HeapGetHeapMemoryPeak(VOID);
#endif
/**
* @ingroup los_memory
* @brief Get the memory statistics from Heap.
*
* @par Description:
* This API is used to get the memory statistics from Heap.
* @attention
* <ul>
* <li>None.</li>
* </ul>
* @param None.
*
* @retval None.
*
* @par Dependency:
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
#if (LOSCFG_KERNEL_MEM_STATISTICS == YES)
VOID LOS_HeapDumpMemoryStats(VOID *pool);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -32,9 +32,8 @@
#ifndef _LOS_MEMBOX_H
#define _LOS_MEMBOX_H
#include "los_config.h"
#if (LOSCFG_PLATFORM_EXC == YES)
#include "los_memcheck.h"
#include "los_memory.h"
#endif
#define BOX_ALIGN_8 0x80000000
@ -198,4 +197,18 @@ extern VOID LOS_MemboxClr(const VOID *boxMem, VOID *box);
*/
extern UINT32 LOS_MemboxStatisticsGet(const VOID *boxMem, UINT32 *maxBlk, UINT32 *blkCnt, UINT32 *blkSize);
#define OS_MEMBOX_NEXT(addr, blkSize) (LOS_MEMBOX_NODE *)((UINT8 *)(addr) + (blkSize))
#ifdef LOS_MEMBOX_CHECK
#define OS_MEMBOX_MAGIC 0xa55a5aa5
#define OS_MEMBOX_SET_MAGIC(addr) (*((UINT32 *)(addr)) = OS_MEMBOX_MAGIC)
#define OS_MEMBOX_CHECK_MAGIC(addr) ((*((UINT32 *)(addr)) == OS_MEMBOX_MAGIC) ? LOS_OK : LOS_NOK)
#else
#define OS_MEMBOX_SET_MAGIC(addr)
#define OS_MEMBOX_CHECK_MAGIC(addr) LOS_OK
#endif
#define OS_MEMBOX_USER_ADDR(addr) ((VOID *)((UINT8 *)(addr) + LOS_MEMBOX_MAGIC_SIZE))
#define OS_MEMBOX_NODE_ADDR(addr) ((LOS_MEMBOX_NODE *)((UINT8 *)(addr) - LOS_MEMBOX_MAGIC_SIZE))
#endif

View File

@ -1,116 +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.
*/
#ifndef _LOS_MEMCHECK_H
#define _LOS_MEMCHECK_H
#include "los_base.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#define MEM_INFO_SIZE ((sizeof(MEM_INFO) * OS_SYS_MEM_NUM) + 4)
extern UINT8 g_memMang[];
enum _MEM_MANG_TYPE {
MEM_MANG_MEMBOX,
MEM_MANG_MEMORY,
MEM_MANG_EMPTY,
};
enum _MEM_MANG_SOUCE {
MEM_MANG_UNUSED,
MEM_MANG_INIT,
MEM_MANG_INT,
MEM_MANG_TASK,
};
typedef struct _MEM_INFO {
UINT32 uwType;
UINT32 uwStartAddr;
UINT32 uwSize;
VOID * blkAddrArray;
}MEM_INFO;
typedef struct _SLAB_INFO {
UINT32 item_sz;
UINT32 item_cnt;
UINT32 cur_usage;
}SLAB_INFO;
#define SLAB_CLASS_NUM (4U)
typedef struct _MEM_INFO_S {
UINT32 uwType;
UINT32 uwStartAddr;
UINT32 uwSize;
UINT32 uwFree;
UINT32 uwBlockSize;
UINT32 uwErrorAddr;
UINT32 uwErrorLen;
UINT32 uwErrorOwner;
SLAB_INFO stSlabInfo[SLAB_CLASS_NUM];
}MEM_INFO_S;
/**
* @ingroup los_memboxcheck
* @brief Get the information of the exc memory.
*
* @par Description:
* <ul>
* <li>This API is used to get the information of the exc memory.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param memNum [IN] Type #UINT32 Memory pool number.
* @param memExcInfo [IN/OUT] Type #MEM_INFO_S * information of the exc memory.
*
* @retval UINT32 Get information result.
* @par Dependency:
* <ul>
* <li>los_memboxcheck.h: the header file that contains the API declaration.</li>
* </ul>
* @see None.
*/
UINT32 LOS_MemExcInfoGet(UINT32 memNum, MEM_INFO_S *memExcInfo);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#endif /* _LOS_MEMCHECK_H */

View File

@ -31,11 +31,9 @@
#ifndef _LOS_MEMORY_H
#define _LOS_MEMORY_H
#include "los_base.h"
#if (LOSCFG_KERNEL_MEM_SLAB == YES)
#include <los_slab.h>
#endif
#include <los_heap.h>
#include "los_config.h"
#include "los_list.h"
#ifdef __cplusplus
#if __cplusplus
@ -43,15 +41,13 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct __s_LOS_MEM_STATUS {
UINT32 totalSize;
UINT32 usedSize;
UINT32 freeSize;
UINT32 allocCount;
UINT32 freeCount;
} LOS_MEM_STATUS;
#if (LOSCFG_MEMORY_BESTFIT == YES)
#define IS_ALIGNED(value) ((((UINT32)(value)) & ((UINT32)((value) - 1))) == 0)
#define OS_MEM_ALIGN(value, align) (((UINT32)(UINTPTR)(value) + (UINT32)((align) - 1)) & \
(~(UINT32)((align) - 1)))
#define OS_MEM_ALIGN_FLAG 0x80000000
#define OS_MEM_SET_ALIGN_FLAG(align) ((align) = ((align) | OS_MEM_ALIGN_FLAG))
#define OS_MEM_GET_ALIGN_FLAG(align) ((align) & OS_MEM_ALIGN_FLAG)
#define OS_MEM_GET_ALIGN_GAPSIZE(align) ((align) & (~OS_MEM_ALIGN_FLAG))
/**
* @ingroup los_memory
@ -64,11 +60,93 @@ typedef struct {
UINT32 uwPoolWaterLine; /**< Maximum usage size in a memory pool */
UINT32 uwPoolCurUsedSize; /**< Current usage size in a memory pool */
#endif
#ifdef LOSCFG_MEM_MUL_POOL
//#ifdef LOSCFG_MEM_MUL_POOL
VOID *pNextPool;
#endif
//#endif
} LOS_MEM_POOL_INFO;
typedef struct __s_LOS_MEM_STATUS {
UINT32 totalSize;
UINT32 usedSize;
UINT32 freeSize;
UINT32 allocCount;
UINT32 freeCount;
} LOS_MEM_STATUS;
#define MEM_INFO_SIZE ((sizeof(MEM_INFO) * OS_SYS_MEM_NUM) + 4)
extern UINT8 g_memMang[];
enum _MEM_MANG_TYPE {
MEM_MANG_MEMBOX,
MEM_MANG_MEMORY,
MEM_MANG_EMPTY,
};
enum _MEM_MANG_SOUCE {
MEM_MANG_UNUSED,
MEM_MANG_INIT,
MEM_MANG_INT,
MEM_MANG_TASK,
};
typedef struct _MEM_INFO {
UINT32 uwType;
UINT32 uwStartAddr;
UINT32 uwSize;
VOID * blkAddrArray;
}MEM_INFO;
typedef struct _SLAB_INFO {
UINT32 item_sz;
UINT32 item_cnt;
UINT32 cur_usage;
}SLAB_INFO;
#define SLAB_CLASS_NUM (4U)
typedef struct _MEM_INFO_S {
UINT32 uwType;
UINT32 uwStartAddr;
UINT32 uwSize;
UINT32 uwFree;
UINT32 uwBlockSize;
UINT32 uwErrorAddr;
UINT32 uwErrorLen;
UINT32 uwErrorOwner;
SLAB_INFO stSlabInfo[SLAB_CLASS_NUM];
}MEM_INFO_S;
/**
* @ingroup los_memboxcheck
* @brief Get the information of the exc memory.
*
* @par Description:
* <ul>
* <li>This API is used to get the information of the exc memory.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param memNum [IN] Type #UINT32 Memory pool number.
* @param memExcInfo [IN/OUT] Type #MEM_INFO_S * information of the exc memory.
*
* @retval UINT32 Get information result.
* @par Dependency:
* <ul>
* <li>los_memboxcheck.h: the header file that contains the API declaration.</li>
* </ul>
* @see None.
*/
UINT32 LOS_MemExcInfoGet(UINT32 memNum, MEM_INFO_S *memExcInfo);
//#if (LOSCFG_MEMORY_BESTFIT == YES)
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == YES)
extern UINT8 g_memMang[];
#endif
@ -82,6 +160,7 @@ extern UINT8 g_memMang[];
#ifdef LOSCFG_MEM_MUL_POOL
extern VOID *g_memPoolHead;
#endif
typedef VOID (*MALLOC_HOOK)(VOID);
extern MALLOC_HOOK g_mallocHook;
@ -364,7 +443,6 @@ extern UINT8 LOS_MemCheckLevelGet(VOID);
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
*/
extern UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_STATUS *status);
#else
/**
* @ingroup los_memory
@ -412,7 +490,7 @@ extern UINT32 LOS_MemStatisticsGet(VOID *pool, LOS_MEM_STATUS *status);
* @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemFree
*/
extern UINT32 LOS_MemGetMaxFreeBlkSize(VOID *pool);
#endif
//#endif
/**
* @ingroup los_memory
@ -601,6 +679,225 @@ extern UINT32 LOS_MemDeInit(const VOID *pool);
extern UINT32 LOS_MemPoolList(VOID);
#endif
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == YES)
/**
* @ingroup los_memboxcheck
* @brief Update the information of the memory.
*
* @par Description:
* <ul>
* <li>This API is used to update the information of the memory.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param pool [IN/OUT] Type #VOID * Memory pool number.
* @param size [IN] Type #UINT32 Memory size.
* @param type [IN] Type #UINT32 Memory mang type.
*
* @retval UINT32 Updateinformation result.
* @par Dependency:
* <ul>
* <li>los_memboxcheck_pri.h: the header file that contains the API declaration.</li>
* </ul>
* @see None.
*/
UINT32 OsMemInfoUpdate(VOID *pool, UINT32 size, UINT32 type);
#endif
#define OS_MEM_ENABLE_MEM_STATISTICS
/*
* memcheck error code: the stack have not inited
* Value: 0x02000100
* Solution: do memcheck must after stack mem init
*/
#define OS_ERRNO_MEMCHECK_NOT_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x0)
/*
* memcheck error code: the pPtr is NULL
* Value: 0x02000101
* Solution: don't give a NULL parameter
*/
#define OS_ERRNO_MEMCHECK_PARA_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x1)
/*
* memcheck error code: the pPtr addr not in the suit range
* Value: 0x02000102
* Solution: check pPtr and comfirm it included by stack
*/
#define OS_ERRNO_MEMCHECK_OUTSIDE LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x2)
/*
* memcheck error code: can't find the ctrl node
* Value: 0x02000103
* Solution: confirm the pPtr if this node has been freed or has not been alloced
*/
#define OS_ERRNO_MEMCHECK_NO_HEAD LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x3)
/*
* memcheck error code: the para level is wrong
* Value: 0x02000104
* Solution: checkout the memcheck level by the func "OS_GetMemCheck_Level"
*/
#define OS_ERRNO_MEMCHECK_WRONG_LEVEL LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x4)
/*
* memcheck error code: memcheck func not open
* Value: 0x02000105
* Solution: enable memcheck by the func "OS_SetMemCheck_Level"
*/
#define OS_ERRNO_MEMCHECK_DISABLED LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x5)
/**
* @ingroup los_memory
* @brief Initialization the memory system.
*
* @par Description:
* <ul>
* <li>This API is used to initialization the memory system.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval UINT32 Initialization result.
* @par Dependency:
* <ul><li>los_memory_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsMemSystemInit(VOID);
/**
* @ingroup los_memory
* Memory linked list node structure
*/
typedef struct tagLosMemDynNode {
LOS_DL_LIST freeNodeInfo; /**< Free memory node */
struct tagLosMemDynNode *preNode; /**< Pointer to the previous memory node */
UINT32 sizeAndFlag; /**< Size and flag of the current node(the highest bit
represents a flag, and the rest bits specify the size) */
} LosMemDynNode;
#define OS_MEM_TASKID_SET(node, ID) \
do { \
UINTPTR tmp = (UINTPTR)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext); \
tmp = tmp & 0xffff0000; \
tmp |= (ID); \
((LosMemDynNode *)(node))->freeNodeInfo.pstNext = (LOS_DL_LIST *)(tmp); \
} while (0)
#define OS_MEM_TASKID_GET(node) ((UINT32)(UINTPTR)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext) & 0xffff)
#define OS_MEM_MODID_SET(node, ID) \
do { \
UINTPTR tmp = (UINTPTR)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext); \
tmp = tmp & 0xffff; \
tmp |= (ID) << 16; \
((LosMemDynNode *)(node))->freeNodeInfo.pstNext = (LOS_DL_LIST *)(tmp); \
} while (0)
#define OS_MEM_MODID_GET(node) ((UINT32)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext) >> 16)
#define OS_MEM_NODE_HEAD_SIZE sizeof(LosMemDynNode)
#define OS_MEM_MIN_POOL_SIZE (OS_DLNK_HEAD_SIZE + (2 * OS_MEM_NODE_HEAD_SIZE) + sizeof(LOS_MEM_POOL_INFO))
#define OS_MEM_ALIGN_SIZE 4
#define OS_MEM_NODE_USED_FLAG 0x80000000
#define OS_MEM_NODE_ALIGNED_FLAG 0x40000000
#define OS_MEM_NODE_ALIGN_SIZE 64
#define OS_MEM_NODE_NUM 2
#define OS_MEM_NODE_DATA_SIZE 4
#define OS_MEM_NODE_COUNT_NUM 8
#define OS_MULTI_DLNK_SIZE (OS_MAX_MULTI_DLNK_LOG2 - OS_MIN_MULTI_DLNK_LOG2)
#define OS_MEM_NODE_GET_ALIGNED_FLAG(sizeAndFlag) ((sizeAndFlag) & OS_MEM_NODE_ALIGNED_FLAG)
#define OS_MEM_NODE_SET_ALIGNED_FLAG(sizeAndFlag) ((sizeAndFlag) = ((sizeAndFlag) | OS_MEM_NODE_ALIGNED_FLAG))
#define OS_MEM_NODE_GET_ALIGNED_GAPSIZE(sizeAndFlag) ((sizeAndFlag) & (~OS_MEM_NODE_ALIGNED_FLAG))
#define OS_MEM_NODE_GET_USED_FLAG(sizeAndFlag) ((sizeAndFlag) & OS_MEM_NODE_USED_FLAG)
#define OS_MEM_NODE_SET_USED_FLAG(sizeAndFlag) ((sizeAndFlag) = ((sizeAndFlag) | OS_MEM_NODE_USED_FLAG))
#define OS_MEM_NODE_GET_SIZE(sizeAndFlag) ((sizeAndFlag) & (~OS_MEM_NODE_USED_FLAG))
#define OS_MEM_IS_NODE_NEXT_EXIST(node, poolInfo) (((UINT32)(node) + (node)->sizeAndFlag) < \
((UINT32)(poolInfo) + (poolInfo)->uwPoolSize))
#define OS_MEM_HEAD(pool, size) OS_DLNK_HEAD(OS_MEM_HEAD_ADDR(pool), size)
#define OS_MEM_HEAD_ADDR(pool) ((VOID *)((UINT32)(UINTPTR)(pool) + sizeof(LOS_MEM_POOL_INFO)))
#define OS_MEM_NEXT_NODE(node) ((LosMemDynNode *)((UINT8 *)(node) + \
OS_MEM_NODE_GET_SIZE((node)->sizeAndFlag)))
#define OS_MEM_FIRST_NODE(pool) ((LosMemDynNode *)((UINT8 *)OS_MEM_HEAD_ADDR(pool) + OS_DLNK_HEAD_SIZE))
#define OS_MEM_END_NODE(pool, size) ((LosMemDynNode *)(((UINT8 *)(pool) + (size)) - OS_MEM_NODE_HEAD_SIZE))
#define OS_MEM_MIDDLE_ADDR_OPEN_END(startAddr, middleAddr, endAddr) \
(((UINT8 *)(startAddr) <= (UINT8 *)(middleAddr)) && ((UINT8 *)(middleAddr) < (UINT8 *)(endAddr)))
#define OS_MEM_MIDDLE_ADDR(startAddr, middleAddr, endAddr) (((UINT8 *)(startAddr) <= (UINT8 *)(middleAddr)) && \
((UINT8 *)(middleAddr) <= (UINT8 *)(endAddr)))
#define OS_MEM_SET_MAGIC(value) (value) = (LOS_DL_LIST *)(UINTPTR)((UINT32)(UINTPTR)(&(value)) ^ 0xffffffff)
#define OS_MEM_MAGIC_VALID(value) ((((UINT32)(UINTPTR)(value)) ^ ((UINT32)(UINTPTR)(&(value)))) == 0xffffffff)
#define OS_MAX_MULTI_DLNK_LOG2 30
#define OS_MIN_MULTI_DLNK_LOG2 4
#define OS_MULTI_DLNK_NUM ((OS_MAX_MULTI_DLNK_LOG2 - OS_MIN_MULTI_DLNK_LOG2) + 1)
#define OS_DLNK_HEAD_SIZE OS_MULTI_DLNK_HEAD_SIZE
#define OS_DLNK_INIT_HEAD OsDLnkInitMultiHead
#define OS_DLNK_HEAD OsDLnkMultiHead
#define OS_DLNK_NEXT_HEAD OsDLnkNextMultiHead
#define OS_DLNK_FIRST_HEAD OsDLnkFirstMultiHead
#define OS_MULTI_DLNK_HEAD_SIZE sizeof(LosMultipleDlinkHead)
typedef struct {
LOS_DL_LIST listHead[OS_MULTI_DLNK_NUM];
} LosMultipleDlinkHead;
STATIC_INLINE LOS_DL_LIST *OsDLnkNextMultiHead(VOID *headAddr, LOS_DL_LIST *listHead)
{
LosMultipleDlinkHead *head = (LosMultipleDlinkHead *)headAddr;
return (&(head->listHead[OS_MULTI_DLNK_NUM - 1]) == listHead) ? NULL : (listHead + 1);
}
STATIC_INLINE LOS_DL_LIST *OsDLnkFirstMultiHead(VOID *headAddr)
{
return (LOS_DL_LIST *)headAddr;
}
extern VOID OsDLnkInitMultiHead(VOID *headAddr);
extern LOS_DL_LIST *OsDLnkMultiHead(VOID *headAddr, UINT32 size);
#if (LOSCFG_MEMORY_BESTFIT == YES)
extern VOID OsTaskMemUsedInc(UINT32 usedSize, UINT32 taskID);
extern VOID OsTaskMemUsedDec(UINT32 usedSize, UINT32 taskID);
extern UINT32 OsTaskMemUsage(UINT32 taskID);
extern VOID OsTaskMemClear(UINT32 taskID);
#ifdef OS_MEM_ENABLE_MEM_STATISTICS
#define OS_MEM_ADD_USED(usedSize, taskID) OsTaskMemUsedInc(usedSize, taskID)
#define OS_MEM_REDUCE_USED(usedSize, taskID) OsTaskMemUsedDec(usedSize, taskID)
#define OS_MEM_CLEAR(taskID) OsTaskMemClear(taskID)
#else
#define OS_MEM_ADD_USED(usedSize, taskID)
#define OS_MEM_REDUCE_USED(usedSize, taskID)
#define OS_MEM_CLEAR(taskID)
#endif
#else
#if (LOSCFG_KERNEL_MEM_STATISTICS == YES)
typedef struct {
UINT32 memUsed;
UINT32 memPeak;
} TaskMemUsedInfo;
extern VOID OsTaskMemStatInit(TaskMemUsedInfo *memStats);
extern VOID OsTaskMemUsedInc(TaskMemUsedInfo *memStats, UINT32 usedSize, UINT32 taskID);
extern VOID OsTaskMemUsedDec(TaskMemUsedInfo *memStats, UINT32 usedSize, UINT32 taskID);
extern UINT32 OsTaskMemUsage(TaskMemUsedInfo *memStats, UINT32 taskID);
extern VOID OsTaskMemClear(TaskMemUsedInfo *memStats, UINT32 taskID);
#endif
#endif
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -37,11 +37,9 @@
#ifndef _LOS_MUX_H
#define _LOS_MUX_H
#include "los_base.h"
#include "los_sys.h"
#include "los_list.h"
#include "los_task.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
@ -284,6 +282,65 @@ extern UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout);
*/
extern UINT32 LOS_MuxPost(UINT32 muxHandle);
/**
* @ingroup los_mux
* Mutex object.
*/
typedef struct {
UINT8 muxStat; /**< State OS_MUX_UNUSED,OS_MUX_USED */
UINT16 muxCount; /**< Times of locking a mutex */
UINT32 muxID; /**< Handle ID */
LOS_DL_LIST muxList; /**< Mutex linked list */
LosTaskCB *owner; /**< The current thread that is locking a mutex */
UINT16 priority; /**< Priority of the thread that is locking a mutex */
} LosMuxCB;
/**
* @ingroup los_mux
* Mutex state: not in use.
*/
#define OS_MUX_UNUSED 0
/**
* @ingroup los_mux
* Mutex state: in use.
*/
#define OS_MUX_USED 1
extern LosMuxCB *g_allMux;
/**
* @ingroup los_mux
* Obtain the pointer to a mutex object of the mutex that has a specified handle.
*/
#define GET_MUX(muxid) (((LosMuxCB *)g_allMux) + (muxid))
/**
* @ingroup los_mux
* @brief Initializes the mutex.
*
* @par Description:
* This API is used to initializes the mutex.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval UINT32 Initialization result.
* @par Dependency:
* <ul><li>los_mux_pri.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MuxDelete
*/
extern UINT32 OsMuxInit(VOID);
/**
* @ingroup los_mux
* Obtain the pointer to the linked list in the mutex pointed to by a specified pointer.
*/
#define GET_MUX_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosMuxCB, muxList)
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -1,135 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: 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.
* ---------------------------------------------------------------------------
* Notice of Export Control Law
* ===============================================
* Huawei LiteOS may be subject to applicable export control laws and regulations, which might
* include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
* Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
* applicable export control laws and regulations.
*/
/**@defgroup los_printf Printf
* @ingroup kernel
*/
#ifndef _LOS_PRINTF_H
#define _LOS_PRINTF_H
#include "stdarg.h"
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define LOS_EMG_LEVEL 0
#define LOS_COMMOM_LEVEL (LOS_EMG_LEVEL + 1)
#define LOS_ERR_LEVEL (LOS_COMMOM_LEVEL + 1)
#define LOS_WARN_LEVEL (LOS_ERR_LEVEL + 1)
#define LOS_INFO_LEVEL (LOS_WARN_LEVEL + 1)
#define LOS_DEBUG_LEVEL (LOS_INFO_LEVEL + 1)
#ifndef PRINT_LEVEL
#define PRINT_LEVEL LOS_ERR_LEVEL
#endif
/**
*@ingroup los_printf
*@brief Format and print data.
*
* @par Description:
* Print argument(s) according to fmt.
*
* @attention
* <ul>
* <li>None</li>
* </ul>
*
*@param fmt [IN] Type char* controls the ouput as in C printf.
*
*@retval None
*@par Dependency:
*<ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
*@see printf
*@since Huawei LiteOS V100R001C00
*/
extern int printf(char const *str, ...);
#define PRINT printf
#if PRINT_LEVEL < LOS_DEBUG_LEVEL
#define PRINT_DEBUG(fmt, args...)
#else
#define PRINT_DEBUG(fmt, args...) do{(PRINT("[DEBUG] "), PRINT(fmt, ##args));}while(0)
#endif
#if PRINT_LEVEL < LOS_INFO_LEVEL
#define PRINT_INFO(fmt, args...)
#else
#define PRINT_INFO(fmt, args...) do{(PRINT("[INFO] "), PRINT(fmt, ##args));}while(0)
#endif
#if PRINT_LEVEL < LOS_WARN_LEVEL
#define PRINT_WARN(fmt, args...)
#else
#define PRINT_WARN(fmt, args...) do{(PRINT("[WARN] "), PRINT(fmt, ##args));}while(0)
#endif
#if PRINT_LEVEL < LOS_ERR_LEVEL
#define PRINT_ERR(fmt, args...)
#else
#define PRINT_ERR(fmt, args...) do{(PRINT("[ERR] "), PRINT(fmt, ##args));}while(0)
#endif
#if PRINT_LEVEL < LOS_COMMOM_LEVEL
#define PRINTK(fmt, args...)
#else
#define PRINTK(fmt, args...) PRINT(fmt, ##args)
#endif
#if PRINT_LEVEL < LOS_EMG_LEVEL
#define PRINT_EMG(fmt, args...)
#else
#define PRINT_EMG(fmt, args...) do{(PRINT("[EMG] "), PRINT(fmt, ##args));}while(0)
#endif
#define PRINT_RELEASE(fmt, args...) PRINT(fmt, ##args)
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_PRINTF_H */

View File

@ -37,7 +37,6 @@
#ifndef _LOS_QUEUE_H
#define _LOS_QUEUE_H
#include "los_base.h"
#include "los_list.h"
#ifdef __cplusplus
@ -719,6 +718,191 @@ extern UINT32 LOS_QueueDelete(UINT32 queueID);
*/
extern UINT32 LOS_QueueInfoGet(UINT32 queueID, QUEUE_INFO_S *queueInfo);
typedef enum {
OS_QUEUE_READ,
OS_QUEUE_WRITE
} QueueReadWrite;
typedef enum {
OS_QUEUE_HEAD,
OS_QUEUE_TAIL
} QueueHeadTail;
typedef enum {
OS_QUEUE_NOT_POINT,
OS_QUEUE_POINT
} QueuePointOrNot;
#define OS_QUEUE_OPERATE_TYPE(ReadOrWrite, HeadOrTail, PointOrNot) \
(((UINT32)(PointOrNot) << 2) | ((UINT32)(HeadOrTail) << 1) | (ReadOrWrite))
#define OS_QUEUE_READ_WRITE_GET(type) ((type) & (0x01))
#define OS_QUEUE_READ_HEAD (OS_QUEUE_READ | (OS_QUEUE_HEAD << 1))
#define OS_QUEUE_READ_TAIL (OS_QUEUE_READ | (OS_QUEUE_TAIL << 1))
#define OS_QUEUE_WRITE_HEAD (OS_QUEUE_WRITE | (OS_QUEUE_HEAD << 1))
#define OS_QUEUE_WRITE_TAIL (OS_QUEUE_WRITE | (OS_QUEUE_TAIL << 1))
#define OS_QUEUE_OPERATE_GET(type) ((type) & (0x03))
#define OS_QUEUE_IS_POINT(type) ((type) & (0x04))
#define OS_QUEUE_IS_READ(type) (OS_QUEUE_READ_WRITE_GET(type) == OS_QUEUE_READ)
#define OS_QUEUE_IS_WRITE(type) (OS_QUEUE_READ_WRITE_GET(type) == OS_QUEUE_WRITE)
#define OS_READWRITE_LEN 2
/**
* @ingroup los_queue
* Queue information block structure
*/
typedef struct {
UINT8 *queue; /**< Pointer to a queue handle */
UINT16 queueState; /**< Queue state */
UINT16 queueLen; /**< Queue length */
UINT16 queueSize; /**< Node size */
UINT16 queueID; /**< queueID */
UINT16 queueHead; /**< Node head */
UINT16 queueTail; /**< Node tail */
UINT16 readWriteableCnt[OS_READWRITE_LEN]; /**< Count of readable or writable resources, 0:readable, 1:writable */
LOS_DL_LIST readWriteList[OS_READWRITE_LEN]; /**< Pointer to the linked list to be read or written,
0:readlist, 1:writelist */
LOS_DL_LIST memList; /**< Pointer to the memory linked list */
} LosQueueCB;
/* queue state */
/**
* @ingroup los_queue
* Message queue state: not in use.
*/
#define OS_QUEUE_UNUSED 0
/**
* @ingroup los_queue
* Message queue state: used.
*/
#define OS_QUEUE_INUSED 1
/**
* @ingroup los_queue
* Not in use.
*/
#define OS_QUEUE_WAIT_FOR_POOL 1
/**
* @ingroup los_queue
* Normal message queue.
*/
#define OS_QUEUE_NORMAL 0
/**
* @ingroup los_queue
* Queue information control block
*/
extern LosQueueCB *g_allQueue;
/**
* @ingroup los_queue
* Obtain a handle of the queue that has a specified ID.
*/
#define GET_QUEUE_HANDLE(QueueID) (((LosQueueCB *)g_allQueue) + (QueueID))
/**
* @ingroup los_queue
* Obtain the head node in a queue doubly linked list.
*/
#define GET_QUEUE_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosQueueCB, readWriteList[OS_QUEUE_WRITE])
/**
* @ingroup los_queue
* @brief Alloc a stationary memory for a mail.
*
* @par Description:
* This API is used to alloc a stationary memory for a mail according to queueID.
* @attention
* <ul>
* <li>Do not alloc memory in unblocking modes such as interrupt.</li>
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
* <li>The argument timeOut is a relative time.</li>
* </ul>
*
* @param queueID [IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
* @param mailPool [IN] The memory poll that stores the mail.
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER].
*
* @retval #NULL The memory allocation is failed.
* @retval #mem The address of alloc memory.
* @par Dependency:
* <ul><li>los_queue_pri.h: the header file that contains the API declaration.</li></ul>
* @see OsQueueMailFree
*/
extern VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 timeOut);
/**
* @ingroup los_queue
* @brief Free a stationary memory of a mail.
*
* @par Description:
* This API is used to free a stationary memory for a mail according to queueID.
* @attention
* <ul>
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
* </ul>
*
* @param queueID [IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
* @param mailPool [IN] The mail memory poll address.
* @param mailMem [IN] The mail memory block address.
*
* @retval #LOS_OK 0x00000000: The memory free successfully.
* @retval #OS_ERRNO_QUEUE_MAIL_HANDLE_INVALID 0x02000619: The handle of the queue passed-in when the memory for
the queue is being freed is invalid.
* @retval #OS_ERRNO_QUEUE_MAIL_PTR_INVALID 0x0200061a: The pointer to the memory to be freed is null.
* @retval #OS_ERRNO_QUEUE_MAIL_FREE_ERROR 0x0200061b: The memory for the queue fails to be freed.
* @par Dependency:
* <ul><li>los_queue_pri.h: the header file that contains the API declaration.</li></ul>
* @see OsQueueMailAlloc
*/
extern UINT32 OsQueueMailFree(UINT32 queueID, VOID *mailPool, VOID *mailMem);
/**
* @ingroup los_queue
* @brief Initialization queue.
*
* @par Description:
* This API is used to initialization queue.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval UINT32 Initialization result.
* @par Dependency:
* <ul><li>los_queue_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsQueueInit(VOID);
/**
* @ingroup los_queue
* @brief Handle when read or write queue.
*
* @par Description:
* This API is used to handle when read or write queue.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param queueID [IN] Queue id.
* @param operateType [IN] Operate type
* @param bufferAddr [IN] Buffer address.
* @param bufferSize [IN] Buffer size.
* @param timeOut [IN] Timeout.
*
* @retval UINT32 Handle result.
* @par Dependency:
* <ul><li>los_queue_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize,
UINT32 timeOut);
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -37,9 +37,6 @@
#ifndef _LOS_SEM_H
#define _LOS_SEM_H
#include "los_base.h"
#include "los_err.h"
#include "los_list.h"
#include "los_task.h"
#ifdef __cplusplus
@ -288,6 +285,91 @@ extern UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout);
*/
extern UINT32 LOS_SemPost(UINT32 semHandle);
enum LosSemMaxCount {
OS_SEM_COUNTING_MAX_COUNT = 0xFFFF, /**< Max count of counting semaphores */
OS_SEM_BINARY_MAX_COUNT = 1 /**< Max count of binary semaphores */
};
/**
* @ingroup los_sem
* Semaphore control structure.
*/
typedef struct {
UINT16 semStat; /**< Semaphore state */
UINT16 semCount; /**< Number of available semaphores */
UINT16 maxSemCount; /**< Max number of available semaphores */
UINT16 semID; /**< Semaphore control structure ID */
LOS_DL_LIST semList; /**< Queue of tasks that are waiting on a semaphore */
} LosSemCB;
/**
* @ingroup los_sem
* The semaphore is not in use.
*
*/
#define OS_SEM_UNUSED 0
/**
* @ingroup los_sem
* The semaphore is used.
*
*/
#define OS_SEM_USED 1
/**
* @ingroup los_sem
* Obtain the head node in a semaphore doubly linked list.
*
*/
#define GET_SEM_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosSemCB, semList)
extern LosSemCB *g_allSem;
/**
* @ingroup los_sem
* Obtain a semaphore ID.
*
*/
#define GET_SEM(semid) (((LosSemCB *)g_allSem) + (semid))
/**
* @ingroup los_sem
* @brief Initialize the Semaphore doubly linked list.
*
* @par Description:
* This API is used to initialize the Semaphore doubly linked list.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval UINT32 Initialization result.
* @par Dependency:
* <ul><li>los_sem_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsSemInit(VOID);
/**
* @ingroup los_sem
* @brief Create Semaphore.
*
* @par Description:
* This API is used to create Semaphore.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param count [IN]Type #UINT16 Semaphore count.
* @param maxCount [IN]Type #UINT16 Max semaphore count.
* @param semHandle [OUT]Type #UINT32 * Index of semaphore.
*
* @retval UINT32 Create result.
* @par Dependency:
* <ul><li>los_sem_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
UINT32 OsSemCreate(UINT16 count, UINT16 maxCount, UINT32 *semHandle);
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -1,66 +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.
*/
/**
* @defgroup los_slab Slab
* @ingroup kernel
*/
#ifndef _LOS_SLAB_H
#define _LOS_SLAB_H
#include <los_typedef.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
// number of slab class
#define SLAB_MEM_COUNT 4
// step size of each class
#define SLAB_MEM_CALSS_STEP_SIZE 0x10
// max size of each class
#define SLAB_MEM_ALLOCATOR_SIZE 512
#define SLAB_BASIC_NEED_SIZE 0x1000
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@ -37,8 +37,6 @@
#ifndef _LOS_SWTMR_H
#define _LOS_SWTMR_H
#include "los_base.h"
#include "los_task.h"
#ifdef __cplusplus
#if __cplusplus
@ -433,6 +431,119 @@ extern UINT32 LOS_SwtmrCreate(UINT32 interval,
*/
extern UINT32 LOS_SwtmrDelete(UINT16 swtmrID);
/**
* @ingroup los_swtmr
* Software timer state
*/
enum SwtmrState {
OS_SWTMR_STATUS_UNUSED, /**< The software timer is not used. */
OS_SWTMR_STATUS_CREATED, /**< The software timer is created. */
OS_SWTMR_STATUS_TICKING /**< The software timer is timing. */
};
/**
* @ingroup los_swtmr
* Structure of the callback function that handles software timer timeout
*/
typedef struct {
SWTMR_PROC_FUNC handler; /**< Callback function that handles software timer timeout */
UINT32 arg; /**< Parameter passed in when the callback function
that handles software timer timeout is called */
} SwtmrHandlerItem;
extern SWTMR_CTRL_S *g_swtmrCBArray;
#define OS_SWT_FROM_SID(swtmrId) ((SWTMR_CTRL_S *)g_swtmrCBArray + ((swtmrId) % LOSCFG_BASE_CORE_SWTMR_LIMIT))
/**
* @ingroup los_swtmr
* @brief Scan a software timer.
*
* @par Description:
* <ul>
* <li>This API is used to scan a software timer when a Tick interrupt occurs and determine whether the software timer
expires.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_swtmr_pri.h: the header file that contains the API declaration.</li></ul>
* @see LOS_SwtmrStop
*/
extern UINT32 OsSwtmrScan(VOID);
/**
* @ingroup los_swtmr
* @brief Initialization software timer.
*
* @par Description:
* <ul>
* <li>This API is used to initialization software.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_swtmr_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsSwtmrInit(VOID);
/**
* @ingroup los_swtmr
* @brief Get next timeout.
*
* @par Description:
* <ul>
* <li>This API is used to get next timeout.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_swtmr_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsSwtmrGetNextTimeout(VOID);
/**
* @ingroup los_swtmr
* @brief Adjust software timer list.
*
* @par Description:
* <ul>
* <li>This API is used to adjust software timer list.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param sleepTime [IN] UINT32 Sleep time.
*
* @retval UINT32 Sleep time.
* @par Dependency:
* <ul><li>los_swtmr_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID OsSwtmrAdjust(UINT32 sleepTime);
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -1,212 +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.
*/
/**
* @defgroup los_sys System time
* @ingroup kernel
*/
#ifndef _LOS_SYS_H
#define _LOS_SYS_H
#include "los_hwi.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_sys
* Number of milliseconds in one second.
*/
#define OS_SYS_MS_PER_SECOND 1000
/**
* @ingroup los_sys
* Number of microseconds in one second.
*/
#define OS_SYS_US_PER_SECOND 1000000
/**
* @ingroup los_sys
* System time basic function error code: Null pointer.
*
* Value: 0x02000010
*
* Solution: Check whether the input parameter is null.
*/
#define LOS_ERRNO_SYS_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x10)
/**
* @ingroup los_sys
* System time basic function error code: Invalid system clock configuration.
*
* Value: 0x02000011
*
* Solution: Configure a valid system clock in los_config.h.
*/
#define LOS_ERRNO_SYS_CLOCK_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x11)
/**
* @ingroup los_sys
* System time basic function error code: This error code is not in use temporarily.
*
* Value: 0x02000012
*
* Solution: None.
*/
#define LOS_ERRNO_SYS_MAXNUMOFCORES_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x12)
/**
* @ingroup los_sys
* System time error code: This error code is not in use temporarily.
*
* Value: 0x02000013
*
* Solution: None.
*/
#define LOS_ERRNO_SYS_PERIERRCOREID_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x13)
/**
* @ingroup los_sys
* System time error code: This error code is not in use temporarily.
*
* Value: 0x02000014
*
* Solution: None.
*/
#define LOS_ERRNO_SYS_HOOK_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x14)
/**
* @ingroup los_typedef
* system time structure.
*/
typedef struct tagSysTime {
UINT16 uwYear; /**< value 1970 ~ 2038 or 1970 ~ 2100 */
UINT8 ucMonth; /**< value 1 - 12 */
UINT8 ucDay; /**< value 1 - 31 */
UINT8 ucHour; /**< value 0 - 23 */
UINT8 ucMinute; /**< value 0 - 59 */
UINT8 ucSecond; /**< value 0 - 59 */
UINT8 ucWeek; /**< value 0 - 6 */
} SYS_TIME_S;
/**
* @ingroup los_sys
* @brief Obtain the number of Ticks.
*
* @par Description:
* This API is used to obtain the number of Ticks.
* @attention
* <ul>
* <li>None</li>
* </ul>
*
* @param None
*
* @retval UINT64 The number of Ticks.
* @par Dependency:
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
* @see None
*/
extern UINT64 LOS_TickCountGet(VOID);
/**
* @ingroup los_sys
* @brief Obtain the number of cycles in one second.
*
* @par Description:
* This API is used to obtain the number of cycles in one second.
* @attention
* <ul>
* <li>None</li>
* </ul>
*
* @param None
*
* @retval UINT32 Number of cycles obtained in one second.
* @par Dependency:
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
* @see None
*/
extern UINT32 LOS_CyclePerTickGet(VOID);
/**
* @ingroup los_sys
* @brief Convert Ticks to milliseconds.
*
* @par Description:
* This API is used to convert Ticks to milliseconds.
* @attention
* <ul>
* <li>The number of milliseconds obtained through the conversion is 32-bit.</li>
* </ul>
*
* @param ticks [IN] Number of Ticks. The value range is (0,OS_SYS_CLOCK).
*
* @retval UINT32 Number of milliseconds obtained through the conversion. Ticks are successfully converted to
* milliseconds.
* @par Dependency:
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MS2Tick
*/
extern UINT32 LOS_Tick2MS(UINT32 ticks);
/**
* @ingroup los_sys
* @brief Convert milliseconds to Ticks.
*
* @par Description:
* This API is used to convert milliseconds to Ticks.
* @attention
* <ul>
* <li>If the parameter passed in is equal to 0xFFFFFFFF, the retval is 0xFFFFFFFF. Pay attention to the value to be
* converted because data possibly overflows.</li>
* </ul>
*
* @param millisec [IN] Number of milliseconds.
*
* @retval UINT32 Number of Ticks obtained through the conversion.
* @par Dependency:
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
* @see LOS_Tick2MS
*/
extern UINT32 LOS_MS2Tick(UINT32 millisec);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_SYS_H */

View File

@ -1,128 +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.
*/
#ifndef _LOS_TABLES_H
#define _LOS_TABLES_H
#include "los_typedef.h"
#define TO_STRING(x) #x
#define X_TO_STRING(x) TO_STRING(x)
#ifndef LOS_HAL_TABLE_WOW_BEGIN
#define LOS_HAL_TABLE_WOW_BEGIN(label, name) \
__asm__(".section \".liteos.table." X_TO_STRING(name) ".wow.begin\",\"aw\"\n" \
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
".previous\n")
#endif
#ifndef LOS_HAL_TABLE_WOW_END
#define LOS_HAL_TABLE_WOW_END(label, name) \
__asm__(".section \".liteos.table." X_TO_STRING(name) ".wow.finish\",\"aw\"\n" \
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
".previous\n")
#endif
#ifndef LOS_HAL_TABLE_SCATTER_BEGIN
#define LOS_HAL_TABLE_SCATTER_BEGIN(label, name) \
__asm__(".section \".liteos.table." X_TO_STRING(name) ".scatter.begin\",\"aw\"\n" \
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
".previous\n")
#endif
#ifndef LOS_HAL_TABLE_SCATTER_END
#define LOS_HAL_TABLE_SCATTER_END(label, name) \
__asm__(".section \".liteos.table." X_TO_STRING(name) ".scatter.finish\",\"aw\"\n" \
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
".previous\n")
#endif
#ifndef LOS_HAL_TABLE_BEGIN
#define LOS_HAL_TABLE_BEGIN(label, name) \
__asm__(".section \".liteos.table." X_TO_STRING(name) ".begin\",\"aw\"\n" \
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
".previous\n")
#endif
#ifndef LOS_HAL_TABLE_END
#define LOS_HAL_TABLE_END(label, name) \
__asm__(".section \".liteos.table." X_TO_STRING(name) ".finish\",\"aw\"\n" \
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
".previous\n")
#endif
// This macro must be applied to any types whose objects are to be placed in tables
#ifndef LOS_HAL_TABLE_TYPE
#define LOS_HAL_TABLE_TYPE LOSBLD_ATTRIB_ALIGN(LOSARC_ALIGNMENT)
#endif
#ifndef LOS_HAL_TABLE_EXTRA
#define LOS_HAL_TABLE_EXTRA(name) \
LOSBLD_ATTRIB_SECTION(".liteos.table." X_TO_STRING(name) ".extra")
#endif
#ifndef LOS_HAL_TABLE_WOW_ENTRY
#define LOS_HAL_TABLE_WOW_ENTRY(name) \
LOSBLD_ATTRIB_SECTION(".liteos.table." X_TO_STRING(name) ".wow.data") \
LOSBLD_ATTRIB_USED
#endif
#ifndef LOS_HAL_TABLE_SCATTER_ENTRY
#define LOS_HAL_TABLE_SCATTER_ENTRY(name) \
LOSBLD_ATTRIB_SECTION(".liteos.table." X_TO_STRING(name) ".scatter.data") \
LOSBLD_ATTRIB_USED
#endif
#ifndef LOS_HAL_TABLE_ENTRY
#define LOS_HAL_TABLE_ENTRY(name) \
LOSBLD_ATTRIB_SECTION(".liteos.table." X_TO_STRING(name) ".data") \
LOSBLD_ATTRIB_USED
#endif
#ifndef LOS_HAL_TABLE_QUALIFIED_ENTRY
#define LOS_HAL_TABLE_QUALIFIED_ENTRY(name, qual) \
LOSBLD_ATTRIB_SECTION(".liteos.table." X_TO_STRING(name) ".data." X_TO_STRING(qual)) \
LOSBLD_ATTRIB_USED
#endif
#endif /* _LOS_TABLES_H */

File diff suppressed because it is too large Load Diff

View File

@ -37,7 +37,7 @@
#ifndef _LOS_TICK_H
#define _LOS_TICK_H
#include "los_errno.h"
#include "los_error.h"
#ifdef __cplusplus
#if __cplusplus
@ -98,6 +98,466 @@ extern "C" {
* */
extern UINT32 LOS_SysClockGet(VOID);
/**
* @ingroup los_tickless
* @brief enable the tickless mode.
*
* @par Description:
* This API is used to enable the tickless mode. System can change from periodic clock mode to dynamic clock mode.
*
* @attention
* <ul>
* </ul>
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_tickless.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TicklessDisable
*/
extern VOID LOS_TicklessEnable(VOID);
/**
* @ingroup los_tickless
* @brief disable the tickless mode.
*
* @par Description:
* This API is used to diable the tickless mode. System will not change from periodic clock mode to dynamic clock mode.
*
* @attention
* <ul>
* </ul>
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_tickless.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TicklessEnable
*/
extern VOID LOS_TicklessDisable(VOID);
/**
* @ingroup los_sys
* Number of milliseconds in one second.
*/
#define OS_SYS_MS_PER_SECOND 1000
/**
* @ingroup los_sys
* Number of microseconds in one second.
*/
#define OS_SYS_US_PER_SECOND 1000000
/**
* @ingroup los_sys
* System time basic function error code: Null pointer.
*
* Value: 0x02000010
*
* Solution: Check whether the input parameter is null.
*/
#define LOS_ERRNO_SYS_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x10)
/**
* @ingroup los_sys
* System time basic function error code: Invalid system clock configuration.
*
* Value: 0x02000011
*
* Solution: Configure a valid system clock in los_config.h.
*/
#define LOS_ERRNO_SYS_CLOCK_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x11)
/**
* @ingroup los_sys
* System time basic function error code: This error code is not in use temporarily.
*
* Value: 0x02000012
*
* Solution: None.
*/
#define LOS_ERRNO_SYS_MAXNUMOFCORES_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x12)
/**
* @ingroup los_sys
* System time error code: This error code is not in use temporarily.
*
* Value: 0x02000013
*
* Solution: None.
*/
#define LOS_ERRNO_SYS_PERIERRCOREID_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x13)
/**
* @ingroup los_sys
* System time error code: This error code is not in use temporarily.
*
* Value: 0x02000014
*
* Solution: None.
*/
#define LOS_ERRNO_SYS_HOOK_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x14)
/**
* @ingroup los_typedef
* system time structure.
*/
typedef struct tagSysTime {
UINT16 uwYear; /**< value 1970 ~ 2038 or 1970 ~ 2100 */
UINT8 ucMonth; /**< value 1 - 12 */
UINT8 ucDay; /**< value 1 - 31 */
UINT8 ucHour; /**< value 0 - 23 */
UINT8 ucMinute; /**< value 0 - 59 */
UINT8 ucSecond; /**< value 0 - 59 */
UINT8 ucWeek; /**< value 0 - 6 */
} SYS_TIME_S;
/**
* @ingroup los_sys
* @brief Obtain the number of Ticks.
*
* @par Description:
* This API is used to obtain the number of Ticks.
* @attention
* <ul>
* <li>None</li>
* </ul>
*
* @param None
*
* @retval UINT64 The number of Ticks.
* @par Dependency:
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
* @see None
*/
extern UINT64 LOS_TickCountGet(VOID);
/**
* @ingroup los_sys
* @brief Obtain the number of cycles in one second.
*
* @par Description:
* This API is used to obtain the number of cycles in one second.
* @attention
* <ul>
* <li>None</li>
* </ul>
*
* @param None
*
* @retval UINT32 Number of cycles obtained in one second.
* @par Dependency:
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
* @see None
*/
extern UINT32 LOS_CyclePerTickGet(VOID);
/**
* @ingroup los_sys
* @brief Convert Ticks to milliseconds.
*
* @par Description:
* This API is used to convert Ticks to milliseconds.
* @attention
* <ul>
* <li>The number of milliseconds obtained through the conversion is 32-bit.</li>
* </ul>
*
* @param ticks [IN] Number of Ticks. The value range is (0,OS_SYS_CLOCK).
*
* @retval UINT32 Number of milliseconds obtained through the conversion. Ticks are successfully converted to
* milliseconds.
* @par Dependency:
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MS2Tick
*/
extern UINT32 LOS_Tick2MS(UINT32 ticks);
/**
* @ingroup los_sys
* @brief Convert milliseconds to Ticks.
*
* @par Description:
* This API is used to convert milliseconds to Ticks.
* @attention
* <ul>
* <li>If the parameter passed in is equal to 0xFFFFFFFF, the retval is 0xFFFFFFFF. Pay attention to the value to be
* converted because data possibly overflows.</li>
* </ul>
*
* @param millisec [IN] Number of milliseconds.
*
* @retval UINT32 Number of Ticks obtained through the conversion.
* @par Dependency:
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
* @see LOS_Tick2MS
*/
extern UINT32 LOS_MS2Tick(UINT32 millisec);
/**
* @ingroup los_tick
* Count of Ticks
*/
extern UINT64 g_ullTickCount;
/**
* @ingroup los_tick
* Ticks per second
*/
extern UINT32 g_ticksPerSec;
/**
* @ingroup los_tick
* Cycles per Second
*/
extern UINT32 g_uwCyclePerSec;
/**
* @ingroup los_tick
* Cycles per Tick
*/
extern UINT32 g_cyclesPerTick;
/**
* @ingroup los_tick
* System Clock
*/
extern UINT32 g_sysClock;
/**
* @ingroup los_tick
* @brief Handle the system tick timeout.
*
* @par Description:
* This API is called when the system tick timeout and triggers the interrupt.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param none.
*
* @retval None.
* @par Dependency:
* <ul><li>los_tick_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID OsTickHandler(VOID);
#if (LOSCFG_KERNEL_TICKLESS == YES)
LITE_OS_SEC_TEXT VOID OsTickHandlerLoop(UINT32 elapseTicks);
#endif
/**
* @ingroup los_tick
* @brief tick modul init.
*
* @par Description:
* This API is called when the system initializating.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param systemClock [IN] Type #UINT32 SystemClock.
* @param tickPerSecond [IN] Type #UINT32 TickPerSecond.
*
* @retval None.
* @par Dependency:
* <ul><li>los_tick_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond);
/**
* @ingroup los_timeslice
* @brief Initialize time slices.
*
* @par Description:
* <ul>
* <li>This API is used to initialize time slices that defines the cycle of time slices according to
LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_timeslice_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID OsTimesliceInit(VOID);
/**
* @ingroup los_timeslice
* @brief Check time slices.
*
* @par Description:
* <ul>
* <li>This API is used to check time slices. If the number of Ticks equals to the time for task switch, tasks are switched. Otherwise, the Tick counting continues.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_timeslice_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID OsTimesliceCheck(VOID);
/**
* @ingroup los_base
* Define the CPU Tick structure.
*/
typedef struct tagCpuTick {
UINT32 cntHi; /* < Upper 32 bits of the tick value */
UINT32 cntLo; /* < Lower 32 bits of the tick value */
} CpuTick;
/**
* @ingroup los_sys
* Number of operable bits of a 32-bit operand
*/
#define OS_SYS_MV_32_BIT 32
/**
* @ingroup los_sys
* Number of milliseconds in one second.
*/
#define OS_SYS_MS_PER_SECOND 1000
/**
* @ingroup los_sys
* Number of microseconds in one second.
*/
#define OS_SYS_US_PER_SECOND 1000000
/**
* @ingroup los_sys
* The maximum length of name.
*/
#define OS_SYS_APPVER_NAME_MAX 64
/**
* @ingroup los_sys
* The magic word.
*/
#define OS_SYS_MAGIC_WORD 0xAAAAAAAA
/**
* @ingroup los_sys
* The initialization value of stack space.
*/
#define OS_SYS_EMPTY_STACK 0xCACACACA
/**
* @ingroup los_sys
* @brief Convert cycles to milliseconds.
*
* @par Description:
* This API is used to convert cycles to milliseconds.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param cpuTick [IN] Number of CPU cycles.
* @param msHi [OUT] Upper 32 bits of the number of milliseconds.
* @param msLo [OUT] Lower 32 bits of the number of milliseconds.
*
* @retval #LOS_ERRNO_SYS_PTR_NULL 0x02000011: Invalid parameter.
* @retval #LOS_OK 0: Cycles are successfully converted to microseconds.
* @par Dependency:
* <ul><li>los_sys_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsCpuTick2MS(CpuTick *cpuTick, UINT32 *msHi, UINT32 *msLo);
/**
* @ingroup los_sys
* @brief Convert cycles to microseconds.
*
* @par Description:
* This API is used to convert cycles to microseconds.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param cpuTick [IN] Number of CPU cycles.
* @param usHi [OUT] Upper 32 bits of the number of microseconds.
* @param usLo [OUT] Lower 32 bits of the number of microseconds.
*
* @retval #LOS_ERRNO_SYS_PTR_NULL 0x02000011: Invalid parameter.
* @retval #LOS_OK 0: Cycles are successfully converted to microseconds.
* @par Dependency:
* <ul><li>los_sys_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsCpuTick2US(CpuTick *cpuTick, UINT32 *usHi, UINT32 *usLo);
/**
* @ingroup los_sys
* @brief Convert cycles to milliseconds.
*
* @par Description:
* This API is used to convert cycles to milliseconds.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param cycle [IN] Number of cycles.
*
* @retval Number of milliseconds obtained through the conversion. Cycles are successfully converted to milliseconds.
* @par Dependency:
* <ul><li>los_sys_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
STATIC_INLINE UINT64 OsCycle2MS(UINT64 cycle)
{
return (UINT64)((cycle / (g_sysClock / OS_SYS_MS_PER_SECOND)));
}
/**
* @ingroup los_sys
* @brief Convert cycles to microseconds.
*
* @par Description:
* This API is used to convert cycles to microseconds.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param cycle [IN] Number of cycles.
*
* @retval Number of microseconds obtained through the conversion. Cycles are successfully converted to microseconds.
* @par Dependency:
* <ul><li>los_sys_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
STATIC_INLINE UINT64 OsCycle2US(UINT64 cycle)
{
UINT64 tmp = g_sysClock / OS_SYS_US_PER_SECOND;
if (tmp == 0) {
return 0;
}
return (UINT64)(cycle / tmp);
}
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -1,91 +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.
*/
/**
* @defgroup los_tickless Tickless
* @ingroup kernel
*/
#ifndef _LOS_TICKLESS_H
#define _LOS_TICKLESS_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_tickless
* @brief enable the tickless mode.
*
* @par Description:
* This API is used to enable the tickless mode. System can change from periodic clock mode to dynamic clock mode.
*
* @attention
* <ul>
* </ul>
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_tickless.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TicklessDisable
*/
extern VOID LOS_TicklessEnable(VOID);
/**
* @ingroup los_tickless
* @brief disable the tickless mode.
*
* @par Description:
* This API is used to diable the tickless mode. System will not change from periodic clock mode to dynamic clock mode.
*
* @attention
* <ul>
* </ul>
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_tickless.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TicklessEnable
*/
extern VOID LOS_TicklessDisable(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@ -1,121 +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.
*/
/**
* @defgroup los_typedef Type define
* @ingroup kernel
*/
#ifndef _LOS_TYPEDEF_H
#define _LOS_TYPEDEF_H
#include "los_builddef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifndef LOS_TYPE_DEF
#define LOS_TYPE_DEF
/* type definitions */
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
typedef signed char INT8;
typedef signed short INT16;
typedef signed int INT32;
typedef float FLOAT;
typedef double DOUBLE;
typedef char CHAR;
typedef unsigned int BOOL;
typedef unsigned long long UINT64;
typedef signed long long INT64;
typedef unsigned int UINTPTR;
typedef signed int INTPTR;
#define VOID void
#endif /* end of #ifndef LOS_TYPE_DEF */
#ifndef FALSE
#define FALSE ((BOOL)0)
#endif
#ifndef TRUE
#define TRUE ((BOOL)1)
#endif
#ifndef NULL
#define NULL ((VOID *)0)
#endif
#ifdef YES
#undef YES
#endif
#define YES 1
#ifdef NO
#undef NO
#endif
#define NO 0
#define OS_NULL_BYTE ((UINT8)0xFF)
#define OS_NULL_SHORT ((UINT16)0xFFFF)
#define OS_NULL_INT ((UINT32)0xFFFFFFFF)
#ifndef LOS_OK
#define LOS_OK 0U
#endif
#ifndef LOS_NOK
#define LOS_NOK 1U
#endif
#define OS_FAIL 1
#define OS_ERROR (UINT32)(-1)
#define OS_INVALID (UINT32)(-1)
#define asm __asm
#ifdef typeof
#undef typeof
#endif
#define typeof __typeof__
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_TYPEDEF_H */

View File

@ -1,63 +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.
*/
#ifndef _LOS_BASE_PRI_H
#define _LOS_BASE_PRI_H
#include "los_base.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_base
* Define the CPU Tick structure.
*/
typedef struct tagCpuTick {
UINT32 cntHi; /* < Upper 32 bits of the tick value */
UINT32 cntLo; /* < Lower 32 bits of the tick value */
} CpuTick;
#define OS_GOTO_ERREND() \
do { \
goto LOS_ERREND; \
} while (0)
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_BASE_PRI_H */

View File

@ -1,132 +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.
*/
#ifndef _LOS_ERR_PRI_H
#define _LOS_ERR_PRI_H
#include "los_err.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_err
* Define the error magic word.
*/
#define OS_ERR_MAGIC_WORD 0xa1b2c3f8
/**
* @ingroup los_err
* @brief Error handling macro capable of returning error codes.
*
* @par Description:
* This API is used to call the error handling function by using an error code and return the same error code.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param errNo [IN] Error code.
*
* @retval errNo
* @par Dependency:
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
#define OS_RETURN_ERROR(errNo) \
do { \
(VOID)LOS_ErrHandle("os_unspecific_file", OS_ERR_MAGIC_WORD, errNo, 0, NULL); \
return (errNo); \
} while (0)
/**
* @ingroup los_err
* @brief Error handling macro capable of returning error codes.
*
* @par Description:
* This API is used to call the error handling function by using an error code and the line number of the erroneous line,
and return the same error code.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param errLine [IN] Line number of the erroneous line.
* @param errNo [IN] Error code.
*
* @retval errNo
* @par Dependency:
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
#define OS_RETURN_ERROR_P2(errLine, errNo) \
do { \
(VOID)LOS_ErrHandle("os_unspecific_file", errLine, errNo, 0, NULL); \
return (errNo); \
} while (0)
/**
* @ingroup los_err
* @brief Macro for jumping to error handler.
*
* @par Description:
* This API is used to call the error handling function by using an error code.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param errorNo [IN] Error code.
*
* @retval None.
* @par Dependency:
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
#define OS_GOTO_ERR_HANDLER(errorNo) \
do { \
errNo = (errorNo); \
errLine = OS_ERR_MAGIC_WORD; \
goto ERR_HANDLER; \
} while (0)
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ERR_PRI_H */

View File

@ -29,12 +29,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_event_pri.h"
#include "los_priqueue_pri.h"
#include "los_task_pri.h"
#include "los_hw.h"
#include "los_hwi.h"
#include "los_task.h"
#include "los_interrupt.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
@ -56,6 +52,9 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventID, UINT32 eventMask, UINT32
UINT32 ret = 0;
UINTPTR intSave;
if (eventID == NULL) {
return LOS_ERRNO_EVENT_PTR_NULL;
}
intSave = LOS_IntLock();
if (mode & LOS_WAITMODE_OR) {
if ((*eventID & eventMask) != 0) {

View File

@ -1,52 +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.
*/
#ifndef _LOS_EVENT_PRI_H
#define _LOS_EVENT_PRI_H
#include "los_event.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
extern UINT32 OsEventReadOnce(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeOut);
extern UINT32 OsEventWriteOnce(PEVENT_CB_S eventCB, UINT32 events);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_EVENT_PRI_H */

View File

@ -1,159 +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.
*/
/**
* @defgroup los_heap Heap
* @ingroup kernel
*/
#ifndef _LOS_HEAP_PRI_H
#define _LOS_HEAP_PRI_H
#include "los_heap.h"
#include "los_slab_pri.h"
#include "los_memstat_pri.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct tagLosHeapStatus {
UINT32 totalSize;
UINT32 usedSize;
UINT32 freeSize;
UINT32 allocCount;
UINT32 freeCount;
} LosHeapStatus;
struct LosHeapManager {
struct LOS_HEAP_NODE *head;
struct LOS_HEAP_NODE *tail;
UINT32 size;
#if (LOSCFG_MEM_MUL_POOL == YES)
VOID *nextPool;
#endif
#if (LOSCFG_KERNEL_MEM_SLAB == YES)
struct LosSlabControlHeader slabCtrlHdr;
#endif
#if (LOSCFG_KERNEL_MEM_STATISTICS == YES)
TaskMemUsedInfo memStats[LOSCFG_BASE_CORE_TSK_LIMIT + 2];
#endif
};
/**
* @ingroup los_heap
* @brief Look up the next memory node according to one memory node in the memory block list.
*
* @par Description:
* This API is used to look up the next memory node according to one memory node in the memory block list.
* @attention
* <ul>
* <li>None.</li>
* </ul>
* @param heapMan [IN] Type #LosHeapManager * Pointer to the manager,to distinguish heap.
* @param node [IN] Type #LOS_HEAP_NODE * Size of memory in bytes to allocate.
*
* @retval LOS_HEAP_NODE * Pointer to next memory node.
*
* @par Dependency:
* <ul><li>los_heap_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern struct LOS_HEAP_NODE* OsHeapPrvGetNext(struct LosHeapManager *heapMan, struct LOS_HEAP_NODE* node);
/**
* @ingroup los_heap
* @brief Obtain the heap information.
*
* @par Description:
* This API is used to obtain the heap information.
* @attention
* <ul>
* <li>None.</li>
* </ul>
* @param pool [IN] Type #VOID * A pointer pointed to the heap memory pool.
*
* @retval None.
*
* @par Dependency:
* <ul><li>los_heap_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID OsAlarmHeapInfo(VOID *pool);
/**
* @ingroup los_heap
* @brief Obtain the heap status.
*
* @par Description:
* This API is used to obtain the heap status.
* @attention
* <ul>
* <li>None.</li>
* </ul>
* @param pool [IN] Type #VOID * A pointer pointed to the heap memory pool.
* @param status [OUT] Type #LosHeapStatus * Heap status.
*
* @retval UINT32 Get status result.
*
* @par Dependency:
* <ul><li>los_heap_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsHeapStatisticsGet(VOID *pool, LosHeapStatus *status);
/**
* @ingroup los_heap
* @brief Get the max free block size.
*
* @par Description:
* This API is used to Get the max free block size.
* @attention
* <ul>
* <li>None.</li>
* </ul>
* @param pool [IN] Type #VOID * A pointer pointed to the heap memory pool.
*
* @retval UINT32 Max free block size.
*
* @par Dependency:
* <ul><li>los_heap_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsHeapGetMaxFreeBlkSize(VOID *pool);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -29,27 +29,23 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_sys.h"
#include "los_tick.h"
#include "los_task_pri.h"
#include "los_tick_pri.h"
#include "los_config.h"
#if (LOSCFG_KERNEL_RUNSTOP == YES)
#include "los_sr.h"
#endif
#include "los_queue.h"
#include "los_memory.h"
#include "los_mux.h"
#if (LOSCFG_PLATFORM_EXC == YES)
#include "los_exc_pri.h"
#include "los_interrupt.h"
#endif
#if (LOSCFG_KERNEL_TRACE == YES)
#include "los_trace.h"
#include "los_debug.h"
#endif
#if (LOSCFG_KERNEL_CPPSUPPORT == YES)
#include "los_cppsupport.h"
#endif
#include "los_printf.h"
#include "los_debug.h"
#ifdef __cplusplus
@ -113,6 +109,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_Start(VOID)
}
extern UINT8 g_memStart[OS_SYS_MEM_SIZE];
/*****************************************************************************
Function : LOS_KernelInit
Description : System kernel initialization function, configure all system modules
@ -122,8 +119,8 @@ extern UINT8 g_memStart[OS_SYS_MEM_SIZE];
*****************************************************************************/
LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
{
printf("entering kernel init...\n");
UINT32 ret;
printf("entering kernel init...\n");
OsRegister();
m_aucSysMem0 = g_memStart;
@ -138,10 +135,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
OsHwiInit();
#endif
#if (LOSCFG_PLATFORM_EXC == YES)
OsExcInit(MAX_EXC_MEM_SIZE);
#endif
ret = OsTaskInit();
if (ret != LOS_OK) {
PRINT_ERR("OsTaskInit error\n");

View File

@ -1,65 +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.
*/
#ifndef _LOS_MEMBOX_PRI_H
#define _LOS_MEMBOX_PRI_H
#include "los_membox.h"
#define OS_MEMBOX_NEXT(addr, blkSize) (LOS_MEMBOX_NODE *)((UINT8 *)(addr) + (blkSize))
#ifdef LOS_MEMBOX_CHECK
#define OS_MEMBOX_MAGIC 0xa55a5aa5
#define OS_MEMBOX_SET_MAGIC(addr) (*((UINT32 *)(addr)) = OS_MEMBOX_MAGIC)
#define OS_MEMBOX_CHECK_MAGIC(addr) ((*((UINT32 *)(addr)) == OS_MEMBOX_MAGIC) ? LOS_OK : LOS_NOK)
#else
#define OS_MEMBOX_SET_MAGIC(addr)
#define OS_MEMBOX_CHECK_MAGIC(addr) LOS_OK
#endif
#define OS_MEMBOX_USER_ADDR(addr) ((VOID *)((UINT8 *)(addr) + LOS_MEMBOX_MAGIC_SIZE))
#define OS_MEMBOX_NODE_ADDR(addr) ((LOS_MEMBOX_NODE *)((UINT8 *)(addr) - LOS_MEMBOX_MAGIC_SIZE))
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_MEMBOX_PRI_H */

View File

@ -1,75 +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.
*/
#ifndef _LOS_MEMCHECK_PRI_H
#define _LOS_MEMCHECK_PRI_H
#include "los_memcheck.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cpluscplus */
#endif /* __cpluscplus */
/**
* @ingroup los_memboxcheck
* @brief Update the information of the memory.
*
* @par Description:
* <ul>
* <li>This API is used to update the information of the memory.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param pool [IN/OUT] Type #VOID * Memory pool number.
* @param size [IN] Type #UINT32 Memory size.
* @param type [IN] Type #UINT32 Memory mang type.
*
* @retval UINT32 Updateinformation result.
* @par Dependency:
* <ul>
* <li>los_memboxcheck_pri.h: the header file that contains the API declaration.</li>
* </ul>
* @see None.
*/
UINT32 OsMemInfoUpdate(VOID *pool, UINT32 size, UINT32 type);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cpluscplus */
#endif /* __cpluscplus */
#endif /* _LOS_MEMCHECK_PRI_H */

View File

@ -1,179 +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.
*/
#ifndef _LOS_MEMORY_PRI_H
#define _LOS_MEMORY_PRI_H
#include "los_memory.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define OS_MEM_ENABLE_MEM_STATISTICS
/*
* memcheck error code: the stack have not inited
* Value: 0x02000100
* Solution: do memcheck must after stack mem init
*/
#define OS_ERRNO_MEMCHECK_NOT_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x0)
/*
* memcheck error code: the pPtr is NULL
* Value: 0x02000101
* Solution: don't give a NULL parameter
*/
#define OS_ERRNO_MEMCHECK_PARA_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x1)
/*
* memcheck error code: the pPtr addr not in the suit range
* Value: 0x02000102
* Solution: check pPtr and comfirm it included by stack
*/
#define OS_ERRNO_MEMCHECK_OUTSIDE LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x2)
/*
* memcheck error code: can't find the ctrl node
* Value: 0x02000103
* Solution: confirm the pPtr if this node has been freed or has not been alloced
*/
#define OS_ERRNO_MEMCHECK_NO_HEAD LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x3)
/*
* memcheck error code: the para level is wrong
* Value: 0x02000104
* Solution: checkout the memcheck level by the func "OS_GetMemCheck_Level"
*/
#define OS_ERRNO_MEMCHECK_WRONG_LEVEL LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x4)
/*
* memcheck error code: memcheck func not open
* Value: 0x02000105
* Solution: enable memcheck by the func "OS_SetMemCheck_Level"
*/
#define OS_ERRNO_MEMCHECK_DISABLED LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x5)
/**
* @ingroup los_memory
* @brief Initialization the memory system.
*
* @par Description:
* <ul>
* <li>This API is used to initialization the memory system.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval UINT32 Initialization result.
* @par Dependency:
* <ul><li>los_memory_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsMemSystemInit(VOID);
/**
* @ingroup los_memory
* Memory linked list node structure
*/
typedef struct tagLosMemDynNode {
LOS_DL_LIST freeNodeInfo; /**< Free memory node */
struct tagLosMemDynNode *preNode; /**< Pointer to the previous memory node */
UINT32 sizeAndFlag; /**< Size and flag of the current node(the highest bit
represents a flag, and the rest bits specify the size) */
} LosMemDynNode;
#define OS_MEM_TASKID_SET(node, ID) \
do { \
UINTPTR tmp = (UINTPTR)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext); \
tmp = tmp & 0xffff0000; \
tmp |= (ID); \
((LosMemDynNode *)(node))->freeNodeInfo.pstNext = (LOS_DL_LIST *)(tmp); \
} while (0)
#define OS_MEM_TASKID_GET(node) ((UINT32)(UINTPTR)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext) & 0xffff)
#define OS_MEM_MODID_SET(node, ID) \
do { \
UINTPTR tmp = (UINTPTR)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext); \
tmp = tmp & 0xffff; \
tmp |= (ID) << 16; \
((LosMemDynNode *)(node))->freeNodeInfo.pstNext = (LOS_DL_LIST *)(tmp); \
} while (0)
#define OS_MEM_MODID_GET(node) ((UINT32)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext) >> 16)
#define OS_MEM_NODE_HEAD_SIZE sizeof(LosMemDynNode)
#define OS_MEM_MIN_POOL_SIZE (OS_DLNK_HEAD_SIZE + (2 * OS_MEM_NODE_HEAD_SIZE) + sizeof(LOS_MEM_POOL_INFO))
#define OS_MEM_ALIGN_SIZE 4
#define OS_MEM_NODE_USED_FLAG 0x80000000
#define OS_MEM_NODE_ALIGNED_FLAG 0x40000000
#define OS_MEM_NODE_ALIGN_SIZE 64
#define OS_MEM_NODE_NUM 2
#define OS_MEM_NODE_DATA_SIZE 4
#define OS_MEM_NODE_COUNT_NUM 8
#define OS_MULTI_DLNK_SIZE (OS_MAX_MULTI_DLNK_LOG2 - OS_MIN_MULTI_DLNK_LOG2)
#define OS_MEM_NODE_GET_ALIGNED_FLAG(sizeAndFlag) ((sizeAndFlag) & OS_MEM_NODE_ALIGNED_FLAG)
#define OS_MEM_NODE_SET_ALIGNED_FLAG(sizeAndFlag) ((sizeAndFlag) = ((sizeAndFlag) | OS_MEM_NODE_ALIGNED_FLAG))
#define OS_MEM_NODE_GET_ALIGNED_GAPSIZE(sizeAndFlag) ((sizeAndFlag) & (~OS_MEM_NODE_ALIGNED_FLAG))
#define OS_MEM_NODE_GET_USED_FLAG(sizeAndFlag) ((sizeAndFlag) & OS_MEM_NODE_USED_FLAG)
#define OS_MEM_NODE_SET_USED_FLAG(sizeAndFlag) ((sizeAndFlag) = ((sizeAndFlag) | OS_MEM_NODE_USED_FLAG))
#define OS_MEM_NODE_GET_SIZE(sizeAndFlag) ((sizeAndFlag) & (~OS_MEM_NODE_USED_FLAG))
#define OS_MEM_IS_NODE_NEXT_EXIST(node, poolInfo) (((UINT32)(node) + (node)->sizeAndFlag) < \
((UINT32)(poolInfo) + (poolInfo)->uwPoolSize))
#define OS_MEM_HEAD(pool, size) OS_DLNK_HEAD(OS_MEM_HEAD_ADDR(pool), size)
#define OS_MEM_HEAD_ADDR(pool) ((VOID *)((UINT32)(UINTPTR)(pool) + sizeof(LOS_MEM_POOL_INFO)))
#define OS_MEM_NEXT_NODE(node) ((LosMemDynNode *)((UINT8 *)(node) + \
OS_MEM_NODE_GET_SIZE((node)->sizeAndFlag)))
#define OS_MEM_FIRST_NODE(pool) ((LosMemDynNode *)((UINT8 *)OS_MEM_HEAD_ADDR(pool) + OS_DLNK_HEAD_SIZE))
#define OS_MEM_END_NODE(pool, size) ((LosMemDynNode *)(((UINT8 *)(pool) + (size)) - OS_MEM_NODE_HEAD_SIZE))
#define OS_MEM_MIDDLE_ADDR_OPEN_END(startAddr, middleAddr, endAddr) \
(((UINT8 *)(startAddr) <= (UINT8 *)(middleAddr)) && ((UINT8 *)(middleAddr) < (UINT8 *)(endAddr)))
#define OS_MEM_MIDDLE_ADDR(startAddr, middleAddr, endAddr) (((UINT8 *)(startAddr) <= (UINT8 *)(middleAddr)) && \
((UINT8 *)(middleAddr) <= (UINT8 *)(endAddr)))
#define OS_MEM_SET_MAGIC(value) (value) = (LOS_DL_LIST *)(UINTPTR)((UINT32)(UINTPTR)(&(value)) ^ 0xffffffff)
#define OS_MEM_MAGIC_VALID(value) ((((UINT32)(UINTPTR)(value)) ^ ((UINT32)(UINTPTR)(&(value)))) == 0xffffffff)
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_MEMORY_PRI_H */

View File

@ -1,82 +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.
*/
#ifndef _LOS_MEMSTAT_PRI_H
#define _LOS_MEMSTAT_PRI_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_MEMORY_BESTFIT == YES)
extern VOID OsTaskMemUsedInc(UINT32 usedSize, UINT32 taskID);
extern VOID OsTaskMemUsedDec(UINT32 usedSize, UINT32 taskID);
extern UINT32 OsTaskMemUsage(UINT32 taskID);
extern VOID OsTaskMemClear(UINT32 taskID);
#ifdef OS_MEM_ENABLE_MEM_STATISTICS
#define OS_MEM_ADD_USED(usedSize, taskID) OsTaskMemUsedInc(usedSize, taskID)
#define OS_MEM_REDUCE_USED(usedSize, taskID) OsTaskMemUsedDec(usedSize, taskID)
#define OS_MEM_CLEAR(taskID) OsTaskMemClear(taskID)
#else
#define OS_MEM_ADD_USED(usedSize, taskID)
#define OS_MEM_REDUCE_USED(usedSize, taskID)
#define OS_MEM_CLEAR(taskID)
#endif
#else
#if (LOSCFG_KERNEL_MEM_STATISTICS == YES)
typedef struct {
UINT32 memUsed;
UINT32 memPeak;
} TaskMemUsedInfo;
extern VOID OsTaskMemStatInit(TaskMemUsedInfo *memStats);
extern VOID OsTaskMemUsedInc(TaskMemUsedInfo *memStats, UINT32 usedSize, UINT32 taskID);
extern VOID OsTaskMemUsedDec(TaskMemUsedInfo *memStats, UINT32 usedSize, UINT32 taskID);
extern UINT32 OsTaskMemUsage(TaskMemUsedInfo *memStats, UINT32 taskID);
extern VOID OsTaskMemClear(TaskMemUsedInfo *memStats, UINT32 taskID);
#endif
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_MEMSTAT_PRI_H */

View File

@ -1,79 +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.
*/
#ifndef _LOS_MULTIPLE_DLINK_HEAD_PRI_H
#define _LOS_MULTIPLE_DLINK_HEAD_PRI_H
#include "los_list.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define OS_MAX_MULTI_DLNK_LOG2 30
#define OS_MIN_MULTI_DLNK_LOG2 4
#define OS_MULTI_DLNK_NUM ((OS_MAX_MULTI_DLNK_LOG2 - OS_MIN_MULTI_DLNK_LOG2) + 1)
#define OS_DLNK_HEAD_SIZE OS_MULTI_DLNK_HEAD_SIZE
#define OS_DLNK_INIT_HEAD OsDLnkInitMultiHead
#define OS_DLNK_HEAD OsDLnkMultiHead
#define OS_DLNK_NEXT_HEAD OsDLnkNextMultiHead
#define OS_DLNK_FIRST_HEAD OsDLnkFirstMultiHead
#define OS_MULTI_DLNK_HEAD_SIZE sizeof(LosMultipleDlinkHead)
typedef struct {
LOS_DL_LIST listHead[OS_MULTI_DLNK_NUM];
} LosMultipleDlinkHead;
STATIC_INLINE LOS_DL_LIST *OsDLnkNextMultiHead(VOID *headAddr, LOS_DL_LIST *listHead)
{
LosMultipleDlinkHead *head = (LosMultipleDlinkHead *)headAddr;
return (&(head->listHead[OS_MULTI_DLNK_NUM - 1]) == listHead) ? NULL : (listHead + 1);
}
STATIC_INLINE LOS_DL_LIST *OsDLnkFirstMultiHead(VOID *headAddr)
{
return (LOS_DL_LIST *)headAddr;
}
extern VOID OsDLnkInitMultiHead(VOID *headAddr);
extern LOS_DL_LIST *OsDLnkMultiHead(VOID *headAddr, UINT32 size);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_MULTIPLE_DLINK_HEAD_PRI_H */

View File

@ -28,16 +28,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_mux_pri.h"
#include "los_err_pri.h"
#include "los_memory_pri.h"
#include "los_priqueue_pri.h"
#include "los_task_pri.h"
#if (LOSCFG_PLATFORM_EXC == YES)
#include "los_exc.h"
#endif
#include "los_hw.h"
#include "los_mux.h"
#include "los_interrupt.h"
#include "los_memory.h"
#include "los_debug.h"
#ifdef __cplusplus
#if __cplusplus

View File

@ -1,110 +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.
*/
#ifndef _LOS_MUX_PRI_H
#define _LOS_MUX_PRI_H
#include "los_task_pri.h"
#include "los_mux.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_mux
* Mutex object.
*/
typedef struct {
UINT8 muxStat; /**< State OS_MUX_UNUSED,OS_MUX_USED */
UINT16 muxCount; /**< Times of locking a mutex */
UINT32 muxID; /**< Handle ID */
LOS_DL_LIST muxList; /**< Mutex linked list */
LosTaskCB *owner; /**< The current thread that is locking a mutex */
UINT16 priority; /**< Priority of the thread that is locking a mutex */
} LosMuxCB;
/**
* @ingroup los_mux
* Mutex state: not in use.
*/
#define OS_MUX_UNUSED 0
/**
* @ingroup los_mux
* Mutex state: in use.
*/
#define OS_MUX_USED 1
extern LosMuxCB *g_allMux;
/**
* @ingroup los_mux
* Obtain the pointer to a mutex object of the mutex that has a specified handle.
*/
#define GET_MUX(muxid) (((LosMuxCB *)g_allMux) + (muxid))
/**
* @ingroup los_mux
* @brief Initializes the mutex.
*
* @par Description:
* This API is used to initializes the mutex.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param None.
*
* @retval UINT32 Initialization result.
* @par Dependency:
* <ul><li>los_mux_pri.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MuxDelete
*/
extern UINT32 OsMuxInit(VOID);
/**
* @ingroup los_mux
* Obtain the pointer to the linked list in the mutex pointed to by a specified pointer.
*/
#define GET_MUX_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosMuxCB, muxList)
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_MUX_PRI_H */

View File

@ -1,113 +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 "los_priqueue_pri.h"
#include "los_base_pri.h"
#include "los_task_pri.h"
#include "los_memory.h"
#include "los_compiler.h"
LITE_OS_SEC_BSS LOS_DL_LIST *g_losPriorityQueueList = NULL;
static LITE_OS_SEC_BSS UINT32 g_priqueueBitmap = 0;
#define PRIQUEUE_PRIOR0_BIT (UINT32)0x80000000
UINT32 OsPriqueueInit(VOID)
{
UINT32 priority;
UINT32 size = OS_PRIORITY_QUEUE_PRIORITYNUM * sizeof(LOS_DL_LIST);
g_losPriorityQueueList = (LOS_DL_LIST *)LOS_MemAlloc(m_aucSysMem0, size);
if (g_losPriorityQueueList == NULL) {
return LOS_NOK;
}
for (priority = 0; priority < OS_PRIORITY_QUEUE_PRIORITYNUM; ++priority) {
LOS_ListInit(&g_losPriorityQueueList[priority]);
}
return LOS_OK;
}
VOID OsPriqueueEnqueue(LOS_DL_LIST *priqueueItem, UINT32 priority)
{
if (LOS_ListEmpty(&g_losPriorityQueueList[priority])) {
g_priqueueBitmap |= (PRIQUEUE_PRIOR0_BIT >> priority);
}
LOS_ListTailInsert(&g_losPriorityQueueList[priority], priqueueItem);
}
VOID OsPriqueueDequeue(LOS_DL_LIST *priqueueItem)
{
LosTaskCB *runningTask = NULL;
LOS_ListDelete(priqueueItem);
runningTask = LOS_DL_LIST_ENTRY(priqueueItem, LosTaskCB, pendList);
if (LOS_ListEmpty(&g_losPriorityQueueList[runningTask->priority])) {
g_priqueueBitmap &= ~(PRIQUEUE_PRIOR0_BIT >> runningTask->priority);
}
}
LOS_DL_LIST *OsPriqueueTop(VOID)
{
UINT32 priority;
if (g_priqueueBitmap != 0) {
priority = CLZ(g_priqueueBitmap);
return LOS_DL_LIST_FIRST(&g_losPriorityQueueList[priority]);
}
return (LOS_DL_LIST *)NULL;
}
UINT32 OsPriqueueSize(UINT32 priority)
{
UINT32 itemCnt = 0;
LOS_DL_LIST *curPQNode = (LOS_DL_LIST *)NULL;
LOS_DL_LIST_FOR_EACH(curPQNode, &g_losPriorityQueueList[priority]) {
++itemCnt;
}
return itemCnt;
}
UINT32 OsPriqueueTotalSize(VOID)
{
UINT32 priority;
UINT32 totalSize = 0;
for (priority = 0; priority < OS_PRIORITY_QUEUE_PRIORITYNUM; ++priority) {
totalSize += OsPriqueueSize(priority);
}
return totalSize;
}

View File

@ -1,171 +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.
*/
#ifndef _LOS_PRIQUEUE_PRI_H
#define _LOS_PRIQUEUE_PRI_H
#include "los_list.h"
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define OS_PRIORITY_QUEUE_PRIORITYNUM 32
/**
* @ingroup los_priqueue
* @brief Initialize the priority queue.
*
* @par Description:
* This API is used to initialize the priority queue.
* @attention
* <ul>
* <li>None.</li>
* </ul>
* @param none.
*
* @retval LOS_OK on success .
* @retval LOS_NOK on failure.
* @par Dependency:
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
* @see none.
*/
extern UINT32 OsPriqueueInit(VOID);
/**
* @ingroup los_priqueue
* @brief Insert a item to the priority queue.
*
* @par Description:
* This API is used to insert a item to the priority queue according to the priority of this item.
* @attention
* <ul>
* <li>Param priqueueItem must point to valid memory.</li>
* <li>Param priority rang is [0, OS_PRIORITY_QUEUE_PRIORITYNUM),included 0 and not included
LOS_PRIORITY_QUEUE_PRIORITYNUM.</li>
* </ul>
* @param priqueueItem [IN] The node of item to be inserted.
* @param priority [IN] Priority of the item be inserted.
*
* @retval none.
* @par Dependency:
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
* @see OsPriqueueDequeue.
*/
extern VOID OsPriqueueEnqueue(LOS_DL_LIST *priqueueItem, UINT32 priority);
/**
* @ingroup los_priqueue
* @brief Delete a item from the priority queue.
*
* @par Description:
* This API is used to delete a item from the priority queue.
* @attention
* <ul>
* <li>Param priqueueItem must point to valid memory.</li>
* </ul>
* @param priqueueItem [IN] The node of item to be deleted.
*
* @retval none.
* @par Dependency:
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
* @see OsPriqueueEnqueue.
*/
extern VOID OsPriqueueDequeue(LOS_DL_LIST *priqueueItem);
/**
* @ingroup los_priqueue
* @brief Obtain the item with highest priority.
*
* @par Description:
* This API is used to obtain the item with highest priority in the priority queue.
* @attention
* <ul>
* <li>None.</li>
* </ul>
* @param none.
*
* @retval NULL : The priority queue is empty.
* @retval item node : The node of the item with highest priority.
* @par Dependency:
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
* @see none.
*/
extern LOS_DL_LIST *OsPriqueueTop(VOID);
/**
* @ingroup los_priqueue
* @brief Obtain the number of items with the specified priority.
*
* @par Description:
* This API is used to obtain the number of items with the specified priority.
* @attention
* <ul>
* <li>Param priority rang is [0, OS_PRIORITY_QUEUE_PRIORITYNUM),included 0 and not included
LOS_PRIORITY_QUEUE_PRIORITYNUM.</li>
* </ul>
* @param priority [IN] Obtain the number of items with the specified priority of priority.
*
* @retval The number of items :The number of items with the specified priority.
* @par Dependency:
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
* @see none.
*/
extern UINT32 OsPriqueueSize(UINT32 priority);
/**
* @ingroup los_priqueue
* @brief Obtain the total number of items in the priority queue.
*
* @par Description:
* This API is used to obtain the number of items in the priority queue.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval The number of items: The total number of items in the priority queue.
* @par Dependency:
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
* @see none.
*/
extern UINT32 OsPriqueueTotalSize(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_PRIQUEUE_PRI_H */

View File

@ -28,18 +28,15 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "string.h"
#include "los_interrupt.h"
#include "securec.h"
#include "los_queue_pri.h"
#include "los_membox_pri.h"
#include "los_memory_pri.h"
#include "los_priqueue_pri.h"
#include "los_task_pri.h"
#include "los_queue.h"
#include "los_membox.h"
#include "los_task.h"
#if (LOSCFG_PLATFORM_EXC == YES)
#include "los_exc_pri.h"
#include "los_interrupt.h"
#endif
#include "los_printf.h"
#include "los_debug.h"
#ifdef __cplusplus

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