

/****************************************************************** 
*  Copyright (C) 2023 - 2023 OneChip, Inc. All rights reserved.
* File name: onechip_load_inf.c	
* Author: fanyidong 	 Date:2023.11.21 
* Description:		加载设备基本信息
* Others:
* History:	
	1. Date: 
		 Author: 
		 Modification:

*****************************************************************/
#include <stdio.h>
#include <string.h>

#include "onechip_include_header.h"
#include "one_chip_git_inf.h"


/*命令种类*/

#define PROTOCOVER  PROTOCOVERDEF(001)
#define DEVICENAME DEVICENAMEDEF(demo)

#define VERINFO_ADDR_BASE   (0x801FF00) //存放FLASH的地址 
#define STR1(R)  #R
#define STR2(R)  STR1(R)

const char Software_Ver[] __attribute__((at(VERINFO_ADDR_BASE + 0x00)))  = "Soft: " STR2(SOFT_VERSION_1) "." STR2(SOFT_VERSION_2) "." STR2(SOFT_VERSION_3) "." STR2(SOFT_VERSION_4);
const char Compiler_Date[] __attribute__((at(VERINFO_ADDR_BASE + 0x10))) = "Time: " __DATE__  "-" __TIME__;
#ifdef ONE_CHIP_GIT_SHA_SHORT
const char git_sha[] __attribute__((at(VERINFO_ADDR_BASE + 0x30))) = "SHA: " ONE_CHIP_GIT_SHA_SHORT;
#endif  

/**********************************************************************************
Func	Name: dev_load_allinf
Descriptions: 加载单板标记
Input	para: 无
In&Out	Para: 无
Output	para: 无
Return value: 无
***********************************************************************************/
void dev_load_description (void)
{
// 	unsigned int readAddr;
// 	readAddr = EEPROM_ADDR_VERSION_ADDR;	
//     // AT24CXX_Read(readAddr, (uint8_t *)&sysinf.devdesc.desversion,sizeof(DeviceBasicInfdef));	
	
// //	Van_Device_Printf(VAN_LOG_CRITICAL, "2  deveice_typer:%x structure_type:%d  hardware_type:%d  \n\r",sysinf.devdesc.deveice_type,sysinf.devdesc.structure_type,sysinf.devdesc.hardware_type);
// 	if(sysinf.devdesc.deveice_type ==  deviceType_deviceNocfg || sysinf.devdesc.deveice_type > deviceType_deviceBoard_V1 ){
// 	sysinf.devdesc.deveice_type = deviceType_deviceNocfg;
// #if defined(DEVICETYPE_IS_ETA)
// 	sysinf.devdesc.deveice_type = deviceType_deviceETA_004;
// 	sysinf.devdesc.structure_type = structureType_structure1_6;
// 	sysinf.devdesc.hardware_type = hardwareType_hardware1_0;	
// 	sysinf.devdesc.deveice_ver = 0;
// 	sysinf.devdesc.structure_ver = 0;
// 	sysinf.devdesc.hardware_ver = 0;	
// 	memset(sysinf.devdesc.serialNumber, 0, 16);
// #elif defined(DEVICETYPE_IS_ATCG)
	 sysinf.devdesc.deveice_type = ONECHIP_MINI7_V2;
	 sysinf.devdesc.structure_type = ONECHIP_SATRUCTURE_VERSION_V0_1;
	 sysinf.devdesc.hardware_type = ONECHIP_HARDWARE_VERSION_V0_1;	
	sysinf.devdesc.deveice_ver = 0;
	sysinf.devdesc.structure_ver = 0;
	sysinf.devdesc.hardware_ver = 0;	
	
	// strcpy(sysinf.wifiname, onechip_name);
	// strcpy(sysinf.password, onechip_pswd);
	// strcpy(sysinf.TCP_IP_Addr, "192.168.43.229");
// 	memset(sysinf.devdesc.serialNumber, 0, 16);
// #endif
// 	}
	
}

/**********************************************************************************
Func	Name: dev_save_description
Descriptions: 保持
Input	para: 无
In&Out	Para: 无
Output	para: 无
Return value: 无
***********************************************************************************/
void dev_save_description (void)
{  
	// unsigned int writeAddr;
	// writeAddr = EEPROM_ADDR_VERSION_ADDR;
	// unsigned int softver = (SOFT_VERSION_1 << 24) | (SOFT_VERSION_2 << 16) | (SOFT_VERSION_3 << 8) | (SOFT_VERSION_4);
	// Van_Device_Printf(VAN_LOG_CRITICAL, "soft ver:%x\n\r",softver);
	
	// Van_Device_Printf(VAN_LOG_CRITICAL, "1   deveice_typer:%x structure_type:%d  hardware_type:%d  \n\r",sysinf.devdesc.deveice_type,sysinf.devdesc.structure_type,sysinf.devdesc.hardware_type);
    // // AT24CXX_Write(writeAddr, (unsigned char *)&sysinf.devdesc.desversion,sizeof(DeviceBasicInfdef));
	// osDelay(10U);
	// dev_load_description();	
	// Van_Device_Printf(VAN_LOG_CRITICAL, "3  deveice_typer:%x structure_type:%d  hardware_type:%d  \n\r",sysinf.devdesc.deveice_type,sysinf.devdesc.structure_type,sysinf.devdesc.hardware_type);	
}

/**********************************************************************************
Func	Name: dev_save_description
Descriptions: 保持
Input	para: 无
In&Out	Para: 无
Output	para: 无
Return value: 无
***********************************************************************************/
void cfg_dev_description (unsigned int dev,unsigned int strtype,unsigned int hdtype,unsigned int devver,unsigned int strver,unsigned int hdver)
{  
	// unsigned int writeAddr;
	// writeAddr = EEPROM_ADDR_VERSION_ADDR;
	// unsigned int softver = (SOFT_VERSION_1 << 24) | (SOFT_VERSION_2 << 16) | (SOFT_VERSION_3 << 8) | (SOFT_VERSION_4);
	// Van_Device_Printf(VAN_LOG_CRITICAL, "soft ver:%x\n\r",softver);
	// sysinf.devdesc.desversion = 0xaa079055;
    // sysinf.devdesc.deveice_type = dev;
    // sysinf.devdesc.structure_type = strtype;
    // sysinf.devdesc.hardware_type = hdtype;
    // sysinf.devdesc.deveice_ver = devver;
    // sysinf.devdesc.structure_ver = strver;
    // sysinf.devdesc.hardware_ver = hdver;
	
	// Van_Device_Printf(VAN_LOG_CRITICAL, "1   deveice_typer:%x structure_type:%d  hardware_type:%d  \n\r",sysinf.devdesc.deveice_type,sysinf.devdesc.structure_type,sysinf.devdesc.hardware_type);
    // AT24CXX_Write(writeAddr, (unsigned char *)&sysinf.devdesc.desversion,sizeof(DeviceBasicInfdef));
	// osDelay(10U);
	// dev_load_description();	
	// Van_Device_Printf(VAN_LOG_CRITICAL, "3  deveice_typer:%x structure_type:%d  hardware_type:%d  \n\r",sysinf.devdesc.deveice_type,sysinf.devdesc.structure_type,sysinf.devdesc.hardware_type);	
}



/**********************************************************************************
Func	Name: dev_load_allinf
Descriptions: 加载单板标记
Input	para: 无
In&Out	Para: 无
Output	para: 无
Return value: 无
***********************************************************************************/
void dev_load_allinf (void)
{

	dev_load_description();	
	sysinf.com_led_pin = MINI7_V2_SYS_R_Pin;	
	sysinf.com_led_port = MINI7_V2_SYS_R_GPIO_Port;	
	sysinf.run_led_pin = MINI7_V2_SYS_B_Pin;	
	sysinf.run_led_port = MINI7_V2_SYS_B_GPIO_Port;	
	sysinf.rgb_band_pin = MINI7_V2_indicator_light_Pin;	
	sysinf.rgb_band_port = MINI7_V2_indicator_light_GPIO_Port;
	sysinf.ms_conter = 0;
}

/**********************************************************************************
Func	Name: con_sysinf_debugUart
Descriptions: 设置调试串口
Input	para: 无
In&Out	Para: 无
Output	para: 无
Return value: 无
***********************************************************************************/
void con_sysinf_debugUart(void * uart)
{
	sysinf.debugUart =  uart;
}

/**********************************************************************************
Func	Name: dev_load_function
Descriptions: 根据单板类型，添加功能
Input	para: 无
In&Out	Para: 无
Output	para: 无
Return value: 无
***********************************************************************************/
void dev_load_function (void)
{
	//Motor_Load_cfg(&sysinf.devdesc);
  //  loadIOStateCfg(&sysinf.devdesc);
  //  loadProportiona_valveCfg(&sysinf.devdesc);
	//onechip_pose_load_config(&sysinf.devdesc);
//	load_com_pwm_Cfg(&sysinf.devdesc);
//	onechip_adp_load_config(&sysinf.devdesc);
}


/**********************************************************************************
Func	Name: dev_load_function_after_os
Descriptions: 系统启动后，再加载组件
Input	para: 无
In&Out	Para: 无
Output	para: 无
Return value: 无
***********************************************************************************/
void dev_load_function_after_os (void)
{

#ifdef USE_CAN_DEVICE
	onechip_can_dev_config();
    osDelay(10U);
	if(((sysinf.devdesc.deveice_type == deviceType_deviceETA_004)||
		(sysinf.devdesc.deveice_type == deviceType_deviceETA_S4))
		&&(sysinf.devdesc.structure_type == structureType_structure1_6||
		sysinf.devdesc.structure_type == structureType_structure1_5)){
		loadKEYTO_5A33Cfg(&sysinf.devdesc);
		loadKEYTO_G31xCfg(&sysinf.devdesc);
	}	
	if(((sysinf.devdesc.deveice_type == deviceType_deviceETA_004)||
		(sysinf.devdesc.deveice_type == deviceType_deviceETA_S4))
		&&sysinf.devdesc.structure_type == structureType_structure1_6){
		loadKEYTO_G_LHHCCfg(&sysinf.devdesc);
	}	
#endif //define (USE_CAN_DEVICE)		
 //   loadPidCfg(&sysinf.devdesc);
}


