/*
 * @file pwr_brd.h
 */

#ifndef PWR_BRD_H
#define PWR_BRD_H

#include "pcal6408a_gpio_expander.h"

/*
 * ADM1176 I2C address
 */
#define ADM1176_U4          0x94     /*! PS1_BRD power supply HSC    => (U4  sensor id)*/
#define ADM1176_U7          0x9C     /*! PS2_BRD power supply HSC    => (U7  sensor id)*/
#define ADM1176_U11         0x90     /*! ES1_BRD power supply HSC    => (U11 sensor id)*/
#define ADM1176_U14         0xEC     /*! ES2_BRD power supply HSC    => (U14 sensor id)*/
#define ADM1176_U17         0x98     /*! IO_BRD power supply HSC     => (U17 sensor id)*/
#define ADM1176_U18         0x9A     /*! IO_BRD TOP1 ENABLE HSC      => (U18 sensor id)*/
#define ADM1176_U32         0x96     /*! IO_BRD TOP2 ENABLE HSC      => (U32 sensor id)*/
#define ADM1176_U34         0xF8     /*! IO_BRD BOTTOM1 ENABLE HSC   => (U34 sensor id)*/
#define ADM1176_U36         0xC0     /*! IO_BRD BOTTOM2 ENABLE HSC   => (U36 sensor id)*/
#define ADM1176_U25         0x8A     /*! SSD_1 HEAT ENABLE HSC       => (U25 sensor id)*/
#define ADM1176_U28         0x8C     /*! SSD_2 HEAT ENABLE HSC       => (U28 sensor id)*/

#define CONTROL             0x83     /*! HSC gate pin register address*/
#define I2C_TEST_TIMEOUT    500      /*! I2C time out */

#define PSM_TEST            1
#define HSC_TEST            2

/*
 * Gate pin set instance id
 */
#define PS1_ON             0
#define PS1_OFF            1
#define PS2_ON             2
#define PS2_OFF            3
#define ES1_ON             4
#define ES1_OFF            5
#define ES2_ON             6
#define ES2_OFF            7
#define IO_ON              8
#define IO_OFF             9

#define IO1_TOP_ON         0
#define IO1_TOP_OFF        1
#define IO2_TOP_ON         2
#define IO2_TOP_OFF        3
#define IO1_BOT_ON         4
#define IO1_BOT_OFF        5
#define IO2_BOT_ON         6
#define IO2_BOT_OFF        7
#define SSD1_HEAT_ON       8
#define SSD1_HEAT_OFF      9
#define SSD2_HEAT_ON       10
#define SSD2_HEAT_OFF      11

/*
 * UART set instance id
 */
#define RS485_U1           1
#define RS485_U16          2
#define RS485_TX           1
#define RS485_RX           2

/*
 *  U3 gpio expander pin name
 */
#define E1_SSD0_HEAT_EN       MCP23008_GPIO_O
#define E2_SSD0_HEAT_EN       MCP23008_GPIO_1
#define SSD_HEAT_TOP1_EN      MCP23008_GPIO_2
#define SSD_HEAT_TOP2_EN      MCP23008_GPIO_3
#define SSD_HEAT_BOT1_EN      MCP23008_GPIO_4
#define SSD_HEAT_BOT2_EN      MCP23008_GPIO_5
#define CORE_PCB_SEN_ALERT    MCP23008_GPIO_6

/*
 *  U19 gpio expander pin names
 */
#define PS1_PCB_SEN_ALERT     MCP23008_GPIO_O
#define PS2_PCB_SEN_ALERT     MCP23008_GPIO_1
#define PAY_LOAD1_ALERT       MCP23008_GPIO_2
#define PAY_LOAD2_ALERT       MCP23008_GPIO_3
#define IO_PCB_SEN_ALERT      MCP23008_GPIO_4
#define E1_PCB_SEN_ALERT      MCP23008_GPIO_5
#define CORE2_PCB_SEN_ALERT   MCP23008_GPIO_6
#define E2_PCB_SEN_ALERT      MCP23008_GPIO_7

/*
 *  U20 gpio expander pin names
 */
#define UART4_IN1_RE                MCP23008_GPIO_O
#define UART4_IN1_DE                MCP23008_GPIO_1
#define UART4_IN2_RE                MCP23008_GPIO_2
#define UART4_IN2_DE                MCP23008_GPIO_3
#define PAY_LOAD1_ALERT3            MCP23008_GPIO_4
#define CORE_IO2_EXPD_INT2_U19      MCP23008_GPIO_5

typedef struct
{
    float temp;                     /*!< temperature            */
    float vbus_vlg;                 /*!< vbus voltage           */
    float vshunt_voltage;           /*!< vshunt voltage         */
    float psm_current;              /*!< current                */
    uint32_t psm_power;             /*!< power                  */
    float hsc_crnt;                 /*!< hot swap cntrl current */
    float hsc_vlt;                  /*!< hot swap cntrl voltage */
}hsc_sns_info_s;

/**
 * @Power board gpio expander test function.
 */
uint8_t pwr_brd_gpio_exp_self_test();

/**
 * @Get power board hot swap controller value.
 */
uint8_t pwr_brd_get_hsc_tempreature(hsc_sns_info_s *hsc_info_s);

/**
 * @Get power board power sensor monitoring value.
 */
uint8_t pwr_brd_get_psm_tempreature(hsc_sns_info_s *hsc_info_s);

/**
 * @Power board adc self test function.
 */
void pwr_brd_adc7291_self_test();

/**
 * @Power board power supply test function.
 */
void power_board_supply_test(uint8_t* case_id, uint8_t on_off);

/**
 * @Power board power sensor self test function.
 */
uint8_t pwr_brd_sensor_self_test(uint8_t *sns_tst_id);

/**
 * @Power board TOP and BOTTOM test function.
 */
void power_board_top_bot_supply_test(uint8_t* case_id, uint8_t on_off);

/*
 *  PWR_BOARD UART_RS_485 IC Test function
 */
void uart_rs485_test(uint8_t* test_id);


#endif
