Main
src/driving_board/main.c
contains the main firmware entry point and runtime logic for the driving board. The system is built on FreeRTOS (CMSIS-RTOS v2) and runs multiple tasks concurrently.
Initialization init_board
init_board()
This function initializes the full system before starting the scheduler.
It:
- Configures MPU and cache
- Initializes HAL and system clock
- Initializes GPIO, timers, and UART logging
- Initializes control algorithm (control_initialize)
- Initializes Ethernet and MAC filtering Creates FreeRTOS tasks Starts PWM and encoder peripherals
- Starts the RTOS kernel. After this, the scheduler takes over.
Tasks
The system runs 3 main threads:
MainTask
This task handles: Ethernet communication Diagnostics message creation and sending Periodic data updates
Example Flow For Sending A Message:
Flow:Initialize UDP Fill DiagnosticsData using FillDiagnostics- Encode using
DBMDiagnosticsEncodeDBMDiagnostics - Encode Send encoded data over Ethernet
- Free allocated memory after sending Also sends test UDP and raw Ethernet messages.
PwmTask
PwmTask This task runs the control loop.
It:
- Calls control_step() from control
modulemodule(Simulink folder) - Reads outputs from rtY
- Updates motor PWM using set_bldc_pwm Runs periodically (1 ms)
DrivingEncoderTask
DrivingEncoderTask This task processes encoder data.
It:
- Reads timer counters
- Calculates: revolutions radians (position) rpm (speed)
Updates global variables used in diagnostics Runs every 100 ms Diagnostics Data FillDiagnostics Fills a DiagnosticsData struct with current system values. It: Sets board state Sets motor countPopulates motor data (rpm, voltage, angle).- Updates global variables used in diagnostics
- Runs every 100 ms