guoqiang 1 год назад
Сommit
e712ba6a9e

+ 97 - 0
Device/gpio.c

@@ -0,0 +1,97 @@
+
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors,  any
+ * reproduction,  modification,  use or disclosure of AutoChips Software,  and
+ * information contained herein,  in whole or in part,  shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2018. All rights reserved.
+ *
+ * BY OPENING THIS FILE,  RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES,  EXPRESS OR IMPLIED,  INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, 
+ * INCORPORATED IN,  OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE,  AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE,  AT AUTOCHIPS'S OPTION,  TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE,  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+
+/*************<start>******************/
+
+
+/*************<include>****************/
+#include "gpio.h"
+
+/*************<macro>******************/
+
+/*************<enum>*******************/
+
+
+/*************<union>******************/
+
+
+/*************<struct>*****************/
+
+
+/*************<variable>***************/
+
+
+/*************<prototype>**************/
+
+/**
+* @prototype GPIO_LedInit(void)
+*
+* @param[in] void
+* @return	 void
+*
+* @brief  	 初始化引脚.
+*/
+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);
+	
+		GPIO_SetDir(GPIO_CLOSE_KEY, GPIO_IN);
+		GPIO_SetDir(GPIO_OPEN_KEY, GPIO_IN);
+		GPIO_SetDir(GPIO_COVER_KEY, GPIO_IN);
+	
+		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);
+	
+	
+	/*初始化引脚功能,如果引脚上电后默认为GPIO,可省略掉初始化步骤.
+	  有部分引脚上电默认为非GPIO,则必须选择其功能为GPIO才能作为GPIO使用.*/
+		GPIO_SetFunc(RS485CTRL_PORT, RS485CTRL_PIN, GPIO_FUN0);
+		GPIO_SetDir(RS485CTRL_PORT, RS485CTRL_PIN, GPIO_OUT);
+	
+		GPIO_SetFunc(RUNLED_PORT, RUNLED_PIN, GPIO_FUN0);
+		GPIO_SetDir(RUNLED_PORT, RUNLED_PIN, GPIO_OUT);
+	
+	
+}
+
+
+/*************<end>********************/

+ 91 - 0
Device/gpio.h

@@ -0,0 +1,91 @@
+
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2018. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+
+/*************<start>******************/
+#ifndef __GPIO_H__
+#define __GPIO_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*************<include>****************/
+#include "ac780x_gpio.h"
+	
+/*************<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 RS485CTRL_PORT (GPIOB)
+#define RS485CTRL_PIN  (GPIO_PIN3)
+
+#define RS485_TX_EN				do{GPIO_SetPinLevel(RS485CTRL_PORT, RS485CTRL_PIN, GPIO_LEVEL_HIGH);}while(0)
+#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)
+
+/*RUNLED¶¯×÷¶¨Òå.*/	
+#define RUNLED_ON				do{GPIO_SetPinLevel(RUNLED_PORT, RUNLED_PIN, GPIO_LEVEL_HIGH);}while(0)
+#define RUNLED_OFF			do{GPIO_SetPinLevel(RUNLED_PORT, RUNLED_PIN, GPIO_LEVEL_LOW);}while(0)
+#define RUNLED_TOGGLE			do{if(GPIO_GetPinLevel(RUNLED_PORT, RUNLED_PIN)){RUNLED_OFF;}else{RUNLED_ON;}}while(0)
+
+
+/*************<enum>*******************/
+
+
+/*************<union>******************/
+
+
+/*************<struct>*****************/
+
+
+/*************<extern>*****************/	
+
+
+/*************<prototype>**************/
+void GPIO_PortInit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GPIO_H__ */
+
+/*************<end>********************/

+ 113 - 0
Device/timer.c

@@ -0,0 +1,113 @@
+
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors,  any
+ * reproduction,  modification,  use or disclosure of AutoChips Software,  and
+ * information contained herein,  in whole or in part,  shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2018. All rights reserved.
+ *
+ * BY OPENING THIS FILE,  RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES,  EXPRESS OR IMPLIED,  INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, 
+ * INCORPORATED IN,  OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE,  AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE,  AT AUTOCHIPS'S OPTION,  TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE,  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+
+/*************<start>******************/
+
+
+/*************<include>****************/
+#include "string.h"
+//#include "gpio.h"
+#include "process.h"
+#include "uart.h"
+#include "timer.h"
+
+/*************<macro>******************/
+
+
+/*************<enum>*******************/
+
+
+/*************<union>******************/
+
+
+/*************<struct>*****************/
+
+
+/*************<variable>***************/
+
+
+/*************<prototype>**************/
+void TIM_CHN2_Callback(void *device, uint32_t wpara, uint32_t lpara);
+
+/**
+* @prototype TIMER_PrdInit(void)
+*
+* @param[in] void
+* @return	 void
+*
+* @brief  	 初始化定时器通道2.
+*/
+void TIMER_PrdInit(void)
+{
+	TIMER_ConfigType tmrConfig;
+	
+	/*清零变量.*/
+	memset(&tmrConfig, 0x00, sizeof(tmrConfig));
+	
+	/*配置定时器.*/
+	tmrConfig.linkModeEn	= DISABLE;
+	tmrConfig.interruptEn	= ENABLE;	
+	tmrConfig.periodValue	= TIM_CHN2_PRD_1ms;
+	tmrConfig.timerEn		= ENABLE;
+	tmrConfig.callBack 		= TIM_CHN2_Callback;
+	TIMER_Init(TIMER_CHANNEL2, &tmrConfig);
+}
+
+/**
+* @prototype TIM_CHN2_Callback(void *device, uint32_t wpara, uint32_t lpara)
+*
+* @param[in] ...
+* @return	 void
+*
+* @brief  	 定时器通道2中断回调函数.
+*/
+void TIM_CHN2_Callback(void *device, uint32_t wpara, uint32_t lpara)
+{
+	
+	if (g_blinkLedTime < 0xFFFF)
+	{
+			g_blinkLedTime++;
+	}
+	
+	if(uart0_info.dmasend_count < 0xFF){
+		  uart0_info.dmasend_count++;
+	}
+	
+	if(g_detectTime < 0xFF){
+			g_detectTime++;
+	}
+	
+}
+
+/*************<end>********************/

+ 72 - 0
Device/timer.h

@@ -0,0 +1,72 @@
+
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2018. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+
+/*************<start>******************/
+#ifndef __TIMER_H__
+#define __TIMER_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*************<include>****************/
+#include "ac780x_timer.h"
+
+/*************<macro>******************/
+#define PERH_BUS_CLK		(24000000U)
+#define TIM_CHN2_PRD_1ms	(PERH_BUS_CLK / 1000 - 1)
+
+
+/*************<enum>*******************/
+
+
+/*************<union>******************/
+
+
+/*************<struct>*****************/
+
+
+/*************<extern>*****************/	
+
+
+/*************<prototype>**************/
+void TIMER_PrdInit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIMER_H__ */
+
+/*************<end>********************/

+ 239 - 0
Device/uart.c

@@ -0,0 +1,239 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+#include "ac780x_uart_reg.h"
+#include "ac780x_dma.h"
+#include "uart.h" 
+#include "gpio.h"
+#include "cfg.h"
+
+//#include "Comm.h"
+
+#define UARTx   UART0
+#define UARTx_IRQn  UART0_IRQn
+
+
+UART_INFO  uart0_info;
+
+uint32_t dmaRxBuf[UART0_RECV_DATA_POOL_COUNT>>2];
+uint32_t dmaTxBuf[UART0_TRANSMIT_DATA_POOL_COUNT>>2];
+
+
+int TransmitData(uint8_t *pdata, uint16_t length);
+
+
+/**
+* UARTTX_DMA_EventCallback
+*
+* @param[in] device: DMA_Type pointer
+* @param[in] wpara: DMA Channel Status
+* @param[in] lpara: reserve for user's code
+* @return    none
+*
+* @brief   uart transmit event callback
+*/
+void UartTxDMAEventCallback(void *device, uint32_t wpara, uint32_t lpara)
+{
+    if (wpara & DMA_CHANNEL_STATUS_FINISH_Msk)    //!<DMA finish
+    {
+			 uart0_info.dmasend_count = UART_DMASEND_COUNT_END;
+    }
+    else if (wpara & DMA_CHANNEL_STATUS_HALF_FINISH_Msk)  //!<DMA half finish
+    {
+        
+    }
+    else if (wpara & DMA_CHANNEL_STATUS_TRANS_ERROR_Msk)  //!<DMA error
+    {
+        
+    }
+    else
+    {
+        //!<never be here
+    }
+}
+
+/**
+* UARTRX_DMA_EventCallback
+*
+* @param[in] device: DMA_Type pointer
+* @param[in] wpara: DMA Channel Status
+* @param[in] lpara: reserve for user's code
+* @return    none
+*
+* @brief   uart dma receive handle
+*/
+static void UartRxDMAEventCallback(void *device, uint32_t wpara, uint32_t lpara)
+{
+    /* Check if DMA Channel Receive Complete */
+    if (wpara & DMA_CHANNEL_STATUS_FINISH_Msk)    //!<DMA finish
+    {
+
+    }
+    else if (wpara & DMA_CHANNEL_STATUS_HALF_FINISH_Msk)  //!<DMA half finish
+    {
+        
+    }
+    else if (wpara & DMA_CHANNEL_STATUS_TRANS_ERROR_Msk)  //!<DMA error
+    {
+        
+    }
+    else
+    {
+        //!<never be here
+    }
+}
+
+/**
+* UARTRX_DMA_EventCallback
+*
+* @param[in] device: UART_Type pointer
+* @param[in] wpara: UART lsr0 register
+* @param[in] lpara: UART lsr1 register
+* @return    none
+*
+* @brief   uart dma receive handle
+*/
+static void UartRxIdleCallBack(void *device, uint32_t wpara, uint32_t lpara)
+{
+    /* Check if IDLE interrupt happened */
+    if (lpara & UART_LSR1_IDLE_Msk)
+    {
+				// 关闭DMA
+				DMA_SetChannel(DMA0_CHANNEL1, DISABLE);
+			
+        ///接收不足4字节会在DMA fifo中缓存
+        uart0_info.recv_len = DMA0_CHANNEL1->DATA_TRANS_NUM + DMA0_CHANNEL1->FIFO_LEFT_NUM;
+			
+        ///将DMA fifo数据flush出来,因为mem设置为32bit,所以fifo也是4字节对齐
+        ///(即使fifo里只有1个字节也会刷出4字节,需要保证缓存冗余不会溢出)
+        DMA_ChannelFlush(DMA0_CHANNEL1);
+			  //DMA_SetChannel(DMA0_CHANNEL1, DISABLE);
+			
+    }
+}
+
+
+/**
+* uart_Initialize
+* 
+* @param[in] none
+* @return none
+*
+* @brief uart 初始化
+*/
+void uart_Initialize(void)
+{
+    UART_ConfigType  uartConfig = {0}; 
+		
+    switch(config->br_index){
+			case BaudRate_4800:
+				uartConfig.baudrate = 4800;
+				break;
+			case BaudRate_9600:
+				uartConfig.baudrate = 9600;
+				break;
+			case BaudRate_19200:
+				uartConfig.baudrate = 19200;
+				break;
+			case BaudRate_38400:
+				uartConfig.baudrate = 38400;
+				break;
+			case BaudRate_57600:
+				uartConfig.baudrate = 57600;
+				break;
+			case BaudRate_115200:
+				uartConfig.baudrate = 115200;
+				break;
+			case BaudRate_230400:
+				uartConfig.baudrate = 230400;
+				break;
+			default:
+				uartConfig.baudrate = 9600;
+				break;
+		};
+		//uartConfig.baudrate = UART0_BaudRate;
+    uartConfig.dataBits = UART_WORD_LEN_8BIT;
+    uartConfig.stopBits = UART_STOP_1BIT;
+    uartConfig.parity = UART_PARI_NO;
+    uartConfig.fifoByteEn = ENABLE; ///<must enable fifoByte when use DMA
+    uartConfig.dmaEn = UART_DMA_TXRX_EN;
+	
+		
+    uartConfig.callBack = UartRxIdleCallBack;   ///<uart2 interrupt callback
+    UART_Init(UARTx, &uartConfig);
+    UARTx->IDLE |= UART_IDLE_IDLEIE_Msk | UART_IDLE_ILEN_Msk;    ///<enable uart idle interrupt
+    
+    ///Enable UARTx interrupt
+    NVIC_SetPriority(UARTx_IRQn, 3);
+    NVIC_ClearPendingIRQ(UARTx_IRQn);
+    NVIC_EnableIRQ(UARTx_IRQn);
+		
+		uart0_info.dmasend_count = 0;
+		uart0_info.recv_buffer = (uint8_t *)dmaRxBuf;
+		uart0_info.send_buffer = (uint8_t *)dmaTxBuf;
+		uart0_info.recv_len = 0;
+		uart0_info.send_len = 0;
+		
+		UART_ReceiveDMA(UARTx, DMA0_CHANNEL1, uart0_info.recv_buffer, UART0_RECV_DATA_POOL_COUNT, UartRxDMAEventCallback); 
+    
+}
+
+/**
+* TransmitData
+* 
+* @param[in] pdata :发送数据指针
+* @param[in] length :发送数据长度
+* @return none
+*
+* @brief uart 发送函数,通过中断发送 
+*/
+int uart0_TransmitData(uint8_t *pdata, uint16_t length) 
+{
+						
+		RS485_TX_EN; 
+		uart0_info.dmasend_count = UART_DMASEND_COUNT_START;
+		UART_TransmitDMA(UARTx, DMA0_CHANNEL0, pdata, length, UartTxDMAEventCallback); 
+
+		//uart0_info.recv_len=0;
+		//UART_ReceiveDMA(UARTx, DMA0_CHANNEL1, uart0_info.recv_buffer, UART0_RECV_DATA_POOL_COUNT, UartRxDMAEventCallback); 
+		
+    return 0;
+}
+
+void uart0_RecvData(void)
+{
+		uart0_info.recv_len=0;
+		UART_ReceiveDMA(UARTx, DMA0_CHANNEL1, uart0_info.recv_buffer, UART0_RECV_DATA_POOL_COUNT, UartRxDMAEventCallback); 
+}
+
+

+ 86 - 0
Device/uart.h

@@ -0,0 +1,86 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+
+#ifndef UART_H
+#define UART_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "ac780x.h"
+#include "cobs.h" 
+#include "fifo.h"
+
+#define BaudRate_4800    (0x01)
+#define BaudRate_9600    (0x02)
+#define BaudRate_19200   (0x03)
+#define BaudRate_38400   (0x04)
+#define BaudRate_57600   (0x05)
+#define BaudRate_115200  (0x06)
+#define BaudRate_230400  (0x07)
+
+
+
+#define UART0_BaudRate    9600
+#define UART0_TRANSMIT_DATA_POOL_COUNT 64
+#define UART0_RECV_DATA_POOL_COUNT     320  
+
+//rs485 send/recv ctrl
+#define UART_DMASEND_COUNT_START   (1)  
+#define UART_DMASEND_COUNT_END   (100)
+#define UART_DMASEND_COUNT_RESET   (105)   
+
+typedef struct
+{
+		uint16_t  recv_len;
+		uint16_t  send_len;
+    uint8_t* recv_buffer;
+		uint8_t* send_buffer;
+		uint8_t  dmasend_count;  //ms count 
+		uint8_t  res;
+}UART_INFO;
+
+
+extern UART_INFO  uart0_info;
+
+void uart_Initialize(void);
+int uart0_TransmitData(uint8_t *pdata, uint16_t length);
+void uart0_RecvData(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* UART_H */
+
+

+ 192 - 0
Lib/cobs.c

@@ -0,0 +1,192 @@
+/*
+ * cobs.c
+ *
+ * Consistent Overhead Byte Stuffing
+ * https://github.com/cmcqueen/cobs-c
+ */
+
+#include "cobs.h"
+
+
+/*****************************************************************************
+ * Defines
+ ****************************************************************************/
+
+#ifndef FALSE
+#define FALSE       (0)
+#endif
+
+#ifndef TRUE
+#define TRUE        (!FALSE)
+#endif
+
+
+/*****************************************************************************
+ * Functions
+ ****************************************************************************/
+
+cobs_encode_result cobs_encode(uint8_t *dst_buf_ptr, size_t dst_buf_len, const uint8_t * src_ptr, size_t src_len)
+{
+    cobs_encode_result  result              = { 0, COBS_ENCODE_OK };
+    const uint8_t *     src_end_ptr         = src_ptr + src_len;
+    uint8_t *           dst_buf_end_ptr     = dst_buf_ptr + dst_buf_len;
+    uint8_t *           dst_code_write_ptr  = dst_buf_ptr;
+    uint8_t *           dst_write_ptr       = dst_code_write_ptr + 1;
+    uint8_t             src_byte            = 0;
+    uint8_t             search_len          = 1;
+
+
+    /* First, do a NULL pointer check and return immediately if it fails. */
+    if ((dst_buf_ptr == NULL) || (src_ptr == NULL))
+    {
+        result.status = COBS_ENCODE_NULL_POINTER;
+        return result;
+    }
+
+    if (src_len != 0)
+    {
+        /* Iterate over the source bytes */
+        for (;;)
+        {
+            /* Check for running out of output buffer space */
+            if (dst_write_ptr >= dst_buf_end_ptr)
+            {
+                result.status |= COBS_ENCODE_OUT_BUFFER_OVERFLOW;
+                break;
+            }
+
+            src_byte = *src_ptr++;
+            if (src_byte == 0)
+            {
+                /* We found a zero byte */
+                *dst_code_write_ptr = search_len;
+                dst_code_write_ptr = dst_write_ptr++;
+                search_len = 1;
+                if (src_ptr >= src_end_ptr)
+                {
+                    break;
+                }
+            }
+            else
+            {
+                /* Copy the non-zero byte to the destination buffer */
+                *dst_write_ptr++ = src_byte;
+                search_len++;
+                if (src_ptr >= src_end_ptr)
+                {
+                    break;
+                }
+                if (search_len == 0xFF)
+                {
+                    /* We have a long string of non-zero bytes, so we need
+                     * to write out a length code of 0xFF. */
+                    *dst_code_write_ptr = search_len;
+                    dst_code_write_ptr = dst_write_ptr++;
+                    search_len = 1;
+                }
+            }
+        }
+    }
+
+    /* We've reached the end of the source data (or possibly run out of output buffer)
+     * Finalise the remaining output. In particular, write the code (length) byte.
+     * Update the pointer to calculate the final output length.
+     */
+    if (dst_code_write_ptr >= dst_buf_end_ptr)
+    {
+        /* We've run out of output buffer to write the code byte. */
+        result.status |= COBS_ENCODE_OUT_BUFFER_OVERFLOW;
+        dst_write_ptr = dst_buf_end_ptr;
+    }
+    else
+    {
+        /* Write the last code (length) byte. */
+        *dst_code_write_ptr = search_len;
+    }
+
+    /* Calculate the output length, from the value of dst_code_write_ptr */
+    result.out_len = dst_write_ptr - dst_buf_ptr;
+
+    return result;
+}
+
+
+cobs_decode_result cobs_decode(uint8_t *dst_buf_ptr, size_t dst_buf_len, const uint8_t * src_ptr, size_t src_len)
+{
+    cobs_decode_result  result              = { 0, COBS_DECODE_OK };
+    const uint8_t *     src_end_ptr         = src_ptr + src_len;
+    uint8_t *           dst_buf_end_ptr     = dst_buf_ptr + dst_buf_len;
+    uint8_t *           dst_write_ptr       = dst_buf_ptr;
+    size_t              remaining_bytes;
+    uint8_t             src_byte;
+    uint8_t             i;
+    uint8_t             len_code;
+
+
+    /* First, do a NULL pointer check and return immediately if it fails. */
+    if ((dst_buf_ptr == NULL) || (src_ptr == NULL))
+    {
+        result.status = COBS_DECODE_NULL_POINTER;
+        return result;
+    }
+
+    if (src_len != 0)
+    {
+        for (;;)
+        {
+            len_code = *src_ptr++;
+            if (len_code == 0)
+            {
+                result.status |= COBS_DECODE_ZERO_BYTE_IN_INPUT;
+                break;
+            }
+            len_code--;
+
+            /* Check length code against remaining input bytes */
+            remaining_bytes = src_end_ptr - src_ptr;
+            if (len_code > remaining_bytes)
+            {
+                result.status |= COBS_DECODE_INPUT_TOO_SHORT;
+                len_code = remaining_bytes;
+            }
+
+            /* Check length code against remaining output buffer space */
+            remaining_bytes = dst_buf_end_ptr - dst_write_ptr;
+            if (len_code > remaining_bytes)
+            {
+                result.status |= COBS_DECODE_OUT_BUFFER_OVERFLOW;
+                len_code = remaining_bytes;
+            }
+
+            for (i = len_code; i != 0; i--)
+            {
+                src_byte = *src_ptr++;
+                if (src_byte == 0)
+                {
+                    result.status |= COBS_DECODE_ZERO_BYTE_IN_INPUT;
+                }
+                *dst_write_ptr++ = src_byte;
+            }
+
+            if (src_ptr >= src_end_ptr)
+            {
+                break;
+            }
+
+            /* Add a zero to the end */
+            if (len_code != 0xFE)
+            {
+                if (dst_write_ptr >= dst_buf_end_ptr)
+                {
+                    result.status |= COBS_DECODE_OUT_BUFFER_OVERFLOW;
+                    break;
+                }
+                *dst_write_ptr++ = 0;
+            }
+        }
+    }
+
+    result.out_len = dst_write_ptr - dst_buf_ptr;
+
+    return result;
+}

+ 83 - 0
Lib/cobs.h

@@ -0,0 +1,83 @@
+/*****************************************************************************
+ *
+ * cobs.h
+ *
+ * Consistent Overhead Byte Stuffing
+ *
+ * https://github.com/cmcqueen/cobs-c
+ *
+ * The COBS encoding does have to increase the packet size to achieve this encoding. However, compared to other byte-stuffing methods,
+ * the packet size increase is reasonable and predictable. COBS always adds 1 byte to the message length. Additionally,
+ * for longer packets of length n, it may add n/254 (rounded down) additional bytes to the encoded packet size.
+ ****************************************************************************/
+
+#ifndef COBS_H_
+#define COBS_H_
+
+
+/*****************************************************************************
+ * Includes
+ ****************************************************************************/
+#include "ac780x.h"
+
+
+/*****************************************************************************
+ * Defines
+ ****************************************************************************/
+
+#define COBS_ENCODE_DST_BUF_LEN_MAX(SRC_LEN)            ((SRC_LEN) + (((SRC_LEN) + 253u)/254u))
+#define COBS_DECODE_DST_BUF_LEN_MAX(SRC_LEN)            (((SRC_LEN) == 0) ? 0u : ((SRC_LEN) - 1u))
+
+
+/*****************************************************************************
+ * Typedefs
+ ****************************************************************************/
+
+typedef enum
+{
+    COBS_ENCODE_OK                  = 0x00,
+    COBS_ENCODE_NULL_POINTER        = 0x01,
+    COBS_ENCODE_OUT_BUFFER_OVERFLOW = 0x02
+} cobs_encode_status;
+
+typedef struct
+{
+    size_t              out_len;
+    cobs_encode_status  status;
+} cobs_encode_result;
+
+
+typedef enum
+{
+    COBS_DECODE_OK                  = 0x00,
+    COBS_DECODE_NULL_POINTER        = 0x01,
+    COBS_DECODE_OUT_BUFFER_OVERFLOW = 0x02,
+    COBS_DECODE_ZERO_BYTE_IN_INPUT  = 0x04,
+    COBS_DECODE_INPUT_TOO_SHORT     = 0x08
+} cobs_decode_status;
+
+typedef struct
+{
+    size_t              out_len;
+    cobs_decode_status  status;
+} cobs_decode_result;
+
+
+/*****************************************************************************
+ * Function prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+cobs_encode_result cobs_encode(uint8_t *dst_buf_ptr, size_t dst_buf_len, const uint8_t * src_ptr, size_t src_len);
+cobs_decode_result cobs_decode(uint8_t *dst_buf_ptr, size_t dst_buf_len, const uint8_t * src_ptr, size_t src_len);
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+
+#endif /* COBS_H_ */

+ 81 - 0
Lib/crc16.c

@@ -0,0 +1,81 @@
+#include "crc16.h"
+
+/* CRC high byte */
+static const uint8_t CRCH[] =
+{
+	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
+	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
+	0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
+	0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
+	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
+	0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
+	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
+	0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
+	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
+	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
+	0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
+	0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
+	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
+	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
+	0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
+	0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
+	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
+	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
+	0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
+	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
+	0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
+	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
+	0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
+	0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
+	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
+	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
+};
+
+/* CRC low byte */
+static const uint8_t CRCL[] =
+{
+	0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06,
+	0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD,
+	0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
+	0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A,
+	0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4,
+	0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
+	0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3,
+	0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,
+	0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
+	0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29,
+	0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED,
+	0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
+	0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60,
+	0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67,
+	0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
+	0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,
+	0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E,
+	0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
+	0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71,
+	0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92,
+	0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
+	0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B,
+	0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B,
+	0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
+	0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42,
+	0x43, 0x83, 0x41, 0x81, 0x80, 0x40
+};
+
+/* crc16 algrothm */
+uint16_t crc16(const uint8_t *buf, uint32_t len)
+{
+    uint8_t crc_hi = 0xFF; /* High byte of CRC initialized */
+    uint8_t crc_lo = 0xFF; /* Low byte of CRC initialized */
+    uint8_t index; /* Index into CRC lookup table */
+
+	while (len--)
+	{
+		index = crc_hi ^ *buf++ ;   /* calculate the CRC */
+		crc_hi = crc_lo ^ CRCH[index];
+		crc_lo = CRCL[index] ;
+	}
+
+	return (crc_hi << 8 | crc_lo) ;
+}
+

+ 7 - 0
Lib/crc16.h

@@ -0,0 +1,7 @@
+#ifndef __CRC16_H__
+#define __CRC16_H__
+#include "ac780x.h"
+
+uint16_t crc16(const uint8_t *buf, uint32_t len);
+
+#endif

+ 346 - 0
Lib/fifo.c

@@ -0,0 +1,346 @@
+/* Copyright Statement:
+*
+* This software/firmware and related documentation ("Autochips Software") are
+* protected under relevant copyright laws. The information contained herein
+* is confidential and proprietary to Autochips Inc. and/or its licensors.
+* Without the prior written permission of Autochips inc. and/or its licensors,
+* any reproduction, modification, use or disclosure of Autochips Software,
+* and information contained herein, in whole or in part, shall be strictly prohibited.
+*
+* Copyright(C) 2016, Autochips ( All rights reserved. )
+*
+* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+* RECEIVED FROM Autochips AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+* AN "AS-IS" BASIS ONLY. Autochips EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+* NEITHER DOES Autochips PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+* SUPPLIED WITH THE Autochips SOFTWARE, AND BUYER AGREES TO LO0 ONLY TO SUCH
+* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. Autochips SHALL ALSO
+* NOT BE RESPONSIBLE FOR ANY Autochips SOFTWARE RELEASES MADE TO BUYER'S
+* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+* BUYER'S SOLE AND EXCLUSIVE REMEDY AND Autochips'S ENTIRE AND CUMULATIVE
+* LIABILITY WITH RESPECT TO THE Autochips SOFTWARE RELEASED HEREUNDER WILL BE,
+* AT Autochips'S OPTION, TO REVISE OR REPLACE THE Autochips SOFTWARE AT ISSUE,
+* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*
+* Autochips FOR SUCH Autochips SOFTWARE AT ISSUE.
+*
+* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+* LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*****************************************************************************/
+
+  
+/* Includes ------------------------------------------------------------------*/
+#include  <stdlib.h>
+#include "fifo.h"
+#include <string.h>
+
+
+
+#define minimum(x, y)  (((x) < (y))? (x) : (y))
+
+
+/************************************************************************
+    Function : 
+    Description : Init the fifo structure.
+            _fifo : reference to _fifo struct.
+            size : size of the fifo.
+            retval 1 if memory allocation fails or 0.
+    Change history:
+    Note:
+    Author:     
+    Date:     Jan-10-2013
+************************************************************************/
+uint8_t fifo_Init(fifo_TypeDef * _fifo, uint8_t* data, uint32_t size)
+{
+    /* check for a valid pointer */
+    if (_fifo == NULL)
+    {
+        return 1;
+    }
+    
+    /* if fifo size is null nothing to do */
+    if ( size == 0)
+    {
+        memset((uint8_t *)_fifo, 0x00, sizeof(fifo_TypeDef));
+        return 1;
+    }
+    else
+    {
+        /* allocate fifo space. */
+        _fifo->baseAddr = data;
+        if (_fifo->baseAddr == NULL)
+        {
+            /* memory allocation failure. */
+            #ifdef SZ_LOG
+            putLine();
+            putString("----> Malloc Fail!");
+            #endif
+            
+            return 1;
+        }
+        else
+        {
+            memset((uint8_t *)_fifo->baseAddr, 0x00, sizeof(uint8_t) * size);
+            /* tail = head --> empty fifo */
+            _fifo->head = 0;
+            _fifo->tail = 0;
+            _fifo->size = size;
+            return 0;
+        }
+    }
+}
+
+
+/************************************************************************
+    Function : 
+    Description : DeInit the fifo structure.
+            _fifo : reference to _fifo struct.
+    Change history:
+    Note:
+    Author:     
+    Date:     Jan-10-2013
+************************************************************************/
+uint8_t fifo_DeInit(fifo_TypeDef * _fifo)
+{
+    uint8_t status = 1;
+    
+    if (_fifo == NULL)
+    {
+        status = 1;
+    }
+    else
+    {
+        if (_fifo->baseAddr != NULL)
+        {
+            /* optional (clear memory region) */
+            memset((uint8_t *)_fifo->baseAddr, 0x00, _fifo->size);
+            memset((uint8_t *)_fifo, 0x00, sizeof(fifo_TypeDef));
+            status = 0;
+        }
+        else
+        {
+            /* FiFo invalid base address. */
+            status = 1;
+        }
+    }
+    return status;
+}
+
+
+/************************************************************************
+    Function : 
+    Description : Reset the fifo structure.
+            _fifo : reference to _fifo struct.
+    Change history:
+    Note:
+    Author:     
+    Date:     Jan-10-2013
+************************************************************************/
+uint8_t fifo_Reset(fifo_TypeDef * _fifo)
+{
+    if (_fifo == NULL)
+    {
+        return 1;
+    }
+    else
+    {
+        if (_fifo->baseAddr != NULL)
+        {
+            /* optional (clear memory region) */
+            memset((uint8_t *)_fifo->baseAddr, 0x00, _fifo->size);
+            
+            _fifo->head = 0;
+            _fifo->tail = 0;
+            return 0;
+        }
+        else
+        {
+            /* FiFo invalid base address. */
+            return 1;
+        }
+    }
+}
+
+
+
+/************************************************************************
+    Function : 
+    Description : returns how much data is stored in the fifo.
+            _fifo : reference to _fifo struct.
+    Change history:
+    Note:
+    Author:     
+    Date:     Jan-10-2013
+************************************************************************/
+uint32_t fifo_GetLen(fifo_TypeDef * _fifo)
+{
+    if (_fifo == NULL)
+    {
+        return 0;
+    }
+    else
+    {
+        return (_fifo->tail - _fifo->head);
+    }
+}
+
+
+/************************************************************************
+    Function : 
+    Description : returns how much free sapce in the fifo.
+            _fifo : reference to _fifo struct.
+    Change history:
+    Note:
+    Author:     
+    Date:     Jan-10-2013
+************************************************************************/
+uint32_t fifo_GetFreeSpace(fifo_TypeDef * _fifo)
+{
+    if (_fifo == NULL)
+    {
+        return 0;
+    }
+    else
+    {
+        return (_fifo->size - (_fifo->tail - _fifo->head));
+    }
+}
+
+
+
+/************************************************************************
+    Function : 
+    Description : returns SET if the FIFO is full.
+            _fifo : reference to _fifo struct.
+    Change history:
+    Note:
+    Author:     
+    Date:     Jan-10-2013
+************************************************************************/
+uint8_t fifo_NotFull(fifo_TypeDef * _fifo)
+{
+    if (_fifo == NULL)
+    {
+        return 0;
+    }
+    else
+    {
+        return ((_fifo->tail - _fifo->head) != _fifo->size) ? 1 : 0;
+    }
+}
+
+
+/************************************************************************
+    Function : 
+    Description : Insert data to the fifo.
+            _fifo : reference to _fifo struct.
+            data : reference to data buffer.
+            len : data buffer length.
+    Change history:
+    Note:
+    Author:     
+    Date:     Jan-10-2013
+************************************************************************/
+uint32_t fifo_insert(fifo_TypeDef * _fifo, uint8_t *data, uint32_t len)
+{
+	uint32_t real_len;
+	uint32_t offset;
+	uint32_t end;
+
+
+	offset   = _fifo->size - (_fifo->tail - _fifo->head);
+    /*Actual size of data we can write*/
+    real_len = minimum(len, offset);
+    /*Offset of write pointer*/
+    offset   = _fifo->tail % _fifo->size;
+    /*End position before buffer being warpped*/
+    end      = minimum(real_len,  _fifo->size - offset);
+    
+	/*Copy data to buffer before warp*/
+	memcpy(_fifo->baseAddr + offset, data, end);
+	
+	/*Copy data to buffer after warp*/
+	memcpy(_fifo->baseAddr, data + end, real_len - end);
+	
+	_fifo->tail += real_len;
+	
+	return real_len;
+}
+
+
+/************************************************************************
+    Function : 
+    Description : Retrieve data from the fifo.
+            _fifo : reference to _fifo struct.
+            data : reference to data buffer.
+            len : data buffer length.
+    Change history:
+    Note:
+    Author:     
+    Date:     Jan-10-2013
+************************************************************************/
+uint32_t fifo_retrieve(fifo_TypeDef * _fifo, uint8_t *data, uint32_t len)
+{
+	uint32_t real_len;
+	uint32_t offset;
+	uint32_t end;
+  
+	
+    offset   = _fifo->tail- _fifo->head;
+	real_len = minimum(len, offset);
+	
+    //得到偏移量
+	offset = _fifo->head % _fifo->size;
+    
+	end = minimum(real_len, _fifo->size - offset);
+	
+	memcpy(data, _fifo->baseAddr + offset, end);
+	
+	memcpy(data + end, _fifo->baseAddr, real_len - end);
+	
+	_fifo->head += real_len;
+	
+	return real_len;
+}
+
+/*****************************************************************************
+* 函数名:  串口通道帧尾获取函数
+* 函数功能: 获取当前帧帧尾所在地址
+* 输入参数: _fifo - fifo结构体
+* 输入参数: data-帧尾结束符
+* 返回数据: fifo中接收到的数据到字节data第一次出现的长度
+*****************************************************************************/ 
+uint32_t  Fifo_strchr(fifo_TypeDef * _fifo, uint8_t data)
+{
+    uint32_t remaining = 0;
+    uint32_t len       = 0;
+    uint32_t head;
+    
+
+    head      = _fifo->head;
+    remaining = _fifo->tail- head;
+    head      = head % _fifo->size;
+	
+	
+	while(remaining)
+	{   
+        len++;
+        if(data == *((_fifo->baseAddr + head)))
+        {
+            return len;
+        }
+        head++;
+        remaining--;
+		head %= _fifo->size;
+	}
+	return 0;
+}
+

+ 73 - 0
Lib/fifo.h

@@ -0,0 +1,73 @@
+/* Copyright Statement:
+*
+* This software/firmware and related documentation ("Autochips Software") are
+* protected under relevant copyright laws. The information contained herein
+* is confidential and proprietary to Autochips Inc. and/or its licensors.
+* Without the prior written permission of Autochips inc. and/or its licensors,
+* any reproduction, modification, use or disclosure of Autochips Software,
+* and information contained herein, in whole or in part, shall be strictly prohibited.
+*
+* Copyright(C) 2016, Autochips ( All rights reserved. )
+*
+* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+* RECEIVED FROM Autochips AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+* AN "AS-IS" BASIS ONLY. Autochips EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+* NEITHER DOES Autochips PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+* SUPPLIED WITH THE Autochips SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. Autochips SHALL ALSO
+* NOT BE RESPONSIBLE FOR ANY Autochips SOFTWARE RELEASES MADE TO BUYER'S
+* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+* BUYER'S SOLE AND EXCLUSIVE REMEDY AND Autochips'S ENTIRE AND CUMULATIVE
+* LIABILITY WITH RESPECT TO THE Autochips SOFTWARE RELEASED HEREUNDER WILL BE,
+* AT Autochips'S OPTION, TO REVISE OR REPLACE THE Autochips SOFTWARE AT ISSUE,
+* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*
+* Autochips FOR SUCH Autochips SOFTWARE AT ISSUE.
+*
+* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+* LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*****************************************************************************/
+
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef _FIFO_H_
+#define _FIFO_H_
+/* Includes ------------------------------------------------------------------*/
+
+#include "ac780x.h"
+
+
+typedef struct
+{
+    uint32_t head;  /* output conut */
+    uint32_t tail;     /*  input count   */
+    uint32_t size;   /*  total size  */
+    uint8_t * baseAddr;
+}fifo_TypeDef;
+
+
+
+
+uint8_t fifo_Init(fifo_TypeDef * _fifo, uint8_t* data, uint32_t size);
+uint8_t fifo_DeInit(fifo_TypeDef * _fifo);
+uint8_t fifo_Reset(fifo_TypeDef * _fifo);
+
+
+uint32_t fifo_insert(fifo_TypeDef * _fifo, uint8_t *data, uint32_t len);
+uint32_t fifo_retrieve(fifo_TypeDef * _fifo, uint8_t *data, uint32_t len);
+
+uint32_t fifo_GetLen(fifo_TypeDef * _fifo);
+uint8_t fifo_NotFull(fifo_TypeDef * _fifo);
+uint32_t fifo_GetFreeSpace(fifo_TypeDef * _fifo);
+uint32_t  Fifo_strchr(fifo_TypeDef * _fifo, uint8_t data);
+
+#endif
+

Разница между файлами не показана из-за своего большого размера
+ 3889 - 0
Project/AirControlValve.uvguix.孙凯


+ 544 - 0
Project/AirControlValve.uvoptx

@@ -0,0 +1,544 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<ProjectOpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_optx.xsd">
+
+  <SchemaVersion>1.0</SchemaVersion>
+
+  <Header>### uVision Project, (C) Keil Software</Header>
+
+  <Extensions>
+    <cExt>*.c</cExt>
+    <aExt>*.s*; *.src; *.a*</aExt>
+    <oExt>*.obj; *.o</oExt>
+    <lExt>*.lib</lExt>
+    <tExt>*.txt; *.h; *.inc; *.md</tExt>
+    <pExt>*.plm</pExt>
+    <CppX>*.cpp; *.cc; *.cxx</CppX>
+    <nMigrate>0</nMigrate>
+  </Extensions>
+
+  <DaveTm>
+    <dwLowDateTime>0</dwLowDateTime>
+    <dwHighDateTime>0</dwHighDateTime>
+  </DaveTm>
+
+  <Target>
+    <TargetName>AirControlValve</TargetName>
+    <ToolsetNumber>0x4</ToolsetNumber>
+    <ToolsetName>ARM-ADS</ToolsetName>
+    <TargetOption>
+      <CLKADS>12000000</CLKADS>
+      <OPTTT>
+        <gFlags>1</gFlags>
+        <BeepAtEnd>1</BeepAtEnd>
+        <RunSim>0</RunSim>
+        <RunTarget>1</RunTarget>
+        <RunAbUc>0</RunAbUc>
+      </OPTTT>
+      <OPTHX>
+        <HexSelection>1</HexSelection>
+        <FlashByte>65535</FlashByte>
+        <HexRangeLowAddress>0</HexRangeLowAddress>
+        <HexRangeHighAddress>0</HexRangeHighAddress>
+        <HexOffset>0</HexOffset>
+      </OPTHX>
+      <OPTLEX>
+        <PageWidth>79</PageWidth>
+        <PageLength>66</PageLength>
+        <TabStop>8</TabStop>
+        <ListingPath>.\Listings\</ListingPath>
+      </OPTLEX>
+      <ListingPage>
+        <CreateCListing>1</CreateCListing>
+        <CreateAListing>1</CreateAListing>
+        <CreateLListing>1</CreateLListing>
+        <CreateIListing>0</CreateIListing>
+        <AsmCond>1</AsmCond>
+        <AsmSymb>1</AsmSymb>
+        <AsmXref>0</AsmXref>
+        <CCond>1</CCond>
+        <CCode>0</CCode>
+        <CListInc>0</CListInc>
+        <CSymb>0</CSymb>
+        <LinkerCodeListing>0</LinkerCodeListing>
+      </ListingPage>
+      <OPTXL>
+        <LMap>1</LMap>
+        <LComments>1</LComments>
+        <LGenerateSymbols>1</LGenerateSymbols>
+        <LLibSym>1</LLibSym>
+        <LLines>1</LLines>
+        <LLocSym>1</LLocSym>
+        <LPubSym>1</LPubSym>
+        <LXref>0</LXref>
+        <LExpSel>0</LExpSel>
+      </OPTXL>
+      <OPTFL>
+        <tvExp>1</tvExp>
+        <tvExpOptDlg>0</tvExpOptDlg>
+        <IsCurrentTarget>1</IsCurrentTarget>
+      </OPTFL>
+      <CpuCode>255</CpuCode>
+      <DebugOpt>
+        <uSim>0</uSim>
+        <uTrg>1</uTrg>
+        <sLdApp>1</sLdApp>
+        <sGomain>1</sGomain>
+        <sRbreak>1</sRbreak>
+        <sRwatch>1</sRwatch>
+        <sRmem>1</sRmem>
+        <sRfunc>1</sRfunc>
+        <sRbox>1</sRbox>
+        <tLdApp>1</tLdApp>
+        <tGomain>1</tGomain>
+        <tRbreak>1</tRbreak>
+        <tRwatch>1</tRwatch>
+        <tRmem>1</tRmem>
+        <tRfunc>0</tRfunc>
+        <tRbox>1</tRbox>
+        <tRtrace>1</tRtrace>
+        <sRSysVw>1</sRSysVw>
+        <tRSysVw>1</tRSysVw>
+        <sRunDeb>0</sRunDeb>
+        <sLrtime>0</sLrtime>
+        <bEvRecOn>1</bEvRecOn>
+        <bSchkAxf>0</bSchkAxf>
+        <bTchkAxf>0</bTchkAxf>
+        <nTsel>4</nTsel>
+        <sDll></sDll>
+        <sDllPa></sDllPa>
+        <sDlgDll></sDlgDll>
+        <sDlgPa></sDlgPa>
+        <sIfile></sIfile>
+        <tDll></tDll>
+        <tDllPa></tDllPa>
+        <tDlgDll></tDlgDll>
+        <tDlgPa></tDlgPa>
+        <tIfile></tIfile>
+        <pMon>Segger\JL2CM3.dll</pMon>
+      </DebugOpt>
+      <TargetDriverDllRegistry>
+        <SetRegEntry>
+          <Number>0</Number>
+          <Key>ARMRTXEVENTFLAGS</Key>
+          <Name>-L70 -Z18 -C0 -M0 -T1</Name>
+        </SetRegEntry>
+        <SetRegEntry>
+          <Number>0</Number>
+          <Key>DLGTARM</Key>
+          <Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)</Name>
+        </SetRegEntry>
+        <SetRegEntry>
+          <Number>0</Number>
+          <Key>ARMDBGFLAGS</Key>
+          <Name></Name>
+        </SetRegEntry>
+        <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>
+        </SetRegEntry>
+        <SetRegEntry>
+          <Number>0</Number>
+          <Key>UL2CM3</Key>
+          <Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0AC780x_128KB -FS08000000 -FL020000 -FP0($$Device:AC78013MDQA$Flash\AC780x_128KB.FLM))</Name>
+        </SetRegEntry>
+      </TargetDriverDllRegistry>
+      <Breakpoint/>
+      <Tracepoint>
+        <THDelay>0</THDelay>
+      </Tracepoint>
+      <DebugFlag>
+        <trace>0</trace>
+        <periodic>1</periodic>
+        <aLwin>1</aLwin>
+        <aCover>0</aCover>
+        <aSer1>0</aSer1>
+        <aSer2>0</aSer2>
+        <aPa>0</aPa>
+        <viewmode>1</viewmode>
+        <vrSel>0</vrSel>
+        <aSym>0</aSym>
+        <aTbox>0</aTbox>
+        <AscS1>0</AscS1>
+        <AscS2>0</AscS2>
+        <AscS3>0</AscS3>
+        <aSer3>0</aSer3>
+        <eProf>0</eProf>
+        <aLa>0</aLa>
+        <aPa1>0</aPa1>
+        <AscS4>0</AscS4>
+        <aSer4>0</aSer4>
+        <StkLoc>0</StkLoc>
+        <TrcWin>0</TrcWin>
+        <newCpu>0</newCpu>
+        <uProt>0</uProt>
+      </DebugFlag>
+      <LintExecutable></LintExecutable>
+      <LintConfigFile></LintConfigFile>
+      <bLintAuto>0</bLintAuto>
+      <bAutoGenD>0</bAutoGenD>
+      <LntExFlags>0</LntExFlags>
+      <pMisraName></pMisraName>
+      <pszMrule></pszMrule>
+      <pSingCmds></pSingCmds>
+      <pMultCmds></pMultCmds>
+      <pMisraNamep></pMisraNamep>
+      <pszMrulep></pszMrulep>
+      <pSingCmdsp></pSingCmdsp>
+      <pMultCmdsp></pMultCmdsp>
+    </TargetOption>
+  </Target>
+
+  <Group>
+    <GroupName>User</GroupName>
+    <tvExp>0</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>1</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\main.c</PathWithFileName>
+      <FilenameWithoutPath>main.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>2</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\Comm.c</PathWithFileName>
+      <FilenameWithoutPath>Comm.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>3</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\Comm.h</PathWithFileName>
+      <FilenameWithoutPath>Comm.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>4</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\IAP.c</PathWithFileName>
+      <FilenameWithoutPath>IAP.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>5</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\IAP.h</PathWithFileName>
+      <FilenameWithoutPath>IAP.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>6</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\IAP_cfg.h</PathWithFileName>
+      <FilenameWithoutPath>IAP_cfg.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>7</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\main_task.c</PathWithFileName>
+      <FilenameWithoutPath>main_task.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>8</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\main_task.h</PathWithFileName>
+      <FilenameWithoutPath>main_task.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>9</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\protocol.h</PathWithFileName>
+      <FilenameWithoutPath>protocol.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>10</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\protocol.c</PathWithFileName>
+      <FilenameWithoutPath>protocol.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>11</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\cfg.h</PathWithFileName>
+      <FilenameWithoutPath>cfg.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>12</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\cfg.c</PathWithFileName>
+      <FilenameWithoutPath>cfg.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>13</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\process.h</PathWithFileName>
+      <FilenameWithoutPath>process.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>14</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\process.c</PathWithFileName>
+      <FilenameWithoutPath>process.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+  </Group>
+
+  <Group>
+    <GroupName>Lib</GroupName>
+    <tvExp>0</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>15</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Lib\cobs.c</PathWithFileName>
+      <FilenameWithoutPath>cobs.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>16</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Lib\cobs.h</PathWithFileName>
+      <FilenameWithoutPath>cobs.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>17</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Lib\crc16.c</PathWithFileName>
+      <FilenameWithoutPath>crc16.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>18</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Lib\crc16.h</PathWithFileName>
+      <FilenameWithoutPath>crc16.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>19</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Lib\fifo.c</PathWithFileName>
+      <FilenameWithoutPath>fifo.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>20</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Lib\fifo.h</PathWithFileName>
+      <FilenameWithoutPath>fifo.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+  </Group>
+
+  <Group>
+    <GroupName>Device</GroupName>
+    <tvExp>0</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>21</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\timer.c</PathWithFileName>
+      <FilenameWithoutPath>timer.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>22</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\timer.h</PathWithFileName>
+      <FilenameWithoutPath>timer.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>23</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\gpio.c</PathWithFileName>
+      <FilenameWithoutPath>gpio.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>24</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\gpio.h</PathWithFileName>
+      <FilenameWithoutPath>gpio.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>25</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\uart.c</PathWithFileName>
+      <FilenameWithoutPath>uart.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>26</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\uart.h</PathWithFileName>
+      <FilenameWithoutPath>uart.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+  </Group>
+
+  <Group>
+    <GroupName>::CMSIS</GroupName>
+    <tvExp>0</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>1</RteFlg>
+  </Group>
+
+  <Group>
+    <GroupName>::Device</GroupName>
+    <tvExp>0</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>1</RteFlg>
+  </Group>
+
+</ProjectOpt>

+ 710 - 0
Project/AirControlValve.uvprojx

@@ -0,0 +1,710 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
+
+  <SchemaVersion>2.1</SchemaVersion>
+
+  <Header>### uVision Project, (C) Keil Software</Header>
+
+  <Targets>
+    <Target>
+      <TargetName>AirControlValve</TargetName>
+      <ToolsetNumber>0x4</ToolsetNumber>
+      <ToolsetName>ARM-ADS</ToolsetName>
+      <pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
+      <uAC6>0</uAC6>
+      <TargetOption>
+        <TargetCommonOption>
+          <Device>AC78013MDQA</Device>
+          <Vendor>AutoChips</Vendor>
+          <PackID>AutoChips.AC780x_DFP.1.0.6</PackID>
+          <PackURL>http://fex.autochips.com:90/download/CMSIS_PACK/AC7801/</PackURL>
+          <Cpu>IRAM(0x20000000,0x5000) IROM(0x08000000,0x20000) CPUTYPE("Cortex-M0+") CLOCK(12000000) ELITTLE</Cpu>
+          <FlashUtilSpec></FlashUtilSpec>
+          <StartupFile></StartupFile>
+          <FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0AC780x_128KB -FS08000000 -FL020000 -FP0($$Device:AC78013MDQA$Flash\AC780x_128KB.FLM))</FlashDriverDll>
+          <DeviceId>0</DeviceId>
+          <RegisterFile>$$Device:AC78013MDQA$Device\Include\ac780x.h</RegisterFile>
+          <MemoryEnv></MemoryEnv>
+          <Cmp></Cmp>
+          <Asm></Asm>
+          <Linker></Linker>
+          <OHString></OHString>
+          <InfinionOptionDll></InfinionOptionDll>
+          <SLE66CMisc></SLE66CMisc>
+          <SLE66AMisc></SLE66AMisc>
+          <SLE66LinkerMisc></SLE66LinkerMisc>
+          <SFDFile>$$Device:AC78013MDQA$SVD\AC780x.svd</SFDFile>
+          <bCustSvd>0</bCustSvd>
+          <UseEnv>0</UseEnv>
+          <BinPath></BinPath>
+          <IncludePath></IncludePath>
+          <LibPath></LibPath>
+          <RegisterFilePath></RegisterFilePath>
+          <DBRegisterFilePath></DBRegisterFilePath>
+          <TargetStatus>
+            <Error>0</Error>
+            <ExitCodeStop>0</ExitCodeStop>
+            <ButtonStop>0</ButtonStop>
+            <NotGenerated>0</NotGenerated>
+            <InvalidFlash>1</InvalidFlash>
+          </TargetStatus>
+          <OutputDirectory>.\Objects\</OutputDirectory>
+          <OutputName>AirControlValve</OutputName>
+          <CreateExecutable>1</CreateExecutable>
+          <CreateLib>0</CreateLib>
+          <CreateHexFile>1</CreateHexFile>
+          <DebugInformation>1</DebugInformation>
+          <BrowseInformation>1</BrowseInformation>
+          <ListingPath>.\Listings\</ListingPath>
+          <HexFormatSelection>1</HexFormatSelection>
+          <Merge32K>0</Merge32K>
+          <CreateBatchFile>0</CreateBatchFile>
+          <BeforeCompile>
+            <RunUserProg1>0</RunUserProg1>
+            <RunUserProg2>0</RunUserProg2>
+            <UserProg1Name></UserProg1Name>
+            <UserProg2Name></UserProg2Name>
+            <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
+            <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
+            <nStopU1X>0</nStopU1X>
+            <nStopU2X>0</nStopU2X>
+          </BeforeCompile>
+          <BeforeMake>
+            <RunUserProg1>0</RunUserProg1>
+            <RunUserProg2>0</RunUserProg2>
+            <UserProg1Name></UserProg1Name>
+            <UserProg2Name></UserProg2Name>
+            <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
+            <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
+            <nStopB1X>0</nStopB1X>
+            <nStopB2X>0</nStopB2X>
+          </BeforeMake>
+          <AfterMake>
+            <RunUserProg1>0</RunUserProg1>
+            <RunUserProg2>0</RunUserProg2>
+            <UserProg1Name></UserProg1Name>
+            <UserProg2Name></UserProg2Name>
+            <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
+            <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
+            <nStopA1X>0</nStopA1X>
+            <nStopA2X>0</nStopA2X>
+          </AfterMake>
+          <SelectedForBatchBuild>0</SelectedForBatchBuild>
+          <SVCSIdString></SVCSIdString>
+        </TargetCommonOption>
+        <CommonProperty>
+          <UseCPPCompiler>0</UseCPPCompiler>
+          <RVCTCodeConst>0</RVCTCodeConst>
+          <RVCTZI>0</RVCTZI>
+          <RVCTOtherData>0</RVCTOtherData>
+          <ModuleSelection>0</ModuleSelection>
+          <IncludeInBuild>1</IncludeInBuild>
+          <AlwaysBuild>0</AlwaysBuild>
+          <GenerateAssemblyFile>0</GenerateAssemblyFile>
+          <AssembleAssemblyFile>0</AssembleAssemblyFile>
+          <PublicsOnly>0</PublicsOnly>
+          <StopOnExitCode>3</StopOnExitCode>
+          <CustomArgument></CustomArgument>
+          <IncludeLibraryModules></IncludeLibraryModules>
+          <ComprImg>1</ComprImg>
+        </CommonProperty>
+        <DllOption>
+          <SimDllName>SARMCM3.DLL</SimDllName>
+          <SimDllArguments> -REMAP-MPU </SimDllArguments>
+          <SimDlgDll>DARMCM1.DLL</SimDlgDll>
+          <SimDlgDllArguments>-pCM0+</SimDlgDllArguments>
+          <TargetDllName>SARMCM3.DLL</TargetDllName>
+          <TargetDllArguments>-MPU </TargetDllArguments>
+          <TargetDlgDll>TARMCM1.DLL</TargetDlgDll>
+          <TargetDlgDllArguments>-pCM0+</TargetDlgDllArguments>
+        </DllOption>
+        <DebugOption>
+          <OPTHX>
+            <HexSelection>1</HexSelection>
+            <HexRangeLowAddress>0</HexRangeLowAddress>
+            <HexRangeHighAddress>0</HexRangeHighAddress>
+            <HexOffset>0</HexOffset>
+            <Oh166RecLen>16</Oh166RecLen>
+          </OPTHX>
+        </DebugOption>
+        <Utilities>
+          <Flash1>
+            <UseTargetDll>1</UseTargetDll>
+            <UseExternalTool>0</UseExternalTool>
+            <RunIndependent>0</RunIndependent>
+            <UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
+            <Capability>1</Capability>
+            <DriverSelection>-1</DriverSelection>
+          </Flash1>
+          <bUseTDR>1</bUseTDR>
+          <Flash2>BIN\UL2CM3.DLL</Flash2>
+          <Flash3></Flash3>
+          <Flash4></Flash4>
+          <pFcarmOut></pFcarmOut>
+          <pFcarmGrp></pFcarmGrp>
+          <pFcArmRoot></pFcArmRoot>
+          <FcArmLst>0</FcArmLst>
+        </Utilities>
+        <TargetArmAds>
+          <ArmAdsMisc>
+            <GenerateListings>0</GenerateListings>
+            <asHll>1</asHll>
+            <asAsm>1</asAsm>
+            <asMacX>1</asMacX>
+            <asSyms>1</asSyms>
+            <asFals>1</asFals>
+            <asDbgD>1</asDbgD>
+            <asForm>1</asForm>
+            <ldLst>0</ldLst>
+            <ldmm>1</ldmm>
+            <ldXref>1</ldXref>
+            <BigEnd>0</BigEnd>
+            <AdsALst>1</AdsALst>
+            <AdsACrf>1</AdsACrf>
+            <AdsANop>0</AdsANop>
+            <AdsANot>0</AdsANot>
+            <AdsLLst>1</AdsLLst>
+            <AdsLmap>1</AdsLmap>
+            <AdsLcgr>1</AdsLcgr>
+            <AdsLsym>1</AdsLsym>
+            <AdsLszi>1</AdsLszi>
+            <AdsLtoi>1</AdsLtoi>
+            <AdsLsun>1</AdsLsun>
+            <AdsLven>1</AdsLven>
+            <AdsLsxf>1</AdsLsxf>
+            <RvctClst>0</RvctClst>
+            <GenPPlst>0</GenPPlst>
+            <AdsCpuType>"Cortex-M0+"</AdsCpuType>
+            <RvctDeviceName></RvctDeviceName>
+            <mOS>0</mOS>
+            <uocRom>0</uocRom>
+            <uocRam>0</uocRam>
+            <hadIROM>1</hadIROM>
+            <hadIRAM>1</hadIRAM>
+            <hadXRAM>0</hadXRAM>
+            <uocXRam>0</uocXRam>
+            <RvdsVP>0</RvdsVP>
+            <RvdsMve>0</RvdsMve>
+            <RvdsCdeCp>0</RvdsCdeCp>
+            <hadIRAM2>0</hadIRAM2>
+            <hadIROM2>0</hadIROM2>
+            <StupSel>8</StupSel>
+            <useUlib>0</useUlib>
+            <EndSel>0</EndSel>
+            <uLtcg>0</uLtcg>
+            <nSecure>0</nSecure>
+            <RoSelD>3</RoSelD>
+            <RwSelD>3</RwSelD>
+            <CodeSel>0</CodeSel>
+            <OptFeed>0</OptFeed>
+            <NoZi1>0</NoZi1>
+            <NoZi2>0</NoZi2>
+            <NoZi3>0</NoZi3>
+            <NoZi4>0</NoZi4>
+            <NoZi5>0</NoZi5>
+            <Ro1Chk>0</Ro1Chk>
+            <Ro2Chk>0</Ro2Chk>
+            <Ro3Chk>0</Ro3Chk>
+            <Ir1Chk>1</Ir1Chk>
+            <Ir2Chk>0</Ir2Chk>
+            <Ra1Chk>0</Ra1Chk>
+            <Ra2Chk>0</Ra2Chk>
+            <Ra3Chk>0</Ra3Chk>
+            <Im1Chk>1</Im1Chk>
+            <Im2Chk>0</Im2Chk>
+            <OnChipMemories>
+              <Ocm1>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm1>
+              <Ocm2>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm2>
+              <Ocm3>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm3>
+              <Ocm4>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm4>
+              <Ocm5>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm5>
+              <Ocm6>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm6>
+              <IRAM>
+                <Type>0</Type>
+                <StartAddress>0x20000000</StartAddress>
+                <Size>0x5000</Size>
+              </IRAM>
+              <IROM>
+                <Type>1</Type>
+                <StartAddress>0x8000000</StartAddress>
+                <Size>0x20000</Size>
+              </IROM>
+              <XRAM>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </XRAM>
+              <OCR_RVCT1>
+                <Type>1</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT1>
+              <OCR_RVCT2>
+                <Type>1</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT2>
+              <OCR_RVCT3>
+                <Type>1</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT3>
+              <OCR_RVCT4>
+                <Type>1</Type>
+                <StartAddress>0x8000000</StartAddress>
+                <Size>0x20000</Size>
+              </OCR_RVCT4>
+              <OCR_RVCT5>
+                <Type>1</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT5>
+              <OCR_RVCT6>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT6>
+              <OCR_RVCT7>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT7>
+              <OCR_RVCT8>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT8>
+              <OCR_RVCT9>
+                <Type>0</Type>
+                <StartAddress>0x20000000</StartAddress>
+                <Size>0x5000</Size>
+              </OCR_RVCT9>
+              <OCR_RVCT10>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT10>
+            </OnChipMemories>
+            <RvctStartVector></RvctStartVector>
+          </ArmAdsMisc>
+          <Cads>
+            <interw>1</interw>
+            <Optim>3</Optim>
+            <oTime>0</oTime>
+            <SplitLS>0</SplitLS>
+            <OneElfS>1</OneElfS>
+            <Strict>0</Strict>
+            <EnumInt>0</EnumInt>
+            <PlainCh>0</PlainCh>
+            <Ropi>0</Ropi>
+            <Rwpi>0</Rwpi>
+            <wLevel>2</wLevel>
+            <uThumb>0</uThumb>
+            <uSurpInc>0</uSurpInc>
+            <uC99>1</uC99>
+            <uGnu>0</uGnu>
+            <useXO>0</useXO>
+            <v6Lang>3</v6Lang>
+            <v6LangP>3</v6LangP>
+            <vShortEn>1</vShortEn>
+            <vShortWch>1</vShortWch>
+            <v6Lto>0</v6Lto>
+            <v6WtE>0</v6WtE>
+            <v6Rtti>0</v6Rtti>
+            <VariousControls>
+              <MiscControls></MiscControls>
+              <Define></Define>
+              <Undefine></Undefine>
+              <IncludePath>..\User;..\Device;..\Lib</IncludePath>
+            </VariousControls>
+          </Cads>
+          <Aads>
+            <interw>1</interw>
+            <Ropi>0</Ropi>
+            <Rwpi>0</Rwpi>
+            <thumb>0</thumb>
+            <SplitLS>0</SplitLS>
+            <SwStkChk>0</SwStkChk>
+            <NoWarn>0</NoWarn>
+            <uSurpInc>0</uSurpInc>
+            <useXO>0</useXO>
+            <ClangAsOpt>1</ClangAsOpt>
+            <VariousControls>
+              <MiscControls></MiscControls>
+              <Define></Define>
+              <Undefine></Undefine>
+              <IncludePath></IncludePath>
+            </VariousControls>
+          </Aads>
+          <LDads>
+            <umfTarg>1</umfTarg>
+            <Ropi>0</Ropi>
+            <Rwpi>0</Rwpi>
+            <noStLib>0</noStLib>
+            <RepFail>1</RepFail>
+            <useFile>0</useFile>
+            <TextAddressRange>0x08000000</TextAddressRange>
+            <DataAddressRange>0x20000000</DataAddressRange>
+            <pXoBase></pXoBase>
+            <ScatterFile></ScatterFile>
+            <IncludeLibs></IncludeLibs>
+            <IncludeLibsPath></IncludeLibsPath>
+            <Misc></Misc>
+            <LinkerInputFile></LinkerInputFile>
+            <DisabledWarnings></DisabledWarnings>
+          </LDads>
+        </TargetArmAds>
+      </TargetOption>
+      <Groups>
+        <Group>
+          <GroupName>User</GroupName>
+          <Files>
+            <File>
+              <FileName>main.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\main.c</FilePath>
+            </File>
+            <File>
+              <FileName>Comm.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\Comm.c</FilePath>
+            </File>
+            <File>
+              <FileName>Comm.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\User\Comm.h</FilePath>
+            </File>
+            <File>
+              <FileName>IAP.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\IAP.c</FilePath>
+            </File>
+            <File>
+              <FileName>IAP.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\User\IAP.h</FilePath>
+            </File>
+            <File>
+              <FileName>IAP_cfg.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\User\IAP_cfg.h</FilePath>
+            </File>
+            <File>
+              <FileName>main_task.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\main_task.c</FilePath>
+            </File>
+            <File>
+              <FileName>main_task.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\User\main_task.h</FilePath>
+            </File>
+            <File>
+              <FileName>protocol.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\User\protocol.h</FilePath>
+            </File>
+            <File>
+              <FileName>protocol.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\protocol.c</FilePath>
+            </File>
+            <File>
+              <FileName>cfg.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\User\cfg.h</FilePath>
+            </File>
+            <File>
+              <FileName>cfg.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\cfg.c</FilePath>
+            </File>
+            <File>
+              <FileName>process.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\User\process.h</FilePath>
+            </File>
+            <File>
+              <FileName>process.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\process.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>Lib</GroupName>
+          <Files>
+            <File>
+              <FileName>cobs.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Lib\cobs.c</FilePath>
+            </File>
+            <File>
+              <FileName>cobs.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Lib\cobs.h</FilePath>
+            </File>
+            <File>
+              <FileName>crc16.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Lib\crc16.c</FilePath>
+            </File>
+            <File>
+              <FileName>crc16.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Lib\crc16.h</FilePath>
+            </File>
+            <File>
+              <FileName>fifo.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Lib\fifo.c</FilePath>
+            </File>
+            <File>
+              <FileName>fifo.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Lib\fifo.h</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>Device</GroupName>
+          <Files>
+            <File>
+              <FileName>timer.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Device\timer.c</FilePath>
+            </File>
+            <File>
+              <FileName>timer.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Device\timer.h</FilePath>
+            </File>
+            <File>
+              <FileName>gpio.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Device\gpio.c</FilePath>
+            </File>
+            <File>
+              <FileName>gpio.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Device\gpio.h</FilePath>
+            </File>
+            <File>
+              <FileName>uart.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Device\uart.c</FilePath>
+            </File>
+            <File>
+              <FileName>uart.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Device\uart.h</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>::CMSIS</GroupName>
+        </Group>
+        <Group>
+          <GroupName>::Device</GroupName>
+        </Group>
+      </Groups>
+    </Target>
+  </Targets>
+
+  <RTE>
+    <apis/>
+    <components>
+      <component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.5.0" condition="ARMv6_7_8-M Device">
+        <package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.8.0"/>
+        <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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="ADC" Cvendor="AutoChips" Cversion="1.0.0" condition="AC780x DMA Driver">
+        <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="CAN" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="CKGEN" Cvendor="AutoChips" Cversion="1.0.0" condition="AC780x CMSIS-CORE">
+        <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="CRC" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="CTU" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="DMA" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="ECC SRAM" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="GPIO" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="I2C" Cvendor="AutoChips" Cversion="1.0.0" condition="AC780x DMA Driver">
+        <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="MMDIVSQART" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="PWDT" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="PWM" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="RTC" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="SPI" Cvendor="AutoChips" Cversion="1.0.0" condition="AC780x DMA Driver">
+        <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="SPM" Cvendor="AutoChips" Cversion="1.0.0" condition="AC780x CMSIS-CORE">
+        <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="TIMER" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="UART" Cvendor="AutoChips" Cversion="1.0.0" condition="AC780x DMA Driver">
+        <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="WDG" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="eFlash" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="Startup" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </component>
+    </components>
+    <files>
+      <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"/>
+        <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="sourceAsm" condition="Startup ARM" name="Device\Source\ARM\startup_ac780x.s" version="1.0.0">
+        <instance index="0">RTE\Device\AC78013MDQA\startup_ac780x.s</instance>
+        <component Cclass="Device" Cgroup="Startup" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </file>
+      <file attr="config" category="source" name="Device\Source\system_ac780x.c" version="1.0.0">
+        <instance index="0">RTE\Device\AC78013MDQA\system_ac780x.c</instance>
+        <component Cclass="Device" Cgroup="Startup" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </file>
+      <file attr="config" category="header" name="Device\system_ac780x.h" version="1.0.0">
+        <instance index="0">RTE\Device\AC78013MDQA\system_ac780x.h</instance>
+        <component Cclass="Device" Cgroup="Startup" 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>
+          <targetInfo name="AirControlValve"/>
+        </targetInfos>
+      </file>
+    </files>
+  </RTE>
+
+</Project>

+ 9 - 0
Project/EventRecorderStub.scvd

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
+
+<component name="EventRecorderStub" version="1.0.0"/>       <!--name and version of the component-->
+  <events>
+  </events>
+
+</component_viewer>

+ 387 - 0
Project/JLinkLog.txt

@@ -0,0 +1,387 @@
+T4C40 000:009.016   SEGGER J-Link V7.80 Log File
+T4C40 000:009.117   DLL Compiled: Sep  9 2022 10:58:20
+T4C40 000:009.122   Logging started @ 2023-12-15 09:25
+T4C40 000:009.127 - 9.129ms
+T4C40 000:009.134 JLINK_SetWarnOutHandler(...)
+T4C40 000:009.139 - 0.006ms
+T4C40 000:009.144 JLINK_OpenEx(...)
+T4C40 000:011.233   Firmware: J-Link V9 compiled May  7 2021 16:26:12
+T4C40 000:011.669   Firmware: J-Link V9 compiled May  7 2021 16:26:12
+T4C40 000:011.831   Decompressing FW timestamp took 128 us
+T4C40 000:017.957   Hardware: V9.50
+T4C40 000:017.977   S/N: 59518874
+T4C40 000:017.982   OEM: SEGGER
+T4C40 000:017.988   Feature(s): GDB, RDI, FlashBP, FlashDL, JFlash, RDDI
+T4C40 000:019.004   TELNET listener socket opened on port 19021
+T4C40 000:019.111   WEBSRV WEBSRV_Init(): Starting webserver thread(s)
+T4C40 000:019.262   WEBSRV Webserver running on local port 19080
+T4C40 000:025.564 - 16.435ms returns "O.K."
+T4C40 000:025.596 JLINK_GetEmuCaps()
+T4C40 000:025.601 - 0.006ms returns 0xB9FF7BBF
+T4C40 000:025.609 JLINK_TIF_GetAvailable(...)
+T4C40 000:025.756 - 0.154ms
+T4C40 000:025.769 JLINK_SetErrorOutHandler(...)
+T4C40 000:025.773 - 0.006ms
+T4C40 000:025.791 JLINK_ExecCommand("ProjectFile = "D:\Code\Embed\AirControlValve\Project\JLinkSettings.ini"", ...). 
+T4C40 000:034.918   Ref file found at: C:\Keil_v5\ARM\Segger\JLinkDevices.ref
+T4C40 000:035.011   REF file references invalid XML file: C:\Program Files\SEGGER\JLink\JLinkDevices.xml
+T4C40 000:035.135 - 9.347ms returns 0x00
+T4C40 000:035.194 JLINK_ExecCommand("Device = AC78013MDQA", ...). 
+T4C40 000:035.306   Device "AC78013MDQA" selected.
+T4C40 000:035.507 - 0.436ms returns 0x00
+T4C40 000:035.655 JLINK_ExecCommand("DisableConnectionTimeout", ...). 
+T4C40 000:035.664 - 0.004ms returns 0x01
+T4C40 000:035.671 JLINK_GetHardwareVersion()
+T4C40 000:035.678 - 0.009ms returns 95000
+T4C40 000:035.684 JLINK_GetDLLVersion()
+T4C40 000:035.691 - 0.010ms returns 78000
+T4C40 000:035.698 JLINK_GetOEMString(...)
+T4C40 000:035.707 JLINK_GetFirmwareString(...)
+T4C40 000:035.712 - 0.007ms
+T4C40 000:035.757 JLINK_GetDLLVersion()
+T4C40 000:035.761 - 0.005ms returns 78000
+T4C40 000:035.765 JLINK_GetCompileDateTime()
+T4C40 000:035.769 - 0.005ms
+T4C40 000:035.778 JLINK_GetFirmwareString(...)
+T4C40 000:035.782 - 0.005ms
+T4C40 000:035.793 JLINK_GetHardwareVersion()
+T4C40 000:035.797 - 0.005ms returns 95000
+T4C40 000:035.806 JLINK_GetSN()
+T4C40 000:035.812 - 0.007ms returns 59518874
+T4C40 000:035.822 JLINK_GetOEMString(...)
+T4C40 000:035.832 JLINK_TIF_Select(JLINKARM_TIF_SWD)
+T4C40 000:036.767 - 0.945ms returns 0x00
+T4C40 000:036.782 JLINK_HasError()
+T4C40 000:036.794 JLINK_SetSpeed(5000)
+T4C40 000:036.952 - 0.174ms
+T4C40 000:036.973 JLINK_GetId()
+T4C40 000:037.276   InitTarget() start
+T4C40 000:037.289    J-Link Script File: Executing InitTarget()
+T4C40 000:039.545   InitTarget() end
+T4C40 000:040.203   Found SW-DP with ID 0x0BC11477
+T4C40 000:042.224   DPIDR: 0x0BC11477
+T4C40 000:042.237   CoreSight SoC-400 or earlier
+T4C40 000:042.246   Scanning AP map to find all available APs
+T4C40 000:042.691   AP[1]: Stopped AP scan as end of AP map has been reached
+T4C40 000:042.702   AP[0]: AHB-AP (IDR: 0x04770031)
+T4C40 000:042.710   Iterating through AP map to find AHB-AP to use
+T4C40 000:043.382   AP[0]: Core found
+T4C40 000:043.391   AP[0]: AHB-AP ROM base: 0xE00FF000
+T4C40 000:043.768   CPUID register: 0x410CC601. Implementer code: 0x41 (ARM)
+T4C40 000:043.779   Found Cortex-M0 r0p1, Little endian.
+T4C40 000:145.044   -- Max. mem block: 0x00010C40
+T4C40 000:145.420   CPU_ReadMem(4 bytes @ 0xE000EDF0)
+T4C40 000:146.106   CPU_WriteMem(4 bytes @ 0xE000EDF0)
+T4C40 000:146.618   CPU_ReadMem(4 bytes @ 0xE0002000)
+T4C40 000:147.126   FPUnit: 4 code (BP) slots and 0 literal slots
+T4C40 000:147.159   CPU_ReadMem(4 bytes @ 0xE000EDFC)
+T4C40 000:147.616   CPU_WriteMem(4 bytes @ 0xE000EDFC)
+T4C40 000:148.157   CPU_ReadMem(4 bytes @ 0xE0001000)
+T4C40 000:148.683   CPU_WriteMem(4 bytes @ 0xE0001000)
+T4C40 000:149.207   CoreSight components:
+T4C40 000:149.257   ROMTbl[0] @ E00FF000
+T4C40 000:149.372   CPU_ReadMem(64 bytes @ 0xE00FF000)
+T4C40 000:150.251   CPU_ReadMem(32 bytes @ 0xE000EFE0)
+T4C40 000:150.969   [0][0]: E000E000 CID B105E00D PID 000BB008 SCS
+T4C40 000:151.004   CPU_ReadMem(32 bytes @ 0xE0001FE0)
+T4C40 000:151.697   [0][1]: E0001000 CID B105E00D PID 000BB00A DWT
+T4C40 000:151.743   CPU_ReadMem(32 bytes @ 0xE0002FE0)
+T4C40 000:152.439   [0][2]: E0002000 CID B105E00D PID 000BB00B FPB
+T4C40 000:152.960 - 116.006ms returns 0x0BC11477
+T4C40 000:153.002 JLINK_GetDLLVersion()
+T4C40 000:153.013 - 0.015ms returns 78000
+T4C40 000:153.027 JLINK_CORE_GetFound()
+T4C40 000:153.037 - 0.019ms returns 0x60000FF
+T4C40 000:153.186 JLINK_GetDebugInfo(0x100 = JLINKARM_ROM_TABLE_ADDR_INDEX)
+T4C40 000:153.221   Value=0xE00FF000
+T4C40 000:153.236 - 0.055ms returns 0
+T4C40 000:153.275 JLINK_GetDebugInfo(0x100 = JLINKARM_ROM_TABLE_ADDR_INDEX)
+T4C40 000:153.287   Value=0xE00FF000
+T4C40 000:153.301 - 0.031ms returns 0
+T4C40 000:153.313 JLINK_GetDebugInfo(0x101 = JLINKARM_DEBUG_INFO_ETM_ADDR_INDEX)
+T4C40 000:153.323   Value=0x00000000
+T4C40 000:153.337 - 0.028ms returns 0
+T4C40 000:153.356 JLINK_ReadMemEx(0xE0041FF0, 0x10 Bytes, Flags = 0x02000004)
+T4C40 000:153.371   CPU_ReadMem(16 bytes @ 0xE0041FF0)
+T4C40 000:153.823   Data:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+T4C40 000:153.832 - 0.478ms returns 16 (0x10)
+T4C40 000:153.838 JLINK_GetDebugInfo(0x102 = JLINKARM_DEBUG_INFO_MTB_ADDR_INDEX)
+T4C40 000:153.842   Value=0x00000000
+T4C40 000:153.847 - 0.010ms returns 0
+T4C40 000:153.851 JLINK_GetDebugInfo(0x103 = JLINKARM_DEBUG_INFO_TPIU_ADDR_INDEX)
+T4C40 000:153.854   Value=0x00000000
+T4C40 000:153.859 - 0.009ms returns 0
+T4C40 000:153.863 JLINK_ReadMemEx(0xE0040FF0, 0x10 Bytes, Flags = 0x02000004)
+T4C40 000:153.870   CPU_ReadMem(16 bytes @ 0xE0040FF0)
+T4C40 000:154.344   Data:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+T4C40 000:154.356 - 0.494ms returns 16 (0x10)
+T4C40 000:154.362 JLINK_GetDebugInfo(0x104 = JLINKARM_DEBUG_INFO_ITM_ADDR_INDEX)
+T4C40 000:154.366   Value=0xE0000000
+T4C40 000:154.370 - 0.010ms returns 0
+T4C40 000:154.374 JLINK_GetDebugInfo(0x105 = JLINKARM_DEBUG_INFO_DWT_ADDR_INDEX)
+T4C40 000:154.378   Value=0xE0001000
+T4C40 000:154.382 - 0.009ms returns 0
+T4C40 000:154.386 JLINK_GetDebugInfo(0x106 = JLINKARM_DEBUG_INFO_FPB_ADDR_INDEX)
+T4C40 000:154.390   Value=0xE0002000
+T4C40 000:154.394 - 0.009ms returns 0
+T4C40 000:154.398 JLINK_GetDebugInfo(0x107 = JLINKARM_DEBUG_INFO_NVIC_ADDR_INDEX)
+T4C40 000:154.401   Value=0xE000E000
+T4C40 000:154.406 - 0.009ms returns 0
+T4C40 000:154.410 JLINK_GetDebugInfo(0x10C = JLINKARM_DEBUG_INFO_DBG_ADDR_INDEX)
+T4C40 000:154.413   Value=0xE000EDF0
+T4C40 000:154.418 - 0.009ms returns 0
+T4C40 000:154.422 JLINK_GetDebugInfo(0x01 = Unknown)
+T4C40 000:154.425   Value=0x00000000
+T4C40 000:154.430 - 0.009ms returns 0
+T4C40 000:154.434 JLINK_ReadMemU32(0xE000ED00, 0x1 Items)
+T4C40 000:154.441   CPU_ReadMem(4 bytes @ 0xE000ED00)
+T4C40 000:154.784   Data:  01 C6 0C 41
+T4C40 000:154.794   Debug reg: CPUID
+T4C40 000:154.798 - 0.366ms returns 1 (0x1)
+T4C40 000:154.804 JLINK_GetDebugInfo(0x10F = JLINKARM_DEBUG_INFO_HAS_CORTEX_M_SECURITY_EXT_INDEX)
+T4C40 000:154.808   Value=0x00000000
+T4C40 000:154.813 - 0.010ms returns 0
+T4C40 000:154.818 JLINK_HasError()
+T4C40 000:154.822 JLINK_SetResetType(JLINKARM_CM3_RESET_TYPE_NORMAL)
+T4C40 000:154.826 - 0.005ms returns JLINKARM_CM3_RESET_TYPE_NORMAL
+T4C40 000:154.830 JLINK_Reset()
+T4C40 000:154.842   CPU is running
+T4C40 000:154.848   CPU_WriteMem(4 bytes @ 0xE000EDF0)
+T4C40 000:155.243   CPU is running
+T4C40 000:155.254   CPU_WriteMem(4 bytes @ 0xE000EDFC)
+T4C40 000:155.648   Reset: Halt core after reset via DEMCR.VC_CORERESET.
+T4C40 000:156.249   Reset: Reset device via AIRCR.SYSRESETREQ.
+T4C40 000:156.259   CPU is running
+T4C40 000:156.266   CPU_WriteMem(4 bytes @ 0xE000ED0C)
+T4C40 000:209.236   CPU_ReadMem(4 bytes @ 0xE000EDF0)
+T4C40 000:209.712   CPU_ReadMem(4 bytes @ 0xE000EDF0)
+T4C40 000:210.143   CPU is running
+T4C40 000:210.181   CPU_WriteMem(4 bytes @ 0xE000EDF0)
+T4C40 000:210.655   CPU is running
+T4C40 000:210.669   CPU_WriteMem(4 bytes @ 0xE000EDFC)
+T4C40 000:216.482   CPU_ReadMem(4 bytes @ 0xE000EDF0)
+T4C40 000:219.133   CPU_WriteMem(4 bytes @ 0xE0002000)
+T4C40 000:219.601   CPU_ReadMem(4 bytes @ 0xE000EDFC)
+T4C40 000:219.987   CPU_ReadMem(4 bytes @ 0xE0001000)
+T4C40 000:220.372   CPU_WriteMem(4 bytes @ 0xE0001000)
+T4C40 000:220.815 - 65.992ms
+T4C40 000:220.840 JLINK_HasError()
+T4C40 000:220.847 JLINK_ReadReg(R15 (PC))
+T4C40 000:220.870 - 0.024ms returns 0x0800019C
+T4C40 000:220.875 JLINK_ReadReg(XPSR)
+T4C40 000:220.879 - 0.006ms returns 0x41000000
+T4C40 000:220.884 JLINK_Halt()
+T4C40 000:220.888 - 0.005ms returns 0x00
+T4C40 000:220.974 JLINK_ReadMemU32(0xE000EDF0, 0x1 Items)
+T4C40 000:220.995   CPU_ReadMem(4 bytes @ 0xE000EDF0)
+T4C40 000:221.310   Data:  03 00 03 00
+T4C40 000:221.364   Debug reg: DHCSR
+T4C40 000:221.371 - 0.399ms returns 1 (0x1)
+T4C40 000:221.381 JLINK_WriteU32_64(0xE000EDF0, 0xA05F0003)
+T4C40 000:221.387   Debug reg: DHCSR
+T4C40 000:221.668   CPU_WriteMem(4 bytes @ 0xE000EDF0)
+T4C40 000:221.965 - 0.590ms returns 0 (0x00000000)
+T4C40 000:221.976 JLINK_WriteU32_64(0xE000EDFC, 0x01000000)
+T4C40 000:221.987   Debug reg: DEMCR
+T4C40 000:222.013   CPU_WriteMem(4 bytes @ 0xE000EDFC)
+T4C40 000:222.365 - 0.406ms returns 0 (0x00000000)
+T4C40 000:222.454 JLINK_GetHWStatus(...)
+T4C40 000:222.786 - 0.349ms returns 0
+T4C40 000:222.854 JLINK_GetNumBPUnits(Type = 0xFFFFFF00)
+T4C40 000:222.867 - 0.018ms returns 0x04
+T4C40 000:222.880 JLINK_GetNumBPUnits(Type = 0xF0)
+T4C40 000:222.890 - 0.015ms returns 0x2000
+T4C40 000:222.902 JLINK_GetNumWPUnits()
+T4C40 000:222.912 - 0.014ms returns 2
+T4C40 000:222.943 JLINK_GetSpeed()
+T4C40 000:222.953 - 0.015ms returns 4000
+T4C40 000:222.989 JLINK_ReadMemU32(0xE000E004, 0x1 Items)
+T4C40 000:223.025   CPU_ReadMem(4 bytes @ 0xE000E004)
+T4C40 000:223.401   Data:  00 00 00 00
+T4C40 000:223.427 - 0.443ms returns 1 (0x1)
+T4C40 000:223.466 JLINK_HasError()
+T4C40 000:223.481 JLINK_ReadReg(R15 (PC))
+T4C40 000:223.497 - 0.021ms returns 0x0800019C
+T4C40 000:223.511 JLINK_ReadReg(XPSR)
+T4C40 000:223.521 - 0.015ms returns 0x41000000
+T4C40 000:293.479 JLINK_HasError()
+T4C40 000:293.511 JLINK_SetResetType(JLINKARM_CM3_RESET_TYPE_NORMAL)
+T4C40 000:293.517 - 0.008ms returns JLINKARM_CM3_RESET_TYPE_NORMAL
+T4C40 000:293.522 JLINK_Reset()
+T4C40 000:293.540   CPU_WriteMem(4 bytes @ 0xE000EDF0)
+T4C40 000:293.865   CPU_WriteMem(4 bytes @ 0xE000EDFC)
+T4C40 000:294.158   Reset: Halt core after reset via DEMCR.VC_CORERESET.
+T4C40 000:294.486   Reset: Reset device via AIRCR.SYSRESETREQ.
+T4C40 000:294.493   CPU_WriteMem(4 bytes @ 0xE000ED0C)
+T4C40 000:346.928   CPU_ReadMem(4 bytes @ 0xE000EDF0)
+T4C40 000:347.424   CPU_ReadMem(4 bytes @ 0xE000EDF0)
+T4C40 000:347.955   CPU_WriteMem(4 bytes @ 0xE000EDF0)
+T4C40 000:348.462   CPU_WriteMem(4 bytes @ 0xE000EDFC)
+T4C40 000:354.200   CPU_ReadMem(4 bytes @ 0xE000EDF0)
+T4C40 000:357.127   CPU_WriteMem(4 bytes @ 0xE0002000)
+T4C40 000:357.666   CPU_ReadMem(4 bytes @ 0xE000EDFC)
+T4C40 000:358.188   CPU_ReadMem(4 bytes @ 0xE0001000)
+T4C40 000:358.643   CPU_WriteMem(4 bytes @ 0xE0001000)
+T4C40 000:359.197 - 65.693ms
+T4C40 000:359.303 JLINK_HasError()
+T4C40 000:359.454 JLINK_ReadReg(R15 (PC))
+T4C40 000:359.489 - 0.041ms returns 0x0800019C
+T4C40 000:359.504 JLINK_ReadReg(XPSR)
+T4C40 000:359.516 - 0.016ms returns 0x41000000
+T4C40 000:360.227 JLINK_ReadMemEx(0x0800019C, 0x3C Bytes, Flags = 0x02000000)
+T4C40 000:360.259   CPU_ReadMem(128 bytes @ 0x08000180)
+T4C40 000:361.308    -- Updating C cache (128 bytes @ 0x08000180)
+T4C40 000:361.356    -- Read from C cache (60 bytes @ 0x0800019C)
+T4C40 000:361.375   Data:  0F 48 80 47 0F 48 10 49 01 60 10 48 10 49 01 60 ...
+T4C40 000:361.390 - 1.168ms returns 60 (0x3C)
+T4C40 000:361.411 JLINK_ReadMemEx(0x0800019C, 0x2 Bytes, Flags = 0x02000000)
+T4C40 000:361.426    -- Read from C cache (2 bytes @ 0x0800019C)
+T4C40 000:361.440   Data:  0F 48
+T4C40 000:361.455 - 0.049ms returns 2 (0x2)
+T4C40 000:361.665 JLINK_ReadMemEx(0x0800019E, 0x2 Bytes, Flags = 0x02000000)
+T4C40 000:361.682    -- Read from C cache (2 bytes @ 0x0800019E)
+T4C40 000:361.697   Data:  80 47
+T4C40 000:361.711 - 0.050ms returns 2 (0x2)
+T4C40 000:361.755 JLINK_ReadMemEx(0x0800019E, 0x2 Bytes, Flags = 0x02000000)
+T4C40 000:361.767    -- Read from C cache (2 bytes @ 0x0800019E)
+T4C40 000:361.781   Data:  80 47
+T4C40 000:361.795 - 0.044ms returns 2 (0x2)
+T4C40 000:361.807 JLINK_ReadMemEx(0x080001A0, 0x3C Bytes, Flags = 0x02000000)
+T4C40 000:361.818    -- Read from C cache (60 bytes @ 0x080001A0)
+T4C40 000:361.834   Data:  0F 48 10 49 01 60 10 48 10 49 01 60 10 48 11 49 ...
+T4C40 000:361.848 - 0.045ms returns 60 (0x3C)
+T4C40 000:361.860 JLINK_ReadMemEx(0x080001A0, 0x2 Bytes, Flags = 0x02000000)
+T4C40 000:361.871    -- Read from C cache (2 bytes @ 0x080001A0)
+T4C40 000:361.885   Data:  0F 48
+T4C40 000:361.899 - 0.044ms returns 2 (0x2)
+T2A70 001:744.445 JLINK_ReadMemEx(0x0800019C, 0x2 Bytes, Flags = 0x02000000)
+T2A70 001:744.476    -- Read from C cache (2 bytes @ 0x0800019C)
+T2A70 001:744.483   Data:  0F 48
+T2A70 001:744.489 - 0.045ms returns 2 (0x2)
+T2A70 001:744.495 JLINK_HasError()
+T2A70 001:744.502 JLINK_SetBPEx(Addr = 0x080025C8, Type = 0xFFFFFFF2)
+T2A70 001:744.511 - 0.010ms returns 0x00000001
+T2A70 001:744.516 JLINK_HasError()
+T2A70 001:744.520 JLINK_HasError()
+T2A70 001:744.525 JLINK_Go()
+T2A70 001:744.942   CPU_WriteMem(4 bytes @ 0xE0002000)
+T2A70 001:745.323   CPU_ReadMem(4 bytes @ 0xE0001000)
+T2A70 001:745.615   CPU_WriteMem(4 bytes @ 0xE0001000)
+T2A70 001:745.905   CPU_WriteMem(4 bytes @ 0xE0002008)
+T2A70 001:745.917   CPU_WriteMem(4 bytes @ 0xE000200C)
+T2A70 001:745.923   CPU_WriteMem(4 bytes @ 0xE0002010)
+T2A70 001:745.928   CPU_WriteMem(4 bytes @ 0xE0002014)
+T2A70 001:746.687   CPU_WriteMem(4 bytes @ 0xE0001004)
+T2A70 001:747.327 - 2.810ms
+T2A70 001:848.271 JLINK_HasError()
+T2A70 001:848.295 JLINK_IsHalted()
+T2A70 001:850.116 - 1.824ms returns TRUE
+T2A70 001:850.123 JLINK_HasError()
+T2A70 001:850.127 JLINK_Halt()
+T2A70 001:850.131 - 0.005ms returns 0x00
+T2A70 001:850.136 JLINK_IsHalted()
+T2A70 001:850.140 - 0.005ms returns TRUE
+T2A70 001:850.144 JLINK_IsHalted()
+T2A70 001:850.148 - 0.005ms returns TRUE
+T2A70 001:850.152 JLINK_IsHalted()
+T2A70 001:850.156 - 0.005ms returns TRUE
+T2A70 001:850.161 JLINK_HasError()
+T2A70 001:850.166 JLINK_ReadReg(R15 (PC))
+T2A70 001:850.171 - 0.007ms returns 0x080025C8
+T2A70 001:850.176 JLINK_ReadReg(XPSR)
+T2A70 001:850.180 - 0.005ms returns 0x01000000
+T2A70 001:850.186 JLINK_HasError()
+T2A70 001:850.190 JLINK_ClrBPEx(BPHandle = 0x00000001)
+T2A70 001:850.195 - 0.006ms returns 0x00
+T2A70 001:850.199 JLINK_HasError()
+T2A70 001:850.203 JLINK_HasError()
+T2A70 001:850.209 JLINK_ReadMemU32(0xE000ED30, 0x1 Items)
+T2A70 001:850.221   CPU_ReadMem(4 bytes @ 0xE000ED30)
+T2A70 001:850.448   Data:  02 00 00 00
+T2A70 001:850.455 - 0.247ms returns 1 (0x1)
+T2A70 001:850.461 JLINK_ReadMemU32(0xE0001028, 0x1 Items)
+T2A70 001:850.467   CPU_ReadMem(4 bytes @ 0xE0001028)
+T2A70 001:850.721   Data:  00 00 00 00
+T2A70 001:850.732   Debug reg: DWT_FUNC[0]
+T2A70 001:850.737 - 0.278ms returns 1 (0x1)
+T2A70 001:850.742 JLINK_ReadMemU32(0xE0001038, 0x1 Items)
+T2A70 001:850.747   CPU_ReadMem(4 bytes @ 0xE0001038)
+T2A70 001:850.981   Data:  00 00 00 00
+T2A70 001:850.987   Debug reg: DWT_FUNC[1]
+T2A70 001:850.992 - 0.251ms returns 1 (0x1)
+T2A70 001:851.026 JLINK_HasError()
+T2A70 001:851.030 JLINK_ReadReg(R0)
+T2A70 001:851.035 - 0.006ms returns 0x20000330
+T2A70 001:851.040 JLINK_ReadReg(R1)
+T2A70 001:851.044 - 0.005ms returns 0x20000330
+T2A70 001:851.048 JLINK_ReadReg(R2)
+T2A70 001:851.052 - 0.005ms returns 0x20000330
+T2A70 001:851.056 JLINK_ReadReg(R3)
+T2A70 001:851.060 - 0.005ms returns 0x20000330
+T2A70 001:851.065 JLINK_ReadReg(R4)
+T2A70 001:851.068 - 0.005ms returns 0x08002B54
+T2A70 001:851.073 JLINK_ReadReg(R5)
+T2A70 001:851.077 - 0.005ms returns 0x200002CC
+T2A70 001:851.081 JLINK_ReadReg(R6)
+T2A70 001:851.085 - 0.005ms returns 0x00000000
+T2A70 001:851.133 JLINK_ReadReg(R7)
+T2A70 001:851.140 - 0.008ms returns 0x00000000
+T2A70 001:851.144 JLINK_ReadReg(R8)
+T2A70 001:851.150 - 0.007ms returns 0x00000000
+T2A70 001:851.155 JLINK_ReadReg(R9)
+T2A70 001:851.159 - 0.005ms returns 0x2000052C
+T2A70 001:851.163 JLINK_ReadReg(R10)
+T2A70 001:851.167 - 0.005ms returns 0x08002B54
+T2A70 001:851.171 JLINK_ReadReg(R11)
+T2A70 001:851.175 - 0.005ms returns 0x08002B54
+T2A70 001:851.180 JLINK_ReadReg(R12)
+T2A70 001:851.184 - 0.005ms returns 0x00000000
+T2A70 001:851.188 JLINK_ReadReg(R13 (SP))
+T2A70 001:851.192 - 0.006ms returns 0x20000730
+T2A70 001:851.197 JLINK_ReadReg(R14)
+T2A70 001:851.200 - 0.005ms returns 0x08000153
+T2A70 001:851.205 JLINK_ReadReg(R15 (PC))
+T2A70 001:851.209 - 0.006ms returns 0x080025C8
+T2A70 001:851.214 JLINK_ReadReg(XPSR)
+T2A70 001:851.218 - 0.005ms returns 0x01000000
+T2A70 001:851.222 JLINK_ReadReg(MSP)
+T2A70 001:851.226 - 0.005ms returns 0x20000730
+T2A70 001:851.231 JLINK_ReadReg(PSP)
+T2A70 001:851.234 - 0.005ms returns 0x20001000
+T2A70 001:851.239 JLINK_ReadReg(CFBP)
+T2A70 001:851.242 - 0.005ms returns 0x00000000
+T4C40 001:854.106 JLINK_HasError()
+T4C40 001:856.120 JLINK_ReadMemEx(0x080025C8, 0x3C Bytes, Flags = 0x02000000)
+T4C40 001:856.152   CPU_ReadMem(128 bytes @ 0x080025C0)
+T4C40 001:856.940    -- Updating C cache (128 bytes @ 0x080025C0)
+T4C40 001:856.956    -- Read from C cache (60 bytes @ 0x080025C8)
+T4C40 001:856.963   Data:  FE F7 BC FE FE F7 CA F8 FE F7 04 FC FE F7 94 FF ...
+T4C40 001:856.968 - 0.850ms returns 60 (0x3C)
+T4C40 001:856.975 JLINK_ReadMemEx(0x080025C8, 0x2 Bytes, Flags = 0x02000000)
+T4C40 001:856.980    -- Read from C cache (2 bytes @ 0x080025C8)
+T4C40 001:856.986   Data:  FE F7
+T4C40 001:856.991 - 0.018ms returns 2 (0x2)
+T4C40 001:856.997 JLINK_ReadMemEx(0x080025CA, 0x2 Bytes, Flags = 0x02000000)
+T4C40 001:857.001    -- Read from C cache (2 bytes @ 0x080025CA)
+T4C40 001:857.006   Data:  BC FE
+T4C40 001:857.011 - 0.016ms returns 2 (0x2)
+T4C40 001:857.039 JLINK_ReadMemEx(0x080025CC, 0x3C Bytes, Flags = 0x02000000)
+T4C40 001:857.043    -- Read from C cache (60 bytes @ 0x080025CC)
+T4C40 001:857.049   Data:  FE F7 CA F8 FE F7 04 FC FE F7 94 FF FF F7 3E FC ...
+T4C40 001:857.054 - 0.017ms returns 60 (0x3C)
+T4C40 001:857.059 JLINK_ReadMemEx(0x080025CC, 0x2 Bytes, Flags = 0x02000000)
+T4C40 001:857.063    -- Read from C cache (2 bytes @ 0x080025CC)
+T4C40 001:857.068   Data:  FE F7
+T4C40 001:857.073 - 0.016ms returns 2 (0x2)
+T4C40 001:857.077 JLINK_ReadMemEx(0x080025CE, 0x2 Bytes, Flags = 0x02000000)
+T4C40 001:857.081    -- Read from C cache (2 bytes @ 0x080025CE)
+T4C40 001:857.086   Data:  CA F8
+T4C40 001:857.092 - 0.016ms returns 2 (0x2)
+T4C40 003:972.062 JLINK_HasError()
+T4C40 003:976.641 JLINK_Close()
+T4C40 003:977.141   CPU_WriteMem(4 bytes @ 0xE0002008)
+T4C40 003:977.558   CPU_ReadMem(4 bytes @ 0xE0001000)
+T4C40 003:977.906   CPU_WriteMem(4 bytes @ 0xE0001000)
+T4C40 003:994.411 - 17.801ms
+T4C40 003:994.447   
+T4C40 003:994.453   Closed

+ 43 - 0
Project/JLinkSettings.ini

@@ -0,0 +1,43 @@
+[BREAKPOINTS]
+ForceImpTypeAny = 0
+ShowInfoWin = 1
+EnableFlashBP = 2
+BPDuringExecution = 0
+[CFI]
+CFISize = 0x00
+CFIAddr = 0x00
+[CPU]
+MonModeVTableAddr = 0xFFFFFFFF
+MonModeDebug = 0
+MaxNumAPs = 0
+LowPowerHandlingMode = 0
+OverrideMemMap = 0
+AllowSimulation = 1
+ScriptFile=""
+[FLASH]
+Loaders=""
+EraseType = 0x00
+CacheExcludeSize = 0x00
+CacheExcludeAddr = 0x00
+MinNumBytesFlashDL = 0
+SkipProgOnCRCMatch = 1
+VerifyDownload = 1
+AllowCaching = 1
+EnableFlashDL = 2
+Override = 0
+Device="ARM7"
+[GENERAL]
+WorkRAMSize = 0x00
+WorkRAMAddr = 0x00
+RAMUsageLimit = 0x00
+[SWO]
+SWOLogFile=""
+[MEM]
+RdOverrideOrMask = 0x00
+RdOverrideAndMask = 0xFFFFFFFF
+RdOverrideAddr = 0xFFFFFFFF
+WrOverrideOrMask = 0x00
+WrOverrideAndMask = 0xFFFFFFFF
+WrOverrideAddr = 0xFFFFFFFF
+[RAM]
+VerifyDownload = 0x00

Разница между файлами не показана из-за своего большого размера
+ 2615 - 0
Project/Listings/AirControlValve.map


Разница между файлами не показана из-за своего большого размера
+ 1068 - 0
Project/Listings/startup_ac780x.lst


+ 0 - 0
Project/Objects/tmp.txt


+ 72 - 0
Project/RTE/Device/AC78013MDQA/device_assert.h

@@ -0,0 +1,72 @@
+/* Copyright Statement:
+*
+* This software/firmware and related documentation ("AutoChips Software") are
+* protected under relevant copyright laws. The information contained herein is
+* confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+* the prior written permission of AutoChips inc. and/or its licensors, any
+* reproduction, modification, use or disclosure of AutoChips Software, and
+* information contained herein, in whole or in part, shall be strictly
+* prohibited.
+*
+* AutoChips Inc. (C) 2020. All rights reserved.
+*
+* BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+* RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+* ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+* WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+* RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+* INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+* TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+* RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+* OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+* SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+* RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+* STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+* ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+* RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+* AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+* CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+*/
+
+#ifndef _DEVICE_ASSERT_H
+#define _DEVICE_ASSERT_H
+/*!
+* @file device_assert.c
+*
+* @brief This file provides assert functions.
+*
+*/
+
+/* ===========================================  Includes  =========================================== */
+
+/* ============================================  Define  ============================================ */
+/*!
+* @brief The assert_param macro is used for function's check.
+*
+* @param  expr: If x is false, it calls assert_failed function which reports 
+*         the name of the source file and the source line number of the call 
+*         that failed. If x is true, it returns no value.
+* @retval none
+*/
+#ifdef ATC_DEVICE_ASSERT
+    #define DEVICE_ASSERT(x) ((x) ? (void)0 : (void)printf("[ASSERT]Detect error on %s %d\n", __FILE__, __LINE__) )
+#elif CUSTOM_DEVICE_ASSERT
+    /* If the CUSTOM_DEVICE_ASSERT symbol is defined, then add the custom implementation */
+#else
+    #define DEVICE_ASSERT(x) ((void)0)
+#endif
+
+/* ===========================================  Typedef  ============================================ */
+
+/* ==========================================  Variables  =========================================== */
+
+/* ====================================  Functions declaration  ===================================== */
+
+/* ======================================  Functions define  ======================================== */
+
+#endif /* _DEVICE_ASSERT_H */
+
+/* =============================================  EOF  ============================================== */

+ 290 - 0
Project/RTE/Device/AC78013MDQA/startup_ac780x.s

@@ -0,0 +1,290 @@
+; /* Copyright Statement:
+; *
+; * This software/firmware and related documentation ("AutoChips Software") are
+; * protected under relevant copyright laws. The information contained herein is
+; * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+; * the prior written permission of AutoChips inc. and/or its licensors, any
+; * reproduction, modification, use or disclosure of AutoChips Software, and
+; * information contained herein, in whole or in part, shall be strictly
+; * prohibited.
+; *
+; * AutoChips Inc. (C) 2020. All rights reserved.
+; *
+; * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+; * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+; * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+; * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+; * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+; * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+; * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+; * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+; * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+; * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+; * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+; * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+; * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+; * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+; * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+; * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+; * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+; * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+; * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+; */
+
+;/*
+;//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
+;*/
+
+
+; <h> Stack Configuration
+;   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
+; </h>
+
+Stack_Size      EQU     0x00000400
+
+                AREA    STACK, NOINIT, READWRITE, ALIGN=3
+Stack_Mem       SPACE   Stack_Size
+__initial_sp
+
+
+; <h> Heap Configuration
+;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
+; </h>
+
+Heap_Size       EQU     0x00000000
+
+                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
+__heap_base
+Heap_Mem        SPACE   Heap_Size
+__heap_limit
+
+
+                PRESERVE8
+                THUMB
+
+
+; Vector Table Mapped to Address 0 at Reset
+
+                AREA    RESET, DATA, READONLY
+                EXPORT  __Vectors
+                EXPORT  __Vectors_End
+                EXPORT  __Vectors_Size
+
+__Vectors       DCD     __initial_sp               ; Top of Stack
+                DCD     Reset_Handler              ; Reset Handler
+                DCD     NMI_Handler                ; NMI Handler
+                DCD     HardFault_Handler          ; Hard Fault Handler
+                DCD     0                          ; Reserved
+                DCD     0                          ; Reserved
+                DCD     0                          ; Reserved
+                DCD     0                          ; Reserved
+                DCD     0                          ; Reserved
+                DCD     0                          ; Reserved
+                DCD     0                          ; Reserved
+                DCD     SVC_Handler                ; SVCall Handler
+                DCD     0                          ; Reserved
+                DCD     0                          ; Reserved
+                DCD     PendSV_Handler             ; PendSV Handler
+                DCD     SysTick_Handler            ; SysTick Handler
+
+                ; External Interrupts
+                DCD     PWDT0_IRQHandler           ;  0: PWDT0 interrupt
+                DCD     PWDT1_IRQHandler           ;  1: PWDT1 interrupt
+                DCD     PWM0_IRQHandler            ;  2: PWM0 interrupt
+                DCD     PWM1_IRQHandler            ;  3: PWM1 interrupt
+                DCD     ACMP0_IRQHandler           ;  4: ACMP0 interrupt
+                DCD     UART0_IRQHandler           ;  5: UART0 interrupt
+                DCD     UART1_IRQHandler           ;  6: UART1 interrupt
+                DCD     UART2_IRQHandler           ;  7: UART2 interrupt
+                DCD     WDG_IRQHandler             ;  8: WDG interrupt
+                DCD     SPI0_IRQHandler            ;  9: SPI0 interrupt
+                DCD     SPI1_IRQHandler            ; 10: SPI1 interrupt
+                DCD     I2C0_IRQHandler            ; 11: I2C0 Interrupt
+                DCD     I2C1_IRQHandler            ; 12: I2C1 Interrupt
+                DCD     DMA0_Channel0_IRQHandler   ; 13: DMA0 channel 0 interrupt
+                DCD     DMA0_Channel1_IRQHandler   ; 14: DMA0 channel 1 interrupt
+                DCD     DMA0_Channel2_IRQHandler   ; 15: DMA0 channel 2 interrupt
+                DCD     DMA0_Channel3_IRQHandler   ; 16: DMA0 channel 3 interrupt
+                DCD     TIMER_Channel0_IRQHandler  ; 17: TIMER channel 0 interrupt
+                DCD     TIMER_Channel1_IRQHandler  ; 18: TIMER channel 1 interrupt
+                DCD     TIMER_Channel2_IRQHandler  ; 19: TIMER channel 2 interrupt
+                DCD     TIMER_Channel3_IRQHandler  ; 20: TIMER channel 3 interrupt
+                DCD     RTC_IRQHandler             ; 21: RTC Interrupt
+                DCD     PVD_IRQHandler             ; 22: PVD Interrupt
+                DCD     SPM_IRQHandler             ; 23: SPM interrupt
+                DCD     CAN0_Handler               ; 24: CAN0 interrupt
+                DCD     ADC0_IRQHandler            ; 25: ADC0 interrupt
+                DCD     ECC_SRAM_IRQHandler        ; 26: ECC SRAM interrupt
+                DCD     EXTI0_IRQHandler           ; 27: GPIOx PIN0 external interrupt
+                DCD     EXTI1_IRQHandler           ; 28: GPIOx PIN1 external interrupt
+                DCD     EXTI2_IRQHandler           ; 29: GPIOx PIN2 external interrupt
+                DCD     EXTI3_8_IRQHandler         ; 30: GPIOx PIN3~8 external interrupt
+                DCD     EXTI9_15_IRQHandler        ; 31: GPIOx PIN9~15 external interrupt
+__Vectors_End
+
+__Vectors_Size  EQU     __Vectors_End - __Vectors
+
+                AREA    |.text|, CODE, READONLY
+
+
+; Reset Handler
+
+Reset_Handler   PROC
+                EXPORT  Reset_Handler             [WEAK]
+                IMPORT  SystemInit
+                IMPORT  __main
+
+                LDR     R0, =SystemInit
+                BLX     R0
+
+                LDR     R0, =0x40008810
+                LDR     R1, =0x000C0000
+                STR     R1, [R0]
+
+                LDR     R0, =0x40008850
+                LDR     R1, =0x01C00000
+                STR     R1, [R0]
+
+                LDR     R0, =0x20080014
+                LDR     R1, =0xFFFF
+                STRH    R1, [R0]
+
+                LDR     R0, =0x20080044
+                LDR     R1, =0xFFFF
+                STRH    R1, [R0]
+
+                LDR     R0, =0x20080074
+                LDR     R1, =0x3FF
+                STRH    R1, [R0]
+
+                LDR     R0, =__main
+                BX      R0
+                ENDP
+
+
+; Dummy Exception Handlers (infinite loops which can be modified)
+
+NMI_Handler     PROC
+                EXPORT  NMI_Handler               [WEAK]
+                B       .
+                ENDP
+HardFault_Handler\
+                PROC
+                EXPORT  HardFault_Handler         [WEAK]
+                B       .
+                ENDP
+SVC_Handler     PROC
+                EXPORT  SVC_Handler               [WEAK]
+                B       .
+                ENDP
+PendSV_Handler  PROC
+                EXPORT  PendSV_Handler            [WEAK]
+                B       .
+                ENDP
+SysTick_Handler PROC
+                EXPORT  SysTick_Handler           [WEAK]
+                B       .
+                ENDP
+
+Default_Handler PROC
+
+                EXPORT  PWDT0_IRQHandler           [WEAK]
+                EXPORT  PWDT1_IRQHandler           [WEAK]
+                EXPORT  PWM0_IRQHandler            [WEAK]
+                EXPORT  PWM1_IRQHandler            [WEAK]
+                EXPORT  ACMP0_IRQHandler           [WEAK]
+                EXPORT  UART0_IRQHandler           [WEAK]
+                EXPORT  UART1_IRQHandler           [WEAK]
+                EXPORT  UART2_IRQHandler           [WEAK]
+                EXPORT  WDG_IRQHandler             [WEAK]
+                EXPORT  SPI0_IRQHandler            [WEAK]
+                EXPORT  SPI1_IRQHandler            [WEAK]
+                EXPORT  I2C0_IRQHandler            [WEAK]
+                EXPORT  I2C1_IRQHandler            [WEAK]
+                EXPORT  DMA0_Channel0_IRQHandler   [WEAK]
+                EXPORT  DMA0_Channel1_IRQHandler   [WEAK]
+                EXPORT  DMA0_Channel2_IRQHandler   [WEAK]
+                EXPORT  DMA0_Channel3_IRQHandler   [WEAK]
+                EXPORT  TIMER_Channel0_IRQHandler  [WEAK]
+                EXPORT  TIMER_Channel1_IRQHandler  [WEAK]
+                EXPORT  TIMER_Channel2_IRQHandler  [WEAK]
+                EXPORT  TIMER_Channel3_IRQHandler  [WEAK]
+                EXPORT  RTC_IRQHandler             [WEAK]
+                EXPORT  PVD_IRQHandler             [WEAK]
+                EXPORT  SPM_IRQHandler             [WEAK]
+                EXPORT  CAN0_Handler               [WEAK]
+                EXPORT  ADC0_IRQHandler            [WEAK]
+                EXPORT  ECC_SRAM_IRQHandler        [WEAK]
+                EXPORT  EXTI0_IRQHandler           [WEAK]
+                EXPORT  EXTI1_IRQHandler           [WEAK]
+                EXPORT  EXTI2_IRQHandler           [WEAK]
+                EXPORT  EXTI3_8_IRQHandler         [WEAK]
+                EXPORT  EXTI9_15_IRQHandler        [WEAK]
+
+PWDT0_IRQHandler
+PWDT1_IRQHandler
+PWM0_IRQHandler
+PWM1_IRQHandler
+ACMP0_IRQHandler
+UART0_IRQHandler
+UART1_IRQHandler
+UART2_IRQHandler
+WDG_IRQHandler
+SPI0_IRQHandler
+SPI1_IRQHandler
+I2C0_IRQHandler
+I2C1_IRQHandler
+DMA0_Channel0_IRQHandler
+DMA0_Channel1_IRQHandler
+DMA0_Channel2_IRQHandler
+DMA0_Channel3_IRQHandler
+TIMER_Channel0_IRQHandler
+TIMER_Channel1_IRQHandler
+TIMER_Channel2_IRQHandler
+TIMER_Channel3_IRQHandler
+RTC_IRQHandler
+PVD_IRQHandler
+SPM_IRQHandler
+CAN0_Handler
+ADC0_IRQHandler
+ECC_SRAM_IRQHandler
+EXTI0_IRQHandler
+EXTI1_IRQHandler
+EXTI2_IRQHandler
+EXTI3_8_IRQHandler
+EXTI9_15_IRQHandler
+                B       .
+
+                ENDP
+
+
+                ALIGN
+
+
+; User Initial Stack & Heap
+
+                IF      :DEF:__MICROLIB
+
+                EXPORT  __initial_sp
+                EXPORT  __heap_base
+                EXPORT  __heap_limit
+
+                ELSE
+
+                IMPORT  __use_two_region_memory
+                EXPORT  __user_initial_stackheap
+
+__user_initial_stackheap PROC
+                LDR     R0, =  Heap_Mem
+                LDR     R1, =(Stack_Mem + Stack_Size)
+                LDR     R2, = (Heap_Mem +  Heap_Size)
+                LDR     R3, = Stack_Mem
+                BX      LR
+                ENDP
+
+                ALIGN
+
+                ENDIF
+
+
+                END

+ 585 - 0
Project/RTE/Device/AC78013MDQA/system_ac780x.c

@@ -0,0 +1,585 @@
+/* Copyright Statement:
+*
+* This software/firmware and related documentation ("AutoChips Software") are
+* protected under relevant copyright laws. The information contained herein is
+* confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+* the prior written permission of AutoChips inc. and/or its licensors, any
+* reproduction, modification, use or disclosure of AutoChips Software, and
+* information contained herein, in whole or in part, shall be strictly
+* prohibited.
+*
+* AutoChips Inc. (C) 2020. All rights reserved.
+*
+* BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+* RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+* ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+* WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+* RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+* INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+* TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+* RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+* OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+* SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+* RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+* STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+* ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+* RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+* AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+* CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+*/
+
+/*!
+* @file system_ac780x.c
+*
+* @brief This file provides system clock config integration functions.
+*
+*/
+
+/* ===========================================  Includes  =========================================== */
+#include "ac780x.h"
+
+/* ============================================  Define  ============================================ */
+
+#define  XTAL            ( USE_XTAL )      /* Oscillator frequency */
+#define  SYSTEM_CLOCK    ( SYSCLK_FREQ )   /* system clock frequency */
+
+#define MAX_SYSTICK_COUNT (SysTick_LOAD_RELOAD_Msk + 1)  /* systemTick max count value */
+
+/* for eFlash clock config */
+#define SYS_EFLSH_UNLOCK_KEY1 0xac7811
+#define SYS_EFLSH_UNLOCK_KEY2 0x01234567
+#define Eflash_KEY_REG        0x40002000
+#define EFLASH_INFO_REG       0x40002004
+#define EFLASH_CTRL1_REG      0x40002014
+#define EFLASH_CTRL2_REG      0x40002040
+
+#define SYSTEM_CLOCK_SRC_HSI  0UL
+#define SYSTEM_CLOCK_SRC_PLL  1UL
+#define SYSTEM_CLOCK_SRC_HSE  2UL
+/* ===========================================  Typedef  ============================================ */
+
+/* ==========================================  Variables  =========================================== */
+/* systemTick us delay factor */
+static uint32_t  s_facus = 0;
+
+/* systemTick ms delay factor */
+static uint32_t  s_facms = 0;
+
+/* system clock frequency save */
+uint32_t SystemCoreClock = SYSTEM_CLOCK;
+
+/* apbclk frequency save */
+uint32_t g_periphAPBClock = SYSTEM_CLOCK / 2;
+
+/* define system pll prediv value */
+static __IOM uint8_t s_pllPREDIV[] = {1, 2, 4};
+
+/* ====================================  Functions declaration  ===================================== */
+
+/* Externals declaration */
+#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
+extern uint32_t __Vectors;
+#endif
+
+/* ======================================  Functions define  ======================================== */
+
+/*!
+* @brief Init Delay count factor, 1s = TICKS * (1/f)  s;
+*
+* @param[in]  none
+* @return none
+*/
+void InitDelay(void)
+{
+    s_facus = __SYSTEM_CLOCK / 1000000;
+    s_facms = s_facus * 1000;
+}
+
+/*!
+* @brief Set HSE bypass mode. if xosc enable fail then change system clock to HSI(8m).
+*
+* @param[in]  none
+* @return none
+*/
+void SetHSEBYPClock(void)
+{
+    __IO PLL_ReferenceType pllReference = PLL_REF_INTERAL_OSC;
+
+    /* enable xosc bypass mode */
+    SPM_EnableXOSCBypassMode(ENABLE);
+    CKGEN_SetSysclkDiv(SYSCLK_DIV);
+    /* check if xosc enable success? */
+    if (SPM_EnableXOSC(ENABLE) == SUCCESS)
+    {
+        CKGEN_SetPLLReference(PLL_REF_EXTERNAL_OSC);
+        pllReference = PLL_REF_EXTERNAL_OSC;
+    }
+    else
+    {
+        /* xosc enable fail, use hsi(8m) as pll clock(default) */
+        CKGEN_SetPLLReference(PLL_REF_INTERAL_OSC);
+        pllReference = PLL_REF_INTERAL_OSC;
+    }
+
+    /* check if pll enable success? */
+    if (SPM_EnablePLL(ENABLE) == SUCCESS)
+    {
+        CKGEN_SetPllPrevDiv(PLL_PREDIV);
+        CKGEN_SetPllPostDiv(PLL_POSDIV);
+        CKGEN_SetPllFeedbackDiv(PLL_FBKDIV);
+        CKGEN_SetSysclkSrc(SYSCLK_SRC_PLL_OUTPUT);
+    }
+    else  /* pll enable fail */
+    {
+        if (pllReference == PLL_REF_EXTERNAL_OSC)
+        {
+            CKGEN_SetSysclkSrc(SYSCLK_SRC_EXTERNAL_OSC);  /* set external osc as sysclk src */
+        }
+        else
+        {
+            CKGEN_SetSysclkSrc(SYSCLK_SRC_INTERNAL_OSC);  /* set internal osc as sysclk src */
+        }
+    }
+}
+
+/*!
+* @brief Set XOSC Clock. if xosc enable fail, change system clock to HSI(8m).
+*
+* @param[in]  none
+* @return none
+*/
+void SetXOSCClock(void)
+{
+    CKGEN_SetSysclkDiv(SYSCLK_DIV);
+    /* check if xosc enable success? */
+    if (SPM_EnableXOSC(ENABLE) == SUCCESS)
+    {
+        /* xosc enable success, use external osc as system clock */
+        CKGEN_SetSysclkSrc(SYSCLK_SRC_EXTERNAL_OSC);
+    }
+    else
+    {
+        /* xosc enable fail, use hsi(8m) as system clock(default) */
+        CKGEN_SetSysclkSrc(SYSCLK_SRC_INTERNAL_OSC);
+    }
+}
+
+/*!
+* @brief Use HSE mode, set the system clock.
+*        pll reference clock default use xosc,if xosc enable fail,change to hsi(8m).
+*        system clock source default use pll output. if pll enable fail, then
+*        stop change system clock source to osc(HSI or HSE).
+*
+* @param[in]  none
+* @return none
+*/
+void SetHSEClock(void)
+{
+    __IO PLL_ReferenceType pllReference = PLL_REF_INTERAL_OSC;
+
+    /* check if xosc enable success? */
+    if (SPM_EnableXOSC(ENABLE) == SUCCESS)
+    {
+        CKGEN_SetPLLReference(PLL_REF_EXTERNAL_OSC);
+        pllReference = PLL_REF_EXTERNAL_OSC;
+    }
+    else  /* if xosc enable fail,change pll reference clock to HSI 8M */
+    {
+        CKGEN_SetPLLReference(PLL_REF_INTERAL_OSC);
+        pllReference = PLL_REF_INTERAL_OSC;
+    }
+
+    /* set system clock divider */
+    CKGEN_SetSysclkDiv(SYSCLK_DIV);
+    /* check if pll enable success? */
+    if (SPM_EnablePLL(ENABLE) == SUCCESS)
+    {
+        CKGEN_SetPllPrevDiv(PLL_PREDIV);
+        CKGEN_SetPllPostDiv(PLL_POSDIV);
+        CKGEN_SetPllFeedbackDiv(PLL_FBKDIV);
+        CKGEN_SetSysclkSrc(SYSCLK_SRC_PLL_OUTPUT);
+    }
+    else  /* pll enable fail */
+    {
+        if (pllReference == PLL_REF_EXTERNAL_OSC)
+        {
+            CKGEN_SetSysclkSrc(SYSCLK_SRC_EXTERNAL_OSC);  /* set external osc as sysclk src */
+        }
+        else
+        {
+            CKGEN_SetSysclkSrc(SYSCLK_SRC_INTERNAL_OSC);  /* set internal osc as sysclk src */
+        }
+    }
+}
+
+/*!
+* @brief Use HSI Mode.Default set pll output as system clock;if pll enable fail
+*        ,change system clock to HSI(8m).
+*
+* @param[in]  none
+* @return none
+*/
+void SetHSIClock(void)
+{
+    CKGEN_SetPLLReference(PLL_REF_INTERAL_OSC);
+    CKGEN_SetPllPrevDiv(PLL_PREDIV);
+    CKGEN_SetPllPostDiv(PLL_POSDIV);
+    CKGEN_SetPllFeedbackDiv(PLL_FBKDIV);
+    CKGEN_SetSysclkDiv(SYSCLK_DIV);
+    /* check if pll enable success? */
+    if (SPM_EnablePLL(ENABLE) == SUCCESS)
+    {
+        /* pll enable success,use pll output as system clock src */
+        CKGEN_SetSysclkSrc(SYSCLK_SRC_PLL_OUTPUT);
+    }
+    else
+    {
+        /* pll enable fail,use hsi(8m) as system clock src */
+        CKGEN_SetSysclkSrc(SYSCLK_SRC_INTERNAL_OSC);
+    }
+}
+
+/*!
+* @brief set system clock
+*
+* @param[in] none
+* @return none
+*/
+void SetSysClock(void)
+{
+#if AC780X_CLOCK_SRC == IC_CLOCK_SRC_XOSC
+    SetXOSCClock();
+#elif AC780X_CLOCK_SRC == IC_CLOCK_SRC_HSI
+    SetHSIClock();
+#elif AC780X_CLOCK_SRC == IC_CLOCK_SRC_HSE
+    SetHSEClock();
+#elif AC780X_CLOCK_SRC == IC_CLOCK_SRC_XOSC_BYPASS
+    SetHSEBYPClock();
+#else
+    SetHSIClock();
+#endif
+}
+
+/**
+* SetEflashClock
+*
+* @param[in] none
+* @return none
+*
+* @brief Set eflash clock.
+*
+**/
+void SetEflashClock(void)
+{
+    uint32_t eflashCKDIV = 0;
+    uint32_t ctrl1 = 0x0;
+    int32_t timeout = 500;
+
+    do
+    {
+        WRITE_MEM32(Eflash_KEY_REG, SYS_EFLSH_UNLOCK_KEY1);
+        WRITE_MEM32(Eflash_KEY_REG, SYS_EFLSH_UNLOCK_KEY2);
+        timeout--;
+    } while ((READ_MEM32(EFLASH_INFO_REG) & ((uint32_t)1 << 31)) && (0 < timeout));
+
+    eflashCKDIV = (SYSCLK_FREQ / 1000000 + 1) & 0x7F;
+    ctrl1 = 0x2000 | eflashCKDIV;
+    WRITE_MEM32(EFLASH_CTRL1_REG, ctrl1);
+
+    SET_BIT32((*(uint32_t*)EFLASH_CTRL1_REG), (uint32_t)1 << 8);
+    SET_BIT32((*(uint32_t*)EFLASH_INFO_REG), (uint32_t)1 << 31);
+}
+
+/*!
+* @brief delay until the syctick count tick to 0
+*
+* @param[in] tick : systick count value
+* @return none
+*/
+static void SysTickDelay(uint32_t tick)
+{
+    __IO uint32_t tickFlag = 0;
+
+    SysTick->LOAD = tick - 1;
+    SysTick->VAL = 0x00;
+    SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
+    do
+    {
+        tickFlag = SysTick->CTRL;
+
+    } while((tickFlag & SysTick_CTRL_ENABLE_Msk) &&
+            (!(tickFlag & SysTick_CTRL_COUNTFLAG_Msk)));
+
+    SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
+    SysTick->VAL = 0X00;
+}
+
+/*!
+* @brief Repeatlly delay the ticks for the given times
+*
+* @param[in] param : times, the times of delay the tick
+* @param[in] param : tick, each tick to delay
+* @return none
+*/
+static void SysTickRepeatDelay(uint32_t times, uint32_t tick)
+{
+    uint32_t i = 0;
+
+    for (i = 0; i < times; i++)
+    {
+        SysTickDelay(tick);
+    }
+}
+
+/*!
+* @brief delay us
+*
+* @param[in] param : us, us for delay
+* @return none
+*/
+void udelay(uint32_t us)
+{
+    uint32_t tick = us * s_facus;
+
+    SysTickRepeatDelay(tick / MAX_SYSTICK_COUNT, MAX_SYSTICK_COUNT);
+
+    SysTickDelay(tick % MAX_SYSTICK_COUNT);
+}
+
+/*!
+* @brief delay ms
+*
+* @param[in] param : ms, ms for delay
+* @return none
+*/
+void mdelay(uint32_t ms)
+{
+    uint32_t tick = ms * s_facms;
+
+    SysTickRepeatDelay(tick / MAX_SYSTICK_COUNT, MAX_SYSTICK_COUNT);
+
+    SysTickDelay(tick % MAX_SYSTICK_COUNT);
+}
+
+
+/*!
+* @brief get system clock frequence
+*
+* @param[in] none
+* @return none
+*/
+void SystemCoreClockUpdate(void)
+{
+    __IO uint8_t clkSrc = 0, postDiv = 0, feedbackDiv = 0, sysclkDiv = 0;
+    __IO uint8_t pllRef = 0, preDiv = 0, apbClkDiv = 0;
+    __IO uint32_t vcoClk = 0;
+
+    clkSrc = CKGEN->CTRL & CKGEN_CTRL_SYSCLK_SEL_Msk;
+    apbClkDiv = ((CKGEN->CTRL & CKGEN_CTRL_APBCLK_DIV_Msk) >> CKGEN_CTRL_APBCLK_DIV_Pos) + 1;
+    switch (clkSrc)
+    {
+    case SYSTEM_CLOCK_SRC_HSI:
+        SystemCoreClock = HSI_FREQ;  /* HSI RC */
+
+        break;
+    case SYSTEM_CLOCK_SRC_PLL:
+        /* PLL Output */
+        pllRef = (CKGEN->CTRL & CKGEN_CTRL_PLL_REF_SEL_Msk) >> CKGEN_CTRL_PLL_REF_SEL_Pos;
+        sysclkDiv = ((CKGEN->CTRL & CKGEN_CTRL_SYSCLK_DIV_Msk) >> CKGEN_CTRL_SYSCLK_DIV_Pos) + 1;
+        preDiv = s_pllPREDIV[(CKGEN->SYSPLL1_CFG0 & CKGEN_SYSPLL1_CFG0_SYSPLL1_PREDIV_Msk) >> CKGEN_SYSPLL1_CFG0_SYSPLL1_PREDIV_Pos];
+        postDiv = ((CKGEN->SYSPLL1_CFG0 & CKGEN_SYSPLL1_CFG0_SYSPLL1_POSDIV_Msk) >> CKGEN_SYSPLL1_CFG0_SYSPLL1_POSDIV_Pos) * 2;
+        feedbackDiv = (CKGEN->SYSPLL1_CFG0 & CKGEN_SYSPLL1_CFG0_SYSPLL1_FBKDIV_Msk) >> CKGEN_SYSPLL1_CFG0_SYSPLL1_FBKDIV_Pos;
+        if (pllRef)
+        {
+            /* ext xosc clock */
+            SystemCoreClock = USE_XTAL;
+        }
+        else
+        {
+            /* internal RC */
+            SystemCoreClock = HSI_FREQ;
+        }
+
+        vcoClk = (SystemCoreClock * feedbackDiv) / preDiv;   /* pll vco clock */
+        SystemCoreClock = vcoClk / (postDiv * sysclkDiv);    /* system clock freq */
+        break;
+    case SYSTEM_CLOCK_SRC_HSE:
+        SystemCoreClock = USE_XTAL;  /* HSE XTAL */
+        break;
+
+    default:
+        break;
+    }
+
+    g_periphAPBClock = SystemCoreClock / apbClkDiv;    /* apb clock freq */
+}
+
+/*!
+* @brief Setup the microcontroller system. Initialize the System.
+*
+* @param[in] none
+* @return none
+*/
+void SystemInit (void)
+{
+#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
+    SCB->VTOR = (uint32_t) &__Vectors;
+#endif
+
+    SystemCoreClock = SYSTEM_CLOCK;
+
+    SetEflashClock();
+    SetSysClock();
+    CKGEN_SetAPBClockDivider(APBCLK_DIV);
+    //SPM_EnableLVD(DISABLE);  //disable LVD if need
+}
+
+/*!
+* @brief  change the current menu and display
+*
+* @param[in]
+* @return return the CPUID
+*/
+uint32_t GetCPUID(void)
+{
+    return SCB->CPUID;
+}
+
+/*!
+* @brief enter the Standby mode
+*
+* @param[in] none
+* @return none
+*/
+void SysStandby(void)
+{
+    SPM_SetLowPowerMode(LOW_POWER_MODE_STANDBY);
+    /* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */
+    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
+
+#if defined ( __ICCARM__ )
+    asm("WFI");
+#elif defined ( __GNUC__)
+    asm("WFI");
+#elif defined (__CC_ARM)
+    // If using KEIL's uVision, use the CMSIS intrinsic
+    __wfi();
+#endif
+
+}
+
+/*!
+* @brief enter the Stop mode
+*
+* @param[in] none
+* @return none
+*/
+void SysStop(void)
+{
+    SPM_SetLowPowerMode(LOW_POWER_MODE_STOP);
+    /* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */
+    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
+#if defined ( __ICCARM__ )
+    asm("WFI");
+#elif defined ( __GNUC__)
+    asm("WFI");
+#elif defined (__CC_ARM)
+    // If using KEIL's uVision, use the CMSIS intrinsic
+    __wfi();
+#endif
+    // Add Debug Interface to enable printf after wakeup
+}
+
+/*!
+* @brief enter the Sleep mode
+*
+* @param[in] none
+* @return none
+*/
+void SysSleep(void)
+{
+    /* Clear the SLEEPDEEP bit to make sure we go into WAIT (sleep) mode instead
+    * of deep sleep.
+    */
+
+    SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
+#if defined ( __ICCARM__ )
+    asm("WFI");
+#elif defined ( __GNUC__)
+    asm("WFI");
+#elif defined (__CC_ARM)
+    // If using KEIL's uVision, use the CMSIS intrinsic
+    __wfi();
+#endif
+}
+
+/*!
+* @brief get uuid from device
+*
+* @param[in] uuidBuffer: uuid buffer
+* @return none
+*/
+void GetUUID(uint32_t *uuidBuffer)
+{
+#define UUID_BASE_ADDRESS  0x4000202C
+
+    uint8_t i = 0;
+
+    if(0 != uuidBuffer)
+    {
+        for (i = 0; i < 4; i++)
+        {
+            uuidBuffer[i] = (*(__IO uint32_t *)(UUID_BASE_ADDRESS  + i * 4));
+        }
+    }
+}
+
+/*!
+* @brief get cpu type from device
+*
+* @param[in] none
+* @return cpu type: AC7801(0xFFAC7801)/AC7811(0xFFAC7811)
+*/
+uint32_t GetCpuType(void)
+{
+#define CPU_TYPE_BASE_ADDRESS  0x40002028
+
+    return (*(__IO uint32_t *)(CPU_TYPE_BASE_ADDRESS));
+}
+
+/*!
+* @brief get reset status
+*
+* @param[in] none
+* @return reset status
+*            - bit0: POR_RESET_STATUS
+*            - bit1: LVD_RESET_STATUS
+*            - bit2: EXT_RESET_STATUS
+*            - bit4: WDT_RESET_STATUS
+*            - bit5: WDT_32K_RESET_STATUS
+*            - bit6: CPU_SYSRESET_STATUS
+*            - bit7: CPU_LOCKUP_RST_STATUS
+*            - bit8: PLL_UNLOCK_RST_STATUS
+*            - bit9: XOSC_LOSS_STATUS
+*            - bit16: CLEAR_ALL_RESET_STATUS
+*/
+uint32_t GetResetStatus(void)
+{
+    return (CKGEN->RESET_STATUS);
+}
+
+/*!
+* @brief clear all reset status
+*
+* @param[in] none
+* @return none
+*/
+void ClearAllResetStatus(void)
+{
+    CKGEN->RESET_STATUS |= (1 << 16);
+}
+
+/* =============================================  EOF  ============================================== */

+ 228 - 0
Project/RTE/Device/AC78013MDQA/system_ac780x.h

@@ -0,0 +1,228 @@
+/* Copyright Statement:
+*
+* This software/firmware and related documentation ("AutoChips Software") are
+* protected under relevant copyright laws. The information contained herein is
+* confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+* the prior written permission of AutoChips inc. and/or its licensors, any
+* reproduction, modification, use or disclosure of AutoChips Software, and
+* information contained herein, in whole or in part, shall be strictly
+* prohibited.
+*
+* AutoChips Inc. (C) 2020. All rights reserved.
+*
+* BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+* RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+* ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+* WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+* NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+* RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+* INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+* TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+* RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+* OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+* SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+* RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+* STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+* ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+* RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+* AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+* CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+*/
+
+#ifndef _SYSTEM_AC780X_H
+#define _SYSTEM_AC780X_H
+
+/*!
+* @file system_ac780x.h
+*
+* @brief This file provides system clock config integration functions interfaces.
+*
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ===========================================  Includes  =========================================== */
+#include "ac780x_ckgen.h"
+#include "ac780x_spm.h"
+#include "device_assert.h"
+#include "ac780x_debugout.h"
+
+/* ============================================  Define  ============================================ */
+
+/*!< global interrupt control */
+#define EnableInterrupts  __ASM(" CPSIE i");
+#define DisableInterrupts __ASM(" CPSID i");
+
+/*!< global fault control */
+#define EnableFatules  __ASM(" CPSIE F");
+#define DisableFatules __ASM(" CPSID F");
+
+#define IC_CLOCK_SRC_HSI         0U  /*!< High speed internal RC(HSI): The internal RC OSC to provide 8MHz clock source */
+#define IC_CLOCK_SRC_HSE         1U  /*!< The external OSC to provide 4MHZ ~30MHz  crystal */
+#define IC_CLOCK_SRC_XOSC        2U  /*!< The external OSC to provide 4MHZ ~30MHz  oscillator */
+#define IC_CLOCK_SRC_XOSC_BYPASS 3U  /*!< The external OSC to provide 4MHZ ~30MHz  oscillator */
+
+#define AC780X_CLOCK_SRC  IC_CLOCK_SRC_HSE /*!< define mcu clock source */
+
+#define HSI_FREQ      8000000UL   /*!< Internal 8M RC clock */
+#define XTAL_16M     16000000UL   /*!< extern crystal oscillator 16m */
+#define XTAL_12M     12000000UL   /*!< extern crystal oscillator 12m */
+#define XTAL_8M       8000000UL   /*!< extern crystal oscillator 8m  */
+#define XTAL_4M       4000000UL   /*!< extern crystal oscillator 4m  */
+#define XTAL_30M     30000000UL   /*!< extern crystal oscillator 30m */
+
+#define USE_XTAL      XTAL_8M  /*!< Select the actual crystal frequency */
+
+/*!< PLL available in HSE & HSI mode */
+#if USE_XTAL == XTAL_16M
+#define PLL_POSDIV   PLL_POSDIV_16
+#define PLL_FBKDIV   96U
+#define PLL_PREDIV   PLL_PREDIV_2
+#elif USE_XTAL == XTAL_12M
+#define PLL_POSDIV   PLL_POSDIV_12
+#define PLL_FBKDIV   96U
+#define PLL_PREDIV   PLL_PREDIV_2
+#elif USE_XTAL == XTAL_8M
+#define PLL_POSDIV   PLL_POSDIV_16
+#define PLL_FBKDIV   96U
+#define PLL_PREDIV   PLL_PREDIV_1
+#elif USE_XTAL == XTAL_4M
+#define PLL_POSDIV   PLL_POSDIV_16
+#define PLL_FBKDIV   192U
+#define PLL_PREDIV   PLL_PREDIV_1
+#elif USE_XTAL == XTAL_30M
+#define PLL_POSDIV   PLL_POSDIV_30
+#define PLL_FBKDIV   48U
+#define PLL_PREDIV   PLL_PREDIV_1
+#else
+#error
+#endif
+
+/*!< VCO = (USE_XTAL * PLL_FBKDIV) / PLL_PREDIV;
+     SYSCLK_FREQ = VCO / PLL_POSDIV / SYSCLK_DIV;
+     APB_BUS_FREQ = SYSCLK_FREQ / APBCLK_DIVIDER_2
+*/
+#define SYSCLK_DIV   SYSCLK_DIVIDER_1
+#define APBCLK_DIV   APBCLK_DIVIDER_2
+#define SYSCLK_FREQ  48000000UL
+#define APB_BUS_FREQ 24000000UL
+
+#define __SYSTEM_CLOCK    SYSCLK_FREQ
+
+/* ===========================================  Typedef  ============================================ */
+
+/* ==========================================  Variables  =========================================== */
+
+extern uint32_t SystemCoreClock;     /*!< System Clock Frequency (Core Clock)  */
+extern uint32_t g_periphAPBClock;    /*!< APB Clock Frequency */
+
+/* ====================================  Functions declaration  ===================================== */
+/*!
+* @brief Setup the microcontroller system. Initialize the System.
+*
+* @param[in] none
+* @return none
+*/
+extern void SystemInit (void);
+/*!
+* @brief get system clock frequence
+*
+* @param[in] none
+* @return none
+*/
+extern void SystemCoreClockUpdate(void);
+/*!
+* @brief Init Delay count factor, 1s = TICKS * (1/f)  s;
+*
+* @param[in] none
+* @return none
+*/
+extern void udelay(uint32_t us);
+/*!
+* @brief delay ms
+*
+* @param[in] param : ms, us for delay
+* @return none
+*/
+extern void mdelay(uint32_t ms);
+/*!
+* @brief Init Delay count factor, 1s = TICKS * (1/f)  s;
+*
+* @param[in] none
+* @return none
+*/
+extern void InitDelay(void);
+/*!
+* @brief enter the Sleep mode
+*
+* @param[in] none
+* @return none
+*/
+extern void SysSleep(void);
+/*!
+* @brief enter the Stop mode
+*
+* @param[in] none
+* @return none
+*/
+extern void SysStop(void);
+/*!
+* @brief enter the Standby mode
+*
+* @param[in] none
+* @return none
+*/
+extern void SysStandby(void);
+/*!
+* @brief get uuid from devie
+*
+* @param[in] uuidBuffer: uuid buffer
+* @return none
+*/
+extern void GetUUID(uint32_t *uuidBuffer);
+
+/*!
+* @brief get cpu type from device
+*
+* @param[in] none
+* @return cpu type: AC7801(0xFFAC7801)/AC7811(0xFFAC7811)
+*/
+extern uint32_t GetCpuType(void);
+
+/*!
+* @brief get reset status
+*
+* @param[in] none
+* @return reset status
+*            - bit0: POR_RESET_STATUS
+*            - bit1: LVD_RESET_STATUS
+*            - bit2: EXT_RESET_STATUS
+*            - bit4: WDT_RESET_STATUS
+*            - bit5: WDT_32K_RESET_STATUS
+*            - bit6: CPU_SYSRESET_STATUS
+*            - bit7: CPU_LOCKUP_RST_STATUS
+*            - bit8: PLL_UNLOCK_RST_STATUS
+*            - bit9: XOSC_LOSS_STATUS
+*            - bit16: CLEAR_ALL_RESET_STATUS
+*/
+extern uint32_t GetResetStatus(void);
+
+/*!
+* @brief clear all reset status
+*
+* @param[in] none
+* @return none
+*/
+extern void ClearAllResetStatus(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYSTEM_AC780X_H */
+
+/* =============================================  EOF  ============================================== */

+ 63 - 0
Project/RTE/_AirControlValve/RTE_Components.h

@@ -0,0 +1,63 @@
+
+/*
+ * Auto generated Run-Time-Environment Configuration File
+ *      *** Do not modify ! ***
+ *
+ * Project: 'AirControlValve' 
+ * Target:  'AirControlValve' 
+ */
+
+#ifndef RTE_COMPONENTS_H
+#define RTE_COMPONENTS_H
+
+
+/*
+ * Define the Device Header File: 
+ */
+#define CMSIS_device_header "ac780x.h"
+
+/* AutoChips::Device:ATC Drivers:ACMP:1.0.0 */
+#define RTE_DEVICE_DRIVER_ACMP
+/* AutoChips::Device:ATC Drivers:ADC:1.0.0 */
+#define RTE_DEVICE_DRIVER_ADC
+/* AutoChips::Device:ATC Drivers:CAN:1.0.0 */
+#define RTE_DEVICE_DRIVER_CAN
+/* AutoChips::Device:ATC Drivers:CKGEN:1.0.0 */
+#define RTE_DEVICE_DRIVER_CKGEN
+/* AutoChips::Device:ATC Drivers:CRC:1.0.0 */
+#define RTE_DEVICE_DRIVER_CRC
+/* AutoChips::Device:ATC Drivers:CTU:1.0.0 */
+#define RTE_DEVICE_DRIVER_CTU
+/* AutoChips::Device:ATC Drivers:DMA:1.0.0 */
+#define RTE_DEVICE_DRIVER_DMA
+/* AutoChips::Device:ATC Drivers:ECC SRAM:1.0.0 */
+#define RTE_DEVICE_DRIVER_ECC_SRAM
+/* AutoChips::Device:ATC Drivers:GPIO:1.0.0 */
+#define RTE_DEVICE_DRIVER_GPIO
+/* AutoChips::Device:ATC Drivers:I2C:1.0.0 */
+#define RTE_DEVICE_DRIVER_I2C
+/* AutoChips::Device:ATC Drivers:MMDIVSQART:1.0.0 */
+#define RTE_DEVICE_DRIVER_MMDIVSQART
+/* AutoChips::Device:ATC Drivers:PWDT:1.0.0 */
+#define RTE_DEVICE_DRIVER_PWDT
+/* AutoChips::Device:ATC Drivers:PWM:1.0.0 */
+#define RTE_DEVICE_DRIVER_PWM
+/* AutoChips::Device:ATC Drivers:RTC:1.0.0 */
+#define RTE_DEVICE_DRIVER_RTC
+/* AutoChips::Device:ATC Drivers:SPI:1.0.0 */
+#define RTE_DEVICE_DRIVER_SPI
+/* AutoChips::Device:ATC Drivers:SPM:1.0.0 */
+#define RTE_DEVICE_DRIVER_SPM
+/* AutoChips::Device:ATC Drivers:TIMER:1.0.0 */
+#define RTE_DEVICE_DRIVER_TIMER
+/* AutoChips::Device:ATC Drivers:UART:1.0.0 */
+#define RTE_DEVICE_DRIVER_UART
+/* AutoChips::Device:ATC Drivers:WDG:1.0.0 */
+#define RTE_DEVICE_DRIVER_WDG
+/* AutoChips::Device:ATC Drivers:eFlash:1.0.0 */
+#define RTE_DEVICE_DRIVER_EFLASH
+/* AutoChips::Device:Startup:1.0.0 */
+#define RTE_DEVICE_STARTUP_AC780X
+
+
+#endif /* RTE_COMPONENTS_H */

+ 63 - 0
Project/RTE/_Target_1/RTE_Components.h

@@ -0,0 +1,63 @@
+
+/*
+ * Auto generated Run-Time-Environment Configuration File
+ *      *** Do not modify ! ***
+ *
+ * Project: 'AirControlValve' 
+ * Target:  'Target 1' 
+ */
+
+#ifndef RTE_COMPONENTS_H
+#define RTE_COMPONENTS_H
+
+
+/*
+ * Define the Device Header File: 
+ */
+#define CMSIS_device_header "ac780x.h"
+
+/* AutoChips::Device:ATC Drivers:ACMP:1.0.0 */
+#define RTE_DEVICE_DRIVER_ACMP
+/* AutoChips::Device:ATC Drivers:ADC:1.0.0 */
+#define RTE_DEVICE_DRIVER_ADC
+/* AutoChips::Device:ATC Drivers:CAN:1.0.0 */
+#define RTE_DEVICE_DRIVER_CAN
+/* AutoChips::Device:ATC Drivers:CKGEN:1.0.0 */
+#define RTE_DEVICE_DRIVER_CKGEN
+/* AutoChips::Device:ATC Drivers:CRC:1.0.0 */
+#define RTE_DEVICE_DRIVER_CRC
+/* AutoChips::Device:ATC Drivers:CTU:1.0.0 */
+#define RTE_DEVICE_DRIVER_CTU
+/* AutoChips::Device:ATC Drivers:DMA:1.0.0 */
+#define RTE_DEVICE_DRIVER_DMA
+/* AutoChips::Device:ATC Drivers:ECC SRAM:1.0.0 */
+#define RTE_DEVICE_DRIVER_ECC_SRAM
+/* AutoChips::Device:ATC Drivers:GPIO:1.0.0 */
+#define RTE_DEVICE_DRIVER_GPIO
+/* AutoChips::Device:ATC Drivers:I2C:1.0.0 */
+#define RTE_DEVICE_DRIVER_I2C
+/* AutoChips::Device:ATC Drivers:MMDIVSQART:1.0.0 */
+#define RTE_DEVICE_DRIVER_MMDIVSQART
+/* AutoChips::Device:ATC Drivers:PWDT:1.0.0 */
+#define RTE_DEVICE_DRIVER_PWDT
+/* AutoChips::Device:ATC Drivers:PWM:1.0.0 */
+#define RTE_DEVICE_DRIVER_PWM
+/* AutoChips::Device:ATC Drivers:RTC:1.0.0 */
+#define RTE_DEVICE_DRIVER_RTC
+/* AutoChips::Device:ATC Drivers:SPI:1.0.0 */
+#define RTE_DEVICE_DRIVER_SPI
+/* AutoChips::Device:ATC Drivers:SPM:1.0.0 */
+#define RTE_DEVICE_DRIVER_SPM
+/* AutoChips::Device:ATC Drivers:TIMER:1.0.0 */
+#define RTE_DEVICE_DRIVER_TIMER
+/* AutoChips::Device:ATC Drivers:UART:1.0.0 */
+#define RTE_DEVICE_DRIVER_UART
+/* AutoChips::Device:ATC Drivers:WDG:1.0.0 */
+#define RTE_DEVICE_DRIVER_WDG
+/* AutoChips::Device:ATC Drivers:eFlash:1.0.0 */
+#define RTE_DEVICE_DRIVER_EFLASH
+/* AutoChips::Device:Startup:1.0.0 */
+#define RTE_DEVICE_STARTUP_AC780X
+
+
+#endif /* RTE_COMPONENTS_H */


+ 323 - 0
User/Basic_uart.c

@@ -0,0 +1,323 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+
+#include <string.h>
+#include "ac780x_uart.h"
+#include "ac780x_gpio.h"
+#include "ac780x_timer.h"
+
+/*
+* 本例程通过使用DMA以及UART空闲中断,实现UART DMA收发,并在UART空闲中断中处理接收的数据
+*/
+
+#define PERH_BUS_CLK		(24000000U)
+#define TIM_CHN2_PRD_1ms	(PERH_BUS_CLK / 1000 - 1)
+
+
+#define UARTx   UART0
+#define UARTx_IRQn  UART0_IRQn
+
+#define RS485CTRL_PORT (GPIOB)
+#define RS485CTRL_PIN  (GPIO_PIN3)
+
+#define RS485_TX_EN				do{GPIO_SetPinLevel(RS485CTRL_PORT, RS485CTRL_PIN, GPIO_LEVEL_HIGH);}while(0)
+#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)
+
+/*RUNLED动作定义.*/	
+#define RUNLED_ON				do{GPIO_SetPinLevel(RUNLED_PORT, RUNLED_PIN, GPIO_LEVEL_HIGH);}while(0)
+#define RUNLED_OFF			do{GPIO_SetPinLevel(RUNLED_PORT, RUNLED_PIN, GPIO_LEVEL_LOW);}while(0)
+#define RUNLED_TOGGLE			do{if(GPIO_GetPinLevel(RUNLED_PORT, RUNLED_PIN)){RUNLED_OFF;}else{RUNLED_ON;}}while(0)
+
+
+#define BaudRate    9600
+
+#define UART_TRANSMIT_DATA_POOL_COUNT 64
+#define UART_RECV_DATA_POOL_COUNT     64
+///这里DMA mem设置为32bit模式,所以DMA传输的buffer必须4字节对齐
+uint32_t dmaRxBuf[UART_RECV_DATA_POOL_COUNT>>2];
+uint32_t dmaTxBuf[UART_TRANSMIT_DATA_POOL_COUNT>>2];
+
+uint8_t *rxBuf = (uint8_t *)dmaRxBuf;
+uint8_t *txBuf = (uint8_t *)dmaTxBuf;
+
+uint8_t trans_finished = 1;
+
+uint16_t		g_scanKeyTime;		/*扫描按键间隔时间*/
+uint16_t	g_blinkLedTime;		/*LED闪烁频率控制时间*/
+uint16_t	g_blinkLedTgtTime;	/*LED目标闪烁频率*/
+
+
+
+/**
+* UARTTX_DMA_EventCallback
+*
+* @param[in] device: DMA_Type pointer
+* @param[in] wpara: DMA Channel Status
+* @param[in] lpara: reserve for user's code
+* @return    none
+*
+* @brief   uart transmit event callback
+*/
+void UartTxDMAEventCallback(void *device, uint32_t wpara, uint32_t lpara)
+{
+    if (wpara & DMA_CHANNEL_STATUS_FINISH_Msk)    //!<DMA finish
+    {
+        //RS485_RX_EN; 
+			trans_finished = 100;
+    }
+    else if (wpara & DMA_CHANNEL_STATUS_HALF_FINISH_Msk)  //!<DMA half finish
+    {
+        
+    }
+    else if (wpara & DMA_CHANNEL_STATUS_TRANS_ERROR_Msk)  //!<DMA error
+    {
+        
+    }
+    else
+    {
+        //!<never be here
+    }
+}
+
+
+/**
+* UARTRX_DMA_EventCallback
+*
+* @param[in] device: DMA_Type pointer
+* @param[in] wpara: DMA Channel Status
+* @param[in] lpara: reserve for user's code
+* @return    none
+*
+* @brief   uart dma receive handle
+*/
+static void UartRxDMAEventCallback(void *device, uint32_t wpara, uint32_t lpara)
+{
+    /* Check if DMA Channel Receive Complete */
+    if (wpara & DMA_CHANNEL_STATUS_FINISH_Msk)    //!<DMA finish
+    {
+
+    }
+    else if (wpara & DMA_CHANNEL_STATUS_HALF_FINISH_Msk)  //!<DMA half finish
+    {
+        
+    }
+    else if (wpara & DMA_CHANNEL_STATUS_TRANS_ERROR_Msk)  //!<DMA error
+    {
+        
+    }
+    else
+    {
+        //!<never be here
+    }
+}
+/**
+* UARTRX_DMA_EventCallback
+*
+* @param[in] device: UART_Type pointer
+* @param[in] wpara: UART lsr0 register
+* @param[in] lpara: UART lsr1 register
+* @return    none
+*
+* @brief   uart dma receive handle
+*/
+static void UartRxIdleCallBack(void *device, uint32_t wpara, uint32_t lpara)
+{
+    /* Check if IDLE interrupt happened */
+    if (lpara & UART_LSR1_IDLE_Msk)
+    {
+        uint16_t recLen;
+        uint16_t index;
+        ///接收不足4字节会在DMA fifo中缓存
+        recLen = DMA0_CHANNEL1->DATA_TRANS_NUM + DMA0_CHANNEL1->FIFO_LEFT_NUM;
+        ///将DMA fifo数据flush出来,因为mem设置为32bit,所以fifo也是4字节对齐
+        ///(即使fifo里只有1个字节也会刷出4字节,需要保证缓存冗余不会溢出)
+        DMA_ChannelFlush(DMA0_CHANNEL1);
+        for (index=0;index<recLen;index++)
+        {
+            txBuf[index] = rxBuf[index];
+        }
+				
+				RS485_TX_EN; 
+				trans_finished = 1;
+        UART_TransmitDMA(UARTx, DMA0_CHANNEL0, txBuf, recLen, UartTxDMAEventCallback); 
+
+        UART_ReceiveDMA(UARTx, DMA0_CHANNEL1, rxBuf, UART_RECV_DATA_POOL_COUNT, UartRxDMAEventCallback); 
+    }
+}
+
+/*************<prototype>**************/
+void TIM_CHN2_Callback(void *device, uint32_t wpara, uint32_t lpara);
+
+/**
+* @prototype TIMER_PrdInit(void)
+*
+* @param[in] void
+* @return	 void
+*
+* @brief  	 初始化定时器通道2.
+*/
+void TIMER_PrdInit(void)
+{
+	TIMER_ConfigType tmrConfig;
+	
+	/*清零变量.*/
+	memset(&tmrConfig, 0x00, sizeof(tmrConfig));
+	
+	/*配置定时器.*/
+	tmrConfig.linkModeEn	= DISABLE;
+	tmrConfig.interruptEn	= ENABLE;	
+	tmrConfig.periodValue	= TIM_CHN2_PRD_1ms;
+	tmrConfig.timerEn		= ENABLE;
+	tmrConfig.callBack 		= TIM_CHN2_Callback;
+	TIMER_Init(TIMER_CHANNEL2, &tmrConfig);
+}
+
+/**
+* @prototype TIM_CHN2_Callback(void *device, uint32_t wpara, uint32_t lpara)
+*
+* @param[in] ...
+* @return	 void
+*
+* @brief  	 定时器通道2中断回调函数.
+*/
+void TIM_CHN2_Callback(void *device, uint32_t wpara, uint32_t lpara)
+{
+	if (g_scanKeyTime < 0xFFFF)
+	{
+		g_scanKeyTime++;
+	}
+	
+	if (g_blinkLedTime < 0xFFFF)
+	{
+		g_blinkLedTime++;
+	}
+	
+	if(trans_finished > 0 ){
+		trans_finished++;
+	}
+	
+}
+
+/**
+* Basic_uart
+*
+* @param[in] none
+* @return    none
+*
+* @brief  Basic_uart function
+*/
+void Basic_uart(void)
+{
+    uint8_t i = 0;
+    UART_ConfigType  uartConfig;
+    memset((void *)&uartConfig, 0, sizeof(UART_ConfigType));
+
+    //set pin mux
+    GPIO_SetFunc(GPIOA, GPIO_PIN7, GPIO_FUN1);
+    GPIO_SetFunc(GPIOA, GPIO_PIN8, GPIO_FUN1);
+	
+		//GPIO_SetDir(GPIOA, GPIO_PIN7, GPIO_OUT);
+		//GPIO_SetPullup(GPIOA, GPIO_PIN7, ENABLE);
+		//GPIO_SetDir(GPIOA, GPIO_PIN8, GPIO_IN);
+	
+		GPIO_SetFunc(RS485CTRL_PORT, RS485CTRL_PIN, GPIO_FUN0);
+		GPIO_SetDir(RS485CTRL_PORT, RS485CTRL_PIN, GPIO_OUT);
+	
+		GPIO_SetFunc(RUNLED_PORT, RUNLED_PIN, GPIO_FUN0);
+		GPIO_SetDir(RUNLED_PORT, RUNLED_PIN, GPIO_OUT);
+    
+    uartConfig.baudrate = BaudRate;
+    uartConfig.dataBits = UART_WORD_LEN_8BIT;
+    uartConfig.stopBits = UART_STOP_1BIT;
+    uartConfig.parity = UART_PARI_NO;
+    uartConfig.fifoByteEn = ENABLE; ///<must enable fifoByte when use DMA
+    uartConfig.dmaEn = UART_DMA_TXRX_EN;
+	
+		
+    uartConfig.callBack = UartRxIdleCallBack;   ///<uart2 interrupt callback
+    UART_Init(UARTx, &uartConfig);
+    UARTx->IDLE |= UART_IDLE_IDLEIE_Msk | UART_IDLE_ILEN_Msk;    ///<enable uart idle interrupt
+    
+    ///Enable UARTx interrupt
+    NVIC_SetPriority(UARTx_IRQn, 3);
+    NVIC_ClearPendingIRQ(UARTx_IRQn);
+    NVIC_EnableIRQ(UARTx_IRQn);
+		
+		TIMER_PrdInit();
+		
+    /* Initializing data in the txBuf */
+		
+    for (i = 0; i < 10; i++)
+    {
+        txBuf[i] = i + 1;
+    }
+		
+		RS485_TX_EN;
+		trans_finished = 1;
+    UART_TransmitDMA(UARTx, DMA0_CHANNEL0, txBuf, 10, UartTxDMAEventCallback); 
+    
+    UART_ReceiveDMA(UARTx, DMA0_CHANNEL1, rxBuf, UART_RECV_DATA_POOL_COUNT, UartRxDMAEventCallback); 
+
+		
+    while(1){
+				
+				if (g_scanKeyTime >= 1000)/*定时周期到,扫描按键动作.*/
+				{
+						g_scanKeyTime = 0;
+					  RUNLED_TOGGLE;
+				}
+				
+				if(trans_finished >= 120){
+						trans_finished = 0;
+						RS485_RX_EN;
+				}
+			
+			
+			/*
+			do{
+					if(GPIO_GetPinLevel(GPIOA, GPIO_PIN7)){
+							GPIO_SetPinLevel(GPIOA, GPIO_PIN7, GPIO_LEVEL_LOW);
+					}else{
+							GPIO_SetPinLevel(GPIOA, GPIO_PIN7, GPIO_LEVEL_HIGH);
+					
+					}
+			}while(0);
+			*/
+			
+			//RS485_TX_EN;
+			//UART_TransmitDMA(UARTx, DMA0_CHANNEL0, txBuf, 10, UartTxDMAEventCallback); 
+		}
+}

+ 597 - 0
User/Comm.c

@@ -0,0 +1,597 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+#include <string.h>
+#include "uart.h"
+#include "crc16.h"
+#include "cobs.h"
+#include "IAP.h"
+#include "Comm.h"
+//#include "can.h"
+///<cmd
+#define ControlCmd      (0x02)
+#define DataTransferCmd (0x40)
+#define DataTransferCmdHost (0x41)
+
+///<smd
+///<cmd=0x40
+#define DataTransferRequest (0x00)
+#define TransferData        (0x01)
+#define TransferExit        (0x02)
+
+///<cmd=0x02
+#define RequestReset        (0x00)
+
+/* cmd=0x40 smd=0x00 */
+/* Transfer type */
+#define IAP_BIN_FILE    (1)
+
+
+#define MaxBlockSize    (256 + 6)
+
+/* Result */
+#define ResultSuccess					(0)
+#define ResultBusy						(1)
+#define ResultExceedLimit			(2)
+#define ResultTotalLengthErr	(3)
+#define ResultCRCErr					(4)
+#define ResultSequenceErr			(5)
+#define ResultParamErr              (6)
+#define ResultExecErr               (7)
+
+
+#define SendBufferLength        (280)
+#define ReceiveBufferLength     (280)
+
+static int SendFrame(uint8_t *data, uint16_t length);
+static int GetFrame(uint8_t *data, uint16_t *length);
+
+fifo_TypeDef g_commRxFifo;
+static uint8_t s_commRxDataBuff[RxBufferLength];
+
+///<flash variable
+uint8_t s_flashType;
+uint32_t s_flashMemSize;
+uint32_t s_recvByte;
+uint8_t s_sequence; 
+
+static uint8_t s_sendBuffer[SendBufferLength];   ///<发送buff
+static uint8_t s_receiveBuffer[ReceiveBufferLength];    
+
+uint32_t s_writeBytes;
+uint8_t *s_startAddress;
+uint8_t s_writeSequence;
+uint32_t s_writeIndex;
+uint8_t s_writeData[SendBufferLength]; 
+void Start_IAPTest(void)
+{
+    uint16_t crc;
+    uint16_t index=0;
+    s_writeBytes = 0x800 * 12;      ///<写24K数据
+    s_writeSequence = 0;
+    s_writeIndex = 0;
+    s_startAddress = (uint8_t *)APP_ADDRESS;   ///<将自己的app程序发送给目标板
+    
+    printf("start IAP writebyte=%08x\r\n", s_writeBytes);
+    s_writeData[index++] = DataTransferCmd;
+    s_writeData[index++] = DataTransferRequest;
+    s_writeData[index++] = IAP_BIN_FILE;
+    
+    s_writeData[index++] = (uint8_t)((s_writeBytes >> 24) & 0xff);
+    s_writeData[index++] = (uint8_t)((s_writeBytes >> 16) & 0xff);
+    s_writeData[index++] = (uint8_t)((s_writeBytes >> 8) & 0xff);
+    s_writeData[index++] = (uint8_t)(s_writeBytes & 0xff);
+    
+    
+    crc = crc16(s_writeData, index);
+    s_writeData[index++] = (uint8_t)((crc>>8) & 0x00ff);
+    s_writeData[index++] = (uint8_t)(crc & 0x00ff); 
+    
+    SendFrame(s_writeData, index);
+}
+
+/**
+* DataTransferRequestHostHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机处理 数据传输请求反馈
+*/
+static void DataTransferRequestHostHandle(uint8_t *pdata, uint16_t length)
+{
+    uint8_t result;
+    uint16_t crc;
+    uint16_t index=0;
+    result = pdata[2];
+    if (result == ResultSuccess)
+    {
+        printf("data transfer request success\r\n");
+        s_writeData[index++] = DataTransferCmd;
+        s_writeData[index++] = TransferData;
+            
+        s_writeData[index++] = s_writeSequence;
+        
+        memcpy(&s_writeData[index], &s_startAddress[s_writeIndex], 256); 
+        index += 256;
+        s_writeIndex += 256;
+        s_writeSequence++; 
+        
+        crc = crc16(s_writeData, index);
+        s_writeData[index++] = (uint8_t)((crc>>8) & 0x00ff);
+        s_writeData[index++] = (uint8_t)(crc & 0x00ff); 
+        
+        SendFrame(s_writeData, index);
+    }
+    else
+    {
+        printf("TransferRequestFail result=%02x\r\n", result);
+    }
+}
+/**
+* TransferDataHostHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机处理 传输数据处理反馈
+*/
+static void TransferDataHostHandle(uint8_t *pdata, uint16_t length)
+{
+    uint8_t result;
+    uint16_t crc;
+    uint16_t index=0;
+    result = pdata[2];
+    if (result == ResultSuccess)
+    {
+        printf("transfer data success\r\n");
+        if (s_writeIndex < s_writeBytes)
+        {
+            s_writeData[index++] = DataTransferCmd;
+            s_writeData[index++] = TransferData;
+                
+            s_writeData[index++] = s_writeSequence;
+            
+            memcpy(&s_writeData[index], &s_startAddress[s_writeIndex], 256); 
+            index += 256;
+            s_writeIndex += 256;
+            s_writeSequence++;
+        }
+        else
+        {
+            s_writeData[index++] = DataTransferCmd;
+            s_writeData[index++] = TransferExit;
+            
+            crc = crc16(s_startAddress, s_writeBytes);
+            s_writeData[index++] = (uint8_t)((crc>>8) & 0x00ff);
+            s_writeData[index++] = (uint8_t)(crc & 0x00ff); 
+        }
+        crc = crc16(s_writeData, index);
+        s_writeData[index++] = (uint8_t)((crc>>8) & 0x00ff);
+        s_writeData[index++] = (uint8_t)(crc & 0x00ff); 
+        
+        SendFrame(s_writeData, index);
+    }
+    else
+    {
+        printf("TransferDataFail result=%02x\r\n", result);
+    }
+}
+/**
+* TransferExitHostHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机处理 传输数据结束反馈
+*/
+static void TransferExitHostHandle(uint8_t *pdata, uint16_t length)
+{
+    uint8_t result;
+    uint16_t crc;
+    uint16_t index=0;
+    result = pdata[2];
+    if (result == ResultSuccess)
+    {
+        printf("transfer exit success\r\n");
+        s_writeData[index++] = ControlCmd;
+        s_writeData[index++] = RequestReset;
+        
+        crc = crc16(s_writeData, index);
+        s_writeData[index++] = (uint8_t)((crc>>8) & 0x00ff);
+        s_writeData[index++] = (uint8_t)(crc & 0x00ff); 
+        
+        SendFrame(s_writeData, index);
+    }
+    else
+    {
+        printf("TransferExitFail result=%02x\r\n", result);
+    }
+}
+/**
+* DataTransferCmdHostHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机处理 数据传输命令反馈处理
+*/
+static void DataTransferCmdHostHandle(uint8_t *pdata, uint16_t length)
+{
+    uint8_t smd = pdata[1];
+    switch (smd)
+    {
+        case DataTransferRequest:
+            DataTransferRequestHostHandle(pdata, length);
+            break;
+        case TransferData:
+            TransferDataHostHandle(pdata, length);
+            break;
+        case TransferExit:
+            TransferExitHostHandle(pdata, length);
+            break;
+        default :break;
+    }
+}
+
+/**
+* DataTransferRequestHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机通信 数据传输请求
+*/
+static void DataTransferRequestHandle(uint8_t *pdata, uint16_t length)
+{
+    uint8_t data[15];
+    uint8_t index=0;
+    uint16_t crc;
+    s_flashType = pdata[2];
+    s_flashMemSize = pdata[3];
+    s_flashMemSize <<= 8;
+    s_flashMemSize += pdata[4];
+    s_flashMemSize <<= 8;
+    s_flashMemSize += pdata[5];
+    s_flashMemSize <<= 8;
+    s_flashMemSize += pdata[6];
+    s_sequence = 0;
+    s_recvByte = 0;
+    
+    data[index++] = pdata[0] + 1;
+    data[index++] = pdata[1];
+    if (s_flashType != IAP_BIN_FILE)    ///<目前只支持传输IAP bin 文件
+    {
+        data[index] = ResultParamErr;
+    }
+    else
+    {
+        if (s_flashMemSize > APP_SIZE)
+        {
+            data[index] = ResultExceedLimit;  ///<exceed limit 
+        }
+        else 
+        {
+            IAP_Start();
+            data[index] = ResultSuccess;
+        }
+    }
+    
+    index++;
+    data[index++] = (uint8_t)((MaxBlockSize >> 24) & 0xff);
+    data[index++] = (uint8_t)((MaxBlockSize >> 16) & 0xff);
+    data[index++] = (uint8_t)((MaxBlockSize >> 8) & 0xff);
+    data[index++] = (uint8_t)(MaxBlockSize & 0xff);
+    
+    crc = crc16(data, index);
+    data[index++] = (uint8_t)((crc>>8) & 0x00ff);
+    data[index++] = (uint8_t)(crc & 0x00ff); 
+    
+    SendFrame(data, index);
+}
+/**
+* TransferDataHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机通信 传输数据处理
+*/
+static void TransferDataHandle(uint8_t *pdata, uint16_t length)
+{
+    uint8_t data[10];
+    uint8_t index=0;
+    uint16_t crc;
+    
+    data[index++] = pdata[0] + 1;
+    data[index++] = pdata[1];
+    if (length > MaxBlockSize)
+    {
+        data[index] = ResultExceedLimit;    ///<长度超出限制
+        IAP_Stop();
+    }
+    else if (pdata[2] != s_sequence)
+    {
+        data[index] = ResultSequenceErr;    ///<序列号不正确
+        IAP_Stop();
+    }
+    else 
+    {
+        data[index] = ResultSuccess;    ///<succeed
+        if (0 != IAP_Write(&pdata[3], length - 5))
+        {
+            data[index] = ResultExecErr;    ///<执行错误
+            IAP_Stop();
+        }
+        s_recvByte += length - 5;
+        s_sequence++;
+    }
+    index++;
+    
+    crc = crc16(data, index);
+    data[index++] = (uint8_t)((crc>>8) & 0x00ff);
+    data[index++] = (uint8_t)(crc & 0x00ff); 
+    
+    SendFrame(data, index);
+}
+/**
+* TransferExitHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机通信 传输数据结束
+*/
+static void TransferExitHandle(uint8_t *pdata, uint16_t length)
+{
+    uint8_t data[10];
+    uint8_t index=0;
+    uint16_t crc;
+    uint16_t crcCheck;
+    
+    data[index++] = pdata[0] + 1;
+    data[index++] = pdata[1];
+    crc = ((uint16_t)pdata[2] << 8) | pdata[3]; 
+    
+    if (0 != IAP_Stop())
+    {
+        data[index] = ResultExecErr;    ///<执行错误
+    }
+    else
+    {
+        if (s_recvByte != s_flashMemSize)
+        {
+            data[index] = ResultTotalLengthErr;    ///<接收数据长度不正确
+        }
+        else
+        {
+            data[index] = ResultSuccess;
+            if (s_flashType == IAP_BIN_FILE)
+            {
+                crcCheck = crc16((const uint8_t *)APP_ADDRESS, s_recvByte);
+                if (crcCheck == crc)
+                {
+                    config->AppCrc = crc;  
+                    config->AppSize = s_flashMemSize;
+                    //if (0 != RefreshConfig())
+                    //{
+                    //   data[index] = ResultExecErr;
+                    //}
+                }
+                else
+                {
+                    data[index] = ResultCRCErr;    ///crc校验失败
+                }
+            }
+        }
+    }
+    
+    index++;
+    
+    crc = crc16(data, index);
+    data[index++] = (uint8_t)((crc>>8) & 0x00ff);
+    data[index++] = (uint8_t)(crc & 0x00ff); 
+    
+    SendFrame(data, index);
+}
+
+/**
+* RequestResetHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机通信 复位请求处理
+*/
+static void RequestResetHandle(uint8_t *pdata, uint16_t length)
+{
+    NVIC_SystemReset();
+}
+/**
+* ControlCmdHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机通信 控制命令处理
+*/
+static void ControlCmdHandle(uint8_t *pdata, uint16_t length)
+{
+    uint8_t smd = pdata[1];
+    switch (smd)
+    {
+        case RequestReset: //0x00
+            printf("Receive Reset Request\r\n");
+            RequestResetHandle(pdata, length);
+            break;
+        default :break;
+    }
+}
+/**
+* DataTransferCmdHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机通信 数据传输命令处理
+*/
+static void DataTransferCmdHandle(uint8_t *pdata, uint16_t length)
+{
+    uint8_t smd = pdata[1];
+    switch (smd)
+    {
+        case DataTransferRequest: //0x00
+            printf("Receive Data Transfer Request\r\n");
+            DataTransferRequestHandle(pdata, length);
+            break;
+        case TransferData: //0x01
+            printf("Receive Transfer Data\r\n");
+            TransferDataHandle(pdata, length);
+            break;
+        case TransferExit: //0x02
+            printf("Receive Transfer Exit\r\n");
+            TransferExitHandle(pdata, length);
+            break;
+        default :break;
+    }
+}
+ 
+/**
+* ComRxDataHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机通信 数据接收处理函数
+*/
+void ComRxDataHandle(void)
+{
+    uint16_t length = ReceiveBufferLength;
+    uint8_t cmd;
+    uint16_t crc;
+    if (0 == GetFrame(s_receiveBuffer, &length))
+    {
+        crc = ((uint16_t)s_receiveBuffer[length-2]<<8) | s_receiveBuffer[length-1]; 
+        if (crc != crc16(s_receiveBuffer, length-2))
+        {
+            ///<crc error
+            return;
+        }
+        cmd = s_receiveBuffer[0];
+        switch (cmd)
+        {
+            case ControlCmd:  //0x02
+                ControlCmdHandle(s_receiveBuffer, length);
+                break;
+            case DataTransferCmd:  //0x40
+                DataTransferCmdHandle(s_receiveBuffer, length);
+                break;
+            case DataTransferCmdHost: //0x41
+                DataTransferCmdHostHandle(s_receiveBuffer, length);
+                break;
+                
+            default :break;
+        }
+    }
+    
+}
+
+void Comm_Init(void)
+{
+    
+    fifo_Init(&g_commRxFifo, s_commRxDataBuff, RxBufferLength);
+    uart_Initialize();
+    //CAN_Initialize();
+}
+
+static int SendFrame(uint8_t *data, uint16_t length)
+{
+    cobs_encode_result result; 
+    if (length != 0)
+    {
+        result = cobs_encode(s_sendBuffer, SendBufferLength, data, length);
+        if (result.status == COBS_ENCODE_OK)
+        {
+            //Add delimitor
+            *(s_sendBuffer+result.out_len) = 0;
+            result.out_len++;
+            uart0_TransmitData(s_sendBuffer, result.out_len);
+            //CAN_Transmit(s_sendBuffer, result.out_len);
+        }
+    }
+    return 0;
+}
+static int GetFrame(uint8_t *data, uint16_t *length) 
+{
+    uint16_t frameLength;
+    cobs_decode_result result;
+    frameLength = Fifo_strchr(&g_commRxFifo, 0); 
+    
+    if (frameLength != 0) 
+    {
+        if (*length < frameLength)
+        {   ///<帧长超过了buff的长度,复位fifo
+            fifo_Reset(&g_commRxFifo); 
+            return -1;  
+        }
+        fifo_retrieve(&g_commRxFifo, data, frameLength);
+        result = cobs_decode(data, *length, data, frameLength-1);
+        if (result.status == COBS_DECODE_OK)
+        {
+            *length = result.out_len;
+            return 0;
+        }
+    }
+    return -1;
+}

+ 58 - 0
User/Comm.h

@@ -0,0 +1,58 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+
+#ifndef COMM_H
+#define COMM_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "fifo.h"
+    
+#define RxBufferLength      (512)   
+///<接收直接判断fifo是否有数据,不另外封装函数
+extern fifo_TypeDef g_commRxFifo;
+    
+extern void Start_IAPTest(void);    
+    
+extern void ComRxDataHandle(void); 
+
+extern void Comm_Init(void);    
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* COMM_H */
+
+

+ 112 - 0
User/IAP.c

@@ -0,0 +1,112 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+#include <string.h>
+#include "IAP.h" 
+
+
+static __align(4)uint8_t WriteDataBuff[2048];
+
+static uint32_t s_writeAddress;
+
+static uint8_t s_iapStep;
+
+static uint32_t s_writeDataBuffSeek;
+
+
+void IAP_Start(void)
+{
+    if (s_iapStep == 1)
+    {
+        return;     ///<repeat start
+    }
+    s_writeAddress = APP_ADDRESS;
+    s_iapStep = 1;
+}
+int IAP_Write(uint8_t *pdata, uint16_t length)
+{
+    EFLASH_StatusType ret = EFLASH_STATUS_SUCCESS;
+    uint16_t MiniLength = 0;
+    if (s_iapStep != 1)     ///<防止用户不先调用start就开始写
+        return -1;
+    while (length > 0)
+    {
+        if ((s_writeAddress < APP_ADDRESS) || (s_writeAddress >= APP_ADDRESS_END))  ///<IAP不能超出APP_BKP地址范围
+            return -1;
+        if (s_writeDataBuffSeek + length > 2048)    ///得到单次写入的长度
+        {
+            MiniLength = 2048 - s_writeDataBuffSeek;    ///<长度超出buff
+        }
+        else
+        {
+            MiniLength = length;    ///<全部写完,
+        }
+        memcpy(&WriteDataBuff[s_writeDataBuffSeek], pdata, MiniLength);
+        pdata += MiniLength;
+        s_writeDataBuffSeek += MiniLength;
+        length -= MiniLength;
+        if (s_writeDataBuffSeek == 2048)
+        {
+            EFLASH_UnlockCtrl();
+            ret = EFLASH_PageErase(s_writeAddress);     ///<erase page
+            if (ret != EFLASH_STATUS_SUCCESS) return -1;
+            ret = EFLASH_PageEraseVerify(s_writeAddress);   ///< verify erase state
+            if (ret != EFLASH_STATUS_SUCCESS) return -1;
+            ret = EFLASH_PageProgram(s_writeAddress, (uint32_t *)WriteDataBuff, 512); 
+            if (ret != EFLASH_STATUS_SUCCESS) return -1;
+            EFLASH_LockCtrl();
+            s_writeAddress += 2048;
+            s_writeDataBuffSeek = 0;
+        }
+    }
+    return 0;
+}
+
+int IAP_Stop(void)
+{
+    EFLASH_StatusType ret = EFLASH_STATUS_SUCCESS;
+    s_iapStep = 0;  ///<stop后重置step
+    if ((s_writeAddress < APP_ADDRESS) || (s_writeAddress >= APP_ADDRESS_END))  ///<IAP不能超出APP_BKP地址范围
+        return -1;
+    EFLASH_UnlockCtrl();
+    ret = EFLASH_PageErase(s_writeAddress);     ///<erase page
+    if (ret != EFLASH_STATUS_SUCCESS) return -1;
+    ret = EFLASH_PageEraseVerify(s_writeAddress);   ///< verify erase state
+    if (ret != EFLASH_STATUS_SUCCESS) return -1;
+    ret = EFLASH_PageProgram(s_writeAddress, (uint32_t *)WriteDataBuff, 512);   ///<此处应该不满2048,但还是全部写入,后面为多余字节
+    if (ret != EFLASH_STATUS_SUCCESS) return -1;
+    EFLASH_LockCtrl();
+    return 0;
+}
+
+

+ 56 - 0
User/IAP.h

@@ -0,0 +1,56 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+
+#ifndef IAP_H
+#define IAP_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "ac780x.h"
+#include "cfg.h"
+#include "ac780x_eflash.h"
+  
+//extern Config_type *config;    
+    
+//extern int IAP_Init(void);
+extern void IAP_Start(void);
+extern int IAP_Write(uint8_t *pdata, uint16_t length);
+extern int IAP_Stop(void);
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* IAP_H */
+

+ 67 - 0
User/IAP_cfg.h

@@ -0,0 +1,67 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+
+#ifndef IAP_CFG_H
+#define IAP_CFG_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "ac780x.h"
+
+#define IAP_BOOTLOAD_ADDRESS    0x8000000    /* define bootload start address */
+#define CONFIG_ADDRESS      0x08004800  /* 预留一个页用于存放配置信息 */
+#define APP_ADDRESS    0x8005000    /* define app start address */   
+    
+#define EFLASH_PAGE_SIZE_INIT 2048  /* define one-page size */
+#define EFLASH_PAGE_NUM_INIT  54    /* define APP page num, size=2048*54=108K */
+    
+#define APP_SIZE        (EFLASH_PAGE_SIZE_INIT * EFLASH_PAGE_NUM_INIT)
+#define APP_ADDRESS_END     ((uint32_t)(APP_ADDRESS + APP_SIZE))   
+    
+
+#define Flag0Value   0xaa
+#define flag1Value   0x55    
+typedef struct 
+{
+    uint8_t flag0;
+    uint8_t flag1;
+    uint32_t AppSize;
+    uint32_t AppCrc;
+}Config_type;
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* IAP_CFG_H */

+ 62 - 0
User/cfg.c

@@ -0,0 +1,62 @@
+#include "cfg.h"
+#include "uart.h"
+#include "ac780x_eflash.h"
+#include <string.h>
+
+static uint32_t reflectionBuff[(sizeof(Config_type)>>2)+1];
+
+Config_type *config = (Config_type *)reflectionBuff;
+
+static void Factory_reset(void)
+{
+		config->magic = CONFIG_MAGIC;
+		config->addr = DEFAULT_ADDR;
+		config->br_index = BaudRate_9600;
+	
+		config->AppSize = 0;
+		config->AppCrc = 0;
+
+}
+
+int Config_Init(void)
+{
+    //EFLASH_StatusType ret = EFLASH_STATUS_SUCCESS;
+    memcpy(reflectionBuff, (void *)CONFIG_ADDRESS, sizeof(Config_type));
+    if (config->magic != CONFIG_MAGIC)
+    {/* initiliaze config */
+        memset(reflectionBuff, 0, sizeof(Config_type)); 
+        //config->magic = CONFIG_MAGIC;
+			
+			
+				Factory_reset();
+        SaveConfig();
+			
+    }
+		
+		//Factory_reset();
+    return 0;
+}
+
+int SaveConfig(void)
+{
+    EFLASH_StatusType ret = EFLASH_STATUS_SUCCESS;
+    
+    EFLASH_UnlockCtrl();
+    ret = EFLASH_PageErase(CONFIG_ADDRESS);     ///<erase page
+    if (ret != EFLASH_STATUS_SUCCESS) return -1;
+    ret = EFLASH_PageEraseVerify(CONFIG_ADDRESS);   ///< verify erase state
+    if (ret != EFLASH_STATUS_SUCCESS) return -1;
+    ret = EFLASH_PageProgram(CONFIG_ADDRESS, (uint32_t *)reflectionBuff, (sizeof(Config_type)>>2)+1);   ///< 
+    if (ret != EFLASH_STATUS_SUCCESS) return -1;
+    EFLASH_LockCtrl();
+    return 0;
+}
+
+int ResetConfig(void)
+{
+    Factory_reset();
+    //SaveConfig();
+	
+    return 0;
+}
+

+ 84 - 0
User/cfg.h

@@ -0,0 +1,84 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+
+#ifndef CFG_H
+#define CFG_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "ac780x.h"
+
+#define IAP_BOOTLOAD_ADDRESS    0x8000000    /* define bootload start address */
+#define CONFIG_ADDRESS      		0x08007800  /* 预留一个页用于存放配置信息 */
+#define APP_ADDRESS    					0x8008000    /* define app start address */   
+#define APP_ADDRESS_TEMP    		0x8014000    /* start address for ota package */   
+    
+#define EFLASH_PAGE_SIZE_INIT 2048  /* define one-page size */
+#define EFLASH_PAGE_NUM_INIT  54    /* define APP page num, size=2048*54=108K */
+    
+#define APP_SIZE        (EFLASH_PAGE_SIZE_INIT * EFLASH_PAGE_NUM_INIT)
+#define APP_ADDRESS_END     ((uint32_t)(APP_ADDRESS + APP_SIZE))   
+  
+
+#define CONFIG_MAGIC   0xaa55
+
+#define DEFAULT_ADDR     0x20
+#define BROADCAST_ADDR   0xFF
+/*
+* sizeof(Config_type) 不能超出2KB 
+*/
+typedef struct 
+{
+		uint16_t magic;
+    uint8_t  addr;
+    uint8_t  br_index;
+		uint16_t hw_version;
+		uint16_t devicetype;
+	  uint32_t deviceid;
+	
+    uint32_t AppSize;
+    uint32_t AppCrc;
+}Config_type;
+
+extern Config_type *config;
+
+extern int Config_Init(void);
+extern int SaveConfig(void);
+extern int ResetConfig(void);
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CFG_H */

+ 32 - 0
User/main.c

@@ -0,0 +1,32 @@
+#include "ac780x.h"
+#include "timer.h"
+#include "gpio.h"
+#include "cfg.h"
+#include "process.h"
+#include "main_task.h"
+
+/*!
+* @brief entry 
+*
+* @param[in] none
+* @return none
+*/
+int main(void)
+{
+		InitDelay();
+		Config_Init();
+	
+    GPIO_PortInit();
+	
+		Process_Init();
+	
+		TIMER_PrdInit();
+    Task_Init();
+	
+	
+    while (1)
+    {
+        Task_Handle();
+    }
+		
+}

+ 233 - 0
User/main_task.c

@@ -0,0 +1,233 @@
+#include "main_task.h"
+#include "uart.h"
+#include "gpio.h"
+#include "cfg.h"
+#include "protocol.h"
+#include "process.h"
+#include "crc16.h"
+#include <string.h>
+
+
+/**
+* Uart0_RxDataHandle
+*                  
+* @return    none
+*
+* @brief  主任务处理函数
+*/
+void Uart0_RxDataHandle(void)
+{
+		uint8_t* rxbuf = uart0_info.recv_buffer;
+		uint16_t rx_len = uart0_info.recv_len;
+		uint8_t* txbuf = uart0_info.send_buffer;
+		uint16_t txbuf_size = UART0_TRANSMIT_DATA_POOL_COUNT;
+		uint16_t tx_len = 0;
+		uint16_t cmd;
+		uint16_t crc;
+		uint16_t ret_len = 0;
+		uint8_t ret_write = RET_OK;
+	
+		if(rx_len > 2){
+
+	
+			//check rs485 addr 
+			if(config->addr == rxbuf[0] || BROADCAST_ADDR == rxbuf[0]){
+				
+#if 1						
+					// check crc
+					crc = ((uint16_t)rxbuf[rx_len-2]<<8) | rxbuf[rx_len-1]; 
+					if (crc == crc16(rxbuf, rx_len-2))
+					{
+							//copy 地址、功能码、命令、到发送buf 
+							memcpy(txbuf, (void *)rxbuf, 4);
+							tx_len +=4;
+							
+							if(MODBUS_FUNC_READ == rxbuf[1]){
+									cmd = ((uint16_t)rxbuf[2]<<8) | rxbuf[3]; 
+									switch(cmd){
+										case Cmd_FirmwareVersion:
+											ret_len = Read_FirmwareVersion(txbuf+tx_len, txbuf_size-tx_len);
+											break;
+										case Cmd_HardwareVersion:
+											ret_len = Read_HardwareVersion(txbuf+tx_len, txbuf_size-tx_len);
+											break;
+										case Cmd_DeviceID:
+											ret_len = Read_Deviceid(txbuf+tx_len, txbuf_size-tx_len);
+											break;
+										case Cmd_DeviceType:
+											ret_len = Read_Devicetype(txbuf+tx_len, txbuf_size-tx_len);
+											break;
+										case Cmd_Addr:
+											ret_len = Read_Addr(txbuf+tx_len, txbuf_size-tx_len);
+											break;
+										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);
+											break;
+										default:
+											txbuf[1] |= 0x80;
+											txbuf[tx_len] = INVALID_COMMAND;
+											ret_len = 1;
+											break;
+									};
+									
+									if(0 == ret_len){
+											// error occur 
+											txbuf[1] |= 0x80;
+											txbuf[tx_len] = DEVICE_FAULT;
+											ret_len = 1;
+									}
+									
+									tx_len += ret_len;
+									crc = crc16(txbuf, tx_len);
+									txbuf[tx_len++] = (uint8_t)((crc>>8) & 0x00ff);
+									txbuf[tx_len++] = (uint8_t)(crc & 0x00ff); 
+									
+									uart0_TransmitData(txbuf, tx_len);
+
+							
+							}else if(MODBUS_FUNC_WRITE == rxbuf[1]){
+								
+									ret_write = RET_OK;
+									cmd = ((uint16_t)rxbuf[2]<<8) | rxbuf[3]; 
+									switch(cmd){
+										case Cmd_HardwareVersion:
+											ret_write = Write_HardwareVersion(rxbuf+4, rx_len-4-2); 
+
+											break;
+										case Cmd_DeviceID:
+											ret_write = Write_Deviceid(rxbuf+4, rx_len-4-2); 
+
+											break;
+										case Cmd_DeviceType:
+											ret_write = Write_Devicetype(rxbuf+4, rx_len-4-2); 
+
+											break;
+										case Cmd_Addr:
+											ret_write = Write_Addr(rxbuf+4, rx_len-4-2); 
+											break;
+										case Cmd_Baudrate:
+											ret_write = Write_Baudrate(rxbuf+4, rx_len-4-2); 
+											break;
+										case Cmd_Reboot:
+											//NVIC_SystemReset();
+											ret_write = RET_NEED_REBOOT;
+											break;
+										case Cmd_Reset:
+											ResetConfig();
+											ret_write = RET_NEED_SAVE|RET_NEED_REBOOT;
+											//NVIC_SystemReset();
+											break;
+										default:
+											ret_write = RET_CMDINVALID;
+											break;
+									};
+									
+									if((ret_write&RET_ERROR_MASK) > 0){
+										
+											if((ret_write&RET_DATAINVALID) > 0){
+												txbuf[1] |= 0x80;
+												txbuf[tx_len++] = INVALID_DATA;
+
+											}else if((ret_write&RET_CMDINVALID) > 0){
+												txbuf[1] |= 0x80;
+												txbuf[tx_len++] = INVALID_COMMAND;
+											}
+									
+									}else{ 
+											//copy the whole rx frame
+											memcpy(txbuf, (void *)rxbuf, rx_len-2);
+											tx_len =rx_len-2;
+									}
+									
+									crc = crc16(txbuf, tx_len);
+									txbuf[tx_len++] = (uint8_t)((crc>>8) & 0x00ff);
+									txbuf[tx_len++] = (uint8_t)(crc & 0x00ff); 
+									
+									uart0_TransmitData(txbuf, tx_len);
+									
+									if((ret_write&RET_NEED_SAVE) > 0 ){
+											SaveConfig();
+									}
+									
+									if((ret_write&RET_NEED_REBOOT) > 0 ){
+											NVIC_SystemReset();
+									}
+	
+									
+							}else{
+								
+								//function code no exist
+								txbuf[1] |= 0x80;
+								txbuf[tx_len++] = INVALID_FUNCTION_CODE;
+								
+								crc = crc16(txbuf, tx_len);
+								txbuf[tx_len++] = (uint8_t)((crc>>8) & 0x00ff);
+								txbuf[tx_len++] = (uint8_t)(crc & 0x00ff); 
+								
+								uart0_TransmitData(txbuf, tx_len);
+
+							}
+							
+					}
+		#else
+		memcpy(txbuf, (void *)rxbuf, rx_len);
+		tx_len +=rx_len;
+		
+		uart0_TransmitData(txbuf, tx_len);
+			
+#endif 			
+				
+			}
+		
+		} //END rx_len 
+		
+		if(rx_len > 0){
+			uart0_RecvData();
+		}
+		
+		
+		
+		//处理 485 收发状态 
+		if(uart0_info.dmasend_count >= UART_DMASEND_COUNT_RESET){
+				uart0_info.dmasend_count = 0;
+				RS485_RX_EN;
+		}
+
+
+}
+
+
+/**
+* Task_Init
+*                  
+* @return    none
+*
+* @brief  初始化
+*/
+
+void Task_Init(void)
+{ 
+    uart_Initialize();
+}
+
+
+/**
+* Task_Handle
+*                  
+* @return    none
+*
+* @brief  主任务处理函数
+*/
+void Task_Handle(void)
+{
+	
+		Process_RunLedPrd();
+		Process_ThreeStatus();
+		Uart0_RxDataHandle();
+
+}
+
+

+ 52 - 0
User/main_task.h

@@ -0,0 +1,52 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+
+#ifndef MAIN_TASK_H
+#define MAIN_TASK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void Task_Handle(void); 
+
+extern void Task_Init(void);    
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MAIN_TASK_H */
+
+

+ 116 - 0
User/process.c

@@ -0,0 +1,116 @@
+#include "process.h"
+#include "gpio.h"
+#include "ac780x_gpio.h"
+
+uint16_t	g_blinkLedTime;		/*LED闪烁频率控制时间*/
+uint16_t	g_blinkLedTgtTime;	/*LED目标闪烁频率*/
+uint8_t		g_detectTime;			/*三个开关状态,检测时间*/
+
+#define STATUS_DETECTINTERVAL  (60)  /*60ms * 8 == 500ms  */
+
+uint8_t g_lockstatus;
+uint8_t g_unlockstatus;
+uint8_t g_coverstatus;
+
+uint8_t lockbits;
+uint8_t unlockbits;
+uint8_t coverbits;
+
+void Process_Init(void)
+{
+		/*初始化控制变量.*/
+		g_blinkLedTime 	  = 0;
+		g_blinkLedTgtTime = BLINK_LED_DFTT;
+	
+		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;
+	
+		lockbits = g_lockstatus == STATUS_OPEN?0xFF:0x00;
+		unlockbits = g_unlockstatus == STATUS_OPEN?0xFF:0x00;
+		coverbits = g_coverstatus == STATUS_OPEN?0xFF:0x00;
+	
+		/*上电默认LED点亮.*/
+		RUNLED_ON;
+}
+
+void Process_RunLedPrd(void)
+{
+	/*周期性地检查LED闪烁,LED2和LED3同时闪烁.*/
+	if (g_blinkLedTime >= g_blinkLedTgtTime)
+	{
+		g_blinkLedTime = 0;
+		
+		RUNLED_TOGGLE;
+	}
+	
+}
+
+
+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{
+			lockbits=(lockbits<<1)|0x00;
+		}
+		
+		if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_OPEN_KEY)){
+			unlockbits=(unlockbits<<1)|0x01;
+		}else{
+			unlockbits=(unlockbits<<1)|0x00;
+		}
+		
+		if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_COVER_KEY)){
+			coverbits=(coverbits<<1)|0x01;
+		}else{
+			coverbits=(coverbits<<1)|0x00;
+		}
+		
+		if(g_lockstatus == STATUS_CLOSE && lockbits == 0xFF){
+				g_lockstatus = STATUS_OPEN;
+		}else if(g_lockstatus == STATUS_OPEN && lockbits == 0x00){
+				g_lockstatus = STATUS_CLOSE;
+		}
+		
+		if(g_unlockstatus == STATUS_CLOSE && unlockbits == 0xFF){
+				g_unlockstatus = STATUS_OPEN;
+		}else if(g_unlockstatus == STATUS_OPEN && unlockbits == 0x00){
+				g_unlockstatus = STATUS_CLOSE;
+		}
+		
+		if(g_coverstatus == STATUS_CLOSE && coverbits == 0xFF){
+				g_coverstatus = STATUS_OPEN;
+		}else if(g_coverstatus == STATUS_OPEN && coverbits == 0x00){
+				g_coverstatus = STATUS_CLOSE;
+		}
+		
+	
+	}
+	
+
+}
+
+
+
+uint8_t Process_LockStatus(void)
+{
+	return g_lockstatus;
+}
+
+uint8_t Process_UnlockStatus(void)
+{
+	return g_unlockstatus;
+}
+
+uint8_t Process_CoverStatus(void)
+{
+	return g_coverstatus;
+}
+

+ 73 - 0
User/process.h

@@ -0,0 +1,73 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+
+#ifndef PROCESS_H
+#define PROCESS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*************<include>****************/
+#include "ac780x_gpio.h"
+
+/*************<extern>*****************/	
+extern uint16_t		g_blinkLedTime;		/*LED闪烁频率控制时间*/
+extern uint16_t		g_blinkLedTgtTime;	/*LED目标闪烁频率*/
+extern uint8_t		g_detectTime;	
+
+#define BLINK_LED_MINT		(100)	/*闪烁LED灯最小时间间隔*/
+#define BLINK_LED_MAXT		(2000)	/*闪烁LED灯最大时间间隔*/
+#define BLINK_LED_DFTT		(1000)	/*闪烁LED默认时间间隔*/
+
+#define STATUS_OPEN  (0x01)
+#define STATUS_CLOSE (0x00)
+
+
+void Process_Init(void);
+void Process_RunLedPrd(void); 
+
+void Process_ThreeStatus(void); 
+
+uint8_t Process_LockStatus(void); 
+uint8_t Process_UnlockStatus(void); 
+uint8_t Process_CoverStatus(void); 
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PROCESS_H */
+
+

+ 182 - 0
User/protocol.c

@@ -0,0 +1,182 @@
+#include "protocol.h"
+#include "process.h"
+#include "cfg.h"
+#include "uart.h"
+
+uint32_t Firmware_Version[8] = {1, 1, 0, 0, 0, 0, 0, 20231214};
+
+uint16_t Read_FirmwareVersion(uint8_t *pBuf, uint16_t buf_len)
+{
+	int i;
+	
+	if( buf_len < 32){
+		return 0;
+	}
+	
+	for (i = 0; i < 8; ++i)
+	{
+		pBuf[i * 4] = (Firmware_Version[i] >> 24) & 0xff;
+		pBuf[i * 4 + 1] = (Firmware_Version[i] >> 16) & 0xff;
+		pBuf[i * 4 + 2] = (Firmware_Version[i] >> 8) & 0xff;
+		pBuf[i * 4 + 3] = (Firmware_Version[i] >> 0) & 0xff;
+	}
+	
+	return 32;
+	
+}
+
+uint16_t Read_HardwareVersion(uint8_t *pBuf, uint16_t buf_len)
+{
+
+	if( buf_len < 2){
+		return 0;
+	}
+	
+	pBuf[0] = (config->hw_version >> 8)&0xff;
+	pBuf[1] = (config->hw_version >> 0)&0xff;
+	
+	return 2;
+}
+
+
+uint16_t Read_Deviceid(uint8_t *pBuf, uint16_t buf_len)
+{
+
+	if( buf_len < 4){
+		return 0;
+	}
+	
+	pBuf[0] = (config->deviceid >> 24)&0xff;
+	pBuf[1] = (config->deviceid >> 16)&0xff;
+	pBuf[2] = (config->deviceid >> 8)&0xff;
+	pBuf[3] = (config->deviceid >> 0)&0xff;
+	
+	return 4;
+	
+}
+
+uint16_t Read_Devicetype(uint8_t *pBuf, uint16_t buf_len)
+{
+
+	if( buf_len < 2){
+		return 0;
+	}
+	
+	pBuf[0] = (config->devicetype >> 8)&0xff;
+	pBuf[1] = (config->devicetype >> 0)&0xff;
+	
+	return 2;
+
+}
+
+uint16_t Read_Addr(uint8_t *pBuf, uint16_t buf_len)
+{
+	if( buf_len < 2){
+		return 0;
+	}
+	
+	pBuf[0] = 0x00;
+	pBuf[1] = config->addr;
+	
+	return 2;
+}
+
+uint16_t Read_Baudrate(uint8_t *pBuf, uint16_t buf_len)
+{
+	if( buf_len < 2){
+		return 0;
+	}
+	
+	pBuf[0] = 0x00;
+	pBuf[1] = config->br_index;
+	
+	return 2;
+
+}
+
+
+uint16_t Read_LockStatus(uint8_t *pBuf, uint16_t buf_len)
+{
+
+	if( buf_len < 3){
+		return 0;
+	}
+	
+	pBuf[0] = Process_LockStatus();
+	pBuf[1] = Process_UnlockStatus();
+	pBuf[2] = Process_CoverStatus();
+	
+	return 3;
+}
+
+
+/*=======================================================================================*/
+
+uint8_t Write_Addr(uint8_t *pdata, uint8_t len)
+{
+	if(len == 2){
+		config->addr = pdata[1]; 
+		return RET_OK|RET_NEED_SAVE;
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+}
+
+uint8_t Write_Baudrate(uint8_t *pdata, uint8_t len)
+{
+	if(len == 2){
+		if(pdata[1] >= BaudRate_4800 && pdata[1] <= BaudRate_230400){
+			config->br_index = pdata[1]; 
+			return RET_OK|RET_NEED_SAVE;
+		
+		}else{
+			return RET_DATAINVALID;
+		}
+		
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+
+}
+
+uint8_t Write_HardwareVersion(uint8_t *pdata, uint8_t len)
+{
+	if(len == 2){
+		
+		config->hw_version = ((uint16_t)pdata[0]<<8) | pdata[1]; 
+		return RET_OK|RET_NEED_SAVE;
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+	
+
+}
+uint8_t Write_Deviceid(uint8_t *pdata, uint8_t len)
+{
+	if(len == 4){
+		config->deviceid = ((uint32_t)pdata[0]<<24) | ((uint32_t)pdata[1]<<16)| ((uint32_t)pdata[2]<<8)| pdata[3]; 
+		return RET_OK|RET_NEED_SAVE;
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+
+}
+uint8_t Write_Devicetype(uint8_t *pdata, uint8_t len)
+{
+
+	if(len == 2){
+		
+		config->devicetype = ((uint16_t)pdata[0]<<8) | pdata[1]; 
+		return RET_OK|RET_NEED_SAVE;
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+}
+
+
+

+ 103 - 0
User/protocol.h

@@ -0,0 +1,103 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+
+#ifndef PROTOCOL_H
+#define PROTOCOL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "ac780x.h"
+
+#define Cmd_FirmwareVersion    (0x0000)
+#define Cmd_HardwareVersion    (0x0001)
+#define Cmd_DeviceID    			 (0x0002)
+#define Cmd_DeviceType    		 (0x0003)
+#define Cmd_Reboot		 		     (0x0004)
+#define Cmd_Reset    					 (0x0005)
+
+#define Cmd_Addr    					 (0x0010)
+#define Cmd_Baudrate    			 (0x0011)
+#define Cmd_LockStatus    		 (0x0020)
+//#define Cmd_FirmwareVersion    (0x0000)
+
+#define MODBUS_FUNC_READ				(0x03)
+#define MODBUS_FUNC_WRITE				(0x06)
+
+#define INVALID_FUNCTION_CODE   (0x01)
+#define INVALID_COMMAND			    (0x02)
+#define INVALID_DATA   					(0x03)
+#define DEVICE_FAULT   					(0x04)
+
+
+
+//读取时返回,数据长度, 如果返回 0, 说明buf_len 不够, 设备故障
+
+uint16_t Read_FirmwareVersion(uint8_t *pBuf, uint16_t buf_len); 
+uint16_t Read_HardwareVersion(uint8_t *pBuf, uint16_t buf_len); 
+uint16_t Read_Deviceid(uint8_t *pBuf, uint16_t buf_len); 
+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);
+
+
+
+#define RET_ERROR_MASK     (0xF0)
+#define RET_OK  		 			(0x00)
+#define RET_NEED_SAVE			(0X01)
+#define RET_NEED_REBOOT		(0X02)
+
+#define RET_DATAINVALID  	(0x10)
+#define RET_CMDINVALID  	(0x20)
+//#define RET_DATAINVALID  	(3)
+
+//写入成功时返回 RET_OK
+//写入不成功时,返回 RET_DATAINVALID
+uint8_t Write_Addr(uint8_t *pdata, uint8_t len); 
+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); 
+  
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PROTOCOL_H */
+
+