1、liteos 目前支持多款平台
具体支持的平台在目录:
\LiteOS-master\targets,以 STM32F103RB_NUCLEO 为例。
其入口函数在 \LiteOS-master\targets\STM32F103RB_NUCLEO\GCC\los_startup_gcc.s 中的 Reset_Handler
入口函数:
Reset_Handler:
#设定栈指针
ldr sp, =_estack /* set stack pointer */
/* Copy the vector_ram segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyVectorInit
#拷贝中断向量
CopyVectorInit:
ldr r3, =_si_liteos_vector_data
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopCopyVectorInit:
ldr r0, =_s_liteos_vector
ldr r3, =_e_liteos_vector
adds r2, r0, r1
cmp r2, r3
bcc CopyVectorInit
#将 data 段从 flash 拷贝到 sram 中
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
CopyDataInit:
ldr r3, =_sidata
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopCopyDataInit:
ldr r0, =_sdata
ldr r3, =_edata
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
b LoopFillZerobss
# 清零 bss 段
/* Zero fill the bss segment. */
FillZerobss:
movs r3, #0
str r3, [r2], #4
LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
/* Call the clock system initialization function.*/
#时钟初始化
bl SystemInit
/* Call static constructors */
bl __libc_init_array
/* Call the application's entry point.*/
#开始调到c语言的入口函数
bl main
LiteOS-master\LiteOS-master\targets\STM32F103RB_NUCLEO\Src\main.c
int main(void)
{
UINT32 uwRet = LOS_OK;
//初始化硬件,这个函数主要设置系统时钟和uart
HardWare_Init();
//os初始化,os支持的各种特性都在这个函数中初始化
uwRet = LOS_KernelInit();
if (uwRet != LOS_OK)
{
return LOS_NOK;
}
//建一个线程
LOS_Inspect_Entry();
//让os开启动调度
LOS_Start();
}
2、线程入口
UINT32 LOS_Inspect_Entry(VOID)
{
UINT32 uwRet;
TSK_INIT_PARAM_S stTaskInitParam;
//线程结构体清零
(VOID)memset((VOID *)(&stTaskInitParam), 0, sizeof(TSK_INIT_PARAM_S));
//设置线程的执行函数
stTaskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)LOS_Inspect_TskDeal;
//设置线程的栈大小
stTaskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE;
//设置线程的名字
stTaskInitParam.pcName = "InspectTsk";
//设置线程的优先级
stTaskInitParam.usTaskPrio = 9;
//开始创建线程
uwRet = LOS_TaskCreate(&g_uwDemoTaskID, &stTaskInitParam);
if (uwRet != LOS_OK)
{
return LOS_NOK;
}
return LOS_OK;
}
3、线程回调函数
static VOID LOS_Inspect_TskDeal(VOID)
{
UINT32 ulRet = LOS_OK;
gInspectErrCnt = 0;
/* output a message on hyperterminal using printf function */
dprintf("\r\nLos Inspect start.\r\n");
for(UINT32 index = 0;index < LOS_INSPECT_BUFF; index++)
{
ulRet = LOS_InspectByID((enInspectID)index);
if(LOS_OK != ulRet)
{
gInspectErrCnt++;
}
}
dprintf("Inspect completed,gInspectErrCnt = [%d]\r\n\r\n", gInspectErrCnt);
while(1);
}
refer:
https://blog.csdn.net/tiantao2012/article/details/86600668