master
ThinkPad-T460P 2021-03-15 19:26:10 +08:00
parent 26ff1cf7bc
commit 3fc9d2c2b2
25 changed files with 374 additions and 335 deletions

View File

@ -13,6 +13,6 @@
osThreadId_t cdcMonitorTaskHandle; osThreadId_t cdcMonitorTaskHandle;
const osThreadAttr_t cdcMonitorTask_attributes; const osThreadAttr_t cdcMonitorTask_attributes;
void StartCdcMonitorTask(void *argument); void CdcMonitorTask(void *argument);
#endif #endif

View File

@ -10,10 +10,10 @@
#include "cmsis_os2.h" #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 #endif

View File

@ -9,7 +9,7 @@ osThreadId_t DemoTask1Handle;
const osThreadAttr_t DemoTask1_attributes; const osThreadAttr_t DemoTask1_attributes;
const osThreadAttr_t DemoTask2_attributes; const osThreadAttr_t DemoTask2_attributes;
void StartDemoTask1(void *argument); void DemoTask1(void *argument);
void StartDemoTask2(void *argument); void DemoTask2(void *argument);
#endif #endif

View File

@ -6,9 +6,9 @@
osSemaphoreId_t ElogOutputBinarySemHandle; osSemaphoreId_t ElogOutputBinarySemHandle;
const osSemaphoreAttr_t ElogOutputBinarySem_attributes; const osSemaphoreAttr_t ElogOutputBinarySem_attributes;
osSemaphoreId_t ElogUartBinarySemHandle;
const osSemaphoreAttr_t ElogUartBinarySem_attributes;
osMutexId_t ElogUartMutexHandle;
const osMutexAttr_t ElogUartMutex_attributes;
osMutexId_t ElogOutputMutexHandle; osMutexId_t ElogOutputMutexHandle;
const osMutexAttr_t ElogOutputMutex_attributes; const osMutexAttr_t ElogOutputMutex_attributes;
@ -19,8 +19,8 @@ osThreadId_t ElogFlushTaskHandle;
const osThreadAttr_t ElogInitTask_attributes; const osThreadAttr_t ElogInitTask_attributes;
const osThreadAttr_t ElogFlushTask_attributes; const osThreadAttr_t ElogFlushTask_attributes;
void StartElogInitTask(void *argument); void ElogInitTask(void *argument);
void StartElogFlushTask(void *argument); void ElogFlushTask(uint8_t intervnal);
void my_elog_init(); void my_elog_init();
#endif #endif

View File

@ -10,24 +10,7 @@
#include "cmsis_os2.h" #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; const osTimerAttr_t CustBtnShortPressTimer_attributes;
//Event Flag //Event Flag
osEventFlagsId_t ExtiEventFlags; // osEventFlagsId_t ExtiEventFlags;
const osEventFlagsAttr_t ExtiEventFlags_attributes; // const osEventFlagsAttr_t ExtiEventFlags_attributes;
//Task //Task
void StartExtiServiceTask(void *argument); void ExtiServiceTask(void *argument);
//callback //callback
void PwrBtnLongPressTimerCallback(void *argument); void PwrBtnLongPressTimerCallback(void *argument);

View File

@ -7,5 +7,5 @@ osThreadId_t InfoOutputTaskHandle;
const osThreadAttr_t InfoOutputTask_attributes; const osThreadAttr_t InfoOutputTask_attributes;
void StartInfoOutputTask(void *argument); void InfoOutputTask(void *argument);
#endif #endif

View File

@ -7,6 +7,6 @@ osThreadId_t IWDGTaskHandle;
const osThreadAttr_t IWDGTask_attributes; const osThreadAttr_t IWDGTask_attributes;
void StartIWDGTask(void *argument); void IWDGTask(void *argument);
#endif #endif

View File

@ -13,7 +13,7 @@
/* Definitions for LedBlinkTask */ /* Definitions for LedBlinkTask */
osThreadId_t LedBlinkTaskHandle; osThreadId_t LedBlinkTaskHandle;
const osThreadAttr_t LedBlinkTask_attributes; const osThreadAttr_t LedBlinkTask_attributes;
void StartLedBlinkTask(void *argument); void LedBlinkTask(void *argument);
#endif #endif

View File

@ -10,9 +10,18 @@
#include "cmsis_os2.h" #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 */ /* Definitions for PowerMonitTask */
osThreadId_t PowerMonitTaskHandle; osThreadId_t PowerMonitTaskHandle;
const osThreadAttr_t PowerMonitTask_attributes; const osThreadAttr_t PowerMonitTask_attributes;
void StartPowerMonitTask(void *argument); void PowerMonitTask(void *argument);
#endif #endif

View File

@ -20,7 +20,7 @@ const osThreadAttr_t cdcMonitorTask_attributes = {
}; };
//task instance //task instance
void StartCdcMonitorTask(void *argument){ void CdcMonitorTask(void *argument){
uint8_t port_restart_temp[64]={0}; uint8_t port_restart_temp[64]={0};
uint32_t number_restart_temp =0; uint32_t number_restart_temp =0;
bool beep_flag = false; bool beep_flag = false;

View File

@ -14,10 +14,10 @@
/* Definitions for CoulombRead */ /* Definitions for CoulombRead */
const osThreadAttr_t CoulombRead_attributes = { const osThreadAttr_t CoulombTask_attributes = {
.name = "CoulombRead", .name = "CoulombTask",
.priority = (osPriority_t) osPriorityBelowNormal, .priority = (osPriority_t) osPriorityBelowNormal,
.stack_size = 128 * 4 .stack_size = 256 * 4
}; };
/* USER CODE BEGIN Header_StartCoulombRead */ /* USER CODE BEGIN Header_StartCoulombRead */
@ -27,7 +27,7 @@ const osThreadAttr_t CoulombRead_attributes = {
* @retval None * @retval None
*/ */
/* USER CODE END Header_StartCoulombRead */ /* USER CODE END Header_StartCoulombRead */
void StartCoulombRead(void *argument) void CoulombTask(void *argument)
{ {
/* USER CODE BEGIN StartCoulombRead */ /* USER CODE BEGIN StartCoulombRead */
log_d("Start Coulomb Read Task"); log_d("Start Coulomb Read Task");

View File

@ -13,23 +13,23 @@
const osThreadAttr_t DemoTask1_attributes = { const osThreadAttr_t DemoTask1_attributes = {
.name = "DemoTask1", .name = "DemoTask1",
.priority = (osPriority_t) osPriorityLow1, .priority = (osPriority_t) osPriorityLow2,
.stack_size = 256 * 4 .stack_size = 256 * 4
}; };
const osThreadAttr_t DemoTask2_attributes = { const osThreadAttr_t DemoTask2_attributes = {
.name = "DemoTask2", .name = "DemoTask2",
.priority = (osPriority_t) osPriorityLow1, .priority = (osPriority_t) osPriorityLow2,
.stack_size = 256 * 4 .stack_size = 256 * 4
}; };
void StartDemoTask1(void *argument){ void DemoTask1(void *argument){
uint8_t i=0; uint8_t i=0;
log_d("Start Demo Task1"); log_d("Start Demo Task1");
for(;;){ for(;;){
log_v("DemoTask1 counter [%d].",i++);
osDelay(100); osDelay(100);
log_v("DemoTask1 counter [%d].",i++);
} }
} }
void StartDemoTask2(void *argument){ void DemoTask2(void *argument){
uint8_t i=0; uint8_t i=0;
log_d("Start Demo Task2"); log_d("Start Demo Task2");
for(;;){ for(;;){

View File

@ -15,9 +15,9 @@
const osSemaphoreAttr_t ElogOutputBinarySem_attributes = { const osSemaphoreAttr_t ElogOutputBinarySem_attributes = {
.name = "ElogOutputBinarySem" .name = "ElogOutputBinarySem"
}; };
//mutex //semaphore
const osMutexAttr_t ElogUartMutex_attributes = { const osSemaphoreAttr_t ElogUartBinarySem_attributes = {
.name = "ElogUartMutex" .name = "ElogUartBinarySem"
}; };
const osMutexAttr_t ElogOutputMutex_attributes = { const osMutexAttr_t ElogOutputMutex_attributes = {
.name = "ElogOutputMutex" .name = "ElogOutputMutex"
@ -31,23 +31,24 @@ const osThreadAttr_t ElogInitTask_attributes = {
const osThreadAttr_t ElogFlushTask_attributes = { const osThreadAttr_t ElogFlushTask_attributes = {
.name = "ElogFlushTask", .name = "ElogFlushTask",
.priority = (osPriority_t) osPriorityLow, .priority = (osPriority_t) osPriorityLow1,
.stack_size = 256 * 4 .stack_size = 256 * 4
}; };
void StartElogInitTask(void *argument){ void ElogInitTask(void *argument){
// my_elog_init(); // my_elog_init();
// osThreadExit();//exit this thread,execute this code only once // osThreadExit();//exit this thread,execute this code only once
} }
void StartElogFlushTask(void *argument){ //intervalbuffer flush time interval
void ElogFlushTask(uint8_t intervnal){
log_d("Start log Flush Task"); log_d("Start log Flush Task");
for(;;){ for(;;){
elog_flush(); elog_flush();
osDelay(1); osDelay(intervnal);
} }
} }
@ -81,3 +82,9 @@ void my_elog_init(){
/* start EasyLogger */ /* start EasyLogger */
elog_start(); elog_start();
} }
void HAL_UART1_TxHalfCpltCallback(UART_HandleTypeDef *huart){
osSemaphoreRelease(ElogUartBinarySemHandle);
}

View File

@ -11,10 +11,28 @@
#include "main.h" #include "main.h"
#include "navikit.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 //Thread
const osThreadAttr_t ExtiServiceTask_attributes = { const osThreadAttr_t ExtiServiceTask_attributes = {
.name = "ExtiServiceTask", .name = "ExtiServiceTask",
.priority = (osPriority_t) osPriorityBelowNormal, .priority = (osPriority_t) osPriorityBelowNormal1,
.stack_size = 256 * 4 .stack_size = 256 * 4
}; };
@ -32,74 +50,88 @@ const osTimerAttr_t CustBtnShortPressTimer_attributes = {
.name = "CustBtnShortPressTimer" .name = "CustBtnShortPressTimer"
}; };
//Event Flag // //Event Flag
const osEventFlagsAttr_t ExtiEventFlags_attributes = { // const osEventFlagsAttr_t ExtiEventFlags_attributes = {
.name = "ExtiEventFlags" // .name = "ExtiEventFlags"
}; // };
/* USER CODE BEGIN Header_StartExtiServiceTask */ /* USER CODE BEGIN Header_ExtiServiceTask */
/** /**
* @brief Function implementing the ExtiServiceTask thread. * @brief Function implementing the ExtiServiceTask thread.
* @param argument: Not used * @param argument: Not used
* @retval None * @retval None
*/ */
/* USER CODE END Header_StartExtiServiceTask */ /* USER CODE END Header_ExtiServiceTask */
void StartExtiServiceTask(void *argument) void ExtiServiceTask(void *argument)
{ {
/* USER CODE BEGIN StartExtiServiceTask */ /* USER CODE BEGIN ExtiServiceTask */
/* Infinite loop */ /* Infinite loop */
uint32_t thread_flag = 0; uint32_t thread_flag = 0;
log_d("Start EXTI Service Task"); 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(;;) for(;;)
{ {
thread_flag = osThreadFlagsGet(); thread_flag = osThreadFlagsGet();
//shutdown request pin
if(thread_flag & SHUTDOWN_REQ){ 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
osTimerStart(PwrBtnLongPressTimerHandle,LONG_PRESS_TIME); if(thread_flag & THREAD_FLAG_EXTI_SERVICE_MOD_SLEEP_ACTIVE){
osTimerStart(PwrBtnShortPressTimerHandle,SHORT_PRESS_TIME); log_v("SOM's mod_sleep pin rising edge");
}else if(!(thread_flag & PWR_BTN) && osTimerIsRunning(PwrBtnLongPressTimerHandle)){ 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);
}
}
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(PwrBtnLongPressTimerHandle);
osTimerStop(PwrBtnShortPressTimerHandle); osTimerStop(PwrBtnShortPressTimerHandle);
} }
//custom button
if((thread_flag & CUS_BTN) && !osTimerIsRunning(CustBtnLongPressTimerHandle)) { //custom button pin
osTimerStart(CustBtnLongPressTimerHandle,LONG_PRESS_TIME); if(thread_flag & THREAD_FLAG_EXTI_SERVICE_CUS_BTN_ACTIVE){
osTimerStart(CustBtnShortPressTimerHandle,SHORT_PRESS_TIME); log_v("custom_btn status: pressed.");
}else if(!(thread_flag & CUS_BTN) && osTimerIsRunning(CustBtnLongPressTimerHandle)){ osThreadFlagsClear(THREAD_FLAG_EXTI_SERVICE_CUS_BTN_ACTIVE);
if(!osTimerIsRunning(CustBtnLongPressTimerHandle)) {
osTimerStart(CustBtnLongPressTimerHandle,LONG_PRESS_TIME);
osTimerStart(CustBtnShortPressTimerHandle,SHORT_PRESS_TIME);
}
}
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(CustBtnLongPressTimerHandle);
osTimerStop(CustBtnShortPressTimerHandle); 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); osDelay(10);
} }
/* USER CODE END StartExtiServiceTask */ /* USER CODE END ExtiServiceTask */
} }
@ -136,34 +168,38 @@ void CustBtnLongPressTimerCallback(void *argument)
} }
void PwrBtnShortPressTimerCallback(void *argument) void PwrBtnShortPressTimerCallback(void *argument)
{ {
log_v("power button short pressed."); if(osThreadFlagsGet() & THREAD_FLAG_EXTI_SERVICE_PWR_BTN_INACTIVE){//power_button has released
switch(NaviKit.sys.sta){ log_v("power button short pressed.");
case run: {//som is running, send sleep requeset to operate system switch(NaviKit.sys.sta){
log_v("Request operate system pop up the shutdown dialog."); case run: {//som is running, send sleep requeset to operate system
PWR_Enable(SOM_SLEEP,true,100); log_v("Request operate system pop up the shutdown dialog.");
PWR_Enable(SOM_SLEEP,false,0); PWR_Enable(SOM_SLEEP,true,100);
}break; PWR_Enable(SOM_SLEEP,false,0);
case idle: { }break;//system is idle now , user request to power on }break;
case dfu: { }break; case idle: { }break;//system is idle now , user request to power on
case sleep:{ }break; case dfu: { }break;
case isp: { }break; case sleep:{ }break;
default : break; case isp: { }break;
} default : break;
}
}
} }
void CustBtnShortPressTimerCallback(void *argument) void CustBtnShortPressTimerCallback(void *argument)
{ {
log_v("custom button short pressed."); if(osThreadFlagsGet() & THREAD_FLAG_EXTI_SERVICE_PWR_BTN_INACTIVE){//power_button has released
switch(NaviKit.sys.sta){ log_v("custom button short pressed.");
case run:{ switch(NaviKit.sys.sta){
}break; case run:{
case idle:{ }break;
}break; case idle:{
case dfu:{ }break;
}break; case dfu:{
case sleep:{ }break;
}break; case sleep:{
default : break; }break;
} default : break;
}
}
} }
@ -174,45 +210,42 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
case SOM_SHUTDOWN_REQ_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(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 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; NaviKit.sys.next_sta = idle;
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)SHUTDOWN_REQ_ACTIVE); osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_SHUTDOWN_REQ_ACTIVE);
// log_i("SOM's shutdown_req pin falling edge, SOM request to shutdown.");
} }
}else{//Rising edge trigger }else{//Rising edge trigger
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)SHUTDOWN_REQ_INACTIVE); osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_SHUTDOWN_REQ_INACTIVE);
} }
}break; }break;
case SOM_MOD_SLEEP_Pin:{ case SOM_MOD_SLEEP_Pin:{
if(HAL_GPIO_ReadPin(SOM_MOD_SLEEP_GPIO_Port, SOM_MOD_SLEEP_Pin)==GPIO_PIN_SET){//Rising edge trigger 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,THREAD_FLAG_EXTI_SERVICE_MOD_SLEEP_ACTIVE);
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)MOD_SLEEP_ACTIVE);
}else{//falling edge trigger }else{//falling edge trigger
// log_v("SOM's sleep pin falling edge."); osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_MOD_SLEEP_INACTIVE);
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)MOD_SLEEP_INACTIVE);
} }
}break; }break;
case SYS_POWER_BTN_Pin:{ case SYS_POWER_BTN_Pin:{
if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){//Rising edge trigger if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){//Rising edge trigger
NaviKit.sys.power_btn = true; // NaviKit.sys.power_btn = true;
// log_v("power_btn status: pressed."); //power button pressed
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)PWR_BTN_ACTIVE); osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_PWR_BTN_ACTIVE);
}else{//falling edge trigger }else{//falling edge trigger
NaviKit.sys.power_btn = false; // NaviKit.sys.power_btn = false;
// log_v("power_btn status: released."); //power button released
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)PWR_BTN_INACTIVE); osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_PWR_BTN_INACTIVE);
} }
}break; }break;
case SYS_CUSTOM_BTN_Pin:{ case SYS_CUSTOM_BTN_Pin:{
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){//falling edge trigger 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;
NaviKit.sys.custom_btn = true; //custom button pressed
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)CUS_BTN_ACTIVE); osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_CUS_BTN_ACTIVE);
}else{//Rising edge trigger }else{//Rising edge trigger
// log_v("custom_btn status: released."); // NaviKit.sys.custom_btn = false;
NaviKit.sys.custom_btn = false; //custom button released
osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)CUS_BTN_INACTIVE); osThreadFlagsSet(ExtiServiceTaskHandle,THREAD_FLAG_EXTI_SERVICE_CUS_BTN_INACTIVE);
} }
}break; }break;
} }

View File

@ -16,7 +16,7 @@ const osThreadAttr_t InfoOutputTask_attributes = {
.priority = (osPriority_t) osPriorityLow2, .priority = (osPriority_t) osPriorityLow2,
.stack_size = 256 * 4 .stack_size = 256 * 4
}; };
void StartInfoOutputTask(void *argument){ void InfoOutputTask(void *argument){
log_d("Start Info Output Task"); log_d("Start Info Output Task");
for(;;){ for(;;){
osThreadExit(); osThreadExit();

View File

@ -18,7 +18,7 @@ const osThreadAttr_t IWDGTask_attributes = {
.stack_size = 256 * 4 .stack_size = 256 * 4
}; };
void StartIWDGTask(void *argument){ void IWDGTask(void *argument){
log_d("Start IWDG Task"); log_d("Start IWDG Task");
for(;;){ for(;;){
HAL_IWDG_Refresh(&hiwdg); HAL_IWDG_Refresh(&hiwdg);

View File

@ -13,35 +13,37 @@
const osThreadAttr_t LedBlinkTask_attributes = { const osThreadAttr_t LedBlinkTask_attributes = {
.name = "LedBlinkTask", .name = "LedBlinkTask",
.priority = (osPriority_t) osPriorityLow7, .priority = (osPriority_t) osPriorityLow,
.stack_size = 256 * 4 .stack_size = 256 * 4
}; };
/* USER CODE BEGIN Header_StartLedBlinkTask */ /* USER CODE BEGIN Header_LedBlinkTask */
/** /**
* @brief Function implementing the LedBlinkTask thread. * @brief Function implementing the LedBlinkTask thread.
* @param argument: Not used * @param argument: Not used
* @retval None * @retval None
*/ */
/* USER CODE END Header_StartLedBlinkTask */ /* USER CODE END Header_LedBlinkTask */
void StartLedBlinkTask(void *argument) void LedBlinkTask(void *argument)
{ {
/* USER CODE BEGIN StartLedBlinkTask */ /* USER CODE BEGIN LedBlinkTask */
/* Infinite loop */ /* Infinite loop */
log_d("Start LED Blink Task"); log_d(" LED Blink Task");
for(;;) for(;;)
{ {
osDelay(1000); osDelay(1000);
switch(NaviKit.sys.sta){ switch(NaviKit.sys.sta){
case run: { case run: {
PWR_Enable(SYS_PWR_LED,true,0);//turn on power led 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,true,50);//turn on sys run led
PWR_Enable(SYS_RUN_LED,false,0);//turn off sys run led PWR_Enable(SYS_RUN_LED,false,0);//turn off sys run led
}break; }break;
case idle:{ 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,true,20);//turn on sys run led
PWR_Enable(SYS_RUN_LED,false,3000);//turn off 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; default : break;
} }
} }
/* USER CODE END StartLedBlinkTask */ /* USER CODE END LedBlinkTask */
} }

View File

@ -18,86 +18,80 @@ const osThreadAttr_t PowerMonitTask_attributes = {
.stack_size = 256 * 4 .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 * @brief Function: Monit som power status and PMB status
* @param argument: Not used * @param argument: Not used
* @retval None * @retval None
*/ */
/* USER CODE END Header_StartPowerMonitTask */ /* USER CODE END Header_PowerMonitTask */
void StartPowerMonitTask(void *argument) void PowerMonitTask(void *argument)
{ {
/* USER CODE BEGIN StartPowerMonitTask */ /* USER CODE BEGIN PowerMonitTask */
log_d("Start Power Monitor Task"); log_d("Start Power Monitor Task");
HAL_ADCEx_Calibration_Start(&hadc1); HAL_ADCEx_Calibration_Start(&hadc1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT); HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT);
osDelay(100); osDelay(10);
/* Infinite loop */ /* Infinite loop */
for(;;) for(;;)
{ {
if((NaviKit.pmb.rails.main_pwr > 30) || (NaviKit.pmb.rails.main_pwr < 19)){
if(NaviKit.pmb.rails.main_pwr > 30){ NaviKit.pmb.main_pwr_good = false;
TaskBeep(200,1); log_e("Main power:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
log_e("Main power is exception:%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.bkp_bat > 15){
log_e("Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); if((NaviKit.pmb.rails.bkp_bat < 8) || (NaviKit.pmb.rails.bkp_bat > 15)){
TaskBeep(200,1); TaskBeep(200,2);
}else{
//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(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));
} }
//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) if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6)
log_v("Backup battery status:%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); log_e("24V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
if(!NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2) else
log_v("Backup battery status:%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); log_d("24V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*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.out_5v > 5.5 || NaviKit.pmb.rails.out_5v < 4.5)
if(NaviKit.pmb.rails.main_pwr < 19){ log_e("5V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
TaskBeep(200,1); else
log_w("Main power has been lost, please shutdown computer as soon as possible:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); log_d("5V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
}else
log_v("Main power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6) if(NaviKit.pmb.rails.out_12v > 13.2 || NaviKit.pmb.rails.out_12v < 10.8)
log_e("24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000)); log_e("12V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
else else
log_v("24V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000)); log_d("12V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*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));
else
log_v("5V(±10%%) power rail regular:%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));
else
log_v("12V(±10%%) power rail regular:%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);
}
// log_d("state :%d",NaviKit.sys.sta);
// log_d("next_state :%d",NaviKit.sys.next_sta);
osDelay(3000);
} }
/* USER CODE END StartPowerMonitTask */ /* USER CODE END PowerMonitTask */
} }

View File

@ -41,11 +41,12 @@ typedef struct
{ {
struct{ struct{
state_t sta,next_sta; //power state machine state_t sta,next_sta; //power state machine
bool power_btn; //power button pressed flag bool ps_on_allow; //allow power-on
bool custom_btn;//custom button pressed flag // bool power_btn; //power button pressed flag
// bool custom_btn;//custom button pressed flag
// bool pwr_led;//power led (on switch) // bool pwr_led;//power led (on switch)
// bool run_led;//run led (on board) // 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; }sys;
struct{ struct{
bool mod_sleep; bool mod_sleep;
@ -78,49 +79,9 @@ typedef struct
float cap; float cap;
float temp; float temp;
}coulomb; }coulomb;
bool main_pwr_good;
}pmb;//power management board }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; }NaviKit_t;
extern NaviKit_t NaviKit; 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 PMB_PS_ON=0x40}; //Power Management Board
void PWR_Enable(enum Device_t device,bool en,uint16_t delay); 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); bool PWR_Status(enum Device_t device);
void NaviKit_var_init(); void NaviKit_var_init();

View File

@ -43,6 +43,7 @@ void MX_USART1_UART_Init(void);
/* USER CODE BEGIN Prototypes */ /* USER CODE BEGIN Prototypes */
void HAL_UART1_TxHalfCpltCallback(UART_HandleTypeDef *huart);
/* USER CODE END Prototypes */ /* USER CODE END Prototypes */
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -17,7 +17,6 @@
****************************************************************************** ******************************************************************************
*/ */
//TODO:拆分该文件中的功能到不同的文件中,按照任务进行模块化拆分
#define LOG_TAG "TH-Default" #define LOG_TAG "TH-Default"
/* USER CODE END Header */ /* USER CODE END Header */
@ -80,9 +79,10 @@ const osThreadAttr_t defaultTask_attributes = {
void IdleStateHoldTimerCallback(void *argument); 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 */ /* USER CODE END FunctionPrototypes */
@ -170,9 +170,9 @@ __weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
void MX_FREERTOS_Init(void) { void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN Init */ /* USER CODE BEGIN Init */
// ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes); ElogUartBinarySemHandle = osSemaphoreNew(1, 0, &ElogUartBinarySem_attributes);
ElogOutputBinarySemHandle = osSemaphoreNew(1, 1, &ElogOutputBinarySem_attributes); ElogOutputBinarySemHandle = osSemaphoreNew(1, 0, &ElogOutputBinarySem_attributes);
// ElogUartMutexHandle = osMutexNew(&ElogUartMutex_attributes);
my_elog_init(); my_elog_init();
NaviKit_var_init(); NaviKit_var_init();
/* USER CODE END Init */ /* USER CODE END Init */
@ -210,56 +210,57 @@ void MX_FREERTOS_Init(void) {
/* add threads, ... */ /* add threads, ... */
//IWDG-------------------------------------------- //IWDG--------------------------------------------
#ifdef IWDG_ENABLE #ifdef IWDG_ENABLE
IWDGTaskHandle = osThreadNew(StartIWDGTask, NULL, &IWDGTask_attributes); IWDGTaskHandle = osThreadNew(IWDGTask, NULL, &IWDGTask_attributes);
#endif #endif
//Power-------------------------------------------- //Power--------------------------------------------
// PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes); PowerMonitTaskHandle = osThreadNew(PowerMonitTask, NULL, &PowerMonitTask_attributes);
//Button-------------------------------------------- //Button--------------------------------------------
ExtiServiceTaskHandle = osThreadNew(StartExtiServiceTask, NULL, &ExtiServiceTask_attributes); ExtiServiceTaskHandle = osThreadNew(ExtiServiceTask, NULL, &ExtiServiceTask_attributes);
//LED-------------------------------------------- //LED--------------------------------------------
LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes); LedBlinkTaskHandle = osThreadNew(LedBlinkTask, NULL, &LedBlinkTask_attributes);
//CDC-------------------------------------------- //CDC--------------------------------------------
cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes); cdcMonitorTaskHandle = osThreadNew(CdcMonitorTask, NULL, &cdcMonitorTask_attributes);
//Coulomb-------------------------------------------- //Coulomb--------------------------------------------
// CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes); // CoulombTaskHandle = osThreadNew(CoulombTask, NULL, &CoulombTask_attributes);
//Elog-------------------------------------------- //Elog--------------------------------------------
// ElogInitTaskHandle = osThreadNew(StartElogInitTask, NULL, &ElogInitTask_attributes); // ElogInitTaskHandle = osThreadNew(ElogInitTask, NULL, &ElogInitTask_attributes);
#ifdef ELOG_BUF_OUTPUT_ENABLE #ifdef ELOG_BUF_OUTPUT_ENABLE
ElogFlushTaskHandle = osThreadNew(StartElogFlushTask, NULL, &ElogFlushTask_attributes); ElogFlushTaskHandle = osThreadNew(ElogFlushTask, 1, &ElogFlushTask_attributes);
#endif #endif
//Demo-------------------------------------------- //Demo--------------------------------------------
DemoTask1Handle = osThreadNew(StartDemoTask1, NULL, &DemoTask1_attributes); // DemoTask1Handle = osThreadNew(DemoTask1, NULL, &DemoTask1_attributes);
DemoTask2Handle = osThreadNew(StartDemoTask2, NULL, &DemoTask2_attributes); // DemoTask2Handle = osThreadNew(DemoTask2, NULL, &DemoTask2_attributes);
/* USER CODE END RTOS_THREADS */ /* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_EVENTS */ /* USER CODE BEGIN RTOS_EVENTS */
/* add events, ... */ /* add events, ... */
ExtiEventFlags = osEventFlagsNew(&ExtiEventFlags_attributes); // ExtiEventFlags = osEventFlagsNew(&ExtiEventFlags_attributes);
// PowerMonitorEventFlags = osEventFlagsNew(&PowerMonitorEventFlags_attributes);
/* USER CODE END RTOS_EVENTS */ /* USER CODE END RTOS_EVENTS */
} }
/* USER CODE BEGIN Header_StartDefaultTask */ /* USER CODE BEGIN Header_DefaultTask */
/** /**
* @brief Function implementing the defaultTask thread. * @brief Function implementing the defaultTask thread.
* @param argument: Not used * @param argument: Not used
* @retval None * @retval None
*/ */
/* USER CODE END Header_StartDefaultTask */ /* USER CODE END Header_DefaultTask */
void StartDefaultTask(void *argument) void StartDefaultTask(void *argument)
{ {
/* init code for USB_DEVICE */ /* init code for USB_DEVICE */
@ -268,7 +269,7 @@ void StartDefaultTask(void *argument)
osVersion_t osVersion; osVersion_t osVersion;
char id_buf[20]; char id_buf[20];
unsigned char id_size=20; unsigned char id_size=20;
// ResetSourceJudge();
HAL_GPIO_WritePin(USB2_FS_ENUM_CTL_GPIO_Port,USB2_FS_ENUM_CTL_Pin, GPIO_PIN_SET); 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" 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_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) if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET)
NaviKit.sys.next_sta = dfu; NaviKit.sys.next_sta = dfu;
else{
NaviKit.sys.power_btn = true;
}
log_i("EC Reset source: [Power Button WakeUP]"); log_i("EC Reset source: [Power Button WakeUP]");
}else{ }else{
NaviKit.sys.next_sta = idle; NaviKit.sys.next_sta = idle;
@ -295,10 +293,9 @@ osVersion_t osVersion;
}else{ }else{
NaviKit.sys.next_sta = idle; NaviKit.sys.next_sta = idle;
} }
// TaskBeep(50,1); TaskBeep(50,1);
} }
log_i("----------------------------------------------");
log_i("Copyright (c) Powered by www.autolabor.com.cn"); log_i("Copyright (c) Powered by www.autolabor.com.cn");
#ifdef DEBUG #ifdef DEBUG
log_i("EC Firmware: %s[DEBUG], build: %s, %s",APP_VERSION,__DATE__ ,__TIME__); 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; NaviKit.sys.sta = NaviKit.sys.next_sta;
} break; } break;
case run: { case run: {
// if(NaviKit.pmb.rails.main_pwr>19){ if(NaviKit.pmb.main_pwr_good){
enter_run_state(100); enter_run_state(100);
NaviKit.sys.sta = NaviKit.sys.next_sta; NaviKit.sys.sta = NaviKit.sys.next_sta;
// }else{ }else{
// NaviKit.sys.next_sta = NaviKit.sys.sta; NaviKit.sys.next_sta = NaviKit.sys.sta;
// TaskBeep(500,2); TaskBeep(500,2);
// log_e(,"Main power not exist, retry after plug in it."); log_e("Retry after main power checked please.");
// log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); }
// }
}break; }break;
case sleep:{ case sleep:{
enter_sleep_state(100); enter_sleep_state(100);
NaviKit.sys.sta = NaviKit.sys.next_sta; NaviKit.sys.sta = NaviKit.sys.next_sta;
}break; }break;
case dfu:{ case dfu:{
// if(NaviKit.pmb.rails.main_pwr>19){ if(NaviKit.pmb.main_pwr_good){
enter_dfu_state(100); enter_dfu_state(100);
NaviKit.sys.sta = NaviKit.sys.next_sta; NaviKit.sys.sta = NaviKit.sys.next_sta;
// }else{ }else{
// NaviKit.sys.next_sta = NaviKit.sys.sta; NaviKit.sys.next_sta = NaviKit.sys.sta;
// TaskBeep(500,2); TaskBeep(500,2);
// log_e(,"Main power not exist, retry after plug in it."); log_e("Retry after main power checked please.");
// log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); }
// }
}break; }break;
case isp:{ case isp:{
enter_isp_state(); enter_isp_state();
@ -365,7 +360,6 @@ osVersion_t osVersion;
}break; }break;
} }
} }
if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){//idle state if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){//idle state
// if((NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2) // 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.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)){//Not Charge or float charge
@ -373,11 +367,10 @@ osVersion_t osVersion;
// } // }
if(!osTimerIsRunning(IdleStateHoldTimerHandle)){ if(!osTimerIsRunning(IdleStateHoldTimerHandle)){
osTimerStart(IdleStateHoldTimerHandle,5000); osTimerStart(IdleStateHoldTimerHandle,5000);
log_i("Idle state hold timer started."); log_i("Idle state hold timer started.");
} }
} }
} }
/* USER CODE END StartDefaultTask */ /* USER CODE END StartDefaultTask */
} }
@ -392,7 +385,41 @@ void IdleStateHoldTimerCallback(void *argument){
NaviKit.sys.next_sta = standby; 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 */ /* USER CODE END Application */

View File

@ -52,9 +52,10 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
} }
} }
//温度变化较大时将触发看门狗,进行校准
void HAL_ADC_LevelOutOfWindowCallback(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 //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."); log_i("Enter to idle state.");
TaskBeep(50,1); TaskBeep(50,1);
@ -108,8 +108,6 @@ void enter_idle_state(uint16_t delay)
PWR_Enable(PMB_PS_ON ,false , 0); PWR_Enable(PMB_PS_ON ,false , 0);
} }
void enter_run_state(uint16_t delay) void enter_run_state(uint16_t delay)
{ {
log_i("Enter to run state"); log_i("Enter to run state");
@ -178,42 +176,56 @@ void som_reboot(uint16_t delay){
PWR_Enable(SOM_RESET,false,0); 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){ void PWR_Enable(enum Device_t device,bool en,uint16_t delay){
switch (device){ bool result = false;
case USB2_Port1: {HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port, USB2_VBUS_CTL_1_Pin, en); }break; result = PWR_Enable_IRQ(device,en,0);
case USB2_Port2: {HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port, USB2_VBUS_CTL_2_Pin, en); }break; if(result){
case USB2_Port3: {HAL_GPIO_WritePin(USB2_VBUS_CTL_3_GPIO_Port, USB2_VBUS_CTL_3_Pin, en); }break; log_v("Device 0x%X has been %s",device,en ? "enabled" : "disabled");
case USB2_Port4: {HAL_GPIO_WritePin(USB2_VBUS_CTL_4_GPIO_Port, USB2_VBUS_CTL_4_Pin, en); }break; osDelay(delay);
case USB2_Port5: {HAL_GPIO_WritePin(USB2_VBUS_CTL_5_GPIO_Port, USB2_VBUS_CTL_5_Pin, en); }break; }else{
case USB2_Port6: {HAL_GPIO_WritePin(USB2_VBUS_CTL_6_GPIO_Port, USB2_VBUS_CTL_6_Pin, en); }break; log_e("Power_Enable device parameter is invalid!");
case USB3_Port1: {HAL_GPIO_WritePin(USB3_VBUS_CTL_1_GPIO_Port, USB3_VBUS_CTL_1_Pin, en); }break; }
case USB3_Port2: {HAL_GPIO_WritePin(USB3_VBUS_CTL_2_GPIO_Port, USB3_VBUS_CTL_2_Pin, en); }break; }
case USB3_Port3: {HAL_GPIO_WritePin(USB3_VBUS_CTL_3_GPIO_Port, USB3_VBUS_CTL_3_Pin, en); }break;
case USB3_Port4: {HAL_GPIO_WritePin(USB3_VBUS_CTL_4_GPIO_Port, USB3_VBUS_CTL_4_Pin, en); }break; //PWR_Enable_IRQfor interrupt safe reversion
case USB3_Port5: {HAL_GPIO_WritePin(USB3_VBUS_CTL_5_GPIO_Port, USB3_VBUS_CTL_5_Pin, en); }break; //device power enable or disable
case USB3_Port6: {HAL_GPIO_WritePin(USB3_VBUS_CTL_6_GPIO_Port, USB3_VBUS_CTL_6_Pin, en); }break; //device: Specified device
case SOC_USB2_HUB: {HAL_GPIO_WritePin(SOC_U2_HUB_PWR_CTL_GPIO_Port,SOC_U2_HUB_PWR_CTL_Pin, en); }break; //en: enable or disable
case SOC_USB3_HUB: {HAL_GPIO_WritePin(SOC_U3_HUB_PWR_CTL_GPIO_Port,SOC_U3_HUB_PWR_CTL_Pin, en); }break; //delay: After executing the operation delay (ms)
case SOC_USB3_HOST: {HAL_GPIO_WritePin(SOC_U3_HOST_PWR_CTL_GPIO_Port,SOC_U3_HOST_PWR_CTL_Pin, en); }break; //return: true-success;false-parameter valid
case SOC_USB3_GEC: {HAL_GPIO_WritePin(SOC_U3_GEC_PWR_CTL_GPIO_Port,SOC_U3_GEC_PWR_CTL_Pin, en); }break; bool PWR_Enable_IRQ(enum Device_t device,bool en,uint16_t delay){
case SOC_GE_SW: {HAL_GPIO_WritePin(SOC_GE_SW_PWR_CTL_GPIO_Port, SOC_GE_SW_PWR_CTL_Pin, en); }break; switch (device){
case SYS_FAN1: {HAL_GPIO_WritePin(SYS_FAN_CTL_1_GPIO_Port, SYS_FAN_CTL_1_Pin, en); }break; case USB2_Port1: {HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port, USB2_VBUS_CTL_1_Pin, en); }break;
case SYS_FAN2: {HAL_GPIO_WritePin(SYS_FAN_CTL_2_GPIO_Port, SYS_FAN_CTL_2_Pin, en); }break; case USB2_Port2: {HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port, USB2_VBUS_CTL_2_Pin, en); }break;
case SYS_FAN3: {HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port, SYS_FAN_CTL_3_Pin, en); }break; case USB2_Port3: {HAL_GPIO_WritePin(USB2_VBUS_CTL_3_GPIO_Port, USB2_VBUS_CTL_3_Pin, en); }break;
case SYS_RUN_LED: {HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port, SYS_RUN_LED_CTL_Pin, !en); }break; case USB2_Port4: {HAL_GPIO_WritePin(USB2_VBUS_CTL_4_GPIO_Port, USB2_VBUS_CTL_4_Pin, en); }break;
case SYS_PWR_LED: {HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port, SYS_POWER_LED_CTL_Pin, !en); }break; case USB2_Port5: {HAL_GPIO_WritePin(USB2_VBUS_CTL_5_GPIO_Port, USB2_VBUS_CTL_5_Pin, en); }break;
case SOM_PWR_EN: {HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port, SOM_POWER_EN_Pin, en); }break; case USB2_Port6: {HAL_GPIO_WritePin(USB2_VBUS_CTL_6_GPIO_Port, USB2_VBUS_CTL_6_Pin, en); }break;
case SOM_DFU: {HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port,SOM_FORCE_RECOVERY_Pin, !en); }break; case USB3_Port1: {HAL_GPIO_WritePin(USB3_VBUS_CTL_1_GPIO_Port, USB3_VBUS_CTL_1_Pin, en); }break;
case SOM_RESET: {HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port, SOM_SYS_RESET_Pin, !en); }break; case USB3_Port2: {HAL_GPIO_WritePin(USB3_VBUS_CTL_2_GPIO_Port, USB3_VBUS_CTL_2_Pin, en); }break;
case SOM_SLEEP: {HAL_GPIO_WritePin(SOM_SLEEP_WAKE_GPIO_Port, SOM_SLEEP_WAKE_Pin, !en); }break; case USB3_Port3: {HAL_GPIO_WritePin(USB3_VBUS_CTL_3_GPIO_Port, USB3_VBUS_CTL_3_Pin, en); }break;
case PMB_PS_ON: {HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port, PMB_PS_ON_Pin, en); }break; case USB3_Port4: {HAL_GPIO_WritePin(USB3_VBUS_CTL_4_GPIO_Port, USB3_VBUS_CTL_4_Pin, en); }break;
default: {log_e("PWR_Enable device parameter is invalid."); }break; case USB3_Port5: {HAL_GPIO_WritePin(USB3_VBUS_CTL_5_GPIO_Port, USB3_VBUS_CTL_5_Pin, en); }break;
case USB3_Port6: {HAL_GPIO_WritePin(USB3_VBUS_CTL_6_GPIO_Port, USB3_VBUS_CTL_6_Pin, en); }break;
case SOC_USB2_HUB: {HAL_GPIO_WritePin(SOC_U2_HUB_PWR_CTL_GPIO_Port,SOC_U2_HUB_PWR_CTL_Pin, en); }break;
case SOC_USB3_HUB: {HAL_GPIO_WritePin(SOC_U3_HUB_PWR_CTL_GPIO_Port,SOC_U3_HUB_PWR_CTL_Pin, en); }break;
case SOC_USB3_HOST: {HAL_GPIO_WritePin(SOC_U3_HOST_PWR_CTL_GPIO_Port,SOC_U3_HOST_PWR_CTL_Pin, en); }break;
case SOC_USB3_GEC: {HAL_GPIO_WritePin(SOC_U3_GEC_PWR_CTL_GPIO_Port,SOC_U3_GEC_PWR_CTL_Pin, en); }break;
case SOC_GE_SW: {HAL_GPIO_WritePin(SOC_GE_SW_PWR_CTL_GPIO_Port, SOC_GE_SW_PWR_CTL_Pin, en); }break;
case SYS_FAN1: {HAL_GPIO_WritePin(SYS_FAN_CTL_1_GPIO_Port, SYS_FAN_CTL_1_Pin, en); }break;
case SYS_FAN2: {HAL_GPIO_WritePin(SYS_FAN_CTL_2_GPIO_Port, SYS_FAN_CTL_2_Pin, en); }break;
case SYS_FAN3: {HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port, SYS_FAN_CTL_3_Pin, en); }break;
case SYS_RUN_LED: {HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port, SYS_RUN_LED_CTL_Pin, !en); }break;
case SYS_PWR_LED: {HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port, SYS_POWER_LED_CTL_Pin, !en); }break;
case SOM_PWR_EN: {HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port, SOM_POWER_EN_Pin, en); }break;
case SOM_DFU: {HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port,SOM_FORCE_RECOVERY_Pin, !en); }break;
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: {return false; }break;
} }
log_v("Device 0x%X has been %s",device,en ? "enabled" : "disabled");
osDelay(delay); osDelay(delay);
return true;
} }
//check device on board power status //check device on board power status

View File

@ -269,6 +269,14 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
} }
/* USER CODE BEGIN 1 */ /* 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 //printf redirect
#ifdef __GNUC__ #ifdef __GNUC__

@ -1 +1 @@
Subproject commit a813ff549eeec5fa41af5604770092e62ab504fc Subproject commit 69ca6cd42c7370db783c8df9943fc44bc3761574

View File

@ -47,6 +47,7 @@
* 串口输出口波特率为56000bps * 串口输出口波特率为56000bps
* 日志输出支持`CSI`颜色模式 * 日志输出支持`CSI`颜色模式
* 由于`elog`中使用了操作系统的信号量对临界资源(日志缓冲区)进行读写保护,所以只能在任务中调用日志接口,请勿在中断中调用日志接口。
# 勘误 # 勘误
硬件的v1.0以前版本中SYS_RESET脚和MOD_SLEEP到单片机的实际连接与网络标号是相反的问题发生在TXB0108PWR芯片附近故代码中在GPIO处进行了相反的设置。 硬件的v1.0以前版本中SYS_RESET脚和MOD_SLEEP到单片机的实际连接与网络标号是相反的问题发生在TXB0108PWR芯片附近故代码中在GPIO处进行了相反的设置。