2021-03-09 18:17:28 +08:00
|
|
|
/*
|
|
|
|
* @Description:
|
|
|
|
* @Date: 2020-04-02 21:44:31
|
|
|
|
* @LastEditors: CK.Zh
|
|
|
|
* @LastEditTime: 2021-03-09 18:11:08
|
|
|
|
* @FilePath: \NaviKit_EC_stm32\Core\Src\freertos.c
|
|
|
|
*/
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE BEGIN Header */
|
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* File Name : freertos.c
|
|
|
|
* Description : Code for freertos applications
|
|
|
|
******************************************************************************
|
|
|
|
* @attention
|
|
|
|
*
|
|
|
|
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
|
|
|
* All rights reserved.</center></h2>
|
|
|
|
*
|
|
|
|
* This software component is licensed by ST under Ultimate Liberty license
|
|
|
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at:
|
|
|
|
* www.st.com/SLA0044
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
2021-03-09 18:17:28 +08:00
|
|
|
|
|
|
|
//TODO:拆分该文件中的功能到不同的文件中,按照任务进行模块化拆分
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END Header */
|
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
2021-03-09 18:17:28 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
#include "FreeRTOS.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "cmsis_os.h"
|
|
|
|
|
|
|
|
/* Private includes ----------------------------------------------------------*/
|
2020-12-16 12:02:47 +08:00
|
|
|
/* USER CODE BEGIN Includes */
|
2021-01-05 14:46:47 +08:00
|
|
|
#include "timers.h"
|
2020-04-17 15:55:14 +08:00
|
|
|
#include "navikit.h"
|
2020-04-27 18:19:02 +08:00
|
|
|
#include "coulomb.h"
|
2021-03-09 18:17:28 +08:00
|
|
|
#include <th_cdc.h>
|
|
|
|
#include <th_demo.h>
|
|
|
|
#include <th_elog.h>
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END Includes */
|
|
|
|
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN PTD */
|
|
|
|
|
|
|
|
/* USER CODE END PTD */
|
|
|
|
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN PD */
|
|
|
|
|
|
|
|
/* USER CODE END PD */
|
|
|
|
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN PM */
|
|
|
|
|
|
|
|
/* USER CODE END PM */
|
|
|
|
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN Variables */
|
2021-03-09 18:17:28 +08:00
|
|
|
|
2021-01-07 19:01:08 +08:00
|
|
|
//Timer
|
2021-01-07 15:11:11 +08:00
|
|
|
osTimerId_t PwrBtnLongPressTimerHandle;
|
|
|
|
const osTimerAttr_t PwrBtnLongPressTimer_attributes = {
|
|
|
|
.name = "PwrBtnLongPressTimer"
|
|
|
|
};
|
|
|
|
osTimerId_t CustBtnLongPressTimerHandle;
|
|
|
|
const osTimerAttr_t CustBtnLongPressTimer_attributes = {
|
|
|
|
.name = "CustBtnLongPressTimer"
|
|
|
|
};
|
|
|
|
osTimerId_t PwrBtnShortPressTimerHandle;
|
|
|
|
const osTimerAttr_t PwrBtnShortPressTimer_attributes = {
|
|
|
|
.name = "PwrBtnShortPressTimer"
|
|
|
|
};
|
|
|
|
osTimerId_t CustBtnShortPressTimerHandle;
|
|
|
|
const osTimerAttr_t CustBtnShortPressTimer_attributes = {
|
|
|
|
.name = "CustBtnShortPressTimer"
|
2021-01-05 14:46:47 +08:00
|
|
|
};
|
2021-01-07 19:01:08 +08:00
|
|
|
osTimerId_t IdleStateHoldTimerHandle;
|
|
|
|
const osTimerAttr_t IdleStateHoldTimer_attributes = {
|
|
|
|
.name = "IdleStateHoldTimer"
|
|
|
|
};
|
|
|
|
|
|
|
|
//Thread
|
2021-02-05 18:22:21 +08:00
|
|
|
|
2021-01-07 19:01:08 +08:00
|
|
|
osThreadId_t LogtoUartTaskHandle;
|
|
|
|
const osThreadAttr_t LogtoUartTask_attributes = {
|
|
|
|
.name = "LogtoUartTask",
|
|
|
|
.priority = (osPriority_t) osPriorityBelowNormal,
|
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
|
|
|
|
2021-03-09 18:17:28 +08:00
|
|
|
|
2021-01-07 19:01:08 +08:00
|
|
|
|
|
|
|
//Queue
|
|
|
|
//osMessageQueueId_t LogMessageQueueHandle;
|
|
|
|
//const osMessageQueueAttr_t LogMessageQueue_attributes = {
|
|
|
|
// .name = "LogMessageQueue"
|
|
|
|
//};
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END Variables */
|
2020-04-06 21:16:18 +08:00
|
|
|
/* Definitions for defaultTask */
|
|
|
|
osThreadId_t defaultTaskHandle;
|
|
|
|
const osThreadAttr_t defaultTask_attributes = {
|
|
|
|
.name = "defaultTask",
|
|
|
|
.priority = (osPriority_t) osPriorityNormal,
|
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
2020-04-14 17:27:52 +08:00
|
|
|
/* Definitions for LedBlinkTask */
|
|
|
|
osThreadId_t LedBlinkTaskHandle;
|
|
|
|
const osThreadAttr_t LedBlinkTask_attributes = {
|
|
|
|
.name = "LedBlinkTask",
|
|
|
|
.priority = (osPriority_t) osPriorityLow,
|
2020-04-10 19:05:38 +08:00
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
2020-04-27 18:19:02 +08:00
|
|
|
/* Definitions for CoulombRead */
|
|
|
|
osThreadId_t CoulombReadHandle;
|
|
|
|
const osThreadAttr_t CoulombRead_attributes = {
|
|
|
|
.name = "CoulombRead",
|
|
|
|
.priority = (osPriority_t) osPriorityLow,
|
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
2020-08-25 19:33:15 +08:00
|
|
|
/* Definitions for PowerMonitTask */
|
|
|
|
osThreadId_t PowerMonitTaskHandle;
|
|
|
|
const osThreadAttr_t PowerMonitTask_attributes = {
|
|
|
|
.name = "PowerMonitTask",
|
2020-07-15 18:26:22 +08:00
|
|
|
.priority = (osPriority_t) osPriorityLow,
|
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
2021-01-05 14:46:47 +08:00
|
|
|
/* Definitions for EventDetect */
|
|
|
|
osThreadId_t EventDetectHandle;
|
|
|
|
const osThreadAttr_t EventDetect_attributes = {
|
|
|
|
.name = "EventDetect",
|
|
|
|
.priority = (osPriority_t) osPriorityLow,
|
|
|
|
.stack_size = 128 * 4
|
|
|
|
};
|
2020-04-02 22:18:11 +08:00
|
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN FunctionPrototypes */
|
2021-01-07 15:11:11 +08:00
|
|
|
|
2021-01-05 14:46:47 +08:00
|
|
|
bool isWakeUpReset() { return __HAL_PWR_GET_FLAG(PWR_FLAG_WU);}
|
2021-01-07 19:01:08 +08:00
|
|
|
//callback
|
2021-01-07 15:11:11 +08:00
|
|
|
void PwrBtnLongPressTimerCallback(void *argument);
|
|
|
|
void CustBtnLongPressTimerCallback(void *argument);
|
|
|
|
void PwrBtnShortPressTimerCallback(void *argument);
|
|
|
|
void CustBtnShortPressTimerCallback(void *argument);
|
|
|
|
|
2021-01-07 19:01:08 +08:00
|
|
|
void IdleStateHoldTimerCallback(void *argument);
|
|
|
|
|
|
|
|
//task
|
|
|
|
void StartLogtoUartTask(void *argument);
|
|
|
|
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END FunctionPrototypes */
|
|
|
|
|
2020-04-14 17:27:52 +08:00
|
|
|
void StartDefaultTask(void *argument);
|
|
|
|
void StartLedBlinkTask(void *argument);
|
2020-04-27 18:19:02 +08:00
|
|
|
void StartCoulombRead(void *argument);
|
2020-08-25 19:33:15 +08:00
|
|
|
void StartPowerMonitTask(void *argument);
|
2021-01-05 14:46:47 +08:00
|
|
|
void StartEventDetect(void *argument);
|
2020-04-02 22:18:11 +08:00
|
|
|
|
|
|
|
extern void MX_USB_DEVICE_Init(void);
|
|
|
|
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
|
|
|
|
2020-12-17 18:22:19 +08:00
|
|
|
/* Hook prototypes */
|
|
|
|
void configureTimerForRunTimeStats(void);
|
|
|
|
unsigned long getRunTimeCounterValue(void);
|
|
|
|
void vApplicationIdleHook(void);
|
|
|
|
void vApplicationTickHook(void);
|
|
|
|
void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName);
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
|
|
|
|
__weak void configureTimerForRunTimeStats(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__weak unsigned long getRunTimeCounterValue(void)
|
|
|
|
{
|
2021-01-07 15:11:11 +08:00
|
|
|
// return osKernelGetTickCount();
|
2020-12-17 18:22:19 +08:00
|
|
|
}
|
|
|
|
/* USER CODE END 1 */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
void vApplicationIdleHook( void )
|
|
|
|
{
|
|
|
|
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
|
|
|
|
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
|
|
|
|
task. It is essential that code added to this hook function never attempts
|
|
|
|
to block in any way (for example, call xQueueReceive() with a block time
|
|
|
|
specified, or call vTaskDelay()). If the application makes use of the
|
|
|
|
vTaskDelete() API function (as this demo application does) then it is also
|
|
|
|
important that vApplicationIdleHook() is permitted to return to its calling
|
|
|
|
function, because it is the responsibility of the idle task to clean up
|
|
|
|
memory allocated by the kernel to any task that has since been deleted. */
|
|
|
|
}
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
|
void vApplicationTickHook( void )
|
|
|
|
{
|
|
|
|
/* This function will be called by each tick interrupt if
|
|
|
|
configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
|
|
|
|
added here, but the tick hook is called from an interrupt context, so
|
|
|
|
code must not attempt to block, and only the interrupt safe FreeRTOS API
|
|
|
|
functions can be used (those that end in FromISR()). */
|
|
|
|
}
|
|
|
|
/* USER CODE END 3 */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 4 */
|
|
|
|
void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName)
|
|
|
|
{
|
|
|
|
/* Run time stack overflow checking is performed if
|
|
|
|
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
|
|
|
|
called if a stack overflow is detected. */
|
|
|
|
}
|
|
|
|
/* USER CODE END 4 */
|
|
|
|
|
2020-12-18 12:46:59 +08:00
|
|
|
/* USER CODE BEGIN PREPOSTSLEEP */
|
|
|
|
__weak void PreSleepProcessing(uint32_t *ulExpectedIdleTime)
|
|
|
|
{
|
|
|
|
/* place for user code */
|
2021-01-05 14:46:47 +08:00
|
|
|
|
2020-12-18 12:46:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
__weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
|
|
|
|
{
|
|
|
|
/* place for user code */
|
2021-01-05 14:46:47 +08:00
|
|
|
|
2020-12-18 12:46:59 +08:00
|
|
|
}
|
|
|
|
/* USER CODE END PREPOSTSLEEP */
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/**
|
|
|
|
* @brief FreeRTOS initialization
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
void MX_FREERTOS_Init(void) {
|
|
|
|
/* USER CODE BEGIN Init */
|
2021-03-09 18:17:28 +08:00
|
|
|
// elog_init();
|
|
|
|
my_elog_init();
|
|
|
|
NaviKit_var_init();
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END Init */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN RTOS_MUTEX */
|
|
|
|
/* add mutexes, ... */
|
|
|
|
/* USER CODE END RTOS_MUTEX */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
|
|
/* add semaphores, ... */
|
|
|
|
/* USER CODE END RTOS_SEMAPHORES */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN RTOS_TIMERS */
|
|
|
|
/* start timers, add new ones, ... */
|
2021-01-07 15:11:11 +08:00
|
|
|
PwrBtnLongPressTimerHandle = osTimerNew(PwrBtnLongPressTimerCallback, osTimerOnce, NULL, &PwrBtnLongPressTimer_attributes);
|
|
|
|
CustBtnLongPressTimerHandle = osTimerNew(CustBtnLongPressTimerCallback, osTimerOnce, NULL, &CustBtnLongPressTimer_attributes);
|
|
|
|
PwrBtnShortPressTimerHandle = osTimerNew(PwrBtnShortPressTimerCallback, osTimerOnce, NULL, &PwrBtnShortPressTimer_attributes);
|
|
|
|
CustBtnShortPressTimerHandle = osTimerNew(CustBtnShortPressTimerCallback, osTimerOnce, NULL, &CustBtnShortPressTimer_attributes);
|
2021-01-07 19:01:08 +08:00
|
|
|
IdleStateHoldTimerHandle = osTimerNew(IdleStateHoldTimerCallback, osTimerOnce, NULL, &IdleStateHoldTimer_attributes);
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END RTOS_TIMERS */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN RTOS_QUEUES */
|
|
|
|
/* add queues, ... */
|
2021-01-07 19:01:08 +08:00
|
|
|
// LogMessageQueueHandle = osMessageQueueNew (1024, sizeof(uint8_t), &LogMessageQueue_attributes);
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END RTOS_QUEUES */
|
|
|
|
|
|
|
|
/* Create the thread(s) */
|
2020-04-06 21:16:18 +08:00
|
|
|
/* creation of defaultTask */
|
2020-04-14 17:27:52 +08:00
|
|
|
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
2020-04-10 19:05:38 +08:00
|
|
|
|
2020-04-14 17:27:52 +08:00
|
|
|
/* creation of LedBlinkTask */
|
|
|
|
LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes);
|
2020-04-10 19:05:38 +08:00
|
|
|
|
2020-04-27 18:19:02 +08:00
|
|
|
/* creation of CoulombRead */
|
2021-01-07 15:11:11 +08:00
|
|
|
// CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes);
|
2020-04-27 18:19:02 +08:00
|
|
|
|
2020-08-25 19:33:15 +08:00
|
|
|
/* creation of PowerMonitTask */
|
2021-01-15 17:04:20 +08:00
|
|
|
// PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes);
|
2020-07-15 18:26:22 +08:00
|
|
|
|
2021-01-05 14:46:47 +08:00
|
|
|
/* creation of EventDetect */
|
|
|
|
EventDetectHandle = osThreadNew(StartEventDetect, NULL, &EventDetect_attributes);
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE BEGIN RTOS_THREADS */
|
|
|
|
/* add threads, ... */
|
2021-01-07 19:01:08 +08:00
|
|
|
// LogtoUartTaskHandle = osThreadNew(StartLogtoUartTask, NULL, &LogtoUartTask_attributes);
|
2021-03-09 18:17:28 +08:00
|
|
|
// DemoTask1Handle = osThreadNew(StartDemoTask1, NULL, &DemoTask1_attributes);
|
|
|
|
// DemoTask2Handle = osThreadNew(StartDemoTask2, NULL, &DemoTask2_attributes);
|
2020-04-10 19:05:38 +08:00
|
|
|
|
2021-02-05 18:22:21 +08:00
|
|
|
cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes);
|
2021-03-09 18:17:28 +08:00
|
|
|
// ElogInitTaskHandle = osThreadNew(StartElogInitTask, NULL, &ElogInitTask_attributes);
|
|
|
|
// ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes);
|
2021-02-05 18:22:21 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END RTOS_THREADS */
|
|
|
|
|
2020-12-17 18:22:19 +08:00
|
|
|
/* USER CODE BEGIN RTOS_EVENTS */
|
|
|
|
/* add events, ... */
|
|
|
|
/* USER CODE END RTOS_EVENTS */
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
2020-04-02 22:18:11 +08:00
|
|
|
/**
|
|
|
|
* @brief Function implementing the defaultTask thread.
|
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE END Header_StartDefaultTask */
|
|
|
|
void StartDefaultTask(void *argument)
|
2020-04-02 22:18:11 +08:00
|
|
|
{
|
|
|
|
/* init code for USB_DEVICE */
|
2021-01-05 14:46:47 +08:00
|
|
|
MX_USB_DEVICE_Init();
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE BEGIN StartDefaultTask */
|
2021-01-05 14:46:47 +08:00
|
|
|
osVersion_t osVersion;
|
|
|
|
char id_buf[20];
|
|
|
|
unsigned char id_size=20;
|
2020-12-17 18:22:19 +08:00
|
|
|
|
|
|
|
HAL_GPIO_WritePin(USB2_FS_ENUM_CTL_GPIO_Port,USB2_FS_ENUM_CTL_Pin, GPIO_PIN_SET);
|
2021-01-05 14:46:47 +08:00
|
|
|
if(isWakeUpReset()){//judge reset source form "wakeup event"
|
|
|
|
|
|
|
|
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
|
|
|
|
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
|
|
|
|
|
|
|
|
if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){
|
2021-01-07 15:11:11 +08:00
|
|
|
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET)
|
|
|
|
NaviKit.sys.next_sta = dfu;
|
|
|
|
else{
|
|
|
|
NaviKit.sys.power_btn = true;
|
|
|
|
}
|
2021-03-09 18:17:28 +08:00
|
|
|
log_i("EC Reset source :Power Button WakeUP");
|
2021-01-05 14:46:47 +08:00
|
|
|
}else{
|
|
|
|
NaviKit.sys.next_sta = idle;
|
2021-03-09 18:17:28 +08:00
|
|
|
log_i("EC Reset source :RTC WakeUP");
|
2021-01-07 15:11:11 +08:00
|
|
|
enter_standby_state();
|
2021-01-05 14:46:47 +08:00
|
|
|
}
|
|
|
|
}else{//judge reset source "power on"
|
2021-03-09 18:17:28 +08:00
|
|
|
log_i("EC Reset source :PowerON");
|
2021-01-05 14:46:47 +08:00
|
|
|
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){
|
2021-03-09 18:17:28 +08:00
|
|
|
log_d("EC next state isp");
|
2021-01-05 14:46:47 +08:00
|
|
|
NaviKit.sys.next_sta = isp;
|
|
|
|
}else{
|
|
|
|
NaviKit.sys.next_sta = idle;
|
|
|
|
}
|
2021-03-09 18:17:28 +08:00
|
|
|
// TaskBeep(50,1);
|
2021-01-05 14:46:47 +08:00
|
|
|
}
|
2020-12-17 18:22:19 +08:00
|
|
|
|
2021-03-09 18:17:28 +08:00
|
|
|
log_i("----------------------------------------------");
|
|
|
|
log_i("Copyright (c) Powered by www.autolabor.com.cn");
|
2020-12-17 18:22:19 +08:00
|
|
|
|
2021-03-09 18:17:28 +08:00
|
|
|
log_i("EC Firmware: %s[%s], build: %s, %s, by STD:%u",APP_VERSION,DEPLOY_MODE,__DATE__ ,__TIME__,__STDC_VERSION__ );
|
|
|
|
log_i("HAL Version: 0x%X ", HAL_GetHalVersion());
|
|
|
|
log_i("Revision ID: 0x%X ", HAL_GetREVID());
|
|
|
|
log_i("Device ID: 0x%X ", HAL_GetDEVID());
|
|
|
|
log_i("Chip UID: 0x%X%X%X ", HAL_GetUIDw0(),HAL_GetUIDw1(),HAL_GetUIDw2());
|
2020-09-02 18:45:43 +08:00
|
|
|
|
2020-12-17 18:44:35 +08:00
|
|
|
if(osOK == osKernelGetInfo(&osVersion,id_buf,id_size)){
|
2021-03-09 18:17:28 +08:00
|
|
|
log_i("OS Kernel Version: %u ", osVersion.kernel);
|
|
|
|
log_i("OS Kernel ID: %s ",id_buf);
|
2020-12-17 18:22:19 +08:00
|
|
|
}
|
2021-03-09 18:17:28 +08:00
|
|
|
log_i("OS Kernel Tick Frequence: %d ",osKernelGetTickFreq());
|
|
|
|
log_i("OS Kernel System Timer Frequence: %d ",osKernelGetSysTimerFreq());
|
|
|
|
log_i("Log Library Version: V%s",ELOG_SW_VERSION);
|
|
|
|
|
|
|
|
log_i("Core initial successfully");
|
|
|
|
// log_i("EasyLogger V%s is initialize success.", ELOG_SW_VERSION);
|
|
|
|
log_i("----------------------------------------------");
|
2021-01-05 14:46:47 +08:00
|
|
|
|
2020-04-10 19:05:38 +08:00
|
|
|
/* Infinite loop */
|
|
|
|
for(;;)
|
|
|
|
{
|
2021-01-05 14:46:47 +08:00
|
|
|
// HAL_IWDG_Refresh(&hiwdg);
|
2021-01-07 15:11:11 +08:00
|
|
|
osDelay(20);
|
2021-01-05 14:46:47 +08:00
|
|
|
if(NaviKit.sys.sta != NaviKit.sys.next_sta){
|
|
|
|
switch(NaviKit.sys.next_sta){
|
2021-01-07 15:11:11 +08:00
|
|
|
case standby: {
|
|
|
|
enter_standby_state();
|
|
|
|
}break;
|
2021-01-05 14:46:47 +08:00
|
|
|
case idle: {
|
|
|
|
enter_idle_state(100);
|
|
|
|
NaviKit.sys.sta = NaviKit.sys.next_sta;
|
|
|
|
} break;
|
|
|
|
case run: {
|
2021-01-15 17:04:20 +08:00
|
|
|
// if(NaviKit.pmb.rails.main_pwr>19){
|
2021-01-07 15:11:11 +08:00
|
|
|
enter_run_state(100);
|
|
|
|
NaviKit.sys.sta = NaviKit.sys.next_sta;
|
2021-01-15 17:04:20 +08:00
|
|
|
// }else{
|
|
|
|
// NaviKit.sys.next_sta = NaviKit.sys.sta;
|
|
|
|
// TaskBeep(500,2);
|
2021-03-09 18:17:28 +08:00
|
|
|
// log_e(,"Main power not exist, retry after plug in it.");
|
|
|
|
// log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
|
2021-01-15 17:04:20 +08:00
|
|
|
// }
|
2021-01-05 14:46:47 +08:00
|
|
|
}break;
|
|
|
|
case sleep:{
|
|
|
|
enter_sleep_state(100);
|
|
|
|
NaviKit.sys.sta = NaviKit.sys.next_sta;
|
|
|
|
}break;
|
|
|
|
case dfu:{
|
2021-01-15 17:04:20 +08:00
|
|
|
// if(NaviKit.pmb.rails.main_pwr>19){
|
2021-01-07 15:11:11 +08:00
|
|
|
enter_dfu_state(100);
|
|
|
|
NaviKit.sys.sta = NaviKit.sys.next_sta;
|
2021-01-15 17:04:20 +08:00
|
|
|
// }else{
|
|
|
|
// NaviKit.sys.next_sta = NaviKit.sys.sta;
|
|
|
|
// TaskBeep(500,2);
|
2021-03-09 18:17:28 +08:00
|
|
|
// log_e(,"Main power not exist, retry after plug in it.");
|
|
|
|
// log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
|
2021-01-15 17:04:20 +08:00
|
|
|
// }
|
2021-01-05 14:46:47 +08:00
|
|
|
}break;
|
|
|
|
case isp:{
|
|
|
|
enter_isp_state();
|
|
|
|
NaviKit.sys.sta = NaviKit.sys.next_sta;
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
2020-09-02 18:45:43 +08:00
|
|
|
|
2021-01-07 19:01:08 +08:00
|
|
|
if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){//idle state
|
|
|
|
// if((NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2)
|
|
|
|
// || (NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)){//Not Charge or float charge
|
|
|
|
// NaviKit.sys.next_sta = standby;
|
|
|
|
// }
|
|
|
|
|
|
|
|
if(!osTimerIsRunning(IdleStateHoldTimerHandle)){
|
|
|
|
osTimerStart(IdleStateHoldTimerHandle,5000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 19:05:38 +08:00
|
|
|
}
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE END StartDefaultTask */
|
2020-04-10 19:05:38 +08:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE BEGIN Header_StartLedBlinkTask */
|
2020-04-10 19:05:38 +08:00
|
|
|
/**
|
2020-04-14 17:27:52 +08:00
|
|
|
* @brief Function implementing the LedBlinkTask thread.
|
2020-04-10 19:05:38 +08:00
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE END Header_StartLedBlinkTask */
|
|
|
|
void StartLedBlinkTask(void *argument)
|
2020-04-10 19:05:38 +08:00
|
|
|
{
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE BEGIN StartLedBlinkTask */
|
2020-04-10 19:05:38 +08:00
|
|
|
/* Infinite loop */
|
2021-03-09 18:17:28 +08:00
|
|
|
// log_v("Start LED Blink");
|
2020-04-10 19:05:38 +08:00
|
|
|
for(;;)
|
|
|
|
{
|
2021-01-07 15:11:11 +08:00
|
|
|
|
2021-01-05 14:46:47 +08:00
|
|
|
osDelay(1000);
|
2020-08-21 17:44:46 +08:00
|
|
|
switch(NaviKit.sys.sta){
|
2021-01-05 14:46:47 +08:00
|
|
|
case run: {
|
2021-01-07 15:11:11 +08:00
|
|
|
PWR_Enable(SYS_PWR_LED,true,0);//turn on power led
|
2021-01-05 14:46:47 +08:00
|
|
|
|
|
|
|
PWR_Enable(SYS_RUN_LED,true,50);//turn on sys run led
|
|
|
|
PWR_Enable(SYS_RUN_LED,false,0);//turn off sys run led
|
|
|
|
}break;
|
|
|
|
case idle:{
|
2021-01-07 15:11:11 +08:00
|
|
|
PWR_Enable(SYS_PWR_LED,false,0);//turn on power led//turn off power led
|
2021-01-05 14:46:47 +08:00
|
|
|
|
|
|
|
PWR_Enable(SYS_RUN_LED,true,20);//turn on sys run led
|
|
|
|
PWR_Enable(SYS_RUN_LED,false,3000);//turn off sys run led
|
|
|
|
}break;
|
|
|
|
case sleep:{//sleep mode
|
|
|
|
for(uint16_t i=0;i<25;i++){//20 light level
|
|
|
|
for(uint16_t j=0;j<3;j++){//the time length of every light level
|
|
|
|
PWR_Enable(SYS_PWR_LED,false,0);
|
|
|
|
PWR_Enable(SYS_RUN_LED,false,0);
|
|
|
|
osDelay(i);
|
|
|
|
PWR_Enable(SYS_PWR_LED,true,0);
|
|
|
|
PWR_Enable(SYS_RUN_LED,true,0);
|
|
|
|
osDelay(25-i);
|
|
|
|
}
|
2020-08-21 17:44:46 +08:00
|
|
|
}
|
2021-01-05 14:46:47 +08:00
|
|
|
for(uint16_t i=0;i<25;i++){
|
|
|
|
for(uint16_t j=0;j<3;j++){
|
|
|
|
PWR_Enable(SYS_PWR_LED,false,0);
|
|
|
|
PWR_Enable(SYS_RUN_LED,false,0);
|
|
|
|
osDelay(25-i);
|
|
|
|
PWR_Enable(SYS_PWR_LED,true,0);
|
|
|
|
PWR_Enable(SYS_RUN_LED,true,0);
|
|
|
|
osDelay(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
case dfu:{
|
2021-01-07 15:11:11 +08:00
|
|
|
PWR_Enable(SYS_PWR_LED,!PWR_Status(SYS_PWR_LED),0);
|
|
|
|
PWR_Enable(SYS_RUN_LED,!PWR_Status(SYS_PWR_LED),0);
|
2020-12-17 18:22:19 +08:00
|
|
|
}break;
|
2021-01-07 15:11:11 +08:00
|
|
|
default : break;
|
2020-08-21 17:44:46 +08:00
|
|
|
}
|
|
|
|
}
|
2020-04-14 17:27:52 +08:00
|
|
|
/* USER CODE END StartLedBlinkTask */
|
2020-04-10 19:05:38 +08:00
|
|
|
}
|
|
|
|
|
2020-04-27 18:19:02 +08:00
|
|
|
/* USER CODE BEGIN Header_StartCoulombRead */
|
|
|
|
/**
|
|
|
|
* @brief Function implementing the CoulombRead thread.
|
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
/* USER CODE END Header_StartCoulombRead */
|
|
|
|
void StartCoulombRead(void *argument)
|
|
|
|
{
|
|
|
|
/* USER CODE BEGIN StartCoulombRead */
|
2021-03-09 18:17:28 +08:00
|
|
|
// log_v("Start Coulomb Read Task");
|
2020-04-29 18:30:35 +08:00
|
|
|
//写寄存器方法
|
|
|
|
coulomb_write_config_load();
|
2020-04-29 17:49:27 +08:00
|
|
|
coulomb_write_config_actual_to_raw();
|
|
|
|
coulomb_write_config();
|
2020-04-29 18:30:35 +08:00
|
|
|
//读寄存器方法
|
|
|
|
coulomb_read_status_and_config();
|
|
|
|
coulomb_read_status_raw_to_actual();
|
|
|
|
coulomb_read_config_raw_to_actual();
|
2020-04-29 17:49:27 +08:00
|
|
|
|
2020-04-27 18:19:02 +08:00
|
|
|
/* Infinite loop */
|
|
|
|
for(;;)
|
|
|
|
{
|
2020-04-29 17:49:27 +08:00
|
|
|
coulomb_read_status_and_config();
|
|
|
|
coulomb_read_status_raw_to_actual();
|
2021-01-05 14:46:47 +08:00
|
|
|
if(NaviKit.sys.sta == run)
|
2020-04-28 18:44:48 +08:00
|
|
|
osDelay(500);
|
|
|
|
else
|
|
|
|
osDelay(5000);
|
2021-03-09 18:17:28 +08:00
|
|
|
|
2020-04-27 18:19:02 +08:00
|
|
|
}
|
|
|
|
/* USER CODE END StartCoulombRead */
|
|
|
|
}
|
|
|
|
|
2021-01-05 14:46:47 +08:00
|
|
|
/* USER CODE BEGIN Header_StartPowerMonitTask */
|
2020-07-15 18:26:22 +08:00
|
|
|
/**
|
2021-01-05 14:46:47 +08:00
|
|
|
* @brief Function: Monit som power status and PMB status
|
2020-07-15 18:26:22 +08:00
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
2021-01-05 14:46:47 +08:00
|
|
|
/* USER CODE END Header_StartPowerMonitTask */
|
|
|
|
void StartPowerMonitTask(void *argument)
|
2020-07-15 18:26:22 +08:00
|
|
|
{
|
2021-01-05 14:46:47 +08:00
|
|
|
/* USER CODE BEGIN StartPowerMonitTask */
|
2021-03-09 18:17:28 +08:00
|
|
|
// log_v("Start Power Monitor Task");
|
2021-01-05 14:46:47 +08:00
|
|
|
HAL_ADCEx_Calibration_Start(&hadc1);
|
2021-01-05 16:06:45 +08:00
|
|
|
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT);
|
2021-01-07 15:11:11 +08:00
|
|
|
osDelay(100);
|
2020-07-15 18:26:22 +08:00
|
|
|
/* Infinite loop */
|
|
|
|
for(;;)
|
|
|
|
{
|
2021-01-07 15:11:11 +08:00
|
|
|
|
|
|
|
if(NaviKit.pmb.rails.main_pwr > 30){
|
|
|
|
TaskBeep(200,1);
|
2021-03-09 18:17:28 +08:00
|
|
|
log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
|
2021-01-07 15:11:11 +08:00
|
|
|
}
|
|
|
|
if(NaviKit.pmb.rails.bkp_bat > 15){
|
2021-03-09 18:17:28 +08:00
|
|
|
log_e("Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
2021-01-07 15:11:11 +08:00
|
|
|
TaskBeep(200,1);
|
|
|
|
}
|
2021-01-05 14:46:47 +08:00
|
|
|
//stat1 stat2 lead-acid
|
|
|
|
//1 1 Not Charging
|
|
|
|
//1 0 Float Charge
|
|
|
|
//0 1 Absorption Charge
|
|
|
|
//0 0 Bulk Charge
|
|
|
|
NaviKit.pmb.sta.chrg_stat1 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT1_GPIO_Port, PMB_CHRG_STAT1_Pin);
|
|
|
|
NaviKit.pmb.sta.chrg_stat2 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT2_GPIO_Port, PMB_CHRG_STAT2_Pin);
|
|
|
|
|
|
|
|
if(!NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("Backup battery status:%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
if(!NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2)
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("Backup battery status:%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
if(NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("Backup battery status:%dmV Float Charge(Vth=13.3V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
if(NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2)
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("Backup battery status:%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
|
2021-01-07 15:11:11 +08:00
|
|
|
if(NaviKit.sys.sta == run || NaviKit.sys.sta == dfu ){
|
|
|
|
if(NaviKit.pmb.rails.main_pwr < 19){
|
|
|
|
TaskBeep(200,1);
|
2021-03-09 18:17:28 +08:00
|
|
|
log_w("Main power has been lost, please shutdown computer as soon as possible:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
|
2021-01-07 15:11:11 +08:00
|
|
|
}else
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("Main power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
|
|
|
|
if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6)
|
2021-03-09 18:17:28 +08:00
|
|
|
log_e("24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
else
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("24V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
|
|
|
|
if(NaviKit.pmb.rails.out_5v > 5.5 || NaviKit.pmb.rails.out_5v < 4.5)
|
2021-03-09 18:17:28 +08:00
|
|
|
log_e("5V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
else
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("5V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
|
|
|
|
if(NaviKit.pmb.rails.out_12v > 13.2 || NaviKit.pmb.rails.out_12v < 10.8)
|
2021-03-09 18:17:28 +08:00
|
|
|
log_e("12V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
else
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("12V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
|
|
|
|
if(NaviKit.pmb.rails.bkp_bat < 9.5)
|
2021-03-09 18:17:28 +08:00
|
|
|
log_w("Backup battery exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
else
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("Backup battery is regular:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
2021-01-05 14:46:47 +08:00
|
|
|
|
2021-01-07 15:11:11 +08:00
|
|
|
osDelay(2000);
|
2021-01-05 14:46:47 +08:00
|
|
|
|
|
|
|
}else {//not run state
|
|
|
|
osDelay(5000);
|
2021-01-07 19:01:08 +08:00
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
2021-03-09 18:17:28 +08:00
|
|
|
// log_d("state :%d",NaviKit.sys.sta);
|
|
|
|
// log_d("next_state :%d",NaviKit.sys.next_sta);
|
2021-01-05 14:46:47 +08:00
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
2021-01-05 14:46:47 +08:00
|
|
|
/* USER CODE END StartPowerMonitTask */
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
|
|
|
|
2021-01-05 14:46:47 +08:00
|
|
|
/* USER CODE BEGIN Header_StartEventDetect */
|
2020-07-15 18:26:22 +08:00
|
|
|
/**
|
2021-01-05 14:46:47 +08:00
|
|
|
* @brief Function implementing the EventDetect thread.
|
2020-07-15 18:26:22 +08:00
|
|
|
* @param argument: Not used
|
|
|
|
* @retval None
|
|
|
|
*/
|
2021-01-05 14:46:47 +08:00
|
|
|
/* USER CODE END Header_StartEventDetect */
|
|
|
|
void StartEventDetect(void *argument)
|
2020-07-15 18:26:22 +08:00
|
|
|
{
|
2021-01-05 14:46:47 +08:00
|
|
|
/* USER CODE BEGIN StartEventDetect */
|
2020-07-15 18:26:22 +08:00
|
|
|
/* Infinite loop */
|
2021-03-09 18:17:28 +08:00
|
|
|
// log_v("Start Event Detect Task.");
|
2020-07-15 18:26:22 +08:00
|
|
|
for(;;)
|
|
|
|
{
|
2021-01-07 15:11:11 +08:00
|
|
|
//power button
|
|
|
|
if(NaviKit.sys.power_btn && !osTimerIsRunning(PwrBtnLongPressTimerHandle)){
|
|
|
|
osTimerStart(PwrBtnLongPressTimerHandle,1500);
|
2021-01-07 19:01:08 +08:00
|
|
|
osTimerStart(PwrBtnShortPressTimerHandle,100);
|
2020-12-18 12:46:59 +08:00
|
|
|
}
|
2021-01-07 15:11:11 +08:00
|
|
|
osDelay(2);
|
|
|
|
if(!NaviKit.sys.power_btn && osTimerIsRunning(PwrBtnLongPressTimerHandle)){
|
|
|
|
osTimerStop(PwrBtnLongPressTimerHandle);
|
|
|
|
osTimerStop(PwrBtnShortPressTimerHandle);
|
2021-01-05 14:46:47 +08:00
|
|
|
}
|
2021-01-07 15:11:11 +08:00
|
|
|
osDelay(2);
|
|
|
|
//custom button
|
|
|
|
if(!NaviKit.sys.custom_btn && osTimerIsRunning(CustBtnLongPressTimerHandle)){
|
|
|
|
osTimerStop(CustBtnLongPressTimerHandle);
|
|
|
|
osTimerStop(CustBtnShortPressTimerHandle);
|
2021-01-05 14:46:47 +08:00
|
|
|
}
|
2021-01-07 15:11:11 +08:00
|
|
|
osDelay(2);
|
|
|
|
if(NaviKit.sys.custom_btn && !osTimerIsRunning(CustBtnLongPressTimerHandle)){
|
|
|
|
osTimerStart(CustBtnLongPressTimerHandle,1500);
|
2021-01-07 19:01:08 +08:00
|
|
|
osTimerStart(CustBtnShortPressTimerHandle,100);
|
2020-12-18 12:46:59 +08:00
|
|
|
}
|
2021-01-07 15:11:11 +08:00
|
|
|
osDelay(2);
|
2021-03-09 18:17:28 +08:00
|
|
|
|
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
2021-01-05 14:46:47 +08:00
|
|
|
/* USER CODE END StartEventDetect */
|
|
|
|
}
|
|
|
|
|
2021-01-07 15:11:11 +08:00
|
|
|
/* Private application code --------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN Application */
|
2021-01-07 19:01:08 +08:00
|
|
|
|
|
|
|
void StartLogtoUartTask(void *argument){
|
|
|
|
|
|
|
|
// HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,2);
|
|
|
|
}
|
|
|
|
|
2021-03-09 18:17:28 +08:00
|
|
|
|
2021-01-07 15:11:11 +08:00
|
|
|
void PwrBtnLongPressTimerCallback(void *argument)
|
2021-01-05 14:46:47 +08:00
|
|
|
{
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("power btn long pressed.");
|
2021-01-05 14:46:47 +08:00
|
|
|
switch(NaviKit.sys.sta){
|
2021-03-09 18:17:28 +08:00
|
|
|
case run: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;//system is run now, user request to idle
|
|
|
|
case idle: {NaviKit.sys.next_sta = run;log_v("change to run"); }break;//system is idle now , user request to power on
|
|
|
|
case dfu: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;
|
|
|
|
case sleep:{NaviKit.sys.next_sta = run;log_v("change to run"); }break;
|
|
|
|
case isp: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;
|
2021-01-07 15:11:11 +08:00
|
|
|
default : break;
|
2021-01-05 14:46:47 +08:00
|
|
|
}
|
|
|
|
}
|
2021-01-07 15:11:11 +08:00
|
|
|
void CustBtnLongPressTimerCallback(void *argument)
|
2021-01-05 14:46:47 +08:00
|
|
|
{
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("custom btn long pressed.");
|
2021-01-05 14:46:47 +08:00
|
|
|
switch(NaviKit.sys.sta){
|
2021-01-07 15:11:11 +08:00
|
|
|
case run:{//system is run now, user request to reboot SOM
|
2021-01-07 19:01:08 +08:00
|
|
|
som_reboot(100);
|
2021-01-05 14:46:47 +08:00
|
|
|
}break;
|
|
|
|
case idle:{
|
|
|
|
}break;
|
|
|
|
case dfu:{
|
2021-01-07 19:01:08 +08:00
|
|
|
som_reboot(100);
|
2021-01-05 14:46:47 +08:00
|
|
|
}break;
|
|
|
|
case sleep:{
|
|
|
|
}break;
|
2021-01-07 15:11:11 +08:00
|
|
|
default : break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void PwrBtnShortPressTimerCallback(void *argument)
|
|
|
|
{
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("power btn short pressed.");
|
2021-01-07 15:11:11 +08:00
|
|
|
switch(NaviKit.sys.sta){
|
|
|
|
case run: {//som is running, send sleep requeset to operate system
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("Request operate system pop up the shutdown dialog.");
|
2021-01-07 19:01:08 +08:00
|
|
|
PWR_Enable(SOM_SLEEP,true,100);
|
2021-01-07 15:11:11 +08:00
|
|
|
PWR_Enable(SOM_SLEEP,false,0);
|
2021-01-05 14:46:47 +08:00
|
|
|
}break;
|
2021-01-07 15:11:11 +08:00
|
|
|
case idle: { }break;//system is idle now , user request to power on
|
|
|
|
case dfu: { }break;
|
|
|
|
case sleep:{ }break;
|
|
|
|
case isp: { }break;
|
|
|
|
default : break;
|
2021-01-05 14:46:47 +08:00
|
|
|
}
|
2020-07-15 18:26:22 +08:00
|
|
|
}
|
2021-01-07 15:11:11 +08:00
|
|
|
void CustBtnShortPressTimerCallback(void *argument)
|
2020-04-10 19:05:38 +08:00
|
|
|
{
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("custom btn short pressed.");
|
2021-01-07 15:11:11 +08:00
|
|
|
switch(NaviKit.sys.sta){
|
2021-01-07 19:01:08 +08:00
|
|
|
case run:{
|
2021-01-07 15:11:11 +08:00
|
|
|
}break;
|
|
|
|
case idle:{
|
|
|
|
}break;
|
|
|
|
case dfu:{
|
|
|
|
}break;
|
|
|
|
case sleep:{
|
|
|
|
}break;
|
|
|
|
default : break;
|
|
|
|
}
|
2020-04-10 19:05:38 +08:00
|
|
|
}
|
2021-01-07 19:01:08 +08:00
|
|
|
void IdleStateHoldTimerCallback(void *argument){
|
|
|
|
if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){
|
2021-03-09 18:17:28 +08:00
|
|
|
log_v("Idle state duration more than 5000ms.");
|
2021-01-07 19:01:08 +08:00
|
|
|
NaviKit.sys.next_sta = standby;
|
|
|
|
}
|
|
|
|
}
|
2020-09-02 18:45:43 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END Application */
|
|
|
|
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|