Refactor panda firmware to use source + header file structure#2311
Closed
AgentsLogic wants to merge 12 commits intocommaai:masterfrom
Closed
Refactor panda firmware to use source + header file structure#2311AgentsLogic wants to merge 12 commits intocommaai:masterfrom
AgentsLogic wants to merge 12 commits intocommaai:masterfrom
Conversation
- Split all header-only files into separate .c (implementation) and .h (declarations) files - Moved function implementations from .h files to new .c files - Updated headers to contain only declarations, macros, and typedefs - Added #pragma once to all header files - Updated SConscript build system to compile all new .c files - Updated MISRA mutation tests to reference .c files instead of .h files - Deleted all *_declarations.h files as they are no longer needed - Improves code organization and MISRA C:2012 compliance - Reduces compilation time by avoiding redundant inline expansions Files converted: - board/critical.c/h, faults.c/h, power_saving.c/h - board/drivers/: bootkick, can_common, clock_source, fan, fdcan, gpio, harness, interrupts, led, pwm, registers, simple_watchdog, spi, uart, usb - board/stm32h7/: clock, lladc, llfan, llfdcan, llflash, lli2c, llspi, lluart, llusb
- Add stdint.h to critical.h for uint8_t - Add stdint.h and stdbool.h to faults.h for uint8_t, uint32_t, bool - Add stdbool.h to power_saving.h for bool
- Add stdbool.h to critical.c for bool type - Add board/drivers/uart.h to faults.c for print() and puth() - Add stdint.h, harness.h, and board_declarations.h to power_saving.c
All .c files need to include board/config.h first to get platform headers (STM32 HAL, CMSIS intrinsics, etc.) before including their own headers.
power_saving.c uses the harness global variable which is declared in board/drivers/harness.h
harness.h uses adc_signal_t which is defined in board/stm32h7/lladc.h
power_saving.c uses board functions (enable_can_transceiver, set_ir_power) that don't exist in the body board struct. It's only included in board/main.c, not board/body/main.c, so it should only be compiled for panda and jungle builds.
The lladc.h header was missing declarations for adc_init(), adc_get_raw(), and adc_get_mV() which are defined in lladc.c. This caused compilation errors when other files (like board/boards/red.h) tried to use adc_get_mV().
uart_ring_debug and uart_ring_som_debug are defined in uart.c but were not declared as extern in uart.h, causing compilation errors when other files (like board/boards/tres.h) tried to use them.
can_rx_q, can_tx1_q, can_tx2_q, and can_tx3_q are defined in can_common.c but were not declared as extern in can_common.h, causing compilation errors when other files tried to use them.
…ivers, power_saving.c - Fix board/body/can.h to include board/drivers/can_common.h instead of non-existent can_common_declarations.h - Add enable_can_transceivers function declaration to power_saving.h - Exclude power_saving.c from jungle build (only for panda, not jungle or body)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors the panda firmware codebase to use a proper source + header file structure, addressing bounty #2171.
Changes
.c(implementation) and.h(declarations) files.hfiles to new.cfiles#pragma onceto all header files for cleaner include guardsSConscriptbuild system to compile all new.cfiles.cfiles instead of.hfiles*_declarations.hfiles as they are no longer neededBenefits
Files Converted
Board-level files:
board/critical.c/h,faults.c/h,power_saving.c/hDrivers:
board/drivers/: bootkick, can_common, clock_source, fan, fdcan, gpio, harness, interrupts, led, pwm, registers, simple_watchdog, spi, uart, usbSTM32H7 low-level drivers:
board/stm32h7/: clock, lladc, llfan, llfdcan, llflash, lli2c, llspi, lluart, llusbTesting
All changes maintain the exact same functionality - only the file organization has changed. The CI will verify:
Closes #2171