misra8.4: board/boards (#2021)

* boards

* revert

* includes
This commit is contained in:
Maxime Desroches 2024-09-16 14:07:21 -07:00 committed by GitHub
parent 2526d1ee4b
commit 93aedd987b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 127 additions and 75 deletions

View File

@ -1,8 +1,12 @@
#pragma once
#include "board_declarations.h"
// /////////////////////////////// //
// Black Panda (STM32F4) + Harness //
// /////////////////////////////// //
void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
@ -22,7 +26,7 @@ void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}
void black_enable_can_transceivers(bool enabled) {
static void black_enable_can_transceivers(bool enabled) {
for(uint8_t i=1U; i<=4U; i++){
// Leave main CAN always on for CAN-based ignition detection
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
@ -33,7 +37,7 @@ void black_enable_can_transceivers(bool enabled) {
}
}
void black_set_led(uint8_t color, bool enabled) {
static void black_set_led(uint8_t color, bool enabled) {
switch (color){
case LED_RED:
set_gpio_output(GPIOC, 9, !enabled);
@ -49,11 +53,11 @@ void black_set_led(uint8_t color, bool enabled) {
}
}
void black_set_usb_load_switch(bool enabled) {
static void black_set_usb_load_switch(bool enabled) {
set_gpio_output(GPIOB, 1, !enabled);
}
void black_set_can_mode(uint8_t mode) {
static void black_set_can_mode(uint8_t mode) {
black_enable_can_transceiver(2U, false);
black_enable_can_transceiver(4U, false);
switch (mode) {
@ -86,12 +90,12 @@ void black_set_can_mode(uint8_t mode) {
}
}
bool black_check_ignition(void){
static bool black_check_ignition(void){
// ignition is checked through harness
return harness_check_ignition();
}
void black_init(void) {
static void black_init(void) {
common_init_gpio();
// A8,A15: normal CAN3 mode
@ -135,13 +139,13 @@ void black_init(void) {
black_set_can_mode(CAN_MODE_NORMAL);
}
void black_init_bootloader(void) {
static void black_init_bootloader(void) {
// GPS OFF
set_gpio_output(GPIOC, 5, 0);
set_gpio_output(GPIOC, 12, 0);
}
harness_configuration black_harness_config = {
static harness_configuration black_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,

View File

@ -1,3 +1,8 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
// ******************** Prototypes ********************
typedef enum {
BOOT_STANDBY,
@ -74,3 +79,12 @@ struct board {
// CAN modes
#define CAN_MODE_NORMAL 0U
#define CAN_MODE_OBD_CAN2 1U
extern struct board board_black;
extern struct board board_dos;
extern struct board board_uno;
extern struct board board_tres;
extern struct board board_grey;
extern struct board board_white;
extern struct board board_cuatro;
extern struct board board_red;

View File

@ -1,8 +1,12 @@
#pragma once
#include "board_declarations.h"
// ////////////////////////// //
// Cuatro (STM32H7) + Harness //
// ////////////////////////// //
void cuatro_set_led(uint8_t color, bool enabled) {
static void cuatro_set_led(uint8_t color, bool enabled) {
switch (color) {
case LED_RED:
set_gpio_output(GPIOD, 15, !enabled);
@ -18,7 +22,7 @@ void cuatro_set_led(uint8_t color, bool enabled) {
}
}
void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver) {
case 1U:
set_gpio_output(GPIOB, 7, !enabled);
@ -37,7 +41,7 @@ void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}
void cuatro_enable_can_transceivers(bool enabled) {
static void cuatro_enable_can_transceivers(bool enabled) {
uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U;
for (uint8_t i=1U; i<=4U; i++) {
// Leave main CAN always on for CAN-based ignition detection
@ -49,25 +53,25 @@ void cuatro_enable_can_transceivers(bool enabled) {
}
}
uint32_t cuatro_read_voltage_mV(void) {
static uint32_t cuatro_read_voltage_mV(void) {
return adc_get_mV(8) * 11U;
}
uint32_t cuatro_read_current_mA(void) {
static uint32_t cuatro_read_current_mA(void) {
return adc_get_mV(3) * 2U;
}
void cuatro_set_fan_enabled(bool enabled) {
static void cuatro_set_fan_enabled(bool enabled) {
set_gpio_output(GPIOD, 3, !enabled);
}
void cuatro_set_bootkick(BootState state) {
static void cuatro_set_bootkick(BootState state) {
set_gpio_output(GPIOA, 0, state != BOOT_BOOTKICK);
// only use if we have to
//set_gpio_output(GPIOC, 12, state != BOOT_RESET);
}
void cuatro_init(void) {
static void cuatro_init(void) {
red_chiplet_init();
// init LEDs as open drain

View File

@ -1,8 +1,12 @@
#pragma once
#include "board_declarations.h"
// /////////////////////// //
// Dos (STM32F4) + Harness //
// /////////////////////// //
void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
@ -22,7 +26,7 @@ void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}
void dos_enable_can_transceivers(bool enabled) {
static void dos_enable_can_transceivers(bool enabled) {
for(uint8_t i=1U; i<=4U; i++){
// Leave main CAN always on for CAN-based ignition detection
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
@ -33,7 +37,7 @@ void dos_enable_can_transceivers(bool enabled) {
}
}
void dos_set_led(uint8_t color, bool enabled) {
static void dos_set_led(uint8_t color, bool enabled) {
switch (color){
case LED_RED:
set_gpio_output(GPIOC, 9, !enabled);
@ -49,11 +53,11 @@ void dos_set_led(uint8_t color, bool enabled) {
}
}
void dos_set_bootkick(BootState state) {
static void dos_set_bootkick(BootState state) {
set_gpio_output(GPIOC, 4, state != BOOT_BOOTKICK);
}
void dos_set_can_mode(uint8_t mode) {
static void dos_set_can_mode(uint8_t mode) {
dos_enable_can_transceiver(2U, false);
dos_enable_can_transceiver(4U, false);
switch (mode) {
@ -85,28 +89,28 @@ void dos_set_can_mode(uint8_t mode) {
}
}
bool dos_check_ignition(void){
static bool dos_check_ignition(void){
// ignition is checked through harness
return harness_check_ignition();
}
void dos_set_ir_power(uint8_t percentage){
static void dos_set_ir_power(uint8_t percentage){
pwm_set(TIM4, 2, percentage);
}
void dos_set_fan_enabled(bool enabled){
static void dos_set_fan_enabled(bool enabled){
set_gpio_output(GPIOA, 1, enabled);
}
void dos_set_siren(bool enabled){
static void dos_set_siren(bool enabled){
set_gpio_output(GPIOC, 12, enabled);
}
bool dos_read_som_gpio (void){
static bool dos_read_som_gpio (void){
return (get_gpio_input(GPIOC, 2) != 0);
}
void dos_init(void) {
static void dos_init(void) {
common_init_gpio();
// A8,A15: normal CAN3 mode
@ -166,7 +170,7 @@ void dos_init(void) {
clock_source_init();
}
harness_configuration dos_harness_config = {
static harness_configuration dos_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,

View File

@ -1,3 +1,7 @@
#pragma once
#include "board_declarations.h"
// //////////////////// //
// Grey Panda (STM32F4) //
// //////////////////// //

View File

@ -1,8 +1,12 @@
#pragma once
#include "board_declarations.h"
// ///////////////////////////// //
// Red Panda (STM32H7) + Harness //
// ///////////////////////////// //
void red_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void red_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver) {
case 1U:
set_gpio_output(GPIOG, 11, !enabled);
@ -21,7 +25,7 @@ void red_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}
void red_enable_can_transceivers(bool enabled) {
static void red_enable_can_transceivers(bool enabled) {
uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U;
for (uint8_t i=1U; i<=4U; i++) {
// Leave main CAN always on for CAN-based ignition detection
@ -33,7 +37,7 @@ void red_enable_can_transceivers(bool enabled) {
}
}
void red_set_led(uint8_t color, bool enabled) {
static void red_set_led(uint8_t color, bool enabled) {
switch (color) {
case LED_RED:
set_gpio_output(GPIOE, 4, !enabled);
@ -49,7 +53,7 @@ void red_set_led(uint8_t color, bool enabled) {
}
}
void red_set_can_mode(uint8_t mode) {
static void red_set_can_mode(uint8_t mode) {
red_enable_can_transceiver(2U, false);
red_enable_can_transceiver(4U, false);
switch (mode) {
@ -91,16 +95,16 @@ void red_set_can_mode(uint8_t mode) {
}
}
bool red_check_ignition(void) {
static bool red_check_ignition(void) {
// ignition is checked through harness
return harness_check_ignition();
}
uint32_t red_read_voltage_mV(void){
static uint32_t red_read_voltage_mV(void){
return adc_get_mV(2) * 11U; // TODO: is this correct?
}
void red_init(void) {
static void red_init(void) {
common_init_gpio();
//C10,C11 : OBD_SBU1_RELAY, OBD_SBU2_RELAY
@ -153,7 +157,7 @@ void red_init(void) {
red_set_can_mode(CAN_MODE_NORMAL);
}
harness_configuration red_harness_config = {
static harness_configuration red_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOA,

View File

@ -1,10 +1,14 @@
#pragma once
#include "board_declarations.h"
// ///////////////////////////////////// //
// Red Panda chiplet (STM32H7) + Harness //
// ///////////////////////////////////// //
// Most hardware functionality is similar to red panda
void red_chiplet_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void red_chiplet_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver) {
case 1U:
set_gpio_output(GPIOG, 11, !enabled);
@ -23,7 +27,7 @@ void red_chiplet_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}
void red_chiplet_enable_can_transceivers(bool enabled) {
static void red_chiplet_enable_can_transceivers(bool enabled) {
uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U;
for (uint8_t i=1U; i<=4U; i++) {
// Leave main CAN always on for CAN-based ignition detection
@ -35,7 +39,7 @@ void red_chiplet_enable_can_transceivers(bool enabled) {
}
}
void red_chiplet_set_can_mode(uint8_t mode) {
static void red_chiplet_set_can_mode(uint8_t mode) {
red_chiplet_enable_can_transceiver(2U, false);
red_chiplet_enable_can_transceiver(4U, false);
switch (mode) {
@ -77,11 +81,11 @@ void red_chiplet_set_can_mode(uint8_t mode) {
}
}
void red_chiplet_set_fan_or_usb_load_switch(bool enabled) {
static void red_chiplet_set_fan_or_usb_load_switch(bool enabled) {
set_gpio_output(GPIOD, 3, enabled);
}
void red_chiplet_init(void) {
static void red_chiplet_init(void) {
common_init_gpio();
// A8, A3: OBD_SBU1_RELAY, OBD_SBU2_RELAY
@ -132,7 +136,7 @@ void red_chiplet_init(void) {
red_chiplet_set_can_mode(CAN_MODE_NORMAL);
}
harness_configuration red_chiplet_harness_config = {
static harness_configuration red_chiplet_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOA,

View File

@ -1,35 +1,39 @@
#pragma once
#include "board_declarations.h"
// ///////////////////////////
// Tres (STM32H7) + Harness //
// ///////////////////////////
bool tres_ir_enabled;
bool tres_fan_enabled;
void tres_update_fan_ir_power(void) {
static bool tres_ir_enabled;
static bool tres_fan_enabled;
static void tres_update_fan_ir_power(void) {
red_chiplet_set_fan_or_usb_load_switch(tres_ir_enabled || tres_fan_enabled);
}
void tres_set_ir_power(uint8_t percentage){
static void tres_set_ir_power(uint8_t percentage){
tres_ir_enabled = (percentage > 0U);
tres_update_fan_ir_power();
pwm_set(TIM3, 4, percentage);
}
void tres_set_bootkick(BootState state) {
static void tres_set_bootkick(BootState state) {
set_gpio_output(GPIOA, 0, state != BOOT_BOOTKICK);
set_gpio_output(GPIOC, 12, state != BOOT_RESET);
}
void tres_set_fan_enabled(bool enabled) {
static void tres_set_fan_enabled(bool enabled) {
// NOTE: fan controller reset doesn't work on a tres if IR is enabled
tres_fan_enabled = enabled;
tres_update_fan_ir_power();
}
bool tres_read_som_gpio (void) {
static bool tres_read_som_gpio (void) {
return (get_gpio_input(GPIOC, 2) != 0);
}
void tres_init(void) {
static void tres_init(void) {
// Enable USB 3.3V LDO for USB block
register_set_bits(&(PWR->CR3), PWR_CR3_USBREGEN);
register_set_bits(&(PWR->CR3), PWR_CR3_USB33DEN);

View File

@ -1,8 +1,12 @@
#pragma once
#include "board_declarations.h"
// /////////////////////// //
// Uno (STM32F4) + Harness //
// /////////////////////// //
void uno_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void uno_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
@ -22,7 +26,7 @@ void uno_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}
void uno_enable_can_transceivers(bool enabled) {
static void uno_enable_can_transceivers(bool enabled) {
for(uint8_t i=1U; i<=4U; i++){
// Leave main CAN always on for CAN-based ignition detection
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
@ -33,7 +37,7 @@ void uno_enable_can_transceivers(bool enabled) {
}
}
void uno_set_led(uint8_t color, bool enabled) {
static void uno_set_led(uint8_t color, bool enabled) {
switch (color){
case LED_RED:
set_gpio_output(GPIOC, 9, !enabled);
@ -49,7 +53,7 @@ void uno_set_led(uint8_t color, bool enabled) {
}
}
void uno_set_bootkick(BootState state) {
static void uno_set_bootkick(BootState state) {
if (state == BOOT_BOOTKICK) {
set_gpio_output(GPIOB, 14, false);
} else {
@ -58,7 +62,7 @@ void uno_set_bootkick(BootState state) {
}
}
void uno_set_can_mode(uint8_t mode) {
static void uno_set_can_mode(uint8_t mode) {
uno_enable_can_transceiver(2U, false);
uno_enable_can_transceiver(4U, false);
switch (mode) {
@ -90,24 +94,24 @@ void uno_set_can_mode(uint8_t mode) {
}
}
bool uno_check_ignition(void){
static bool uno_check_ignition(void){
// ignition is checked through harness
return harness_check_ignition();
}
void uno_set_usb_switch(bool phone){
static void uno_set_usb_switch(bool phone){
set_gpio_output(GPIOB, 3, phone);
}
void uno_set_ir_power(uint8_t percentage){
static void uno_set_ir_power(uint8_t percentage){
pwm_set(TIM4, 2, percentage);
}
void uno_set_fan_enabled(bool enabled){
static void uno_set_fan_enabled(bool enabled){
set_gpio_output(GPIOA, 1, enabled);
}
void uno_init(void) {
static void uno_init(void) {
common_init_gpio();
// A8,A15: normal CAN3 mode
@ -170,14 +174,14 @@ void uno_init(void) {
uno_set_bootkick(BOOT_BOOTKICK);
}
void uno_init_bootloader(void) {
static void uno_init_bootloader(void) {
// GPS off
set_gpio_output(GPIOB, 1, 0);
set_gpio_output(GPIOC, 5, 0);
set_gpio_output(GPIOC, 12, 0);
}
harness_configuration uno_harness_config = {
static harness_configuration uno_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,

View File

@ -1,3 +1,5 @@
#pragma once
void unused_init_bootloader(void) {
}
@ -23,4 +25,4 @@ void unused_set_bootkick(BootState state) {
bool unused_read_som_gpio(void) {
return false;
}
}

View File

@ -1,8 +1,12 @@
#pragma once
#include "board_declarations.h"
// ///////////////////// //
// White Panda (STM32F4) //
// ///////////////////// //
void white_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void white_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
@ -19,14 +23,14 @@ void white_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}
void white_enable_can_transceivers(bool enabled) {
static void white_enable_can_transceivers(bool enabled) {
uint8_t t1 = enabled ? 1U : 2U; // leave transceiver 1 enabled to detect CAN ignition
for(uint8_t i=t1; i<=3U; i++) {
white_enable_can_transceiver(i, enabled);
}
}
void white_set_led(uint8_t color, bool enabled) {
static void white_set_led(uint8_t color, bool enabled) {
switch (color){
case LED_RED:
set_gpio_output(GPIOC, 9, !enabled);
@ -42,7 +46,7 @@ void white_set_led(uint8_t color, bool enabled) {
}
}
void white_set_usb_power_mode(uint8_t mode){
static void white_set_usb_power_mode(uint8_t mode){
switch (mode) {
case USB_POWER_CLIENT:
// B2,A13: set client mode
@ -65,7 +69,7 @@ void white_set_usb_power_mode(uint8_t mode){
}
}
void white_set_can_mode(uint8_t mode){
static void white_set_can_mode(uint8_t mode){
if (mode == CAN_MODE_NORMAL) {
// B12,B13: disable GMLAN mode
set_gpio_mode(GPIOB, 12, MODE_INPUT);
@ -85,21 +89,21 @@ void white_set_can_mode(uint8_t mode){
}
}
uint32_t white_read_voltage_mV(void){
static uint32_t white_read_voltage_mV(void){
return adc_get_mV(12) * 11U;
}
uint32_t white_read_current_mA(void){
static uint32_t white_read_current_mA(void){
// This isn't in mA, but we're keeping it for backwards compatibility
return adc_get_raw(13);
}
bool white_check_ignition(void){
static bool white_check_ignition(void){
// ignition is on PA1
return !get_gpio_input(GPIOA, 1);
}
void white_grey_init(void) {
static void white_grey_init(void) {
common_init_gpio();
// C3: current sense
@ -174,13 +178,13 @@ void white_grey_init(void) {
set_gpio_output(GPIOC, 14, 0);
}
void white_grey_init_bootloader(void) {
static void white_grey_init_bootloader(void) {
// ESP/GPS off
set_gpio_output(GPIOC, 5, 0);
set_gpio_output(GPIOC, 14, 0);
}
harness_configuration white_harness_config = {
static harness_configuration white_harness_config = {
.has_harness = false
};