@@ -64,25 +64,28 @@ void calibrate() {
6464 uint32_t t = micros ();
6565 burnCPU (1000 );
6666 t = micros () - t;
67- cal = (TICK_USEC* 1000 * cal)/ t;
67+ cal = (TICK_USEC * 1000 * cal) / t;
6868}
6969// ------------------------------------------------------------------------------
7070// 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
7175void 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 );
7779}
7880void done (const char * msg, task_t * task, TickType_t now) {
7981 vTaskSuspendAll ();
8082 Serial.println (msg);
8183 Serial.print (" Tick: " );
8284 Serial.println (now);
8385 Serial.print (" Task: " );
86+ Serial.flush ();
8487 printTask (task);
85- while (1 );
88+ while (1 );
8689}
8790// ------------------------------------------------------------------------------
8891// start tasks at 1000 ticks
@@ -120,7 +123,7 @@ void setup() {
120123 portBASE_TYPE s; // task create status
121124
122125 Serial.begin (9600 );
123- while (!Serial) {}
126+ while (!Serial) {}
124127 Serial.println (" Rate Monotonic Scheduling Examples." );
125128 Serial.println (" Cases 1 and 3 should fail" );
126129 Serial.println (" Cases 2 and 4 should succeed" );
@@ -149,28 +152,29 @@ void setup() {
149152
150153 uint32_t t = micros ();
151154 burnCPU (1000 );
152- Serial.println (micros () -t);
155+ Serial.println (micros () - t);
153156 Serial.println (" Starting tasks - period and CPU in ticks" );
154157 Serial.println (" Period,CPU,Priority" );
158+ Serial.flush ();
155159 for (int i = 0 ; i < n; i++) {
156160 printTask (&tasks[i]);
157- cpuUse += tasks[i].cpu / (float )tasks[i].period ;
161+ cpuUse += tasks[i].cpu / (float )tasks[i].period ;
158162
159163 s = xTaskCreate (task, NULL , 200 , (void *)&tasks[i], tasks[i].priority , NULL );
160164 if (s != pdPASS) {
161- Serial. println (" task create failed" );
162- while (1 );
165+ printf (" task create failed\n " );
166+ while (1 );
163167 }
164168 }
165- Serial.print (" CPU use %: " );
166- Serial.println (cpuUse*100 );
167- Serial.print (" Liu and Layland bound %: " );
168- Serial.println (LiuLayland[n - 1 ]);
169169
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));
170174 // start tasks
171175 vTaskStartScheduler ();
172176 Serial.println (" Scheduler failed" );
173- while (1 );
177+ while (1 );
174178}
175179// ------------------------------------------------------------------------------
176180// WARNING idle loop has a very small stack (configMINIMAL_STACK_SIZE)
0 commit comments