Files
kunlun/export/inc/bsp/iot_board_api.h

557 lines
18 KiB
C

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef IOT_BOARD_API_H
#define IOT_BOARD_API_H
#include "os_types_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \defgroup BOARD_INFO_APIs
* @brief WQ30x1 BOARD_INFO API
*/
/** @addtogroup BOARD_INFO_APIs
* @{
*/
/**************************** gpio type ***************************************/
#define GPIO_PLC_EVENT 0
#define GPIO_STA_OUT 1
#define GPIO_TX_LED 2
#define GPIO_RX_LED 3
#define GPIO_PA_LED 4
#define GPIO_PB_LED 5
#define GPIO_PC_LED 6
#define GPIO_RS485_TXE 7
#define GPIO_IR_TXD 8
#define GPIO_IR_RXD 9
#define GPIO_GEODE_OVT 10 // 外部pa的gpio中断
#define GPIO_SMART_BOOT_SEL 11
#define GPIO_PM_CHARGE_EN 12
#define GPIO_RST_CTRL 13
#define GPIO_BAND_FILTER 14
#define GPIO_EM_PULSE 15
#define GPIO_PM_COLLAPSE_EN 16
#define GPIO_GOLDEN_SET 17
#define GPIO_PA_ZC 18
#define GPIO_PB_ZC 19
#define GPIO_PC_ZC 20
#define GPIO_PT_K48_CHARGE_EN 21
#define GPIO_PT_PWR_CTRL 22
#define GPIO_PT_JIG_DET 23
#define GPIO_GOLDEN_RXD0 24
#define GPIO_PT_K48_CLK 25
#define GPIO_PT_K48_CS 26
#define GPIO_PT_K48_SDO 27
#define GPIO_PT_K48_SDI 28
#define GPIO_PM_DETECTION 29
#define GPIO_PLC_LINK_LED 30
#define GPIO_RGST_LED 31
#define GPIO_DLINK_LED 32
#define GPIO_RESET_CONTROL 33
#define GPIO_GOLDEN_TXD0 34
#define GPIO_TSFM_SIGNAL_PA 35
#define GPIO_RELAY_CTRL_PA 36
#define GPIO_RELAY_CTRL_PB 37
#define GPIO_RELAY_CTRL_PC 38
#define GPIO_OPEN_BOX_DETECTION 39
#define GPIO_METER_RST_CTRL 40
#define GPIO_SPI_CS_1 42
#define GPIO_SPI_CS_2 43
#define GPIO_PA_ZC_EXT 44
#define GPIO_PB_ZC_EXT 45
#define GPIO_PC_ZC_EXT 46
#define GPIO_GPS_RST_CTRL 47
#define GPIO_EXT_UART_INT 48
#define GPIO_EXT_RS485_TXE1 49
#define GPIO_EXT_RS485_TXE2 50
#define GPIO_EXT_RS485_TXE3 51
#define GPIO_EXT_RS485_TXE4 52
#define GPIO_EXT_UART_SDA 53
#define GPIO_EXT_UART_SCL 54
#define GPIO_EXTEND_IO_INT 55
#define GPIO_BRK_MCU_RXD 56
#define GPIO_BRK_MCU_TXD 57
#define GPIO_BT_RST_CTRL 58
#define GPIO_HTM_I2C_SCL 59
#define GPIO_HTM_I2C_SDA 60
#define GPIO_METER_CS_CTRL 61
#define GPIO_METER_CLK_CTRL 62
#define GPIO_METER_MISO_CTRL 63
#define GPIO_METER_MOSI_CTRL 64
#define GPIO_TSFM_SIGNAL_PB 65
#define GPIO_TSFM_SIGNAL_PC 66
#define GPIO_PN_ZC 67
#define GPIO_SPI_FLASH_CLK 68
#define GPIO_SPI_FLASH_CS 69
#define GPIO_SPI_FLASH_MOSI 70
#define GPIO_SPI_FLASH_MISO 71
#define GPIO_EXT_BT_EN 72
#define GPIO_RUNNING_LED 73
#define GPIO_VC_EXT_CHIP_BOOT 74
#define GPIO_VC_EXT_CHIP_RST 75
#define GPIO_MAC_SET 76
#define GPIO_VC_EXT_EVENT 77
#define GPIO_VC_SPI_CLK 78
#define GPIO_VC_SPI_MISO 79
#define GPIO_VC_SPI_MOSI 80
#define GPIO_VC_SPI_CS 81
#define GPIO_TSFM_LOAD_TRIGGER 82
#define GPIO_EXT_RTC_I2C_SCL 83
#define GPIO_EXT_RTC_I2C_SDA 84
#define GPIO_MCP3941_CLK 85
#define GPIO_MCP3941_MOSI 86
#define GPIO_MCP3941_MISO 87
#define GPIO_MCP3941_CS 88
#define GPIO_MCP3941_RST 89
#define GPIO_MCP3941_DR 90
#define GPIO_BSRM_IO0 91
#define GPIO_BSRM_IO1 92
#define GPIO_BSRM_IO2 93
#define GPIO_BSRM_IO3 94
/* iot module, stamps package, goldenfinger package */
#define GPIO_CUS_IO_0 95
#define GPIO_CUS_IO_1 96
#define GPIO_CUS_IO_3 97
#define GPIO_CUS_IO_4 98
#define GPIO_CUS_IO_11 99
#define GPIO_CUS_IO_12 100
#define GPIO_CUS_IO_15 101
#define GPIO_CUS_IO_16 102
#define GPIO_CUS_IO_17 103
#define GPIO_CUS_IO_18 104
#define GPIO_CUS_IO_19 105
#define GPIO_CUS_IO_20 106
/* kl3 rf spi */
#define GPIO_SPI_RF_CLK 107
#define GPIO_SPI_RF_CS 108
#define GPIO_SPI_RF_MISO 109
#define GPIO_SPI_RF_MOSI 110
/* RS485_2_EN GPIO */
#define GPIO_RS485_TXE_2 111
/* peripheral circuit power control */
#define GPIO_P3V3_EN 112
#define GPIO_EX_IO_I2C_SCL 113
#define GPIO_EX_IO_I2C_SDA 114
/* extend io tsfm pwm output control chip select gpio */
#define GPIO_EX_IO_PWM_CS_P0 115
#define GPIO_EX_IO_PWM_CS_P1 116
#define GPIO_EX_IO_PWM_CS_P2 117
/* extend io pn zero cross input control chip select gpio */
#define GPIO_EX_IO_PN_ZC_CS_P0 118
#define GPIO_EX_IO_PN_ZC_CS_P1 119
/* single sta use k68 chip, set pa lic pin to save power */
#define GPIO_LIC_CTRL 120
/* rf clk : MCU provides CLK to RF chip */
#define GPIO_RF_CLK 121
/* reset pin of ethernet phy */
#define GPIO_ETH_PHY_RESET 122
/* used for 12v power collapsed detection */
#define GPIO_P12V_DETECTION 123
/* phase A gpio tx and rx switch */
#define GPIO_TXRX_SWITCH_A 124
/* phase B gpio tx and rx switch */
#define GPIO_TXRX_SWITCH_B 125
/* phase C gpio tx and rx switch */
#define GPIO_TXRX_SWITCH_C 126
/* nw 21 multi pulse pin */
#define GPIO_MULTI_PULSE 127
#define GPIO_PT_RELAY_EN 128
#define GPIO_PT_RELAY_HPLC 129
#define GPIO_PT_ADC_CTRL1 130
#define GPIO_PT_ADC_CTRL2 131
/* SPG21 sta version, pin12 always connect to GND */
#define GPIO_PT_GND_DET 132
#define GPIO_RF_PA_CSD 133
#define GPIO_RF_PA_CTX 134
#define GPIO_NO_VALID 0xff
/**************************** adc type ****************************************/
#define ADC_PM_12V 0
#define ADC_PM_3V 1
#define ADC_PM_GND 2
#define ADC_CT_SIGNAL_DIFF_PA 3
#define ADC_CT_SIGNAL_DIFF_PB 4
#define ADC_CT_SIGNAL_DIFF_PC 5
#define ADC_VOLTAGE_SIGNAL_PA 6
#define ADC_VOLTAGE_SIGNAL_PB 7
#define ADC_VOLTAGE_SIGNAL_PC 8
/* iot module, stamps package, goldenfinger package */
#define ADC_CUS_ADC_1 9
#define ADC_CUS_ADC_2 10
#define ADC_CUS_ADC_3 11
#define ADC_CUS_ADC 12
#define ADC_CUS_ADC_4 13
#define ADC_CUS_ADC_5 14
#define ADC_CUS_ADC_6 15
#define ADC_PT_DUT_VCORE 16
#define ADC_PT_DUT_3V 17
#define ADC_PT_DUT_12V 18
#define ADC_PT_LIGHT_SENSOR 19
#define ADC_TYPE_MAX 20
#define ADC_TYPE_INVALID 0xff
#define CFG_START_CHARGE_THR 0
#define CFG_STOP_CHARGE_THR 1
/**************************** pwm type ****************************************/
/* define pwm channel type */
#define PWM_CH_TYPE_TSFM_LAUNCH_CTRLA 0
#define PWM_CH_TYPE_TSFM_LAUNCH_CTRLB 1
#define PWM_CH_TYPE_TSFM_LAUNCH_CTRLC 2
#define PWM_CH_TYPE_TSFM_LOAD_CTRL 3
/**************************** spi type ****************************************/
#define SPI_PORT_TYPE_PYH_RF 0
#define CUS_BOARD_ID_LEDCSTA01 17
#define CUS_BOARD_ID_LEDCCCO01 25
#define CUS_BOARD_ID_STAMP_22P 41
#define CUS_BOARD_ID_GOLDFINGER_17P 42
#define CUS_BOARD_ID_SI301X_30P 46
#define CUS_BOARD_ID_LEDC_V3_0 47
#define CUS_BOARD_ID_SOLRMPPT_V1_0 96
/* watchdog reset */
#define SYSTEM_RESET_WDT 0
/*soft reset */
#define SYSTEM_RESET_SOFT 1
/*power on reset */
#define SYSTEM_RESET_PWR 2
/* define hardware transmitter receive mode */
#define HW_REC_MODE_INVALID 0
#define HW_REC_MODE_SYB 1
#define HW_REC_MODE_WQ 2
/* chip name buffer min len */
#define IOT_CHIP_NAME_BUFFER_MIN_LEN 10
typedef struct _iot_board_pt_basic_data {
/* the golden mac which used for the pt test */
uint8_t golden_mac[6];
/* year of production test date, bcd format */
uint8_t year;
/* month of production test date, bcd format */
uint8_t month;
/* day of production test date, bcd format */
uint8_t day;
/* hour of production test date, bcd format */
uint8_t hour;
/* minute of production test date, bcd format */
uint8_t min;
/* the golden's firmware version */
uint32_t golden_fw_ver;
/* the production test tool's version */
uint32_t pt_tool_ver;
/* the production test board's version */
uint32_t pt_board_ver;
} iot_board_pt_basic_data_t;
typedef struct _iot_board_pt_info {
/* pt ppm valid flag, 0-invalid, 1-valid */
uint8_t ppm_valid : 1,
/* dut version valid flag, 0-invalid, 1-valid */
pt_dut_ver_valid : 1,
/* basic pt info valid flag, 0-invalid, 1-valid */
basic_info_valid : 1,
/* reserved for the future */
resv : 5;
/* ppm value, updated in the production test */
int8_t ppm;
/* the dut firmware version */
uint32_t pt_dut_ver;
/* pt test basic info */
iot_board_pt_basic_data_t basic_info;
} iot_board_pt_info_t;
/**
* @brief iot_board_get_uart() - get a uart port
* @param type: the define UART_xxxx_PORT
*
* @return uart port
*/
uint8_t iot_board_get_uart(uint8_t type);
/**
* @brief iot_board_get_board_id() - get board_id
*
* @return board id
*/
uint8_t iot_board_get_board_id(void);
/**
* @brief iot_board_get_gpio() - get a gpio
* @param type: the define GPIO_XXX
*
* @return gpio pin
*/
uint8_t iot_board_get_gpio(uint8_t type);
/**
* @brief iot_board_get_led() - get a led's gpio
* @param type: led's id, see IOT_LED_TYPE enum.
*
* @return gpio pin
*/
uint8_t iot_board_get_led(uint8_t type);
/**
* @brief iot_board_get_led_cnt() - get a led's total number
*
* @return gpio pin
*/
uint8_t iot_board_get_led_cnt();
/**
* @brief iot_board_get_adc() - get an adc channel
* @param type: adc's type, see ADC_CHANNEL enum.
*
* @return adc's channel
*/
uint8_t iot_board_get_adc(uint8_t type);
/**
* @brief iot_board_get_cus_cfg() - get cus config information
* @param type: cus cfg type
*
* @return cus cfg information
*/
int iot_board_get_cus_cfg(uint8_t type);
/**
* @brief iot_board_get_led_id() - get a led's id
* @param sig_out: gpio matrix signal out number
*
* @return gpio pin
*/
uint8_t iot_board_get_led_id(uint8_t sig_out);
/**
* @brief iot_board_get_reset_count() - get reset count
* @param type: the define SYSTEM_RESET_xxx
*
* @return reset count
*/
uint32_t iot_board_get_reset_count(uint8_t type);
/**
* @brief get boot reason
* @param reason: detail boot reason. see IOT_SYS_RST_REASON_XXX
* @return boot reason (defined SYSTEM_BOOT_XXX)
*/
uint32_t iot_board_get_boot_reason(uint8_t *reason);
/**
* @brief load user vendor id from board config. if vendor id in board config
* is not available, vendor id from OEM section will be returned.
*
* @return user vendor id
*/
uint16_t iot_board_load_user_vendor_id();
/**
* @brief get user passcode from board config. if passcode in board config
* is not available, passcode from OEM section will be returned.
*/
uint16_t iot_board_get_user_passcode();
/**
* @brief get hw version hex info.
*
* @return hw version
*/
uint32_t iot_board_hw_version_hex();
/**
* @brief iot_board_chip_name_get() - chip name get.
* @param buffer: pointer to chip name buffer, ASCII format.
* @param buffer_len: buffer len, min buffer len see
* IOT_CHIP_NAME_BUFFER_MIN_LEN.
* @return 0 -- failed
* @return otherwise -- chip name len
*/
uint8_t iot_board_chip_name_get(uint8_t *buffer, uint8_t buffer_len);
/**
* @brief check if this board use rmii or not.
*
* @return true - this board use rmii interface
* false - this board not use eth rmii interface
*/
bool_t iot_board_support_rmii();
/**
* @brief check if this board use 6 way zero-crossing or not.
*
* @return true - this board use 6 way zero-crossing
* false - this board not use 6 way zero-crossing
*/
bool_t iot_board_support_zc6();
/**
* @brief check if this board use pulse for zero crossing or not.
*
* @return true - this board use pulse
* false - this board not use pulse
*/
bool_t iot_board_support_zc_pulse(void);
/**
* @brief check if this board use high precision zero crossing or not.
*
* @return true - this board use high precision
* false - this board not use high precision
*/
bool_t iot_board_support_zc_high_precision(void);
/**
* @brief get ntb offset between collected zc and real zc
*
* @return offset ntb, negative offset means collected zc is earlier than
* real zc, unit is 0.04us
*/
int32_t iot_board_get_zc_ntb_offset(void);
/**
* @brief check if this board use extend gpio switch
* reverse zero crossing or not.
*
* @return true - this board use extend gpio switch
* false - this board not use extend gpio switch
*/
bool_t iot_board_support_rev_zc_ext_gpio_switch(void);
/**
* @brief check whether the zero crossing circuit is the falling edge.
*
* @return true - yes. false - not.
*/
bool_t iot_board_zc_edge_is_failing(void);
/**
* @brief check if this board support topo rx or not.
*
* @return true - yes. false - not.
*/
bool_t iot_board_support_topo_rx(void);
/**
* @brief iot_board_type_is_brmt_class_b() - check whether the board type
* is BRMT class B.
* @return true - yes. false - not.
*/
bool_t iot_board_type_is_brmt_class_b(void);
/**
* @brief iot_board_get_tsfm_mode() - get tsfm mode
* @return tsfm mode. see HW_REC_MODE_XXX
*/
uint8_t iot_board_get_tsfm_mode();
/**
* @brief iot_board_get_pwm_ch() - get pwm channel
* @param type: pwm channel type, see PWM_CH_TYPE_XXX.
* @retval: pwm channel num, see IOT_PWM_CHANNEL_XXX.
*/
uint8_t iot_board_get_pwm_ch(uint8_t type);
/**
* @brief iot_hardware_version_check() - check whether the incoming
* hardware version number is defined by software.
* @param hw_version: hardware version number to be checked.
* @return ERR_OK: the software can identify the hardware version number.
* ERR_FAIL: The software does not recognize the hardware version number.
*/
uint8_t iot_hardware_version_check(uint32_t hw_version);
/**
* @brief iot_board_calc_data_check() - check whether the factory calibration
* data is valid.
* @retval: 1 mean factory calibration data is valid.
* @retval: 0 mean factory calibration data is invalid.
*/
uint8_t iot_board_calc_data_check();
/******************** check funtion by hardware version ***********************/
/**
* @brief iot_hwver_is_noele_brk() - check whether it has the non-electric BRK function.
* @retval: 1 mean non-electric control.
* @retval: 0 mean electric control.
*/
uint8_t iot_hwver_is_noele_brk(void);
/**
* @brief iot_hwver_is_320a_brk() - check whether it has i3c-brk function.
* @retval: 1 mean i3c-brk.
* @retval: 0 mean non-i3c-brk.
*/
uint8_t iot_hwver_is_320a_brk(void);
/**
* @brief iot_hwver_is_630a_brk() - check whether it has 630A i3c-brk function.
* @retval: 1 mean 630A i3c-brk.
* @retval: 0 mean not 630A i3c-brk.
*/
uint8_t iot_hwver_is_630a_brk(void);
/**
* @brief iot_hwver_is_ledc_v3_0_jy() - check whether it has the iot ledc function
* of jingyi v3 version.
* @retval: 1 mean iot ledc v3.
* @retval: 0 mean non-iot-ledc-v3.
*/
uint8_t iot_hwver_is_ledc_v3_0_jy(void);
/**
* @brief iot_board_fw_get_start_addr() - get the fw start address for
* fw and upgrade file check case.
* @return fw start address.
*/
uint32_t iot_board_fw_get_start_addr();
/**
* @brief iot_board_check_magic_no() - check if the magic no is valid.
* @param magic_no: magic number.
* @return: 1 - if magic no is valid, 0 - invalid.
*/
uint32_t iot_board_check_magic_no(uint32_t magic_no);
/**
* @brief iot_board_get_pt_info() - get the production test info
* @param pt_info: production test info to be refreshed.
* @retval: 0 means production test info is valid.
* @retval: non-0 mean production test info is invalid.
*/
uint8_t iot_board_get_pt_info(iot_board_pt_info_t *pt_info);
/**
* @brief iot_board_set_ppm() - set ppm to flash
* @param ppm: ppm value
* @retval ERR_OK success; others fail
*/
uint32_t iot_board_set_ppm(int8_t ppm);
#ifdef __cplusplus
}
#endif
#endif /*IOT_BOARD_API_H*/