代码片段
CMSIS-RTOS,版本V1
- 延时函数,也可以当成HAL_delay函数
void delay (unsigned int count)
{
unsigned int index;
for(index =0;index<count;index++)
{
;
}
}
- 任务一
void led_thread1 (void const *argument)
{
static uint32_t num = 0;
for (;;)
{
num++ ;
LED_On(1);
//delay(500);
LED_Off(1);
//delay(500);
osDelay(50);
}
}
- 任务二
void led_thread2 (void const *argument)
{
for (;;)
{
LED_On(2);
delay(25);
// osDelay(25);
LED_Off(2);
//delay(500);
osDelay(50);
}
}
- 定义线程
osThreadId main_ID,led_ID1,led_ID2;
osThreadDef(led_thread2, osPriorityNormal, 1, 0);
//osThreadDef(led_thread1, osPriorityNormal, 1, 0);
osThreadDef(led_thread1, osPriorityLow, 1, 0);
- 创建线程
int main (void)
{
osKernelInitialize (); // initialize CMSIS-RTOS
LED_Initialize ();
led_ID2 = osThreadCreate(osThread(led_thread2), NULL);
led_ID1 = osThreadCreate(osThread(led_thread1), NULL);
osKernelStart (); // start thread execution
while(1)
{
osDelay(50);
}
}
官方文档
结果显示
在stop/start debug session模式下,在工具栏中的Debug->OS Support->Event Viewer或者是System and Thread Viewer
- 延时的效果