2021-01-05 14:46:47 +08:00
|
|
|
/*
|
|
|
|
* @Description:
|
|
|
|
* @Date: 2020-12-16 18:05:14
|
|
|
|
* @LastEditors: CK.Zh
|
|
|
|
* @LastEditTime: 2020-12-25 17:52:50
|
|
|
|
* @FilePath: \NaviKit_stm32\Core\Inc\navikit.h
|
|
|
|
*/
|
2020-04-17 15:55:14 +08:00
|
|
|
/*
|
|
|
|
* navikit.h
|
|
|
|
*
|
|
|
|
* Created on: Apr 17, 2020
|
|
|
|
* Author: oarap
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INC_NAVIKIT_H_
|
|
|
|
#define INC_NAVIKIT_H_
|
|
|
|
|
|
|
|
#include "stdbool.h"
|
2020-08-25 19:33:15 +08:00
|
|
|
#include "stm32f1xx_hal.h"
|
|
|
|
#include "adc.h"
|
|
|
|
#include "gpio.h"
|
2020-12-17 18:22:19 +08:00
|
|
|
#include "log.h"
|
|
|
|
|
2020-08-25 19:33:15 +08:00
|
|
|
|
2020-08-26 18:13:51 +08:00
|
|
|
#define ADC_CH_COUNT 5+2 //number of adc channels (include temp sensor and vrefint adc_in17)
|
2020-04-17 15:55:14 +08:00
|
|
|
|
2020-07-15 18:26:22 +08:00
|
|
|
|
2021-01-05 14:46:47 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
2021-01-06 12:27:08 +08:00
|
|
|
standby, //minimum current state
|
2021-01-05 14:46:47 +08:00
|
|
|
idle, //only mcu runing
|
|
|
|
run, //all function runing
|
|
|
|
sleep, //SOCs and FANs are stop
|
|
|
|
dfu, //device firmware update for SOM
|
|
|
|
isp //in system program for EC
|
|
|
|
}state_t;
|
2020-07-15 18:26:22 +08:00
|
|
|
|
2020-04-17 15:55:14 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2020-07-15 18:26:22 +08:00
|
|
|
struct{
|
2021-01-05 14:46:47 +08:00
|
|
|
state_t sta,next_sta; //power state machine
|
|
|
|
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
|
2020-07-15 18:26:22 +08:00
|
|
|
}sys;
|
|
|
|
struct{
|
|
|
|
bool mod_sleep;
|
|
|
|
bool power_en;
|
|
|
|
bool shutdown_req;
|
|
|
|
bool sys_reset;
|
|
|
|
bool force_recovery;
|
|
|
|
bool sleep_wake;
|
|
|
|
}som;//som power management
|
|
|
|
|
|
|
|
struct{
|
2020-08-26 18:13:51 +08:00
|
|
|
struct{
|
2020-08-25 19:33:15 +08:00
|
|
|
uint32_t adc[ADC_CH_COUNT];
|
2020-08-26 18:13:51 +08:00
|
|
|
float out_24v;//_div16
|
|
|
|
float out_5v;//_div8
|
|
|
|
float out_12v;//_div8
|
|
|
|
float bkp_bat;//_div8
|
|
|
|
float main_pwr;//_div16
|
|
|
|
}rails;//power rails
|
|
|
|
struct{
|
2020-08-25 19:33:15 +08:00
|
|
|
bool temp_sen_en;
|
|
|
|
bool temp_sen_alt;
|
|
|
|
bool coulomb_alcc;
|
|
|
|
bool chrg_stat2;
|
|
|
|
bool chrg_stat1;
|
2020-08-26 18:13:51 +08:00
|
|
|
}sta;
|
|
|
|
struct{
|
|
|
|
float voltage;
|
|
|
|
float current;
|
|
|
|
float cap;
|
|
|
|
float temp;
|
|
|
|
}coulomb;
|
2020-07-15 18:26:22 +08:00
|
|
|
}pmb;//power management board
|
|
|
|
|
2020-08-26 18:13:51 +08:00
|
|
|
// 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{
|
2020-07-15 18:26:22 +08:00
|
|
|
|
2020-08-26 18:13:51 +08:00
|
|
|
// bool fan_1;
|
|
|
|
// bool fan_2;
|
|
|
|
// bool fan_3;
|
|
|
|
// }status;
|
|
|
|
// struct {
|
|
|
|
// float sensor_1;
|
|
|
|
// float sensor_2;
|
|
|
|
// float sensor_3;
|
|
|
|
// }temp;
|
2020-07-15 18:26:22 +08:00
|
|
|
|
2021-01-05 14:46:47 +08:00
|
|
|
|
|
|
|
|
2020-04-17 15:55:14 +08:00
|
|
|
}NaviKit_t;
|
|
|
|
extern NaviKit_t NaviKit;
|
|
|
|
|
2021-01-05 14:46:47 +08:00
|
|
|
//device on board
|
2021-01-05 16:06:45 +08:00
|
|
|
enum Device_t{USB2_Port1,USB2_Port2,USB2_Port3,USB2_Port4,USB2_Port5,USB2_Port6, //USB2.0 Port
|
|
|
|
USB3_Port1,USB3_Port2,USB3_Port3,USB3_Port4,USB3_Port5,USB3_Port6, //USB3.0 Port
|
|
|
|
SOC_USB2_HUB,SOC_USB3_HUB,SOC_USB3_HOST,SOC_USB3_GEC,SOC_GE_SW, //SOC on Board
|
|
|
|
SYS_FAN1,SYS_FAN2,SYS_FAN3, //Fan on Board
|
|
|
|
SYS_RUN_LED,SYS_PWR_LED, //LED on Board
|
2021-01-07 15:11:11 +08:00
|
|
|
SOM_PWR_EN,SOM_DFU,SOM_RESET,SOM_SLEEP, //SOM Control
|
2021-01-05 16:06:45 +08:00
|
|
|
PMB_PS_ON}; //Power Management Board
|
2021-01-05 14:46:47 +08:00
|
|
|
|
|
|
|
void PWR_Enable(enum Device_t device,bool en,uint16_t delay);
|
|
|
|
bool PWR_Status(enum Device_t device);
|
|
|
|
|
2020-04-27 16:58:16 +08:00
|
|
|
void NaviKit_var_init();
|
2020-08-26 18:13:51 +08:00
|
|
|
|
|
|
|
//power state machine switch function
|
2021-01-06 12:27:08 +08:00
|
|
|
void enter_standby_state();
|
2020-08-26 18:13:51 +08:00
|
|
|
void enter_isp_state();
|
2021-01-05 14:46:47 +08:00
|
|
|
void enter_run_state(uint16_t delay);
|
|
|
|
void enter_idle_state(uint16_t delay);
|
|
|
|
void enter_sleep_state(uint16_t delay);
|
|
|
|
void enter_dfu_state(uint16_t delay);
|
2021-01-07 15:11:11 +08:00
|
|
|
void som_reboot(uint16_t delay);
|
2021-01-05 14:46:47 +08:00
|
|
|
//non-blocking beep function with os delay
|
|
|
|
void TaskBeep(uint32_t time_ms, uint8_t n);
|
2020-08-25 19:33:15 +08:00
|
|
|
|
|
|
|
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
|
2021-01-05 14:46:47 +08:00
|
|
|
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
|
2020-04-27 16:58:16 +08:00
|
|
|
|
2020-12-18 12:46:59 +08:00
|
|
|
|
|
|
|
|
2020-04-17 15:55:14 +08:00
|
|
|
#endif /* INC_NAVIKIT_H_ */
|