update
parent
26ff1cf7bc
commit
3fc9d2c2b2
|
@ -13,6 +13,6 @@
|
|||
osThreadId_t cdcMonitorTaskHandle;
|
||||
const osThreadAttr_t cdcMonitorTask_attributes;
|
||||
|
||||
void StartCdcMonitorTask(void *argument);
|
||||
void CdcMonitorTask(void *argument);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
osThreadId_t CoulombReadHandle;
|
||||
osThreadId_t CoulombTaskHandle;
|
||||
|
||||
const osThreadAttr_t CoulombRead_attributes;
|
||||
const osThreadAttr_t CoulombTask_attributes;
|
||||
|
||||
void StartCoulombRead(void *argument);
|
||||
void CoulombTask(void *argument);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,7 +9,7 @@ osThreadId_t DemoTask1Handle;
|
|||
const osThreadAttr_t DemoTask1_attributes;
|
||||
const osThreadAttr_t DemoTask2_attributes;
|
||||
|
||||
void StartDemoTask1(void *argument);
|
||||
void StartDemoTask2(void *argument);
|
||||
void DemoTask1(void *argument);
|
||||
void DemoTask2(void *argument);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
osSemaphoreId_t ElogOutputBinarySemHandle;
|
||||
const osSemaphoreAttr_t ElogOutputBinarySem_attributes;
|
||||
|
||||
osSemaphoreId_t ElogUartBinarySemHandle;
|
||||
const osSemaphoreAttr_t ElogUartBinarySem_attributes;
|
||||
|
||||
osMutexId_t ElogUartMutexHandle;
|
||||
const osMutexAttr_t ElogUartMutex_attributes;
|
||||
|
||||
osMutexId_t ElogOutputMutexHandle;
|
||||
const osMutexAttr_t ElogOutputMutex_attributes;
|
||||
|
@ -19,8 +19,8 @@ osThreadId_t ElogFlushTaskHandle;
|
|||
const osThreadAttr_t ElogInitTask_attributes;
|
||||
const osThreadAttr_t ElogFlushTask_attributes;
|
||||
|
||||
void StartElogInitTask(void *argument);
|
||||
void StartElogFlushTask(void *argument);
|
||||
void ElogInitTask(void *argument);
|
||||
void ElogFlushTask(uint8_t intervnal);
|
||||
|
||||
void my_elog_init();
|
||||
#endif
|
||||
|
|
|
@ -10,24 +10,7 @@
|
|||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//pressed time < short press time(ms)
|
||||
#define SHORT_PRESS_TIME 500
|
||||
|
||||
//pressed time > long press time(ms)
|
||||
#define LONG_PRESS_TIME 1000
|
||||
|
||||
//define exti flag for task-notification / thread-flags
|
||||
typedef enum{
|
||||
SHUTDOWN_REQ_ACTIVE = 0x01<< 0,
|
||||
SHUTDOWN_REQ_INACTIVE = 0x01<< 1,
|
||||
MOD_SLEEP_ACTIVE = 0x01<< 2,
|
||||
MOD_SLEEP_INACTIVE = 0x01<< 3,
|
||||
PWR_BTN_ACTIVE = 0x01<< 4,
|
||||
PWR_BTN_INACTIVE = 0x01<< 5,
|
||||
CUS_BTN_ACTIVE = 0x01<< 6,
|
||||
CUS_BTN_INACTIVE = 0x01<< 7,
|
||||
}Exti_Flags_t;
|
||||
Exti_Flags_t Exti_Flags;
|
||||
|
||||
|
||||
|
||||
|
@ -49,11 +32,11 @@ osTimerId_t CustBtnShortPressTimerHandle;
|
|||
const osTimerAttr_t CustBtnShortPressTimer_attributes;
|
||||
|
||||
//Event Flag
|
||||
osEventFlagsId_t ExtiEventFlags;
|
||||
const osEventFlagsAttr_t ExtiEventFlags_attributes;
|
||||
// osEventFlagsId_t ExtiEventFlags;
|
||||
// const osEventFlagsAttr_t ExtiEventFlags_attributes;
|
||||
|
||||
//Task
|
||||
void StartExtiServiceTask(void *argument);
|
||||
void ExtiServiceTask(void *argument);
|
||||
|
||||
//callback
|
||||
void PwrBtnLongPressTimerCallback(void *argument);
|
||||
|
|
|
@ -7,5 +7,5 @@ osThreadId_t InfoOutputTaskHandle;
|
|||
|
||||
const osThreadAttr_t InfoOutputTask_attributes;
|
||||
|
||||
void StartInfoOutputTask(void *argument);
|
||||
void InfoOutputTask(void *argument);
|
||||
#endif
|
||||
|
|
|
@ -7,6 +7,6 @@ osThreadId_t IWDGTaskHandle;
|
|||
|
||||
const osThreadAttr_t IWDGTask_attributes;
|
||||
|
||||
void StartIWDGTask(void *argument);
|
||||
void IWDGTask(void *argument);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
/* Definitions for LedBlinkTask */
|
||||
osThreadId_t LedBlinkTaskHandle;
|
||||
const osThreadAttr_t LedBlinkTask_attributes;
|
||||
void StartLedBlinkTask(void *argument);
|
||||
void LedBlinkTask(void *argument);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,9 +10,18 @@
|
|||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#define EVENT_FLAG_POWER_MONITOR_MAIN_POWER_GOOD (0x01 << 0)
|
||||
//#define THREAD_FLAG_POWER_MONITOR_BKUP_POWER_GOOD
|
||||
|
||||
|
||||
//Event Flag
|
||||
osEventFlagsId_t PowerMonitorEventFlags;
|
||||
const osEventFlagsAttr_t PowerMonitorEventFlags_attributes;
|
||||
|
||||
|
||||
/* Definitions for PowerMonitTask */
|
||||
osThreadId_t PowerMonitTaskHandle;
|
||||
const osThreadAttr_t PowerMonitTask_attributes;
|
||||
|
||||
void StartPowerMonitTask(void *argument);
|
||||
void PowerMonitTask(void *argument);
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,7 @@ const osThreadAttr_t cdcMonitorTask_attributes = {
|
|||
};
|
||||
|
||||
//task instance
|
||||
void StartCdcMonitorTask(void *argument){
|
||||
void CdcMonitorTask(void *argument){
|
||||
uint8_t port_restart_temp[64]={0};
|
||||
uint32_t number_restart_temp =0;
|
||||
bool beep_flag = false;
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
|
||||
|
||||
/* Definitions for CoulombRead */
|
||||
const osThreadAttr_t CoulombRead_attributes = {
|
||||
.name = "CoulombRead",
|
||||
const osThreadAttr_t CoulombTask_attributes = {
|
||||
.name = "CoulombTask",
|
||||
.priority = (osPriority_t) osPriorityBelowNormal,
|
||||
.stack_size = 128 * 4
|
||||
.stack_size = 256 * 4
|
||||
};
|
||||
|
||||
/* USER CODE BEGIN Header_StartCoulombRead */
|
||||
|
@ -27,7 +27,7 @@ const osThreadAttr_t CoulombRead_attributes = {
|
|||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_StartCoulombRead */
|
||||
void StartCoulombRead(void *argument)
|
||||
void CoulombTask(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN StartCoulombRead */
|
||||
log_d("Start Coulomb Read Task");
|
||||
|
|
|
@ -13,23 +13,23 @@
|
|||
|
||||
const osThreadAttr_t DemoTask1_attributes = {
|
||||
.name = "DemoTask1",
|
||||
.priority = (osPriority_t) osPriorityLow1,
|
||||
.priority = (osPriority_t) osPriorityLow2,
|
||||
.stack_size = 256 * 4
|
||||
};
|
||||
const osThreadAttr_t DemoTask2_attributes = {
|
||||
.name = "DemoTask2",
|
||||
.priority = (osPriority_t) osPriorityLow1,
|
||||
.priority = (osPriority_t) osPriorityLow2,
|
||||
.stack_size = 256 * 4
|
||||
};
|
||||
void StartDemoTask1(void *argument){
|
||||
void DemoTask1(void *argument){
|
||||
uint8_t i=0;
|
||||
log_d("Start Demo Task1");
|
||||
for(;;){
|
||||
log_v("DemoTask1 counter [%d].",i++);
|
||||
osDelay(100);
|
||||
log_v("DemoTask1 counter [%d].",i++);
|
||||
}
|
||||
}
|
||||
void StartDemoTask2(void *argument){
|
||||
void DemoTask2(void *argument){
|
||||
uint8_t i=0;
|
||||
log_d("Start Demo Task2");
|
||||
for(;;){
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
const osSemaphoreAttr_t ElogOutputBinarySem_attributes = {
|
||||
.name = "ElogOutputBinarySem"
|
||||
};
|
||||
//mutex
|
||||
const osMutexAttr_t ElogUartMutex_attributes = {
|
||||
.name = "ElogUartMutex"
|
||||
//semaphore
|
||||
const osSemaphoreAttr_t ElogUartBinarySem_attributes = {
|
||||
.name = "ElogUartBinarySem"
|
||||
};
|
||||
const osMutexAttr_t ElogOutputMutex_attributes = {
|
||||
.name = "ElogOutputMutex"
|
||||
|
@ -31,23 +31,24 @@ const osThreadAttr_t ElogInitTask_attributes = {
|
|||
|
||||
const osThreadAttr_t ElogFlushTask_attributes = {
|
||||
.name = "ElogFlushTask",
|
||||
.priority = (osPriority_t) osPriorityLow,
|
||||
.priority = (osPriority_t) osPriorityLow1,
|
||||
.stack_size = 256 * 4
|
||||
};
|
||||
|
||||
void StartElogInitTask(void *argument){
|
||||
void ElogInitTask(void *argument){
|
||||
|
||||
// my_elog_init();
|
||||
|
||||
// osThreadExit();//exit this thread,execute this code only once
|
||||
}
|
||||
|
||||
void StartElogFlushTask(void *argument){
|
||||
//interval:buffer flush time interval
|
||||
void ElogFlushTask(uint8_t intervnal){
|
||||
|
||||
log_d("Start log Flush Task");
|
||||
for(;;){
|
||||
elog_flush();
|
||||
osDelay(1);
|
||||
osDelay(intervnal);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,3 +82,9 @@ void my_elog_init(){
|
|||
/* start EasyLogger */
|
||||
elog_start();
|
||||
}
|
||||
|
||||
void HAL_UART1_TxHalfCpltCallback(UART_HandleTypeDef *huart){
|
||||
|
||||
osSemaphoreRelease(ElogUartBinarySemHandle);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,28 @@
|
|||
#include "main.h"
|
||||
#include "navikit.h"
|
||||
|
||||
|
||||
//pressed time < short press time(ms)
|
||||
#define SHORT_PRESS_TIME 200
|
||||
|
||||
//pressed time > long press time(ms)
|
||||
#define LONG_PRESS_TIME 1000
|
||||
|
||||
//define exti flag for task-notification / thread-flags
|
||||
#define THREAD_FLAG_EXTI_SERVICE_SHUTDOWN_REQ_ACTIVE (0x01<< 0)
|
||||
#define THREAD_FLAG_EXTI_SERVICE_SHUTDOWN_REQ_INACTIVE (0x01<< 1)
|
||||
#define THREAD_FLAG_EXTI_SERVICE_MOD_SLEEP_ACTIVE (0x01<< 2)
|
||||
#define THREAD_FLAG_EXTI_SERVICE_MOD_SLEEP_INACTIVE (0x01<< 3)
|
||||
#define THREAD_FLAG_EXTI_SERVICE_PWR_BTN_ACTIVE (0x01<< 4)
|
||||
#define THREAD_FLAG_EXTI_SERVICE_PWR_BTN_INACTIVE (0x01<< 5)
|
||||
#define THREAD_FLAG_EXTI_SERVICE_CUS_BTN_ACTIVE (0x01<< 6)
|
||||
#define THREAD_FLAG_EXTI_SERVICE_CUS_BTN_INACTIVE (0x01<< 7)
|
||||
|
||||
|
||||
//Thread
|
||||
const osThreadAttr_t ExtiServiceTask_attributes = {
|
||||
.name = "ExtiServiceTask",
|
||||
.priority = (osPriority_t) osPriorityBelowNormal,
|
||||
.priority = (osPriority_t) osPriorityBelowNormal1,
|
||||
.stack_size = 256 * 4
|
||||
};
|
||||
|
||||
|
@ -32,74 +50,88 @@ const osTimerAttr_t CustBtnShortPressTimer_attributes = {
|
|||
.name = "CustBtnShortPressTimer"
|
||||
};
|
||||
|
||||
//Event Flag
|
||||
const osEventFlagsAttr_t ExtiEventFlags_attributes = {
|
||||
.name = "ExtiEventFlags"
|
||||
};
|
||||
// //Event Flag
|
||||
// const osEventFlagsAttr_t ExtiEventFlags_attributes = {
|
||||
// .name = "ExtiEventFlags"
|
||||
// };
|
||||
|
||||
|
||||
/* USER CODE BEGIN Header_StartExtiServiceTask */
|
||||
/* USER CODE BEGIN Header_ExtiServiceTask */
|
||||
/**
|
||||
* @brief Function implementing the ExtiServiceTask thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_StartExtiServiceTask */
|
||||
void StartExtiServiceTask(void *argument)
|
||||
/* USER CODE END Header_ExtiServiceTask */
|
||||
void ExtiServiceTask(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN StartExtiServiceTask */
|
||||
/* USER CODE BEGIN ExtiServiceTask */
|
||||
/* Infinite loop */
|
||||
uint32_t thread_flag = 0;
|
||||
log_d("Start EXTI Service Task");
|
||||
|
||||
if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET)
|
||||
osTimerStart(PwrBtnLongPressTimerHandle,LONG_PRESS_TIME);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
thread_flag = osThreadFlagsGet();
|
||||
|
||||
if(thread_flag & SHUTDOWN_REQ){
|
||||
|
||||
//shutdown request pin
|
||||
if(thread_flag & THREAD_FLAG_EXTI_SERVICE_SHUTDOWN_REQ_ACTIVE){
|
||||
log_i("SOM's shutdown_req pin falling edge, SOM request to shutdown.");
|
||||
osThreadFlagsClear(THREAD_FLAG_EXTI_SERVICE_SHUTDOWN_REQ_ACTIVE);
|
||||
}
|
||||
if(thread_flag & MOD_SLEEP){
|
||||
|
||||
if(thread_flag & THREAD_FLAG_EXTI_SERVICE_SHUTDOWN_REQ_INACTIVE){
|
||||
log_v("SOM's shutdown_req pin rising edge");
|
||||
osThreadFlagsClear(THREAD_FLAG_EXTI_SERVICE_SHUTDOWN_REQ_INACTIVE);
|
||||
}
|
||||
//powwer button
|
||||
if((thread_flag & PWR_BTN) && !osTimerIsRunning(PwrBtnLongPressTimerHandle)){
|
||||
|
||||
//module sleep pin
|
||||
if(thread_flag & THREAD_FLAG_EXTI_SERVICE_MOD_SLEEP_ACTIVE){
|
||||
log_v("SOM's mod_sleep pin rising edge");
|
||||
osThreadFlagsClear(THREAD_FLAG_EXTI_SERVICE_MOD_SLEEP_ACTIVE);
|
||||
}
|
||||
if(thread_flag & THREAD_FLAG_EXTI_SERVICE_MOD_SLEEP_INACTIVE){
|
||||
log_v("SOM's mod_sleep pin falling edge");
|
||||
osThreadFlagsClear(THREAD_FLAG_EXTI_SERVICE_MOD_SLEEP_INACTIVE);
|
||||
}
|
||||
|
||||
//power button pin
|
||||
if(thread_flag & THREAD_FLAG_EXTI_SERVICE_PWR_BTN_ACTIVE){
|
||||
log_v("power_btn status: pressed.");
|
||||
osThreadFlagsClear(THREAD_FLAG_EXTI_SERVICE_PWR_BTN_ACTIVE);
|
||||
if(!osTimerIsRunning(PwrBtnLongPressTimerHandle)){
|
||||
osTimerStart(PwrBtnLongPressTimerHandle,LONG_PRESS_TIME);
|
||||
osTimerStart(PwrBtnShortPressTimerHandle,SHORT_PRESS_TIME);
|
||||
}else if(!(thread_flag & PWR_BTN) && osTimerIsRunning(PwrBtnLongPressTimerHandle)){
|
||||
}
|
||||
}
|
||||
if(thread_flag & THREAD_FLAG_EXTI_SERVICE_PWR_BTN_INACTIVE){
|
||||
log_v("power_btn status: released.");
|
||||
osThreadFlagsClear(THREAD_FLAG_EXTI_SERVICE_PWR_BTN_INACTIVE);
|
||||
osTimerStop(PwrBtnLongPressTimerHandle);
|
||||
osTimerStop(PwrBtnShortPressTimerHandle);
|
||||
}
|
||||
//custom button
|
||||
if((thread_flag & CUS_BTN) && !osTimerIsRunning(CustBtnLongPressTimerHandle)) {
|
||||
|
||||
//custom button pin
|
||||
if(thread_flag & THREAD_FLAG_EXTI_SERVICE_CUS_BTN_ACTIVE){
|
||||
log_v("custom_btn status: pressed.");
|
||||
osThreadFlagsClear(THREAD_FLAG_EXTI_SERVICE_CUS_BTN_ACTIVE);
|
||||
if(!osTimerIsRunning(CustBtnLongPressTimerHandle)) {
|
||||
osTimerStart(CustBtnLongPressTimerHandle,LONG_PRESS_TIME);
|
||||
osTimerStart(CustBtnShortPressTimerHandle,SHORT_PRESS_TIME);
|
||||
}else if(!(thread_flag & CUS_BTN) && osTimerIsRunning(CustBtnLongPressTimerHandle)){
|
||||
}
|
||||
}
|
||||
if(thread_flag & THREAD_FLAG_EXTI_SERVICE_CUS_BTN_INACTIVE){
|
||||
log_v("custom_btn status: released.");
|
||||
osThreadFlagsClear(THREAD_FLAG_EXTI_SERVICE_CUS_BTN_INACTIVE);
|
||||
osTimerStop(CustBtnLongPressTimerHandle);
|
||||
osTimerStop(CustBtnShortPressTimerHandle);
|
||||
}
|
||||
|
||||
// //power button
|
||||
// if(NaviKit.sys.power_btn && !osTimerIsRunning(PwrBtnLongPressTimerHandle)){
|
||||
// osTimerStart(PwrBtnLongPressTimerHandle,LONG_PRESS_TIME);
|
||||
// osTimerStart(PwrBtnShortPressTimerHandle,SHORT_PRESS_TIME);
|
||||
// }
|
||||
// osDelay(2);
|
||||
// if(!NaviKit.sys.power_btn && osTimerIsRunning(PwrBtnLongPressTimerHandle)){
|
||||
// osTimerStop(PwrBtnLongPressTimerHandle);
|
||||
// osTimerStop(PwrBtnShortPressTimerHandle);
|
||||
// }
|
||||
// osDelay(2);
|
||||
//custom button
|
||||
// if(!NaviKit.sys.custom_btn && osTimerIsRunning(CustBtnLongPressTimerHandle)){
|
||||
// }
|
||||
// osDelay(2);
|
||||
// if(NaviKit.sys.custom_btn && !osTimerIsRunning(CustBtnLongPressTimerHandle)){
|
||||
// }
|
||||
// osDelay(2);
|
||||
osDelay(10);
|
||||
|
||||
}
|
||||
/* USER CODE END StartExtiServiceTask */
|
||||
/* USER CODE END ExtiServiceTask */
|
||||
}
|
||||
|
||||
|
||||
|
@ -136,6 +168,7 @@ void CustBtnLongPressTimerCallback(void *argument)
|
|||
}
|
||||
void PwrBtnShortPressTimerCallback(void *argument)
|
||||
{
|
||||
if(osThreadFlagsGet() & THREAD_FLAG_EXTI_SERVICE_PWR_BTN_INACTIVE){//power_button has released
|
||||
log_v("power button short pressed.");
|
||||
switch(NaviKit.sys.sta){
|
||||
case run: {//som is running, send sleep requeset to operate system
|
||||
|
@ -149,9 +182,11 @@ void PwrBtnShortPressTimerCallback(void *argument)
|
|||
case isp: { }break;
|
||||
default : break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void CustBtnShortPressTimerCallback(void *argument)
|
||||
{
|
||||
if(osThreadFlagsGet() & THREAD_FLAG_EXTI_SERVICE_PWR_BTN_INACTIVE){//power_button has released
|
||||
log_v("custom button short pressed.");
|
||||
switch(NaviKit.sys.sta){
|
||||
case run:{
|
||||
|
@ -164,6 +199,7 @@ void CustBtnShortPressTimerCallback(void *argument)
|
|||
}break;
|
||||
default : break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -174,45 +210,42 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|||
case SOM_SHUTDOWN_REQ_Pin:{
|
||||
if(HAL_GPIO_ReadPin(SOM_SHUTDOWN_REQ_GPIO_Port, SOM_SHUTDOWN_REQ_Pin)==GPIO_PIN_RESET){//falling edge trigger
|
||||
if(NaviKit.sys.sta == run){//if jetson nano shutdown output low,the power_en should be set low less than 10us
|
||||
PWR_Enable(SOM_PWR_EN,false,0);
|
||||
PWR_Enable_IRQ(SOM_PWR_EN,false,0);
|
||||
NaviKit.sys.next_sta = idle;
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)SHUTDOWN_REQ_ACTIVE);
|
||||
// log_i("SOM's shutdown_req pin falling edge, SOM request to shutdown.");
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_SHUTDOWN_REQ_ACTIVE);
|
||||
}
|
||||
}else{//Rising edge trigger
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)SHUTDOWN_REQ_INACTIVE);
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_SHUTDOWN_REQ_INACTIVE);
|
||||
}
|
||||
}break;
|
||||
|
||||
case SOM_MOD_SLEEP_Pin:{
|
||||
if(HAL_GPIO_ReadPin(SOM_MOD_SLEEP_GPIO_Port, SOM_MOD_SLEEP_Pin)==GPIO_PIN_SET){//Rising edge trigger
|
||||
// log_i("SOM's sleep pin rising edge.");
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)MOD_SLEEP_ACTIVE);
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_MOD_SLEEP_ACTIVE);
|
||||
}else{//falling edge trigger
|
||||
// log_v("SOM's sleep pin falling edge.");
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)MOD_SLEEP_INACTIVE);
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_MOD_SLEEP_INACTIVE);
|
||||
}
|
||||
}break;
|
||||
case SYS_POWER_BTN_Pin:{
|
||||
if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){//Rising edge trigger
|
||||
NaviKit.sys.power_btn = true;
|
||||
// log_v("power_btn status: pressed.");
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)PWR_BTN_ACTIVE);
|
||||
// NaviKit.sys.power_btn = true;
|
||||
//power button pressed
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_PWR_BTN_ACTIVE);
|
||||
}else{//falling edge trigger
|
||||
NaviKit.sys.power_btn = false;
|
||||
// log_v("power_btn status: released.");
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)PWR_BTN_INACTIVE);
|
||||
// NaviKit.sys.power_btn = false;
|
||||
//power button released
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_PWR_BTN_INACTIVE);
|
||||
}
|
||||
}break;
|
||||
case SYS_CUSTOM_BTN_Pin:{
|
||||
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){//falling edge trigger
|
||||
// log_v("custom_btn status: pressed.");
|
||||
NaviKit.sys.custom_btn = true;
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)CUS_BTN_ACTIVE);
|
||||
// NaviKit.sys.custom_btn = true;
|
||||
//custom button pressed
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_CUS_BTN_ACTIVE);
|
||||
}else{//Rising edge trigger
|
||||
// log_v("custom_btn status: released.");
|
||||
NaviKit.sys.custom_btn = false;
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)CUS_BTN_INACTIVE);
|
||||
// NaviKit.sys.custom_btn = false;
|
||||
//custom button released
|
||||
osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_CUS_BTN_INACTIVE);
|
||||
}
|
||||
}break;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ const osThreadAttr_t InfoOutputTask_attributes = {
|
|||
.priority = (osPriority_t) osPriorityLow2,
|
||||
.stack_size = 256 * 4
|
||||
};
|
||||
void StartInfoOutputTask(void *argument){
|
||||
void InfoOutputTask(void *argument){
|
||||
log_d("Start Info Output Task");
|
||||
for(;;){
|
||||
osThreadExit();
|
||||
|
|
|
@ -18,7 +18,7 @@ const osThreadAttr_t IWDGTask_attributes = {
|
|||
.stack_size = 256 * 4
|
||||
};
|
||||
|
||||
void StartIWDGTask(void *argument){
|
||||
void IWDGTask(void *argument){
|
||||
log_d("Start IWDG Task");
|
||||
for(;;){
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
|
|
|
@ -13,35 +13,37 @@
|
|||
|
||||
const osThreadAttr_t LedBlinkTask_attributes = {
|
||||
.name = "LedBlinkTask",
|
||||
.priority = (osPriority_t) osPriorityLow7,
|
||||
.priority = (osPriority_t) osPriorityLow,
|
||||
.stack_size = 256 * 4
|
||||
};
|
||||
|
||||
/* USER CODE BEGIN Header_StartLedBlinkTask */
|
||||
/* USER CODE BEGIN Header_LedBlinkTask */
|
||||
/**
|
||||
* @brief Function implementing the LedBlinkTask thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_StartLedBlinkTask */
|
||||
void StartLedBlinkTask(void *argument)
|
||||
/* USER CODE END Header_LedBlinkTask */
|
||||
void LedBlinkTask(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN StartLedBlinkTask */
|
||||
/* USER CODE BEGIN LedBlinkTask */
|
||||
/* Infinite loop */
|
||||
log_d("Start LED Blink Task");
|
||||
log_d(" LED Blink Task");
|
||||
for(;;)
|
||||
{
|
||||
|
||||
osDelay(1000);
|
||||
switch(NaviKit.sys.sta){
|
||||
case run: {
|
||||
if(false == PWR_Status(SYS_PWR_LED))
|
||||
PWR_Enable(SYS_PWR_LED,true,0);//turn on power led
|
||||
|
||||
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:{
|
||||
PWR_Enable(SYS_PWR_LED,false,0);//turn on power led//turn off power led
|
||||
if(true == PWR_Status(SYS_PWR_LED))
|
||||
PWR_Enable(SYS_PWR_LED,false,0);//turn off power led
|
||||
|
||||
PWR_Enable(SYS_RUN_LED,true,20);//turn on sys run led
|
||||
PWR_Enable(SYS_RUN_LED,false,3000);//turn off sys run led
|
||||
|
@ -75,6 +77,6 @@ void StartLedBlinkTask(void *argument)
|
|||
default : break;
|
||||
}
|
||||
}
|
||||
/* USER CODE END StartLedBlinkTask */
|
||||
/* USER CODE END LedBlinkTask */
|
||||
}
|
||||
|
||||
|
|
|
@ -18,33 +18,44 @@ const osThreadAttr_t PowerMonitTask_attributes = {
|
|||
.stack_size = 256 * 4
|
||||
};
|
||||
|
||||
//Event Flag
|
||||
const osEventFlagsAttr_t PowerMonitorEventFlags_attributes = {
|
||||
.name = "PowerMonitorEventFlags"
|
||||
};
|
||||
|
||||
/* USER CODE BEGIN Header_StartPowerMonitTask */
|
||||
|
||||
|
||||
/* USER CODE BEGIN Header_PowerMonitTask */
|
||||
/**
|
||||
* @brief Function: Monit som power status and PMB status
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_StartPowerMonitTask */
|
||||
void StartPowerMonitTask(void *argument)
|
||||
/* USER CODE END Header_PowerMonitTask */
|
||||
void PowerMonitTask(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN StartPowerMonitTask */
|
||||
/* USER CODE BEGIN PowerMonitTask */
|
||||
log_d("Start Power Monitor Task");
|
||||
HAL_ADCEx_Calibration_Start(&hadc1);
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT);
|
||||
osDelay(100);
|
||||
osDelay(10);
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
if((NaviKit.pmb.rails.main_pwr > 30) || (NaviKit.pmb.rails.main_pwr < 19)){
|
||||
NaviKit.pmb.main_pwr_good = false;
|
||||
log_e("Main power:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
|
||||
if((NaviKit.sys.next_sta == run) && (NaviKit.sys.next_sta == run)){
|
||||
TaskBeep(200,2);
|
||||
}
|
||||
}else{
|
||||
log_d("Main power :%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
|
||||
NaviKit.pmb.main_pwr_good = true;
|
||||
}
|
||||
|
||||
if(NaviKit.pmb.rails.main_pwr > 30){
|
||||
TaskBeep(200,1);
|
||||
log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
|
||||
}
|
||||
if(NaviKit.pmb.rails.bkp_bat > 15){
|
||||
log_e("Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
||||
TaskBeep(200,1);
|
||||
}
|
||||
if((NaviKit.pmb.rails.bkp_bat < 8) || (NaviKit.pmb.rails.bkp_bat > 15)){
|
||||
TaskBeep(200,2);
|
||||
}else{
|
||||
//stat1 stat2 lead-acid
|
||||
//1 1 Not Charging
|
||||
//1 0 Float Charge
|
||||
|
@ -53,51 +64,34 @@ void StartPowerMonitTask(void *argument)
|
|||
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)
|
||||
log_v("Backup battery status:%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
||||
if(!NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2)
|
||||
log_v("Backup battery status:%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
||||
if(NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)
|
||||
log_v("Backup battery status:%dmV Float Charge(Vth=13.3V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
||||
if(NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2)
|
||||
log_v("Backup battery status:%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
||||
|
||||
if(NaviKit.sys.sta == run || NaviKit.sys.sta == dfu ){
|
||||
if(NaviKit.pmb.rails.main_pwr < 19){
|
||||
TaskBeep(200,1);
|
||||
log_w("Main power has been lost, please shutdown computer as soon as possible:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
|
||||
}else
|
||||
log_v("Main power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
|
||||
if(false == NaviKit.pmb.sta.chrg_stat1 && false == NaviKit.pmb.sta.chrg_stat2)
|
||||
log_d("Backup battery :%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
||||
else if(false == NaviKit.pmb.sta.chrg_stat1 && true == NaviKit.pmb.sta.chrg_stat2)
|
||||
log_d("Backup battery :%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
||||
else if(true == NaviKit.pmb.sta.chrg_stat1 && false == NaviKit.pmb.sta.chrg_stat2)
|
||||
log_d("Backup battery :%dmV Float Charge(Vth=13.3V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
||||
else if(true == NaviKit.pmb.sta.chrg_stat1 && true == NaviKit.pmb.sta.chrg_stat2)
|
||||
log_d("Backup battery :%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
||||
}
|
||||
|
||||
if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6)
|
||||
log_e("24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
|
||||
log_e("24V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
|
||||
else
|
||||
log_v("24V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
|
||||
log_d("24V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
|
||||
|
||||
if(NaviKit.pmb.rails.out_5v > 5.5 || NaviKit.pmb.rails.out_5v < 4.5)
|
||||
log_e("5V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
|
||||
log_e("5V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
|
||||
else
|
||||
log_v("5V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
|
||||
log_d("5V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
|
||||
|
||||
if(NaviKit.pmb.rails.out_12v > 13.2 || NaviKit.pmb.rails.out_12v < 10.8)
|
||||
log_e("12V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
|
||||
log_e("12V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
|
||||
else
|
||||
log_v("12V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
|
||||
log_d("12V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
|
||||
|
||||
if(NaviKit.pmb.rails.bkp_bat < 9.5)
|
||||
log_w("Backup battery exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
||||
else
|
||||
log_v("Backup battery is regular:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
|
||||
|
||||
osDelay(2000);
|
||||
|
||||
}else {//not run state
|
||||
osDelay(5000);
|
||||
|
||||
osDelay(3000);
|
||||
}
|
||||
// log_d("state :%d",NaviKit.sys.sta);
|
||||
// log_d("next_state :%d",NaviKit.sys.next_sta);
|
||||
|
||||
}
|
||||
/* USER CODE END StartPowerMonitTask */
|
||||
/* USER CODE END PowerMonitTask */
|
||||
}
|
||||
|
|
|
@ -41,11 +41,12 @@ typedef struct
|
|||
{
|
||||
struct{
|
||||
state_t sta,next_sta; //power state machine
|
||||
bool power_btn; //power button pressed flag
|
||||
bool custom_btn;//custom button pressed flag
|
||||
bool ps_on_allow; //allow power-on
|
||||
// bool power_btn; //power button pressed flag
|
||||
// bool custom_btn;//custom button pressed flag
|
||||
// bool pwr_led;//power led (on switch)
|
||||
// bool run_led;//run led (on board)
|
||||
bool dbg_msg_out;//enable/disable debug message output
|
||||
// bool dbg_msg_out;//enable/disable debug message output
|
||||
}sys;
|
||||
struct{
|
||||
bool mod_sleep;
|
||||
|
@ -78,49 +79,9 @@ typedef struct
|
|||
float cap;
|
||||
float temp;
|
||||
}coulomb;
|
||||
bool main_pwr_good;
|
||||
}pmb;//power management board
|
||||
|
||||
// struct{
|
||||
// bool u2_vbus_1;
|
||||
// bool u2_vbus_2;
|
||||
// bool u2_vbus_3;
|
||||
// bool u2_vbus_4;
|
||||
// bool u2_vbus_5;
|
||||
// bool u2_vbus_6;
|
||||
|
||||
// bool u3_vbus_1;
|
||||
// bool u3_vbus_2;
|
||||
// bool u3_vbus_3;
|
||||
// bool u3_vbus_4;
|
||||
// bool u3_vbus_5;
|
||||
// bool u3_vbus_6;
|
||||
// }port;
|
||||
// struct{
|
||||
// bool u2_hub_pwr;
|
||||
// bool u3_hub_pwr;
|
||||
// bool u3_host_pwr;
|
||||
// bool u3_gec_pwr;
|
||||
// bool ge_sw_pwr;
|
||||
// }soc;
|
||||
// struct{
|
||||
// bool fan_valid_1;
|
||||
// bool fan_valid_2;
|
||||
// bool fan_valid_3;
|
||||
// }fan;
|
||||
// struct{
|
||||
|
||||
// bool fan_1;
|
||||
// bool fan_2;
|
||||
// bool fan_3;
|
||||
// }status;
|
||||
// struct {
|
||||
// float sensor_1;
|
||||
// float sensor_2;
|
||||
// float sensor_3;
|
||||
// }temp;
|
||||
|
||||
|
||||
|
||||
}NaviKit_t;
|
||||
extern NaviKit_t NaviKit;
|
||||
|
||||
|
@ -138,6 +99,7 @@ enum Device_t{USB2_Port1=0x00,USB2_Port2,USB2_Port3,USB2_Port4,USB2_Port5,USB2_P
|
|||
PMB_PS_ON=0x40}; //Power Management Board
|
||||
|
||||
void PWR_Enable(enum Device_t device,bool en,uint16_t delay);
|
||||
bool PWR_Enable_IRQ(enum Device_t device,bool en,uint16_t delay);
|
||||
bool PWR_Status(enum Device_t device);
|
||||
|
||||
void NaviKit_var_init();
|
||||
|
|
|
@ -43,6 +43,7 @@ void MX_USART1_UART_Init(void);
|
|||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
void HAL_UART1_TxHalfCpltCallback(UART_HandleTypeDef *huart);
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
******************************************************************************
|
||||
*/
|
||||
|
||||
//TODO:拆分该文件中的功能到不同的文件中,按照任务进行模块化拆分
|
||||
#define LOG_TAG "TH-Default"
|
||||
/* USER CODE END Header */
|
||||
|
||||
|
@ -80,9 +79,10 @@ const osThreadAttr_t defaultTask_attributes = {
|
|||
|
||||
void IdleStateHoldTimerCallback(void *argument);
|
||||
|
||||
bool isWakeUpFromReset() { return __HAL_PWR_GET_FLAG(PWR_FLAG_WU);}
|
||||
bool isWakeUpFromReset();
|
||||
|
||||
//__HAL_RCC_GET_FLAG(); //judge reset source flag
|
||||
//judge reset source flag
|
||||
uint8_t ResetSourceJudge();
|
||||
|
||||
/* USER CODE END FunctionPrototypes */
|
||||
|
||||
|
@ -170,9 +170,9 @@ __weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
|
|||
void MX_FREERTOS_Init(void) {
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
// ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes);
|
||||
ElogOutputBinarySemHandle = osSemaphoreNew(1, 1, &ElogOutputBinarySem_attributes);
|
||||
// ElogUartMutexHandle = osMutexNew(&ElogUartMutex_attributes);
|
||||
ElogUartBinarySemHandle = osSemaphoreNew(1, 0, &ElogUartBinarySem_attributes);
|
||||
ElogOutputBinarySemHandle = osSemaphoreNew(1, 0, &ElogOutputBinarySem_attributes);
|
||||
|
||||
my_elog_init();
|
||||
NaviKit_var_init();
|
||||
/* USER CODE END Init */
|
||||
|
@ -210,56 +210,57 @@ void MX_FREERTOS_Init(void) {
|
|||
/* add threads, ... */
|
||||
//IWDG--------------------------------------------
|
||||
#ifdef IWDG_ENABLE
|
||||
IWDGTaskHandle = osThreadNew(StartIWDGTask, NULL, &IWDGTask_attributes);
|
||||
IWDGTaskHandle = osThreadNew(IWDGTask, NULL, &IWDGTask_attributes);
|
||||
#endif
|
||||
|
||||
//Power--------------------------------------------
|
||||
// PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes);
|
||||
PowerMonitTaskHandle = osThreadNew(PowerMonitTask, NULL, &PowerMonitTask_attributes);
|
||||
|
||||
|
||||
//Button--------------------------------------------
|
||||
ExtiServiceTaskHandle = osThreadNew(StartExtiServiceTask, NULL, &ExtiServiceTask_attributes);
|
||||
ExtiServiceTaskHandle = osThreadNew(ExtiServiceTask, NULL, &ExtiServiceTask_attributes);
|
||||
|
||||
|
||||
//LED--------------------------------------------
|
||||
LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes);
|
||||
LedBlinkTaskHandle = osThreadNew(LedBlinkTask, NULL, &LedBlinkTask_attributes);
|
||||
|
||||
|
||||
//CDC--------------------------------------------
|
||||
cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes);
|
||||
cdcMonitorTaskHandle = osThreadNew(CdcMonitorTask, NULL, &cdcMonitorTask_attributes);
|
||||
|
||||
|
||||
//Coulomb--------------------------------------------
|
||||
// CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes);
|
||||
// CoulombTaskHandle = osThreadNew(CoulombTask, NULL, &CoulombTask_attributes);
|
||||
|
||||
|
||||
//Elog--------------------------------------------
|
||||
// ElogInitTaskHandle = osThreadNew(StartElogInitTask, NULL, &ElogInitTask_attributes);
|
||||
// ElogInitTaskHandle = osThreadNew(ElogInitTask, NULL, &ElogInitTask_attributes);
|
||||
#ifdef ELOG_BUF_OUTPUT_ENABLE
|
||||
ElogFlushTaskHandle = osThreadNew(StartElogFlushTask, NULL, &ElogFlushTask_attributes);
|
||||
ElogFlushTaskHandle = osThreadNew(ElogFlushTask, 1, &ElogFlushTask_attributes);
|
||||
#endif
|
||||
|
||||
//Demo--------------------------------------------
|
||||
DemoTask1Handle = osThreadNew(StartDemoTask1, NULL, &DemoTask1_attributes);
|
||||
DemoTask2Handle = osThreadNew(StartDemoTask2, NULL, &DemoTask2_attributes);
|
||||
// DemoTask1Handle = osThreadNew(DemoTask1, NULL, &DemoTask1_attributes);
|
||||
// DemoTask2Handle = osThreadNew(DemoTask2, NULL, &DemoTask2_attributes);
|
||||
|
||||
|
||||
/* USER CODE END RTOS_THREADS */
|
||||
|
||||
/* USER CODE BEGIN RTOS_EVENTS */
|
||||
/* add events, ... */
|
||||
ExtiEventFlags = osEventFlagsNew(&ExtiEventFlags_attributes);
|
||||
// ExtiEventFlags = osEventFlagsNew(&ExtiEventFlags_attributes);
|
||||
// PowerMonitorEventFlags = osEventFlagsNew(&PowerMonitorEventFlags_attributes);
|
||||
/* USER CODE END RTOS_EVENTS */
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||
/* USER CODE BEGIN Header_DefaultTask */
|
||||
/**
|
||||
* @brief Function implementing the defaultTask thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_StartDefaultTask */
|
||||
/* USER CODE END Header_DefaultTask */
|
||||
void StartDefaultTask(void *argument)
|
||||
{
|
||||
/* init code for USB_DEVICE */
|
||||
|
@ -268,7 +269,7 @@ void StartDefaultTask(void *argument)
|
|||
osVersion_t osVersion;
|
||||
char id_buf[20];
|
||||
unsigned char id_size=20;
|
||||
|
||||
// ResetSourceJudge();
|
||||
HAL_GPIO_WritePin(USB2_FS_ENUM_CTL_GPIO_Port,USB2_FS_ENUM_CTL_Pin, GPIO_PIN_SET);
|
||||
if(isWakeUpFromReset()){//judge reset source form "wakeup event"
|
||||
|
||||
|
@ -278,9 +279,6 @@ osVersion_t osVersion;
|
|||
if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){
|
||||
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;
|
||||
}
|
||||
log_i("EC Reset source: [Power Button WakeUP]");
|
||||
}else{
|
||||
NaviKit.sys.next_sta = idle;
|
||||
|
@ -295,10 +293,9 @@ osVersion_t osVersion;
|
|||
}else{
|
||||
NaviKit.sys.next_sta = idle;
|
||||
}
|
||||
// TaskBeep(50,1);
|
||||
TaskBeep(50,1);
|
||||
}
|
||||
|
||||
log_i("----------------------------------------------");
|
||||
log_i("Copyright (c) Powered by www.autolabor.com.cn");
|
||||
#ifdef DEBUG
|
||||
log_i("EC Firmware: %s[DEBUG], build: %s, %s",APP_VERSION,__DATE__ ,__TIME__);
|
||||
|
@ -334,30 +331,28 @@ osVersion_t osVersion;
|
|||
NaviKit.sys.sta = NaviKit.sys.next_sta;
|
||||
} break;
|
||||
case run: {
|
||||
// if(NaviKit.pmb.rails.main_pwr>19){
|
||||
if(NaviKit.pmb.main_pwr_good){
|
||||
enter_run_state(100);
|
||||
NaviKit.sys.sta = NaviKit.sys.next_sta;
|
||||
// }else{
|
||||
// NaviKit.sys.next_sta = NaviKit.sys.sta;
|
||||
// TaskBeep(500,2);
|
||||
// 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));
|
||||
// }
|
||||
}else{
|
||||
NaviKit.sys.next_sta = NaviKit.sys.sta;
|
||||
TaskBeep(500,2);
|
||||
log_e("Retry after main power checked please.");
|
||||
}
|
||||
}break;
|
||||
case sleep:{
|
||||
enter_sleep_state(100);
|
||||
NaviKit.sys.sta = NaviKit.sys.next_sta;
|
||||
}break;
|
||||
case dfu:{
|
||||
// if(NaviKit.pmb.rails.main_pwr>19){
|
||||
if(NaviKit.pmb.main_pwr_good){
|
||||
enter_dfu_state(100);
|
||||
NaviKit.sys.sta = NaviKit.sys.next_sta;
|
||||
// }else{
|
||||
// NaviKit.sys.next_sta = NaviKit.sys.sta;
|
||||
// TaskBeep(500,2);
|
||||
// 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));
|
||||
// }
|
||||
}else{
|
||||
NaviKit.sys.next_sta = NaviKit.sys.sta;
|
||||
TaskBeep(500,2);
|
||||
log_e("Retry after main power checked please.");
|
||||
}
|
||||
}break;
|
||||
case isp:{
|
||||
enter_isp_state();
|
||||
|
@ -365,7 +360,6 @@ osVersion_t osVersion;
|
|||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -377,7 +371,6 @@ osVersion_t osVersion;
|
|||
log_i("Idle state hold timer started.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* USER CODE END StartDefaultTask */
|
||||
}
|
||||
|
@ -392,7 +385,41 @@ void IdleStateHoldTimerCallback(void *argument){
|
|||
NaviKit.sys.next_sta = standby;
|
||||
}
|
||||
}
|
||||
bool isWakeUpFromReset(){
|
||||
return __HAL_PWR_GET_FLAG(PWR_FLAG_WU);
|
||||
}
|
||||
|
||||
//judge reset source flag
|
||||
uint8_t ResetSourceJudge(){
|
||||
uint8_t rst_src=0;
|
||||
rst_src = __HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) ? RCC_FLAG_PINRST : 0;
|
||||
rst_src = __HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) ? RCC_FLAG_PORRST : 0;
|
||||
rst_src = __HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) ? RCC_FLAG_SFTRST : 0;
|
||||
rst_src = __HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) ? RCC_FLAG_IWDGRST : 0;
|
||||
rst_src = __HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST) ? RCC_FLAG_WWDGRST : 0;
|
||||
rst_src = __HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST) ? RCC_FLAG_LPWRRST : 0;
|
||||
switch (rst_src){
|
||||
case RCC_FLAG_PINRST :{
|
||||
log_i("Reset source RCC_FLAG_PINRST");
|
||||
}break;
|
||||
case RCC_FLAG_PORRST :{
|
||||
log_i("Reset source RCC_FLAG_PORRST");
|
||||
}break;
|
||||
case RCC_FLAG_SFTRST :{
|
||||
log_i("Reset source RCC_FLAG_SFTRST");
|
||||
}break;
|
||||
case RCC_FLAG_IWDGRST :{
|
||||
log_i("Reset source RCC_FLAG_IWDGRST");
|
||||
}break;
|
||||
case RCC_FLAG_WWDGRST :{
|
||||
log_i("Reset source RCC_FLAG_WWDGRST");
|
||||
}break;
|
||||
case RCC_FLAG_LPWRRST :{
|
||||
log_i("Reset source RCC_FLAG_LPWRRST");
|
||||
}break;
|
||||
}
|
||||
return rst_src;
|
||||
}
|
||||
|
||||
/* USER CODE END Application */
|
||||
|
||||
|
|
|
@ -52,9 +52,10 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
|
|||
}
|
||||
}
|
||||
|
||||
//温度变化较大时将触发看门狗,进行校准
|
||||
void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
HAL_ADCEx_Calibration_Start(&hadc1);
|
||||
// HAL_ADCEx_Calibration_Start(&hadc1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,8 +73,7 @@ void enter_isp_state()
|
|||
}
|
||||
|
||||
//timeout:the time of wait
|
||||
void enter_idle_state(uint16_t delay)
|
||||
{
|
||||
void enter_idle_state(uint16_t delay){
|
||||
log_i("Enter to idle state.");
|
||||
TaskBeep(50,1);
|
||||
|
||||
|
@ -108,8 +108,6 @@ void enter_idle_state(uint16_t delay)
|
|||
PWR_Enable(PMB_PS_ON ,false , 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void enter_run_state(uint16_t delay)
|
||||
{
|
||||
log_i("Enter to run state");
|
||||
|
@ -178,10 +176,24 @@ void som_reboot(uint16_t delay){
|
|||
PWR_Enable(SOM_RESET,false,0);
|
||||
}
|
||||
|
||||
|
||||
//device power enable or disable
|
||||
//delay: After executing the operation delay (ms)
|
||||
void PWR_Enable(enum Device_t device,bool en,uint16_t delay){
|
||||
bool result = false;
|
||||
result = PWR_Enable_IRQ(device,en,0);
|
||||
if(result){
|
||||
log_v("Device 0x%X has been %s",device,en ? "enabled" : "disabled");
|
||||
osDelay(delay);
|
||||
}else{
|
||||
log_e("Power_Enable device parameter is invalid!");
|
||||
}
|
||||
}
|
||||
|
||||
//PWR_Enable_IRQ:for interrupt safe reversion
|
||||
//device power enable or disable
|
||||
//device: Specified device
|
||||
//en: enable or disable
|
||||
//delay: After executing the operation delay (ms)
|
||||
//return: true-success;false-parameter valid
|
||||
bool PWR_Enable_IRQ(enum Device_t device,bool en,uint16_t delay){
|
||||
switch (device){
|
||||
case USB2_Port1: {HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port, USB2_VBUS_CTL_1_Pin, en); }break;
|
||||
case USB2_Port2: {HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port, USB2_VBUS_CTL_2_Pin, en); }break;
|
||||
|
@ -210,10 +222,10 @@ void PWR_Enable(enum Device_t device,bool en,uint16_t delay){
|
|||
case SOM_RESET: {HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port, SOM_SYS_RESET_Pin, !en); }break;
|
||||
case SOM_SLEEP: {HAL_GPIO_WritePin(SOM_SLEEP_WAKE_GPIO_Port, SOM_SLEEP_WAKE_Pin, !en); }break;
|
||||
case PMB_PS_ON: {HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port, PMB_PS_ON_Pin, en); }break;
|
||||
default: {log_e("PWR_Enable device parameter is invalid."); }break;
|
||||
default: {return false; }break;
|
||||
}
|
||||
log_v("Device 0x%X has been %s",device,en ? "enabled" : "disabled");
|
||||
osDelay(delay);
|
||||
return true;
|
||||
}
|
||||
|
||||
//check device on board power status
|
||||
|
|
|
@ -269,6 +269,14 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
|||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart){
|
||||
if(huart->Instance == USART1){
|
||||
HAL_UART1_TxHalfCpltCallback(huart);
|
||||
}
|
||||
}
|
||||
__weak void HAL_UART1_TxHalfCpltCallback(UART_HandleTypeDef *huart){
|
||||
UNUSED(huart);
|
||||
}
|
||||
|
||||
//printf redirect
|
||||
#ifdef __GNUC__
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit a813ff549eeec5fa41af5604770092e62ab504fc
|
||||
Subproject commit 69ca6cd42c7370db783c8df9943fc44bc3761574
|
Loading…
Reference in New Issue