1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#include "Application.h"
/**************************** 任务句柄 ********************************/
/*
* 任务句柄是一个指针,用于指向一个任务,当任务创建好之后,它就具有了一个任务句柄
* 以后我们要想操作这个任务都需要通过这个任务句柄,如果是自身的任务操作自己,那么
* 这个句柄可以为NULL。
*/
static TaskHandle_t COLOR_LED_Handle = NULL; /* LED任务句柄 */
static TaskHandle_t TEST_TASK_Handle = NULL; /* 任务句柄 */
/********************************** 内核对象句柄 *********************************/
/*
* 信号量,消息队列,事件标志组,软件定时器这些都属于内核的对象,要想使用这些内核
* 对象,必须先创建,创建成功之后会返回一个相应的句柄。实际上就是一个指针,后续我
* 们就可以通过这个句柄操作这些内核对象。
*
* 内核对象说白了就是一种全局的数据结构,通过这些数据结构我们可以实现任务间的通信,
* 任务间的事件同步等各种功能。至于这些功能的实现我们是通过调用这些内核对象的函数
* 来完成的
*
*/
/******************************* 全局变量声明 ************************************/
/*
* 当我们在写应用程序的时候,可能需要用到一些全局变量。
*/
/*
*************************************************************************
* 函数声明
*************************************************************************
*/
void app_main_delay_ms(uint16_t ms);
/*
*************************************************************************
*************************************************************************
*/
/// @brief 创建任务
/// @param
void AppTaskCreate(void)
{
taskENTER_CRITICAL(); // 进入临界区
BaseType_t xReturn = pdPASS; /* 定义一个创建信息返回值,默认为pdPASS */
uint32_t count = 0;
/* 创建Test_Task任务 */
xReturn = xTaskCreate((TaskFunction_t)color_led_task_fun, /* 任务入口函数 */
(const char *)"COLOR_LED_TASK", /* 任务名字 */
(uint16_t)256, /* 任务栈大小 */
(void *)NULL, /* 任务入口函数参数 */
(UBaseType_t)osPriorityNormal, /* 任务的优先级 */
(TaskHandle_t *)&COLOR_LED_Handle); /* 任务控制块指针 */
if (pdPASS != xReturn)
{
goto error;
}
UART1_Printf("COLOR_LED_TASK[info]:Runing, Priority:%d\n", osPriorityNormal);
xReturn = xTaskCreate((TaskFunction_t)test_task_fun, /* 任务入口函数 */
(const char *)"TEST_TASK", /* 任务名字 */
(uint16_t)256, /* 任务栈大小 */
(void *)NULL, /* 任务入口函数参数 */
(UBaseType_t)osPriorityNormal, /* 任务的优先级 */
(TaskHandle_t *)&TEST_TASK_Handle); /* 任务控制块指针 */
if (pdPASS != xReturn)
{
goto error;
}
UART1_Printf("TEST_TASK[info]:Runing, Priority:%d\n", osPriorityNormal);
return;
error:
UART1_Printf("App_Task_Create[error]:Task Create fail,system exception\n");
while (1)
{
UART1_Printf("error count:%d\n", (int)count++);
app_main_delay_ms(1000);
}
taskEXIT_CRITICAL(); // 退出临界区
}
void app_main_delay_ms(uint16_t ms)
{
vTaskDelay(pdMS_TO_TICKS(ms));
}
|