Adapt to inverted SDC close

This commit is contained in:
2023-08-04 23:00:31 +02:00
parent 1e4e5a91aa
commit f97daa8df3
5 changed files with 29 additions and 13 deletions

View File

@ -144,6 +144,7 @@ mission_t mission = M_NONE;
bool setup_done = false;
#ifdef WATCHDOG_STM
bool heartbeat_received = false;
bool pHeartbeat = false;
bool WD_OK = false;
bool WD_initialized = false;
@ -198,6 +199,7 @@ int main(void)
#if false
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_CAN_Init();
@ -209,7 +211,7 @@ int main(void)
__HAL_DBGMCU_FREEZE_IWDG();
// Ensure we start with SDC disabled
HAL_GPIO_WritePin(AS_close_SDC_GPIO_Port, AS_close_SDC_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(AS_close_SDC_GPIO_Port, AS_close_SDC_Pin, GPIO_PIN_SET);
if (HAL_CAN_Start(&hcan) != HAL_OK)
Error_Handler();
@ -458,7 +460,10 @@ static void MX_GPIO_Init(void)
|AMI_AUTOX_Pin|AMI_SKIDPAD_Pin|AMI_ACCEL_Pin|AMI_MANUAL_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, AS_close_SDC_Pin|Watchdog_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(AS_close_SDC_GPIO_Port, AS_close_SDC_Pin, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(Watchdog_GPIO_Port, Watchdog_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : TS_activate_MUXed_Pin ASMS_Pin INITIAL_OPEN_Pin CLOSED_Pin
REOPENED_Pin WD_OK_Pin SDC_is_ready_Pin SDC_in_3V3_Pin
@ -515,7 +520,10 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) {
if (rxData.signals.heartbeat != pHeartbeat) {
if (WD_initialized)
HAL_IWDG_Refresh(&hiwdg);
WD_OK = true;
if (heartbeat_received) {
WD_OK = true;
}
heartbeat_received = true;
//HAL_GPIO_WritePin(Watchdog_GPIO_Port, Watchdog_Pin, GPIO_PIN_SET);
}
pHeartbeat = rxData.signals.heartbeat;
@ -530,8 +538,9 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) {
bool close_sdc = rxData.signals.as_close_sdc;
#endif
// Set whether to close the relay
HAL_GPIO_WritePin(AS_close_SDC_GPIO_Port, AS_close_SDC_Pin, close_sdc);
// Set whether to close the relay. The port is inverted due to multiple bodges
GPIO_PinState close_sdc_val = close_sdc ? GPIO_PIN_RESET : GPIO_PIN_SET;
HAL_GPIO_WritePin(AS_close_SDC_GPIO_Port, AS_close_SDC_Pin, close_sdc_val);
// Reset old mission LED
setMissionLED(mission, GPIO_PIN_RESET);