#ifndef LINUX_TEMP_PORT
#include "main.h"
#endif
#include "exo_osal.h"
#include "exo_gpio.h"
#include "exo_ahw_al_temp_sensor_common.h"
#include "exo_ahw_al_psm_common.h"
#include "exo_ahw_al_dt_common.h"
#include "exo_ahw_al_hsc_common.h"
#include "obc_bringup_test.h"
#include "exo_ahw_al_gpio_exp_common.h"
#include "obc_tc_tm.h"
#include "exo_tctm_ipc.h"
#include "exo_ahw_al_data_logger_common.h"
#include "sensor_driver_intf.h"
#include "exo_ahw_al_spi_to_uart_common.h"
#include "sensor_driver_intf.h"

s_test_spi_uart_conv spi_uart_conv;
static os_sem_handle_ptr spi_uart_rcv_sem;

core_brd_brgup_sts core_brd_sts;
nic_brd_brgup_sts nic_brd_sts;
pwr_brd_brgup_sts pwr_brd_sts;
edge_brd_brgup_sts edge_brd_sts;
ssd_brd_brgup_sts ssd_brd_sts;
bp_brd_brgup_sts bp_brd_sts;
payload_brd_brgup_sts ps_brd_sts;

ahw_al_temp_sensor_hdl tmp_obc;
ahw_al_temp_sensor_hdl tmp_edge1;
ahw_al_temp_sensor_hdl tmp_edge2;
ahw_al_temp_sensor_hdl tmp_ps;
ahw_al_temp_sensor_hdl tmp_nic1;
ahw_al_temp_sensor_hdl tmp_ssd1;
ahw_al_temp_sensor_hdl tmp_ssd2;
ahw_al_temp_sensor_hdl tmp_ssd3;
ahw_al_temp_sensor_hdl tmp_ssd4;

ahw_al_hsc_hdl tmp_hsc;
ahw_al_hsc_hdl tmp_hsc_ps1_sup;
ahw_al_hsc_hdl tmp_hsc_ps2_sup;
ahw_al_hsc_hdl tmp_hsc_edge1_sup;
ahw_al_hsc_hdl tmp_hsc_edge1_heat_coil;
ahw_al_hsc_hdl tmp_hsc_edge2_sup;
ahw_al_hsc_hdl tmp_hsc_edge2_heat_coil;
ahw_al_hsc_hdl tmp_hsc_io_brd_sup;
ahw_al_hsc_hdl tmp_hsc_io_brd_top1;
ahw_al_hsc_hdl tmp_hsc_io_brd_top2;
ahw_al_hsc_hdl tmp_hsc_io_brd_bot1;
ahw_al_hsc_hdl tmp_hsc_io_brd_bot2;

ahw_al_psm_hdle tmp_psm;
ahw_al_psm_hdle tmp_core_brd_a;
ahw_al_psm_hdle tmp_core_brd_b;
ahw_al_psm_hdle tmp_ps1;
ahw_al_psm_hdle tmp_ps2;
ahw_al_psm_hdle tmp_psm_edge1;
ahw_al_psm_hdle tmp_edge2_sup;
ahw_al_psm_hdle tmp_io_sup;

ahw_al_ad7291_hdl tmp_adc_1;
ahw_al_ad7291_hdl tmp_adc_2;
ahw_al_ad7291_hdl tmp_oring_circuit;

//ahw_al_temp_sensor_hdl ahw_ts_obc;
//static temp_sens_cfg PLACE_IN_EXT_RAM_MEM temp_sns_cfg_obc;

uint8_t bringup_temp_sensors_init(ahw_al_temp_sensor_hdl* tmp_hdl, uint32_t ahw_id)
{
//    uint64_t tp_epoch_time = 0;
//    tp_epoch_time = tp_epoch_time;
    hal_ret_sts sts;
//    tmp_hdl->high_temp_threshold= 70;
//    tmp_hdl->low_temp_threshold = 10;
//    tmp_hdl->resolution = RES_0_25 ;
//    tmp_hdl->intr_polarity = TEMP_SENSE_ACTIVE_LOW;
//    tmp_hdl->intr_mask=1;
    sts=ahw_al_temp_sensor_init(tmp_hdl,ahw_id);
    return sts;
}


uint8_t bringup_power_sensors_init(ahw_al_psm_hdle* hpsm_arg, uint32_t ahw_id)
{
	hal_ret_sts sts;
	sts = ahw_al_psm_init(hpsm_arg,ahw_id);
	return sts;
}

 uint8_t bringup_dgtl_thrmst_sensor_init(ahw_al_dt_hdle* hdt_arg, ahw_inst_id_t ahw_id)
 {
	 hal_ret_sts sts;
	 sts=ahw_al_dt_init(hdt_arg,ahw_id);
	 return sts;
 }

 uint8_t bringup_hsc_sensor_init(ahw_al_hsc_hdl* hsc_arg, ahw_inst_id_t ahw_id)
 {
	 hal_ret_sts sts;
	 sts=ahw_al_hsc_init(hsc_arg,ahw_id);
	 return sts;
 }

 uint8_t bringup_adc_sensor_init(ahw_al_ad7291_hdl* hadc_arg, ahw_inst_id_t ahw_id)
 {
	 hal_ret_sts sts;
	 sts=ahw_al_data_logger_init(hadc_arg,ahw_id);
	 return sts;
 }


 uint8_t bringup_sensors_init()
 {
	    hal_ret_sts sts=0;

	    bringup_temp_sensors_init(&tmp_obc,TEMP_SENSOR_MCP9843_OBC);
	    bringup_temp_sensors_init(&tmp_edge1,TEMP_SENSOR_MCP9843_EDGE_1);
	    bringup_temp_sensors_init(&tmp_edge2,TEMP_SENSOR_MCP9843_EDGE_2);
	    bringup_temp_sensors_init(&tmp_ps,TEMP_SENSOR_MCP9843_PS_GEN_2);
	    bringup_temp_sensors_init(&tmp_nic1,TEMP_SENSOR_MCP9843_NIC_1);
	    bringup_temp_sensors_init(&tmp_ssd1,TEMP_SENSOR_MCP9843_SSD_1);
		bringup_temp_sensors_init(&tmp_ssd2,TEMP_SENSOR_MCP9843_SSD_2);
		bringup_temp_sensors_init(&tmp_ssd3,TEMP_SENSOR_MCP9843_SSD_3);
		bringup_temp_sensors_init(&tmp_ssd4,TEMP_SENSOR_MCP9843_SSD_4);

		bringup_hsc_sensor_init(&tmp_hsc,HSC_ADM1176_PAYLOAD_BRD_IN_SUPPLY);
		bringup_hsc_sensor_init(&tmp_hsc_ps1_sup,HSC_ADM1176_PS_1_IN_SUPPLY);
		bringup_hsc_sensor_init(&tmp_hsc_ps2_sup,HSC_ADM1176_PS_2_IN_SUPPLY);
		bringup_hsc_sensor_init(&tmp_hsc_edge1_sup,HSC_ADM1176_EDGE_1_IN_SUPPLY);
		bringup_hsc_sensor_init(&tmp_hsc_edge1_heat_coil,HSC_ADM1176_EDGE_1_HEAT_COIL);
		bringup_hsc_sensor_init(&tmp_hsc_edge2_sup,HSC_ADM1176_EDGE_2_IN_SUPPLY);
		bringup_hsc_sensor_init(&tmp_hsc_edge2_heat_coil,HSC_ADM1176_EDGE_2_HEAT_COIL);
		bringup_hsc_sensor_init(&tmp_hsc_io_brd_sup,HSC_ADM1176_IO_BRD_IN_SUPPLY);
		bringup_hsc_sensor_init(&tmp_hsc_io_brd_top1,HSC_ADM1176_IO_BRD_HEAT_COIL_TOP_1);
		bringup_hsc_sensor_init(&tmp_hsc_io_brd_top2,HSC_ADM1176_IO_BRD_HEAT_COIL_TOP_2);
		bringup_hsc_sensor_init(&tmp_hsc_io_brd_bot1,HSC_ADM1176_IO_BRD_HEAT_COIL_BOTTOM_1);
		bringup_hsc_sensor_init(&tmp_hsc_io_brd_bot2,HSC_ADM1176_IO_BRD_HEAT_COIL_BOTTOM_2);

		bringup_power_sensors_init(&tmp_psm,PSM_INA230_PS_GEN_2);
		bringup_power_sensors_init(&tmp_core_brd_a,PSM_INA230_CORE_BRD_A);
		bringup_power_sensors_init(&tmp_core_brd_b,PSM_INA230_CORE_BRD_B);
		bringup_power_sensors_init(&tmp_ps1,PSM_INA230_PS_1);
		bringup_power_sensors_init(&tmp_ps2,PSM_INA230_PS_2);
		bringup_power_sensors_init(&tmp_psm_edge1,PSM_INA230_EDGE_1);
		bringup_power_sensors_init(&tmp_edge2_sup,PSM_INA230_EDGE_2_IN_SUPPLY);
		bringup_power_sensors_init(&tmp_io_sup,PSM_INA230_IO_BRD_IN_SUPPLY);

		bringup_adc_sensor_init(&tmp_adc_1,ADC_AD7291_PS_1);
		//bringup_adc_sensor_init(&tmp_adc_2,ADC_AD7291_PS_2);
		bringup_adc_sensor_init(&tmp_oring_circuit,ADC_AD7291_ORING_CIRCUIT);
		return sts;
 }

 void core_board_test()  //1
 {
	 os_memset(&core_brd_sts.temp_sts,0x1,sizeof(core_brd_brgup_sts));
	 core_brd_sts.temp_sts = ahw_al_temp_sensor_self_test(TEMP_SENSOR_MCP9843_OBC);
 }

void io_board_test() //4
{
	 os_memset(&nic_brd_sts.io_temp_sts,0x1,sizeof(nic_brd_brgup_sts));
	nic_brd_sts.io_temp_sts  = ahw_al_temp_sensor_self_test(TEMP_SENSOR_MCP9843_NIC_1);
	nic_brd_sts.gpx_nic1_sts = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_NIC_1);
	nic_brd_sts.gpx_nic2_sts = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_NIC_2);
	nic_brd_sts.gpx_nic3_sts = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_NIC_3);
}


void power_brd_bringup_test() //23
{
	os_memset(&pwr_brd_sts.gpx_bp_1_sts,0x1,sizeof(pwr_brd_brgup_sts));
	pwr_brd_sts.gpx_bp_1_sts      = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_POWER_BOARD_1);
	pwr_brd_sts.gpx_bp_2_sts      = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_POWER_BOARD_2);
	pwr_brd_sts.gpx_bp_3_sts      = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_POWER_BOARD_3);

	pwr_brd_sts.pwr_core_a_sts    = ahw_al_psm_self_test(PSM_INA230_CORE_BRD_A);
	pwr_brd_sts.pwr_core_b_sts    = ahw_al_psm_self_test(PSM_INA230_CORE_BRD_B);
	pwr_brd_sts.pwr_ps1_sts       = ahw_al_psm_self_test(PSM_INA230_PS_1);
	pwr_brd_sts.pwr_ps2_sts       = ahw_al_psm_self_test(PSM_INA230_PS_2);
	pwr_brd_sts.pwr_edge1_sts     = ahw_al_psm_self_test(PSM_INA230_EDGE_1);
	pwr_brd_sts.pwr_edge2_sup_sts = ahw_al_psm_self_test(PSM_INA230_EDGE_2_IN_SUPPLY);
	pwr_brd_sts.pwr_io_sup_sts    = ahw_al_psm_self_test(PSM_INA230_IO_BRD_IN_SUPPLY);

	pwr_brd_sts.hsc_ps2_sts       = ahw_al_hsc_self_test(HSC_ADM1176_PS_2_IN_SUPPLY);
	pwr_brd_sts.hsc_ps1_sts       = ahw_al_hsc_self_test(HSC_ADM1176_PS_1_IN_SUPPLY);
	pwr_brd_sts.hsc_edge1_sup_sts = ahw_al_hsc_self_test(HSC_ADM1176_EDGE_1_IN_SUPPLY);
	pwr_brd_sts.hsc_edge1_hc_sts  = ahw_al_hsc_self_test(HSC_ADM1176_EDGE_1_HEAT_COIL);
	pwr_brd_sts.hsc_edge2_sup_sts = ahw_al_hsc_self_test(HSC_ADM1176_EDGE_2_IN_SUPPLY);
	pwr_brd_sts.hsc_edge2_hc_sts  = ahw_al_hsc_self_test(HSC_ADM1176_EDGE_2_HEAT_COIL);
	pwr_brd_sts.hsc_io_sup_sts    = ahw_al_hsc_self_test(HSC_ADM1176_IO_BRD_IN_SUPPLY);
	pwr_brd_sts.hsc_io_top1_sts   = ahw_al_hsc_self_test(HSC_ADM1176_IO_BRD_HEAT_COIL_TOP_1);
	pwr_brd_sts.hsc_io_top2_sts   = ahw_al_hsc_self_test(HSC_ADM1176_IO_BRD_HEAT_COIL_TOP_2);
	pwr_brd_sts.hsc_bot1_sts      = ahw_al_hsc_self_test(HSC_ADM1176_IO_BRD_HEAT_COIL_BOTTOM_1);
	pwr_brd_sts.hsc_bot2_sts      = ahw_al_hsc_self_test(HSC_ADM1176_IO_BRD_HEAT_COIL_BOTTOM_2);

	pwr_brd_sts.adc_ps1_sts       = ahw_al_data_logger_self_test(ADC_AD7291_PS_1);
	//pwr_brd_sts.adc_ps2_sts       = ahw_al_data_logger_self_test(ADC_AD7291_PS_2);
	pwr_brd_sts.adc_oring_sts     = ahw_al_data_logger_self_test(ADC_AD7291_ORING_CIRCUIT);
}

void backplane_brd_test() //1
{
	os_memset(&bp_brd_sts.gpx_sts,0x1,sizeof(bp_brd_brgup_sts));
	bp_brd_sts.gpx_sts            = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_BACK_PLANE);
}

void edge_brd_test() //6
{
	os_memset(&edge_brd_sts.temp_edge1_sts,0x1,sizeof(edge_brd_brgup_sts));
	edge_brd_sts.temp_edge1_sts   = ahw_al_temp_sensor_self_test(TEMP_SENSOR_MCP9843_EDGE_1);
	edge_brd_sts.temp_edge2_sts   = ahw_al_temp_sensor_self_test(TEMP_SENSOR_MCP9843_EDGE_2);
	edge_brd_sts.gpx_edge1_sts    = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_EDGE_1_GEN_2);
	edge_brd_sts.gpx_edge2_sts    = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_EDGE_2_GEN_2);
	edge_brd_sts.gpx_edge3_sts    = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_EDGE_3_GEN_2);
	edge_brd_sts.gpx_edge4_sts    = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_EDGE_4_GEN_2);
}

void ssd_brd_test() //6
{
	os_memset(&ssd_brd_sts.gpx_ssd1_sts,0x1,sizeof(ssd_brd_brgup_sts));
    ssd_brd_sts.gpx_ssd1_sts     = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_SSD_1);
    ssd_brd_sts.gpx_ssd2_sts     = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_MCP23008_SSD_2);
    ssd_brd_sts.temp_ssd1_sts    = ahw_al_temp_sensor_self_test(TEMP_SENSOR_MCP9843_SSD_1);
    ssd_brd_sts.temp_ssd2_sts    = ahw_al_temp_sensor_self_test(TEMP_SENSOR_MCP9843_SSD_2);
    ssd_brd_sts.temp_ssd3_sts    = ahw_al_temp_sensor_self_test(TEMP_SENSOR_MCP9843_SSD_3);
    ssd_brd_sts.temp_ssd4_sts    = ahw_al_temp_sensor_self_test(TEMP_SENSOR_MCP9843_SSD_4);

}

void ps_brd_test() //4
{
	os_memset(&ps_brd_sts.temp_ps_sts,0x1,sizeof(payload_brd_brgup_sts));
	ps_brd_sts.temp_ps_sts      = ahw_al_temp_sensor_self_test(TEMP_SENSOR_MCP9843_PS_GEN_2);
	ps_brd_sts.gpx_ps_sts       = ahw_al_gpio_exp_self_test(GPIO_EXPANDER_PCAL6408A_PS_GEN2);
	ps_brd_sts.hsc_ps_sts       = ahw_al_hsc_self_test(HSC_ADM1176_PAYLOAD_BRD_IN_SUPPLY);
	ps_brd_sts.pwr_ps_sts       = ahw_al_psm_self_test(PSM_INA230_PS_GEN_2);
}

void bringup_force_test_run()
{
	 core_board_test();
	 io_board_test();
	 power_brd_bringup_test();
	 edge_brd_test();
	 ssd_brd_test();
	 backplane_brd_test();
	 ps_brd_test();
}

uint8_t obc_test_sensor( uint8_t *id)
{
	hal_ret_sts sts;
	sts = HAL_MAX_ERR;
	uint32_t ahw_id;
	os_memcpy(&ahw_id ,id ,4);

	switch (ahw_id)
	{
	case TEMP_SENSOR_MCP9843_OBC:
	case TEMP_SENSOR_MCP9843_PS:
	case TEMP_SENSOR_MCP9843_EDGE:
	case TEMP_SENSOR_MCP9843_GPS:
	case TEMP_SENSOR_MCP9843_EDGE_1:
	case TEMP_SENSOR_MCP9843_EDGE_2:
	case TEMP_SENSOR_MCP9843_PS_GEN_2:
	case TEMP_SENSOR_MCP9843_NIC_1:
	case TEMP_SENSOR_MCP9843_SSD_1:
	case TEMP_SENSOR_MCP9843_SSD_2:
	case TEMP_SENSOR_MCP9843_SSD_3:
	case TEMP_SENSOR_MCP9843_SSD_4:

		sts =ahw_al_temp_sensor_self_test (ahw_id);
		break;

	case PSM_INA230_OBC:
        case PSM_INA230_PS:
        case PSM_INA230_CORE_BRD_A:
        case PSM_INA230_CORE_BRD_B:
        case PSM_INA230_PS_GEN_2:
        case PSM_INA230_PS_1:
        case PSM_INA230_PS_2:
        case PSM_INA230_EDGE_1:
        case PSM_INA230_EDGE_2_IN_SUPPLY:
        case PSM_INA230_IO_BRD_IN_SUPPLY:

                    sts =ahw_al_psm_self_test( ahw_id);
		break;

	case DIGITAL_THERMOSTAT_DS620_EDGE:
	case DIGITAL_THERMOSTAT_DS620_PS:

		sts =ahw_al_dt_self_test( ahw_id);
	break;

        case HSC_ADM1176_EDGE:
        case HSC_ADM1176_PS_1:
        case HSC_ADM1176_PS_2:
        case HSC_ADM1176_PAYLOAD_BRD_IN_SUPPLY:
        case HSC_ADM1176_PS_1_IN_SUPPLY:
        case HSC_ADM1176_PS_2_IN_SUPPLY:
        case HSC_ADM1176_EDGE_1_IN_SUPPLY:
        case HSC_ADM1176_EDGE_1_HEAT_COIL:
        case HSC_ADM1176_EDGE_2_IN_SUPPLY:
        case HSC_ADM1176_EDGE_2_HEAT_COIL:
        case HSC_ADM1176_IO_BRD_IN_SUPPLY:
        case HSC_ADM1176_IO_BRD_HEAT_COIL_TOP_1:
        case HSC_ADM1176_IO_BRD_HEAT_COIL_TOP_2:
        case HSC_ADM1176_IO_BRD_HEAT_COIL_BOTTOM_1:
        case HSC_ADM1176_IO_BRD_HEAT_COIL_BOTTOM_2:
        sts =ahw_al_hsc_self_test(ahw_id);
        break;

        case ADC_AD7291_PS_1:
        //case ADC_AD7291_PS_2:
        case ADC_AD7291_ORING_CIRCUIT:
        sts = ahw_al_data_logger_self_test(ahw_id);
        break;

        }
        return sts ;
}

/*
 * This function self test every sensor and gpio expander
 */
uint64_t obc_auto_sensor_test()
{
	uint64_t sts = 0;
	uint64_t temp_sts = 0;

	temp_sts = ahw_al_temp_sensor_self_test (TEMP_SENSOR_MCP9843_OBC);
	sts = sts | (temp_sts<<0);
	temp_sts = ahw_al_temp_sensor_self_test (TEMP_SENSOR_MCP9843_EDGE_1);
	sts = sts | (temp_sts<<1);
	temp_sts =ahw_al_temp_sensor_self_test (TEMP_SENSOR_MCP9843_EDGE_2);
	sts = sts | (temp_sts<<2);
	temp_sts =ahw_al_temp_sensor_self_test (TEMP_SENSOR_MCP9843_PS_GEN_2);
	sts = sts | (temp_sts<<3);
	temp_sts =ahw_al_temp_sensor_self_test (TEMP_SENSOR_MCP9843_NIC_1);
	sts = sts | (temp_sts<<4);
	temp_sts =ahw_al_temp_sensor_self_test (TEMP_SENSOR_MCP9843_SSD_1);
	sts = sts | (temp_sts<<5);
	temp_sts =ahw_al_temp_sensor_self_test (TEMP_SENSOR_MCP9843_SSD_2);
	sts = sts | (temp_sts<<6);
	temp_sts =ahw_al_temp_sensor_self_test (TEMP_SENSOR_MCP9843_SSD_3);
	sts = sts | (temp_sts<<7);
	temp_sts =ahw_al_temp_sensor_self_test (TEMP_SENSOR_MCP9843_SSD_4);
	sts = sts | (temp_sts<<8);

	temp_sts =ahw_al_psm_self_test(PSM_INA230_CORE_BRD_A);
	sts = sts | (temp_sts<<9);
	temp_sts =ahw_al_psm_self_test(PSM_INA230_CORE_BRD_B);
	sts = sts | (temp_sts<<10);
	temp_sts =ahw_al_psm_self_test(PSM_INA230_PS_GEN_2);
	sts = sts | (temp_sts<<11);
	temp_sts =ahw_al_psm_self_test(PSM_INA230_PS_1);
	sts = sts | (temp_sts<<12);
	temp_sts =ahw_al_psm_self_test(PSM_INA230_PS_2);
	sts = sts | (temp_sts<<13);
	temp_sts =ahw_al_psm_self_test(PSM_INA230_EDGE_1);
	sts = sts | (temp_sts<<14);
	temp_sts =ahw_al_psm_self_test(PSM_INA230_EDGE_2_IN_SUPPLY);
	sts = sts | (temp_sts<<15);
	temp_sts =ahw_al_psm_self_test(PSM_INA230_IO_BRD_IN_SUPPLY);
	sts = sts | (temp_sts<<16);

	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_PAYLOAD_BRD_IN_SUPPLY);
	sts = sts | (temp_sts<<17);
	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_PS_1_IN_SUPPLY);
	sts = sts | (temp_sts<<18);
	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_PS_2_IN_SUPPLY);
	sts = sts | (temp_sts<<19);
	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_EDGE_1_IN_SUPPLY);
	sts = sts | (temp_sts<<20);
	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_EDGE_1_HEAT_COIL);
	sts = sts | (temp_sts<<21);
	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_EDGE_2_IN_SUPPLY);
	sts = sts | (temp_sts<<22);
	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_EDGE_2_HEAT_COIL);
	sts = sts | (temp_sts<<23);
	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_IO_BRD_IN_SUPPLY);
	sts = sts | (temp_sts<<24);
	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_IO_BRD_HEAT_COIL_TOP_1);
	sts = sts | (temp_sts<<25);
	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_IO_BRD_HEAT_COIL_TOP_2);
	sts = sts | (temp_sts<<26);
	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_IO_BRD_HEAT_COIL_BOTTOM_1);
	sts = sts | (temp_sts<<27);
	temp_sts =ahw_al_hsc_self_test(HSC_ADM1176_IO_BRD_HEAT_COIL_BOTTOM_2);
	sts = sts | (temp_sts<<28);

	temp_sts = ahw_al_data_logger_self_test(ADC_AD7291_PS_1);
	sts = sts | (temp_sts<<29);
	temp_sts = ahw_al_data_logger_self_test(ADC_AD7291_ORING_CIRCUIT);
	sts = sts | (temp_sts<<30);/*
                temp_sts = ahw_al_data_logger_self_test(ADC_AD7291_PS_2);
                sts = sts | (temp_sts<<31);*/
                return sts;
}


 uint8_t obc_test_gpio_exp( uint8_t *id)
{
	hal_ret_sts sts;
		sts = HAL_MAX_ERR;
		uint32_t ahw_id;
		os_memcpy(&ahw_id ,id ,4);

			sts=ahw_al_gpio_exp_self_test( ahw_id);
	    return sts;
}

void spi_uart_rx_complete_cb()
{
     os_sem_give(spi_uart_rcv_sem);
}

/*
 * This function convert SPI to UART data
 */
#if defined(JANUS2) || defined(GEN2)
uint8_t obc_test_spi_uart_conv(const uint8 *data)
{
    //uint8_t cmd_ack[15];
    hal_ret_sts sts;
    obc_pck_data tm_info;
    os_memcpy(&spi_uart_conv,data,sizeof(s_test_spi_uart_conv));
    os_sem_create_bin(&spi_uart_rcv_sem,"SPI_UART_RCV_SEM");
    if(spi_uart_conv.test_mode == 0)
    {
        sts = ahw_al_uart_conv_self_test(UART_EXPANDER_MAX14830_OBC);
    }
    else if(spi_uart_conv.test_mode == 1)
    {
        sts = ahw_al_uart_conv_transmit(UART_EXPANDER_MAX14830_OBC,spi_uart_conv.channel_id,(uint8_t*)spi_uart_conv.data,15);
    }
    else if(spi_uart_conv.test_mode == 2)
    {
    	os_memset(&spi_uart_conv.data,0,15);
       // ahw_al_uart_conv_transmit(UART_EXPANDER_MAX14830_OBC,spi_uart_conv.channel_id,(uint8_t*)spi_uart_conv.data,15);
        if((os_sem_take(spi_uart_rcv_sem, 30000) == ral_success))
        {
           sts = ahw_al_uart_conv_receive(UART_EXPANDER_MAX14830_OBC,spi_uart_conv.channel_id,5,spi_uart_rx_complete_cb,(uint8_t*)spi_uart_conv.data);
        }
        else
        {
            printf("SPI to UART Channel read FAIL");
        }
}
    spi_uart_conv.status = sts;
    tm_info.rx_data_len = sizeof(s_test_spi_uart_conv);
    tm_info.rx_data = (uint8_t*)&spi_uart_conv;

    tm_info.tm_rsp_id = TM_SPI_UART_CONV_TEST;
    obc_pack_tm_data(&tm_info);

    os_sem_delete(spi_uart_rcv_sem);
    sts = TCTM_OK;
    return sts;
}
#endif
