Wakeup and Standby systems
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include "BSP_INA.h"
|
||||
#include "BSP_POWER.h"
|
||||
#include "LightTask.h"
|
||||
#include "BSP_GPIO.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -65,12 +66,20 @@ const osThreadAttr_t defaultTask_attributes = {
|
||||
.priority = (osPriority_t) osPriorityNormal,
|
||||
};
|
||||
|
||||
osThreadId_t waitForStartConfirmHandle;
|
||||
const osThreadAttr_t waitForStartConfirm_attributes = {
|
||||
.name = "waitForStartConfirm",
|
||||
.stack_size = 128 * 4,
|
||||
.priority = (osPriority_t) osPriorityNormal,
|
||||
};
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
|
||||
/* USER CODE END FunctionPrototypes */
|
||||
|
||||
void StartDefaultTask(void *argument);
|
||||
void WaitForStartConfirm_Task(void *argument);
|
||||
|
||||
extern void MX_USB_DEVICE_Init(void);
|
||||
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
||||
@@ -99,7 +108,6 @@ return __HAL_TIM_GetCounter(&htim2);
|
||||
*/
|
||||
void MX_FREERTOS_Init(void) {
|
||||
/* USER CODE BEGIN Init */
|
||||
BSP_POWER_Init();
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* USER CODE BEGIN RTOS_MUTEX */
|
||||
@@ -123,6 +131,9 @@ void MX_FREERTOS_Init(void) {
|
||||
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
||||
|
||||
/* USER CODE BEGIN RTOS_THREADS */
|
||||
|
||||
waitForStartConfirmHandle = osThreadNew(WaitForStartConfirm_Task, NULL, &waitForStartConfirm_attributes);
|
||||
|
||||
ULOG_INFO("Setup UsbDataHandler");
|
||||
UsbDataHandler_Start();
|
||||
ULOG_INFO("Setup CanDataTask");
|
||||
@@ -200,5 +211,34 @@ void StartDefaultTask(void *argument)
|
||||
/* Private application code --------------------------------------------------*/
|
||||
/* USER CODE BEGIN Application */
|
||||
|
||||
void WaitForStartConfirm_Task(void *argument) {
|
||||
|
||||
// wait for up to 1 s and check if either K15 is set or we got a Car CAN message
|
||||
// once one of these is true, we can start the power systems.
|
||||
// after waiting for 1s, the system should shutdown / go to standby mode
|
||||
uint32_t tick = osKernelGetTickCount();
|
||||
uint32_t delayTime = 50; // Set the initial delay time to 50ms
|
||||
uint32_t maxDelayTime = 1000; // Set the maximum delay time to 1000ms
|
||||
|
||||
while(1) {
|
||||
osDelayUntil(tick);
|
||||
tick += delayTime;
|
||||
if(BSP_GPIO_K15isSet() || CanDataTask_gotCarCanMessage()) {
|
||||
BSP_GPIO_ClsOn();
|
||||
BSP_GPIO_RadioOn();
|
||||
ULOG_INFO("Power systems started");
|
||||
osThreadExit();
|
||||
return;
|
||||
}
|
||||
|
||||
if(tick > maxDelayTime) {
|
||||
BSP_POWER_EnterStandby();
|
||||
ULOG_INFO("System in standby mode");
|
||||
osThreadExit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE END Application */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user