Java教程

RTX笔记2 - RTX5时间管理

本文主要是介绍RTX笔记2 - RTX5时间管理,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

  osStatus_t osDelay (uint32_t ticks):相对时间延时

  osStatus_t osDelayUntil (uint32_t ticks):绝对时间延时

 1 static void
 2 _Led1Task(void *argument)
 3 {
 4     (void)argument;
 5     
 6     for(;;) {
 7         ledOn(&led1);
 8         osDelay(500); /** delay 500 RTOS ticks **/
 9         ledOff(&led1);
10         osDelay(500); /** delay 500 RTOS ticks **/
11     }
12 }
13 
14 static void
15 _segLedTask(void *argument)
16 {
17     (void)argument;
18     uint32_t tick;
19     static const uint8_t seg_code[] =
20     {
21         DEF_LED_0,
22         DEF_LED_1,
23         DEF_LED_2,
24         DEF_LED_3,
25         DEF_LED_4,
26         DEF_LED_5,
27         DEF_LED_6,
28         DEF_LED_7,
29         DEF_LED_8,
30         DEF_LED_9,
31     };
32     uint8_t sc_sz;
33     uint8_t start_ix;
34     uint8_t ix;
35     
36     start_ix = 0;
37     sc_sz = ARRAYSIZE(seg_code);
38     tick = osKernelGetTickCount();
39     
40     for(;;) {
41         tick += 1000;
42         osDelayUntil(tick); /** waits until an absolute time (1000 kernel ticks) is reached **/
43         
44         for(ix=0; ix < LED_GRID_NBR_MAX; ix++) {
45             seg_led.buf[ix] = seg_code[(start_ix+ix)%sc_sz];
46         }
47         
48         start_ix ++;
49         if(start_ix >= sc_sz) {
50             start_ix = 0;
51         }
52         
53         ledRefresh(&seg_led);
54     }
55 }

 

这篇关于RTX笔记2 - RTX5时间管理的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!