The demo Co-routines demonstrate basic use of FreeRTOS, with inter-task communication using queues and mutexes.
For details on how the demo works, see Introduction.
For detailed information on the Co-routines, see:
The demo Co-routines depend on the following drivers:
Functions | |
static void | cdc_rx_handler (uint8_t instance) |
Interrupt handler for reception from EDBG Virtual COM Port. More... | |
void | demo_co_routines_init (void) |
Initialize Co-routines and resources for demo. More... | |
void | vApplicationIdleHook (void) |
This idle task hook will schedule a co-routine each time it is called. More... | |
Co-routines configuration | |
#define | UART_CO_ROUTINE_PRIORITY (configMAX_CO_ROUTINE_PRIORITIES - 1) |
#define | MAIN_CO_ROUTINE_PRIORITY (configMAX_CO_ROUTINE_PRIORITIES - 2) |
#define | MAIN_CO_ROUTINE_DELAY (100 / portTICK_RATE_MS) |
#define | GRAPH_CO_ROUTINE_PRIORITY (configMAX_CO_ROUTINE_PRIORITIES - 3) |
#define | GRAPH_CO_ROUTINE_DELAY (50 / portTICK_RATE_MS) |
#define | TERMINAL_CO_ROUTINE_PRIORITY (configMAX_CO_ROUTINE_PRIORITIES - 3) |
#define | ABOUT_CO_ROUTINE_PRIORITY (configMAX_CO_ROUTINE_PRIORITIES - 3) |
Global constants and variables | |
static const char | menu_items_text [MENU_NUM_ITEMS][6] |
Labels for menu items. More... | |
static const char | about_text [] |
Text to display on about screen. More... | |
static struct usart_module | cdc_usart |
Instance for Embedded Debugger (EDBG) Virtual COM Port driver. More... | |
static uint8_t | graph_noise = 128 |
Pseudo-random noise for graph Co-routine. More... | |
static gfx_coord_t | x1 = 0 |
x coord for graph Co-routine More... | |
static uint8_t | terminal_buffer [TERMINAL_BUFFER_LINES][TERMINAL_BUFFER_COLUMNS] |
Buffer for terminal text. More... | |
static uint8_t | terminal_line_offset |
Index of latest terminal line (first to be printed) More... | |
static QueueHandle_t | terminal_in_queue |
Queue for incoming terminal characters. More... | |
static QueueHandle_t | graph_co_routine_queue |
Queue for sync graph Co-routine. More... | |
static QueueHandle_t | terminal_co_routine_queue |
Queue for sync terminal Co-routine. More... | |
static QueueHandle_t | about_co_routine_queue |
Queue for sync about Co-routine. More... | |
static | OLED1_CREATE_INSTANCE (oled1, OLED1_EXT_HEADER) |
Instance for OLED1 Xplained Pro LED and button driver. More... | |
Co-routines for demo | |
static void | main_co_routine (CoRoutineHandle_t xHandle, UBaseType_t uxIndex) |
Main demo Co-routine. More... | |
static void | graph_co_routine (CoRoutineHandle_t xHandle, UBaseType_t uxIndex) |
Graph Co-routine. More... | |
static void | terminal_co_routine (CoRoutineHandle_t xHandle, UBaseType_t uxIndex) |
Terminal Co-routine. More... | |
static void | about_co_routine (CoRoutineHandle_t xHandle, UBaseType_t uxIndex) |
About Co-routine. More... | |
static void | uart_co_routine (CoRoutineHandle_t xHandle, UBaseType_t uxIndex) |
UART Co-routine. More... | |
#define ABOUT_CO_ROUTINE_PRIORITY (configMAX_CO_ROUTINE_PRIORITIES - 3) |
Referenced by demo_co_routines_init().
#define CANVAS_HEIGHT ((GFX_MONO_LCD_HEIGHT) - (MENU_HEIGHT + 1)) |
Height of area in which to draw content.
Referenced by about_co_routine(), graph_co_routine(), and main_co_routine().
#define CANVAS_WIDTH (GFX_MONO_LCD_WIDTH) |
Width of area in which to draw content.
Referenced by about_co_routine(), graph_co_routine(), and terminal_co_routine().
#define GRAPH_CO_ROUTINE_DELAY (50 / portTICK_RATE_MS) |
Referenced by graph_co_routine().
#define GRAPH_CO_ROUTINE_PRIORITY (configMAX_CO_ROUTINE_PRIORITIES - 3) |
Referenced by demo_co_routines_init().
#define MAIN_CO_ROUTINE_DELAY (100 / portTICK_RATE_MS) |
Referenced by main_co_routine().
#define MAIN_CO_ROUTINE_PRIORITY (configMAX_CO_ROUTINE_PRIORITIES - 2) |
Referenced by demo_co_routines_init().
#define MENU_HEIGHT 8 |
Height of menu bar.
Referenced by main_co_routine().
#define MENU_ITEM_WIDTH (((GFX_MONO_LCD_WIDTH - (MENU_NUM_ITEMS - 1))) / MENU_NUM_ITEMS) |
Width per menu item.
Referenced by main_co_routine().
#define TERMINAL_BUFFER_COLUMNS (1 + TERMINAL_COLUMNS) |
Character columns in terminal buffer.
#define TERMINAL_BUFFER_LINES (1 + TERMINAL_LINES) |
Character lines in terminal buffer.
Referenced by terminal_co_routine(), and uart_co_routine().
#define TERMINAL_CO_ROUTINE_PRIORITY (configMAX_CO_ROUTINE_PRIORITIES - 3) |
Referenced by demo_co_routines_init().
#define TERMINAL_COLUMNS (CANVAS_WIDTH / SYSFONT_WIDTH) |
Character columns on display.
Referenced by about_co_routine(), terminal_co_routine(), and uart_co_routine().
#define TERMINAL_LINES (1 + ((CANVAS_HEIGHT - SYSFONT_HEIGHT) / (SYSFONT_HEIGHT + 1))) |
Character lines on display.
Referenced by terminal_co_routine().
#define UART_CO_ROUTINE_PRIORITY (configMAX_CO_ROUTINE_PRIORITIES - 1) |
Referenced by demo_co_routines_init().
enum menu_items |
Available selections in menu.
|
static |
About Co-routine.
This Co-routine prints a short text about the demo, with a simple zooming animation.
xHandle | Type by which co-routines are referenced. |
uxIndex | Parameter for the Co-routine. |
References about_co_routine_queue, about_text, c, CANVAS_HEIGHT, CANVAS_WIDTH, crEND, crQUEUE_RECEIVE, crSTART, gfx_mono_draw_char(), i, OLED1_LED2_ID, oled1_set_led_state(), pdPASS, sysfont, and TERMINAL_COLUMNS.
Referenced by demo_co_routines_init().
|
static |
Interrupt handler for reception from EDBG Virtual COM Port.
UART interrupt handler for reception on EDBG CDC UART.
This function is based on the interrupt handler of the SERCOM USART callback driver (_usart_interrupt_handler()). It has been modified to only handle the receive interrupt and to push the received data directly into the queue for terminal characters (terminal_in_queue), and echo the character back to the sender.
instance | Instance number of SERCOM that generated interrupt. |
References crQUEUE_SEND_FROM_ISR, data, pdFALSE, and terminal_in_queue.
Referenced by demo_co_routines_init().
void demo_co_routines_init | ( | void | ) |
Initialize Co-routines and resources for demo.
This function initializes the OLED1 Xplained Pro LED and button driver instance and the Embedded Debugger (EDBG) Virtual COM Port driver instance for reception, then creates all the objects for FreeRTOS to run the demo.
References about_co_routine(), ABOUT_CO_ROUTINE_PRIORITY, about_co_routine_queue, cdc_rx_handler(), cdc_rx_init(), cdc_usart, graph_co_routine(), GRAPH_CO_ROUTINE_PRIORITY, graph_co_routine_queue, main_co_routine(), MAIN_CO_ROUTINE_PRIORITY, oled1_init(), terminal_co_routine(), TERMINAL_CO_ROUTINE_PRIORITY, terminal_co_routine_queue, terminal_in_queue, uart_co_routine(), UART_CO_ROUTINE_PRIORITY, xCoRoutineCreate(), and xQueueCreate.
Referenced by main().
|
static |
Graph Co-routine.
This Co-routine runs in the background to draw a pseudo-random graph to a dedicated display buffer. If the user selects a different screen than the graph, it will continue to update even though it is not visible until the graph screen is selected again.
xHandle | Type by which co-routines are referenced. |
uxIndex | Parameter for the Co-routine. |
References CANVAS_HEIGHT, CANVAS_WIDTH, crDELAY, crEND, crQUEUE_RECEIVE, crSTART, gfx_mono_draw_line, gfx_mono_draw_pixel, gfx_mono_draw_vertical_line, GFX_PIXEL_CLR, GFX_PIXEL_SET, GRAPH_CO_ROUTINE_DELAY, graph_co_routine_queue, graph_noise, OLED1_LED1_ID, oled1_set_led_state(), pdPASS, and x1.
Referenced by demo_co_routines_init().
|
static |
Main demo Co-routine.
This Co-routine keeps track of which screen the user has selected, which resume/suspend to draw the selected screen, and also draws the menu bar.
The menu bar shows which screens the user can select by clicking the corresponding buttons on the OLED1 Xplained Pro:
xHandle | Type by which co-routines are referenced. |
uxIndex | Parameter for the Co-routine. |
References about_co_routine_queue, Assert, CANVAS_HEIGHT, crDELAY, crEND, crQUEUE_SEND, crSTART, gfx_mono_draw_filled_rect, gfx_mono_draw_horizontal_line, gfx_mono_draw_rect, gfx_mono_draw_string(), gfx_mono_draw_vertical_line, GFX_MONO_LCD_HEIGHT, GFX_MONO_LCD_WIDTH, GFX_PIXEL_CLR, GFX_PIXEL_SET, graph_co_routine_queue, i, MAIN_CO_ROUTINE_DELAY, MENU_HEIGHT, MENU_ITEM_ABOUT, MENU_ITEM_GRAPH, MENU_ITEM_TERMINAL, MENU_ITEM_WIDTH, menu_items_text, MENU_NUM_ITEMS, OLED1_BUTTON1_ID, OLED1_BUTTON2_ID, OLED1_BUTTON3_ID, oled1_get_button_state(), OLED1_LED3_ID, oled1_set_led_state(), pdPASS, result, sysfont, terminal_co_routine_queue, and x1.
Referenced by demo_co_routines_init().
|
static |
Instance for OLED1 Xplained Pro LED and button driver.
The extension header to use is configured with OLED1_EXT_HEADER.
|
static |
Terminal Co-routine.
This Co-routine prints the terminal text buffer to the display.
xHandle | Type by which co-routines are referenced. |
uxIndex | Parameter for the Co-routine. |
References CANVAS_WIDTH, crEND, crQUEUE_RECEIVE, crSTART, gfx_mono_draw_char(), gfx_mono_draw_filled_rect, GFX_PIXEL_CLR, OLED1_LED2_ID, oled1_set_led_state(), pdPASS, sysfont, terminal_buffer, TERMINAL_BUFFER_LINES, terminal_co_routine_queue, TERMINAL_COLUMNS, terminal_line_offset, and TERMINAL_LINES.
Referenced by demo_co_routines_init().
|
static |
UART Co-routine.
This Co-routine runs in the background to handle the queued, incoming terminal characters and write them to the terminal text buffer. It does not print anything to the display – that is done by terminal_co_routine().
xHandle | Type by which co-routines are referenced. |
uxIndex | Parameter for the Co-routine. |
References crEND, crQUEUE_RECEIVE, crSTART, OLED1_LED1_ID, oled1_set_led_state(), pdPASS, terminal_buffer, TERMINAL_BUFFER_LINES, TERMINAL_COLUMNS, terminal_in_queue, and terminal_line_offset.
Referenced by demo_co_routines_init().
void vApplicationIdleHook | ( | void | ) |
This idle task hook will schedule a co-routine each time it is called.
References vCoRoutineSchedule().
Referenced by portTASK_FUNCTION().
|
static |
Queue for sync about Co-routine.
Referenced by about_co_routine(), demo_co_routines_init(), and main_co_routine().
|
static |
Text to display on about screen.
Referenced by about_co_routine().
|
static |
Instance for Embedded Debugger (EDBG) Virtual COM Port driver.
Referenced by demo_co_routines_init().
|
static |
Queue for sync graph Co-routine.
Referenced by demo_co_routines_init(), graph_co_routine(), and main_co_routine().
|
static |
Pseudo-random noise for graph Co-routine.
Referenced by graph_co_routine().
|
static |
Labels for menu items.
Referenced by main_co_routine().
|
static |
Buffer for terminal text.
Referenced by terminal_co_routine(), and uart_co_routine().
|
static |
Queue for sync terminal Co-routine.
Referenced by demo_co_routines_init(), main_co_routine(), and terminal_co_routine().
|
static |
Queue for incoming terminal characters.
Referenced by cdc_rx_handler(), demo_co_routines_init(), and uart_co_routine().
|
static |
Index of latest terminal line (first to be printed)
Referenced by terminal_co_routine(), and uart_co_routine().
|
static |
x coord for graph Co-routine
Referenced by _usart_set_config(), cpu_start(), gfx_mono_generic_draw_line(), graph_co_routine(), hif_isr(), i2s_serializer_read_buffer_job(), i2s_serializer_write_buffer_job(), main_co_routine(), nmi_get_chipid(), nvm_execute_command(), spi_flash_enter_low_power_mode(), spi_flash_leave_low_power_mode(), and spi_flash_rdid().