// Include FreeRTOS headers. #include "FreeRTOSConfig.h" #include "FreeRTOS.h" #include "task.h" #include #include #include #include "lib_ee152.h" //***************************************************** // Our big-hammer debugging facility. It works with macros in FreeRTOSConfig.h. // - At each 1ms SysTick interrupt, the macro traceTASK_INCREMENT_TICK() appends // the number 4 to g_debug_notes[]. // - Whenever we context switch to task_writer1() -- whether it's triggered by a // SysTick interrupt, by a task calling vTaskDelay(), or whatever -- we append // the number 1 to g_debug_notes[] // - Similarly, switch to task_writer2() appends 2, switching to // task_UART_daemon() appends 3, and switching to the idle task appends 0. // - Then, at the end of the run, task_UART_daemon() dump g_debug_notes[]: // printing out "*" for each SysTick interrupt, "1" for task_writer1, "2" for // task_writer2, "D" for the UART daemon and "I" for the idle task. //***************************************************** unsigned char g_debug_notes [MAX_DEBUG_NOTES]; unsigned g_n_debug_notes; //***************************************************** // The blinky task. //***************************************************** #define BLINK_GRN_ON 10 #define BLINK_GRN_OFF 40 void task_blink_grn( void * pvParameters ) { vTaskSetApplicationTaskTag (NULL, (void *)1); // The green LED is at Nano D13, or PB3. pinMode(D13, "OUTPUT"); for ( ;; ) { digitalWrite (D13, 1); vTaskDelay (BLINK_GRN_ON); digitalWrite (D13, 0); vTaskDelay (BLINK_GRN_OFF); } } // 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 ...) void task_pi (void *pvParameters) { vTaskSetApplicationTaskTag (NULL, (void *)2); float pi = 1; for (float denom=1.0; denom < 10000000; denom += 4) { pi -= 1.0 / denom; pi += 1.0 / (denom+2); } pi *= 4; // Done computing pi. Print the accumulated debug info and then spin. serial_write (USART2, "Printing debug info\r\n"); char buf[2]; buf[1]='\0'; for (int i=0; i