kernel_liteos_m移植到正点原子阿波罗F429_keil版
前期准备
先调通打印点击跳转
能正常打印源码下载
下载代码仓
kernel_liteos_m源码
third_party_bounds_checking_function源码
使用git下载固定OpenHarmony-v6.0-Release节点,避免后续更新导致的编译失败
git clone git@gitee.com:openharmony/third_party_bounds_checking_function.git -b OpenHarmony-v6.0-Releasegit clone git@gitee.com:openharmony/kernel_liteos_m.git -b OpenHarmony-v6.0-Release
移植
新建文件夹
如果上面没有问题,你会有3个文件夹
在自己工程的目录下新增liteos文件夹
把kernel_liteos_m的arch、components、kernal、utils文件夹复制到自己的liteos目录下,再新建一个securec文件夹
kernel
删除BUILD.gn文件,只留两个文件夹即可
arch
arch下只留arm和include文件夹
arm目录下只留common、cortex-m4、include目录
cortex-m4下只留keil
components
components下只留exchook和signal
utils
不动
securec
把third_party_bounds_checking_function目录下include和src拷贝到securec目录下。
src下只保留memcpy_s.c、memset_s.c、strncpy_s.c、securecutil.h
文件
keil
新建文件夹
打开keil的配置,准备添加需要编译的文件
先新建5个跟文件夹前缀带liteos。
liteos/arch
liteos/components
liteos/kernal
liteos/utils
liteos/securec
添加头文件目录
记得一定要点OK才是保存
编译及错误修复
到这里你可以到尝试编译一次;会提示找不到target_config.h和sigset_t未定义
target_config.h
/** Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.** Redistribution and use in source and binary forms, with or without modification,* are permitted provided that the following conditions are met:** 1. Redistributions of source code must retain the above copyright notice, this list of* conditions and the following disclaimer.** 2. Redistributions in binary form must reproduce the above copyright notice, this list* of conditions and the following disclaimer in the documentation and/or other materials* provided with the distribution.** 3. Neither the name of the copyright holder nor the names of its contributors may be used* to endorse or promote products derived from this software without specific prior written* permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*//**@defgroup los_config System configuration items* @ingroup kernel*/#ifndef _TARGET_CONFIG_H
#define _TARGET_CONFIG_H#include "stm32f4xx.h"
#include "stm32f4xx_it.h"#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus *//*=============================================================================System clock module configuration
=============================================================================*/
#define OS_SYS_CLOCK SystemCoreClock
#define LOSCFG_BASE_CORE_TICK_PER_SECOND (1000UL)
#define LOSCFG_BASE_CORE_TICK_HW_TIME 0
#define LOSCFG_BASE_CORE_TICK_WTIMER 0
#define LOSCFG_BASE_CORE_TICK_RESPONSE_MAX SysTick_LOAD_RELOAD_Msk/*=============================================================================Hardware interrupt module configuration
=============================================================================*/
#define LOSCFG_PLATFORM_HWI 1
#define LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT 1
#define LOSCFG_PLATFORM_HWI_LIMIT 128
/*=============================================================================Task module configuration
=============================================================================*/
#define LOSCFG_BASE_CORE_TSK_LIMIT 24
#define LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE (0x500U)
#define LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE (0x2D0U)
#define LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE (0x130U)
#define LOSCFG_BASE_CORE_TIMESLICE 1
#define LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT 20000
/*=============================================================================Semaphore module configuration
=============================================================================*/
#define LOSCFG_BASE_IPC_SEM 1
#define LOSCFG_BASE_IPC_SEM_LIMIT 48
/*=============================================================================Mutex module configuration
=============================================================================*/
#define LOSCFG_BASE_IPC_MUX 1
#define LOSCFG_BASE_IPC_MUX_LIMIT 24
/*=============================================================================Queue module configuration
=============================================================================*/
#define LOSCFG_BASE_IPC_QUEUE 1
#define LOSCFG_BASE_IPC_QUEUE_LIMIT 24
/*=============================================================================Software timer module configuration
=============================================================================*/
#define LOSCFG_BASE_CORE_SWTMR 1
#define LOSCFG_BASE_CORE_SWTMR_ALIGN 0
#define LOSCFG_BASE_CORE_SWTMR_LIMIT 48
/*=============================================================================Memory module configuration
=============================================================================*/
#define LOSCFG_MEM_MUL_POOL 1
#define OS_SYS_MEM_NUM 20
/*=============================================================================Exception module configuration
=============================================================================*/
#define LOSCFG_PLATFORM_EXC 1
/* =============================================================================printf module configuration
============================================================================= */
#define LOSCFG_KERNEL_PRINTF 0#define LOSCFG_BASE_CORE_SCHED_SLEEP 1#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */#endif /* _TARGET_CONFIG_H */
把target_config.h文件放到arch\include下。
los_signal.h
/** Copyright (c) 2022-2022 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_SIGNAL_H
#define _LOS_SIGNAL_H#include <signal.h>
#include "los_list.h"#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus *//*** @ingroup los_signal* Signal error code: The parameters of interface is error.** Value: 0x02003200**/
#define LOS_ERRNO_SIGNAL_INVALID LOS_ERRNO_OS_FATAL(LOS_MOD_SIGNAL, 0x00)/*** @ingroup los_signal* Signal error code: The memory requests failed.** Value: 0x02003201**/
#define LOS_ERRNO_SIGNAL_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_SIGNAL, 0x01)/*** @ingroup los_signal* Signal error code: The signal is not set.** Value: 0x02003202**/
#define LOS_ERRNO_SIGNAL_NO_SET LOS_ERRNO_OS_ERROR(LOS_MOD_SIGNAL, 0x02)/*** @ingroup los_signal* Signal error code: Waiting for signal timeout.** Value: 0x02003203**/
#define LOS_ERRNO_SIGNAL_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_SIGNAL, 0x03)/*** @ingroup los_signal* Signal error code: The interface is used before system start.** Value: 0x02003204**/
#define LOS_ERRNO_SIGNAL_CAN_NOT_CALL LOS_ERRNO_OS_ERROR(LOS_MOD_SIGNAL, 0x04)/**
* @ingroup los_signal
* Mutex error code: Waiting for signal in interrupt callback.
*
* Value: 0x02003205
*
*/
#define LOS_ERRNO_SIGNAL_PEND_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_SIGNAL, 0x05)/*** @ingroup los_signal* Add the signal num to the signal set.*/
#define LOS_SIGNAL_MASK(sigNo) (1U << ((sigNo) - 1))/*** @ingroup los_signal* Maximum signal supported num.*/
#define LOS_SIGNAL_SUPPORT_MAX 31/*** @ingroup los_signal* Signal handler type.*/
typedef VOID (*SIG_HANDLER)(INT32 sigNo);#if (LOSCFG_KERNEL_SIGNAL == 1)
typedef struct {sigset_t sigSetFlag; /**< installing signals */sigset_t sigPendFlag; /**< pending signals */sigset_t sigWaitFlag; /**< waiting signals */siginfo_t sigInfo; /**< signal info */SIG_HANDLER sigHandlers[LOS_SIGNAL_SUPPORT_MAX + 1]; /**< signal handler */LOS_DL_LIST sigInfoList; /**< signal info list */VOID *sigSaveSP; /**< save stack pointer */VOID *sigRestoreSP; /**< restore stack pointer */UINT32 sigStatus; /**< status of signal */
} OsSigCB;typedef struct {LOS_DL_LIST node;siginfo_t info;
} OsSigInfoNode;#define OS_SIGNAL_STATUS_WAIT 0x0001
#define OS_SIGNAL_VALID(sigNo) (((sigNo) > 0) && ((sigNo) <= LOS_SIGNAL_SUPPORT_MAX))UINT32 OsSignalInit(VOID);
#endif
UINTPTR OsSignalTaskContextRestore(VOID);
#if (LOSCFG_KERNEL_SIGNAL == 1)
/*** @ingroup los_signal* @brief Register the handler for the specified signal.** @par Description:* This API is used to register the handler for the specified signal, otherwise it is the default handler.** @attention None.** @param sigNo [IN] The specified signal num.* @param handler [IN] The handler for this signal, which is either SIG_IGN, SIG_DFL,* or the address of a programmer-defined function.** @retval: SIG_ERR Type#SIG_HANDLER: error code.* @retval: old Type#SIG_HANDLER: success, the previous handler is returned.* <ul><li>los_signal.h: the header file that contains the API declaration.</li></ul>* @see None*/
SIG_HANDLER LOS_SignalSet(INT32 sigNo, SIG_HANDLER handler);/*** @ingroup los_signal* @brief Shield the specified signal set.** @par Description:* This API is used to shield the specified signal set and get the current signal set.** @attention None.** @param how [IN] The behavior of the call is dependent on the value of how, which is either SIG_BLOCK,* SIG_UNBLOCK, SIG_SETMASK.* @param set [IN] The new signal set.* @param oldSet [OUT] The old signal set.** @retval: LOS_ERRNO_SIGNAL_CAN_NOT_CALL Type#UINT32: The interface is used before system start.* @retval: LOS_ERRNO_SIGNAL_NO_MEMORY Type#UINT32: The memory requests failed.* @retval: LOS_ERRNO_SIGNAL_INVALID Type#UINT32: The parameters of interface is error.* @retval: LOS_OK Type#UINT32: success.* <ul><li>los_signal.h: the header file that contains the API declaration.</li></ul>* @see None*/
UINT32 LOS_SignalMask(INT32 how, const sigset_t *set, sigset_t *oldSet);/*** @ingroup los_signal* @brief Suspend execution of the calling thread until one of the signals specified in* the signal set becomes pending.** @par Description:* This API is used to suspend execution of the calling thread until one of the signals* specified in the signal set becomes pending and return the signal number in sig.** @attention None.** @param set [IN] The specified signal set which waiting for.* @param info [OUT] The info of signal becomes pending.* @param timeout [IN] The waiting time.** @retval: LOS_ERRNO_SIGNAL_INVALID Type#UINT32: The parameters of interface is error.* @retval: LOS_ERRNO_SIGNAL_CAN_NOT_CALL Type#UINT32: The interface is used before system start.* @retval: LOS_ERRNO_SIGNAL_NO_MEMORY Type#UINT32: The memory requests failed.* @retval: LOS_ERRNO_SIGNAL_PEND_INTERR Type#UINT32: Waiting for signal in interrupt callback.* @retval: LOS_ERRNO_SIGNAL_TIMEOUT Type#UINT32: Waiting for signal timeout.* @retval: signo Type#UINT32: success, returning the signal num which becomes pending.* <ul><li>los_signal.h: the header file that contains the API declaration.</li></ul>* @see LOS_SignalSend*/
UINT32 LOS_SignalWait(const sigset_t *set, siginfo_t *info, UINT32 timeout);/*** @ingroup los_signal* @brief Send the specified signal to the specified task.** @par Description:* This API is used to send the specified signal to the specified task.** @attention None.** @param taskID [IN] Send a signal to this task.* @param sigNo [IN] The signal num.** @retval: LOS_ERRNO_SIGNAL_NO_MEMORY Type#UINT32: The memory requests failed.* @retval: LOS_ERRNO_SIGNAL_INVALID Type#UINT32: The parameters of interface is error.* @retval: LOS_ERRNO_SIGNAL_NO_SET Type#UINT32: The signal is not set.* @retval: LOS_OK Type#UINT32: success.* <ul><li>los_signal.h: the header file that contains the API declaration.</li></ul>* @see None*/
UINT32 LOS_SignalSend(UINT32 taskID, INT32 sigNo);
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */#endif /* _LOS_SIGNAL_H */
就是sigset_t在keil未定位,需要屏蔽下。
在.h的115行和141加上
#if (LOSCFG_KERNEL_SIGNAL == 1)
在.h的139行和231加上
#endif
到此编译成功。
上板运行
需要在main调用下任务初始哈函数:
user_main.c
#include "user_main.h"#include "printf.h"#include "stm32f4xx_hal.h"#include "los_task.h"VOID TaskSampleEntry2(VOID)
{while (1) {Printf("TaskSampleEntry2 running...\n");(VOID)LOS_TaskDelay(2000);}
}VOID TaskSampleEntry1(VOID)
{while (1) {Printf("TaskSampleEntry1 running...\n");(VOID)LOS_TaskDelay(1000);}
}
VOID TaskSample(VOID)
{UINT32 uwRet;UINT32 taskID1;UINT32 taskID2;TSK_INIT_PARAM_S stTask = {0};stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskSampleEntry1;stTask.uwStackSize = 0x1000;stTask.pcName = "TaskSampleEntry1";stTask.usTaskPrio = 6; /* Os task priority is 6 */uwRet = LOS_TaskCreate(&taskID1, &stTask);if (uwRet != LOS_OK) {Printf("Task1 create failed\n");}stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskSampleEntry2;stTask.uwStackSize = 0x1000;stTask.pcName = "TaskSampleEntry2";stTask.usTaskPrio = 7; /* Os task priority is 7 */uwRet = LOS_TaskCreate(&taskID2, &stTask);if (uwRet != LOS_OK) {Printf("Task2 create failed\n");}
}void UserMain(void)
{Printf("Hello, World!\r\n");UINT32 ret = LOS_KernelInit(); //初始化内核。if (ret == LOS_OK) {TaskSample(); //示例任务函数,在此函数中创建线程任务。LOS_Start(); //开始任务调度,程序执行将阻塞在此,由内核接管调度。}while(1) {HAL_Delay(1000);Printf("Hello World!\r\n");}
}
编译烧录运行,串口打印如下,移植成功