diff --git a/Core/Inc/monitor.h b/Core/Inc/monitor.h index 374d5427..6bb3b7fd 100644 --- a/Core/Inc/monitor.h +++ b/Core/Inc/monitor.h @@ -6,7 +6,16 @@ /* Defining Temperature Monitor Task */ void vTempMonitor(void *pv_params); +/** + * @brief Pet the watchdog + * @param pv_params GPIO_TypeDef pointer to the watchdog pin + */ +void vWatchdogMonitor(void *pv_params); + extern osThreadId_t temp_monitor_handle; extern const osThreadAttr_t temp_monitor_attributes; +extern osThreadId_t watchdog_monitor_handle; +extern const osThreadAttr_t watchdog_monitor_attributes; + #endif // MONITOR_H \ No newline at end of file diff --git a/Core/Src/main.c b/Core/Src/main.c index 9237e687..5d0f494c 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -148,7 +148,10 @@ int main(void) /* USER CODE BEGIN RTOS_THREADS */ temp_monitor_handle = osThreadNew(vTempMonitor, &hi2c1, &temp_monitor_attributes); + watchdog_monitor_handle = osThreadNew(vWatchdogMonitor, GPIOB, &watchdog_monitor_attributes); + route_can_incoming_handle = osThreadNew(vRouteCanIncoming, &hcan1, &route_can_incoming_attributes); + /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ diff --git a/Core/Src/monitor.c b/Core/Src/monitor.c index ed18a78e..f8707f7d 100644 --- a/Core/Src/monitor.c +++ b/Core/Src/monitor.c @@ -6,6 +6,7 @@ #include "can.h" #include "fault.h" #include "sht30.h" +#include "stm32f405xx.h" osThreadId_t temp_monitor_handle; const osThreadAttr_t temp_monitor_attributes = { @@ -42,7 +43,6 @@ void vTempMonitor(void *pv_params) } for(;;) { - /* Take measurement */ if (sht30_get_temp_humid(&temp_sensor)) { fault_data.diag = "Failed to get temp"; @@ -68,4 +68,31 @@ void vTempMonitor(void *pv_params) /* Yield to other tasks */ osDelayUntil(temp_sensor_sample_delay); } -} \ No newline at end of file +} + +osThreadId_t watchdog_monitor_handle; +const osThreadAttr_t watchdog_monitor_attributes = { + .name = "WatchdogMonitor", + .stack_size = 128 * 4, + .priority = (osPriority_t) osPriorityLow, +}; + +void vWatchdogMonitor(void *pv_params) +{ + GPIO_TypeDef *gpio; + gpio = (GPIO_TypeDef *)pv_params; + + for(;;) { + /* Pets Watchdog */ + HAL_GPIO_WritePin(gpio, GPIO_PIN_15, GPIO_PIN_SET); + + /* Delay for 5ms */ + osDelay(5); + + /* Set Low Again */ + HAL_GPIO_WritePin(gpio, GPIO_PIN_15, GPIO_PIN_RESET); + + /* Yield to other RTOS tasks */ + osThreadYield(); + } +}