@@ -64,25 +64,28 @@ void calibrate() {
64
64
uint32_t t = micros ();
65
65
burnCPU (1000 );
66
66
t = micros () - t;
67
- cal = (TICK_USEC* 1000 * cal)/ t;
67
+ cal = (TICK_USEC * 1000 * cal) / t;
68
68
}
69
69
// ------------------------------------------------------------------------------
70
70
// print helpers
71
+ // On Cortex-M0 and Cortex-M0+, all IT are disabled between xTaskCreate() and vTaskStartScheduler().
72
+ // So it is not possible to use IT inbetween, like Serial.print() ...
73
+ // This is the reason why, in example "frLiyLayland", between xTaskCreate() and vTaskStartScheduler(),
74
+ // we use direct printf(), which will access directly USART without interrupt
71
75
void printTask (task_t * task) {
72
- Serial.print (task->period );
73
- Serial.write (' ,' );
74
- Serial.print (task->cpu );
75
- Serial.write (' ,' );
76
- Serial.println (task->priority );
76
+ printf (" %u, " , task->period );
77
+ printf (" %u, " , task->cpu );
78
+ printf (" %u\r\n " , task->priority );
77
79
}
78
80
void done (const char * msg, task_t * task, TickType_t now) {
79
81
vTaskSuspendAll ();
80
82
Serial.println (msg);
81
83
Serial.print (" Tick: " );
82
84
Serial.println (now);
83
85
Serial.print (" Task: " );
86
+ Serial.flush ();
84
87
printTask (task);
85
- while (1 );
88
+ while (1 );
86
89
}
87
90
// ------------------------------------------------------------------------------
88
91
// start tasks at 1000 ticks
@@ -120,7 +123,7 @@ void setup() {
120
123
portBASE_TYPE s; // task create status
121
124
122
125
Serial.begin (9600 );
123
- while (!Serial) {}
126
+ while (!Serial) {}
124
127
Serial.println (" Rate Monotonic Scheduling Examples." );
125
128
Serial.println (" Cases 1 and 3 should fail" );
126
129
Serial.println (" Cases 2 and 4 should succeed" );
@@ -149,28 +152,29 @@ void setup() {
149
152
150
153
uint32_t t = micros ();
151
154
burnCPU (1000 );
152
- Serial.println (micros () -t);
155
+ Serial.println (micros () - t);
153
156
Serial.println (" Starting tasks - period and CPU in ticks" );
154
157
Serial.println (" Period,CPU,Priority" );
158
+ Serial.flush ();
155
159
for (int i = 0 ; i < n; i++) {
156
160
printTask (&tasks[i]);
157
- cpuUse += tasks[i].cpu / (float )tasks[i].period ;
161
+ cpuUse += tasks[i].cpu / (float )tasks[i].period ;
158
162
159
163
s = xTaskCreate (task, NULL , 200 , (void *)&tasks[i], tasks[i].priority , NULL );
160
164
if (s != pdPASS) {
161
- Serial. println (" task create failed" );
162
- while (1 );
165
+ printf (" task create failed\n " );
166
+ while (1 );
163
167
}
164
168
}
165
- Serial.print (" CPU use %: " );
166
- Serial.println (cpuUse*100 );
167
- Serial.print (" Liu and Layland bound %: " );
168
- Serial.println (LiuLayland[n - 1 ]);
169
169
170
+ char CPU[10 ];
171
+ char bound[10 ];
172
+ printf (" CPU use %%: %s\r\n " , dtostrf (cpuUse*100 , 6 , 2 , CPU));
173
+ printf (" Liu and Layland bound %%: %s\r\n " , dtostrf (LiuLayland[n - 1 ], 6 , 2 , bound));
170
174
// start tasks
171
175
vTaskStartScheduler ();
172
176
Serial.println (" Scheduler failed" );
173
- while (1 );
177
+ while (1 );
174
178
}
175
179
// ------------------------------------------------------------------------------
176
180
// WARNING idle loop has a very small stack (configMINIMAL_STACK_SIZE)
0 commit comments