-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added PD fault module * Moving unnecessary include * Exposing only update routine * Added requested fixes * Removed unnecessary things
- Loading branch information
1 parent
9e2b3dc
commit 23b2a16
Showing
6 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include "status.h" | ||
|
||
/* | ||
* @brief Checks for PD fault states and updates fault bitset CAN message | ||
* @return STATUS_CODE_OK on success or appropriate error code | ||
*/ | ||
StatusCode check_pd_fault(void); |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "pd_fault.h" | ||
|
||
#include "adc.h" | ||
#include "exported_enums.h" | ||
#include "gpio.h" | ||
#include "pin_defs.h" | ||
#include "power_distribution_setters.h" | ||
|
||
static uint8_t s_fault_bitset = 0; | ||
|
||
// Fault pin address definitions | ||
static const GpioAddress aux_fault_gpio_1 = AUX_FAULT_GPIO_1; | ||
static const GpioAddress aux_fault_gpio_2 = AUX_FAULT_GPIO_2; | ||
static const GpioAddress dcdc_fault_gpio_1 = DCDC_FAULT_GPIO_1; | ||
static const GpioAddress dcdc_fault_gpio_2 = DCDC_FAULT_GPIO_2; | ||
static const GpioAddress dcdc_fault_gpio_3 = DCDC_FAULT_GPIO_3; | ||
|
||
static void prv_set_fault_bit(uint8_t mask, bool condition) { | ||
if (condition) { | ||
s_fault_bitset |= mask; | ||
} else { | ||
s_fault_bitset &= ~(mask); | ||
} | ||
} | ||
|
||
static StatusCode prv_check_aux_fault(void) { | ||
GpioState aux_gpio_1_state; | ||
GpioState aux_gpio_2_state; | ||
status_ok_or_return(gpio_get_state(&aux_fault_gpio_1, &aux_gpio_1_state)); | ||
status_ok_or_return(gpio_get_state(&aux_fault_gpio_2, &aux_gpio_2_state)); | ||
|
||
bool aux_fault = (aux_gpio_1_state == GPIO_STATE_LOW || aux_gpio_2_state == GPIO_STATE_LOW); | ||
prv_set_fault_bit(EE_PD_STATUS_FAULT_BITSET_AUX_FAULT_MASK, aux_fault); | ||
|
||
return STATUS_CODE_OK; | ||
} | ||
|
||
static StatusCode prv_check_dcdc_fault(void) { | ||
GpioState dcdc_gpio_1_state; | ||
GpioState dcdc_gpio_2_state; | ||
GpioState dcdc_gpio_3_state; | ||
status_ok_or_return(gpio_get_state(&dcdc_fault_gpio_1, &dcdc_gpio_1_state)); | ||
status_ok_or_return(gpio_get_state(&dcdc_fault_gpio_2, &dcdc_gpio_2_state)); | ||
status_ok_or_return(gpio_get_state(&dcdc_fault_gpio_3, &dcdc_gpio_3_state)); | ||
|
||
bool dcdc_fault = (dcdc_gpio_1_state == GPIO_STATE_LOW || dcdc_gpio_2_state == GPIO_STATE_LOW || | ||
dcdc_gpio_3_state == GPIO_STATE_HIGH); | ||
prv_set_fault_bit(EE_PD_STATUS_FAULT_BITSET_DCDC_FAULT_MASK, dcdc_fault); | ||
|
||
return STATUS_CODE_OK; | ||
} | ||
|
||
StatusCode check_pd_fault() { | ||
status_ok_or_return(prv_check_aux_fault()); | ||
status_ok_or_return(prv_check_dcdc_fault()); | ||
|
||
set_pd_status_fault_bitset(s_fault_bitset); | ||
|
||
return STATUS_CODE_OK; | ||
} |