进入首个函数中我们就需要建立任务
代码事例:
图上是RTX的接口代码所以,所用的栈地址,和栈大小有点不一样,uCOSII的是如下定义:
static uint32_t taskLedStk[TASK_LED_STK_SIZE] = {0};
osThreadDef(TaskLed, TASK_LED_PRIO, taskLedStk, TASK_LED_STK_SIZE);
下面介绍信号量样例代码:
osSemaphoreDef(LED_CTRL); //定义信号量
osSemaphoreId osSem = NULL; //信号量句柄
osSem = osSemaphoreCreate(osSemaphore(LED_CTRL), 0); //建立一个信号量 初值为0
osSemaphoreRelease(osSem); //释放一个信号量
定时回调函数事例代码:
#include "cmsis_os.h"
void Timer1_Callback (void const *arg); // prototypes for timer callback function
void Timer2_Callback (void const *arg);
osTimerDef (Timer1, Timer1_Callback); // define timers
osTimerDef (Timer2, Timer2_Callback);
uint32_t exec1; // argument for the timer call back function
uint32_t exec2; // argument for the timer call back function
void TimerCreate_example (void) {
osTimerId id1; // timer id
osTimerId id2; // timer id
// Create one-shoot timer
exec1 = 1;
id1 = osTimerCreate (osTimer(Timer1), osTimerOnce, &exec1);
if (id1 != NULL) {
// One-shoot timer created
}
// Create periodic timer
exec2 = 2;
id2 = osTimerCreate (osTimer(Timer2), osTimerPeriodic, &exec2);
if (id2 != NULL) {
// Periodic timer created
}
:
}
|