stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskSampleEntry2;
stTask.uwStackSize = 0x800;
stTask.pcName = "TaskSampleEntry2";
stTask.usTaskPrio = 6; /* Os task priority is 6 */
uwRet = LOS_TaskCreate(&taskID2, &stTask);
if (uwRet != LOS_OK) {
printf("Task2 create failed\n");
}
}
/**
* @brief This is the ohos entry, and you could call this in your main funciton after the
* necessary hardware has been initialized.
*/
void OHOS_Boot(void)
{
UINT32 ret;
before_ohos_run();
ret = LOS_KernelInit();
if (ret == LOS_OK) {
OHOS_SystemInit();
TaskSample();
LOS_Start();
}
return; // and should never come here
}
```
3. 运行结果、错误截图
这是运行结果
// 检查 PRIMASK 状态确认全局中断是否启用
if (CheckPrimaskStatus()) {
// 如果中断被禁用,启用中断
__asm volatile ("CPSIE i"); // 使能中断
printf("Interrupts were disabled, now enabled\n");
} else {
// 中断已经启用
printf("Interrupts are enabled\n");
}
}
```
其结果如下所示
```
CheckSystemStatus
PendSV priority was incorrect 0x0, fixed to 0xF0
PendSV is not set
Manually triggering PendSV...
Interrupts were disabled, now enabled
```
函数执行的位置在 `LOS_KernelIni`之后
```
void OHOS_Boot(void)
{
UINT32 ret;
before_ohos_run();
ret = LOS_KernelInit();
if (ret == LOS_OK) {
TaskSample();
PrintVectorTable();
OsGetAllTskInfo();
CheckSystemStatus();
LOS_Start();
}
return; // and should never come here
}
```
```
int main(void)
{
int i = 0;
hal_clock_init(hal_clk_150M);
uart3_init();
systick_init();
OHOS_Boot();