/*
 * obc_mcu_info.c
 *
 *  Created on: Jan 3, 2024
 *      Author: Invcuser_63
 */


#include "obc_mcu_info.h"
#include "obc_tc_tm.h"
#include "obc_icd.h"
#include "obc_intf_ctrl_msg.h"
#include "exo_ahw_al_temp_sensor_common.h"
#include "exo_io_al_sos_timer.h"
#include "exo_tctm_ipc.h"
#include "exo_io_al_temperature.h"

int16 obc_get_dev_temp_info_dec(uint8 *data)
{
	 int8 status;
	if(data[0] == 0)
	{
		obc_pck_data mcu_get_temp;
		mcu_get_temp.tm_rsp_id = TM_GET_PS_TEMP;
		mcu_get_temp.tx_data=&data[0];
		mcu_get_temp.tx_data_len=1;

		obc_pack_tm_data(&mcu_get_temp);

	}
	else if(data[0] == 1)
	{
		//ps_get_temp_s ps_get_temp;
		obc_encode_icd_cmd(OBC_PS_TEMP_INFO, 0, NULL);
	}
	else
	{
		/*TODO for Edge*/
	}
	status = TCTM_OK;
	    return status;
//	obc_pack_tm_data(&ipcc_trig_resp);
}

int16 obc_get_dev_time_info_dec(uint8 *data)
{
	 int8 status;
	if(data[0] == 0)
	{
		obc_pck_data mcu_get_time;
		mcu_get_time.tm_rsp_id = TM_GET_PS_TIME;
		mcu_get_time.tx_data=&data[0];
		mcu_get_time.tx_data_len=1;

		obc_pack_tm_data(&mcu_get_time);
	}
	else if(data[0] == 1)
	{
	//ps_get_temp_s ps_get_temp;
	obc_encode_icd_cmd(OBC_PS_TIME_INFO, 0, NULL);
	}
	else
	{
		/*TODO for Edge*/
	}
	status = TCTM_OK;
	    return status;
//	obc_pack_tm_data(&ipcc_trig_resp);
}

int16 obc_get_dev_chip_info_dec(uint8 *data)
{
	 int8 status;
	if(data[0] == 0)
	{
		obc_pck_data mcu_get_cpu_info;
		mcu_get_cpu_info.tm_rsp_id = TM_GET_MCU_CHIP_INFO;
		mcu_get_cpu_info.tx_data=&data[0];
		mcu_get_cpu_info.tx_data_len=1;

		obc_pack_tm_data(&mcu_get_cpu_info);
	}
	else if(data[0] == 1)
	{
	//ps_get_temp_s ps_get_temp;
	obc_encode_icd_cmd(OBC_PS_CHIP_INFO, 0, NULL);
	}
	else
	{
		/*TODO for Edge*/
	}
	status = TCTM_OK;
	    return status;
//	obc_pack_tm_data(&ipcc_trig_resp);
}

int16 obc_get_dev_ext_mem_dec(uint8 *data)
{
	 int8 status;
	if(data[0] == 0)
	{
		obc_pck_data mcu_get_ext_mem;
		mcu_get_ext_mem.tm_rsp_id = TM_GET_MCU_EXT_MEM_INFO;
		mcu_get_ext_mem.tx_data=&data[0];
		mcu_get_ext_mem.tx_data_len=1;
		obc_pack_tm_data(&mcu_get_ext_mem);
	}
	else if(data[0] == 1)
	{
	//ps_get_temp_s ps_get_temp;
	obc_encode_icd_cmd(OBC_PS_EXT_MEM, 0, NULL);
	}
	else
	{
		/*TODO for Edge*/
	}
	status = TCTM_OK;
	    return status;
//	obc_pack_tm_data(&ipcc_trig_resp);
}
#if 0
int16 obc_get_dev_int_mem_dec(uint8 *data)
{
	int8 status;
		tm_rsp_id = TM_GET_MCU_INT_MEM_INFO;
		obc_pack_tm_data(NULL);
		status = TCTM_OK;
		return status;

}

int16 obc_get_dev_int_pher_info_dec(uint8 *data)
{
	int8 status;
	tm_rsp_id = TM_GET_MCU_INT_PHERIPHARL_INFO;
	obc_pack_tm_data(NULL);
	status = TCTM_OK;
	return status;
}

int16 obc_get_dev_ext_pher_info_dec(uint8 *data)
{
	int8 status;
	tm_rsp_id = TM_GET_MCU_EXT_PHERIPHARL_INFO;
	obc_pack_tm_data(NULL);
	status = TCTM_OK;
	return status;
}

int16 obc_get_dev_get_rst_info_dec(uint8 *data)
{
	int8 status;
	tm_rsp_id = TM_GET_MCU_RST_INFO;
	obc_pack_tm_data(NULL);
	status = TCTM_OK;
	return status;
}
#endif
int8 obc_tm_get_temp_enc(uint8_t *temp)
{
	int8 status;
	float temperature;
	temperature = get_mcu_ic_temperature();
	//temperature = 12.0;
	*temp = (int)temperature;
	status = TCTM_OK;
	return status;
}

int8 obc_tm_get_time_enc(uint32_t *epoch_time)
{
	int8 status;
	*epoch_time=get_crnt_time_date_in_epoch();
	status = TCTM_OK;
	return status;
}

int8 obc_tm_get_mcu_info_enc(mcu_get_chip_info_s *mcu_get_chip_info,uint8_t id)
{
	int8 status;
	mcu_get_chip_info->dev_id=id;
	//mcu_get_chip_info->processor_name={"Arm® 32-bit Cortex®-M7"};
	strcpy(mcu_get_chip_info->processor_name,"Arm® 32-bit Cortex®-M7");
	strcpy((char*)&mcu_get_chip_info->chip_id,"M7");
	mcu_get_chip_info->cores=1;
	mcu_get_chip_info->clock_speed=200;
	mcu_get_chip_info->cache_size=524288;
	status = TCTM_OK;
	return status;
}

int8 obc_tm_get_mcu_ext_mem_info_enc(mcu_get_ext_mem_s *mcu_get_ext_mem,uint8_t id)
{
	int8 status;
#if 0
	obc_get_ext_mem->dev_id=id;
	obc_get_ext_mem->eram_tot_mem=33554432;
	obc_get_ext_mem->eram_used_mem=11268282;
	obc_get_ext_mem->flash_fmc_tot_mem=16777216;
	obc_get_ext_mem->flash_fmc_used_mem=9961472;
	obc_get_ext_mem->flash_qspi_tot_mem=67108864;
	obc_get_ext_mem->flash_qspi_used_mem=1024;
#endif
	mcu_get_ext_mem->dev_id=id;
	mcu_get_ext_mem->mem_cnt=MCU_EXT_MEM_MAX_CNT;
	mcu_get_ext_mem->ext_mem_info[MCU_ERAM].tot_mem=33554432;
	mcu_get_ext_mem->ext_mem_info[MCU_ERAM].free_mem=22181282;
	mcu_get_ext_mem->ext_mem_info[MCU_ERAM].used_mem=11268282;
	mcu_get_ext_mem->ext_mem_info[MCU_FLASH_FMC].tot_mem=16777216;
	mcu_get_ext_mem->ext_mem_info[MCU_FLASH_FMC].free_mem=6553600;
	mcu_get_ext_mem->ext_mem_info[MCU_FLASH_FMC].used_mem=9961472;
	mcu_get_ext_mem->ext_mem_info[MCU_FLASH_QSPI].tot_mem=67108864;
	mcu_get_ext_mem->ext_mem_info[MCU_FLASH_QSPI].free_mem=65010688;
	mcu_get_ext_mem->ext_mem_info[MCU_FLASH_QSPI].used_mem=1024;
	status = TCTM_OK;
	return status;
}

int8 obc_tm_get_mcu_int_mem_info_enc(obc_get_int_mem_s *obc_get_int_mem)
{
	int8 status;
	obc_get_int_mem->iram_tot_mem=508928;
	obc_get_int_mem->iram_used_mem=471440;
	obc_get_int_mem->iram_free_mem=37488;
	status = TCTM_OK;
	return status;
}


int8 obc_tm_get_mcu_int_pher_info_enc(obc_get_int_pher_info_s *obc_get_int_pher_info)
{
	int8 status;
	obc_get_int_pher_info->pher_infor_buf[MCU_CAN_2].pher_id=0x02;
	obc_get_int_pher_info->pher_infor_buf[MCU_CAN_2].pher_speed=1;
	obc_get_int_pher_info->pher_infor_buf[MCU_SPI_1].pher_id=0x11;
	obc_get_int_pher_info->pher_infor_buf[MCU_SPI_1].pher_speed=1;//dummy
	obc_get_int_pher_info->pher_infor_buf[MCU_I2C_2].pher_id=0x22;
	obc_get_int_pher_info->pher_infor_buf[MCU_I2C_2].pher_speed=1;//dummy
	obc_get_int_pher_info->pher_infor_buf[MCU_I2C_3].pher_id=0x23;
	obc_get_int_pher_info->pher_infor_buf[MCU_I2C_3].pher_speed=1;//dummy
	obc_get_int_pher_info->pher_infor_buf[MCU_I2C_4].pher_id=0x24;
	obc_get_int_pher_info->pher_infor_buf[MCU_I2C_4].pher_speed=1;//dummy
	obc_get_int_pher_info->pher_infor_buf[MCU_UART_4].pher_id=0x34;
	obc_get_int_pher_info->pher_infor_buf[MCU_UART_4].pher_speed=1;//dummy
	obc_get_int_pher_info->pher_infor_buf[MCU_UART_5].pher_id=0x35;
	obc_get_int_pher_info->pher_infor_buf[MCU_UART_5].pher_speed=1;//dummy
	obc_get_int_pher_info->pher_infor_buf[MCU_FMC_1].pher_id=0x41;
	obc_get_int_pher_info->pher_infor_buf[MCU_FMC_1].pher_speed=1;//dummy
	obc_get_int_pher_info->pher_infor_buf[MCU_QSPI_1].pher_id=0x51;
	obc_get_int_pher_info->pher_infor_buf[MCU_QSPI_1].pher_speed=1;//dummy
	obc_get_int_pher_info->pher_infor_buf[MCU_USB_1].pher_id=0x61;
	obc_get_int_pher_info->pher_infor_buf[MCU_USB_1].pher_speed=1;;//dummy
	obc_get_int_pher_info->pher_infor_buf[MCU_ETH_1].pher_id=0x71;
	obc_get_int_pher_info->pher_infor_buf[MCU_ETH_1].pher_speed=1;//dummy
	//ethernet-100MHz
	//usb - full speed mode-dev mode
	status = TCTM_OK;
	return status;

}

int8 obc_tm_get_mcu_ext_pher_info_enc(obc_get_ext_pher_info_s *obc_get_ext_pher_info)
{
	int8 status;
	obc_get_ext_pher_info->pheripheral_cnt=MAX_EXT_PHER_CNT;
	obc_get_ext_pher_info->pher_infor_buf[0].pher_speed=1;//dummy
	obc_get_ext_pher_info->pher_infor_buf[0].pher_id=0x61;
	//gpio exp - no speed
	status = TCTM_OK;
	return status;

}




