Files
cosyos/Demo-Build/demo_task.c
T
2025-12-24 10:55:21 +00:00

64 lines
2.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**************************************************************************//**
* @item CosyOS-III 例程(系统构建)
* @file demo_task.c
* @brief 例程-任务
* @author 迟凯峰
* @version V1.0.4
* @date 2025.12.24
******************************************************************************/
#if 0 /* 编译开关 */
#include "CosyOS.H" // 用户的各个c文件中应包含此文件
#include <stdio.h> // for printf
/*-----------------------*
| 创建任务 - 参数说明表 |
|-----------------------+-----------------------------------------------------------*
| 任务名称 | 任务优先级 | 任务栈大小 | 安全运行时 | 任务名称文本(兼容模式) |
|----------+------------+------------+------------+---------------------------------|
| task_1 | 1级 | 384字节 | 0为无限长 | 0为自动引用任务名称,即"task_1" |
|----------+------------+------------+------------+---------------------------------|
| task_2 | 2级 | 384字节 | 9滴答周期 | "task_led"为任务名称文本 |
*-----------------------------------------------------------------------------------*/
/*
注意事项 for 8051
1、在默认情况下,任务栈SIZE不允许大于255。
2、只有在启用了XBPSTACK的任务切换现场保护时,任务栈SIZE才允许大于255,最大可为65535。
*/
/* 静态创建 task_1 */
uCreateTask(task_1, 1, 384, 0, 0)
{
while(1){
printf("task_1\r\n");
uDelay_ms(1000);
}
}
/* 动态创建 task_2 */
dCreateTask(task_2, 2, 384, 9, "task_led")
{
while(1){
printf("task_2\r\n");
uDelay_ms(1000);
}
}
/*
* 启动钩子
* 除了启动用户任务以外,启动钩子还适用于那些允许缓期执行的、
* 需要开中断以后执行的、需要调用任务级服务执行的初始化工作。
* 如果不想在启动任务过程中进行任务调度,可开启调度锁。
*/
void start_hook(void)
{
// uScheduleLock();
uStartTask_Ready(task_1); // 启动 task_1,初始状态为就绪状态
uStartTask_Ready(task_2); // 启动 task_2,初始状态为就绪状态
// uScheduleUnlock();
}
#endif