ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
main_freertos.c File Reference

FreeRTOS-based LED test application for the Pico 2 W board. More...

#include "pico/stdlib.h"
#include <assert.h>
#include <stdio.h>
#include <FreeRTOS.h>
#include <task.h>
Include dependency graph for main_freertos.c:

Macros

#define LED_DELAY_MS   100
 

Functions

int pico_led_init (void)
 Initialize the board-specific LED backend.
 
void pico_set_led (bool led_on)
 Set the onboard LED state.
 
static void led_task (void *argument)
 FreeRTOS task that blinks the onboard LED at LED_DELAY_MS.
 
static void log_task (void *argument)
 Low-priority FreeRTOS task for periodic logging.
 
int main ()
 Application entry point.
 

Detailed Description

FreeRTOS-based LED test application for the Pico 2 W board.

This C source is intended for testing a Pico 2 W board by blinking the onboard LED using the Pico C SDK and FreeRTOS. It configures LED control for either:

  • boards with a direct LED GPIO (PICO_DEFAULT_LED_PIN), or
  • Pico W style boards where the LED is controlled through the CYW43 Wi-Fi chip (CYW43_WL_GPIO_LED_PIN).

Two FreeRTOS tasks are created:

  • led_task(): toggles the LED periodically.
  • log_task(): prints a periodic low-priority status message.

Macro Definition Documentation

◆ LED_DELAY_MS

#define LED_DELAY_MS   100

Function Documentation

◆ led_task()

static void led_task ( void *  argument)
static

FreeRTOS task that blinks the onboard LED at LED_DELAY_MS.

Usage:

  • Created from main() using xTaskCreate().
  • Runs forever and alternates LED ON/OFF with vTaskDelay().
Parameters
argumentUnused task argument.
Here is the call graph for this function:

◆ log_task()

static void log_task ( void *  argument)
static

Low-priority FreeRTOS task for periodic logging.

Usage:

  • Created from main() with lower priority than led_task().
  • Runs forever and prints a heartbeat log every 1 second.
Parameters
argumentUnused task argument.

◆ main()

int main ( void  )

Application entry point.

Startup sequence:

  1. Initialize stdio (stdio_init_all()).
  2. Initialize LED backend (pico_led_init()).
  3. Create FreeRTOS tasks (led_task() and log_task()).
  4. Start scheduler (vTaskStartScheduler()).

Usage:

  • Build this target with Pico SDK + FreeRTOS support.
  • Flash to supported hardware (including Pico 2 W) to validate LED and scheduler/task behavior.
Returns
Never returns under normal operation.
Here is the call graph for this function:

◆ pico_led_init()

int pico_led_init ( void  )

Initialize the board-specific LED backend.

Usage:

  • Call once during startup before any call to pico_set_led().
  • In main(), the return value is checked with hard_assert() to ensure initialization succeeded.
Returns
PICO_OK on success for GPIO-based boards, or the result of cyw43_arch_init() for Pico W style boards.
Here is the caller graph for this function:

◆ pico_set_led()

void pico_set_led ( bool  led_on)

Set the onboard LED state.

This function abstracts the hardware difference between direct GPIO LED control and CYW43-controlled LED GPIO on Pico W style boards.

Usage:

  • Call after pico_led_init() succeeds.
  • Pass true to turn the LED on, false to turn it off.
Parameters
led_onDesired LED state (true = on, false = off).
Here is the caller graph for this function: