瀏覽代碼

第一次提交代码

guoqiang 1 年之前
當前提交
705ff96c6c
共有 54 個文件被更改,包括 45107 次插入0 次删除
  1. 1 0
      .gitignore
  2. 191 0
      Device/adxl312.c
  3. 85 0
      Device/adxl312.h
  4. 67 0
      Device/flash.c
  5. 54 0
      Device/flash.h
  6. 126 0
      Device/gpio.c
  7. 139 0
      Device/gpio.h
  8. 97 0
      Device/timer.c
  9. 71 0
      Device/timer.h
  10. 385 0
      Device/uart.c
  11. 85 0
      Device/uart.h
  12. 77 0
      Device/wdg.c
  13. 53 0
      Device/wdg.h
  14. 81 0
      Lib/crc16.c
  15. 7 0
      Lib/crc16.h
  16. 370 0
      Lib/md5c.c
  17. 27 0
      Lib/md5c.h
  18. 3734 0
      Project/BVACS.uvguix.孙凯
  19. 606 0
      Project/BVACS.uvoptx
  20. 718 0
      Project/BVACS.uvprojx
  21. 9 0
      Project/EventRecorderStub.scvd
  22. 1686 0
      Project/JLinkLog.txt
  23. 40 0
      Project/JLinkSettings.ini
  24. 4545 0
      Project/Listings/BVACS.map
  25. 4725 0
      Project/Listings/BVACS_20240112.map
  26. 4892 0
      Project/Listings/BVACS_20240115.map
  27. 4892 0
      Project/Listings/BVACS_20240123.map
  28. 4896 0
      Project/Listings/BVACS_20240124.map
  29. 4923 0
      Project/Listings/BVACS_20240125.map
  30. 1906 0
      Project/Listings/startup_ac7840x.lst
  31. 250 0
      Project/RTE/Board_Support/AC78406HGLA/debugout_ac7840x.c
  32. 1001 0
      Project/RTE/Device/AC78406HGLA/ac7840x_features.h
  33. 81 0
      Project/RTE/Device/AC78406HGLA/device_assert.h
  34. 58 0
      Project/RTE/Device/AC78406HGLA/device_register.h
  35. 120 0
      Project/RTE/Device/AC78406HGLA/device_status.h
  36. 475 0
      Project/RTE/Device/AC78406HGLA/startup_ac7840x.s
  37. 563 0
      Project/RTE/Device/AC78406HGLA/system_ac7840x.c
  38. 157 0
      Project/RTE/Device/AC78406HGLA/system_ac7840x.h
  39. 45 0
      Project/RTE/_Target_1/RTE_Components.h
  40. 45 0
      Project/RTE/_bvacs/RTE_Components.h
  41. 2 0
      README.md
  42. 575 0
      User/IAP.c
  43. 89 0
      User/IAP.h
  44. 73 0
      User/cfg.c
  45. 103 0
      User/cfg.h
  46. 287 0
      User/clock_config.c
  47. 91 0
      User/clock_config.h
  48. 149 0
      User/main.c
  49. 268 0
      User/main_task.c
  50. 52 0
      User/main_task.h
  51. 614 0
      User/process.c
  52. 142 0
      User/process.h
  53. 258 0
      User/protocol.c
  54. 121 0
      User/protocol.h

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+Project/Objects/

+ 191 - 0
Device/adxl312.c

@@ -0,0 +1,191 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+/*!
+* @file ADXL312.c
+*
+* @brief This file contains the user function.
+*
+*/
+
+/* ===========================================  Includes  =========================================== */
+#include "adxl312.h"
+#include "spi_hw.h"
+#include "spi_master_drv.h"
+#include "spi_slave_drv.h"
+#include "port_hw.h"
+#include "gpio_hw.h"
+#include "gpio.h"
+#include "debugout_ac7840x.h"
+#include "osif.h"
+
+/* ==========================================  Variables  =========================================== */
+/*! @brief SPI master configure parameter */
+spi_master_config_t spiMasteConfig2 =
+{
+    .bitsPerSec = 100000UL,                    /*! 设置SPI波特率*/
+    .whichPcs = SPI_PCS0,                       /*! 设置SPI片选引脚*/
+    .pcsPolarity = SPI_ACTIVE_LOW,              /*! 设置SPI片选低有效*/
+    .isPcsContinuous = true,                    /*! 设置片选连续模式*/
+    .bitcount = 8UL,                            /*! SPI 帧长度,支持 4~32 bits*/
+    .spiSrcClk = 2000000UL,                    /*! SPI时钟源频率*/
+    .clkPhase = SPI_CLOCK_PHASE_2ND_EDGE,       /*! 设置数据采样相位,第1个边沿采样数据*/
+    .clkPolarity = SPI_SCK_ACTIVE_LOW,         /*! 设置SCK工作时极性,工作时SCK为高*/
+    .msbFirst = true,                           /*! 选择从最高位开始收发*/
+    .transferType = SPI_USING_INTERRUPTS,       /*! 选择通信类型为中断方式*/
+    .rxDMAChannel = 1UL,                        /*! 设置SPI DMA接收通道,若未使用DMA方式传输,则该配置可忽略*/
+    .txDMAChannel = 0UL,                        /*! 设置SPI DMA发送通道,若未使用DMA方式传输,则该配置可忽略*/
+    .callback = NULL,                           /*! 注册回调函数 */
+    .callbackParam = NULL,                      /*! 回调函数参数 */
+};
+
+static spi_state_t s_spiMasterState2;
+/*! SPI发送和接收数组*/
+uint8_t g_adxTxBuff[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+uint8_t g_adxRxBuff[8] = {0};
+
+/* ====================================  Functions declaration  ===================================== */
+void WriteCmd(uint8_t cmd, uint8_t data)
+{
+		g_adxTxBuff[0] = cmd;
+		g_adxTxBuff[1] = data;
+		
+		
+		SPI_DRV_MasterTransferBlocking(ADXL_SPI_INSTANCE, g_adxTxBuff, g_adxRxBuff, 2, ADXL_SPI_TIMEOUT);
+}
+
+uint8_t ReadCmd(uint8_t cmd)
+{
+		cmd |=(0x80);
+		g_adxTxBuff[0] = cmd;
+		g_adxTxBuff[1] = 0x00;
+		SPI_DRV_MasterTransferBlocking(ADXL_SPI_INSTANCE, g_adxTxBuff, g_adxRxBuff, 2, ADXL_SPI_TIMEOUT);
+	
+		return g_adxRxBuff[1];
+}
+
+uint8_t ReadCmd2(uint8_t cmd, uint8_t* data)
+{
+		g_adxTxBuff[0] = cmd;
+		g_adxTxBuff[1] = 0x00;
+		g_adxTxBuff[2] = 0x00;
+		g_adxTxBuff[3] = 0x00;
+		g_adxTxBuff[4] = 0x00;
+		g_adxTxBuff[5] = 0x00;
+		g_adxTxBuff[6] = 0x00;
+		SPI_DRV_MasterTransferBlocking(ADXL_SPI_INSTANCE, g_adxTxBuff, g_adxRxBuff, 7, ADXL_SPI_TIMEOUT);
+	
+		data[0] = g_adxRxBuff[1];
+		data[1] = g_adxRxBuff[2];
+		data[2] = g_adxRxBuff[3];
+		data[3] = g_adxRxBuff[4];
+		data[4] = g_adxRxBuff[5];
+		data[5] = g_adxRxBuff[6];
+	
+		return 0;
+}
+
+
+static void SPI_Init_Gpio(void)
+{
+    GPIO_DRV_SetMuxModeSel(ADXL_SPI_SCK, ADXL_PIN_SCK, PORT_MUX_ALT3);        /*! SCK */
+    GPIO_DRV_SetMuxModeSel(ADXL_SPI_SOUT, ADXL_PIN_SOUT, PORT_MUX_ALT3);      /*! SOUT */
+    GPIO_DRV_SetMuxModeSel(ADXL_SPI_SIN, ADXL_PIN_SIN, PORT_MUX_ALT3);        /*! SIN */
+    GPIO_DRV_SetMuxModeSel(ADXL_SPI_CS, ADXL_PIN_CS, PORT_MUX_ALT3);          /*! CS */
+	
+		//GPIO_DRV_SetPullSel(ADXL_SPI_CS, ADXL_PIN_CS, PORT_INTERNAL_PULL_UP_ENABLED);
+}
+
+void ADXL312_Init(void)
+{
+		uint8_t tmp_data;
+	
+	  SPI_Init_Gpio();                                                        /*! 初始化对应引脚为SPI功能 */
+
+    SPI_DRV_MasterInit(ADXL_SPI_INSTANCE, &s_spiMasterState2, &spiMasteConfig2);   /*! SPI主机模式初始化 */
+    NVIC_SetPriority(ADXL_SPI_IRQ, 2);   	/*! 设置SPI中断优先级 */
+
+		//SPI_DRV_MasterSetDelay(ADXL_SPI_INSTANCE, 1U,1U, 1U);
+	
+	
+		tmp_data = ReadCmd(0x00);
+		while(tmp_data!=0xE5)     //判断是否器件ID正确 验证SPI通信是否正常
+		{
+			OSIF_TimeDelay(20);
+			tmp_data = ReadCmd(0x00);
+			
+		}
+		
+		WriteCmd(0x2E, 0x00);
+		WriteCmd(0x31, 0x0B); // 4线SPI 13bit 全分辨率 12g量程
+		
+		WriteCmd(0x2D, 0x08); //传感器测试模式 
+		WriteCmd(0x2C, 0x0E); //传感器传输数据速率 1600HZ 
+		
+		WriteCmd(0x2F, 0x03);
+		WriteCmd(0x38, 0x94);  //FIFO 模式 
+		
+		WriteCmd(0x1E, 0x00);
+		WriteCmd(0x1F, 0x00);
+		WriteCmd(0x20, 0x00);
+		
+		
+		//printf(" adxl312 ready 00 \r\n");
+		
+}
+
+void ADXL312_ReadID(uint8_t* p_id)
+{
+	uint8_t tmp_data = 0x00;
+	tmp_data = ReadCmd(0x00);
+	*p_id = tmp_data;
+
+}
+	
+uint8_t ADXL312_ReadAcc(int16_t* pAcc_x, int16_t* pAcc_y,int16_t* pAcc_z)
+{
+	uint8_t tmp[6];
+	
+	
+	ReadCmd2(0xF2, tmp);
+
+	*pAcc_x = ((tmp[1]<<8)|tmp[0]);
+	*pAcc_y = ((tmp[3]<<8)|tmp[2]);
+	*pAcc_z = ((tmp[5]<<8)|tmp[4]);
+	
+	return 0;
+	
+}

+ 85 - 0
Device/adxl312.h

@@ -0,0 +1,85 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+#ifndef _ADXL312_H
+#define _ADXL312_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* ===========================================  Includes  =========================================== */
+#include "ac7840x.h"
+
+/* ===========================================   Define    ========================================== */
+#define ADXL_SPI_TIMEOUT 		20U
+#define ADXL_SPI_INSTANCE        (1U)
+#define ADXL_SPI_IRQ             (SPI1_IRQn)
+#define ADXL_SPI_SCK        (PORTD)
+#define ADXL_SPI_CS         (PORTD)
+#define ADXL_SPI_SIN        (PORTD)
+#define ADXL_SPI_SOUT       (PORTD)
+#define ADXL_PIN_SCK         (0U)
+#define ADXL_PIN_CS          (3U)
+#define ADXL_PIN_SIN         (1U)
+#define ADXL_PIN_SOUT        (2U)
+
+#define ADXL_RET_OK						(0U)
+#define ADXL_RET_ERROR				(1U)
+/* ===========================================  Typedef  ============================================ */
+
+/* ==========================================  Variables  =========================================== */
+
+
+/* ====================================  Functions declaration  ===================================== */
+void ADXL312_Init(void);
+void ADXL312_ReadID(uint8_t* p_id);
+uint8_t ADXL312_ReadAcc(int16_t* pAcc_x, int16_t* pAcc_y,int16_t* pAcc_z);
+
+/* ======================================  Functions define  ======================================== */
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ADXL312_H */
+
+/* =============================================  EOF  ============================================== */
+
+

+ 67 - 0
Device/flash.c

@@ -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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+/* ===========================================  Includes  =========================================== */
+#include "flash_drv.h"
+#include "flash.h"
+
+
+/* ============================================  Define  ============================================ */
+
+
+/* ===========================================  Typedef  ============================================ */
+
+/* ==========================================  Variables  =========================================== */
+
+flash_config_t g_Flash_Config;                   /*!< Flash 饜离賦凳极 */
+const flash_user_config_t Flash_InitConfig = 
+{
+    .pFlashBase = 0x00000000U,                   /*!< Pflash お宎華硊 */
+    .pFlashSize = 0x80000U,                     /*!< Pflash 湮苤 */
+    .dFlashBase = 0x01000000U,                   /*!< Dflash お宎華硊 */
+    .flexRAMBase = 0x14000000U,                  /*!< FlexRAM お宎華硊 */
+    .callback = NULL,                            /*!< 隙覃 */
+};
+
+/* ====================================  Functions declaration  ===================================== */
+
+/* ======================================  Functions define  ======================================== */
+
+void Flash_Init(void)
+{
+		FLASH_DRV_Init(&Flash_InitConfig, &g_Flash_Config);                                    /*!< Flash 耀輸場宎趙 */
+}
+

+ 54 - 0
Device/flash.h

@@ -0,0 +1,54 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+#ifndef __FLASH_H__
+#define __FLASH_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "flash_drv.h"
+extern flash_config_t g_Flash_Config;
+
+void Flash_Init(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*__FLASH_H__*/
+ 

+ 126 - 0
Device/gpio.c

@@ -0,0 +1,126 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+/*!
+ * @file gpio.c
+ *
+ * @brief This file contains the user gpio function..
+ */
+
+/* ===========================================  Includes  =========================================== */
+#include  "gpio.h"
+
+/* ============================================  Define  ============================================ */
+
+
+/* ===========================================  Typedef  ============================================ */
+
+
+/* ==========================================  Variables  =========================================== */
+
+
+/* ====================================  Functions declaration  ===================================== */
+
+
+/*!
+* @brief  初始化LED引脚
+*
+* @param none
+* @return none
+*/
+void GPIO_LedInit(void)
+{
+    /*初始化引脚功能,有部分引脚上电默认为非GPIO,必须选择其功能为GPIO才能作为GPIO使用*/
+	  GPIO_DRV_SetMuxModeSel(LED1_PORT, LED1_PIN, PORT_MUX_AS_GPIO); /*功能复用选择*/
+    GPIO_DRV_SetMuxModeSel(LED2_PORT, LED2_PIN, PORT_MUX_AS_GPIO);
+    GPIO_DRV_SetMuxModeSel(LED3_PORT, LED3_PIN, PORT_MUX_AS_GPIO); /*功能复用选择*/
+    GPIO_DRV_SetMuxModeSel(LED4_PORT, LED4_PIN, PORT_MUX_AS_GPIO);
+	
+	
+	  GPIO_DRV_SetPinDirection(LED1_GPIO, LED1_PIN, 1); /*设置GPIO为输出*/
+    GPIO_DRV_SetPinDirection(LED2_GPIO, LED2_PIN, 1);
+    GPIO_DRV_SetPinDirection(LED3_GPIO, LED3_PIN, 1); /*设置GPIO为输出*/
+    GPIO_DRV_SetPinDirection(LED4_GPIO, LED4_PIN, 1);
+
+
+    /*上电默认LED关闭*/
+		LED1_OFF;
+		LED2_OFF;
+		LED3_OFF;
+		LED4_OFF;
+
+}
+
+/*!
+* @brief  初始化按键引脚
+*
+* @param none
+* @return none
+*/
+void GPIO_KeyInit(void)
+{
+    /*初始化引脚功能,有部分引脚上电默认为非GPIO,必须选择其功能为GPIO才能作为GPIO使用*/
+    GPIO_DRV_SetMuxModeSel(KEY3_PORT, KEY3_PIN, PORT_MUX_AS_GPIO); /*功能复用选择*/
+    //GPIO_DRV_SetMuxModeSel(KEY4_PORT, KEY4_PIN, PORT_MUX_AS_GPIO);
+
+    GPIO_DRV_SetPinDirection(KEY3_GPIO, KEY3_PIN, 0); /*设置按键引脚为输入*/
+    //GPIO_DRV_SetPinDirection(KEY4_GPIO, KEY4_PIN, 0);
+
+    //GPIO_DRV_SetPullSel(KEY3_PORT, KEY3_PIN, PORT_INTERNAL_PULL_UP_ENABLED); /*使能按键引脚的上拉*/
+    //GPIO_DRV_SetPullSel(KEY4_PORT, KEY4_PIN, PORT_INTERNAL_PULL_UP_ENABLED);
+}
+
+/*!
+ * @brief GPIO配置
+ *
+ * @param none
+ *
+ * @return none
+ */
+void GPIO_Init(void)
+{
+    GPIO_LedInit();
+    GPIO_KeyInit();
+    //PORT_SetPinIntSel(KEY4_PORT, KEY4_PIN, PORT_INT_FALLING_EDGE);
+
+    //GPIO_DRV_InstallCallback(KEY4_INSTANCE, KEY4_handler, 0);
+    //NVIC_SetPriority(KEY4_IRQ, 3);
+}
+
+/* ======================================  Functions define  ======================================== */
+
+
+/* =============================================  EOF  ============================================== */

+ 139 - 0
Device/gpio.h

@@ -0,0 +1,139 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+#ifndef _GPIO_H
+#define _GPIO_H
+
+/*!
+ * @file gpio.h
+ *
+ * @brief gpio function definition.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* ===========================================  Includes  =========================================== */
+#include <stdbool.h>
+#include <stdint.h>
+#include "ac7840x.h"
+#include "gpio_drv.h"
+#include "port_hw.h"
+
+
+/* ============================================  Define  ============================================ */
+
+//电磁阀输出
+#define LED1_PORT      (PORTD)
+#define LED1_GPIO      (GPIOD)
+#define LED1_PIN       (7)
+
+//433 语音播报输出
+#define LED2_PORT      (PORTC)
+#define LED2_GPIO      (GPIOC)
+#define LED2_PIN       (5)
+
+//设备运行指示灯
+#define LED3_PORT      (PORTC)
+#define LED3_GPIO      (GPIOC)
+#define LED3_PIN       (16)
+
+//底阀开关状态指示灯
+#define LED4_PORT      (PORTC)
+#define LED4_GPIO      (GPIOC)
+#define LED4_PIN       (17)
+
+
+//底阀开关状态输入
+#define KEY3_PORT      (PORTD)
+#define KEY3_GPIO      (GPIOD)
+#define KEY3_PIN       (6)
+
+
+//#define KEY4_PORT      (PORTE)
+//#define KEY4_GPIO      (GPIOE)
+//#define KEY4_PIN       (7)
+//#define KEY4_IRQ       (PORTE_IRQn)
+//#define KEY4_INSTANCE  (4)
+
+#define LED1_ON        do{GPIO_DRV_WritePin(LED1_GPIO , LED1_PIN, 1);}while(0)
+#define LED1_OFF       do{GPIO_DRV_WritePin(LED1_GPIO, LED1_PIN, 0);}while(0)
+#define LED1_TOGGLE    do{GPIO_DRV_TogglePins(LED1_GPIO, (1<<LED1_PIN));}while(0)
+
+#define LED2_ON        do{GPIO_DRV_WritePin(LED2_GPIO , LED2_PIN, 1);}while(0)
+#define LED2_OFF       do{GPIO_DRV_WritePin(LED2_GPIO, LED2_PIN, 0);}while(0)
+#define LED2_TOGGLE    do{GPIO_DRV_TogglePins(LED2_GPIO, (1<<LED2_PIN));}while(0)
+
+#define LED3_ON        do{GPIO_DRV_WritePin(LED3_GPIO , LED3_PIN, 0);}while(0)
+#define LED3_OFF       do{GPIO_DRV_WritePin(LED3_GPIO, LED3_PIN, 1);}while(0)
+#define LED3_TOGGLE    do{GPIO_DRV_TogglePins(LED3_GPIO, (1<<LED3_PIN));}while(0)
+
+#define LED4_ON        do{GPIO_DRV_WritePin(LED4_GPIO, LED4_PIN, 0);}while(0)
+#define LED4_OFF       do{GPIO_DRV_WritePin(LED4_GPIO, LED4_PIN, 1);}while(0)
+#define LED4_TOGGLE    do{GPIO_DRV_TogglePins(LED4_GPIO, (1<<LED4_PIN));}while(0)
+
+
+
+#define GET_K3_STS()   (GPIO_DRV_ReadPins(KEY3_GPIO)& (1<<KEY3_PIN))
+//#define GET_K4_STS()   (GPIO_DRV_ReadPins(KEY4_GPIO)& (1<<KEY4_PIN))
+
+#define DIR_IN  (0)
+#define DIR_OUT (1)
+
+#define LOW     (0)
+#define HIGH    (1)
+
+
+/* ===========================================  Typedef  ============================================ */
+
+/* ==========================================  Variables  =========================================== */
+//extern uint8_t g_key4PressDown_count;
+/* ====================================  Functions declaration  ===================================== */
+extern void GPIO_LedInit(void);
+extern void GPIO_KeyInit(void);
+void GPIO_Init(void);
+
+/* ======================================  Functions define  ======================================== */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GPIO_H */
+
+/* =============================================  EOF  ============================================== */

+ 97 - 0
Device/timer.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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+/*!
+* @file timer.c
+*
+* @brief This file contains the user function.
+*
+*/
+
+/* ===========================================  Includes  =========================================== */
+#include "timer.h"
+#include "string.h"
+#include "timer_drv.h"
+#include "timer_hw.h"
+#include "process.h"
+
+
+
+/*!* @brief TIMER0中断回调函数
+*
+* @param[in] none
+* @return none
+*/
+void TIMER0_Callback(void *device, uint32_t wpara, uint32_t lpara)
+{
+
+		timer_callback();
+		
+}
+
+/*!
+* @brief TIMER初始化函数
+*
+* @param[in] none
+* @return none
+*注意:timer时钟源在clock_config.c文件的peripheralClockConfig0结构体中第二个元素配置
+*/
+void Timer_Init(void)
+{
+    timer_user_channel_config_t timerConfig;
+    memset(&timerConfig, 0U, sizeof(timerConfig));
+
+    /*TIMER参数配置*/
+    timerConfig.timerMode = TIMER_PERIODIC_COUNTER;                         /* 32bit计数 */
+    timerConfig.periodUnits = TIMER_PERIOD_UNITS_MICROSECONDS;              /* 以us为单位计数 */
+    timerConfig.period = 10000U;                                          /* 10ms为周期 */
+    timerConfig.triggerSource = TIMER_TRIGGER_SOURCE_INTERNAL;              /* 选择内部触发 */
+    timerConfig.triggerSelect = 0x00U;                                      /* 选择通道0作为触发源,触发是否奏效由TSOT决定,1:触发源上升沿来时开始计数;0:使能后就开始计数,触发源无效 */
+    timerConfig.enableReloadOnTrigger = false;                              /* 触发源来时不重新加载计数值 */
+    timerConfig.enableStopOnInterrupt = false;                              /* 发生一次中断后不停止Timer的计数 */
+    timerConfig.enableStartOnTrigger = false;                               /* 配置ENRx=1即会使Timer开始计数,该位决定触发源是否奏效 */
+    timerConfig.chainChannel = false;                                       /* 禁能链接 */
+    timerConfig.isInterruptEnabled = true;                                  /* 使能中断 */
+    timerConfig.callback = TIMER0_Callback;                                 /* 回调函数配置 */
+
+    /*TIMER调用底层接口*/
+    TIMER_DRV_Init(0, true);
+    TIMER_DRV_InitChannel(0, TIMER_CHANNEL_0, &timerConfig);
+		NVIC_SetPriority(TIMER_CHANNEL0_IRQn, 3);   	/*! 设置SPI中断优先级 */
+    TIMER_DRV_StartChannels(0, 1 << TIMER_CHANNEL_0);
+}
+
+

+ 71 - 0
Device/timer.h

@@ -0,0 +1,71 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+#ifndef _TIMER_H
+#define _TIMER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* ===========================================  Includes  =========================================== */
+#include "ac7840x.h"
+
+/* ===========================================   Define    ========================================== */
+
+/* ===========================================  Typedef  ============================================ */
+
+/* ==========================================  Variables  =========================================== */
+
+
+/* ====================================  Functions declaration  ===================================== */
+void Timer_Init(void);
+
+
+/* ======================================  Functions define  ======================================== */
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ADXL312_H */
+
+/* =============================================  EOF  ============================================== */
+
+

+ 385 - 0
Device/uart.c

@@ -0,0 +1,385 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+#include "uart.h"
+#include "string.h"
+#include "ckgen_drv.h"
+#include "ckgen_hw.h"
+#include "gpio_drv.h"
+#include "gpio_hw.h"
+#include "uart_drv.h"
+#include "uart_hw.h"
+#include "uart_irq.h"
+#include "dma_drv.h"
+#include "dma_hw.h"
+#include "cfg.h"
+
+#define UART1_RX_DMA_CHANNEL   0
+#define UART1_TX_DMA_CHANNEL   1
+#define UART1_INSTANCE_ID   1
+
+//#define UART_DATA_LEN         4  /*数据传输长度*/
+uart_state_t s_uartState = {NULL}; /*UART运行变量状态*/
+
+
+UART_INFO  uart1_info;
+
+uint32_t dmaRxBuf[UART1_RECV_DATA_POOL_COUNT>>2];
+uint32_t dmaTxBuf[UART1_TRANSMIT_DATA_POOL_COUNT>>2];
+
+
+
+//uint8_t g_sendflag = 0;
+
+void UART_TxDMAEventCallback(void *device, uint32_t wparam, uint32_t lparam);
+void UART_RxDMAEventCallback(void *DMAx, uint32_t wparam, uint32_t lparam);
+
+/* UART rx DMA channel config */
+dma_channel_config_t s_uartRxDmaChConfig =
+{
+    .channelPriority = DMA_CHN_PRIORITY_LOW,
+    .virtChnConfig = UART1_RX_DMA_CHANNEL,
+    .source = DMA_REQ_UART1_RX,
+    .callback = (dma_callback_t)UART_RxDMAEventCallback,
+    .callbackParam = NULL,
+    .enableTrigger = false,
+
+};
+
+/* UART tx DMA channel config */
+dma_channel_config_t s_uartTxDmaChConfig =
+{
+    .channelPriority = DMA_CHN_PRIORITY_LOW,
+    .virtChnConfig = UART1_TX_DMA_CHANNEL,
+    .source = DMA_REQ_UART1_TX,
+    .callback = (dma_callback_t)UART_TxDMAEventCallback,
+    .callbackParam = NULL,
+    .enableTrigger = false,
+
+};
+
+dma_chn_state_t s_uartRxDmaChState =
+{
+    .virtChn  = UART1_RX_DMA_CHANNEL,         /* dma virtual channel */
+    .status   = DMA_CHN_NORMAL,               /* dma channel normal */
+    .callback = NULL,                         /* no callback function */
+
+};
+
+/* UART tx dma channel state */
+dma_chn_state_t s_uartTxDmaChState =
+{
+    .virtChn  = UART1_TX_DMA_CHANNEL,         /* dma virtual channel */
+    .status   = DMA_CHN_NORMAL,               /* dma channel normal */
+    .callback = NULL,
+};
+
+dma_state_t  g_dma_state;
+
+typedef enum
+{
+    UART_RX_INIT   = 1,
+    UART_RX_DATA   = 2,
+    UART_RX_FINISH = 3,
+    UART_TX_STA    = 4,
+} uart_rx_step_t;
+
+uart_rx_step_t g_uartRxStep = UART_RX_INIT;
+
+/*!
+* @brief Uart transmit event callback
+* @param[in] DMAx: DMA_Type pointer
+* @param[in] wparam: reserve for user's code
+* @param[in] lparam: reserve for user's code
+* @return none
+*/
+void UART_TxDMAEventCallback(void *device, uint32_t wparam, uint32_t lparam)
+{
+
+}
+
+/*!
+* @brief Uart dma receive handle
+* @param[in] DMAx: DMA_Type pointer
+* @param[in] wparam: reserve for user's code
+* @param[in] lparam: reserve for user's code
+* @return none
+*/
+void UART_RxDMAEventCallback(void *DMAx, uint32_t wparam, uint32_t lparam)
+{
+
+}
+
+/*!
+ * @brief   UART1接收中断回调函数
+ *
+ *
+ * @param   none
+ * @return  none
+ */
+void UART1_RX_Callback(void *driverState, uint32_t event, void *userData)
+{
+    if(event == UART_EVENT_IDLE_LINE){
+			
+			
+				//UART_Type * uart_type = UART_DRV_GetBase(UART1_INSTANCE_ID);
+				//UART_SetIdleInterrupt(uart_type, false);
+			
+
+				uint32_t rxRemainByte = UART1_RECV_DATA_POOL_COUNT;
+				UART_DRV_GetReceiveStatus(UART1_INSTANCE_ID, &rxRemainByte);
+				uart1_info.recv_len = UART1_RECV_DATA_POOL_COUNT - rxRemainByte;
+			
+				UART_DRV_AbortReceivingData(UART1_INSTANCE_ID);
+
+		}else if(event == UART_EVENT_END_TRANSFER){
+				//LED3_TOGGLE;
+
+		}else{
+		
+		}
+}
+
+/*!
+ * @brief   UART1发送中断回调函数
+ *
+ *
+ * @param   none
+ * @return  none
+ */
+void UART1_TX_Callback(void *driverState, uint32_t event, void *userData)
+{
+		if(UART_EVENT_TX_EMPTY == event){
+		
+			
+		}else if(event == UART_EVENT_END_TRANSFER){
+
+				//uart1_info.recv_len = 0;
+				//UART_Type * uart_type = UART_DRV_GetBase(UART1_INSTANCE_ID);
+				//UART_SetIdleInterrupt(uart_type, true);
+				//UART_DRV_ReceiveData(1, uart1_info.recv_buffer, UART1_RECV_DATA_POOL_COUNT); /*接收数据*/
+			
+			
+		}else{
+		
+		}
+
+}
+
+/**
+* Uart1_Initialize
+* 
+* @param[in] none
+* @return none
+*
+* @brief uart 初始化
+*/
+void Uart1_Initialize(void)
+{
+		uart_user_config_t userConfig;
+		memset(&userConfig, 0U, sizeof(userConfig));
+	
+    /*GPIO Configuration for UART1 */
+    GPIO_DRV_SetMuxModeSel(PORTC, (gpio_channel_type_t)8U, PORT_MUX_ALT2);  /* PC8: UART1_RX */
+    GPIO_DRV_SetMuxModeSel(PORTC, (gpio_channel_type_t)9U, PORT_MUX_ALT2);  /* PC9: UART1_TX */
+
+    GPIO_DRV_SetPullSel(PORTC, (gpio_channel_type_t)8U, PORT_INTERNAL_PULL_UP_ENABLED);
+    GPIO_DRV_SetPullSel(PORTC, (gpio_channel_type_t)9U, PORT_INTERNAL_PULL_UP_ENABLED);	
+	
+	    switch(config->br_index){
+			case BaudRate_4800:
+				userConfig.baudRate = 4800;
+				break;
+			case BaudRate_9600:
+				userConfig.baudRate = 9600;
+				break;
+			case BaudRate_19200:
+				userConfig.baudRate = 19200;
+				break;
+			case BaudRate_38400:
+				userConfig.baudRate = 38400;
+				break;
+			case BaudRate_57600:
+				userConfig.baudRate = 57600;
+				break;
+			case BaudRate_115200:
+				userConfig.baudRate = 115200;
+				break;
+			case BaudRate_230400:
+				userConfig.baudRate = 230400;
+				break;
+			default:
+				userConfig.baudRate = 115200;
+				break;
+		};
+			
+		userConfig.parityMode = UART_PARITY_DISABLED;         /*奇偶校验模式选择 */
+    userConfig.stopBitCount = UART_ONE_STOP_BIT;          /*停止位选择1-bit */
+    userConfig.bitCountPerChar = UART_8_BITS_PER_CHAR;    /*数据长度选择8 */
+	
+    userConfig.transferType = UART_USING_INTERRUPTS;             /*UART传输方式选择 (interrupt or dma) */
+    userConfig.rxDMAChannel = UART1_RX_DMA_CHANNEL;       /*DMA传输方式下的DMA rx 通道*/
+    userConfig.txDMAChannel = UART1_TX_DMA_CHANNEL;       /*DMA传输方式下的DMA tx 通道*/
+	
+		userConfig.rxCallback = UART1_RX_Callback;
+		userConfig.rxCallbackParam = NULL;
+		userConfig.txCallback = UART1_TX_Callback;
+		userConfig.txCallbackParam = NULL;
+
+		UART_DRV_Init(UART1_INSTANCE_ID, &s_uartState, &userConfig);
+		
+		UART_Type * uart_type = UART_DRV_GetBase(UART1_INSTANCE_ID);
+		UART_SetIdleFunc(uart_type, true);
+		UART_SetIdleInterrupt(uart_type, true);
+		
+		
+		uart1_info.recv_buffer = (uint8_t *)dmaRxBuf;
+		uart1_info.send_buffer = (uint8_t *)dmaTxBuf;
+		uart1_info.recv_len = 0;
+		uart1_info.send_len = 0;
+		
+		UART_DRV_ReceiveData(UART1_INSTANCE_ID, uart1_info.recv_buffer, UART1_RECV_DATA_POOL_COUNT); /*接收数据*/
+	
+}
+
+
+int Uart1_TransmitData(uint8_t *pdata, uint16_t length)
+{
+		//UART_DRV_SendData(UART1_INSTANCE_ID, pdata, length);
+		UART_DRV_SendDataBlocking(UART1_INSTANCE_ID, pdata, length, 50);
+		return 0;
+}
+
+
+void Uart1_RecvData(void)
+{
+		uart1_info.recv_len = 0;
+		//UART_Type * uart_type = UART_DRV_GetBase(UART1_INSTANCE_ID);
+		//UART_SetIdleFunc(uart_type, true);
+		//UART_SetIdleInterrupt(uart_type, true);
+		UART_DRV_ReceiveData(1, uart1_info.recv_buffer, UART1_RECV_DATA_POOL_COUNT); /*接收数据*/
+}
+
+/*!
+ * @brief   UART模块配置
+ *          UART1配置普通UART模式,波特率115200,数据长度为8bit,停止位为1bit
+ *          使能接收和发送DMA功能
+ * @param   none
+ * @return  none
+ */
+void UART1_Init(void)
+{
+    uart_user_config_t userConfig;
+
+    /*GPIO Configuration for UART1 */
+    GPIO_DRV_SetMuxModeSel(PORTC, (gpio_channel_type_t)8U, PORT_MUX_ALT2);  /* PC8: UART1_RX */
+    GPIO_DRV_SetMuxModeSel(PORTC, (gpio_channel_type_t)9U, PORT_MUX_ALT2);  /* PC9: UART1_TX */
+
+    GPIO_DRV_SetPullSel(PORTC, (gpio_channel_type_t)8U, PORT_INTERNAL_PULL_UP_ENABLED);
+    GPIO_DRV_SetPullSel(PORTC, (gpio_channel_type_t)9U, PORT_INTERNAL_PULL_UP_ENABLED);
+
+    memset(&userConfig, 0U, sizeof(userConfig));
+
+    userConfig.baudRate = 115200;                         /*波特率配置 */
+    userConfig.parityMode = UART_PARITY_DISABLED;         /*奇偶校验模式选择 */
+    userConfig.stopBitCount = UART_ONE_STOP_BIT;          /*停止位选择1-bit */
+    userConfig.bitCountPerChar = UART_8_BITS_PER_CHAR;    /*数据长度选择8 */
+	
+    userConfig.transferType = UART_USING_INTERRUPTS;             /*UART传输方式选择 (interrupt or dma) */
+    userConfig.rxDMAChannel = UART1_RX_DMA_CHANNEL;       /*DMA传输方式下的DMA rx 通道*/
+    userConfig.txDMAChannel = UART1_TX_DMA_CHANNEL;       /*DMA传输方式下的DMA tx 通道*/
+	
+		userConfig.rxCallback = UART1_RX_Callback;
+		userConfig.rxCallbackParam = NULL;
+		userConfig.txCallback = UART1_TX_Callback;
+		userConfig.txCallbackParam = NULL;
+
+		UART_DRV_Init(UART1_INSTANCE_ID, &s_uartState, &userConfig);
+		
+		UART_Type * uart_type = UART_DRV_GetBase(UART1_INSTANCE_ID);
+		UART_SetIdleFunc(uart_type, true);
+		UART_SetIdleInterrupt(uart_type, true);
+	 
+
+    /*DMA配置*/
+    //DMA_DRV_Init(&g_dma_state, NULL, NULL, NULL);
+    //DMA_DRV_ChannelInit(&s_uartRxDmaChState, &s_uartRxDmaChConfig);
+    //DMA_DRV_ChannelInit(&s_uartTxDmaChState, &s_uartTxDmaChConfig);
+		
+
+		uart1_info.recv_buffer = (uint8_t *)dmaRxBuf;
+		uart1_info.send_buffer = (uint8_t *)dmaTxBuf;
+		uart1_info.recv_len = 0;
+		uart1_info.send_len = 0;
+		
+		UART_DRV_ReceiveData(UART1_INSTANCE_ID, uart1_info.recv_buffer, UART1_RECV_DATA_POOL_COUNT); /*接收数据*/
+}
+
+/*!
+ * @brief   UART数据传输处理
+ *          UART查询接收数据,接收到数据后再将数据发送出去
+ *
+ * @param   none
+ * @return  none
+ */
+void UART1_DATA_Proce(void)
+{
+		//uint32_t rxRemainByte = 0;
+		#if 0
+	
+	  status_t status;
+
+    status = UART_DRV_ReceiveDataPolling(1, uart1_info.recv_buffer, UART1_RECV_DATA_POOL_COUNT); /*接收数据*/
+    if (status == STATUS_SUCCESS)
+    {
+        memcpy(uart1_info.send_buffer, uart1_info.recv_buffer, uart1_info.recv_len); /*将接收到的数据拷贝给发送数据*/
+				uart1_info.send_len = uart1_info.recv_len;
+				UART_DRV_SendData(UART1_INSTANCE, uart1_info.send_buffer, uart1_info.send_len);
+    }
+	
+	#else
+		if(uart1_info.recv_len > 0){
+			
+			memcpy(uart1_info.send_buffer, uart1_info.recv_buffer, uart1_info.recv_len); /*将接收到的数据拷贝给发送数据*/
+			uart1_info.send_len = uart1_info.recv_len;
+			UART_DRV_SendData(UART1_INSTANCE_ID, uart1_info.send_buffer, uart1_info.send_len);
+			
+			uart1_info.recv_len = 0;
+		}
+		
+		#endif 
+}
+

+ 85 - 0
Device/uart.h

@@ -0,0 +1,85 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+#ifndef __UART_H__
+#define __UART_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ===========================================  Includes  =========================================== */
+#include "ac7840x.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 UART1_BaudRate    115200
+#define UART1_TRANSMIT_DATA_POOL_COUNT 64
+#define UART1_RECV_DATA_POOL_COUNT     320  
+
+typedef struct
+{
+		uint32_t  recv_len;
+		uint32_t  send_len;
+    uint8_t* recv_buffer;
+		uint8_t* send_buffer;
+		uint8_t  res[2];
+}UART_INFO;
+
+extern UART_INFO  uart1_info;
+
+extern void Uart1_Initialize(void);
+extern int Uart1_TransmitData(uint8_t *pdata, uint16_t length);
+extern void Uart1_RecvData(void);
+
+
+//extern void UART1_Init(void);
+//extern void UART1_DATA_Proce(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*__UART_SAMPLE_H__*/

+ 77 - 0
Device/wdg.c

@@ -0,0 +1,77 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+#include "string.h"
+#include "wdg_drv.h"
+#include "wdg.h"
+
+#define WDG_INSTANCE  (0)
+
+/*!
+* @brief WDG_Init函数
+*
+* @param[in] none
+* @return none
+*/
+void WDG_Init(void)
+{
+    wdg_user_config_t wdg_config;
+    memset(&wdg_config, 0U, sizeof(wdg_config));
+
+    wdg_config.clkSource      = WDG_LSI_CLOCK; /*时钟源选择LSI*/
+    wdg_config.opMode.debugEn = true;          /*调试模式使能*/
+    wdg_config.opMode.stopEn  = true;          /*stop模式使能*/
+    wdg_config.prescalerEn    = true;          /*分频器开启,固定256分频*/
+    wdg_config.timeoutValue   = 499;           /*1S超时值配置:((WDG_LSI_CLOCK / 256) * n -1),公式根据时钟源和是否开启预分频器改变*/
+    wdg_config.windowValue    = 0;             /*窗口值设置为0*/
+    wdg_config.updateEn       = true;          /*WDG配置更新使能*/
+    wdg_config.intEn          = false;         /*WDG中断关闭*/
+    wdg_config.winEn          = false;         /*窗口功能关闭*/
+     
+	#ifdef WATCHDOG_ENABLE	
+    WDG_DRV_Init(WDG_INSTANCE, &wdg_config);             /*初始化WDG driver*/
+  #endif                                             
+}
+
+
+void WDG_Feed(void)
+{
+	#ifdef WATCHDOG_ENABLE	
+	 WDG_DRV_Trigger(WDG_INSTANCE);
+	#endif 
+}
+
+

+ 53 - 0
Device/wdg.h

@@ -0,0 +1,53 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+#ifndef __WDG_H__
+#define __WDG_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//#define  WATCHDOG_ENABLE   (1)
+
+extern void WDG_Init(void);
+extern void WDG_Feed(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*__WDG_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 "ac7840x.h"
+
+uint16_t crc16(const uint8_t *buf, uint32_t len);
+
+#endif

+ 370 - 0
Lib/md5c.c

@@ -0,0 +1,370 @@
+/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm 
+ */ 
+ 
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 
+rights reserved. 
+ 
+License to copy and use this software is granted provided that it 
+is identified as the "RSA Data Security, Inc. MD5 Message-Digest 
+Algorithm" in all material mentioning or referencing this software 
+or this function. 
+ 
+License is also granted to make and use derivative works provided 
+that such works are identified as "derived from the RSA Data 
+Security, Inc. MD5 Message-Digest Algorithm" in all material 
+mentioning or referencing the derived work. 
+ 
+RSA Data Security, Inc. makes no representations concerning either 
+the merchantability of this software or the suitability of this 
+software for any particular purpose. It is provided "as is" 
+without express or implied warranty of any kind. 
+ 
+These notices must be retained in any copies of any part of this 
+documentation and/or software. 
+ */ 
+#include "md5c.h" 
+#include <string.h> 
+#include <stdio.h> 
+ 
+/* Constants for MD5Transform routine. 
+*/ 
+ 
+ 
+#define S11 7 
+#define S12 12 
+#define S13 17 
+#define S14 22 
+#define S21 5 
+#define S22 9 
+#define S23 14 
+#define S24 20 
+#define S31 4 
+#define S32 11 
+#define S33 16 
+#define S34 23 
+#define S41 6 
+#define S42 10 
+#define S43 15 
+#define S44 21 
+ 
+static void MD5_memcpy (POINTER output, POINTER input, unsigned int len); 
+static void MD5Transform (UINT4 state[4], unsigned char block[64]); 
+static void Encode (unsigned char *output, UINT4 *input, unsigned int len); 
+static void MD5_memset (POINTER output, int value, unsigned int len); 
+static void Decode (UINT4 *output, unsigned char *input, unsigned int len); 
+ 
+static unsigned char PADDING[64] = { 
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 
+}; 
+ 
+/* F, G, H and I are basic MD5 functions. 
+*/ 
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) 
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) 
+#define H(x, y, z) ((x) ^ (y) ^ (z)) 
+#define I(x, y, z) ((y) ^ ((x) | (~z))) 
+ 
+/* ROTATE_LEFT rotates x left n bits. 
+*/ 
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 
+ 
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 
+Rotation is separate from addition to prevent recomputation. 
+*/ 
+#define FF(a, b, c, d, x, s, ac) { \
+	(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ } 
+#define GG(a, b, c, d, x, s, ac) { \
+ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ } 
+#define HH(a, b, c, d, x, s, ac) { \
+ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ } 
+#define II(a, b, c, d, x, s, ac) { \
+ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ } 
+ 
+/* MD5 initialization. Begins an MD5 operation, writing a new context. 
+ */ 
+void MD5Init (MD5_CTX *context)          /* context */ 
+{ 
+ context->count[0] = context->count[1] = 0; 
+ /* Load magic initialization constants. 
+ */ 
+ context->state[0] = 0x67452301; 
+ context->state[1] = 0xefcdab89; 
+ context->state[2] = 0x98badcfe; 
+ context->state[3] = 0x10325476; 
+} 
+ 
+/* MD5 block update operation. Continues an MD5 message-digest 
+ operation, processing another message block, and updating the 
+ context. 
+ */ 
+void MD5Update (MD5_CTX *context, unsigned char *input, unsigned int inputLen) 
+ 
+{ 
+ unsigned int i, index, partLen; 
+ 
+ /* Compute number of bytes mod 64 */ 
+ index = (unsigned int)((context->count[0] >> 3) & 0x3F); 
+ 
+ /* Update number of bits */ 
+ if ((context->count[0] += ((UINT4)inputLen << 3)) 
+  < ((UINT4)inputLen << 3)) 
+  context->count[1]++; 
+ context->count[1] += ((UINT4)inputLen >> 29); 
+ 
+ partLen = 64 - index; 
+ 
+ /* Transform as many times as possible. 
+ */ 
+ if (inputLen >= partLen) { 
+  MD5_memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen); 
+  MD5Transform (context->state, context->buffer); 
+ 
+  for (i = partLen; i + 63 < inputLen; i += 64) 
+   MD5Transform (context->state, &input[i]); 
+ 
+  index = 0; 
+ } 
+ else 
+  i = 0; 
+ 
+ /* Buffer remaining input */ 
+ MD5_memcpy((POINTER)&context->buffer[index], (POINTER)&input[i],inputLen-i); 
+} 
+ 
+/* MD5 finalization. Ends an MD5 message-digest operation, writing the 
+ the message digest and zeroizing the context. 
+ */ 
+void MD5Final (unsigned char digest[16], MD5_CTX *context)         
+{ 
+ unsigned char bits[8]; 
+ unsigned int index, padLen; 
+ 
+ /* Save number of bits */ 
+ Encode (bits, context->count, 8); 
+ 
+ /* Pad out to 56 mod 64. 
+ */ 
+ index = (unsigned int)((context->count[0] >> 3) & 0x3f); 
+ padLen = (index < 56) ? (56 - index) : (120 - index); 
+ MD5Update (context, PADDING, padLen); 
+ 
+ /* Append length (before padding) */ 
+ MD5Update (context, bits, 8); 
+ 
+ /* Store state in digest */ 
+ Encode (digest, context->state, 16); 
+ 
+ /* Zeroize sensitive information. 
+ */ 
+ MD5_memset ((POINTER)context, 0, sizeof (*context)); 
+} 
+ 
+/* MD5 basic transformation. Transforms state based on block. 
+ */ 
+static void MD5Transform (UINT4 state[4], unsigned char block[64]) 
+{ 
+ UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; 
+ 
+ Decode (x, block, 64); 
+ 
+ /* Round 1 */ 
+ FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ 
+ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ 
+ FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ 
+ FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ 
+ FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ 
+ FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ 
+ FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ 
+ FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ 
+ FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ 
+ FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ 
+ FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ 
+ FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ 
+ FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ 
+ FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ 
+ FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ 
+ FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ 
+ 
+ /* Round 2 */ 
+ GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ 
+ GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ 
+ GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ 
+ GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ 
+ GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ 
+ GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ 
+ GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ 
+ GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ 
+ GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ 
+ GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ 
+ GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ 
+ GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ 
+ GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ 
+ GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ 
+ GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ 
+ GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ 
+ 
+ /* Round 3 */ 
+ HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ 
+ HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ 
+ HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ 
+ HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ 
+ HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ 
+ HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ 
+ HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ 
+ HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ 
+ HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ 
+ HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ 
+ HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ 
+ HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ 
+ HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ 
+ HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ 
+ HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ 
+ HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ 
+ 
+ /* Round 4 */ 
+ II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ 
+ II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ 
+ II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ 
+ II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ 
+ II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ 
+ II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ 
+ II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ 
+ II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ 
+ II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ 
+ II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ 
+ II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ 
+ II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ 
+ II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ 
+ II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ 
+ II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ 
+ II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ 
+ 
+ state[0] += a; 
+ state[1] += b; 
+ state[2] += c; 
+ state[3] += d; 
+ 
+ /* Zeroize sensitive information. 
+ */ 
+ MD5_memset ((POINTER)x, 0, sizeof (x)); 
+} 
+ 
+/* Encodes input (UINT4) into output (unsigned char). Assumes len is 
+ a multiple of 4. 
+ */ 
+static void Encode (unsigned char *output, UINT4 *input, unsigned int len) 
+{ 
+ unsigned int i, j; 
+ 
+ for (i = 0, j = 0; j < len; i++, j += 4) { 
+  output[j] = (unsigned char)(input[i] & 0xff); 
+  output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); 
+  output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); 
+  output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); 
+ } 
+} 
+ 
+/* Decodes input (unsigned char) into output (UINT4). Assumes len is 
+ a multiple of 4. 
+ */ 
+static void Decode (UINT4 *output, unsigned char *input, unsigned int len) 
+{ 
+ unsigned int i, j; 
+ 
+ for (i = 0, j = 0; j < len; i++, j += 4) 
+  output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | 
+  (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); 
+} 
+ 
+/* Note: Replace "for loop" with standard memcpy if possible. 
+ */ 
+ 
+static void MD5_memcpy (POINTER output, POINTER input, unsigned int len) 
+{ 
+ unsigned int i; 
+ 
+ for (i = 0; i < len; i++) 
+  output[i] = input[i]; 
+} 
+ 
+/* Note: Replace "for loop" with standard memset if possible. 
+ */ 
+static void MD5_memset (POINTER output, int value, unsigned int len) 
+{ 
+ unsigned int i; 
+ 
+ for (i = 0; i < len; i++) 
+  ((char *)output)[i] = (char)value; 
+} 
+
+#if 0
+/* Digests a string and prints the result. 
+ */ 
+void MDString (char *string,unsigned char digest[16]) 
+{ 
+ MD5_CTX context; 
+ unsigned int len = strlen (string); 
+ 
+ MD5Init (&context); 
+ MD5Update (&context, (unsigned char *)string, len); 
+ MD5Final (digest, &context); 
+} 
+/* Digests a file and prints the result. 
+ */ 
+int MD5File (char *filename,unsigned char digest[16]) 
+{ 
+ FILE *file; 
+ MD5_CTX context; 
+ int len; 
+ unsigned char buffer[1024]; 
+ 
+ if ((file = fopen (filename, "rb")) == NULL) 
+  return -1; 
+ else { 
+  MD5Init (&context); 
+  while (len = fread (buffer, 1, 1024, file)) 
+   MD5Update (&context, buffer, len); 
+  MD5Final (digest, &context); 
+ 
+  fclose (file); 
+ } 
+ return 0; 
+} 
+
+
+void MD5UpdaterString(MD5_CTX *context,const char *string) 
+{ 
+ unsigned int len = strlen (string); 
+ MD5Update (context, (unsigned char *)string, len); 
+} 
+int MD5FileUpdateFile (MD5_CTX *context,char *filename) 
+{ 
+ FILE *file; 
+ int len; 
+ unsigned char buffer[1024]; 
+ 
+ if ((file = fopen (filename, "rb")) == NULL) 
+  return -1; 
+ else { 
+  while (len = fread (buffer, 1, 1024, file)) 
+   MD5Update (context, buffer, len); 
+  fclose (file); 
+ } 
+ return 0; 
+} 
+#endif 
+

+ 27 - 0
Lib/md5c.h

@@ -0,0 +1,27 @@
+#ifndef __MD5C_H__
+#define __MD5C_H__
+/* POINTER defines a generic pointer type */ 
+typedef unsigned char * POINTER; 
+ 
+/* UINT2 defines a two byte word */ 
+//typedef unsigned short int UINT2; 
+ 
+/* UINT4 defines a four byte word */ 
+typedef unsigned long int UINT4; 
+ 
+ 
+/* MD5 context. */ 
+typedef struct { 
+ UINT4 state[4];         /* state (ABCD) */ 
+ UINT4 count[2];  /* number of bits, modulo 2^64 (lsb first) */ 
+ unsigned char buffer[64];       /* input buffer */ 
+} MD5_CTX; 
+ 
+void MD5Init (MD5_CTX *context); 
+void MD5Update (MD5_CTX *context, unsigned char *input, unsigned int inputLen); 
+void MD5UpdaterString(MD5_CTX *context,const char *string); 
+int MD5FileUpdateFile (MD5_CTX *context,char *filename); 
+void MD5Final (unsigned char digest[16], MD5_CTX *context); 
+//void MDString (char *string,unsigned char digest[16]); 
+//int MD5File (char *filename,unsigned char digest[16]); 
+#endif

文件差異過大導致無法顯示
+ 3734 - 0
Project/BVACS.uvguix.孙凯


+ 606 - 0
Project/BVACS.uvoptx

@@ -0,0 +1,606 @@
+<?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>bvacs</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>DLGUARM</Key>
+          <Name></Name>
+        </SetRegEntry>
+        <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)(1009=-1,-1,-1,-1,0)(1012=-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(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO23 -FD1FFF0000 -FC1000 -FN1 -FF0AC7840X_P1024KB.FLM -FS00 -FL080000 -FP0($$Device:AC78406HGLA$Flash\AC7840X_P1024KB.FLM)</Name>
+        </SetRegEntry>
+        <SetRegEntry>
+          <Number>0</Number>
+          <Key>UL2CM3</Key>
+          <Name>UL2CM3(-S0 -C0 -P0 -FD1FFF0000 -FC1000 -FN1 -FF0AC7840X_P1024KB -FS00 -FL0100000 -FP0($$Device:AC78406HGLA$Flash\AC7840X_P1024KB.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>
+      <SystemViewers>
+        <Entry>
+          <Name>System Viewer\UART1</Name>
+          <WinId>35905</WinId>
+        </Entry>
+      </SystemViewers>
+      <DebugDescription>
+        <Enable>1</Enable>
+        <EnableFlashSeq>1</EnableFlashSeq>
+        <EnableLog>0</EnableLog>
+        <Protocol>2</Protocol>
+        <DbgClock>10000000</DbgClock>
+      </DebugDescription>
+    </TargetOption>
+  </Target>
+
+  <Group>
+    <GroupName>User</GroupName>
+    <tvExp>1</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\clock_config.c</PathWithFileName>
+      <FilenameWithoutPath>clock_config.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>2</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\User\clock_config.h</PathWithFileName>
+      <FilenameWithoutPath>clock_config.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>3</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>4</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>5</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>6</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>7</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>8</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>9</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>10</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>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>11</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>12</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>13</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>
+  </Group>
+
+  <Group>
+    <GroupName>Lib</GroupName>
+    <tvExp>1</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>14</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>15</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>16</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Lib\md5c.c</PathWithFileName>
+      <FilenameWithoutPath>md5c.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>17</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Lib\md5c.h</PathWithFileName>
+      <FilenameWithoutPath>md5c.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+  </Group>
+
+  <Group>
+    <GroupName>Device</GroupName>
+    <tvExp>1</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>18</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\adxl312.h</PathWithFileName>
+      <FilenameWithoutPath>adxl312.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>19</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\adxl312.c</PathWithFileName>
+      <FilenameWithoutPath>adxl312.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>20</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>21</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>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\timer.c</PathWithFileName>
+      <FilenameWithoutPath>timer.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\uart.h</PathWithFileName>
+      <FilenameWithoutPath>uart.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\flash.h</PathWithFileName>
+      <FilenameWithoutPath>flash.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>27</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\flash.c</PathWithFileName>
+      <FilenameWithoutPath>flash.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>28</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\wdg.h</PathWithFileName>
+      <FilenameWithoutPath>wdg.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>29</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\wdg.c</PathWithFileName>
+      <FilenameWithoutPath>wdg.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+  </Group>
+
+  <Group>
+    <GroupName>::Board Support</GroupName>
+    <tvExp>0</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>1</RteFlg>
+  </Group>
+
+  <Group>
+    <GroupName>::CMSIS</GroupName>
+    <tvExp>0</tvExp>
+    <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>

+ 718 - 0
Project/BVACS.uvprojx

@@ -0,0 +1,718 @@
+<?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>bvacs</TargetName>
+      <ToolsetNumber>0x4</ToolsetNumber>
+      <ToolsetName>ARM-ADS</ToolsetName>
+      <pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
+      <uAC6>0</uAC6>
+      <TargetOption>
+        <TargetCommonOption>
+          <Device>AC78406HGLA</Device>
+          <Vendor>AutoChips</Vendor>
+          <PackID>AutoChips.AC7840x_DFP.2.0.5</PackID>
+          <PackURL>https://armfileget.autochips.com/CMSIS_PACK/AC7840x/</PackURL>
+          <Cpu>IRAM(0x1FFF0000,0x00010000) IRAM2(0x20000000,0x0000F000) IROM(0x00000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
+          <FlashUtilSpec></FlashUtilSpec>
+          <StartupFile></StartupFile>
+          <FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD1FFF0000 -FC1000 -FN1 -FF0AC7840X_P1024KB -FS00 -FL0100000 -FP0($$Device:AC78406HGLA$Flash\AC7840X_P1024KB.FLM))</FlashDriverDll>
+          <DeviceId>0</DeviceId>
+          <RegisterFile>$$Device:AC78406HGLA$Device\ac7840x\include\ac7840x.h</RegisterFile>
+          <MemoryEnv></MemoryEnv>
+          <Cmp></Cmp>
+          <Asm></Asm>
+          <Linker></Linker>
+          <OHString></OHString>
+          <InfinionOptionDll></InfinionOptionDll>
+          <SLE66CMisc></SLE66CMisc>
+          <SLE66AMisc></SLE66AMisc>
+          <SLE66LinkerMisc></SLE66LinkerMisc>
+          <SFDFile>$$Device:AC78406HGLA$SVD\AC7840x.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>BVACS_20240125</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>1</RunUserProg1>
+            <RunUserProg2>0</RunUserProg2>
+            <UserProg1Name>fromelf --bin -o "$L@L.bin" "#L</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>  -MPU</SimDllArguments>
+          <SimDlgDll>DCM.DLL</SimDlgDll>
+          <SimDlgDllArguments>-pCM4</SimDlgDllArguments>
+          <TargetDllName>SARMCM3.DLL</TargetDllName>
+          <TargetDllArguments> -MPU</TargetDllArguments>
+          <TargetDlgDll>TCM.DLL</TargetDlgDll>
+          <TargetDlgDllArguments>-pCM4</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>4096</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-M4"</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>2</RvdsVP>
+            <RvdsMve>0</RvdsMve>
+            <RvdsCdeCp>0</RvdsCdeCp>
+            <hadIRAM2>1</hadIRAM2>
+            <hadIROM2>0</hadIROM2>
+            <StupSel>8</StupSel>
+            <useUlib>0</useUlib>
+            <EndSel>0</EndSel>
+            <uLtcg>0</uLtcg>
+            <nSecure>0</nSecure>
+            <RoSelD>3</RoSelD>
+            <RwSelD>4</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>1</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>0x1fff0000</StartAddress>
+                <Size>0x10000</Size>
+              </IRAM>
+              <IROM>
+                <Type>1</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x100000</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>0x0</StartAddress>
+                <Size>0x28000</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>0x1fff0000</StartAddress>
+                <Size>0x10000</Size>
+              </OCR_RVCT9>
+              <OCR_RVCT10>
+                <Type>0</Type>
+                <StartAddress>0x20000000</StartAddress>
+                <Size>0xf000</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;..\Lib;..\Device</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>0x00000000</TextAddressRange>
+            <DataAddressRange>0x1FFF0000</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>clock_config.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\clock_config.c</FilePath>
+            </File>
+            <File>
+              <FileName>clock_config.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\User\clock_config.h</FilePath>
+            </File>
+            <File>
+              <FileName>main.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\main.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>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>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>process.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\process.c</FilePath>
+            </File>
+            <File>
+              <FileName>process.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\User\process.h</FilePath>
+            </File>
+            <File>
+              <FileName>protocol.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\protocol.c</FilePath>
+            </File>
+            <File>
+              <FileName>protocol.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\User\protocol.h</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>Lib</GroupName>
+          <Files>
+            <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>md5c.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Lib\md5c.c</FilePath>
+            </File>
+            <File>
+              <FileName>md5c.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Lib\md5c.h</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>Device</GroupName>
+          <Files>
+            <File>
+              <FileName>adxl312.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Device\adxl312.h</FilePath>
+            </File>
+            <File>
+              <FileName>adxl312.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Device\adxl312.c</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>timer.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Device\timer.h</FilePath>
+            </File>
+            <File>
+              <FileName>timer.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Device\timer.c</FilePath>
+            </File>
+            <File>
+              <FileName>uart.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Device\uart.h</FilePath>
+            </File>
+            <File>
+              <FileName>uart.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Device\uart.c</FilePath>
+            </File>
+            <File>
+              <FileName>flash.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Device\flash.h</FilePath>
+            </File>
+            <File>
+              <FileName>flash.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Device\flash.c</FilePath>
+            </File>
+            <File>
+              <FileName>wdg.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Device\wdg.h</FilePath>
+            </File>
+            <File>
+              <FileName>wdg.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Device\wdg.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>::Board Support</GroupName>
+        </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="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="CMSIS" Cgroup="DSP" Cvariant="Source" Cvendor="ARM" Cversion="1.9.0-dev" condition="CMSIS DSP">
+        <package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.8.0"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cbundle="AC7840x Development Kit" Cclass="Board Support" Cgroup="AC7840x Development Kit" Csub="Debug" Cvariant="AC7840x Development Kit" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x Debug Interface">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="CKGEN" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x CKGEN Driver Require">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="DMA" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x System">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="EFLASH" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x FLASH Require">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="GPIO" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x System">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="RCM" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x System">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="SPI" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x SPI Driver Require">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="SPM" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x System">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="TIMER" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x System">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="UART" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x UART Driver Require">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC Drivers" Csub="WDG" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x System">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="ATC OSIF" Csub="OSIF" Cvariant="Bare Metal" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x System">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+      <component Cclass="Device" Cgroup="Startup" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x CMSIS-CORE">
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </component>
+    </components>
+    <files>
+      <file attr="config" category="source" name="Device\ac7840x\startup\debugout_ac7840x.c" version="1.0.0">
+        <instance index="0">RTE\Board_Support\AC78406HGLA\debugout_ac7840x.c</instance>
+        <component Cbundle="AC7840x Development Kit" Cclass="Board Support" Cgroup="AC7840x Development Kit" Csub="Debug" Cvariant="AC7840x Development Kit" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x Debug Interface"/>
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </file>
+      <file attr="config" category="header" name="Device\ac7840x\include\ac7840x_features.h" version="1.0.0">
+        <instance index="0">RTE\Device\AC78406HGLA\ac7840x_features.h</instance>
+        <component Cclass="Device" Cgroup="Startup" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x CMSIS-CORE"/>
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </file>
+      <file attr="config" category="header" name="Device\device_assert.h" version="1.0.0">
+        <instance index="0">RTE\Device\AC78406HGLA\device_assert.h</instance>
+        <component Cclass="Device" Cgroup="Startup" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x CMSIS-CORE"/>
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </file>
+      <file attr="config" category="header" name="Device\device_register.h" version="1.0.0">
+        <instance index="0">RTE\Device\AC78406HGLA\device_register.h</instance>
+        <component Cclass="Device" Cgroup="Startup" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x CMSIS-CORE"/>
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </file>
+      <file attr="config" category="header" name="Device\device_status.h" version="1.0.0">
+        <instance index="0">RTE\Device\AC78406HGLA\device_status.h</instance>
+        <component Cclass="Device" Cgroup="Startup" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x CMSIS-CORE"/>
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </file>
+      <file attr="config" category="sourceAsm" name="Device\ac7840x\startup\armc\startup_ac7840x.s" version="1.0.0">
+        <instance index="0">RTE\Device\AC78406HGLA\startup_ac7840x.s</instance>
+        <component Cclass="Device" Cgroup="Startup" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x CMSIS-CORE"/>
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </file>
+      <file attr="config" category="source" name="Device\ac7840x\startup\system_ac7840x.c" version="1.0.0">
+        <instance index="0">RTE\Device\AC78406HGLA\system_ac7840x.c</instance>
+        <component Cclass="Device" Cgroup="Startup" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x CMSIS-CORE"/>
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </targetInfos>
+      </file>
+      <file attr="config" category="header" name="Device\ac7840x\startup\system_ac7840x.h" version="1.0.0">
+        <instance index="0">RTE\Device\AC78406HGLA\system_ac7840x.h</instance>
+        <component Cclass="Device" Cgroup="Startup" Cvendor="AutoChips" Cversion="1.0.0" condition="AC7840x CMSIS-CORE"/>
+        <package name="AC7840x_DFP" schemaVersion="1.4" url="https://armfileget.autochips.com/CMSIS_PACK/AC7840x/" vendor="AutoChips" version="2.0.5"/>
+        <targetInfos>
+          <targetInfo name="bvacs"/>
+        </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>

文件差異過大導致無法顯示
+ 1686 - 0
Project/JLinkLog.txt


+ 40 - 0
Project/JLinkSettings.ini

@@ -0,0 +1,40 @@
+[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]
+EraseType = 0x00
+CacheExcludeSize = 0x00
+CacheExcludeAddr = 0x00
+MinNumBytesFlashDL = 0
+SkipProgOnCRCMatch = 1
+VerifyDownload = 1
+AllowCaching = 1
+EnableFlashDL = 2
+Override = 1
+Device="AC7840x"
+[GENERAL]
+WorkRAMSize = 0x00
+WorkRAMAddr = 0x00
+RAMUsageLimit = 0x00
+[SWO]
+SWOLogFile=""
+[MEM]
+RdOverrideOrMask = 0x00
+RdOverrideAndMask = 0xFFFFFFFF
+RdOverrideAddr = 0xFFFFFFFF
+WrOverrideOrMask = 0x00
+WrOverrideAndMask = 0xFFFFFFFF
+WrOverrideAddr = 0xFFFFFFFF

文件差異過大導致無法顯示
+ 4545 - 0
Project/Listings/BVACS.map


文件差異過大導致無法顯示
+ 4725 - 0
Project/Listings/BVACS_20240112.map


文件差異過大導致無法顯示
+ 4892 - 0
Project/Listings/BVACS_20240115.map


文件差異過大導致無法顯示
+ 4892 - 0
Project/Listings/BVACS_20240123.map


文件差異過大導致無法顯示
+ 4896 - 0
Project/Listings/BVACS_20240124.map


文件差異過大導致無法顯示
+ 4923 - 0
Project/Listings/BVACS_20240125.map


文件差異過大導致無法顯示
+ 1906 - 0
Project/Listings/startup_ac7840x.lst


+ 250 - 0
Project/RTE/Board_Support/AC78406HGLA/debugout_ac7840x.c

@@ -0,0 +1,250 @@
+/* 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) 2021. 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 debugout_ac7840x.c
+ *
+ * @brief This file provides debug information output integration functions.
+ *
+ */
+
+/* ===========================================  Includes  =========================================== */
+#include "device_register.h"
+#include "gpio_drv.h"
+#include "ckgen_drv.h"
+#include "debugout_ac7840x.h"
+#include "../src/uart/uart_hw.h"
+
+/* ============================================  Define  ============================================ */
+#define MAX_DEBUG_BUFF_SIZE      100UL               /* define uart max receive buffer size */
+
+#define DEBUG_INSTANCE           1UL
+#define DEBUG_UART               UART1              /* define uart1 for debug output  */
+#define DEBUG_UART_IRQ           UART1_IRQn         /* define uart1 interrupt vector  */
+#define DEBUG_UART_CLK           CLK_UART1          /* define uart1 ckgen clock value */
+#define DEBUG_UART_SRST          SRST_UART1         /* define uart1 ckgen reset value */
+#define DEBUG_UART_BAUDRATE      115200UL
+#if 0
+#define DEBUG_UART_TX_PIN        PORTB, 22UL        /* define uart1 tx gpio */
+#define DEBUG_UART_RX_PIN        PORTB, 23UL        /* define uart1 rx gpio */
+#define DEBUG_UART_TX_FUNC       PORT_MUX_ALT5      /* define uart1 tx pinmux */
+#define DEBUG_UART_RX_FUNC       PORT_MUX_ALT3      /* define uart1 rx pinmux */
+#else
+#define DEBUG_UART_TX_PIN        PORTC, 9UL         /* define uart1 tx gpio */
+#define DEBUG_UART_RX_PIN        PORTC, 8UL         /* define uart1 rx gpio */
+#define DEBUG_UART_TX_FUNC       PORT_MUX_ALT2      /* define uart1 tx pinmux */
+#define DEBUG_UART_RX_FUNC       PORT_MUX_ALT2      /* define uart1 rx pinmux */
+#endif
+
+/* ===========================================  Typedef  ============================================ */
+
+/* ==========================================  Variables  =========================================== */
+/* debug uart receive buf */
+uint8_t g_debugBuff[MAX_DEBUG_BUFF_SIZE] = {0U};
+/* debug init flag */
+static uint8_t s_debugInit = 0U;
+
+/* define std FILE struct */
+struct __FILE
+{
+    int handle;
+};
+
+/* refine stdout,stdin,stderr */
+FILE __stdout;
+FILE __stdin;
+FILE __stderr;
+
+/* ====================================  Functions declaration  ===================================== */
+
+/* ======================================  Functions define  ======================================== */
+/*!
+ * @brief Refine _sys_exit.
+ *
+ * @param[in] x:  no use
+ * @return always 0
+ */
+int _sys_exit(int x)
+{
+    x = x;
+    (void)x;
+
+    return 0;
+}
+
+/*!
+ * @brief Refine _ttywrch.
+ *
+ * @param[in] x:  no use
+ * @return always 0
+ */
+int _ttywrch(int x)
+{
+    x = x;
+    (void)x;
+
+    return 0;
+}
+
+#ifdef ITM_DEBUG_OUT
+/*!
+ * @brief Put a char to ITM.
+ *
+ * @param[in] ch: the char to put
+ * @param[in] f:  file pointer for the std input
+ * @return return the char of be put
+ */
+int fputc(int ch, FILE *f)
+{
+    if (s_debugInit)
+    {
+        ITM_SendChar(ch);
+    }
+
+    return ch;
+}
+
+/* for ITM use */
+volatile int ITM_RxBuffer;
+
+/*!
+ * @brief Get a char from ITM.
+ *
+ * @param[in] f: file pointer for the std input
+ * @return -1: not get char, other: the char get from ITM
+ */
+int fgetc(FILE *f)
+{
+    int ch = ITM_ReceiveChar();
+
+    return ch;
+}
+#else
+/*!
+ * @brief Put a char to UART.
+ *
+ * @param[in] ch: the char to put
+ * @param[in] f:  file pointer for the std input
+ * @return return the char of be put
+ */
+int fputc(int ch, FILE *f)
+{
+    if (s_debugInit)
+    {
+        while (!UART_GetStatusFlag(DEBUG_UART, UART_TX_DATA_NOT_FULL));
+        UART_Putchar(DEBUG_UART, (uint8_t)ch);
+    }
+
+    return ch;
+}
+
+/*!
+ * @brief Get a char from UART.
+ *
+ * @param[in] f: file pointer for the std input
+ * @return -1: not get char, other: the char get from UART
+ */
+int fgetc(FILE *f)
+{
+    int ch = -1;
+
+    if (s_debugInit)
+    {
+        if (UART_GetStatusFlag(DEBUG_UART, UART_RX_DATA_READY))
+        {
+            UART_Getchar(DEBUG_UART, (uint8_t *)&ch);
+            ch &= 0xFF;
+        }
+    }
+
+    return ch;
+}
+#endif /* ITM_DEBUG_OUT */
+
+/*!
+ * @brief Set the debug out is invalid.
+ *
+ * @param[in] none
+ * @return none
+ */
+void DeinitDebug(void)
+{
+    s_debugInit = 0U;
+}
+
+/*!
+ * @brief Init debug out, and set the debug out is valid.
+ *
+ * @param[in] none
+ * @return none
+ */
+void InitDebug(void)
+{
+#ifndef ITM_DEBUG_OUT
+#ifdef DEBUG_CMD_INTERRUPT
+    NVIC_SetPriority(DEBUG_UART_IRQ, 3U);
+    NVIC_ClearPendingIRQ(DEBUG_UART_IRQ);
+    NVIC_EnableIRQ(DEBUG_UART_IRQ);
+#endif /* DEBUG_CMD_INTERRUPT */
+
+    /* Set pinmux */
+    GPIO_DRV_SetMuxModeSel(DEBUG_UART_TX_PIN, DEBUG_UART_TX_FUNC);
+    GPIO_DRV_SetMuxModeSel(DEBUG_UART_RX_PIN, DEBUG_UART_RX_FUNC);
+
+    /* Check UART function clock */
+    if (0U == (CKGEN->PERI_CLK_MUX2 & \
+        (CKGEN_PERI_CLK_MUX2_UART0_MUX_Msk << ((uint32_t)DEBUG_UART_CLK * 4U))))
+    {
+        /* Default set clock to HSIDIV2 */
+        CKGEN->PERI_CLK_MUX2 |= 5U << ((uint32_t)DEBUG_UART_CLK * 4U);
+    }
+    /* Enable UART bus clock and release UART module from reset status */
+    CKGEN_DRV_Enable(DEBUG_UART_CLK, true);
+    CKGEN_DRV_SoftReset(DEBUG_UART_SRST, true);
+
+    /* Set the baudrate */
+    (void)UART_DRV_SetBaudRate(DEBUG_INSTANCE, DEBUG_UART_BAUDRATE);
+
+    UART_SetBitCountPerChar(DEBUG_UART, UART_8_BITS_PER_CHAR);
+    UART_SetStopBitCount(DEBUG_UART, UART_ONE_STOP_BIT);
+    UART_SetParityMode(DEBUG_UART, UART_PARITY_DISABLED);
+    UART_SetFIFO(DEBUG_UART, true);
+
+    /* Enable UART TX and RX */
+    UART_SetTransmitterCmd(DEBUG_UART, true);
+    UART_SetReceiverCmd(DEBUG_UART, true);
+#endif /* ITM_DEBUG_OUT */
+    s_debugInit = 1U;
+}
+
+/* =============================================  EOF  ============================================== */

文件差異過大導致無法顯示
+ 1001 - 0
Project/RTE/Device/AC78406HGLA/ac7840x_features.h


+ 81 - 0
Project/RTE/Device/AC78406HGLA/device_assert.h

@@ -0,0 +1,81 @@
+/* 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) 2021. 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 device_assert.h
+ *
+ * @brief  This file provides assert functions.
+ *
+ */ 
+ 
+#ifndef _DEVICE_ASSERT_H
+#define _DEVICE_ASSERT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* ===========================================  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  ======================================== */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _DEVICE_ASSERT_H */
+
+/* =============================================  EOF  ============================================== */

+ 58 - 0
Project/RTE/Device/AC78406HGLA/device_register.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) 2021. 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 device_register.h
+ *
+ * @brief  This file provides include the cpu specific register header files.
+ *
+ */
+
+#ifndef _DEVICE_REGISTER_H
+#define _DEVICE_REGISTER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "ac7840x.h"
+#include "device_assert.h"
+#include "ac7840x_features.h"
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _DEVICE_REGISTER_H */
+
+/* =============================================  EOF  ============================================== */

+ 120 - 0
Project/RTE/Device/AC78406HGLA/device_status.h

@@ -0,0 +1,120 @@
+/* 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) 2021. 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 device_status.h
+ *
+ * @brief This file provides all device status enum.
+ *
+ */ 
+ 
+#ifndef _DEVICE_STATUS_H
+#define _DEVICE_STATUS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+typedef enum
+{
+    /* Generic error codes */
+    STATUS_SUCCESS                         = 0x000U,    /*!< Generic operation success status */
+    STATUS_ERROR                           = 0x001U,    /*!< Generic operation failure status */
+    STATUS_BUSY                            = 0x002U,    /*!< Generic operation busy status */
+    STATUS_TIMEOUT                         = 0x003U,    /*!< Generic operation timeout status */
+    STATUS_UNSUPPORTED                     = 0x004U,    /*!< Generic operation unsupported status */
+    /* MCU specific error codes */
+    STATUS_MCU_GATED_OFF                   = 0x100U,    /*!< Module is gated off */
+    STATUS_MCU_TRANSITION_FAILED           = 0x101U,    /*!< Error occurs during transition. */
+    STATUS_MCU_INVALID_STATE               = 0x102U,    /*!< Unsupported in current state. */
+    STATUS_MCU_NOTIFY_BEFORE_ERROR         = 0x103U,    /*!< Error occurs during send "BEFORE" notification. */
+    STATUS_MCU_NOTIFY_AFTER_ERROR          = 0x104U,    /*!< Error occurs during send "AFTER" notification. */
+    /* I2C specific error codes */
+    STATUS_I2C_RECEIVED_NACK               = 0x200U,    /*!< NACK signal received  */
+    STATUS_I2C_TX_UNDERRUN                 = 0x201U,    /*!< TX underrun error */
+    STATUS_I2C_RX_OVERRUN                  = 0x202U,    /*!< RX overrun error */
+    STATUS_I2C_ARBITRATION_LOST            = 0x203U,    /*!< Arbitration lost */
+    STATUS_I2C_ABORTED                     = 0x204U,    /*!< A transfer was aborted */
+    STATUS_I2C_BUS_BUSY                    = 0x205U,    /*!< I2C bus is busy, cannot start transfer */
+    /* Security specific error codes */
+    STATUS_SEC_SEQUENCE_ERROR              = 0x402U,    /*!< The sequence of commands or subcommands is out of
+                                                             sequence */
+    STATUS_SEC_KEY_NOT_AVAILABLE           = 0x403U,    /*!< A key is locked due to failed boot measurement or
+                                                             an active debugger */
+    STATUS_SEC_KEY_INVALID                 = 0x404U,    /*!< A function is called to perform an operation with
+                                                             a key that is not allowed for the given operation */
+    STATUS_SEC_KEY_EMPTY                   = 0x405U,    /*!< Attempt to use a key that has not been initialized yet */
+    STATUS_SEC_NO_SECURE_BOOT              = 0x406U,    /*!< The conditions for a secure boot process are not met */
+    STATUS_SEC_KEY_WRITE_PROTECTED         = 0x407U,    /*!< Request for updating a write protected key slot,
+                                                             or activating debugger with write protected key(s) */
+    STATUS_SEC_KEY_UPDATE_ERROR            = 0x408U,    /*!< Key update did not succeed due to errors in
+                                                             verification of the messages */
+    STATUS_SEC_RNG_SEED                    = 0x409U,    /*!< Returned by CMD_RND and CMD_DEBUG if the seed has not
+                                                             been initialized before */
+    STATUS_SEC_NO_DEBUGGING                = 0x40AU,    /*!< DEBUG command authentication failed */
+    STATUS_SEC_MEMORY_FAILURE              = 0x40CU,    /*!< General memory technology failure
+                                                            (multibit ECC error, common fault detected) */
+    STATUS_SEC_HSM_INTERNAL_MEMORY_ERROR   = 0x410U,    /*!< An internal memory error encountered while
+                                                             executing the command */
+    STATUS_SEC_INVALID_COMMAND             = 0x411U,    /*!< Command value out of range */
+    STATUS_SEC_TRNG_ERROR                  = 0x412U,    /*!< One or more statistical tests run on the TRNG output failed */
+    STATUS_SEC_HSM_FLASH_BLOCK_ERROR       = 0x413U,    /*!< Error reading, programming or erasing one of the HSM flash blocks */
+    STATUS_SEC_INTERNAL_CMD_ERROR          = 0x414U,    /*!< An internal command processor error while executing a command */
+    STATUS_SEC_MAC_LENGTH_ERROR            = 0x415U,    /*!< MAC/Message length out of range */
+    STATUS_SEC_INVALID_ARG                 = 0x421U,    /*!< Invalid command argument */
+    STATUS_SEC_TRNG_CLOCK_ERROR            = 0x423U,    /*!< TRNG not provided with a stable clock */
+    /* SPI specific error codes */
+    STATUS_SPI_TX_UNDERRUN                 = 0x500U,    /*!< TX underrun error */
+    STATUS_SPI_RX_OVERRUN                  = 0x501U,    /*!< RX overrun error */
+    STATUS_SPI_ABORTED                     = 0x502U,    /*!< A transfer was aborted */
+    /* UART specific error codes */
+    STATUS_UART_TX_UNDERRUN                = 0x600U,    /*!< TX underrun error */
+    STATUS_UART_RX_OVERRUN                 = 0x601U,    /*!< RX overrun error */
+    STATUS_UART_ABORTED                    = 0x602U,    /*!< A transfer was aborted */
+    STATUS_UART_FRAMING_ERROR              = 0x603U,    /*!< Framing error */
+    STATUS_UART_PARITY_ERROR               = 0x604U,    /*!< Parity error */
+    STATUS_UART_BREAK_ERROR                = 0x605U,    /*!< Break error */
+    STATUS_UART_NOISE_ERROR                = 0x606U,    /*!< Noise error */
+    /* I2S specific error codes */
+    STATUS_I2S_TX_UNDERRUN                 = 0x700U,    /*!< TX underrun error */
+    STATUS_I2S_RX_OVERRUN                  = 0x701U,    /*!< RX overrun error */
+    STATUS_I2S_ABORTED                     = 0x702U,    /*!< A transfer was aborted */
+} status_t;
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _DEVICE_STATUS_H */
+
+/* =============================================  EOF  ============================================== */

+ 475 - 0
Project/RTE/Device/AC78406HGLA/startup_ac7840x.s

@@ -0,0 +1,475 @@
+;/* 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) 2021. 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 >>> ------------------
+;*/
+
+; Amount of memory (in bytes) allocated for Stack
+; Tailor this value to your application needs
+; <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     0x00000200
+
+                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     MemManage_Handler          ; MPU Fault Handler
+                DCD     BusFault_Handler           ; Bus Fault Handler
+                DCD     UsageFault_Handler         ; Usage Fault Handler
+                DCD     0                          ; Reserved
+                DCD     0                          ; Reserved
+                DCD     0                          ; Reserved
+                DCD     0                          ; Reserved
+                DCD     SVC_Handler                ; SVCall Handler
+                DCD     DebugMon_Handler           ; Debug Monitor Handler
+                DCD     0                          ; Reserved
+                DCD     PendSV_Handler             ; PendSV Handler
+                DCD     SysTick_Handler            ; SysTick Handler
+
+                ;External Interrupts
+                DCD     DMA0_Channel0_IRQHandler            ;DMA channel 0 transfer complete
+                DCD     DMA0_Channel1_IRQHandler            ;DMA channel 1 transfer complete
+                DCD     DMA0_Channel2_IRQHandler            ;DMA channel 2 transfer complete
+                DCD     DMA0_Channel3_IRQHandler            ;DMA channel 3 transfer complete
+                DCD     DMA0_Channel4_IRQHandler            ;DMA channel 4 transfer complete
+                DCD     DMA0_Channel5_IRQHandler            ;DMA channel 5 transfer complete
+                DCD     DMA0_Channel6_IRQHandler            ;DMA channel 6 transfer complete
+                DCD     DMA0_Channel7_IRQHandler            ;DMA channel 7 transfer complete
+                DCD     DMA0_Channel8_IRQHandler            ;DMA channel 8 transfer complete
+                DCD     DMA0_Channel9_IRQHandler            ;DMA channel 9 transfer complete
+                DCD     DMA0_Channel10_IRQHandler           ;DMA channel 10 transfer complete
+                DCD     DMA0_Channel11_IRQHandler           ;DMA channel 11 transfer complete
+                DCD     DMA0_Channel12_IRQHandler           ;DMA channel 12 transfer complete
+                DCD     DMA0_Channel13_IRQHandler           ;DMA channel 13 transfer complete
+                DCD     DMA0_Channel14_IRQHandler           ;DMA channel 14 transfer complete
+                DCD     DMA0_Channel15_IRQHandler           ;DMA channel 15 transfer complete
+                DCD     PORTA_IRQHandler                    ;Port A pin detect interrupt
+                DCD     PORTB_IRQHandler                    ;Port B pin detect interrupt
+                DCD     PORTC_IRQHandler                    ;Port C pin detect interrupt
+                DCD     PORTD_IRQHandler                    ;Port D pin detect interrupt
+                DCD     PORTE_IRQHandler                    ;Port E pin detect interrupt
+                DCD     UART0_IRQHandler                    ;UART0 Transmit / Receive Interrupt
+                DCD     UART1_IRQHandler                    ;UART1 Transmit / Receive Interrupt
+                DCD     UART2_IRQHandler                    ;UART2 Transmit / Receive Interrupt
+                DCD     UART3_IRQHandler                    ;UART3 Transmit / Receive Interrupt
+                DCD     0                                   ;Reserved
+                DCD     0                                   ;Reserved
+                DCD     SPI0_IRQHandler                     ;SPI0 Interrupt
+                DCD     SPI1_IRQHandler                     ;SPI1 Interrupt
+                DCD     SPI2_IRQHandler                     ;SPI2 Interrupt
+                DCD     0                                   ;Reserved
+                DCD     I2C0_IRQHandler                     ;I2C0 Interrupt
+                DCD     0                                   ;Reserved
+                DCD     EIO_IRQHandler                      ;EIO Interrupt
+                DCD     CAN0_IRQHandler                     ;CAN0 Interrupt
+                DCD     CAN0_Wakeup_IRQHandler              ;CAN0 Wakeup Interrupt
+                DCD     CAN1_IRQHandler                     ;CAN1 Interrupt
+                DCD     CAN1_Wakeup_IRQHandler              ;CAN1 Wakeup Interrupt
+                DCD     CAN2_IRQHandler                     ;CAN2 Interrupt
+                DCD     CAN2_Wakeup_IRQHandler              ;CAN2 Wakeup Interrupt
+                DCD     CAN3_IRQHandler                     ;CAN3 Interrupt
+                DCD     CAN3_Wakeup_IRQHandler              ;CAN3 Wakeup Interrupt
+                DCD     0                                   ;Reserved
+                DCD     0                                   ;Reserved
+                DCD     0                                   ;Reserved
+                DCD     0                                   ;Reserved
+                DCD     PDT0_IRQHandler                     ;PDT0 Interrupt
+                DCD     PDT1_IRQHandler                     ;PDT1 Interrupt
+                DCD     ADC0_IRQHandler                     ;ADC0 Interrupt
+                DCD     ADC1_IRQHandler                     ;ADC1 Interrupt
+                DCD     ACMP0_IRQHandler                    ;ACMP0 Interrupt
+                DCD     WDG_IRQHandler                      ;WDG Interrupt
+                DCD     EWDG_IRQHandler                     ;EWDG Interrupt
+                DCD     MCM_IRQHandler                      ;MCM Interrupt
+                DCD     LVD_IRQHandler                      ;LVD Interrupt
+                DCD     SPM_IRQHandler                      ;SPM Interrupt
+                DCD     RCM_IRQHandler                      ;RCM Interrupt
+                DCD     PWM0_Overflow_IRQHandler            ;PWM0 Overflow Interrupt
+                DCD     PWM0_Channel_IRQHandler             ;PWM0 Channel Interrupt
+                DCD     PWM0_Fault_IRQHandler               ;PWM0 Fault Interrupt
+                DCD     PWM1_Overflow_IRQHandler            ;PWM1 Overflow Interrupt
+                DCD     PWM1_Channel_IRQHandler             ;PWM1 Channel Interrupt
+                DCD     PWM1_Fault_IRQHandler               ;PWM1 Fault Interrupt
+                DCD     PWM2_Overflow_IRQHandler            ;PWM2 Overflow Interrupt
+                DCD     PWM2_Channel_IRQHandler             ;PWM2 Channel Interrupt
+                DCD     PWM2_Fault_IRQHandler               ;PWM2 Fault Interrupt
+                DCD     PWM3_Overflow_IRQHandler            ;PWM3 Overflow Interrupt
+                DCD     PWM3_Channel_IRQHandler             ;PWM3 Channel Interrupt
+                DCD     PWM3_Fault_IRQHandler               ;PWM3 Fault Interrupt
+                DCD     PWM4_Overflow_IRQHandler            ;PWM4 Overflow Interrupt
+                DCD     PWM4_Channel_IRQHandler             ;PWM4 Channel Interrupt
+                DCD     PWM4_Fault_IRQHandler               ;PWM4 Fault Interrupt
+                DCD     PWM5_Overflow_IRQHandler            ;PWM5 Overflow Interrupt
+                DCD     PWM5_Channel_IRQHandler             ;PWM5 Channel Interrupt
+                DCD     PWM5_Fault_IRQHandler               ;PWM5 Fault Interrupt
+                DCD     0                                   ;Reserved
+                DCD     0                                   ;Reserved
+                DCD     0                                   ;Reserved
+                DCD     0                                   ;Reserved
+                DCD     0                                   ;Reserved
+                DCD     0                                   ;Reserved
+                DCD     RTC_IRQHandler                      ;RTC Interrupt
+                DCD     PCT_IRQHandler                      ;PCT Interrupt
+                DCD     TIMER_Channel0_IRQHandler           ;TIMER Channel0 Interrupt
+                DCD     TIMER_Channel1_IRQHandler           ;TIMER Channel1 Interrupt
+                DCD     TIMER_Channel2_IRQHandler           ;TIMER Channel2 Interrupt
+                DCD     TIMER_Channel3_IRQHandler           ;TIMER Channel3 Interrupt
+                DCD     CSE_IRQHandler                      ;CSE Interrupt
+                DCD     FLASH_ECC_IRQHandler                ;Flash ECC Interrupt
+                DCD     FLASH_IRQHandler                    ;Flash Interrupt
+                DCD     FLASH_Collision_IRQHandler          ;Flash Collision Interrupt
+                DCD     ECC_1BIT_IRQHandler                 ;ECC 1BIT Interrupt
+                DCD     ECC_2BIT_IRQHandler                 ;ECC 2BIT Interrupt
+
+__Vectors_End
+
+__Vectors_Size  EQU  __Vectors_End - __Vectors
+
+                AREA    |.text|, CODE, READONLY
+
+; Reset handler
+Reset_Handler    PROC
+                 EXPORT  Reset_Handler             [WEAK]
+                 CPSID   I              ; Mask interrupts
+
+                 IF      :DEF:NOT_INIT_SRAM_AFTER_RESET
+                 ; Check reset status, if there is any reset except power on and lvr, don't init SRAM
+                 LDR     R0, =0x4000001C
+                 LDR     R1, [R0]
+                 AND     R1, R1, #0x30000
+                 CMP     R1, #0x00000
+                 BEQ     ECC_INIT_END0
+                 ENDIF
+
+                 ; Init ECC SRAM
+                 LDR     R1, =0x1FFF0000
+                 LDR     R2, =0x2000F000
+                 SUBS    R2, R1
+                 SUBS    R2, #1
+                 BLE     ECC_INIT_END0
+
+                 MOVS    R0, #0
+                 MOVS    R3, #4
+LOOP0
+                 STR     R0, [R1]
+                 ADD     R1, R1, R3
+                 SUBS    R2, #4
+                 BGE     LOOP0
+ECC_INIT_END0
+                 IMPORT  SystemInit
+                 IMPORT  __main
+
+                 LDR     R0, =SystemInit
+                 BLX     R0
+
+                 IF      :DEF:NOT_INIT_SRAM_AFTER_RESET
+                 ; Clear reset status
+                 LDR     R0, =0x4000001C
+                 LDR     R1, =0x80000000
+                 STR     R1, [R0]
+                 ENDIF
+
+                 CPSIE   I              ; Unmask interrupts
+                 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
+MemManage_Handler\
+                PROC
+                EXPORT  MemManage_Handler                 [WEAK]
+                B       .
+                ENDP
+BusFault_Handler\
+                PROC
+                EXPORT  BusFault_Handler                  [WEAK]
+                B       .
+                ENDP
+UsageFault_Handler\
+                PROC
+                EXPORT  UsageFault_Handler                [WEAK]
+                B       .
+                ENDP
+SVC_Handler     PROC
+                EXPORT  SVC_Handler                       [WEAK]
+                B       .
+                ENDP
+DebugMon_Handler\
+                PROC
+                EXPORT  DebugMon_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  DMA0_Channel0_IRQHandler          [WEAK]
+                EXPORT  DMA0_Channel1_IRQHandler          [WEAK]
+                EXPORT  DMA0_Channel2_IRQHandler          [WEAK]
+                EXPORT  DMA0_Channel3_IRQHandler          [WEAK]
+                EXPORT  DMA0_Channel4_IRQHandler          [WEAK]
+                EXPORT  DMA0_Channel5_IRQHandler          [WEAK]
+                EXPORT  DMA0_Channel6_IRQHandler          [WEAK]
+                EXPORT  DMA0_Channel7_IRQHandler          [WEAK]
+                EXPORT  DMA0_Channel8_IRQHandler          [WEAK]
+                EXPORT  DMA0_Channel9_IRQHandler          [WEAK]
+                EXPORT  DMA0_Channel10_IRQHandler         [WEAK]
+                EXPORT  DMA0_Channel11_IRQHandler         [WEAK]
+                EXPORT  DMA0_Channel12_IRQHandler         [WEAK]
+                EXPORT  DMA0_Channel13_IRQHandler         [WEAK]
+                EXPORT  DMA0_Channel14_IRQHandler         [WEAK]
+                EXPORT  DMA0_Channel15_IRQHandler         [WEAK]
+                EXPORT  PORTA_IRQHandler                  [WEAK]
+                EXPORT  PORTB_IRQHandler                  [WEAK]
+                EXPORT  PORTC_IRQHandler                  [WEAK]
+                EXPORT  PORTD_IRQHandler                  [WEAK]
+                EXPORT  PORTE_IRQHandler                  [WEAK]
+                EXPORT  UART0_IRQHandler                  [WEAK]
+                EXPORT  UART1_IRQHandler                  [WEAK]
+                EXPORT  UART2_IRQHandler                  [WEAK]
+                EXPORT  UART3_IRQHandler                  [WEAK]
+                EXPORT  SPI0_IRQHandler                   [WEAK]
+                EXPORT  SPI1_IRQHandler                   [WEAK]
+                EXPORT  SPI2_IRQHandler                   [WEAK]
+                EXPORT  I2C0_IRQHandler                   [WEAK]
+                EXPORT  EIO_IRQHandler                    [WEAK]
+                EXPORT  CAN0_IRQHandler                   [WEAK]
+                EXPORT  CAN0_Wakeup_IRQHandler            [WEAK]
+                EXPORT  CAN1_IRQHandler                   [WEAK]
+                EXPORT  CAN1_Wakeup_IRQHandler            [WEAK]
+                EXPORT  CAN2_IRQHandler                   [WEAK]
+                EXPORT  CAN2_Wakeup_IRQHandler            [WEAK]
+                EXPORT  CAN3_IRQHandler                   [WEAK]
+                EXPORT  CAN3_Wakeup_IRQHandler            [WEAK]
+                EXPORT  PDT0_IRQHandler                   [WEAK]
+                EXPORT  PDT1_IRQHandler                   [WEAK]
+                EXPORT  ADC0_IRQHandler                   [WEAK]
+                EXPORT  ADC1_IRQHandler                   [WEAK]
+                EXPORT  ACMP0_IRQHandler                  [WEAK]
+                EXPORT  WDG_IRQHandler                    [WEAK]
+                EXPORT  EWDG_IRQHandler                   [WEAK]
+                EXPORT  MCM_IRQHandler                    [WEAK]
+                EXPORT  LVD_IRQHandler                    [WEAK]
+                EXPORT  SPM_IRQHandler                    [WEAK]
+                EXPORT  RCM_IRQHandler                    [WEAK]
+                EXPORT  PWM0_Overflow_IRQHandler          [WEAK]
+                EXPORT  PWM0_Channel_IRQHandler           [WEAK]
+                EXPORT  PWM0_Fault_IRQHandler             [WEAK]
+                EXPORT  PWM1_Overflow_IRQHandler          [WEAK]
+                EXPORT  PWM1_Channel_IRQHandler           [WEAK]
+                EXPORT  PWM1_Fault_IRQHandler             [WEAK]
+                EXPORT  PWM2_Overflow_IRQHandler          [WEAK]
+                EXPORT  PWM2_Channel_IRQHandler           [WEAK]
+                EXPORT  PWM2_Fault_IRQHandler             [WEAK]
+                EXPORT  PWM3_Overflow_IRQHandler          [WEAK]
+                EXPORT  PWM3_Channel_IRQHandler           [WEAK]
+                EXPORT  PWM3_Fault_IRQHandler             [WEAK]
+                EXPORT  PWM4_Overflow_IRQHandler          [WEAK]
+                EXPORT  PWM4_Channel_IRQHandler           [WEAK]
+                EXPORT  PWM4_Fault_IRQHandler             [WEAK]
+                EXPORT  PWM5_Overflow_IRQHandler          [WEAK]
+                EXPORT  PWM5_Channel_IRQHandler           [WEAK]
+                EXPORT  PWM5_Fault_IRQHandler             [WEAK]
+                EXPORT  RTC_IRQHandler                    [WEAK]
+                EXPORT  PCT_IRQHandler                    [WEAK]
+                EXPORT  TIMER_Channel0_IRQHandler         [WEAK]
+                EXPORT  TIMER_Channel1_IRQHandler         [WEAK]
+                EXPORT  TIMER_Channel2_IRQHandler         [WEAK]
+                EXPORT  TIMER_Channel3_IRQHandler         [WEAK]
+                EXPORT  CSE_IRQHandler                    [WEAK]
+                EXPORT  FLASH_ECC_IRQHandler              [WEAK]
+                EXPORT  FLASH_IRQHandler                  [WEAK]
+                EXPORT  FLASH_Collision_IRQHandler        [WEAK]
+                EXPORT  ECC_1BIT_IRQHandler               [WEAK]
+                EXPORT  ECC_2BIT_IRQHandler               [WEAK]
+DMA0_Channel0_IRQHandler
+DMA0_Channel1_IRQHandler
+DMA0_Channel2_IRQHandler
+DMA0_Channel3_IRQHandler
+DMA0_Channel4_IRQHandler
+DMA0_Channel5_IRQHandler
+DMA0_Channel6_IRQHandler
+DMA0_Channel7_IRQHandler
+DMA0_Channel8_IRQHandler
+DMA0_Channel9_IRQHandler
+DMA0_Channel10_IRQHandler
+DMA0_Channel11_IRQHandler
+DMA0_Channel12_IRQHandler
+DMA0_Channel13_IRQHandler
+DMA0_Channel14_IRQHandler
+DMA0_Channel15_IRQHandler
+PORTA_IRQHandler
+PORTB_IRQHandler
+PORTC_IRQHandler
+PORTD_IRQHandler
+PORTE_IRQHandler
+UART0_IRQHandler
+UART1_IRQHandler
+UART2_IRQHandler
+UART3_IRQHandler
+SPI0_IRQHandler
+SPI1_IRQHandler
+SPI2_IRQHandler
+I2C0_IRQHandler
+EIO_IRQHandler
+CAN0_IRQHandler
+CAN0_Wakeup_IRQHandler
+CAN1_IRQHandler
+CAN1_Wakeup_IRQHandler
+CAN2_IRQHandler
+CAN2_Wakeup_IRQHandler
+CAN3_IRQHandler
+CAN3_Wakeup_IRQHandler
+PDT0_IRQHandler
+PDT1_IRQHandler
+ADC0_IRQHandler
+ADC1_IRQHandler
+ACMP0_IRQHandler
+WDG_IRQHandler
+EWDG_IRQHandler
+MCM_IRQHandler
+LVD_IRQHandler
+SPM_IRQHandler
+RCM_IRQHandler
+PWM0_Overflow_IRQHandler
+PWM0_Channel_IRQHandler
+PWM0_Fault_IRQHandler
+PWM1_Overflow_IRQHandler
+PWM1_Channel_IRQHandler
+PWM1_Fault_IRQHandler
+PWM2_Overflow_IRQHandler
+PWM2_Channel_IRQHandler
+PWM2_Fault_IRQHandler
+PWM3_Overflow_IRQHandler
+PWM3_Channel_IRQHandler
+PWM3_Fault_IRQHandler
+PWM4_Overflow_IRQHandler
+PWM4_Channel_IRQHandler
+PWM4_Fault_IRQHandler
+PWM5_Overflow_IRQHandler
+PWM5_Channel_IRQHandler
+PWM5_Fault_IRQHandler
+RTC_IRQHandler
+PCT_IRQHandler
+TIMER_Channel0_IRQHandler
+TIMER_Channel1_IRQHandler
+TIMER_Channel2_IRQHandler
+TIMER_Channel3_IRQHandler
+CSE_IRQHandler
+FLASH_ECC_IRQHandler
+FLASH_IRQHandler
+FLASH_Collision_IRQHandler
+ECC_1BIT_IRQHandler
+ECC_2BIT_IRQHandler
+
+                B       .
+
+                ENDP
+
+                ALIGN
+
+;*******************************************************************************
+; User Stack and Heap initialization
+;*******************************************************************************
+                 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
+
+                 LDR     R0, =  Heap_Mem
+                 LDR     R1, =(Stack_Mem + Stack_Size)
+                 LDR     R2, = (Heap_Mem +  Heap_Size)
+                 LDR     R3, = Stack_Mem
+                 BX      LR
+
+                 ALIGN
+
+                 ENDIF
+
+                 END
+
+;****************END OF FILE******************************************

+ 563 - 0
Project/RTE/Device/AC78406HGLA/system_ac7840x.c

@@ -0,0 +1,563 @@
+/* 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) 2021. 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_ac7840x.c
+ *
+ * @brief This file provides system clock config integration functions.
+ *
+ */
+
+/* ===========================================  Includes  =========================================== */
+#include "device_register.h"
+#if SYSTEM_USE_CKGEN
+#include "ckgen_drv.h"
+#endif
+
+/* ============================================  Define  ============================================ */
+
+/* ===========================================  Typedef  ============================================ */
+
+/* ==========================================  Variables  =========================================== */
+uint32_t SystemCoreClock = DEFAULT_SYSTEM_CLOCK;  /* System/core clock */
+
+/* ====================================  Functions declaration  ===================================== */
+/* Externals declaration */
+#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
+extern uint32_t __Vectors;
+#endif
+
+/* ======================================  Functions define  ======================================== */
+/*!
+ * @brief Initialize SPLL then set system clock to the SPLL clock
+ *        (just support SPLL refer clock 4/8/12/16/30MHz, others need to modify).
+ *
+ * @param[in] refClk: 0: HSI clock, 1: HSE clock
+ * @param[in] freq: SPLL out frequency (16 - 120)
+ * @return status 0: success others: error
+ */
+uint32_t SetSysClkToSPLL(uint8_t refClk, uint8_t freq)
+{
+    uint32_t ret = 0U, status, outFreq = freq;
+    uint32_t timeout = 100000U, posdiv, fbkdiv, prediv;
+
+    if (outFreq > 120U)
+    {
+        outFreq = 120U;
+    }
+    if (outFreq < 16U)
+    {
+        outFreq = 16U;
+    }
+
+    if (refClk != 0U)
+    {
+        /* Set XOSC bypass mode */
+        MODIFY_REG32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_XOSC_HSEBYP_Msk, SPM_PWR_MGR_CFG1_XOSC_HSEBYP_Pos, 0U);
+        /* XOSC enable */
+        SET_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_XOSC_HSEEN_Msk);
+        do
+        {
+            status = READ_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_XOSC_RDY_Msk);
+        } while ((0U == status) && (--timeout != 0U));
+        if (0U == timeout)
+        {
+            ret = 1U;
+        }
+
+        /* SPLL configuration outFreq = (srcFreq / (prediv + 1)) * fbkdiv / (posdiv * 2) */
+        #if (CKGEN_HSE_FREQ == 30000000U)  /* For HSE frequency 30MHz */
+        if (outFreq == 120U)
+        {
+            posdiv = 5U;
+            fbkdiv = 160U;
+        }
+        else if (outFreq == 96U)
+        {
+            posdiv = 5U;
+            fbkdiv = 128U;
+        }
+        else if (outFreq == 80U)
+        {
+            posdiv = 6U;
+            fbkdiv = 128U;
+        }
+        else  /* Output frequency 48MHz */
+        {
+            posdiv = 10U;
+            fbkdiv = 128U;
+            outFreq = 48U;
+        }
+        prediv = 3U;
+        #elif (CKGEN_HSE_FREQ == 16000000U)  /* For HSE frequency 16MHz */
+        if (outFreq > 64U)
+        {
+            posdiv = 4U;
+            fbkdiv = outFreq;
+        }
+        else if (outFreq > 32U)
+        {
+            posdiv = 8U;
+            fbkdiv = outFreq * 2U;
+        }
+        else
+        {
+            posdiv = 16U;
+            fbkdiv = outFreq * 4U;
+        }
+        prediv = 1U;
+        #elif (CKGEN_HSE_FREQ == 12000000U)  /* For HSE frequency 12MHz */
+        if (outFreq > 62U)
+        {
+            posdiv = 6U;
+            fbkdiv = outFreq;
+        }
+        else if (outFreq > 31U)
+        {
+            posdiv = 12U;
+            fbkdiv = outFreq * 2U;
+        }
+        else
+        {
+            posdiv = 24U;
+            fbkdiv = outFreq * 4U;
+        }
+        prediv = 0U;
+        #elif (CKGEN_HSE_FREQ == 4000000U)  /* For HSE frequency 4MHz */
+        if (outFreq > 64U)
+        {
+            posdiv = 4U;
+            fbkdiv = outFreq * 2;
+        }
+        else if (outFreq > 32U)
+        {
+            posdiv = 8U;
+            fbkdiv = outFreq * 4U;
+        }
+        else
+        {
+            posdiv = 16U;
+            fbkdiv = outFreq * 8U;
+        }
+        prediv = 0U;
+        #else  /* For default HSE 8MHz */
+        if (outFreq > 64U)
+        {
+            posdiv = 4U;
+            fbkdiv = outFreq;
+        }
+        else if (outFreq > 32U)
+        {
+            posdiv = 8U;
+            fbkdiv = outFreq * 2U;
+        }
+        else
+        {
+            posdiv = 16U;
+            fbkdiv = outFreq * 4U;
+        }
+        prediv = 0U;
+        #endif
+    }
+    else
+    {
+        /* HSI enable */
+        SET_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_HSI_EN_NORMAL_Msk);
+        timeout = 1000U;
+        do
+        {
+            status = READ_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_HSI_RDY_Msk);
+        } while ((0U == status) && (--timeout != 0U));
+        if (0U == timeout)
+        {
+            ret = 2U;
+        }
+
+        /* For HSI 8MHz */
+        if (outFreq > 64U)
+        {
+            posdiv = 4U;
+            fbkdiv = outFreq;
+        }
+        else if (outFreq > 32U)
+        {
+            posdiv = 8U;
+            fbkdiv = outFreq * 2U;
+        }
+        else
+        {
+            posdiv = 16U;
+            fbkdiv = outFreq * 4U;
+        }
+        prediv = 0U;
+    }
+
+    if (0U == ret)
+    {
+        CLEAR_BIT32(CKGEN->CTRL, CKGEN_CTRL_LOCK_Msk);
+        /* Configure SPLL */
+        if (refClk != 0U)
+        {
+            SET_BIT32(CKGEN->CTRL, CKGEN_CTRL_PLL_REF_SEL_Msk);
+        }
+        else
+        {
+            CLEAR_BIT32(CKGEN->CTRL, CKGEN_CTRL_PLL_REF_SEL_Msk);
+        }
+        MODIFY_REG32(ANA->SPLL_CFG0, ANA_SPLL_CFG0_POSDIV_Msk, ANA_SPLL_CFG0_POSDIV_Pos, posdiv);
+        MODIFY_REG32(ANA->SPLL_CFG0, ANA_SPLL_CFG0_FBKDIV_Msk, ANA_SPLL_CFG0_FBKDIV_Pos, fbkdiv);
+        MODIFY_REG32(ANA->SPLL_CFG0, ANA_SPLL_CFG0_PREDIV_Msk, ANA_SPLL_CFG0_PREDIV_Pos, prediv);
+        MODIFY_REG32(ANA->SPLL_CFG1, ANA_SPLL_CFG1_LD_DLY_SEL_Msk, ANA_SPLL_CFG1_LD_DLY_SEL_Pos, 3U);
+        /* SPLL enable */
+        SET_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_SPLL_EN_Msk);
+        timeout = 10000U;
+        do
+        {
+            status = READ_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_SPLL_RDY_Msk);
+        } while ((0U == status) && (--timeout != 0U));
+        if (0U == timeout)
+        {
+            ret = 3U;
+        }
+    }
+
+    if (0U == ret)
+    {
+        /* Unlock and set flash clock frequency */
+        WRITE_REG32(FLASH->KEYUNLK, FLASH_UNLOCK_KEY1);
+        WRITE_REG32(FLASH->KEYUNLK, FLASH_UNLOCK_KEY2);
+        MODIFY_REG32(FLASH->CNFG, FLASH_CNFG_CLKFREQ_Msk, FLASH_CNFG_CLKFREQ_Pos, outFreq);
+        /* Switch system clock to spll */
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Msk, CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Pos, 3U);
+        /* Set divider, default sysdiv is 1 divider and busdiv is 2 divider */
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_SYSCLK_DIV_Msk, CKGEN_CTRL_SYSCLK_DIV_Pos, 0U);
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_BUS_CLK_DIV_RUN_Msk, CKGEN_CTRL_BUS_CLK_DIV_RUN_Pos, 1U);
+        /* Check current system clock */
+        if (3U != ((CKGEN->CTRL & CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Msk) >> CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Pos))
+        {
+            ret = 4U;
+        }
+    }
+
+    return ret;
+}
+
+/*!
+ * @brief Initialize VHSI then set system clock to the VHSI clock.
+ *
+ * @param[in] none
+ * @return status 0: success others: error
+ */
+uint32_t SetSysClkToVHSI(void)
+{
+    uint32_t ret = 0U, status, timeout = 100U;
+
+    /* VHSI enable */
+    SET_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_VHSI_EN_Msk);
+    do
+    {
+        status = READ_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_VHSI_RDY_Msk);
+    } while ((0U == status) && (--timeout != 0U));
+    if (0U == timeout)
+    {
+        ret = 1U;
+    }
+
+    if (0U == ret)
+    {
+        CLEAR_BIT32(CKGEN->CTRL, CKGEN_CTRL_LOCK_Msk);
+        /* Unlock and set flash clock frequency */
+        WRITE_REG32(FLASH->KEYUNLK, FLASH_UNLOCK_KEY1);
+        WRITE_REG32(FLASH->KEYUNLK, FLASH_UNLOCK_KEY2);
+        MODIFY_REG32(FLASH->CNFG, FLASH_CNFG_CLKFREQ_Msk, FLASH_CNFG_CLKFREQ_Pos, 48U);
+        /* Switch system clock to vhsi */
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Msk, CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Pos, 0U);
+        /* Set divider, default sysdiv is 1 divider and busdiv is 2 divider */
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_SYSCLK_DIV_Msk, CKGEN_CTRL_SYSCLK_DIV_Pos, 0U);
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_BUS_CLK_DIV_RUN_Msk, CKGEN_CTRL_BUS_CLK_DIV_RUN_Pos, 1U);
+        /* Check current system clock */
+        if (0U != ((CKGEN->CTRL & CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Msk) >> CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Pos))
+        {
+            ret = 2U;
+        }
+    }
+
+    return ret;
+}
+
+/*!
+ * @brief Initialize HSE then set system clock to the HSE clock.
+ *
+ * @param[in] bypass: 0: disable, 1: enable
+ * @return status 0: success others: error
+ */
+uint32_t SetSysClkToHSE(uint8_t bypass)
+{
+    uint32_t ret = 0U, status, timeout = 100000U;
+
+    /* Set XOSC bypass mode */
+    if (bypass != 0U)
+    {
+        SET_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_XOSC_HSEBYP_Msk);
+    }
+    else
+    {
+        CLEAR_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_XOSC_HSEBYP_Msk);
+    }
+    /* XOSC enable */
+    SET_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_XOSC_HSEEN_Msk);
+    do
+    {
+        status = READ_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_XOSC_RDY_Msk);
+    } while ((0U == status) && (--timeout != 0U));
+    if (0U == timeout)
+    {
+        ret = 1U;
+    }
+
+    if (0U == ret)
+    {
+        CLEAR_BIT32(CKGEN->CTRL, CKGEN_CTRL_LOCK_Msk);
+        /* Unlock and set flash clock frequency */
+        WRITE_REG32(FLASH->KEYUNLK, FLASH_UNLOCK_KEY1);
+        WRITE_REG32(FLASH->KEYUNLK, FLASH_UNLOCK_KEY2);
+        MODIFY_REG32(FLASH->CNFG, FLASH_CNFG_CLKFREQ_Msk, FLASH_CNFG_CLKFREQ_Pos, CKGEN_HSE_FREQ / 1000000U);
+        /* Switch system clock to hse */
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Msk, CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Pos, 1U);
+        /* Set divider, default sysdiv is 1 divider and busdiv is 2 divider */
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_SYSCLK_DIV_Msk, CKGEN_CTRL_SYSCLK_DIV_Pos, 0U);
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_BUS_CLK_DIV_RUN_Msk, CKGEN_CTRL_BUS_CLK_DIV_RUN_Pos, 1U);
+        /* Check current system clock */
+        if (1U != ((CKGEN->CTRL & CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Msk) >> CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Pos))
+        {
+            ret = 2U;
+        }
+    }
+
+    return ret;
+}
+
+/*!
+ * @brief Initialize HSI then set system clock to the HSI clock.
+ *
+ * @param[in] none
+ * @return status 0: success others: error
+ */
+uint32_t SetSysClkToHSI(void)
+{
+    uint32_t ret = 0U, status, timeout = 100U;
+
+    /* HSI enable */
+    SET_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_HSI_EN_NORMAL_Msk);
+    do
+    {
+        status = READ_BIT32(SPM->PWR_MGR_CFG1, SPM_PWR_MGR_CFG1_HSI_RDY_Msk);
+    } while ((0U == status) && (--timeout != 0U));
+    if (0U == timeout)
+    {
+        ret = 1U;
+    }
+
+    if (0U == ret)
+    {
+        CLEAR_BIT32(CKGEN->CTRL, CKGEN_CTRL_LOCK_Msk);
+        /* Unlock and set flash clock frequency */
+        WRITE_REG32(FLASH->KEYUNLK, FLASH_UNLOCK_KEY1);
+        WRITE_REG32(FLASH->KEYUNLK, FLASH_UNLOCK_KEY2);
+        MODIFY_REG32(FLASH->CNFG, FLASH_CNFG_CLKFREQ_Msk, FLASH_CNFG_CLKFREQ_Pos, 8U);
+        /* Switch system clock to hsi */
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Msk, CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Pos, 2U);
+        /* Set divider, default sysdiv is 1 divider and busdiv is 2 divider */
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_SYSCLK_DIV_Msk, CKGEN_CTRL_SYSCLK_DIV_Pos, 0U);
+        MODIFY_REG32(CKGEN->CTRL, CKGEN_CTRL_BUS_CLK_DIV_RUN_Msk, CKGEN_CTRL_BUS_CLK_DIV_RUN_Pos, 1U);
+        /* Check current system clock */
+        if (2U != ((CKGEN->CTRL & CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Msk) >> CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Pos))
+        {
+            ret = 2U;
+        }
+    }
+
+    return ret;
+}
+
+/*!
+ * @brief Get MCU CPUID.
+ *
+ * @param[in] none
+ * @return MCU CPUID
+ */
+uint32_t GetCPUID(void)
+{
+    return SCB->CPUID;
+}
+
+/*!
+ * @brief Get UUID from device.
+ *
+ * @param[out] uuidBuffer: UUID buffer
+ * @return none
+ */
+void GetUUID(uint32_t *uuidBuffer)
+{
+#define UUID_BASE_ADDRESS  0x00201800U
+
+    uint32_t i;
+
+    if (uuidBuffer != NULL)
+    {
+        for (i = 0U; i < 4U; i++)
+        {
+            uuidBuffer[i] = (*(__IO uint32_t *)(UUID_BASE_ADDRESS + i * 4U));
+        }
+    }
+}
+
+/*!
+ * @brief Setup the microcontroller system. Initialize the System.
+ *
+ * @param[in] none
+ * @return none
+ */
+void SystemInit(void)
+{
+    /* Sram L&U ECC read enable */
+#if (SRAM_ECC_READ_ENABLE)
+    MCM->MLMDR0 |= MCM_MLMDR0_LREEN_Msk | MCM_MLMDR0_UREEN_Msk;
+    /* Sram ECC 2bit error reset disable */
+#if !(SRAM_ECC_ERR_RST_ENABLE)
+    CKGEN->RCM_EN &= ~CKGEN_RCM_EN_ECC2_ERR_RST_EN_Msk;
+#endif
+#endif
+
+    /* Set CP10 and CP11 Full Access */
+#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
+    SCB->CPACR |= ((3U << (10U * 2U)) | (3U << (11U * 2U)));
+#endif
+
+    /* Disable watchdog */
+#if (WDG_DISABLE)
+#define WDG_UNLOCK_VALUE1      0xE064D987U
+#define WDG_UNLOCK_VALUE2      0x868A8478U
+    WDG->CNT = (uint32_t)WDG_UNLOCK_VALUE1;
+    WDG->CNT = (uint32_t)WDG_UNLOCK_VALUE2;
+    WDG->CS0 &= ~WDG_CS0_EN_Msk;
+#endif
+
+    /* Relocate vector table */
+#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
+    SCB->VTOR = (uint32_t) &__Vectors;
+#endif
+}
+
+/*!
+ * @brief Update system clock frequence.
+ *
+ * @param[in] none
+ * @return none
+ */
+void SystemCoreClockUpdate(void)
+{
+#if SYSTEM_USE_CKGEN
+    (void)CKGEN_DRV_GetFreq(CORE_CLK, &SystemCoreClock);
+#else
+    uint32_t runMode, clkSrc, sysDiv, prediv, fbkdiv, postdiv, srcFreq;
+
+    runMode = SPM->STATUS & SPM_STATUS_CURR_POWER_MODE_Msk;
+    if (1U == runMode)  /* VLPR mode */
+    {
+        sysDiv = (CKGEN->CTRL & CKGEN_CTRL_SYSCLK_DIV_VLPR_Msk) >> CKGEN_CTRL_SYSCLK_DIV_VLPR_Pos;
+        srcFreq = CKGEN_HSI_FREQ;
+    }
+    else  /* RUN mode */
+    {
+        sysDiv = (CKGEN->CTRL & CKGEN_CTRL_SYSCLK_DIV_Msk) >> CKGEN_CTRL_SYSCLK_DIV_Pos;
+        clkSrc = (CKGEN->CTRL & CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Msk) >> CKGEN_CTRL_SYSCLK_SRC_SEL_RUN_Pos;
+        switch (clkSrc)
+        {
+        case 1U:  /* HSE clock, user define */
+            srcFreq = CKGEN_HSE_FREQ;
+            break;
+
+        case 2U:  /* HSI clock */
+            srcFreq = CKGEN_HSI_FREQ;
+            break;
+
+        case 3U:  /* SPLL clock */
+            prediv = (ANA->SPLL_CFG0 & ANA_SPLL_CFG0_PREDIV_Msk) >> ANA_SPLL_CFG0_PREDIV_Pos;
+            fbkdiv = (ANA->SPLL_CFG0 & ANA_SPLL_CFG0_FBKDIV_Msk) >> ANA_SPLL_CFG0_FBKDIV_Pos;
+            postdiv = (ANA->SPLL_CFG0 & ANA_SPLL_CFG0_POSDIV_Msk) >> ANA_SPLL_CFG0_POSDIV_Pos;
+            /* Get reference clock */
+            if (0U == ((CKGEN->CTRL & CKGEN_CTRL_PLL_REF_SEL_Msk) >> CKGEN_CTRL_PLL_REF_SEL_Pos))
+            {
+                srcFreq = CKGEN_HSI_FREQ;
+            }
+            else
+            {
+                srcFreq = CKGEN_HSE_FREQ;
+            }
+            /* Calculate SPLL frequency */
+            if (postdiv != 0U)
+            {
+                srcFreq = (srcFreq / (prediv + 1U)) * fbkdiv / (postdiv * 2U);
+            }
+            break;
+
+        default:  /* VHSI clock */
+            srcFreq = CKGEN_VHSI_FREQ;
+            break;
+        }
+    }
+
+    SystemCoreClock = srcFreq / (sysDiv + 1U);
+#endif
+}
+
+/*!
+ * @brief Enable NMI, after set pinmux.
+ *
+ * @param[in] enable: enable state
+ * @return none
+ */
+void EnableNMI(uint8_t enable)
+{
+    if (enable != 0U)
+    {
+        SET_BIT32(MCM->MNCR, MCM_MNCR_NMI_EN_Msk);
+    }
+    else
+    {
+        CLEAR_BIT32(MCM->MNCR, MCM_MNCR_NMI_EN_Msk);
+    }
+}
+
+/* =============================================  EOF  ============================================== */

+ 157 - 0
Project/RTE/Device/AC78406HGLA/system_ac7840x.h

@@ -0,0 +1,157 @@
+/* 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) 2021. 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_ac7840x.h
+ *
+ * @brief This file provides system clock config integration functions interfaces.
+ *
+ */
+
+#ifndef _SYSTEM_AC7840X_H
+#define _SYSTEM_AC7840X_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ===========================================  Includes  =========================================== */
+#include <stdint.h>
+
+/* ============================================  Define  ============================================ */
+/*!< Sram ECC read enable */
+#define SRAM_ECC_READ_ENABLE     (1UL)
+
+/*!< Sram ECC 2bit error reset enable */
+#define SRAM_ECC_ERR_RST_ENABLE  (0UL)
+
+/*!< Watchdog disable */
+#ifndef WDG_DISABLE
+  #define WDG_DISABLE            (1UL)
+#endif
+
+/*!< Default system clock */
+#define DEFAULT_SYSTEM_CLOCK     (48000000UL)
+
+/*!< Default HSE(XOSC) frequency or user define */
+#define CKGEN_HSE_FREQ           (8000000UL)
+
+/*!< System clock uses ckgen driver */
+#define SYSTEM_USE_CKGEN         (0UL)
+
+/*!< 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");
+
+/* ===========================================  Typedef  ============================================ */
+
+/* ==========================================  Variables  =========================================== */
+
+/* ====================================  Functions declaration  ===================================== */
+/*!
+ * @brief Initialize SPLL then set system clock to the SPLL clock
+ *        (just support SPLL refer clock 4/8/12/16/30MHz, others need to modify).
+ *
+ * @param[in] refClk: 0: HSI clock, 1: HSE clock
+ * @param[in] freq: SPLL out frequency (16 - 120)
+ * @return status 0: success others: error
+ */
+uint32_t SetSysClkToSPLL(uint8_t refClk, uint8_t freq);
+
+/*!
+ * @brief Initialize VHSI then set system clock to the VHSI clock.
+ *
+ * @param[in] none
+ * @return status 0: success others: error
+ */
+uint32_t SetSysClkToVHSI(void);
+
+/*!
+ * @brief Initialize HSE then set system clock to the HSE clock.
+ *
+ * @param[in] bypass: 0: disable, 1: enable
+ * @return status 0: success others: error
+ */
+uint32_t SetSysClkToHSE(uint8_t bypass);
+
+/*!
+ * @brief Initialize HSI then set system clock to the HSI clock.
+ *
+ * @param[in] none
+ * @return status 0: success others: error
+ */
+uint32_t SetSysClkToHSI(void);
+
+/*!
+ * @brief Get UUID from devie
+ *
+ * @param[out] uuidBuffer: UUID buffer
+ * @return none
+ */
+void GetUUID(uint32_t *uuidBuffer);
+
+/*!
+ * @brief Setup the microcontroller system. Initialize the System.
+ *
+ * @param[in] none
+ * @return none
+ */
+void SystemInit(void);
+
+/*!
+ * @brief Update system clock frequence.
+ *
+ * @param[in] none
+ * @return none
+ */
+void SystemCoreClockUpdate(void);
+
+/*!
+ * @brief Enable NMI, after set pinmux.
+ *
+ * @param[in] enable: enable state
+ * @return none
+ */
+void EnableNMI(uint8_t enable);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _SYSTEM_AC7840X_H */
+
+/* =============================================  EOF  ============================================== */

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

@@ -0,0 +1,45 @@
+
+/*
+ * Auto generated Run-Time-Environment Configuration File
+ *      *** Do not modify ! ***
+ *
+ * Project: 'BVACS' 
+ * Target:  'Target 1' 
+ */
+
+#ifndef RTE_COMPONENTS_H
+#define RTE_COMPONENTS_H
+
+
+/*
+ * Define the Device Header File: 
+ */
+#define CMSIS_device_header "ac7840x.h"
+
+/* AutoChips::Device:ATC Drivers:CKGEN:1.0.0 */
+#define RTE_DEVICE_DRIVER_CKGEN
+/* AutoChips::Device:ATC Drivers:DMA:1.0.0 */
+#define RTE_DEVICE_DRIVER_DMA
+/* AutoChips::Device:ATC Drivers:EFLASH:1.0.0 */
+#define RTE_DEVICE_DRIVER_EFLASH
+/* AutoChips::Device:ATC Drivers:GPIO:1.0.0 */
+#define RTE_DEVICE_DRIVER_GPIO
+/* AutoChips::Device:ATC Drivers:RCM:1.0.0 */
+#define RTE_DEVICE_DRIVER_RCM
+/* 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 OSIF:OSIF:Bare Metal:1.0.0 */
+#define RTE_DEVICE_DRIVER_OSIF
+/* AutoChips::Device:Startup:1.0.0 */
+#define RTE_DEVICE_STARTUP_AC7840x
+
+
+#endif /* RTE_COMPONENTS_H */

+ 45 - 0
Project/RTE/_bvacs/RTE_Components.h

@@ -0,0 +1,45 @@
+
+/*
+ * Auto generated Run-Time-Environment Configuration File
+ *      *** Do not modify ! ***
+ *
+ * Project: 'BVACS' 
+ * Target:  'bvacs' 
+ */
+
+#ifndef RTE_COMPONENTS_H
+#define RTE_COMPONENTS_H
+
+
+/*
+ * Define the Device Header File: 
+ */
+#define CMSIS_device_header "ac7840x.h"
+
+/* AutoChips::Device:ATC Drivers:CKGEN:1.0.0 */
+#define RTE_DEVICE_DRIVER_CKGEN
+/* AutoChips::Device:ATC Drivers:DMA:1.0.0 */
+#define RTE_DEVICE_DRIVER_DMA
+/* AutoChips::Device:ATC Drivers:EFLASH:1.0.0 */
+#define RTE_DEVICE_DRIVER_EFLASH
+/* AutoChips::Device:ATC Drivers:GPIO:1.0.0 */
+#define RTE_DEVICE_DRIVER_GPIO
+/* AutoChips::Device:ATC Drivers:RCM:1.0.0 */
+#define RTE_DEVICE_DRIVER_RCM
+/* 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 OSIF:OSIF:Bare Metal:1.0.0 */
+#define RTE_DEVICE_DRIVER_OSIF
+/* AutoChips::Device:Startup:1.0.0 */
+#define RTE_DEVICE_STARTUP_AC7840x
+
+
+#endif /* RTE_COMPONENTS_H */

+ 2 - 0
README.md

@@ -0,0 +1,2 @@
+5公里底阀自动控制系统 V2.0
+本方案采用加速度传感检测速度变化

+ 575 - 0
User/IAP.c

@@ -0,0 +1,575 @@
+/* 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 "crc16.h"
+#include "IAP.h" 
+#include "md5c.h"
+#include "flash.h"
+#include "WDG.h"
+
+
+static __align(4)uint8_t WriteDataBuff[2048];
+
+static uint32_t s_writeAddress;
+
+static uint8_t s_iapStep;
+
+static uint32_t s_writeDataBuffSeek;
+
+//升级完成后, 重启标志
+uint8_t iap_reboot = 0;
+
+
+///< 升级包信息
+static uint8_t s_flashType;
+static uint32_t s_version[4];
+static uint32_t s_flashMemSize;
+static uint32_t s_recvByte=0;
+static uint16_t s_sequence=0; 
+
+//回传数据buffer 指针、 及数据长度
+static uint8_t* s_wData = NULL;
+static uint16_t s_wLen = 0;
+
+
+typedef void (*pFunction)(void);
+static pFunction s_jumpToApplication;
+/**
+* JumpTOApp
+*
+* @param[in] none
+* @return    none
+*
+* @brief  Jump to APP Code
+*/
+void JumpTOApp1(void)
+{
+    uint32_t JumpAddress;
+
+		//if ( (*(__IO uint32_t *)APP1_ADDRESS) <= 0x80000)
+		if (((*(__IO uint32_t *)APP1_ADDRESS) >= 0x1FFF0000) && ((*(__IO uint32_t *)APP1_ADDRESS) <= 0x2000EFFF))
+    {
+        DisableInterrupts                                               /* 关全局中断 */
+        s_jumpToApplication = (pFunction)(*(__IO uint32_t *)(APP1_ADDRESS + 4));    /* 指向APP程序的Reset中断*/
+        __set_MSP(*(__IO uint32_t*)APP1_ADDRESS);
+        s_jumpToApplication();
+    }
+    else
+    {
+        //printf("top of stack pointer is unvalid! enter APP update!\r\n");
+        return;
+    }
+    while (1);
+}
+
+int App_MD5_Check(uint32_t addr,unsigned int all_len)
+{
+	unsigned char digest[16];
+//	unsigned char *md5_ptr=(unsigned char *)(StartMode_Addr+72);
+	unsigned int i,update_len;
+	MD5_CTX md5c;
+	all_len -= 16;
+	MD5Init(&md5c);
+	for(i=0;i<all_len;)
+	{
+		if(all_len>(i+512))
+			update_len = 512;
+		else
+			update_len = all_len-i;
+		//memcpy(WriteDataBuff,(const void *)(addr+i),update_len);
+		FLASH_DRV_Read(&g_Flash_Config,(addr+i), (uint8_t*)WriteDataBuff, update_len);
+		MD5Update (&md5c, WriteDataBuff, update_len);
+		i += update_len;
+		
+		WDG_Feed();
+	}
+	MD5Final(digest,&md5c);
+	//memcpy(iapbuf,(const void *)(addr+all_len),16);
+	for(i=0;i<16;++i)
+	{
+		if(digest[i]!=*(unsigned char *)(addr+all_len+i))
+			break;
+	}
+	if(i>=16)
+		return 1;
+	else
+		return 0;
+}
+
+/*
+// appxaddr:应用程序的起始地址
+// appbuf:应用程序CODE.
+// appsize:应用程序大小(字节).
+void IAP_write_appbin(uint32_t appxaddr, uint8_t *appbuf, uint32_t appsize)
+{
+	uint32_t t;
+	uint16_t i = 0;
+	uint16_t temp;
+	uint32_t fwaddr = appxaddr; //当前写入的地址
+	uint32_t *dfu = appbuf;
+	for (t = 0; t < appsize; t += 2)
+	{
+		temp = (uint16_t)dfu[1] << 8;
+		temp += (uint16_t)dfu[0];
+		dfu += 2; //偏移2个字节
+		iapbuf[i++] = temp;
+		if (i == 1024)
+		{
+			i = 0;
+			HAL_GPIO_TogglePin(WDI_sp706_kanmemgou_GPIO_Port, WDI_sp706_kanmemgou_Pin);
+			STMFLASH_Write(fwaddr, iapbuf, 1024);
+			fwaddr += 2048; //偏移2048  16=2*8.所以要乘以2.
+		}
+		
+	}
+	if (i)
+		STMFLASH_Write(fwaddr, iapbuf, i); //将最后的一些内容字节写进去.
+}
+
+*/
+
+//
+int IAP_Init(void)
+{
+		s_recvByte=0;
+		s_sequence=0;
+		
+		s_version[0] = 0;
+		s_version[1] = 0;
+		s_version[2] = 0;
+		s_version[3] = 0;
+		
+		s_flashType = 0;
+		s_flashMemSize = 0;
+		
+		iap_reboot = 0;
+		
+    return 0;
+}
+
+
+void IAP_Start(void)
+{
+    if (s_iapStep == 1)
+    {
+        return;     ///<repeat start
+    }
+    s_writeAddress = APP2_ADDRESS;
+    s_iapStep = 1;
+}
+
+
+int IAP_Write(uint8_t *pdata, uint16_t length)
+{
+    status_t ret = STATUS_SUCCESS;
+    uint16_t MiniLength = 0;
+    if (s_iapStep != 1)     ///<防止用户不先调用start就开始写
+        return -1;
+    while (length > 0)
+    {
+        if ((s_writeAddress < APP2_ADDRESS) || (s_writeAddress >= APP2_ADDRESS_END))  ///<IAP不能超出APP_BKP地址范围
+            return -1;
+        if (s_writeDataBuffSeek + length > EFLASH_PAGE_SIZE_INIT)    ///得到单次写入的长度
+        {
+            MiniLength = EFLASH_PAGE_SIZE_INIT - s_writeDataBuffSeek;    ///<长度超出buff
+        }
+        else
+        {
+            MiniLength = length;    ///<全部写完,
+        }
+        memcpy(&WriteDataBuff[s_writeDataBuffSeek], pdata, MiniLength);
+        pdata += MiniLength;
+        s_writeDataBuffSeek += MiniLength;
+        length -= MiniLength;
+        if (s_writeDataBuffSeek == EFLASH_PAGE_SIZE_INIT)
+        {
+            FLASH_DRV_UnlockCtrl();
+            //ret = EFLASH_PageErase(s_writeAddress);     ///<erase page
+						ret = FLASH_DRV_EraseSector(&g_Flash_Config, s_writeAddress, EFLASH_PAGE_SIZE_INIT); 
+            if (ret != STATUS_SUCCESS) return -1;
+            //ret = EFLASH_PageEraseVerify(s_writeAddress);   ///< verify erase state
+						ret = FLASH_DRV_VerifySection(&g_Flash_Config,s_writeAddress, EFLASH_PAGE_SIZE_INIT/8);
+            if (ret != STATUS_SUCCESS) return -1;
+            //ret = EFLASH_PageProgram(s_writeAddress, (uint32_t *)WriteDataBuff, 512); 
+						ret = FLASH_DRV_Program(&g_Flash_Config, s_writeAddress, EFLASH_PAGE_SIZE_INIT, (uint8_t*)WriteDataBuff); 
+            if (ret != STATUS_SUCCESS) return -1;
+            FLASH_DRV_LockCtrl();  
+            s_writeAddress += EFLASH_PAGE_SIZE_INIT;
+            s_writeDataBuffSeek = 0;
+        }
+    }
+    return 0;
+}
+
+int IAP_Stop(void)
+{
+    status_t ret = STATUS_SUCCESS;
+    s_iapStep = 0;  ///<stop后重置step
+    if ((s_writeAddress < APP2_ADDRESS) || (s_writeAddress >= APP2_ADDRESS_END))  ///<IAP不能超出APP_BKP地址范围
+        return -1;
+    FLASH_DRV_UnlockCtrl();
+    //ret = EFLASH_PageErase(s_writeAddress);     ///<erase page
+		ret = FLASH_DRV_EraseSector(&g_Flash_Config, s_writeAddress, EFLASH_PAGE_SIZE_INIT); 
+    if (ret != STATUS_SUCCESS) return -1;
+    //ret = EFLASH_PageEraseVerify(s_writeAddress);   ///< verify erase state
+		ret = FLASH_DRV_VerifySection(&g_Flash_Config,s_writeAddress, EFLASH_PAGE_SIZE_INIT/8);
+    if (ret != STATUS_SUCCESS) return -1;
+    //ret = EFLASH_PageProgram(s_writeAddress, (uint32_t *)WriteDataBuff, 512);   ///<此处应该不满2048,但还是全部写入,后面为多余字节
+		ret = FLASH_DRV_Program(&g_Flash_Config, s_writeAddress, EFLASH_PAGE_SIZE_INIT, (uint8_t*)WriteDataBuff); 
+    if (ret != STATUS_SUCCESS) return -1;
+    FLASH_DRV_LockCtrl(); 
+    return 0;
+}
+
+
+
+/**
+* DataTransferRequestHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机通信 数据传输请求
+*/
+static void DataTransferRequestHandle(uint8_t *pdata, uint16_t length)
+{
+		uint32_t _version[4];
+    s_flashType = pdata[2];
+	
+		_version[0] = ((uint32_t)pdata[3]<<24) | ((uint32_t)pdata[4]<<16)| ((uint32_t)pdata[5]<<8)| pdata[6]; 
+		_version[1] = ((uint32_t)pdata[7]<<24) | ((uint32_t)pdata[8]<<16)| ((uint32_t)pdata[9]<<8)| pdata[10]; 
+		_version[2] = ((uint32_t)pdata[11]<<24) | ((uint32_t)pdata[12]<<16)| ((uint32_t)pdata[13]<<8)| pdata[14]; 
+		_version[3] = ((uint32_t)pdata[15]<<24) | ((uint32_t)pdata[16]<<16)| ((uint32_t)pdata[17]<<8)| pdata[18]; 
+	
+    s_flashMemSize = pdata[19];
+    s_flashMemSize <<= 8;
+    s_flashMemSize += pdata[20];
+    s_flashMemSize <<= 8;
+    s_flashMemSize += pdata[21];
+    s_flashMemSize <<= 8;
+    s_flashMemSize += pdata[22];
+	
+    
+    s_wData[s_wLen++] = DataTransferCmdHost;
+    s_wData[s_wLen++] = DataTransferRequest;
+		
+    if (s_flashType != IAP_BIN_FILE)    ///<目前只支持传输IAP bin 文件
+    {
+        s_wData[s_wLen++] = ResultParamErr;
+    }
+    else
+    {
+        if (s_flashMemSize > APP_SIZE)
+        {
+            s_wData[s_wLen++] = ResultExceedLimit;  ///<exceed limit 
+        }
+        else 
+        {
+            IAP_Start();
+            s_wData[s_wLen++] = ResultSuccess;
+        }
+    }
+    
+    s_wData[s_wLen++] = (uint8_t)((MaxBlockSize >> 24) & 0xff);
+    s_wData[s_wLen++] = (uint8_t)((MaxBlockSize >> 16) & 0xff);
+    s_wData[s_wLen++] = (uint8_t)((MaxBlockSize >> 8) & 0xff);
+    s_wData[s_wLen++] = (uint8_t)(MaxBlockSize & 0xff);
+		
+		//版本不一致
+		if(0 != memcmp(s_version, _version, 16)){
+			
+			s_version[0] = _version[0];
+			s_version[1] = _version[1];
+			s_version[2] = _version[2];
+			s_version[3] = _version[3];
+			
+			s_recvByte=0;
+			s_sequence=0;
+
+		}
+		
+		s_wData[s_wLen++] = (s_sequence>>8)&0xFF;
+		s_wData[s_wLen++] =  s_sequence&0xFF;
+		
+}
+/**
+* TransferDataHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机通信 传输数据处理
+*/
+static void TransferDataHandle(uint8_t *pdata, uint16_t length)
+{
+		uint16_t _sequence = pdata[2];
+		_sequence <<= 8;
+		_sequence += pdata[3];
+		
+		s_wData[s_wLen++] = DataTransferCmdHost;
+    s_wData[s_wLen++] = DataTransferRequest;
+	
+    if (length-4 > MaxBlockSize)
+    {
+        s_wData[s_wLen++] = ResultExceedLimit;    ///<长度超出限制
+        IAP_Stop();
+    }
+    else if (_sequence != s_sequence)
+    {
+        s_wData[s_wLen++] = ResultSequenceErr;    ///<序列号不正确
+        IAP_Stop();
+    }
+    else 
+    {
+        
+        if (0 != IAP_Write(&pdata[4], length - 4))
+        {
+            s_wData[s_wLen++] = ResultExecErr;    ///<执行错误
+            IAP_Stop();
+        }else{
+						s_wData[s_wLen++] = ResultSuccess;    ///<succeed
+						s_recvByte += length - 4;
+						s_sequence++;
+				}
+        
+    }
+		
+		s_wData[s_wLen++] = (s_sequence>>8)&0xFF;
+		s_wData[s_wLen++] =  s_sequence&0xFF;
+		
+}
+/**
+* TransferExitHandle
+*
+* @param[in] pdata:data point
+* @param[in] length:data length
+*                   
+* @return    none
+*
+* @brief  上位机通信 传输数据结束
+*/
+static void TransferExitHandle(uint8_t *pdata, uint16_t length)
+{
+    s_wData[s_wLen++] = DataTransferCmdHost;
+    s_wData[s_wLen++] = DataTransferRequest;
+	
+    //crc = ((uint16_t)pdata[2] << 8) | pdata[3]; 
+    
+    if (0 != IAP_Stop())
+    {
+        s_wData[s_wLen++] = ResultExecErr;    ///<执行错误
+    }
+    else
+    {
+        if (s_recvByte != s_flashMemSize)
+        {
+            s_wData[s_wLen++] = ResultTotalLengthErr;    ///<接收数据长度不正确
+        }
+        else
+        {
+
+						s_wData[s_wLen++] = ResultSuccess;
+					
+						config->App2Size = s_flashMemSize;
+						config->IapFlag = Startup_Update;
+						SaveConfig();
+					
+						//if (0 != SaveConfig())
+						//{
+						//   data[index] = ResultExecErr;
+						//}
+					
+						iap_reboot = 1;
+ 
+        }
+    }
+    
+}
+
+
+/**
+* IAP_CmdHandle
+*
+* @param[in] pdata:recv data point
+* @param[in] length:data length
+* @param[in] pout:send data point                 
+* @return    none
+*
+* @brief  上位机通信 数据接收处理函数
+*/
+uint16_t IAP_CmdHandle(uint8_t* pdata, uint16_t length, uint8_t* pout)
+{
+		s_wData = pout;
+		s_wLen = 0;
+	
+		if(DataTransferCmd == pdata[0]){
+			
+				switch (pdata[1])
+				{
+						case DataTransferRequest: //0x00
+								DataTransferRequestHandle(pdata, length);
+								break;
+						case TransferData: //0x01
+								TransferDataHandle(pdata, length);
+								break;
+						case TransferExit: //0x02
+								TransferExitHandle(pdata, length);
+								break;
+						default :
+							s_wData[0] = ResultCmdErr;
+							s_wLen =  1;
+								break;
+				}
+				
+		
+		}else{
+			
+			s_wData[0] = ResultCmdErr;
+			s_wLen =  1;
+		}
+		 
+		return s_wLen;
+    
+}
+
+
+
+/**
+ * @bieaf 进行BootLoader的启动
+ *
+ * @param none
+ * @return none
+ */
+void Start_BootLoader(void)
+{
+	//uint16_t crcCheck;
+	uint32_t writed_len;
+	uint32_t will_write_len;
+	status_t ret = STATUS_SUCCESS;
+
+	switch (config->IapFlag) ///< 读取是否启动应用程序 */
+	{
+	case Startup_Normal: ///< 正常启动 */   //在APP2中可以设定此标志位   使得下次重启之后进入APP1
+	{
+		//printf("> Normal start......\r\n");
+		break;
+	}
+	case Startup_Update: /*启动最新的程序 */
+				//printf("> Startup_Update start......\r\n");
+			//crcCheck = crc16((const uint8_t *)APP2_ADDRESS, config->App2Size);
+			if ((config->App2Size <= APP_SIZE) && App_MD5_Check(APP2_ADDRESS,config->App2Size))
+			{
+					writed_len =0;
+					will_write_len = config->App2Size;
+				
+					do{
+						
+						WDG_Feed();
+						
+						if(will_write_len >= EFLASH_PAGE_SIZE_INIT){
+							//memcpy(WriteDataBuff, (void *)(APP2_ADDRESS+writed_len), EFLASH_PAGE_SIZE_INIT);
+							FLASH_DRV_Read(&g_Flash_Config,(APP2_ADDRESS+writed_len), (uint8_t*)WriteDataBuff, EFLASH_PAGE_SIZE_INIT);
+							
+							FLASH_DRV_UnlockCtrl(); 
+							//ret = EFLASH_PageErase(APP1_ADDRESS+writed_len);     ///<erase page
+							ret = FLASH_DRV_EraseSector(&g_Flash_Config, (APP1_ADDRESS+writed_len), EFLASH_PAGE_SIZE_INIT); 
+							if (ret != STATUS_SUCCESS) break;
+							//ret = EFLASH_PageEraseVerify(APP1_ADDRESS+writed_len);   ///< verify erase state
+							ret = FLASH_DRV_VerifySection(&g_Flash_Config,(APP1_ADDRESS+writed_len), EFLASH_PAGE_SIZE_INIT/8);
+							if (ret != STATUS_SUCCESS) break;
+							//ret = EFLASH_PageProgram(APP1_ADDRESS+writed_len, (uint32_t *)WriteDataBuff, 512); 
+							ret = FLASH_DRV_Program(&g_Flash_Config, (APP1_ADDRESS+writed_len), EFLASH_PAGE_SIZE_INIT, (uint8_t*)WriteDataBuff); 
+							if (ret != STATUS_SUCCESS) break;
+							FLASH_DRV_LockCtrl();   
+							
+							writed_len += EFLASH_PAGE_SIZE_INIT;
+							will_write_len -= EFLASH_PAGE_SIZE_INIT;
+							
+						}else{
+							
+							//memcpy(WriteDataBuff, (void *)(APP2_ADDRESS+writed_len), will_write_len);
+							FLASH_DRV_Read(&g_Flash_Config,(APP2_ADDRESS+writed_len), (uint8_t*)WriteDataBuff, will_write_len);
+							
+							FLASH_DRV_UnlockCtrl(); 
+							//ret = EFLASH_PageErase(APP1_ADDRESS+writed_len);     ///<erase page
+							ret = FLASH_DRV_EraseSector(&g_Flash_Config, (APP1_ADDRESS+writed_len), EFLASH_PAGE_SIZE_INIT); 
+							if (ret != STATUS_SUCCESS) break;
+							//ret = EFLASH_PageEraseVerify(APP1_ADDRESS+writed_len);   ///< verify erase state
+							ret = FLASH_DRV_VerifySection(&g_Flash_Config,(APP1_ADDRESS+writed_len), EFLASH_PAGE_SIZE_INIT/8);
+							if (ret != STATUS_SUCCESS) break;
+							//ret = EFLASH_PageProgram(APP1_ADDRESS+writed_len, (uint32_t *)WriteDataBuff, (will_write_len+3)/4); 
+							ret = FLASH_DRV_Program(&g_Flash_Config, (APP1_ADDRESS+writed_len), (((will_write_len+7)/8)*8), (uint8_t*)WriteDataBuff); 
+							if (ret != STATUS_SUCCESS) break;
+							FLASH_DRV_LockCtrl();   
+							
+							writed_len += will_write_len;
+							will_write_len = 0;
+						
+						}
+						
+					}while(will_write_len > 0);
+					
+					if(STATUS_SUCCESS == ret){
+							config->App1Size = config->App2Size;
+					
+					}		
+				
+			}
+			
+			config->IapFlag = Startup_APP1;
+			SaveConfig();
+						
+	case Startup_APP1: /*启动最新的程序 */
+			//printf("> Startup_APP1 start......\r\n");
+			//printf("> Startup_APP1 App1Size = [%d].\r\n", config->App1Size);
+			//crcCheck = crc16((const uint8_t *)APP1_ADDRESS, config->App1Size);
+			if((config->App1Size <= APP_SIZE) && App_MD5_Check(APP1_ADDRESS,config->App1Size))
+			{
+				//printf("> Startup_APP1 JumpTOApp1 ......\r\n");
+					JumpTOApp1();
+			}
+	
+		break;
+	default: ///< 启动失败
+	{
+		return;
+	}
+	}
+}
+
+

+ 89 - 0
User/IAP.h

@@ -0,0 +1,89 @@
+/* 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 "ac7840x.h"
+#include "cfg.h"
+//#include "ac780x_eflash.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)  //²»Äܳ¬³ö½ÓÊÕbuffer size  #define UART0_RECV_DATA_POOL_COUNT     320  
+
+/* Result */
+#define ResultSuccess					(0)
+#define ResultBusy						(1)
+#define ResultExceedLimit			(2)
+#define ResultTotalLengthErr	(3)
+#define ResultSequenceErr			(4)
+#define ResultCRCErr					(5)
+#define ResultParamErr        (6)
+#define ResultCmdErr        	(7)
+#define ResultExecErr         (8)
+
+extern uint8_t iap_reboot;
+    
+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);
+extern uint16_t IAP_CmdHandle(uint8_t* pdata, uint16_t length, uint8_t* pout);
+
+extern void Start_BootLoader(void);
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* IAP_H */
+

+ 73 - 0
User/cfg.c

@@ -0,0 +1,73 @@
+#include "cfg.h"
+#include "uart.h"
+#include "flash.h"
+#include <string.h>
+
+static uint64_t reflectionBuff[(sizeof(Config_type)>>3)+1];
+
+Config_type *config = (Config_type *)reflectionBuff;
+
+static void Factory_reset(void)
+{
+		config->magic = CONFIG_MAGIC;
+		config->addr = DEFAULT_ADDR;
+		config->br_index = BaudRate_115200;
+	
+		//config->App2Size = 0;
+		//config->App2Crc = 0;
+		//config->IapFlag = 0;
+
+}
+
+int Config_Init(void)
+{
+    //EFLASH_StatusType ret = EFLASH_STATUS_SUCCESS;
+    //memcpy(reflectionBuff, (void *)CONFIG_ADDRESS, sizeof(Config_type));
+		FLASH_DRV_Read(&g_Flash_Config,CONFIG_ADDRESS, (uint8_t*)reflectionBuff, sizeof(reflectionBuff));
+    if (config->magic != CONFIG_MAGIC)
+    {/* initiliaze config */
+        memset(reflectionBuff, 0xFF, sizeof(reflectionBuff)); 
+        //config->magic = CONFIG_MAGIC;
+			
+			
+				Factory_reset();
+			
+				//
+				config->IapFlag = Startup_Normal;
+				config->hw_version = 0x0000;
+				config->devicetype = 0x0000;
+				config->deviceid = 0x00;
+				
+        SaveConfig();
+			
+    }
+		
+		//Factory_reset();
+    return 0;
+}
+
+int SaveConfig(void)
+{
+	  status_t ret = STATUS_SUCCESS;
+    ret = FLASH_DRV_UnlockCtrl(); 
+    if(STATUS_SUCCESS != ret) return -1;
+		ret = FLASH_DRV_EraseSector(&g_Flash_Config, CONFIG_ADDRESS, EFLASH_PAGE_SIZE_INIT);
+		if(STATUS_SUCCESS != ret) return -1;
+		ret = FLASH_DRV_VerifySection(&g_Flash_Config,CONFIG_ADDRESS, EFLASH_PAGE_SIZE_INIT/8);
+		if(STATUS_SUCCESS != ret) return -1;
+		ret = FLASH_DRV_Program(&g_Flash_Config, CONFIG_ADDRESS, sizeof(reflectionBuff), (uint8_t*)reflectionBuff); 
+	
+    FLASH_DRV_LockCtrl(); 
+		
+		return 0;
+		
+}
+
+int ResetConfig(void)
+{
+    Factory_reset();
+    //SaveConfig();
+	
+    return 0;
+}
+

+ 103 - 0
User/cfg.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 CFG_H
+#define CFG_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "ac7840x.h"
+
+//控制程序,是否编译为  bootloader, hex 格式
+#define IS_BOOTLOADER       (1)   
+
+
+
+#define IAP_BOOTLOAD_ADDRESS    0x0000000    /* define bootload start address */
+#define CONFIG_ADDRESS      		0x1000000    /* 预留一个页用于存放配置信息 */
+#define APP1_ADDRESS    					0x28000    /* define app start address */   
+#define APP2_ADDRESS    					0x50000    /* 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 * 80)  /* 160 KB*/
+#define APP2_ADDRESS_END     ((uint32_t)(APP2_ADDRESS + APP_SIZE))   
+  
+
+#define CONFIG_MAGIC   		0xA5A5
+
+#define DEFAULT_ADDR     0x30
+#define BROADCAST_ADDR   0xFF
+
+/* 升级标志 */
+#define Startup_Normal 	0xBBBB	///< run bootloader 
+#define Startup_Update 	0xAAAA	///< copy app2 to app1 
+//#define Startup_Reset  	0x5555AAAA	///< ***???? ?????***
+#define Startup_APP1  	0x55BB	///< jump and run  app1,
+
+/*
+* sizeof(Config_type)  不能超出2KB 
+* sizeof(Config_type)  采用固定大小, 256 字节, 对于传感器来说足够用了。 最后是IAP 升级需要的信息; 要与前面的参数分开
+*/
+typedef struct 
+{
+		uint16_t magic;
+    uint8_t  addr;
+    uint8_t  br_index;
+	
+		uint32_t  res[58];
+	
+		uint16_t hw_version;
+		uint16_t devicetype;
+	  uint32_t deviceid;
+	
+		uint32_t App1Size;
+    uint32_t App2Size;
+	
+		uint16_t IapFlag;
+		uint16_t res2;
+}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 */

+ 287 - 0
User/clock_config.c

@@ -0,0 +1,287 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+/*!
+* @file clock_config.c
+*
+* @brief This file provides clock config integration functions.
+*
+*/
+
+/* ===========================================  Includes  =========================================== */
+#include "clock_config.h"
+
+/* ============================================  Define  ============================================ */
+
+
+/* ===========================================  Typedef  ============================================ */
+
+
+/* ==========================================  Variables  =========================================== */
+
+/*! @brief peripheral clock configuration 0 */
+peripheral_clock_config_t peripheralClockConfig0[NUM_OF_PERIPHERAL_CLOCKS_0] = {
+    {
+        .clockName        = I2C0_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = TIMER_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = SPI0_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = SPI1_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = SPI2_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = ADC0_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = ADC1_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = CAN0_CLK,
+        .clkSrc           = CORE_CLK,
+        .divider          = DIVIDE_BY_TWO,
+    },
+    {
+        .clockName        = CAN1_CLK,
+        .clkSrc           = CORE_CLK,
+        .divider          = DIVIDE_BY_TWO,
+    },
+    {
+        .clockName        = CAN2_CLK,
+        .clkSrc           = CORE_CLK,
+        .divider          = DIVIDE_BY_TWO,
+    },
+    {
+        .clockName        = CAN3_CLK,
+        .clkSrc           = CORE_CLK,
+        .divider          = DIVIDE_BY_TWO,
+    },
+    {
+        .clockName        = PCT_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = EIO_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = UART0_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = UART1_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = UART2_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = UART3_CLK,
+        .clkSrc           = SPLLDIV2_CLK,
+    },
+    {
+        .clockName        = PWM0_CLK,
+        .clkSrc           = SPLLDIV1_CLK,
+    },
+    {
+        .clockName        = PWM1_CLK,
+        .clkSrc           = SPLLDIV1_CLK,
+    },
+    {
+        .clockName        = PWM2_CLK,
+        .clkSrc           = SPLLDIV1_CLK,
+    },
+    {
+        .clockName        = PWM3_CLK,
+        .clkSrc           = SPLLDIV1_CLK,
+    },
+    {
+        .clockName        = PWM4_CLK,
+        .clkSrc           = SPLLDIV1_CLK,
+    },
+    {
+        .clockName        = PWM5_CLK,
+        .clkSrc           = SPLLDIV1_CLK,
+    },
+};
+
+/*! @brief User Configuration structure clockMan1_InitConfig0 */
+clock_manager_user_config_t clockMan1_InitConfig0 = {
+    /* CKGEN Clock Configuration. */
+    .ckgenConfig =
+    {
+        /* Slow Internal Reference Clock Configuration. */
+        .hsiConfig =
+        {
+            /* HSIDIV */
+            .div1               = CKGEN_ASYNC_CLOCK_DIV_BY_1,                   /*!< HSIDIV1    */
+            .div2               = CKGEN_ASYNC_CLOCK_DIV_BY_1,                   /*!< HSIDIV2    */
+
+            .initialize         = true,                                         /*!< Initialize */
+            .enableInLowPower   = true,                                         /*!< Enable in VLPS mode */
+        },
+        /* Fast Internal Reference Clock Configuration. */
+        .vhsiConfig =
+        {
+            /* VHSIDIV */
+            .div1               = CKGEN_ASYNC_CLOCK_DIV_BY_1,                   /*!< VHSIDIV1   */
+            .div2               = CKGEN_ASYNC_CLOCK_DIV_BY_1,                   /*!< VHSIDIV2   */
+
+            .initialize         = true,                                         /*!< Initialize */
+        },
+        /* System Oscillator Configuration. */
+        .hseConfig =
+        {
+            .freq               = 25000000U,                                     /*!< Frequency  */
+            .monitor            = CKGEN_XOSC_MONITOR_RESET,
+            /* HSEREF */
+            .extRef             = CKGEN_HSE_REF_OSC,                            /*!< HSEREF     */
+            /* HSEDIV */
+            .div1               = CKGEN_ASYNC_CLOCK_DIV_BY_1,                   /*!< HSEDIV1    */
+            .div2               = CKGEN_ASYNC_CLOCK_DIV_BY_1,                   /*!< HSEDIV2    */
+            .initialize         = true,                                         /*!< Initialize */
+        },
+        /* System Phase Locked Loop Configuration. */
+        .spllConfig =
+        {
+            /* SPLLCFG */
+            .prediv             = (uint8_t)CKGEN_SPLL_CLOCK_PREDIV_BY_4,        /*!< PREDIV     */
+            .fbkdiv             = 100U,                                         /*!< FBKDIV     */
+            .posdiv             = 6U,                                           /*!< POSDIV     */
+            .src                = (uint8_t)CKGEN_SPLL_REF_HSE,                  /*!< SOURCE     */
+            .lockDetect         = CKGEN_SPLL_LOCK_DETECT_RESET,
+            /* SPLLDIV */
+            .div1               = CKGEN_ASYNC_CLOCK_DIV_BY_2,                   /*!< SPLLDIV1   */
+            .div2               = CKGEN_ASYNC_CLOCK_DIV_BY_2,                   /*!< SPLLDIV2   */
+            .initialize         = true,                                         /*!< Initialize */
+        },
+        /* RTC Configuration.*/
+        .rtcConfig =
+        {
+            .rtcClkInFreq       = 0U,                                           /*!< RTC_CLKIN  */
+            .initialize         = true,                                         /*!< Initialize */
+        },
+        /* Clock Mode Configuration.*/
+        .clockModeConfig =
+        {
+            /* RCCR - Run Clock Control Register. */
+            .rccrConfig =
+            {
+                .src            = CKGEN_SYSTEM_CLOCK_SRC_SPLL,                  /*!< SCS        */
+                .divCore        = CKGEN_SYSTEM_CLOCK_DIV_BY_1,                  /*!< DIVCORE    */
+                .divBus         = CKGEN_SYSTEM_CLOCK_DIV_BY_2,                  /*!< DIVBUS     */
+            },
+            /* VCCR - VLPR Clock Control Register */
+            .vccrConfig =
+            {
+                .src            = CKGEN_SYSTEM_CLOCK_SRC_HSI,                   /*!< SCS        */
+                .divCore        = CKGEN_SYSTEM_CLOCK_DIV_BY_1,                  /*!< DIVCORE    */
+                .divBus         = CKGEN_SYSTEM_CLOCK_DIV_BY_2,                  /*!< DIVBUS     */
+            },
+            .initialize         = true,                                         /*!< Initialize */
+        },
+    },
+
+    .simConfig =
+    {
+        /* Clock Out Configuration. */
+        .clockOutConfig =
+        {
+            .initialize         = true,                                         /*!< Initialize */
+            .enable             = false,
+            .source             = CKGEN_CLKOUT_SEL_HSI_CLK,                     /*!< CLKOUTSEL  */
+            .divider            = CKGEN_CLKOUT_DIV_BY_2,                        /*!< CLKOUTDIV  */
+        },
+        /* Low Power Clock Configuration. */
+        .lpClockConfig =
+        {
+            .initialize         = true,                                         /*!< Initialize */
+            .sourceLsiClk       = LSI_CLK_SEL_128K,                             /*!< LSICLKSEL  */
+            .sourceRtcClk       = RTC_CLK_SEL_VHSIDIV1,                         /*!< RTCCLKSEL  */
+        },
+        /* Tclk Clock Configuration. */
+        .tclkConfig =
+        {
+            .initialize         = true,                                         /*!< Initialize */
+            .tclkFreq[0U]       = 0UL,                                          /*!< TCLK0      */
+            .tclkFreq[1U]       = 0UL,                                          /*!< TCLK1      */
+            .tclkFreq[2U]       = 0UL,                                          /*!< TCLK2      */
+        },
+        /* Debug Trace Clock Configuration. */
+        .traceClockConfig =
+        {
+            .initialize       = true,                                           /*!< Initialize */
+            .divider          = 0U,                                             /*!< TRACEDIV   */
+        },
+    },
+
+    /* PCC - Peripheral Clock Configuration. */
+    .pccConfig =
+    {
+        .peripheralClocks = peripheralClockConfig0,                             /*!< Peripheral clock control configurations               */
+        .count = NUM_OF_PERIPHERAL_CLOCKS_0,                                    /*!< Number of the peripheral clock control configurations */
+    },
+};
+
+/*! @brief Array of pointers to User configuration structures */
+clock_manager_user_config_t const * g_clockManConfigsArr[] = {
+    &clockMan1_InitConfig0
+};
+
+/*! @brief Array of pointers to User defined Callbacks configuration structures */
+clock_manager_callback_user_config_t * g_clockManCallbacksArr[] = {(void*)0};
+
+/* ====================================  Functions declaration  ===================================== */
+
+
+/* ======================================  Functions define  ======================================== */
+
+
+/* =============================================  EOF  ============================================== */

+ 91 - 0
User/clock_config.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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+#ifndef _CLOCK_CONIFG_H
+#define _CLOCK_CONIFG_H
+
+/*!
+ * @file clock_config.h
+ *
+ * @brief clock config function definition.
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* ===========================================  Includes  =========================================== */
+#include <stdbool.h>
+#include <stdint.h>
+#include "ckgen_drv.h"
+
+/* ===========================================  Typedef  ============================================ */
+
+/* ==========================================  Variables  =========================================== */
+
+/*! @brief User configuration structure 0 */
+extern clock_manager_user_config_t clockMan1_InitConfig0;
+
+/*! @brief Count of user configuration structures */
+#define CLOCK_MANAGER_CONFIG_CNT 1U
+
+/*! @brief Array of pointers to User configuration structures */
+extern clock_manager_user_config_t const *g_clockManConfigsArr[];
+
+/*! @brief User peripheral configuration structure 0 */
+extern peripheral_clock_config_t peripheralClockConfig0[];
+
+/*! @brief Count of peripheral clock user configurations */
+#define NUM_OF_PERIPHERAL_CLOCKS_0 23U
+
+
+/*! @brief Count of user Callbacks */
+#define CLOCK_MANAGER_CALLBACK_CNT 0U
+
+/*! @brief Array of User callbacks */
+extern clock_manager_callback_user_config_t *g_clockManCallbacksArr[];
+
+/* ====================================  Functions declaration  ===================================== */
+
+
+/* ======================================  Functions define  ======================================== */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _CLOCK_CONIFG_H */
+
+/* =============================================  EOF  ============================================== */

+ 149 - 0
User/main.c

@@ -0,0 +1,149 @@
+/* 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) 2022. 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.
+ */
+/******************************************************************************
+ * @version: V2.0.1  AC7840x  Demo
+ ******************************************************************************/
+
+/*!
+ *例程说明:
+ *1.SPI 作为主机采用阻塞方式收发数据
+ *2.按一次按键通信一次
+ */
+
+/*!
+ * @file main.c
+ *
+ * @brief This file is main.c.
+ */
+
+/* ===========================================  Includes  =========================================== */
+#include "ac7840x.h"
+#include "debugout_ac7840x.h"
+#include "ckgen_hw.h"
+#include "ckgen_drv.h"
+#include "clock_config.h"
+#include "port_hw.h"
+#include "gpio_hw.h"
+#include "spi_master_drv.h"
+#include "gpio.h"
+#include "osif.h"
+#include "adxl312.h"
+#include "timer.h"
+#include "wdg.h"
+#include "flash.h"
+#include "cfg.h"
+#include "IAP.h"
+//#include "process.h"
+#include "main_task.h"
+/* ============================================  Define  ============================================ */
+
+
+/* ===========================================  Typedef  ============================================ */
+
+
+/* ==========================================  Variables  =========================================== */
+
+
+/* ====================================  Functions declaration  ===================================== */
+
+/*!
+ * @brief 时钟配置函数.
+ *
+ * @param none
+ *
+ * @return none
+ */
+void SystemClock_Config(void)
+{
+    CKGEN_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
+                   g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
+    CKGEN_DRV_UpdateConfiguration(0, CLOCK_MANAGER_POLICY_AGREEMENT);
+}
+
+/*!
+ * @brief main
+ *
+ * @param  none
+ *
+ * @return 0: success, other: error value
+ */
+int main(void)
+{
+	
+	#ifndef IS_BOOTLOADER
+    DisableInterrupts;
+    SCB->VTOR = APP1_ADDRESS;
+    EnableInterrupts;
+	#endif
+	
+    SystemClock_Config();                                                                                           /*! 时钟初始化 */
+    //InitDebug();
+                                                                                                    /*! 初始化调试串口 */
+		Flash_Init();
+		Config_Init();
+		WDG_Init();
+	
+	#ifdef IS_BOOTLOADER
+		Start_BootLoader();
+	#endif
+	
+    GPIO_Init();                                                                                                    /*! GPIO Init */
+    IAP_Init();                                                                                           /*! SPI主机初始化 */
+
+		WDG_Feed();
+		ADXL312_Init();
+	
+		Task_Init();
+		Timer_Init();
+		WDG_Feed();
+		
+    while (1)
+    {
+			//uint32_t start =  OSIF_GetMilliseconds();
+				Task_Handle();
+				WDG_Feed();
+			//uint32_t end =  OSIF_GetMilliseconds();
+			//printf("elapsed:%d ms : %d \r",  end-start, start);
+        //OSIF_TimeDelay(100);
+				//LED3_TOGGLE;
+				//LED4_TOGGLE;
+        //printf("delay 1s \r\n");
+			
+
+    }
+}
+
+/* ======================================  Functions define  ======================================== */
+
+
+/* =============================================  EOF  ============================================== */

+ 268 - 0
User/main_task.c

@@ -0,0 +1,268 @@
+#include "main_task.h"
+#include "uart.h"
+#include "gpio.h"
+#include "cfg.h"
+#include "IAP.h"
+#include "protocol.h"
+#include "process.h"
+#include "crc16.h"
+#include <string.h>
+#include "osif.h"
+
+
+/**
+* Uart0_RxDataHandle
+*                  
+* @return    none
+*
+* @brief  主任务处理函数
+*/
+void Uart1_RxDataHandle(void)
+{
+		uint8_t* rxbuf = uart1_info.recv_buffer;
+		uint16_t rx_len = uart1_info.recv_len;
+		uint8_t* txbuf = uart1_info.send_buffer;
+		uint16_t txbuf_size = UART1_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_BvStatus:
+											ret_len = Read_BvStatus(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); 
+									
+									Uart1_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;
+										case Cmd_ControlSV:
+											ret_write = Control_SValve(rxbuf+4, rx_len-4-2);
+											break;
+										case Cmd_TriggerVO:
+											ret_write = Trigger_VoicOutput(rxbuf+4, rx_len-4-2);
+											break;
+										case Cmd_TriggerSendRaw:
+											ret_write = Trigger_SendRaw(rxbuf+4, rx_len-4-2);
+											break;
+										case Cmd_TriggerSendFiltered:
+											ret_write = Trigger_SendFiltered(rxbuf+4, rx_len-4-2);
+											break;
+										
+										case Cmd_IapUpgrade:
+											tx_len += IAP_CmdHandle(rxbuf+tx_len, rx_len-4-2, txbuf+tx_len);
+											if(1 == iap_reboot){
+												ret_write |= RET_NEED_REBOOT;
+											}
+											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{ 
+											if(Cmd_IapUpgrade != cmd){
+												
+												//copy the whole rx frame
+												memcpy(txbuf, (void *)rxbuf, rx_len-2);
+												tx_len =rx_len-2;
+												
+											}else{ 
+												//升级命令,啥都不用做
+											
+											}
+											
+									}
+									
+									crc = crc16(txbuf, tx_len);
+									txbuf[tx_len++] = (uint8_t)((crc>>8) & 0x00ff);
+									txbuf[tx_len++] = (uint8_t)(crc & 0x00ff); 
+									
+									Uart1_TransmitData(txbuf, tx_len);
+									
+									if((ret_write&RET_NEED_SAVE) > 0 ){
+											SaveConfig();
+									}
+									
+									if((ret_write&RET_NEED_REBOOT) > 0 ){
+											OSIF_TimeDelay(100);
+											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); 
+								
+								Uart1_TransmitData(txbuf, tx_len);
+
+							}
+							
+					}
+					
+#else
+				memcpy(txbuf, (void *)rxbuf, rx_len);
+				tx_len +=rx_len;
+				
+				Uart1_TransmitData(txbuf, tx_len);
+			
+#endif 			
+				
+			}
+			
+		
+		} //END rx_len 
+		
+		if(rx_len > 0){
+			Uart1_RecvData();
+		}
+
+}
+
+
+/**
+* Task_Init
+*                  
+* @return    none
+*
+* @brief  初始化
+*/
+
+void Task_Init(void)
+{ 
+		Process_Init();
+	
+#if 1
+    Uart1_Initialize();
+
+		memcpy(uart1_info.send_buffer, (void *)"Booted", 6);
+		uart1_info.send_len = 6;
+		
+		Uart1_TransmitData(uart1_info.send_buffer, uart1_info.send_len);
+		Uart1_RecvData();
+#endif 
+		
+}
+
+
+/**
+* Task_Handle
+*                  
+* @return    none
+*
+* @brief  主任务处理函数
+*/
+void Task_Handle(void)
+{
+	
+		Process_RunLedPrd();
+		Uart1_RxDataHandle();
+		Process_Alg();
+
+}
+
+

+ 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 */
+
+

+ 614 - 0
User/process.c

@@ -0,0 +1,614 @@
+#include "process.h"
+#include "osif.h"
+#include "gpio.h"
+#include "adxl312.h"
+#include "uart.h"
+#include "crc16.h"
+#include "string.h"
+#include "math.h"
+
+
+uint16_t	g_blinkLedTime;			/*RUN LED闪烁频率控制时间*/
+uint16_t	g_blinkLedTgtTime;	/*RUN LED目标闪烁频率*/
+//uint32_t	g_alg_run_count;			
+//uint8_t	  g_bvopen_delay;    
+
+uint8_t	  g_bvopen;  // 0: close , 1: open
+uint8_t   g_trigger_vo;
+
+#define  DEFAULT_VO_PERIOD     (500) /* 5秒*/
+uint16_t	g_VoiceOutTime;			/*语音播报频率控制时间*/
+
+#define BV_OPEN  	(1)
+#define BV_CLOSE  (0)
+
+#define STATUS_DETECTINTERVAL  (60)  /*60ms * 8 == 500ms  */
+
+#define BV_DELAY_COUNT  				(50)  /*50次, 500ms */
+static uint8_t	g_bvopen_delay;    
+
+static circle_buffer cbuffer;
+static filter_avg_t filter_avg;
+static axis_info_t  axis_info;
+static detect_info_t detect_info;
+
+static int16_t accx = 0;
+static int16_t accy = 0;
+static int16_t accz = 0;
+
+static int16_t acc_x = 0;
+static int16_t acc_y = 0;
+static int16_t acc_z = 0;
+
+//static float acc_fx = 0;
+//static float acc_fy = 0;
+//static float acc_fz = 0;
+
+//static float fx_sum = 0;
+//static float fy_sum = 0;
+//static float fz_sum = 0;
+
+uint8_t g_send_raw = 0;
+uint8_t g_send_filtered = 0;
+uint32_t g_send_sequence = 0;
+uint8_t  g_vo_alarm = 0;	  /*  是否触发语音输出*/ 
+
+ALG_CONTEXT g_alg_context;
+
+void cbuffer_pushdata(int16_t acc_x, int16_t acc_y, int16_t acc_z);
+
+//每10ms 调用一次
+void timer_callback(void)
+{
+		if (g_blinkLedTime < 0xFFFF)
+		{
+				g_blinkLedTime++;
+		}
+		
+		if(g_VoiceOutTime < 0xFFFF){
+				g_VoiceOutTime++;
+		}
+		
+		//底阀打开状态
+		if(LOW == GET_K3_STS()){
+			
+				if(g_bvopen_delay <= BV_DELAY_COUNT){
+					g_bvopen_delay++;
+				}else{
+					//g_alg_run_count = 10*60*100; //10 min
+					if(BV_CLOSE == g_bvopen){
+						//g_alg_context.state = ALG_Start;
+						g_bvopen =BV_OPEN;
+						//g_VoiceOutTime = DEFAULT_VO_PERIOD-100;
+					}
+					
+					//g_alg_context.rundelay_count = RUNDELAY_COUNT;
+				}
+				
+		}else{
+		
+				if(g_bvopen_delay > 0){
+					g_bvopen_delay--;
+					
+				}else{
+					
+					g_bvopen = BV_CLOSE;
+					
+					//if(g_alg_context.rundelay_count > 0){
+					//		g_alg_context.rundelay_count--;
+					//}
+				
+				}
+
+		}
+		
+	//433  语音输出
+	if(g_trigger_vo > 0){
+		g_trigger_vo--;
+	
+	}
+	
+	// 算法触发开阀延时
+	if(g_alg_context.valveclose_delay > 0){
+			g_alg_context.valveclose_delay--;
+	}
+	
+	//read acc data
+  ADXL312_ReadAcc(&accx, &accy, &accz);
+	cbuffer_pushdata(accx, accy, accz);
+
+}
+
+void Process_Init(void)
+{
+		g_blinkLedTime 	  = 0;
+		g_blinkLedTgtTime = BLINK_LED_DFTT;
+		//g_alg_run_count		= 0;
+		g_bvopen_delay	= 0;
+		g_bvopen = BV_CLOSE;
+		g_trigger_vo = 0;
+		g_vo_alarm = 0;
+	
+		/* acc data */
+
+	  g_send_raw = 0;
+	  g_send_filtered = 0;
+	
+		g_alg_context.state = ALG_None;
+		//g_alg_context.rundelay_count = 0;
+		g_alg_context.valveclose_delay = 0;
+	
+		cbuffer.read_index = 0;
+		cbuffer.write_index = 0;
+	
+		filter_avg.count = 0;
+	
+	
+}
+
+void Process_RunLedPrd(void)
+{
+	/*周期性地检查LED闪烁,运行指示灯闪烁.*/
+	if (g_blinkLedTime >= g_blinkLedTgtTime)
+	{
+		g_blinkLedTime = 0;
+		
+		LED3_TOGGLE;
+	}
+	
+	/*语音输出*/
+	if(g_VoiceOutTime >= DEFAULT_VO_PERIOD){
+			g_VoiceOutTime = 0;
+			
+			if((g_vo_alarm == 1) && (g_trigger_vo == 0)){
+				g_trigger_vo = VO_COUNT_DFTT;
+			}
+		
+	}
+
+	
+	if(g_bvopen == BV_OPEN){
+			LED4_ON;
+	}else{
+			LED4_OFF;
+	}
+	
+	
+		//433  语音输出
+	if(g_trigger_vo > 0){
+		
+		if(GPIO_DRV_GetPinsOutput(LED2_GPIO)& (1<<LED2_PIN))
+		{
+				
+		}else{
+				LED2_ON;
+		}
+		
+	
+	}else{
+		
+		if(GPIO_DRV_GetPinsOutput(LED2_GPIO)&(1<<LED2_PIN))
+		{
+			LED2_OFF;
+		}
+	
+	}
+	
+	
+}
+
+void sv_open(void)
+{
+	LED1_ON;
+}
+void sv_close(void)
+{
+	LED1_OFF;
+}
+
+void cbuffer_pushdata(int16_t acc_x, int16_t acc_y, int16_t acc_z)
+{
+		cbuffer.data[0][cbuffer.write_index] = acc_x;
+		cbuffer.data[1][cbuffer.write_index] = acc_y;
+		cbuffer.data[2][cbuffer.write_index] = acc_z;
+	
+		cbuffer.write_index++;
+	
+		if(cbuffer.write_index == ACC_DATASIZE){
+				cbuffer.write_index = 0;
+		}
+	
+}
+
+int cbuffer_popdata(int16_t* acc_x, int16_t* acc_y, int16_t* acc_z)
+{
+		if(cbuffer.write_index == cbuffer.read_index){
+				return 1;
+		}
+		
+		*acc_x = cbuffer.data[0][cbuffer.read_index];
+		*acc_y = cbuffer.data[1][cbuffer.read_index];
+		*acc_z = cbuffer.data[2][cbuffer.read_index];
+		
+		cbuffer.read_index++;
+		if(cbuffer.read_index == ACC_DATASIZE){
+			cbuffer.read_index = 0;
+		}
+		
+		return 0;
+		
+}
+
+
+void alg_PreProcess(void)
+{
+		static uint8_t _bvopen = BV_CLOSE;
+		
+		//状态切换
+		if(_bvopen != g_bvopen){
+			
+				_bvopen = g_bvopen;
+				if(BV_OPEN == g_bvopen){
+						if(ALG_None == g_alg_context.state){
+								g_alg_context.state = ALG_Start;
+						}
+						
+						//g_VoiceOutTime = DEFAULT_VO_PERIOD-200;
+				}else{
+					  if(ALG_Triggering != g_alg_context.state){
+								g_alg_context.state = ALG_None;
+						}
+						
+						g_vo_alarm = 0;
+				
+				}
+		
+		}
+		
+}
+
+void alg_start(void)
+{
+	
+		g_alg_context.state = ALG_Calibrate;
+	
+		g_alg_context.axis_offset.x = 0.0;
+		g_alg_context.axis_offset.y = 0.0;
+		g_alg_context.axis_offset.z = 0.0;
+		g_alg_context.calibrate_count = 0;
+	
+		g_alg_context.valveclose_delay = 0;
+		g_alg_context.valveclose_times = 0;
+
+		detect_info.count = 0;
+		memset(detect_info.info, 0x00, sizeof(axis_info_t)*DETECT_CNT);
+	
+		//filter_avg.count = 0;
+		//printf("alg_start \r");
+	
+	
+}
+
+
+void alg_calibrate(axis_info_t* pAxis_info){
+	
+	g_alg_context.axis_offset.x += pAxis_info->x;
+	g_alg_context.axis_offset.y += pAxis_info->y;
+	g_alg_context.axis_offset.z += pAxis_info->z;
+	
+	g_alg_context.calibrate_count++;
+	
+	if(g_alg_context.calibrate_count == CALIBRATE_COUNT){
+		g_alg_context.axis_offset.x /= CALIBRATE_COUNT;
+		g_alg_context.axis_offset.y /= CALIBRATE_COUNT;
+		g_alg_context.axis_offset.z /= CALIBRATE_COUNT;
+		
+		g_alg_context.state = ALG_Detecting;
+		g_alg_context.calibrate_count = 0;
+		
+		//printf("X=%4.3f g Y=%4.3f g Z=%4.3f g \r", g_alg_context.axis_offset.x, g_alg_context.axis_offset.y, g_alg_context.axis_offset.z);
+	}
+	
+	
+	
+}
+
+void alg_detect(axis_info_t* paxis_info)
+{
+		uint16_t i=0;
+		uint16_t _trigger=0;
+		static uint16_t x_keepcount =0;
+		static uint16_t y_keepcount =0;
+		static uint16_t z_keepcount =0;
+		float accx_sum = 0.0;
+		float accy_sum = 0.0;
+		float accz_sum = 0.0;
+	
+		//消除零偏
+		paxis_info->x  -= g_alg_context.axis_offset.x;
+		paxis_info->y  -= g_alg_context.axis_offset.y;
+		paxis_info->z  -= g_alg_context.axis_offset.z;
+	
+		//机械滤波
+		if(fabs(paxis_info->x) <= MECHANICAL_NOISE_THRESHOLD){
+				paxis_info->x = 0.0;
+		}
+		if(fabs(paxis_info->y) <= MECHANICAL_NOISE_THRESHOLD){
+				paxis_info->y = 0.0;
+		}
+		if(fabs(paxis_info->z) <= MECHANICAL_NOISE_THRESHOLD){
+				paxis_info->z = 0.0;
+		}
+		
+	
+		detect_info.info[detect_info.count].x = paxis_info->x;
+		detect_info.info[detect_info.count].y = paxis_info->y;
+		detect_info.info[detect_info.count].z = paxis_info->z;
+	
+		for(i=0; i < DETECT_CNT; i++){
+			accx_sum += detect_info.info[i].x*0.01;
+			accy_sum += detect_info.info[i].y*0.01;
+			accz_sum += detect_info.info[i].z*0.01;
+		
+		}
+		
+		accx_sum *= 9.8;
+		accy_sum *= 9.8;
+		accz_sum *= 9.8;
+		
+		//printf("X=%4.3f g Y=%4.3f g Z=%4.3f g \r", accx_sum, accy_sum, accz_sum);
+		
+		//加速度累加值大于了 5Km/h, 需要持续 2s 去震动
+		if(fabs(accx_sum) >= DETECT_THRESHOLD){
+			x_keepcount++;
+			
+			if(KEEP_CNT == x_keepcount){
+				_trigger = 1;
+			}
+			
+		}else if(fabs(accx_sum) >= DETECT_THRESHOLD_DOWN){
+			if(x_keepcount>0){
+				x_keepcount++;
+			}
+			
+			if(KEEP_CNT == x_keepcount){
+				_trigger = 1;
+			}
+		}else{
+			x_keepcount=0;
+		}
+		
+		
+		if(fabs(accy_sum) >= DETECT_THRESHOLD){
+			y_keepcount++;
+			
+			if(KEEP_CNT == y_keepcount){
+				_trigger = 1;
+			}
+			
+		}else if(fabs(accy_sum) >= DETECT_THRESHOLD_DOWN){
+			if(y_keepcount>0){
+				y_keepcount++;
+			}
+			
+			if(KEEP_CNT == y_keepcount){
+				_trigger = 1;
+			}
+		
+		}else{
+			y_keepcount = 0;
+		}
+	
+		
+		if(fabs(accz_sum) >= DETECT_THRESHOLD){
+			z_keepcount++;
+			
+			if(KEEP_CNT == z_keepcount){
+				_trigger = 1;
+			}
+		}else if(fabs(accz_sum) >= DETECT_THRESHOLD_DOWN){
+			if(z_keepcount>0){
+				z_keepcount++;
+			}
+			
+			if(KEEP_CNT == z_keepcount){
+				_trigger = 1;
+			}
+		}else{
+			z_keepcount = 0;
+		}
+		
+		if(1 == _trigger){
+				g_alg_context.state = ALG_Triggering;
+				g_alg_context.valveclose_delay = CLOSEVALVE_DELAY;
+				sv_open();  //打开电磁阀,泄气
+				g_alg_context.valveclose_times =0;
+				g_alg_context.valveclose_interval = CLOSEVALVE_INTERVAL;
+				g_vo_alarm = 0;
+				x_keepcount = 0;
+				y_keepcount = 0;
+				z_keepcount = 0;
+		}
+		
+	
+		detect_info.count++;
+		if(detect_info.count == DETECT_CNT)
+		{
+				detect_info.count = 0;
+		}
+	
+	
+}
+
+void alg_Triggering(void)
+{
+		//时间到强制关阀
+		//底阀关闭时,就可以关阀了
+	
+		//if(BV_CLOSE == g_bvopen){
+		//		sv_close();
+		//		g_alg_context.state = ALG_Finished;
+		//		g_vo_alarm = 0;
+		//}else{
+		
+			if(0 == g_alg_context.valveclose_delay)
+			{
+					/*
+					if(1 != g_vo_alarm){
+						g_VoiceOutTime = DEFAULT_VO_PERIOD-50;
+						g_vo_alarm = 1;
+					}
+					*/
+					
+					sv_close();
+					
+					if(g_alg_context.valveclose_interval > 0){
+						g_alg_context.valveclose_interval--;
+					}else{
+						
+						if(BV_CLOSE == g_bvopen){
+							//sv_close();
+							g_alg_context.state = ALG_Finished;
+							g_vo_alarm = 0;
+							return ;
+						}
+						
+						g_alg_context.valveclose_delay = CLOSEVALVE_DELAY;
+						sv_open();  //打开电磁阀,泄气
+						g_alg_context.valveclose_times++;
+						g_alg_context.valveclose_interval = CLOSEVALVE_INTERVAL;
+					}
+						
+					
+			}
+			
+			if(g_alg_context.valveclose_times >= 3){
+				sv_close();
+				g_alg_context.state = ALG_Finished;
+				
+				if(1 != g_vo_alarm){
+						g_VoiceOutTime = DEFAULT_VO_PERIOD-10;
+						g_vo_alarm = 1;
+				}
+			}
+			
+		//}	
+		
+}
+
+void alg_Finished(void)
+{
+		//if(g_alg_context.rundelay_count == 0){
+			
+			g_alg_context.state = ALG_None;
+		//}
+}
+
+void alg_filter(axis_info_t* paxis_info)
+{
+		uint16_t i=0;
+		float x_sum = 0.0;
+		float y_sum = 0.0;
+		float z_sum = 0.0;
+	
+		filter_avg.info[filter_avg.count].x = paxis_info->x;
+		filter_avg.info[filter_avg.count].y = paxis_info->y;
+		filter_avg.info[filter_avg.count].z = paxis_info->z;
+	
+		for(i=0; i < FILTER_CNT; i++){
+			x_sum += filter_avg.info[i].x;
+			y_sum += filter_avg.info[i].y;
+			z_sum += filter_avg.info[i].z;
+		
+		}
+		
+		paxis_info->x = x_sum/FILTER_CNT;
+		paxis_info->y = y_sum/FILTER_CNT;
+		paxis_info->z = z_sum/FILTER_CNT;
+		
+		filter_avg.count++;
+		if(filter_avg.count == FILTER_CNT){
+			filter_avg.count = 0;
+		}
+	
+	
+}
+
+
+static uint16_t d_crc;
+static uint8_t d_buffer[20] = {0};
+
+void Process_Alg(void)
+{
+		alg_PreProcess();
+	
+		if(0 == cbuffer_popdata(&acc_x, &acc_y, &acc_z)){
+			
+				axis_info.x = acc_x*2.9/1000;
+				axis_info.y = acc_y*2.9/1000;
+				axis_info.z = acc_z*2.9/1000;
+			
+				alg_filter(&axis_info);
+				uint32_t start =  OSIF_GetMilliseconds();
+
+				//printf("alg:%d ms st: %d \r", start, g_alg_context.state);
+			
+			switch(g_alg_context.state){
+				case ALG_Start:
+					alg_start();
+					break;
+				case ALG_Calibrate:
+					alg_calibrate(&axis_info);
+					break;
+				case ALG_Detecting:
+					alg_detect(&axis_info);
+					break;
+				case ALG_Triggering:
+					alg_Triggering();
+					break;
+				case ALG_Finished:
+					alg_Finished();
+					break;
+				default:
+					break;
+			}
+			
+		#if 1
+		
+			if(g_send_raw){
+				
+					d_buffer[0] = 0xAA;
+					d_buffer[1] = 0xAA;
+					
+					g_send_sequence++;
+					
+					d_buffer[2] = (g_send_sequence >> 24)&0xff;
+					d_buffer[3] = (g_send_sequence >> 16)&0xff;
+					d_buffer[4] = (g_send_sequence >> 8)&0xff;
+					d_buffer[5] = (g_send_sequence >> 0)&0xff;
+					
+					d_buffer[6] = (acc_x>>8)&0xFF;
+					d_buffer[7] = (acc_x)&0xFF;
+					d_buffer[8] = (acc_y>>8)&0xFF;
+					d_buffer[9] = (acc_y)&0xFF;
+					d_buffer[10] = (acc_z>>8)&0xFF;
+					d_buffer[11] = (acc_z)&0xFF;
+					
+					d_crc = crc16(d_buffer, 12);
+					d_buffer[12] = (uint8_t)((d_crc>>8) & 0xff);
+					d_buffer[13] = (uint8_t)(d_crc & 0xff); 
+					
+					
+					Uart1_TransmitData(d_buffer, 14);
+			
+			}
+			
+				
+			
+	#endif  
+		
+		}
+	
+}
+
+

+ 142 - 0
User/process.h

@@ -0,0 +1,142 @@
+/* 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 "ac7840x.h"
+
+/*************<extern>*****************/	
+extern uint8_t	  g_bvopen;  // 0: close , 1: open
+extern uint8_t   	g_trigger_vo;
+
+extern uint8_t g_send_raw;
+extern uint8_t g_send_filtered;
+extern uint32_t g_send_sequence;
+
+
+#define BLINK_LED_MINT		(100)	/*闪烁LED灯最小时间间隔*/
+#define BLINK_LED_MAXT		(2000)	/*闪烁LED灯最大时间间隔*/
+#define BLINK_LED_DFTT		(100)	/*闪烁LED默认时间间隔*/
+#define VO_COUNT_DFTT			(50)	/*闪烁LED默认时间间隔*/
+
+#define CLOSEVALVE_DELAY  	(200)  // 打开电磁阀,泄气2秒钟
+#define CLOSEVALVE_INTERVAL (100)  /*触发关阀间隔*/
+#define CLOSEVALVE_MAXTIMES (3)  		/*最大关阀次数*/
+
+#define ALG_None    			(0)
+#define ALG_Start     		(1)
+#define ALG_Calibrate     (2)
+#define ALG_Detecting     (3)
+#define ALG_Triggering    (4)
+#define ALG_Finished    	(5)
+
+#define CALIBRATE_COUNT    (5*100)   //10秒钟
+#define RUNDELAY_COUNT			(5*60*100) //5分钟
+
+
+#define FILTER_CNT			(32)
+ 
+typedef struct {
+  float x;
+  float y;
+  float z;
+}axis_info_t;
+ 
+typedef struct _filter_avg{
+	axis_info_t info[FILTER_CNT];
+	uint8_t count;
+}filter_avg_t;
+
+
+#define DETECT_CNT   						(400) // 4s 
+#define KEEP_CNT								(80)
+#define DETECT_THRESHOLD  			(0.8)	//(1.39)  m/s   5Km/h
+#define DETECT_THRESHOLD_DOWN 	(0.2) //(0.4) // m/s2   5Km/h
+#define MECHANICAL_NOISE_THRESHOLD  (0.02) //g 
+
+typedef struct _detect_info{
+	axis_info_t info[DETECT_CNT];
+	uint16_t count;
+}detect_info_t;
+
+
+#define ACC_DATASIZE  (16)
+typedef struct
+{
+ int16_t data[3][ACC_DATASIZE];
+ uint16_t write_index;
+ uint16_t read_index;
+}circle_buffer;
+
+
+//算法三个加速度轴同时检测, 只要有一个轴的速度变化超进阈值,就触发动作。
+typedef struct 
+{
+    uint8_t  state;
+    uint16_t  valveclose_delay;  				//触发关阀持续时间
+		uint8_t  valveclose_times;  		 		//触发关阀次数 
+		uint8_t  valveclose_interval;  		  //触发关阀间隔 
+
+		uint16_t	calibrate_count;
+		//uint8_t  vo_alarm;	  				/*  是否触发语音输出*/ 
+	
+		//加速度零偏,主要是重力加速度在每个轴的分量
+		axis_info_t axis_offset;
+	
+}ALG_CONTEXT;
+
+
+void Process_Init(void);
+void Process_RunLedPrd(void); 
+void Process_Alg(void); 
+
+void timer_callback(void);
+void sv_open(void);
+void sv_close(void);
+
+
+   
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PROCESS_H */
+
+

+ 258 - 0
User/protocol.c

@@ -0,0 +1,258 @@
+#include "protocol.h"
+#include "process.h"
+#include "cfg.h"
+#include "uart.h"
+
+
+#ifdef IS_BOOTLOADER
+uint32_t Firmware_Version[4] = {1, 0, 1, 20240129};
+#else
+uint32_t Firmware_Version[4] = {1, 1, 5, 20240125};
+#endif
+
+
+uint16_t Read_FirmwareVersion(uint8_t *pBuf, uint16_t buf_len)
+{
+	int i;
+	
+	if( buf_len < 16){
+		return 0;
+	}
+	
+	for (i = 0; i < 4; ++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 16;
+	
+}
+
+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_BvStatus(uint8_t *pBuf, uint16_t buf_len)
+{
+	
+	if( buf_len < 2){
+		return 0;
+	}
+	
+	pBuf[0] = 0x00;
+	pBuf[1] = g_bvopen;
+	
+	return 2;
+
+}
+
+
+
+
+/*=======================================================================================*/
+
+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;
+	}
+}
+
+//电磁阀控制
+uint8_t Control_SValve(uint8_t *pdata, uint8_t len)
+{
+	if(len == 2){
+		
+		if(pdata[1] == 0x00){
+			sv_close();
+		}else{
+			sv_open();
+		}
+		
+		return RET_OK;
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+}
+
+//语音输出
+uint8_t Trigger_VoicOutput(uint8_t *pdata, uint8_t len)
+{
+	if(len == 2){
+		
+		g_trigger_vo = VO_COUNT_DFTT;
+		return RET_OK;
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+}
+
+//发送原始数据
+uint8_t Trigger_SendRaw(uint8_t *pdata, uint8_t len)
+{
+	if(len == 2){
+		
+		if(pdata[1] == 0x00){
+			g_send_raw = 0;
+		}else{
+			g_send_raw = 1;
+			g_send_sequence = 0;
+		}
+		
+		return RET_OK;
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+}
+
+//发送滤波后数据
+uint8_t Trigger_SendFiltered(uint8_t *pdata, uint8_t len)
+{
+	if(len == 2){
+		
+		if(pdata[1] == 0x00){
+			g_send_filtered = 0;
+		}else{
+			g_send_filtered = 1;
+			g_send_sequence = 0;
+		}
+		
+		return RET_OK;
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+}
+
+
+

+ 121 - 0
User/protocol.h

@@ -0,0 +1,121 @@
+/* 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 "ac7840x.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 Cmd_BvStatus    		 		(0x0021)
+#define Cmd_ControlSV    		 		(0x0022)
+#define Cmd_TriggerVO    		 		(0x0023)
+#define Cmd_TriggerSendRaw    	(0x0024)
+#define Cmd_TriggerSendFiltered (0x0025)
+
+
+#define Cmd_IapUpgrade    		 (0xAABB)
+
+#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_BvStatus(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); 
+
+//电磁阀控制
+uint8_t Control_SValve(uint8_t *pdata, uint8_t len); 
+
+//语音输出
+uint8_t Trigger_VoicOutput(uint8_t *pdata, uint8_t len); 
+
+//发送原始数据
+uint8_t Trigger_SendRaw(uint8_t *pdata, uint8_t len); 
+
+//发送滤波后数据
+uint8_t Trigger_SendFiltered(uint8_t *pdata, uint8_t len); 
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PROTOCOL_H */
+
+