CH32V208开发板开发板使用沁恒CH32V208WBU6主控,RISC-V架构。片内资源RAM:64KB,Flash:128KB(RAM,Flash可灵活配置)。开环环境IDE:MounRiver Studio.
官方SDK有移植好HarmonyOS的例程,这里做下梳理与学习。工程如下:
1.工程中加载了LiteOS库。在ch32v20x_it.c配置好了中断接入。system_ch32v20x.c配置好了主频与时钟节拍。
2.在main函数可以看到引用系统头文件
#include "debug.h"
#include "los_tick.h"
#include "los_task.h"
#include "los_config.h"
#include "los_interrupt.h"
#include "los_debug.h"
#include "los_compiler.h"
3.主函数如下,初始化了系统时钟、串口及LiteOS内核。通过taskSample创建示例任务,并随后 LOS_Start();启动。
LITE_OS_SEC_TEXT_INIT int main(void)
{
unsigned int ret;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
SystemCoreClockUpdate();
Delay_Init();
USART_Printf_Init(115200);
printf("SystemClk:%d\r\n",SystemCoreClock);
printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
ret = LOS_KernelInit();
taskSample();
if (ret == LOS_OK)
{
LOS_Start();
}
printf("shouldn't run at here!!!\r\n");
while (1) {
__asm volatile("nop");
}
}
4.任务创建如下,任务创建API为LOS_TaskCreate,创建了任务taskSampleEntry1和taskSampleEntry2
UINT32 taskSample(VOID)
{
UINT32 uwRet;
UINT32 taskID1,taskID2;
TSK_INIT_PARAM_S stTask={0};
stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry1;
stTask.uwStackSize = 0X500;
stTask.pcName = "taskSampleEntry1";
stTask.usTaskPrio = 6;
uwRet = LOS_TaskCreate(&taskID1, &stTask);
if (uwRet != LOS_OK) {
printf("create task1 failed\n");
}
stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry2;
stTask.uwStackSize = 0X500;
stTask.pcName = "taskSampleEntry2";
stTask.usTaskPrio = 7;
uwRet = LOS_TaskCreate(&taskID2, &stTask);
if (uwRet != LOS_OK) {
printf("create task2 failed\n");
}
EXTI0_INT_INIT();
return LOS_OK;
}
5.任务函数如下,可以看到循环延时2s/10s打印SP寄存器地址
VOID taskSampleEntry1(VOID)
{
while(1) {
LOS_TaskDelay(2000);
printf("taskSampleEntry1 running,task1 SP:%08x\n",__get_SP());
}
}
VOID taskSampleEntry2(VOID)
{
while(1) {
LOS_TaskDelay(10000);
printf("taskSampleEntry2 running,task2 SP:%08x\n",__get_SP());
}
}
6.编译烧录,日志如下
对于LiteOS库可以做更输入了解,作为国产系统,还是值得推广应用的。从日志也可看出,HarmonyOS系统正常运行了起来。
|