Jelajahi Sumber

新增内置电源管理相关的端口配置

BJQX-ZHENGCHAO\Zhengchao 1 tahun lalu
induk
melakukan
4be086924b

+ 3 - 3
.cproject

@@ -30,8 +30,8 @@
 							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.64147430" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
 							<builder buildPath="${workspace_loc:/S32K146_4G}/Debug_FLASH" id="com.freescale.s32ds.cross.gnu.builder.466747471" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="FSL Make Builder" superClass="com.freescale.s32ds.cross.gnu.builder"/>
 							<tool id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.tool.c.compiler.1980082058" name="Standard S32DS C Compiler" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.tool.c.compiler">
-								<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.1168627068" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.c.optimization.level.size" valueType="enumerated"/>
-								<option defaultValue="gnu.c.debugging.level.max" id="gnu.c.compiler.option.debugging.level.1120041103" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
+								<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.1168627068" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.c.optimization.level.none" valueType="enumerated"/>
+								<option defaultValue="gnu.c.debugging.level.max" id="gnu.c.compiler.option.debugging.level.1120041103" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
 								<option id="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.optimization.functionsections.1916093778" name="Function sections (-ffunction-sections)" superClass="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.optimization.functionsections" useByScannerDiscovery="true" value="false" valueType="boolean"/>
 								<option id="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.optimization.datasections.499071697" name="Data sections (-fdata-sections)" superClass="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.optimization.datasections" useByScannerDiscovery="true" value="false" valueType="boolean"/>
 								<option id="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.debugging.format.155687014" name="Debug format" superClass="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.debugging.format" useByScannerDiscovery="true"/>
@@ -150,7 +150,7 @@
 							<tool id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.archiver.50914677" name="Standard S32DS Archiver" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.archiver"/>
 							<tool id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.339533218" name="Standard S32DS Assembler" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler">
 								<option id="com.freescale.s32ds.cross.gnu.tool.assembler.usepreprocessor.608521688" name="Use preprocessor" superClass="com.freescale.s32ds.cross.gnu.tool.assembler.usepreprocessor" useByScannerDiscovery="false" value="true" valueType="boolean"/>
-								<option defaultValue="gnu.c.debugging.level.max" id="com.freescale.s32ds.cross.gnu.tool.assembler.option.debugging.level.935781758" name="Debug Level" superClass="com.freescale.s32ds.cross.gnu.tool.assembler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
+								<option defaultValue="gnu.c.debugging.level.max" id="com.freescale.s32ds.cross.gnu.tool.assembler.option.debugging.level.935781758" name="Debug Level" superClass="com.freescale.s32ds.cross.gnu.tool.assembler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.libraries.2115819142" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.libraries.newlib_nano_noio" valueType="enumerated"/>
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.sysroot.1519150514" name="Sysroot" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.sysroot" useByScannerDiscovery="false" value="--sysroot=&quot;${S32DS_ARM32_NEWLIB_DIR}&quot;" valueType="string"/>
 								<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.both.asm.option.include.paths.763521555" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" useByScannerDiscovery="false" valueType="includePath">

+ 12 - 17
Project_Settings/Linker_Files/linker_flash_s32k146.ld

@@ -31,18 +31,13 @@
 
 MEMORY
 {         
-    int_flash_interrupts    : ORIGIN = 0x00014200, LENGTH = 0x00000400    /* 1K */    /* Do not change this section */
-   /* int_flash_config        : ORIGIN = 0x00000400, LENGTH = 0x00000010    /* 16bytes */ /* Do not change this section */
-     int_flash               : ORIGIN = 0x00014600, LENGTH = 0x000EBA00    /* ~1.0MB */ 
-/*	int_flash_interrupts    : ORIGIN = 0x00080200, LENGTH = 0x00000400	/**/
-/*	int_flash               : ORIGIN = 0x00080600, LENGTH = 0x0007FA00	/**/
-	
-	m_flexram				: ORIGIN = 0x14000000, LENGTH = 0x00001000	
+    int_flash_interrupts    : ORIGIN = 0x00000000, LENGTH = 0x00000400    /* 1K */    /* Do not change this section */
+    int_flash_config        : ORIGIN = 0x00000400, LENGTH = 0x00000010    /* 16bytes */ /* Do not change this section */
+    int_flash               : ORIGIN = 0x00000410, LENGTH = 0x000FFBF0    /* ~1.0MB */ 
     int_sram_results        : ORIGIN = 0x1FFF0000, LENGTH = 0x00000100    /* 256bytes */
     int_sram                : ORIGIN = 0x1FFF0100, LENGTH = 0x0001DF00    /* ~120K */
-    int_sram_stack_c0       : ORIGIN = 0x2000E000, LENGTH = 0x00001000 - 0x10    /* 4K  */
-    ram_rsvd2               : ORIGIN = 0x2000EFF0, LENGTH = 0             /* End of SRAM */
-    ExchangeInfo            : ORIGIN = 0x2000EFF0, LENGTH = 0x10          
+    int_sram_stack_c0       : ORIGIN = 0x2000E000, LENGTH = 0x00001000    /* 4K  */
+    ram_rsvd2               : ORIGIN = 0x2000F000, LENGTH = 0             /* End of SRAM */
 }
 
 
@@ -56,19 +51,20 @@ SECTIONS
    {						
     	*(.eeprom)			
     } >m_flexram			
+    
 	.flash_interrupts :
 	{
-		. = ALIGN(512);
+		. = ALIGN(4096);
         __interrupts_rom_start = .;
         KEEP(*(.intc_vector))    
-        . = ALIGN(512);
+        . = ALIGN(4);
         __interrupts_rom_end = .;
 	} > int_flash_interrupts
 	
-/*	.flash_config :				*/
-/*	{							*/
-/*		KEEP(*(.flash_config))	*/
-/*	} > int_flash_config		*/
+	.flash_config :
+	{
+		KEEP(*(.flash_config))
+	} > int_flash_config
 	
 	.flash :
 	{
@@ -115,7 +111,6 @@ SECTIONS
 		__DATA_ROM = .;
 	} > int_flash
     
-    
     . = ALIGN(4);
     PROVIDE(__exidx_start = .);
     .ARM.exidx :

+ 17 - 12
Project_Settings/Linker_Files/linker_flash_s32k146.ldlocal → Project_Settings/Linker_Files/linker_flash_s32k146.ldota

@@ -31,13 +31,18 @@
 
 MEMORY
 {         
-    int_flash_interrupts    : ORIGIN = 0x00000000, LENGTH = 0x00000400    /* 1K */    /* Do not change this section */
-    int_flash_config        : ORIGIN = 0x00000400, LENGTH = 0x00000010    /* 16bytes */ /* Do not change this section */
-    int_flash               : ORIGIN = 0x00000410, LENGTH = 0x000FFBF0    /* ~1.0MB */ 
+    int_flash_interrupts    : ORIGIN = 0x00014200, LENGTH = 0x00000400    /* 1K */    /* Do not change this section */
+   /* int_flash_config        : ORIGIN = 0x00000400, LENGTH = 0x00000010    /* 16bytes */ /* Do not change this section */
+     int_flash               : ORIGIN = 0x00014600, LENGTH = 0x000EBA00    /* ~1.0MB */ 
+/*	int_flash_interrupts    : ORIGIN = 0x00080200, LENGTH = 0x00000400	/**/
+/*	int_flash               : ORIGIN = 0x00080600, LENGTH = 0x0007FA00	/**/
+	
+	m_flexram				: ORIGIN = 0x14000000, LENGTH = 0x00001000	
     int_sram_results        : ORIGIN = 0x1FFF0000, LENGTH = 0x00000100    /* 256bytes */
     int_sram                : ORIGIN = 0x1FFF0100, LENGTH = 0x0001DF00    /* ~120K */
-    int_sram_stack_c0       : ORIGIN = 0x2000E000, LENGTH = 0x00001000    /* 4K  */
-    ram_rsvd2               : ORIGIN = 0x2000F000, LENGTH = 0             /* End of SRAM */
+    int_sram_stack_c0       : ORIGIN = 0x2000E000, LENGTH = 0x00001000 - 0x10    /* 4K  */
+    ram_rsvd2               : ORIGIN = 0x2000EFF0, LENGTH = 0             /* End of SRAM */
+    ExchangeInfo            : ORIGIN = 0x2000EFF0, LENGTH = 0x10          
 }
 
 
@@ -51,20 +56,19 @@ SECTIONS
    {						
     	*(.eeprom)			
     } >m_flexram			
-    
 	.flash_interrupts :
 	{
-		. = ALIGN(4096);
+		. = ALIGN(512);
         __interrupts_rom_start = .;
         KEEP(*(.intc_vector))    
-        . = ALIGN(4);
+        . = ALIGN(512);
         __interrupts_rom_end = .;
 	} > int_flash_interrupts
 	
-	.flash_config :
-	{
-		KEEP(*(.flash_config))
-	} > int_flash_config
+/*	.flash_config :				*/
+/*	{							*/
+/*		KEEP(*(.flash_config))	*/
+/*	} > int_flash_config		*/
 	
 	.flash :
 	{
@@ -111,6 +115,7 @@ SECTIONS
 		__DATA_ROM = .;
 	} > int_flash
     
+    
     . = ALIGN(4);
     PROVIDE(__exidx_start = .);
     .ARM.exidx :

+ 14 - 2
code/app/AppGlobalVar.c

@@ -16,9 +16,9 @@
 
 #include "AppGlobalVar.h"
 
-#define defaultSn "ZLTEST00000000002"
+#define defaultSn "ZLTEST00000000003"
 
-#define APP_RELEASE
+//#define APP_RELEASE
 
 #ifdef APP_RELEASE
 const char WebSiteName[] = "\"iotp.fast-fun.cn\"";
@@ -49,6 +49,18 @@ uint16 WebSitePort = 8812;
 #include "Eep_MemMap.h"
 AppConfigBody AppConfigInfo = {false, true, {defaultSn}, {0}};
 BcuSaveType BcuSaveDataInfo = {0};
+BcuAppSaveBody BcuAppSaveDataInfoDefaultValue =
+{
+		//uint8 1*16
+		0,23,01,01,0,0,0,0,
+		0,0,0,0,0,0,0,0,
+		//uint16 2*8
+		0,0,0,0,0,0,0,0,
+		//float 4*24
+		0,0,100,0,0,0,0,0,
+		0,0,0,0,0,0,0,0,
+		0,0,0,0,0,0,0,0
+};
 #define EEP_STOP_SEC_VAR_INIT_8_NO_CACHEABLE
 #include "Eep_MemMap.h"
 #endif

+ 1 - 1
code/app/AppTaskUart1.c

@@ -1756,7 +1756,7 @@ uint16 tcpUdsFunc(uint8 *Ptr, uint8 *AnsPtr)
 					case 0x0202:  //soh correction did
 					{
 
-						if(udsDataLen == 1)
+						if(udsDataLen == 2)
 						{
 							float sohCorrectionValue = (float)((float)((DataBuffer[0]<<8 | DataBuffer[1])&0xFFFF)*0.1);
 							if(sohCorrectionValue > 0 && sohCorrectionValue<100)  //有效修正

+ 398 - 0
code/app/lib/hal_sy6970.c

@@ -0,0 +1,398 @@
+#include "hal_sy6970.h"
+
+#define __nop() __asm__("NOP")
+
+#define GPIO_SDA	DioConf_DioChannel_PTA10_GPIO_IN_OUT_MCU_BATT_IIC_SDA
+#define GPIO_SCL    DioConf_DioChannel_PTC5_GPIO_IN_OUT_MCU_BATT_IIC_SCK
+
+#define READ_SDA4   Dio_ReadChannel(GPIO_SDA)
+
+#define GPIO_SETPIN(channel)  	Dio_WriteChannel(channel,1)
+#define GPIO_RESETPIN(channel)  Dio_WriteChannel(channel,0)
+
+
+#define IIC_SDA4(n) (n?GPIO_SETPIN(GPIO_SDA):GPIO_RESETPIN(GPIO_SDA))
+#define IIC_SCL4(n) (n?GPIO_SETPIN(GPIO_SCL):GPIO_RESETPIN(GPIO_SCL))
+
+
+
+#define sy6970_speed 5
+ 
+//需要示波器调1us的时间
+static void delay_us(uint16_t time)
+{
+	uint16_t i;
+
+	for(i=time;i>0;i--)
+	{
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();		
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+		__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
+	}
+}
+
+//static void iic4_init(void)
+//{
+//	stc_gpio_init_t  pstcGpioInit1;
+//	GPIO_StructInit(&pstcGpioInit1);
+//
+//	pstcGpioInit1.u16PinDir = PIN_DIR_OUT;
+//	pstcGpioInit1.u16PinState = PIN_STAT_RST;
+//	GPIO_Init(GPIO_PORT_A, GPIO_PIN_11,&pstcGpioInit1);
+//	GPIO_Init(GPIO_PORT_A, GPIO_PIN_12,&pstcGpioInit1);
+//
+//	GPIO_SetPins(GPIO_PORT_A, GPIO_PIN_11);
+//	GPIO_SetPins(GPIO_PORT_A, GPIO_PIN_12);
+//}
+
+//void sy6970_init(void)
+//{
+//	 iic4_init();
+//}
+
+static void SDA_IN4(void)
+{
+//	 stc_gpio_init_t pstcGpioInit3;//iic的引脚
+//	 pstcGpioInit3.u16PinDir = PIN_DIR_IN;
+//	 //pstcGpioInit3.u16PinInputType = PIN_PU_ON;
+//	 GPIO_Init(GPIO_PORT_A, GPIO_PIN_12,&pstcGpioInit3);
+	Port_SetPinDirection(PortConfigSet_PortContainer_GPIO_PTA10_GPIO_IN_OUT_MCU_BATT_IIC_SDA,PORT_CI_PORT_PIN_IN);
+	//????Port_SetPinDirection(GPIO_SDA,PORT_CI_PORT_PIN_IN);
+}
+
+static void SDA_OUT4(void)  
+{
+//	stc_gpio_init_t pstcGpioInit3;
+//	pstcGpioInit3.u16PinDir = PIN_DIR_OUT;
+//	pstcGpioInit3.u16PinOutputType=PIN_OUT_TYPE_NMOS;
+//	GPIO_Init(GPIO_PORT_A, GPIO_PIN_12,&pstcGpioInit3);
+	Port_SetPinDirection(PortConfigSet_PortContainer_GPIO_PTA10_GPIO_IN_OUT_MCU_BATT_IIC_SDA,PORT_CI_PORT_PIN_OUT);
+	//????Port_SetPinDirection(GPIO_SDA,PORT_CI_PORT_PIN_OUT);
+}	
+ 
+ 
+
+static void iic_start(void)
+{
+	SDA_OUT4();
+	
+	IIC_SDA4(1);
+	IIC_SCL4(1);
+	delay_us(sy6970_speed);
+	
+	IIC_SDA4(0);
+	delay_us(sy6970_speed);
+	IIC_SCL4(0);
+}
+
+
+static void iic_stop(void)
+{
+	SDA_OUT4();
+	
+	IIC_SCL4(0);
+	IIC_SDA4(0);
+	delay_us(sy6970_speed);
+	
+	IIC_SCL4(1);
+	IIC_SDA4(1);
+	delay_us(sy6970_speed);
+}
+
+static void iic_ack(void)
+{
+	SDA_OUT4();
+	
+	IIC_SCL4(0);
+	IIC_SDA4(0);
+	delay_us(sy6970_speed);
+	
+	IIC_SCL4(1);
+	delay_us(sy6970_speed);
+	IIC_SCL4(0);
+}
+
+static void iic_nack(void)
+{
+	SDA_OUT4();
+	
+	IIC_SCL4(0);
+	IIC_SDA4(1);
+	delay_us(sy6970_speed);
+	
+	IIC_SCL4(1);
+	delay_us(sy6970_speed);
+	IIC_SCL4(0);
+}
+ 
+
+static uint8_t iic_wait_ack(void)
+{
+	uint16_t t =200;
+	SDA_OUT4();
+	
+	IIC_SDA4(1);delay_us(1);
+	IIC_SCL4(1);delay_us(1);
+
+	SDA_IN4();
+
+	while(READ_SDA4) 
+	{
+		t--;
+		
+		if(t==0)
+		{
+			iic_stop();
+			return 1;
+		}
+		delay_us(1);
+	}
+	IIC_SCL4(0);
+		
+	return 0;
+}
+
+
+static void iic_send_byte(uint8_t byte)
+{
+  uint8_t bit_cnt;
+	SDA_OUT4();
+	IIC_SCL4(0);
+	 
+	for(bit_cnt=0;bit_cnt<8;bit_cnt++)
+	{	 
+		if(byte&0x80)	
+			IIC_SDA4(1); 
+		else	
+			IIC_SDA4(0);
+		
+		byte<<=1;
+		delay_us(sy6970_speed);
+		IIC_SCL4(1);
+		delay_us(sy6970_speed);
+		IIC_SCL4(0);
+	}	
+}
+ 
+
+static uint8_t iic_recive_byte(unsigned char ack)
+{
+  uint8_t retc = 0;
+  uint8_t bit_cnt;
+
+	SDA_IN4(); 
+	delay_us(1);
+	
+	for(bit_cnt=0;bit_cnt<8;bit_cnt++)
+	{
+		IIC_SCL4(0);
+		delay_us(sy6970_speed);
+		IIC_SCL4(1);
+		
+		retc=retc<<1;
+		
+		if(READ_SDA4)
+			retc++;
+		
+		delay_us(sy6970_speed);
+	}
+ 
+	return(retc);
+}
+ 
+ 
+
+static void sy6970_write_byte(uint8_t dev_addr,uint8_t RAddr, uint8_t WData)
+{
+  iic_start();								 		 
+  iic_send_byte(dev_addr); 
+  iic_wait_ack();							 		 	
+  iic_send_byte(RAddr);   		 		 
+  iic_wait_ack(); 	 					 		 				  		   
+  iic_send_byte(WData);      		 				   
+  iic_wait_ack();  		    	   		 		 
+  iic_stop();									 		 
+}
+ 
+
+static void sy6970_read_byte(uint8_t dev_addr,uint8_t RAddr, uint8_t *RData)
+{
+  iic_start();								 		 
+  iic_send_byte(dev_addr); 
+  iic_wait_ack();  						 		 
+  iic_send_byte(RAddr);   		 		 
+  iic_wait_ack();	    				 		 
+  iic_start();  	 	   				 		 
+  iic_send_byte(dev_addr|0x01);    
+  iic_wait_ack();	 						 		 	
+  *RData = iic_recive_byte(0);	 		    
+  iic_stop();									 		 	
+}
+
+
+  
+ 
+_Bool sy6970_write_bytes ( unsigned char SlaveAddr, unsigned char RegAddr, unsigned char *Buf, unsigned char Num )
+{
+	iic_start();						//起始信号
+	//发送设备地址(写)
+	iic_send_byte ( SlaveAddr );	//等待应答
+	iic_wait_ack(); 
+
+	//发送寄存器地址
+	iic_send_byte ( RegAddr ) ;	//等待应答
+	iic_wait_ack(); 
+	while ( Num-- )								//循环写入数据
+	{
+		//发送数据
+		iic_send_byte ( *Buf );	//等待应答
+		iic_wait_ack(); 
+		Buf++;									//数据指针偏移到下一个
+		delay_us(10);
+	}
+	iic_stop();							//停止信号
+	return 0;
+}
+
+
+
+ 
+_Bool sy6970_read_bytes ( unsigned char SlaveAddr, unsigned char RegAddr, unsigned char *Buf, unsigned char Num )
+{
+	iic_start();							//起始信号
+	//发送设备地址(写)
+	iic_send_byte ( SlaveAddr );		//等待应答
+	iic_wait_ack(); 
+	//发送寄存器地址
+	iic_send_byte ( RegAddr );			//等待应答
+	iic_wait_ack(); 
+	iic_start();				   			//重启信号
+	//发送设备地址(读)
+	iic_send_byte ( SlaveAddr + 1 );	//等待应答
+	iic_wait_ack(); 
+	while ( Num-- )
+	{
+		//偏移到下一个数据存储地址
+		if ( Num == 0 )
+		{
+			*Buf = iic_recive_byte ( 0 );	//最后一个数据需要回NOACK
+		}
+		else
+		{
+			*Buf = iic_recive_byte ( 1 );	//回应ACK
+		}
+		Buf++;
+	}
+	iic_stop();
+	return 0;
+}
+
+
+
+
+/**********************************************SY6970 操作函数****************************************************/
+/*
+ * 设置sy6970输入电流的大小
+ *
+ * set_val  需要操作的从机设备
+	Fast Charge Current Limit:
+	ICHG=[ICHG]*64mA
+	Range:0mA(0000000)-5056mA(1001111)
+	0000000=0mA(Disable Charge)
+	0000001=64mA
+	…
+	0100000=2048mA(Default)
+	…
+	1001111~1111111=5056mA
+ *
+ * 返回值:void
+ * */
+void sy6970_set_input_current_limit(uint8_t set_val)
+{
+	set_val&= 0x7F;
+	sy6970_write_byte(SY6970_ADDR,0x04,set_val);
+}
+
+
+
+/*
+ * 设置sy6970输入电压的大小
+ *
+ * set_val  需要操作的从机设备
+  Charge Voltage Limit:
+	VREG=3.840V+[VREG]*16mV
+	Range:3.840V-4.608V(110000)
+	000000=3.840V
+	000001=3.856V
+	…
+	010111=4.208V(Default)
+	…
+	110000~111111=4.608V
+ *
+ * 返回值:void
+ * */
+void sy6970_set_input_voltage_limit(uint8_t set_val)
+{
+	set_val&= 0xFC;
+	sy6970_write_byte(SY6970_ADDR,0x06,set_val);
+}
+
+/*充电使能*/
+void sy6970_charge_enable(void)
+{
+	uint8_t set_val = 0x00;
+	set_val&= 0x01<<4;
+	sy6970_write_byte(SY6970_ADDR,0x03,set_val);
+}
+
+/*充电不使能*/
+void sy6970_charge_disable(void)
+{
+	uint8_t set_val = 0x00;
+	set_val&= 0x00<<4;
+	sy6970_write_byte(SY6970_ADDR,0x03,set_val);
+}
+
+
+/*充电状态查询
+返回值:
+00-Not Charging
+01-Pre-charge (VBAT <VBATLOWV)
+10-Fast Charging
+11-Charge Termination Done
+*/
+uint8_t sy6970_charge_status(void)
+{
+	uint8_t status = 0;
+	sy6970_read_byte(SY6970_ADDR,0x0b,&status);
+	status >>=3;
+	status &=0x03;
+	return status;
+}
+
+uint8_t statusx = 0;
+#include "FreeRTOS.h"
+#include "task.h"
+void sy6970_task(void *argv)
+{
+	while(1)
+	{
+		statusx = sy6970_charge_status();
+		vTaskDelay(500);		
+	}
+}

+ 21 - 0
code/app/lib/hal_sy6970.h

@@ -0,0 +1,21 @@
+#ifndef __HAL_SY6970_H__
+#define __HAL_SY6970_H__
+
+ 
+//#include "hc32_ll_gpio.h"
+//#include "hc32_ll_fcg.h"
+//#include "hc32_ll_interrupts.h"
+//#include "hc32_ll_tmr0.h"
+//#include "ring_buf.h"
+//#include "hc32_ll_aos.h"
+
+#include "port.h"
+#include "dio.h"
+ 
+ 
+#define SY6970_ADDR  0x6A
+  
+void sy6970_init(void);
+uint8_t sy6970_charge_status(void);
+void sy6970_task(void *argv);
+#endif

+ 1 - 1
code/hal/hal_adapter.c

@@ -1323,7 +1323,7 @@ void OH_Data_Update(void)
 	//socd_pct_ekfSoc;			//EKFSOC
 	//socd_pct_battSoc;			//电池SOC
 	//socd_pct_bcuSoc;				//显示SOC
-	BBox_PackSOC 			= (uint8)(socd_pct_ahSoc /0.4);		//安时SOC
+	BBox_PackSOC 			= (uint8)(socd_pct_battSoc /0.4);		//安时SOC->battSoc
 	BBox_PackSOH 			= (uint8)(sohd_pct_bcuSoh);		//Soh
 	BBox_Dq_Dv_MIN 			= (uint32)(socd_Q_dMin * 1000);					//dQ/dV
 	BBox_Dq_Dv_MAX 			= (uint32)(socd_Q_dMax * 1000);					//dQ/dV

+ 40 - 0
generate/include/Dio_Cfg.h

@@ -248,6 +248,30 @@ extern "C" {
 */
 #define  DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY ((uint16)0x0007U)
 
+
+
+/**
+* @brief          Symbolic name for the channel PTA10_GPIO_IN_OUT_MCU_BATT_IIC_SDA.
+*
+*/
+#define  DioConf_DioChannel_PTA10_GPIO_IN_OUT_MCU_BATT_IIC_SDA ((uint16)0x000aU)
+
+
+
+/**
+* @brief          Symbolic name for the channel PTA0_GPIO_IN_MCU_PWR_INPUT_SIGNAL.
+*
+*/
+#define  DioConf_DioChannel_PTA0_GPIO_IN_MCU_PWR_INPUT_SIGNAL ((uint16)0x0000U)
+
+
+
+/**
+* @brief          Symbolic name for the channel PTA1_GPIO_OUT_MCU_BAT_PWR_EN.
+*
+*/
+#define  DioConf_DioChannel_PTA1_GPIO_OUT_MCU_BAT_PWR_EN ((uint16)0x0001U)
+
 /* ---------- DioPort_B ---------- */
 
 /**
@@ -312,6 +336,14 @@ extern "C" {
 */
 #define  DioConf_DioChannel_PTC17_GPIO_OUT_MCU_CAN0_STB ((uint16)0x0051U)
 
+
+
+/**
+* @brief          Symbolic name for the channel PTC5_GPIO_IN_OUT_MCU_BATT_IIC_SCK.
+*
+*/
+#define  DioConf_DioChannel_PTC5_GPIO_IN_OUT_MCU_BATT_IIC_SCK ((uint16)0x0045U)
+
 /* ---------- DioPort_D ---------- */
 
 /**
@@ -409,6 +441,14 @@ extern "C" {
 #define  DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3 ((uint16)0x0087U)
 
 
+
+/**
+* @brief          Symbolic name for the channel PTE10_GPIO_IN_MCU_CHRG_STATE.
+*
+*/
+#define  DioConf_DioChannel_PTE10_GPIO_IN_MCU_CHRG_STATE ((uint16)0x008aU)
+
+
 /*=================================================================================================
 *                                             ENUMS
 =================================================================================================*/

+ 7 - 2
generate/include/Port_Cfg.h

@@ -603,6 +603,11 @@ PORT_CONFIG_VS_0_PB \
 #define PortConfigSet_PortContainer_GPIO_PTD16_GPIO_OUT_MCU_LOW_DRV_EN  39
 #define PortConfigSet_PortContainer_GPIO_PTC17_GPIO_OUT_MCU_CAN0_STB  40
 #define PortConfigSet_PortContainer_GPIO_PTC16_GPIO_OUT_MCU_CAN1_STB  41
+#define PortConfigSet_PortContainer_GPIO_PTA10_GPIO_IN_OUT_MCU_BATT_IIC_SDA  42
+#define PortConfigSet_PortContainer_GPIO_PTC5_GPIO_IN_OUT_MCU_BATT_IIC_SCK  43
+#define PortConfigSet_PortContainer_GPIO_PTA0_GPIO_IN_MCU_PWR_INPUT_SIGNAL  44
+#define PortConfigSet_PortContainer_GPIO_PTA1_GPIO_OUT_MCU_BAT_PWR_EN  45
+#define PortConfigSet_PortContainer_GPIO_PTE10_GPIO_IN_MCU_CHRG_STATE  46
 
 
 /**
@@ -623,12 +628,12 @@ PORT_CONFIG_VS_0_PB \
 /**
 * @brief The maximum number of configured pins
 */
-#define PORT_MAX_CONFIGURED_PADS_U16                        ((uint16)42)
+#define PORT_MAX_CONFIGURED_PADS_U16                        ((uint16)47)
 
 /**
  * @brief Number of UnUsed pin array
 */
-#define PORT_MAX_UNUSED_PADS_U16   (79U)
+#define PORT_MAX_UNUSED_PADS_U16   (76U)
 
 /**
 * @brief Port driver Pre-Compile configuration switch

+ 1 - 1
generate/include/Port_Ci_Port_Ip_Cfg.h

@@ -120,7 +120,7 @@ extern "C"{
 /*! @brief Definitions for BOARD_InitPins Functional Group */
 
 /*! @brief User number of configured pins */
-#define NUM_OF_CONFIGURED_PINS 42
+#define NUM_OF_CONFIGURED_PINS 47
 
 #define PORT_START_SEC_CONFIG_DATA_UNSPECIFIED
 #include "Port_MemMap.h"

+ 65 - 0
generate/src/Port_Ci_Port_Ip_VS_0_PBcfg.c

@@ -631,6 +631,71 @@ const Port_Ci_Port_Ip_PinSettingsConfig g_pin_mux_InitConfigArr_VS_0[NUM_OF_CONF
         .lockRegister                = PORT_LOCK_REGISTER_DISABLED,
         .digitalFilter               = (boolean)FALSE,
         .initValue                   = 1
+    },
+    {
+        .portBase                    = IP_PORTA,
+        .gpioBase                    = IP_PTA,
+        .pinPortIdx                  = 10,
+        .mux                         = PORT_MUX_AS_GPIO,
+        .direction                   = PORT_CI_PORT_PIN_OUT,
+        .pullConfig                  = PORT_INTERNAL_PULL_NOT_ENABLED,
+        .driveStrength               = PORT_DRIVE_STRENGTH_LOW,
+        .passiveFilter               = (boolean)FALSE,
+        .lockRegister                = PORT_LOCK_REGISTER_DISABLED,
+        .digitalFilter               = (boolean)FALSE,
+        .initValue                   = 0
+    },
+    {
+        .portBase                    = IP_PORTC,
+        .gpioBase                    = IP_PTC,
+        .pinPortIdx                  = 5,
+        .mux                         = PORT_MUX_AS_GPIO,
+        .direction                   = PORT_CI_PORT_PIN_OUT,
+        .pullConfig                  = PORT_INTERNAL_PULL_NOT_ENABLED,
+        .driveStrength               = PORT_DRIVE_STRENGTH_LOW,
+        .passiveFilter               = (boolean)FALSE,
+        .lockRegister                = PORT_LOCK_REGISTER_DISABLED,
+        .digitalFilter               = (boolean)FALSE,
+        .initValue                   = 0
+    },
+    {
+        .portBase                    = IP_PORTA,
+        .gpioBase                    = IP_PTA,
+        .pinPortIdx                  = 0,
+        .mux                         = PORT_MUX_AS_GPIO,
+        .direction                   = PORT_CI_PORT_PIN_IN,
+        .pullConfig                  = PORT_INTERNAL_PULL_NOT_ENABLED,
+        .driveStrength               = PORT_DRIVE_STRENGTH_LOW,
+        .passiveFilter               = (boolean)FALSE,
+        .lockRegister                = PORT_LOCK_REGISTER_DISABLED,
+        .digitalFilter               = (boolean)FALSE,
+        .initValue                   = 0
+    },
+    {
+        .portBase                    = IP_PORTA,
+        .gpioBase                    = IP_PTA,
+        .pinPortIdx                  = 1,
+        .mux                         = PORT_MUX_AS_GPIO,
+        .direction                   = PORT_CI_PORT_PIN_OUT,
+        .pullConfig                  = PORT_INTERNAL_PULL_NOT_ENABLED,
+        .driveStrength               = PORT_DRIVE_STRENGTH_LOW,
+        .passiveFilter               = (boolean)FALSE,
+        .lockRegister                = PORT_LOCK_REGISTER_DISABLED,
+        .digitalFilter               = (boolean)FALSE,
+        .initValue                   = 0
+    },
+    {
+        .portBase                    = IP_PORTE,
+        .gpioBase                    = IP_PTE,
+        .pinPortIdx                  = 10,
+        .mux                         = PORT_MUX_AS_GPIO,
+        .direction                   = PORT_CI_PORT_PIN_IN,
+        .pullConfig                  = PORT_INTERNAL_PULL_NOT_ENABLED,
+        .driveStrength               = PORT_DRIVE_STRENGTH_LOW,
+        .passiveFilter               = (boolean)FALSE,
+        .lockRegister                = PORT_LOCK_REGISTER_DISABLED,
+        .digitalFilter               = (boolean)FALSE,
+        .initValue                   = 0
     }
 };
 

+ 16 - 4
generate/src/Port_VS_0_PBcfg.c

@@ -169,6 +169,11 @@ static const uint32 au32Port_PinToPartitionMap_VS_0[PORT_MAX_CONFIGURED_PADS_U16
     (uint32)0x00000001,
     (uint32)0x00000001,
     (uint32)0x00000001,
+    (uint32)0x00000001,
+    (uint32)0x00000001,
+    (uint32)0x00000001,
+    (uint32)0x00000001,
+    (uint32)0x00000001,
     (uint32)0x00000001
 };
 #define PORT_STOP_SEC_CONFIG_DATA_32
@@ -183,8 +188,6 @@ static const uint32 au32Port_PinToPartitionMap_VS_0[PORT_MAX_CONFIGURED_PADS_U16
 */
 static const uint16 Port_au16NoUnUsedPadsArrayDefault_VS_0[PORT_MAX_UNUSED_PADS_U16]=
 {
-    (uint16)0,
-    (uint16)1,
     (uint16)8,
     (uint16)9,
     (uint16)14,
@@ -249,7 +252,6 @@ static const uint16 Port_au16NoUnUsedPadsArrayDefault_VS_0[PORT_MAX_UNUSED_PADS_
     (uint16)131,
     (uint16)136,
     (uint16)137,
-    (uint16)138,
     (uint16)140,
     (uint16)141,
     (uint16)142,
@@ -367,7 +369,17 @@ static const Port_PinConfigType Port_aPinConfigDefault_VS_0[PORT_MAX_CONFIGURED_
     /* PCR Id, PCR Value, Output Level, Direction, IsGpio, Direction Configurable, Mode Changeable */
     {(uint16)81, (uint32)0x00000100, (uint8)1, (Port_PinDirectionType)2, (boolean)TRUE, (boolean)TRUE, (boolean)TRUE},
     /* PCR Id, PCR Value, Output Level, Direction, IsGpio, Direction Configurable, Mode Changeable */
-    {(uint16)80, (uint32)0x00000100, (uint8)1, (Port_PinDirectionType)2, (boolean)TRUE, (boolean)TRUE, (boolean)TRUE}
+    {(uint16)80, (uint32)0x00000100, (uint8)1, (Port_PinDirectionType)2, (boolean)TRUE, (boolean)TRUE, (boolean)TRUE},
+    /* PCR Id, PCR Value, Output Level, Direction, IsGpio, Direction Configurable, Mode Changeable */
+    {(uint16)10, (uint32)0x00000100, (uint8)0, (Port_PinDirectionType)2, (boolean)TRUE, (boolean)TRUE, (boolean)TRUE},
+    /* PCR Id, PCR Value, Output Level, Direction, IsGpio, Direction Configurable, Mode Changeable */
+    {(uint16)69, (uint32)0x00000100, (uint8)0, (Port_PinDirectionType)2, (boolean)TRUE, (boolean)TRUE, (boolean)TRUE},
+    /* PCR Id, PCR Value, Output Level, Direction, IsGpio, Direction Configurable, Mode Changeable */
+    {(uint16)0, (uint32)0x00000100, (uint8)0, (Port_PinDirectionType)1, (boolean)TRUE, (boolean)TRUE, (boolean)TRUE},
+    /* PCR Id, PCR Value, Output Level, Direction, IsGpio, Direction Configurable, Mode Changeable */
+    {(uint16)1, (uint32)0x00000100, (uint8)0, (Port_PinDirectionType)2, (boolean)TRUE, (boolean)TRUE, (boolean)TRUE},
+    /* PCR Id, PCR Value, Output Level, Direction, IsGpio, Direction Configurable, Mode Changeable */
+    {(uint16)138, (uint32)0x00000100, (uint8)0, (Port_PinDirectionType)1, (boolean)TRUE, (boolean)TRUE, (boolean)TRUE}
 
 };