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

#ifndef EXO_CORE_OBC_INC_OBC_MCU_INFO_H_
#define EXO_CORE_OBC_INC_OBC_MCU_INFO_H_

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <exo_types.h>

#define MAX_INT_PHER_CNT 11
#define MAX_EXT_PHER_CNT 1
#define MCU_EXT_MEM_MAX_CNT 3


typedef struct
{
    uint8_t dev_id;
    uint8_t temp;
}mcu_get_temp_s;

typedef struct
{
    uint8_t dev_id;
    uint32_t mcu_uptime;
    uint32_t epoch_time;
}mcu_get_time_s;

typedef struct
{
    uint8_t dev_id;
    char processor_name[50];
//    char chip_id[2];
    uint16_t chip_id;
    uint32_t clock_speed;
    uint8_t cores;
    uint32_t cache_size;
}__attribute__((__packed__))mcu_get_chip_info_s;
/*
typedef struct
{
    uint8_t dev_id;
    uint32_t eram_tot_mem;
    uint32_t eram_used_mem;
    uint32_t flash_qspi_tot_mem;
    uint32_t flash_qspi_used_mem;
    uint32_t flash_fmc_tot_mem;
    uint32_t flash_fmc_used_mem;
}obc_get_ext_mem_s;
*/
typedef struct
{
    uint32_t iram_tot_mem;
    uint32_t iram_used_mem;
    uint32_t iram_free_mem;
}obc_get_int_mem_s;
/*
typedef struct
{
    uint8_t dev_id;
    uint64_t tot_mem;
    uint64_t available_mem;
    uint64_t free_mem;
}ps_get_ext_mem_s;
*/
typedef struct
{
    uint64_t tot_mem;
    uint64_t used_mem;
    uint64_t free_mem;
}__attribute__((__packed__))ext_mem_info_s;

typedef struct
{
    uint8_t dev_id;
    uint32_t mem_cnt;
    ext_mem_info_s ext_mem_info[MCU_EXT_MEM_MAX_CNT];
}__attribute__((__packed__))mcu_get_ext_mem_s;
/*
typedef struct
{
    uint8_t dev_id;
    uint32_t clock_speed;
    uint8_t cores;
    uint32_t cache_size;
}ps_get_feature_s;
*/
typedef struct
{
	uint8_t  pher_id;
	uint16_t pher_speed;
	//uint8_t  curnt_active_sts;
	//uint16_t error_count;
}__attribute__((__packed__))pher_infor_buf_s;

typedef struct
{
    //uint8_t dev_id;
    uint32_t pheripheral_cnt;
    pher_infor_buf_s pher_infor_buf[MAX_INT_PHER_CNT];
}__attribute__((__packed__))obc_get_int_pher_info_s;

typedef struct
{
    //uint8_t dev_id;
    uint32_t pheripheral_cnt;
    pher_infor_buf_s pher_infor_buf[MAX_EXT_PHER_CNT];
}__attribute__((__packed__))obc_get_ext_pher_info_s;


typedef enum
{
	MCU_CAN_2=0,
	MCU_SPI_1,
	MCU_I2C_2,
	MCU_I2C_3,
	MCU_I2C_4,
	MCU_UART_4,
	MCU_UART_5,
	MCU_FMC_1,
	MCU_QSPI_1,
	MCU_USB_1,
	MCU_ETH_1
}mcu_int_pher_e;

typedef enum
{
	MCU_ERAM,
	MCU_FLASH_FMC,
	MCU_FLASH_QSPI
}mcu_ext_mem_e;



int16 obc_get_dev_temp_info_dec(uint8 *data);
int16 obc_get_dev_time_info_dec(uint8 *data);
int16 obc_get_dev_chip_info_dec(uint8 *data);
int16 obc_get_dev_ext_mem_dec(uint8 *data);
//int16 obc_get_dev_int_pher_info_dec(uint8 *data);
//int16 obc_get_dev_ext_pher_info_dec(uint8 *data);
//int16 obc_get_dev_get_rst_info_dec(uint8 *data);

int8 obc_tm_get_temp_enc(uint8_t *temp);
int8 obc_tm_get_time_enc(uint32_t *epoch_time);
int8 obc_tm_get_mcu_info_enc(mcu_get_chip_info_s *mcu_get_chip_info,uint8_t id);
int8 obc_tm_get_mcu_ext_mem_info_enc(mcu_get_ext_mem_s *mcu_get_ext_mem,uint8_t id);
int8 obc_tm_get_mcu_int_mem_info_enc(obc_get_int_mem_s *obc_get_int_mem);
int8 obc_tm_get_mcu_int_pher_info_enc(obc_get_int_pher_info_s *obc_get_int_pher_info);
int8 obc_tm_get_mcu_ext_pher_info_enc(obc_get_ext_pher_info_s *obc_get_ext_pher_info);




#endif /* EXO_CORE_OBC_INC_OBC_MCU_INFO_H_ */
