603 lines
20 KiB
C
603 lines
20 KiB
C
/* USER CODE BEGIN Header */
|
||
/**
|
||
******************************************************************************
|
||
* File Name : freertos.c
|
||
* Description : Code for freertos applications
|
||
******************************************************************************
|
||
* @attention
|
||
*
|
||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||
* All rights reserved.</center></h2>
|
||
*
|
||
* This software component is licensed by ST under Ultimate Liberty license
|
||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||
* the License. You may obtain a copy of the License at:
|
||
* www.st.com/SLA0044
|
||
*
|
||
******************************************************************************
|
||
*/
|
||
/* USER CODE END Header */
|
||
|
||
/* Includes ------------------------------------------------------------------*/
|
||
#include "FreeRTOS.h"
|
||
#include "task.h"
|
||
#include "main.h"
|
||
#include "cmsis_os.h"
|
||
|
||
/* Private includes ----------------------------------------------------------*/
|
||
/* USER CODE BEGIN Includes */
|
||
#include "iwdg.h"
|
||
#include "gpio.h"
|
||
#include "usart.h"
|
||
#include "stdio.h"
|
||
#include "navikit.h"
|
||
#include "coulomb.h"
|
||
#include "stdbool.h"
|
||
/* USER CODE END Includes */
|
||
|
||
/* Private typedef -----------------------------------------------------------*/
|
||
/* USER CODE BEGIN PTD */
|
||
|
||
/* USER CODE END PTD */
|
||
|
||
/* Private define ------------------------------------------------------------*/
|
||
/* USER CODE BEGIN PD */
|
||
|
||
/* USER CODE END PD */
|
||
|
||
/* Private macro -------------------------------------------------------------*/
|
||
/* USER CODE BEGIN PM */
|
||
|
||
/* USER CODE END PM */
|
||
|
||
/* Private variables ---------------------------------------------------------*/
|
||
/* USER CODE BEGIN Variables */
|
||
|
||
/* USER CODE END Variables */
|
||
/* Definitions for defaultTask */
|
||
osThreadId_t defaultTaskHandle;
|
||
const osThreadAttr_t defaultTask_attributes = {
|
||
.name = "defaultTask",
|
||
.priority = (osPriority_t) osPriorityNormal,
|
||
.stack_size = 128 * 4
|
||
};
|
||
/* Definitions for LedBlinkTask */
|
||
osThreadId_t LedBlinkTaskHandle;
|
||
const osThreadAttr_t LedBlinkTask_attributes = {
|
||
.name = "LedBlinkTask",
|
||
.priority = (osPriority_t) osPriorityLow,
|
||
.stack_size = 128 * 4
|
||
};
|
||
/* Definitions for IWDGRefreshTask */
|
||
osThreadId_t IWDGRefreshTaskHandle;
|
||
const osThreadAttr_t IWDGRefreshTask_attributes = {
|
||
.name = "IWDGRefreshTask",
|
||
.priority = (osPriority_t) osPriorityHigh,
|
||
.stack_size = 128 * 4
|
||
};
|
||
/* Definitions for ButtonDetect */
|
||
osThreadId_t ButtonDetectHandle;
|
||
const osThreadAttr_t ButtonDetect_attributes = {
|
||
.name = "ButtonDetect",
|
||
.priority = (osPriority_t) osPriorityLow,
|
||
.stack_size = 128 * 4
|
||
};
|
||
/* Definitions for CoulombRead */
|
||
osThreadId_t CoulombReadHandle;
|
||
const osThreadAttr_t CoulombRead_attributes = {
|
||
.name = "CoulombRead",
|
||
.priority = (osPriority_t) osPriorityLow,
|
||
.stack_size = 128 * 4
|
||
};
|
||
/* Definitions for StateSwitchTask */
|
||
osThreadId_t StateSwitchTaskHandle;
|
||
const osThreadAttr_t StateSwitchTask_attributes = {
|
||
.name = "StateSwitchTask",
|
||
.priority = (osPriority_t) osPriorityLow,
|
||
.stack_size = 128 * 4
|
||
};
|
||
/* Definitions for SOMPowerManageTask */
|
||
osThreadId_t SOMPowerManageTaskHandle;
|
||
const osThreadAttr_t SOMPowerManageTask_attributes = {
|
||
.name = "SOMPowerManageTask",
|
||
.priority = (osPriority_t) osPriorityLow,
|
||
.stack_size = 128 * 4
|
||
};
|
||
|
||
/* Private function prototypes -----------------------------------------------*/
|
||
/* USER CODE BEGIN FunctionPrototypes */
|
||
/* USER CODE END FunctionPrototypes */
|
||
|
||
void StartDefaultTask(void *argument);
|
||
void StartLedBlinkTask(void *argument);
|
||
void StartIWDGRefreshTask(void *argument);
|
||
void StartButtonDetect(void *argument);
|
||
void StartCoulombRead(void *argument);
|
||
void StartStateSwitchTask(void *argument);
|
||
void StartSOMPowerManageTask(void *argument);
|
||
|
||
extern void MX_USB_DEVICE_Init(void);
|
||
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
||
|
||
/**
|
||
* @brief FreeRTOS initialization
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
void MX_FREERTOS_Init(void) {
|
||
/* USER CODE BEGIN Init */
|
||
|
||
/* USER CODE END Init */
|
||
|
||
/* USER CODE BEGIN RTOS_MUTEX */
|
||
/* add mutexes, ... */
|
||
/* USER CODE END RTOS_MUTEX */
|
||
|
||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||
/* add semaphores, ... */
|
||
/* USER CODE END RTOS_SEMAPHORES */
|
||
|
||
/* USER CODE BEGIN RTOS_TIMERS */
|
||
/* start timers, add new ones, ... */
|
||
/* USER CODE END RTOS_TIMERS */
|
||
|
||
/* USER CODE BEGIN RTOS_QUEUES */
|
||
/* add queues, ... */
|
||
/* USER CODE END RTOS_QUEUES */
|
||
|
||
/* Create the thread(s) */
|
||
/* creation of defaultTask */
|
||
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
||
|
||
/* creation of LedBlinkTask */
|
||
LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes);
|
||
|
||
/* creation of IWDGRefreshTask */
|
||
IWDGRefreshTaskHandle = osThreadNew(StartIWDGRefreshTask, NULL, &IWDGRefreshTask_attributes);
|
||
|
||
/* creation of ButtonDetect */
|
||
ButtonDetectHandle = osThreadNew(StartButtonDetect, NULL, &ButtonDetect_attributes);
|
||
|
||
/* creation of CoulombRead */
|
||
CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes);
|
||
|
||
/* creation of StateSwitchTask */
|
||
StateSwitchTaskHandle = osThreadNew(StartStateSwitchTask, NULL, &StateSwitchTask_attributes);
|
||
|
||
/* creation of SOMPowerManageTask */
|
||
SOMPowerManageTaskHandle = osThreadNew(StartSOMPowerManageTask, NULL, &SOMPowerManageTask_attributes);
|
||
|
||
/* USER CODE BEGIN RTOS_THREADS */
|
||
/* add threads, ... */
|
||
|
||
/* USER CODE END RTOS_THREADS */
|
||
|
||
}
|
||
|
||
/* USER CODE BEGIN Header_StartDefaultTask */
|
||
/**
|
||
* @brief Function implementing the defaultTask thread.
|
||
* @param argument: Not used
|
||
* @retval None
|
||
*/
|
||
/* USER CODE END Header_StartDefaultTask */
|
||
void StartDefaultTask(void *argument)
|
||
{
|
||
/* init code for USB_DEVICE */
|
||
MX_USB_DEVICE_Init();
|
||
/* USER CODE BEGIN StartDefaultTask */
|
||
|
||
NaviKit_var_init();
|
||
HAL_GPIO_WritePin(USB2_FS_ENUM_CTL_GPIO_Port,USB2_FS_ENUM_CTL_Pin, GPIO_PIN_SET);
|
||
Beep(50);
|
||
/* Infinite loop */
|
||
for(;;)
|
||
{
|
||
osDelay(1000);
|
||
printf("[%f]\n",(float)(osKernelGetTickCount()/1000.0));
|
||
}
|
||
/* USER CODE END StartDefaultTask */
|
||
}
|
||
|
||
/* USER CODE BEGIN Header_StartLedBlinkTask */
|
||
/**
|
||
* @brief Function implementing the LedBlinkTask thread.
|
||
* @param argument: Not used
|
||
* @retval None
|
||
*/
|
||
/* USER CODE END Header_StartLedBlinkTask */
|
||
void StartLedBlinkTask(void *argument)
|
||
{
|
||
/* USER CODE BEGIN StartLedBlinkTask */
|
||
/* Infinite loop */
|
||
for(;;)
|
||
{
|
||
|
||
if(NaviKit.sys.sta == runing)
|
||
{
|
||
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
|
||
|
||
if(HAL_GPIO_ReadPin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin) == GPIO_PIN_SET)//sys run led is off
|
||
{
|
||
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_RESET);//turn on sys run led
|
||
osDelay(50);
|
||
}
|
||
else
|
||
{
|
||
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_SET);//turn off sys run led
|
||
osDelay(300);
|
||
}
|
||
}
|
||
else if(NaviKit.sys.sta == shutdown)
|
||
{
|
||
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_SET);//turn off power led
|
||
|
||
|
||
if(HAL_GPIO_ReadPin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin) == GPIO_PIN_SET)//sys run led is off
|
||
{
|
||
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_RESET);//turn on sys run led
|
||
osDelay(20);
|
||
}
|
||
else
|
||
{
|
||
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_SET);//turn off sys run led
|
||
osDelay(2000);
|
||
}
|
||
}
|
||
else if(NaviKit.sys.sta == sleep)
|
||
{
|
||
for(uint16_t i=0;i<20;i++)
|
||
{//20 light level
|
||
for(uint16_t j=0;j<4;j++)
|
||
{//the time length of every light level
|
||
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_SET);
|
||
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_SET);
|
||
osDelay(i);
|
||
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_RESET);
|
||
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_RESET);
|
||
osDelay(20-i);
|
||
}
|
||
}
|
||
for(uint16_t i=0;i<20;i++)
|
||
{
|
||
for(uint16_t j=0;j<4;j++)
|
||
{
|
||
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_SET);
|
||
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_SET);
|
||
osDelay(20-i);
|
||
HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin,GPIO_PIN_RESET);
|
||
HAL_GPIO_WritePin(SYS_RUN_LED_CTL_GPIO_Port,SYS_RUN_LED_CTL_Pin,GPIO_PIN_RESET);
|
||
osDelay(i);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
/* USER CODE END StartLedBlinkTask */
|
||
}
|
||
|
||
/* USER CODE BEGIN Header_StartIWDGRefreshTask */
|
||
/**
|
||
* @brief Function implementing the IWDGRefreshTask thread.
|
||
* @param argument: Not used
|
||
* @retval None
|
||
*/
|
||
/* USER CODE END Header_StartIWDGRefreshTask */
|
||
void StartIWDGRefreshTask(void *argument)
|
||
{
|
||
/* USER CODE BEGIN StartIWDGRefreshTask */
|
||
/* Infinite loop */
|
||
for(;;)
|
||
{
|
||
HAL_IWDG_Refresh(&hiwdg);
|
||
// printf("2\n");
|
||
osDelay(1000);
|
||
}
|
||
/* USER CODE END StartIWDGRefreshTask */
|
||
}
|
||
|
||
/* USER CODE BEGIN Header_StartButtonDetect */
|
||
/**
|
||
* @brief Function implementing the ButtonDetect thread.
|
||
* @param argument: Not used
|
||
* @retval None
|
||
*/
|
||
/* USER CODE END Header_StartButtonDetect */
|
||
void StartButtonDetect(void *argument)
|
||
{
|
||
/* USER CODE BEGIN StartButtonDetect */
|
||
|
||
/* Infinite loop */
|
||
for(;;)
|
||
{
|
||
//长按<E995BF>???????<3F>???????
|
||
if(NaviKit.sys.power_btn == true)
|
||
{//power btn has been pushed
|
||
osDelay(2000);
|
||
if(NaviKit.sys.power_btn == true)
|
||
{//power btn has been pushed more than 2000 ms
|
||
if(NaviKit.sys.sta == runing)
|
||
{//system is runing now, user request to shutdown
|
||
enter_shutdown_state();
|
||
printf("shutdown \n");
|
||
Beep(50);
|
||
|
||
|
||
}
|
||
else if(NaviKit.sys.sta == shutdown)
|
||
{//system is shutdown now , user request to power on
|
||
enter_runing_state();
|
||
printf("power on \n");
|
||
Beep(200);
|
||
osDelay(500);
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(NaviKit.sys.sta == runing)
|
||
{
|
||
enter_sleep_state();
|
||
}
|
||
else if(NaviKit.sys.sta == sleep)
|
||
{
|
||
enter_runing_state();
|
||
}
|
||
|
||
}
|
||
}
|
||
if(NaviKit.sys.custom_btn == true )
|
||
{//custom button has been pushed
|
||
osDelay(2000);
|
||
if(NaviKit.sys.custom_btn == true )
|
||
{//custom button has been pushed over 2000 ms
|
||
if(NaviKit.sys.sta == runing)
|
||
{
|
||
// restart();
|
||
}
|
||
}
|
||
}
|
||
|
||
osDelay(10);
|
||
}
|
||
/* USER CODE END StartButtonDetect */
|
||
}
|
||
|
||
/* USER CODE BEGIN Header_StartCoulombRead */
|
||
/**
|
||
* @brief Function implementing the CoulombRead thread.
|
||
* @param argument: Not used
|
||
* @retval None
|
||
*/
|
||
/* USER CODE END Header_StartCoulombRead */
|
||
void StartCoulombRead(void *argument)
|
||
{
|
||
/* USER CODE BEGIN StartCoulombRead */
|
||
//写寄存器方法
|
||
coulomb_write_config_load();
|
||
coulomb_write_config_actual_to_raw();
|
||
coulomb_write_config();
|
||
//读寄存器方法
|
||
coulomb_read_status_and_config();
|
||
coulomb_read_status_raw_to_actual();
|
||
coulomb_read_config_raw_to_actual();
|
||
|
||
/* Infinite loop */
|
||
for(;;)
|
||
{
|
||
coulomb_read_status_and_config();
|
||
coulomb_read_status_raw_to_actual();
|
||
if(NaviKit.sys.sta)
|
||
osDelay(500);
|
||
else
|
||
osDelay(5000);
|
||
}
|
||
/* USER CODE END StartCoulombRead */
|
||
}
|
||
|
||
/* USER CODE BEGIN Header_StartStateSwitchTask */
|
||
/**
|
||
* @brief Function implementing the StateSwitchTask thread.
|
||
* @param argument: Not used
|
||
* @retval None
|
||
*/
|
||
/* USER CODE END Header_StartStateSwitchTask */
|
||
void StartStateSwitchTask(void *argument)
|
||
{
|
||
/* USER CODE BEGIN StartStateSwitchTask */
|
||
/* Infinite loop */
|
||
for(;;)
|
||
{
|
||
if(NaviKit.sys.last_sta != NaviKit.sys.sta)
|
||
switch(NaviKit.sys.sta)
|
||
{
|
||
case shutdown:
|
||
{
|
||
|
||
}break;
|
||
case runing:
|
||
{
|
||
|
||
}break;
|
||
case sleep:
|
||
{
|
||
|
||
}break;
|
||
}
|
||
osDelay(10);
|
||
}
|
||
/* USER CODE END StartStateSwitchTask */
|
||
}
|
||
|
||
/* USER CODE BEGIN Header_StartSOMPowerManageTask */
|
||
/**
|
||
* @brief Function implementing the SOMPowerManageTask thread.
|
||
* @param argument: Not used
|
||
* @retval None
|
||
*/
|
||
/* USER CODE END Header_StartSOMPowerManageTask */
|
||
void StartSOMPowerManageTask(void *argument)
|
||
{
|
||
/* USER CODE BEGIN StartSOMPowerManageTask */
|
||
/* Infinite loop */
|
||
for(;;)
|
||
{
|
||
osDelay(1);
|
||
}
|
||
/* USER CODE END StartSOMPowerManageTask */
|
||
}
|
||
|
||
/* Private application code --------------------------------------------------*/
|
||
/* USER CODE BEGIN Application */
|
||
void sys_start()
|
||
{
|
||
|
||
|
||
}
|
||
//power off by button pushed
|
||
void force_sys_stop()
|
||
{
|
||
|
||
|
||
Beep(40);
|
||
}
|
||
|
||
//module request to stop
|
||
void sys_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);
|
||
}
|
||
}
|
||
|
||
|
||
void enter_shutdown_state()
|
||
{
|
||
HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port ,SOM_POWER_EN_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
|
||
for(uint8_t i=0;i<100;i++)
|
||
{
|
||
if(HAL_GPIO_ReadPin(SOM_SHUTDOWN_REQ_GPIO_Port,SOM_SHUTDOWN_REQ_Pin))
|
||
osDelay(10);
|
||
}
|
||
|
||
HAL_GPIO_WritePin(SOC_U3_HUB_PWR_CTL_GPIO_Port,SOC_U3_HUB_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(SOC_U2_HUB_PWR_CTL_GPIO_Port,SOC_U2_HUB_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(SOC_U3_HOST_PWR_CTL_GPIO_Port,SOC_U3_HOST_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(SOC_GE_SW_PWR_CTL_GPIO_Port,SOC_GE_SW_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(SOC_U3_GEC_PWR_CTL_GPIO_Port,SOC_U3_GEC_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
|
||
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_4_GPIO_Port,USB3_VBUS_CTL_4_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_3_GPIO_Port,USB3_VBUS_CTL_3_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_2_GPIO_Port,USB3_VBUS_CTL_2_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_1_GPIO_Port,USB3_VBUS_CTL_1_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_6_GPIO_Port,USB3_VBUS_CTL_6_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_5_GPIO_Port,USB3_VBUS_CTL_5_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_6_GPIO_Port,USB2_VBUS_CTL_6_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_5_GPIO_Port,USB2_VBUS_CTL_5_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_4_GPIO_Port,USB2_VBUS_CTL_4_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_3_GPIO_Port,USB2_VBUS_CTL_3_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port,USB2_VBUS_CTL_2_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port,USB2_VBUS_CTL_1_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
|
||
HAL_GPIO_WritePin(SYS_FAN_CTL_1_GPIO_Port,SYS_FAN_CTL_1_Pin,GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(SYS_FAN_CTL_2_GPIO_Port,SYS_FAN_CTL_2_Pin,GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port,SYS_FAN_CTL_3_Pin,GPIO_PIN_RESET); osDelay(100);
|
||
|
||
HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port ,PMB_PS_ON_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
|
||
NaviKit.sys.sta = shutdown;
|
||
}
|
||
void enter_sleep_state()
|
||
{
|
||
|
||
|
||
// HAL_GPIO_WritePin(SOC_U3_HUB_PWR_CTL_GPIO_Port,SOC_U3_HUB_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(SOC_U2_HUB_PWR_CTL_GPIO_Port,SOC_U2_HUB_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(SOC_U3_HOST_PWR_CTL_GPIO_Port,SOC_U3_HOST_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(SOC_GE_SW_PWR_CTL_GPIO_Port,SOC_GE_SW_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
// HAL_GPIO_WritePin(SOC_U3_GEC_PWR_CTL_GPIO_Port,SOC_U3_GEC_PWR_CTL_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
|
||
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_4_GPIO_Port,USB3_VBUS_CTL_4_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_3_GPIO_Port,USB3_VBUS_CTL_3_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_2_GPIO_Port,USB3_VBUS_CTL_2_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_1_GPIO_Port,USB3_VBUS_CTL_1_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
// HAL_GPIO_WritePin(USB3_VBUS_CTL_6_GPIO_Port,USB3_VBUS_CTL_6_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
// HAL_GPIO_WritePin(USB3_VBUS_CTL_5_GPIO_Port,USB3_VBUS_CTL_5_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_6_GPIO_Port,USB2_VBUS_CTL_6_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_5_GPIO_Port,USB2_VBUS_CTL_5_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_4_GPIO_Port,USB2_VBUS_CTL_4_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_3_GPIO_Port,USB2_VBUS_CTL_3_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port,USB2_VBUS_CTL_2_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port,USB2_VBUS_CTL_1_Pin, GPIO_PIN_RESET); osDelay(100);
|
||
|
||
HAL_GPIO_WritePin(SYS_FAN_CTL_1_GPIO_Port,SYS_FAN_CTL_1_Pin,GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(SYS_FAN_CTL_2_GPIO_Port,SYS_FAN_CTL_2_Pin,GPIO_PIN_RESET); osDelay(100);
|
||
HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port,SYS_FAN_CTL_3_Pin,GPIO_PIN_RESET); osDelay(100);
|
||
|
||
NaviKit.sys.sta = sleep;
|
||
|
||
}
|
||
void enter_runing_state()
|
||
{
|
||
NaviKit.sys.sta = runing;
|
||
|
||
Beep(40);
|
||
HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port ,PMB_PS_ON_Pin, GPIO_PIN_SET); osDelay(100);
|
||
|
||
HAL_GPIO_WritePin(SYS_FAN_CTL_1_GPIO_Port,SYS_FAN_CTL_1_Pin,GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(SYS_FAN_CTL_2_GPIO_Port,SYS_FAN_CTL_2_Pin,GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(SYS_FAN_CTL_3_GPIO_Port,SYS_FAN_CTL_3_Pin,GPIO_PIN_SET); osDelay(100);
|
||
|
||
HAL_GPIO_WritePin(SOC_U3_HUB_PWR_CTL_GPIO_Port,SOC_U3_HUB_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(SOC_U2_HUB_PWR_CTL_GPIO_Port,SOC_U2_HUB_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(SOC_U3_HOST_PWR_CTL_GPIO_Port,SOC_U3_HOST_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(SOC_GE_SW_PWR_CTL_GPIO_Port,SOC_GE_SW_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(SOC_U3_GEC_PWR_CTL_GPIO_Port,SOC_U3_GEC_PWR_CTL_Pin, GPIO_PIN_SET); osDelay(100);
|
||
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port,USB2_VBUS_CTL_1_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_2_GPIO_Port,USB2_VBUS_CTL_2_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_3_GPIO_Port,USB2_VBUS_CTL_3_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_4_GPIO_Port,USB2_VBUS_CTL_4_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_5_GPIO_Port,USB2_VBUS_CTL_5_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB2_VBUS_CTL_6_GPIO_Port,USB2_VBUS_CTL_6_Pin, GPIO_PIN_SET); osDelay(100);
|
||
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_5_GPIO_Port,USB3_VBUS_CTL_5_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_6_GPIO_Port,USB3_VBUS_CTL_6_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_1_GPIO_Port,USB3_VBUS_CTL_1_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_2_GPIO_Port,USB3_VBUS_CTL_2_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_3_GPIO_Port,USB3_VBUS_CTL_3_Pin, GPIO_PIN_SET); osDelay(100);
|
||
HAL_GPIO_WritePin(USB3_VBUS_CTL_4_GPIO_Port,USB3_VBUS_CTL_4_Pin, GPIO_PIN_SET); osDelay(100);
|
||
|
||
HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port ,SOM_POWER_EN_Pin, GPIO_PIN_SET); osDelay(100);
|
||
|
||
}
|
||
|
||
|
||
|
||
#ifdef __GNUC__
|
||
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
|
||
PUTCHAR_PROTOTYPE
|
||
{
|
||
|
||
while(HAL_UART_GetState(&huart1) == HAL_UART_STATE_BUSY_TX){}
|
||
HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,0xffff);
|
||
return ch;
|
||
}
|
||
#endif
|
||
/* USER CODE END Application */
|
||
|
||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|