Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#54 Pet the Watchdog #76

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Core/Inc/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
31 changes: 29 additions & 2 deletions Core/Src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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";
Expand All @@ -68,4 +68,31 @@ void vTempMonitor(void *pv_params)
/* Yield to other tasks */
osDelayUntil(temp_sensor_sample_delay);
}
}
}

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);
Peyton-McKee marked this conversation as resolved.
Show resolved Hide resolved

/* Delay for 5ms */
osDelay(5);

/* Set Low Again */
HAL_GPIO_WritePin(gpio, GPIO_PIN_15, GPIO_PIN_RESET);

/* Yield to other RTOS tasks */
osThreadYield();
}
}