master
ThinkPad-T460P 2020-09-02 18:45:43 +08:00
parent 1845408b14
commit 178b3e001f
4 changed files with 61 additions and 53 deletions

View File

@ -22,7 +22,7 @@ typedef struct
struct{ struct{
enum { enum {
shutdown, //only mcu runing shutdown, //only mcu runing
runing, //all function runing running, //all function runing
sleep, //SOCs and FANs are stop sleep, //SOCs and FANs are stop
dfu, //device firmware update for SOM dfu, //device firmware update for SOM
isp //in system program for BIOS isp //in system program for BIOS

View File

@ -157,7 +157,7 @@ void MX_FREERTOS_Init(void) {
/* Create the queue(s) */ /* Create the queue(s) */
/* creation of uartQueue */ /* creation of uartQueue */
uartQueueHandle = osMessageQueueNew (128, sizeof(uint8_t), &uartQueue_attributes); uartQueueHandle = osMessageQueueNew (1024, sizeof(uint8_t), &uartQueue_attributes);
/* USER CODE BEGIN RTOS_QUEUES */ /* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */ /* add queues, ... */
@ -207,24 +207,28 @@ void StartDefaultTask(void *argument)
/* init code for USB_DEVICE */ /* init code for USB_DEVICE */
MX_USB_DEVICE_Init(); MX_USB_DEVICE_Init();
/* USER CODE BEGIN StartDefaultTask */ /* USER CODE BEGIN StartDefaultTask */
uint8_t count,temp[256];
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);
Beep(50); Beep(50);
printf("\nCore initial successfully\n");
printf("---------------------------------------------\n");
printf("Copyright (c) Powered by www.autolabor.com.cn\n");
osDelay(100);
printf("BIOS SW Version: V0.9, build: %s, %s\n",__DATE__ ,__TIME__ );
printf("HAL Version: %d \n", HAL_GetHalVersion());
printf("Revision ID: %d \n", HAL_GetREVID());
printf("Device ID: %d \n", HAL_GetDEVID());
osDelay(100);
printf("Chip UID: %d%d%d \n", HAL_GetUIDw0(),HAL_GetUIDw1(),HAL_GetUIDw2);
printf("----------------------------------------------\n");
/* Infinite loop */ /* Infinite loop */
for(;;) for(;;)
{ {
osDelay(100); osDelay(100);
// count = osMessageQueueGetCount(uartQueueHandle);
// if(count){ // printf("Time:[%f s]; OUT_24:[%f V]; OUT_5:[%f V]; OUT_12:[%f V]; BKP_BAT:[%f V]; MAIN_PWR:[%f V]\n",(float)(osKernelGetTickCount()/1000.0),NaviKit.pmb.rails.out_24v,NaviKit.pmb.rails.out_5v,NaviKit.pmb.rails.out_12v,NaviKit.pmb.rails.bkp_bat,NaviKit.pmb.rails.main_pwr);
// for(uint8_t i=0;i<count;i++){
// osMessageQueueGet(uartQueueHandle,&temp[i],0,10);
// }
// HAL_UART_Transmit(&huart1,(uint8_t *)&temp,count,0xffff);
// }
// printf("test");
// printf("Time:[%f s]; OUT_24:[%f V]; OUT_5:[%f V]; OUT_12:[%f V]; BKP_BAT:[%f V]; MAIN_PWR:[%f V]\n",(float)(osKernelGetTickCount()/1000.0),NaviKit.pmb.rails.out_24v,NaviKit.pmb.rails.out_5v,NaviKit.pmb.rails.out_12v,NaviKit.pmb.rails.bkp_bat,NaviKit.pmb.rails.main_pwr);
} }
/* USER CODE END StartDefaultTask */ /* USER CODE END StartDefaultTask */
@ -244,7 +248,7 @@ void StartLedBlinkTask(void *argument)
for(;;) for(;;)
{ {
switch(NaviKit.sys.sta){ switch(NaviKit.sys.sta){
case runing: case running:
{ {
if(HAL_GPIO_ReadPin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin)) if(HAL_GPIO_ReadPin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin))
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_RESET);//turn on power led HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_RESET);//turn on power led
@ -375,17 +379,17 @@ void StartEventDetect(void *argument)
{//power btn has been pushed more than 1000 ms {//power btn has been pushed more than 1000 ms
// while(NaviKit.sys.power_btn == true);//wait to release button // while(NaviKit.sys.power_btn == true);//wait to release button
switch(NaviKit.sys.sta){ switch(NaviKit.sys.sta){
case runing:{//system is runing now, user request to shutdown case running:{//system is running now, user request to shutdown
NaviKit.sys.next_sta = shutdown; NaviKit.sys.next_sta = shutdown;
}break; }break;
case shutdown:{//system is shutdown now , user request to power on case shutdown:{//system is shutdown now , user request to power on
NaviKit.sys.next_sta = runing; NaviKit.sys.next_sta = running;
}break; }break;
case dfu:{ case dfu:{
NaviKit.sys.next_sta = shutdown; NaviKit.sys.next_sta = shutdown;
}break; }break;
case sleep:{ case sleep:{
NaviKit.sys.next_sta = runing; NaviKit.sys.next_sta = running;
}break; }break;
} }
} }
@ -447,7 +451,7 @@ void StartCoulombRead(void *argument)
{ {
coulomb_read_status_and_config(); coulomb_read_status_and_config();
coulomb_read_status_raw_to_actual(); coulomb_read_status_raw_to_actual();
if(NaviKit.sys.sta == runing) if(NaviKit.sys.sta == running)
osDelay(500); osDelay(500);
else else
osDelay(5000); osDelay(5000);
@ -474,17 +478,17 @@ void StartStateSwitchTask(void *argument)
switch(NaviKit.sys.next_sta) switch(NaviKit.sys.next_sta)
{ {
case shutdown: case shutdown:
{//only from runing state {//only from running state
if(NaviKit.sys.sta == runing) if(NaviKit.sys.sta == running)
enter_shutdown_state(); enter_shutdown_state();
}break; }break;
case runing: case running:
{//from sleep and shutdown state {//from sleep and shutdown state
enter_runing_state(); enter_runing_state();
}break; }break;
case sleep: case sleep:
{//only form runing state {//only form running state
if(NaviKit.sys.sta == runing) if(NaviKit.sys.sta == running)
enter_sleep_state(); enter_sleep_state();
}break; }break;
@ -525,20 +529,6 @@ void StartPowerMonitTask(void *argument)
// printf("bkp_bat: %f \n",NaviKit.pmb.bkp_bat_div8); // printf("bkp_bat: %f \n",NaviKit.pmb.bkp_bat_div8);
// printf("main_pwr: %f \n",NaviKit.pmb.main_pwr_div16); // printf("main_pwr: %f \n",NaviKit.pmb.main_pwr_div16);
// //module request to stop
// if(HAL_GPIO_ReadPin(SOM_SHUTDOWN_REQ_GPIO_Port,SOM_SHUTDOWN_REQ_Pin) == GPIO_PIN_SET)
// {
// //1.the last step of normal power off process
// //2.Thermal shutdown
// //3.vdd_in's wave more than 5% of 5.0V
//
//
// HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port,SOM_POWER_EN_Pin,GPIO_PIN_RESET);
// }
} }
/* USER CODE END StartPowerMonitTask */ /* USER CODE END StartPowerMonitTask */
} }
@ -553,10 +543,26 @@ void StartPowerMonitTask(void *argument)
void StartUartQueueTask(void *argument) void StartUartQueueTask(void *argument)
{ {
/* USER CODE BEGIN StartUartQueueTask */ /* USER CODE BEGIN StartUartQueueTask */
uint8_t count,temp[256];
// osMessageQueuePut(uartQueueHandle,"t",0,100);
// osMessageQueuePut(uartQueueHandle,"e",0,100);
// osMessageQueuePut(uartQueueHandle,"s",0,100);
// osMessageQueuePut(uartQueueHandle,"t",0,100);
/* Infinite loop */ /* Infinite loop */
for(;;) for(;;)
{ {
osDelay(1); osDelay(1);
count = osMessageQueueGetCount(uartQueueHandle);
if(count){
for(uint8_t i=0;i<count;i++){
osMessageQueueGet(uartQueueHandle,&temp[i],0,10);
}
// taskENTER_CRITICAL();
while(HAL_UART_GetState(&huart1) == HAL_UART_STATE_BUSY_TX){}
HAL_UART_Transmit(&huart1,(uint8_t *)&temp,count,0xffff);
// taskEXIT_CRITICAL();
}
} }
/* USER CODE END StartUartQueueTask */ /* USER CODE END StartUartQueueTask */
} }
@ -565,20 +571,31 @@ void StartUartQueueTask(void *argument)
/* USER CODE BEGIN Application */ /* USER CODE BEGIN Application */
//printf redefine //printf redefine
#ifdef __GNUC__ #ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
PUTCHAR_PROTOTYPE PUTCHAR_PROTOTYPE
{ {
while(HAL_UART_GetState(&huart1) == HAL_UART_STATE_BUSY_TX){} // while(HAL_UART_GetState(&huart1) == HAL_UART_STATE_BUSY_TX){}
HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,0xffff); // HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,0xffff);
// osMessageQueuePut(uartQueueHandle,(uint8_t *)&ch,0,100); //queue space check before enqueue
if(osMessageQueueGetSpace(uartQueueHandle)>0){
osMessageQueuePut(uartQueueHandle,(uint8_t*)&ch,0,100);
}
else{
// uint8_t front[1];//trash
// osMessageQueueGet(uartQueueHandle,front,0,10);
// osMessageQueuePut(uartQueueHandle,(uint8_t *)&ch,0,100);
}
return ch; return ch;
} }
#endif
/* USER CODE END Application */ /* USER CODE END Application */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -108,16 +108,7 @@ int main(void)
/* Initialize interrupts */ /* Initialize interrupts */
MX_NVIC_Init(); MX_NVIC_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
//HAL_IWDG_Refresh(&hiwdg);
printf("\nCore initial successfully\n");
printf("---------------------------------------------\n");
printf("Copyright (c) Powered by www.autolabor.com.cn\n");
printf("BIOS SW Version: V0.9, build: %s %s\n",__DATE__ ,__TIME__ );
printf("HAL Version: %d \n", HAL_GetHalVersion());
printf("Revision ID: %d \n", HAL_GetREVID());
printf("Device ID: %d \n", HAL_GetDEVID());
printf("Chip UID: %d%d%d \n", HAL_GetUIDw0(),HAL_GetUIDw1(),HAL_GetUIDw2);
printf("----------------------------------------------\n");
/* USER CODE END 2 */ /* USER CODE END 2 */
/* Init scheduler */ /* Init scheduler */
@ -231,7 +222,7 @@ static void MX_NVIC_Init(void)
/* USER CODE BEGIN 4 */ /* USER CODE BEGIN 4 */
void ISP_Judge() void ISP_Judge()
{ {//Judge that if need jump to ISP area
RTC_HandleTypeDef hrtc; RTC_HandleTypeDef hrtc;
hrtc.Instance = RTC; hrtc.Instance = RTC;
if(HAL_RTCEx_BKUPRead(&hrtc,RTC_BKP_DR1) == 0x32f2) if(HAL_RTCEx_BKUPRead(&hrtc,RTC_BKP_DR1) == 0x32f2)

View File

@ -60,7 +60,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
if(HAL_GPIO_ReadPin(SOM_SHUTDOWN_REQ_GPIO_Port, SOM_SHUTDOWN_REQ_Pin)==GPIO_PIN_RESET) if(HAL_GPIO_ReadPin(SOM_SHUTDOWN_REQ_GPIO_Port, SOM_SHUTDOWN_REQ_Pin)==GPIO_PIN_RESET)
{//falling edge trigger {//falling edge trigger
// NaviKit.som.shutdown_req = false; // NaviKit.som.shutdown_req = false;
if(NaviKit.sys.sta == runing) if(NaviKit.sys.sta == running)
{ {
NaviKit.sys.next_sta = shutdown; NaviKit.sys.next_sta = shutdown;
} }