8
8
* GLOBAL VARIABLES
9
9
**************************************************************************************/
10
10
11
- TaskHandle_t blinky_thread_hdl ;
11
+ TaskHandle_t loop_task, blinky_task ;
12
12
13
13
/* *************************************************************************************
14
14
* SETUP/LOOP
@@ -19,37 +19,78 @@ void setup()
19
19
Serial.begin (115200 );
20
20
while (!Serial) { }
21
21
22
- /* Init RTOS tasks. */
23
- auto const rc = xTaskCreate
22
+ pinMode (LEDR, OUTPUT);
23
+ digitalWrite (LEDR, LOW);
24
+
25
+ /* Init a task that calls 'loop'
26
+ * since after the call to
27
+ * 'vTaskStartScheduler' we'll never
28
+ * get out of setup() and therefore
29
+ * would never get to loop(), as we
30
+ * are leaving the default execution
31
+ * flow.
32
+ */
33
+ #if 1
34
+ auto const rc_loop = xTaskCreate
35
+ (
36
+ loop_thread_func,
37
+ static_cast <const char *>(" Loop Thread" ),
38
+ 512 / 4 , /* usStackDepth in words */
39
+ nullptr , /* pvParameters */
40
+ 1 , /* uxPriority */
41
+ &loop_task /* pxCreatedTask */
42
+ );
43
+
44
+ if (rc_loop != pdPASS) {
45
+ Serial.println (" Failed to create 'loop' thread" );
46
+ return ;
47
+ }
48
+ #endif
49
+ #if 1
50
+ auto const rc_blinky = xTaskCreate
24
51
(
25
52
blinky_thread_func,
26
53
static_cast <const char *>(" Blinky Thread" ),
27
- 512 / 4 , /* usStackDepth in words */
28
- nullptr , /* pvParameters */
29
- 1 , /* uxPriority */
30
- &blinky_thread_hdl /* pxCreatedTask */
54
+ 512 / 4 , /* usStackDepth in words */
55
+ nullptr , /* pvParameters */
56
+ 1 , /* uxPriority */
57
+ &blinky_task /* pxCreatedTask */
31
58
);
32
59
33
- if (rc != pdPASS)
60
+ if (rc_blinky != pdPASS) {
61
+ Serial.println (" Failed to create 'loop' thread" );
34
62
return ;
35
-
63
+ }
64
+ #endif
36
65
Serial.println (" Starting scheduler ..." );
37
66
/* Start the scheduler. */
38
- vTaskStartScheduler ();
67
+ vTaskStartScheduler ();
68
+ /* We'll never get here. */
69
+ for ( ;; );
39
70
}
40
71
41
72
void loop ()
42
73
{
74
+ digitalWrite (LEDR, !digitalRead (LEDR));
75
+ vTaskDelay (configTICK_RATE_HZ/4 );
76
+ }
43
77
78
+ void loop_thread_func (void *pvParameters)
79
+ {
80
+ for (;;)
81
+ {
82
+ loop ();
83
+ taskYIELD ();
84
+ }
44
85
}
45
86
46
87
void blinky_thread_func (void *pvParameters)
47
88
{
48
- /* blinky_thread. setup() */
89
+ /* setup() */
49
90
pinMode (LED_BUILTIN, OUTPUT);
50
91
digitalWrite (LED_BUILTIN, LOW);
51
92
52
- /* blinky_thread. loop() */
93
+ /* loop() */
53
94
for (;;)
54
95
{
55
96
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN));
0 commit comments