PER Firmware
Loading...
Searching...
No Matches
switch.h
Go to the documentation of this file.
1
8#ifndef SWITCH_H
9#define SWITCH_H
10
11#include "phal_G4/gpio/gpio.h"
12#include "can_library/generated/PDU.h"
13
14static constexpr uint8_t NUM_SWITCHES = SWITCH_ID_EMETER + 1;
15
16typedef enum {
20
21typedef struct {
22 GPIO_TypeDef* ctrl_port;
23 uint8_t ctrl_pin;
25 uint8_t mux_addr;
26 fault_id_t fault_id;
28} switch_t;
29
30// TPS27S100B IMON current sense: G_IMON = 500 A/A, R1 = 180 ohm, R2 = 330 ohm
31static constexpr float SWITCH_IMON_R1_OHMS = 180.0f;
32static constexpr float SWITCH_IMON_R2_OHMS = 330.0f;
33static constexpr float SWITCH_CURRENT_SENSE_GAIN = 500.0f;
35
36// High power switch outputs 4.75v on fault -> scaled by R1=180, R2=330
37static constexpr float SWITCH_FAULT_SENSE_V = 4.75f;
38
39// todo: tune margin
40static constexpr float SWITCH_FAULT_MARGIN = 0.95f;
41static constexpr float SWITCH_FAULT_CURRENT_THRESHOLD_MA =
44 * 1000.0f
46
47
49
50void SWITCH_enable(switch_id_t switch_id);
51void SWITCH_disable(switch_id_t switch_id);
52
53
54void SWITCH_enable_all(void);
55
56#endif // SWITCH_H
G4 GPIO public API.
Definition switch.h:21
float current_ma
Definition switch.h:27
uint8_t mux_addr
Definition switch.h:25
mux_id_t mux_id
Definition switch.h:24
fault_id_t fault_id
Definition switch.h:26
GPIO_TypeDef * ctrl_port
Definition switch.h:22
uint8_t ctrl_pin
Definition switch.h:23
static constexpr float SWITCH_CURRENT_SENSE_GAIN
Definition switch.h:33
void SWITCH_disable(switch_id_t switch_id)
Definition switch.c:178
void SWITCH_enable_all(void)
Definition switch.c:193
switch_t g_switches[NUM_SWITCHES]
Definition switch.c:14
static constexpr float SWITCH_FAULT_MARGIN
Definition switch.h:40
void SWITCH_enable(switch_id_t switch_id)
Definition switch.c:166
static constexpr float SWITCH_IMON_R1_OHMS
Definition switch.h:31
static constexpr float SWITCH_SENSE_DIVIDER_GAIN
Definition switch.h:34
mux_id_t
Definition switch.h:16
@ ANALOG_MUX2
Definition switch.h:18
@ ANALOG_MUX1
Definition switch.h:17
static constexpr float SWITCH_FAULT_CURRENT_THRESHOLD_MA
Definition switch.h:41
static constexpr float SWITCH_IMON_R2_OHMS
Definition switch.h:32
static constexpr uint8_t NUM_SWITCHES
Definition switch.h:14
static constexpr float SWITCH_FAULT_SENSE_V
Definition switch.h:37