Explorar o código

气动控制盒,第一次提交

guoqiang hai 1 ano
pai
achega
1fc5a062f7

+ 49 - 5
Device/gpio.c

@@ -50,7 +50,7 @@
 
 
 /*************<variable>***************/
-
+uint8_t g_svstatus = 0;
 
 /*************<prototype>**************/
 
@@ -64,7 +64,7 @@
 */
 void GPIO_PortInit(void)
 {
-	
+	/*
 		GPIO_SetFunc(GPIO_CLOSE_KEY, GPIO_FUN0);
 		GPIO_SetFunc(GPIO_OPEN_KEY, GPIO_FUN0);
 		GPIO_SetFunc(GPIO_COVER_KEY, GPIO_FUN0);
@@ -76,10 +76,11 @@ void GPIO_PortInit(void)
 		GPIO_SetPullup(GPIO_CLOSE_KEY, ENABLE);
 		GPIO_SetPullup(GPIO_OPEN_KEY, ENABLE);
 		GPIO_SetPullup(GPIO_COVER_KEY, ENABLE);
+	*/
 	
-	//set pin mux uart0
-    GPIO_SetFunc(GPIOA, GPIO_PIN7, GPIO_FUN1);
-    GPIO_SetFunc(GPIOA, GPIO_PIN8, GPIO_FUN1);
+	//set pin mux uart1
+    GPIO_SetFunc(GPIOA, GPIO_PIN4, GPIO_FUN3);
+    GPIO_SetFunc(GPIOA, GPIO_PIN5, GPIO_FUN3);
 	
 	
 	/*初始化引脚功能,如果引脚上电后默认为GPIO,可省略掉初始化步骤.
@@ -89,8 +90,51 @@ void GPIO_PortInit(void)
 	
 		GPIO_SetFunc(RUNLED_PORT, RUNLED_PIN, GPIO_FUN0);
 		GPIO_SetDir(RUNLED_PORT, RUNLED_PIN, GPIO_OUT);
+		
+		GPIO_SetFunc(SV1_PORT, SV1_PIN, GPIO_FUN0);
+		GPIO_SetDir(SV1_PORT, SV1_PIN, GPIO_OUT);
+		
+		GPIO_SetFunc(SV2_PORT, SV2_PIN, GPIO_FUN0);
+		GPIO_SetDir(SV2_PORT, SV2_PIN, GPIO_OUT);
+		
+		GPIO_SetFunc(SV3_PORT, SV3_PIN, GPIO_FUN0);
+		GPIO_SetDir(SV3_PORT, SV3_PIN, GPIO_OUT);
+		
+		GPIO_SetFunc(SV4_PORT, SV4_PIN, GPIO_FUN0);
+		GPIO_SetDir(SV4_PORT, SV4_PIN, GPIO_OUT);
+		
+		GPIO_SetPinLevel(SV1_PORT, SV1_PIN, SV_CLOSE);
+		GPIO_SetPinLevel(SV2_PORT, SV2_PIN, SV_CLOSE);
+		GPIO_SetPinLevel(SV3_PORT, SV3_PIN, SV_CLOSE);
+		GPIO_SetPinLevel(SV4_PORT, SV4_PIN, SV_CLOSE);
+		
+		g_svstatus = 0x00;
+	
+	
+}
+
+void Sv_Control(uint8_t id, uint8_t action)
+{
+	if(id >= SV_ALL){
+		return ;
+	}
+	
+	if(SV_OPEN == action){
+		g_svstatus |= (1 << id);
 	
+	}else{
+		g_svstatus &= ~(1 << id);
+	}
 	
+	if(SV_01 == id){
+		GPIO_SetPinLevel(SV1_PORT, SV1_PIN, action);
+	}else if(SV_02 == id){
+		GPIO_SetPinLevel(SV2_PORT, SV2_PIN, action);
+	}else if(SV_03 == id){
+		GPIO_SetPinLevel(SV3_PORT, SV3_PIN, action);
+	}else if(SV_04 == id){
+		GPIO_SetPinLevel(SV4_PORT, SV4_PIN, action);
+	}
 }
 
 

+ 26 - 5
Device/gpio.h

@@ -46,9 +46,9 @@ extern "C" {
 /*************<macro>******************/
 
 /* define key gpio */
-#define GPIO_CLOSE_KEY   GPIOA,GPIO_PIN15
-#define GPIO_OPEN_KEY    GPIOA,GPIO_PIN0
-#define GPIO_COVER_KEY   GPIOA,GPIO_PIN1
+//#define GPIO_CLOSE_KEY   GPIOA,GPIO_PIN15
+//#define GPIO_OPEN_KEY    GPIOA,GPIO_PIN0
+//#define GPIO_COVER_KEY   GPIOA,GPIO_PIN1
 
 
 
@@ -59,7 +59,7 @@ extern "C" {
 #define RS485_RX_EN			do{GPIO_SetPinLevel(RS485CTRL_PORT, RS485CTRL_PIN, GPIO_LEVEL_LOW);}while(0)
 
 #define RUNLED_PORT			(GPIOA)
-#define RUNLED_PIN			(GPIO_PIN2)
+#define RUNLED_PIN			(GPIO_PIN0)
 
 /*RUNLED¶¯×÷¶¨Òå.*/	
 #define RUNLED_ON				do{GPIO_SetPinLevel(RUNLED_PORT, RUNLED_PIN, GPIO_LEVEL_HIGH);}while(0)
@@ -67,7 +67,26 @@ extern "C" {
 #define RUNLED_TOGGLE			do{if(GPIO_GetPinLevel(RUNLED_PORT, RUNLED_PIN)){RUNLED_OFF;}else{RUNLED_ON;}}while(0)
 
 
+#define SV1_PORT			(GPIOC)
+#define SV1_PIN			  (GPIO_PIN8)
+#define SV2_PORT			(GPIOC)
+#define SV2_PIN			  (GPIO_PIN7)
+#define SV3_PORT			(GPIOC)
+#define SV3_PIN			  (GPIO_PIN6)
+#define SV4_PORT			(GPIOA)
+#define SV4_PIN			  (GPIO_PIN11)
+
+#define SV_OPEN   (1)
+#define SV_CLOSE  (0)
+
 /*************<enum>*******************/
+enum SV_ID {
+	SV_01 = 0, 
+	SV_02, 
+	SV_03,
+	SV_04,
+	SV_ALL
+};
 
 
 /*************<union>******************/
@@ -77,11 +96,13 @@ extern "C" {
 
 
 /*************<extern>*****************/	
-
+extern uint8_t g_svstatus;
 
 /*************<prototype>**************/
 void GPIO_PortInit(void);
 
+void Sv_Control(uint8_t id, uint8_t action);
+
 #ifdef __cplusplus
 }
 #endif

+ 2 - 2
Device/uart.c

@@ -39,8 +39,8 @@
 
 //#include "Comm.h"
 
-#define UARTx   UART0
-#define UARTx_IRQn  UART0_IRQn
+#define UARTx   UART1
+#define UARTx_IRQn  UART1_IRQn
 
 
 UART_INFO  uart0_info;

+ 1 - 1
Device/watchdog.h

@@ -40,7 +40,7 @@ extern "C" {
 #include "ac780x.h"
 
 
-#define WATCHDOG_ENABLE   (1)  //
+//#define WATCHDOG_ENABLE   (1)  //
 #define WATCHDOG_TIMEOUT  2  // 2s 
 
 

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 83 - 74
Project/AirControlValve.uvguix.孙凯


+ 9 - 1
Project/AirControlValve.uvoptx

@@ -140,7 +140,7 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>JL2CM3</Key>
-          <Name>-U59518874 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(0BC11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO7 -FD20000000 -FC1000 -FN1 -FF0AC780x_128KB.FLM -FS08000000 -FL020000 -FP0($$Device:AC78013MDQA$Flash\AC780x_128KB.FLM)</Name>
+          <Name>-U59518874 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(0BC11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO7 -FD20000000 -FC1000 -FN1 -FF0AC780x_128KB.FLM -FS08000000 -FL010000 -FP0($$Device:AC78013MDQA$Flash\AC780x_128KB.FLM)</Name>
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
@@ -542,6 +542,14 @@
     </File>
   </Group>
 
+  <Group>
+    <GroupName>::Board Support</GroupName>
+    <tvExp>0</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>1</RteFlg>
+  </Group>
+
   <Group>
     <GroupName>::CMSIS</GroupName>
     <tvExp>0</tvExp>

+ 17 - 0
Project/AirControlValve.uvprojx

@@ -530,6 +530,9 @@
             </File>
           </Files>
         </Group>
+        <Group>
+          <GroupName>::Board Support</GroupName>
+        </Group>
         <Group>
           <GroupName>::CMSIS</GroupName>
         </Group>
@@ -549,6 +552,12 @@
           <targetInfo name="AirControlValve"/>
         </targetInfos>
       </component>
+      <component Cbundle="AC780x Development Kit" Cclass="Board Support" Cgroup="AC780x Development Kit" Csub="Debug" Cvendor="AutoChips" Cversion="1.0.0" condition="AC780x Debug Interface">
+        <package name="AC780x_DFP" schemaVersion="1.4" url="http://fex.autochips.com:90/download/CMSIS_PACK/AC7801/" vendor="AutoChips" version="1.0.6"/>
+        <targetInfos>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
       <component Cclass="Device" Cgroup="ATC Drivers" Csub="ACMP" Cvendor="AutoChips" Cversion="1.0.0" condition="AC780x System">
         <package name="AC780x_DFP" schemaVersion="1.4" url="http://fex.autochips.com:90/download/CMSIS_PACK/AC7801/" vendor="AutoChips" version="1.0.6"/>
         <targetInfos>
@@ -677,6 +686,14 @@
       </component>
     </components>
     <files>
+      <file attr="config" category="source" name="Device\Source\ac780x_debugout.c" version="1.0.0">
+        <instance index="0">RTE\Board_Support\AC78013MDQA\ac780x_debugout.c</instance>
+        <component Cbundle="AC780x Development Kit" Cclass="Board Support" Cgroup="AC780x Development Kit" Csub="Debug" Cvendor="AutoChips" Cversion="1.0.0" condition="AC780x Debug Interface"/>
+        <package name="AC780x_DFP" schemaVersion="1.4" url="http://fex.autochips.com:90/download/CMSIS_PACK/AC7801/" vendor="AutoChips" version="1.0.6"/>
+        <targetInfos>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </file>
       <file attr="config" category="header" name="Device\device_assert.h" version="1.0.0">
         <instance index="0">RTE\Device\AC78013MDQA\device_assert.h</instance>
         <component Cclass="Device" Cgroup="Startup" Cvendor="AutoChips" Cversion="1.0.0" condition="AC780x System"/>

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 3584 - 1715
Project/JLinkLog.txt


+ 1 - 1
User/cfg.h

@@ -58,7 +58,7 @@ extern "C" {
 
 #define CONFIG_MAGIC   		0xA5A5
 
-#define DEFAULT_ADDR     0x20
+#define DEFAULT_ADDR     0x40
 #define BROADCAST_ADDR   0xFF
 
 /* ÉýźśąęÖž */

+ 4 - 1
User/main.c

@@ -23,6 +23,8 @@ int main(void)
 	#endif
 	
 		InitDelay();
+		InitDebug();
+	
 		Config_Init();
 		Watchdog_Init();
 		
@@ -39,7 +41,8 @@ int main(void)
 	
 		TIMER_PrdInit();
     Task_Init();
-	
+		
+		printf("AirControlBox booted \r\n");
 	
     while (1)
     {

+ 6 - 3
User/main_task.c

@@ -64,8 +64,8 @@ void Uart0_RxDataHandle(void)
 										case Cmd_Baudrate:
 											ret_len = Read_Baudrate(txbuf+tx_len, txbuf_size-tx_len);
 											break;
-										case Cmd_LockStatus:
-											ret_len = Read_LockStatus(txbuf+tx_len, txbuf_size-tx_len);
+										case Cmd_SvStatus:
+											ret_len = Read_SvStatus(txbuf+tx_len, txbuf_size-tx_len);
 											break;
 										default:
 											txbuf[1] |= 0x80;
@@ -121,6 +121,9 @@ void Uart0_RxDataHandle(void)
 											ret_write = RET_NEED_SAVE|RET_NEED_REBOOT;
 											//NVIC_SystemReset();
 											break;
+										case Cmd_SvControl:
+											ret_write = Write_SvControl(rxbuf+4, rx_len-4-2);
+											break;
 										case Cmd_IapUpgrade:
 											tx_len += IAP_CmdHandle(rxbuf+tx_len, rx_len-4-2, txbuf+tx_len);
 											if(1 == iap_reboot){
@@ -250,7 +253,7 @@ void Task_Handle(void)
 {
 	
 		Process_RunLedPrd();
-		Process_ThreeStatus();
+		//Process_ThreeStatus();
 		Uart0_RxDataHandle();
 
 }

+ 6 - 5
User/process.c

@@ -24,9 +24,9 @@ void Process_Init(void)
 	
 		g_detectTime = 0;
 	
-		g_lockstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_CLOSE_KEY)? STATUS_OPEN:STATUS_CLOSE;
-		g_unlockstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_OPEN_KEY)? STATUS_OPEN:STATUS_CLOSE;
-		g_coverstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_COVER_KEY)? STATUS_OPEN:STATUS_CLOSE;
+		//g_lockstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_CLOSE_KEY)? STATUS_OPEN:STATUS_CLOSE;
+		//g_unlockstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_OPEN_KEY)? STATUS_OPEN:STATUS_CLOSE;
+		//g_coverstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_COVER_KEY)? STATUS_OPEN:STATUS_CLOSE;
 	
 		lockbits = g_lockstatus == STATUS_OPEN?0xFF:0x00;
 		unlockbits = g_unlockstatus == STATUS_OPEN?0xFF:0x00;
@@ -42,6 +42,7 @@ void Process_RunLedPrd(void)
 	if (g_blinkLedTime >= g_blinkLedTgtTime)
 	{
 		g_blinkLedTime = 0;
+		printf("AirControlBox RUNLED_TOGGLE \r\n");
 		
 		RUNLED_TOGGLE;
 	}
@@ -54,7 +55,7 @@ void Process_ThreeStatus(void)
 	if(g_detectTime >= STATUS_DETECTINTERVAL){
 		g_detectTime = 0;
 		
-		
+		/*
 		if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_CLOSE_KEY)){
 			lockbits=(lockbits<<1)|0x01;
 		}else{
@@ -90,7 +91,7 @@ void Process_ThreeStatus(void)
 		}else if(g_coverstatus == STATUS_OPEN && coverbits == 0x00){
 				g_coverstatus = STATUS_CLOSE;
 		}
-		
+		*/
 	
 	}
 	

+ 22 - 7
User/protocol.c

@@ -2,10 +2,11 @@
 #include "process.h"
 #include "cfg.h"
 #include "uart.h"
+#include "gpio.h"
 
 
 #ifdef IS_BOOTLOADER
-uint32_t Firmware_Version[4] = {1, 0, 0, 20231214};
+uint32_t Firmware_Version[4] = {1, 0, 0, 20230307};
 #else
 uint32_t Firmware_Version[4] = {1, 1, 0, 20240108};
 #endif
@@ -101,18 +102,16 @@ uint16_t Read_Baudrate(uint8_t *pBuf, uint16_t buf_len)
 }
 
 
-uint16_t Read_LockStatus(uint8_t *pBuf, uint16_t buf_len)
+uint16_t Read_SvStatus(uint8_t *pBuf, uint16_t buf_len)
 {
 
-	if( buf_len < 3){
+	if( buf_len < 1){
 		return 0;
 	}
 	
-	pBuf[0] = Process_LockStatus();
-	pBuf[1] = Process_UnlockStatus();
-	pBuf[2] = Process_CoverStatus();
+	pBuf[0] = g_svstatus;
 	
-	return 3;
+	return 1;
 }
 
 
@@ -184,5 +183,21 @@ uint8_t Write_Devicetype(uint8_t *pdata, uint8_t len)
 	}
 }
 
+uint8_t Write_SvControl(uint8_t *pdata, uint8_t len)
+{
+	if(len == 2){
+		
+		if(0x00 == pdata[1]){
+			Sv_Control(pdata[0], SV_CLOSE);
+		}else{
+			Sv_Control(pdata[0], SV_OPEN);
+		}
+		return RET_OK;
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+}
+
 
 

+ 5 - 3
User/protocol.h

@@ -50,8 +50,10 @@ extern "C" {
 
 #define Cmd_Addr    					 (0x0010)
 #define Cmd_Baudrate    			 (0x0011)
-#define Cmd_LockStatus    		 (0x0020)
+//#define Cmd_LockStatus    		 (0x0020)
 //#define Cmd_FirmwareVersion    (0x0000)
+#define Cmd_SvControl    			 (0x0022)
+#define Cmd_SvStatus    			 (0x0023)
 
 #define Cmd_IapUpgrade    		 (0xAABB)
 
@@ -74,7 +76,7 @@ uint16_t Read_Devicetype(uint8_t *pBuf, uint16_t buf_len);
 uint16_t Read_Addr(uint8_t *pBuf, uint16_t buf_len);
 uint16_t Read_Baudrate(uint8_t *pBuf, uint16_t buf_len); 
 
-uint16_t Read_LockStatus(uint8_t *pBuf, uint16_t buf_len);
+uint16_t Read_SvStatus(uint8_t *pBuf, uint16_t buf_len);
 
 
 
@@ -94,7 +96,7 @@ uint8_t Write_Baudrate(uint8_t *pdata, uint8_t len);
 uint8_t Write_HardwareVersion(uint8_t *pdata, uint8_t len); 
 uint8_t Write_Deviceid(uint8_t *pdata, uint8_t len); 
 uint8_t Write_Devicetype(uint8_t *pdata, uint8_t len); 
-  
+uint8_t Write_SvControl(uint8_t *pdata, uint8_t len);  
     
 #ifdef __cplusplus
 }