这篇来学习下,XR806开发板在FreeRTOS系统下创建两个任务测试,由于没有找到学习的文档,试着参考例程来测试。
一、复制工程
上篇测试了hello_demo的测试例程,直接复制这个工程文件,在此基础上修改
root@ubuntu:/home/xr806_sdk/project/demo# cp -r hello_demo/ task_demo/
复制完成后,文件如下:
修改 /demo/task_demo/gcc目录下的defconfig文件
root@ubuntu:/home/xr806_sdk/project/demo/task_demo/gcc# vi defconfig
二、代码
2.1、main.c
#include "common/framework/platform_init.h"
#include <stdio.h>
#include "kernel/os/os.h"
#include "task.h"int main(void)
{platform_init();task_init();return 0;
}
2.2、task.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "kernel/os/os.h"#define START_THREAD_STACK_SIZE (512)
#define THREAD_STACK1_SIZE (512)
#define THREAD_STACK2_SIZE (512)static OS_Thread_t start_task_thread;
static OS_Thread_t task1_thread;
static OS_Thread_t task2_thread;static void task1(void *arg)
{while (1){printf("task1 running....\n");OS_MSleep(100);}
}static void task2(void *arg)
{while (1){printf("task2 running....\n");OS_MSleep(200);}
}static void start_task(void *arg)
{//create task1if (OS_ThreadCreate(&task1_thread,"task1",task1,NULL,OS_THREAD_PRIO_APP,THREAD_STACK1_SIZE) != OS_OK) {printf("thread create task1 error\n");}//create task2if (OS_ThreadCreate(&task2_thread,"task2",task2,NULL,OS_THREAD_PRIO_APP,THREAD_STACK2_SIZE) != OS_OK) {printf("thread create task2 error\n");}OS_ThreadDelete(&start_task_thread);
}int task_init(void)
{if (OS_ThreadCreate(&start_task_thread,"start_task",start_task,NULL,OS_THREAD_PRIO_APP,START_THREAD_STACK_SIZE) != OS_OK) {printf("thread create error\n");return -1;}return 0;
}
三、程序运行
编译完成后,下载镜像到开发板。
复位开发板运行后,串口输出: