1、初始程序

This commit is contained in:
cui635
2025-09-09 12:04:11 +08:00
parent 28ff7582ad
commit 8556e1b9ab
118 changed files with 88261 additions and 0 deletions
@@ -0,0 +1,13 @@
#ifndef __ADS1231__
#define __ADS1231__
#include "bsp.h"
void ADS1231_Open(void);
void ADS1231_SpeedSet(void);
bool ADS1231_Read(uint32_t *r_data, uint8_t channel);
void ADS1231_HighSpeedSet(void);
void ADS1231_LowSpeedSet(void);
#endif
@@ -0,0 +1,7 @@
#ifndef __EPT__
#define __EPT__
void Encrypt_Code(unsigned char *data, unsigned char *EPT_data);
void Decrypt_Code(unsigned char *EPT_data,unsigned char *DPT_data);
#endif
+232
View File
@@ -0,0 +1,232 @@
#ifndef __BSP_H
#define __BSP_H
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "hc32_ddl.h"
//#define WATCH_DOG 1
#define DEBUG 1
#define RS485 1
#define DBGUART_IRQn Int006_IRQn
#define DBGUART_EI_IRQn Int007_IRQn
#define DBG_RXPIN_IRQn Int002_IRQn
#define RS485UART_IRQn Int008_IRQn
#define RS485UART_EI_IRQn Int009_IRQn
#define RS485_RXPIN_IRQn Int005_IRQn
#define RTC_IRQn Int001_IRQn
//DEBUG
#define DBG_USART_CH (M4_USART3)
//#define DBG_USART_RX_PORT (PortA)
//#define DBG_USART_RX_PIN (Pin15)
//#define DBG_USART_TX_PORT (PortA)
//#define DBG_USART_TX_PIN (Pin12)
#define DBG_USART_RX_PORT (PortB)
#define DBG_USART_RX_PIN (Pin09)
#define DBG_USART_TX_PORT (PortB)
#define DBG_USART_TX_PIN (Pin08)
#define DBG_USART_RX_FUNC (Func_Usart3_Rx)
#define DBG_USART_TX_FUNC (Func_Usart3_Tx)
#define DBG_USART_RI_NUM (INT_USART3_RI)
#define DBG_USART_EI_NUM (INT_USART3_EI)
#define DBG_USART_TI_NUM (INT_USART3_TI)
#define DBG_USART_TCI_NUM (INT_USART3_TCI)
#define DBG_FCG1_PERIPH (PWC_FCG1_PERIPH_USART3)
#define DBG_RXPIN_EXIT_CH (ExtiCh13)
#define DBG_RXPIN_EXIT_SRC (INT_PORT_EIRQ13)
//#define DBG_USART_CH (M4_USART1)
//#define DBG_USART_RX_PORT (PortC)
//#define DBG_USART_RX_PIN (Pin13)
//#define DBG_USART_TX_PORT (PortH)
//#define DBG_USART_TX_PIN (Pin02)
//#define DBG_USART_RX_FUNC (Func_Usart1_Rx)
//#define DBG_USART_TX_FUNC (Func_Usart1_Tx)
//#define DBG_USART_RI_NUM (INT_USART1_RI)
//#define DBG_USART_EI_NUM (INT_USART1_EI)
//#define DBG_USART_TI_NUM (INT_USART1_TI)
//#define DBG_USART_TCI_NUM (INT_USART1_TCI)
//#define DBG_FCG1_PERIPH (PWC_FCG1_PERIPH_USART1)
//#define DBG_RXPIN_EXIT_CH (ExtiCh13)
//#define DBG_RXPIN_EXIT_SRC (INT_PORT_EIRQ13)
//RS485
#define RS485_USART_CH (M4_USART1)
//#define RS485_USART_RX_PORT (PortB)
//#define RS485_USART_RX_PIN (Pin08)
//#define RS485_USART_TX_PORT (PortB)
//#define RS485_USART_TX_PIN (Pin09)
#define RS485_USART_RX_PORT (PortA)
#define RS485_USART_RX_PIN (Pin15)
#define RS485_USART_TX_PORT (PortA)
#define RS485_USART_TX_PIN (Pin12)
#define RS485_USART_RX_FUNC (Func_Usart1_Rx)
#define RS485_USART_TX_FUNC (Func_Usart1_Tx)
#define RS485_USART_RI_NUM (INT_USART1_RI)
#define RS485_USART_EI_NUM (INT_USART1_EI)
#define RS485_USART_TI_NUM (INT_USART1_TI)
#define RS485_USART_TCI_NUM (INT_USART1_TCI)
#define RS485_FCG1_PERIPH (PWC_FCG1_PERIPH_USART1)
#define RS485_RXPIN_EXIT_CH (ExtiCh14)
#define RS485_RXPIN_EXIT_SRC (INT_PORT_EIRQ14)
#define RS485_CTRL_PORT (PortC)
#define RS485_CTRL_PIN (Pin13)
#define RS485_TX() PORT_SetBits(RS485_CTRL_PORT, RS485_CTRL_PIN)
#define RS485_RX() PORT_ResetBits(RS485_CTRL_PORT, RS485_CTRL_PIN)
/* LED */
#define LED_Blue_PORT (PortH)
#define LED_Blue_PIN (Pin02)
#define LED_Green_PORT (PortB)
#define LED_Green_PIN (Pin01)
/* SPI_SCK Port/Pin definition */
#define SPI_SCK_PORT (PortA)
#define SPI_SCK_PIN (Pin05)
#define SPI_SCK_FUNC (Func_Spi1_Sck)
/* SPI_MOSI Port/Pin definition */
#define SPI_MOSI_PORT (PortA)
#define SPI_MOSI_PIN (Pin04)
#define SPI_MOSI_FUNC (Func_Spi1_Mosi)
/* SPI_MISO Port/Pin definition */
#define SPI_MISO_PORT (PortA)
#define SPI_MISO_PIN (Pin02)
#define SPI_MISO_FUNC (Func_Spi1_Miso)
/* SPI_MOSI Port/Pin definition */
#define SPI_NSS_PORT (PortA)
#define SPI_NSS_PIN (Pin03)
#define SPI_NSS_FUNC (Func_Spi1_Nss0)
#define SPI_NSS_SET() PORT_SetBits(SPI_NSS_PORT, SPI_NSS_PIN)
#define SPI_NSS_CLR() PORT_ResetBits(SPI_NSS_PORT, SPI_NSS_PIN)
/* SPI unit and clock definition */
#define SPI_UNIT (M4_SPI1)
#define SPI_UNIT_CLOCK (PWC_FCG1_PERIPH_SPI1)
//SPI3
/* SPI3_SCK Port/Pin definition */
#define SPI3_SCK_PORT (PortB)
#define SPI3_SCK_PIN (Pin14)
#define SPI3_SCK_FUNC (Func_Spi3_Sck)
/* SPI3_MOSI Port/Pin definition */
#define SPI3_MOSI_PORT (PortB)
#define SPI3_MOSI_PIN (Pin10)
#define SPI3_MOSI_FUNC (Func_Spi3_Mosi)
/* SPI3_MISO Port/Pin definition */
#define SPI3_MISO_PORT (PortB)
#define SPI3_MISO_PIN (Pin12)
#define SPI3_MISO_FUNC (Func_Spi3_Miso)
/* SPI3_MOSI Port/Pin definition */
#define SPI3_NSS_PORT (PortB)
#define SPI3_NSS_PIN (Pin13)
#define SPI3_NSS_FUNC (Func_Spi3_Nss0)
#define SPI3_NSS_SET() PORT_SetBits(SPI3_NSS_PORT, SPI3_NSS_PIN)
#define SPI3_NSS_CLR() PORT_ResetBits(SPI3_NSS_PORT, SPI3_NSS_PIN)
/* SPI3 unit and clock definition */
#define SPI3_UNIT (M4_SPI3)
#define SPI3_UNIT_CLOCK (PWC_FCG1_PERIPH_SPI3)
/* SDIOC Port/Pin definition */
#define SDIOC_CD_PORT (PortA)
#define SDIOC_CD_PIN (Pin10)
#define SDIOC_CK_PORT (PortB)
#define SDIOC_CK_PIN (Pin15)
#define SDIOC_CMD_PORT (PortA)
#define SDIOC_CMD_PIN (Pin06)
#define SDIOC_D0_PORT (PortB)
#define SDIOC_D0_PIN (Pin04)
#define SDIOC_D1_PORT (PortA)
#define SDIOC_D1_PIN (Pin08)
#define SDIOC_D2_PORT (PortA)
#define SDIOC_D2_PIN (Pin09)
#define SDIOC_D3_PORT (PortB)
#define SDIOC_D3_PIN (Pin05)
/* SD sector && count */
#define SD_SECTOR_START (0u)
#define SD_SECTOR_COUNT (4u)
/* SDIOC unit */
#define SDIOC_UNIT (M4_SDIOC1)
void BSP_Init(void);
uint8_t DbgUartRec(void);
void DebugUartSend(uint8_t *sData, uint16_t sLen);
void Error_Handler(void);
void FeedDog(void);
void EnterStop(void);
void Wakeup(void);
uint8_t RS485UartRec(void);
void RS485UsartErrIrqCallback(void);
void RS485_RxPinIntCallBack(void);
void RS485UsartRxIrqCallback(void);
void RS485UartSend(uint8_t *sData, uint16_t sLen);
void RS485_1msRoutine(void);
void DbgUsartRxIrqCallback(void);
void DBGUsartErrIrqCallback(void);
void DBG_RxPinIntCallBack(void);
void SysTick_IrqHandler(void);
void RtcPeriod_IrqCallback(void);
uint16_t SpiSendReceive(uint16_t sData);
uint8_t Spi3_RWByte(M4_SPI_TypeDef *SPIx, uint8_t u8Data);
en_result_t SdioInit(void);
bool SDCardErase(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr);
bool SDCardReadBlocks(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr, uint8_t *ReadBuff);
bool SDCardWriteBlocks(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr, uint8_t *WriteBuff);
void ReadAdcValue(uint16_t *ADValue);
void ADC_Start(void) ;
void ADC_Stop(void) ;
uint16_t *GetADCBuffPoint(void);
uint8_t exf_getfree(uint8_t *drv,uint32_t *total,uint32_t *free);
uint32_t mf_showfree(uint8_t *drv);
void TimeGet(struct tm *cTime);
int TimeTs(void);
void TimeShow(uint32_t dwStamp);
void TimeSync(time_t ts) ;
#endif
@@ -0,0 +1,160 @@
/*******************************************************************************
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software component is licensed by HDSC under BSD 3-Clause license
* (the "License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*/
/******************************************************************************/
/** \file ddl_config.h
**
** A detailed description is available at
** @link DdlConfigGroup Ddl Config description @endlink
**
** - 2021-04-16 CDT First version for Device Driver Library config.
**
******************************************************************************/
#ifndef __DDL_CONFIG_H__
#define __DDL_CONFIG_H__
/*******************************************************************************
* Include files
******************************************************************************/
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup DdlConfigGroup Device Driver Library config(DDLCONFIG)
**
******************************************************************************/
//@{
/*******************************************************************************
* Global type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Global pre-processor symbols/macros ('#define')
******************************************************************************/
/*! Chip module on-off define */
#define DDL_ON (1u)
#define DDL_OFF (0u)
/**
*******************************************************************************
** \brief This is the list of modules to be used in the device driver library
** Select the modules you need to use to DDL_ON.
**
** \note DDL_ICG_ENABLE must be turned on(DDL_ON) to ensure that the chip works
** properly.
**
** \note DDL_UTILITY_ENABLE must be turned on(DDL_ON) if using Device Driver
** Library.
**
** \note DDL_PRINT_ENABLE must be turned on(DDL_ON) if using printf function.
******************************************************************************/
#define DDL_ICG_ENABLE (DDL_ON)
#define DDL_UTILITY_ENABLE (DDL_ON)
#define DDL_PRINT_ENABLE (DDL_OFF)
#define DDL_ADC_ENABLE (DDL_ON)
#define DDL_AES_ENABLE (DDL_OFF)
#define DDL_CAN_ENABLE (DDL_OFF)
#define DDL_CLK_ENABLE (DDL_ON)
#define DDL_CMP_ENABLE (DDL_OFF)
#define DDL_CRC_ENABLE (DDL_OFF)
#define DDL_DCU_ENABLE (DDL_OFF)
#define DDL_DMAC_ENABLE (DDL_ON)
#define DDL_EFM_ENABLE (DDL_ON)
#define DDL_EMB_ENABLE (DDL_OFF)
#define DDL_EVENT_PORT_ENABLE (DDL_OFF)
#define DDL_EXINT_NMI_SWI_ENABLE (DDL_ON)
#define DDL_GPIO_ENABLE (DDL_ON)
#define DDL_HASH_ENABLE (DDL_OFF)
#define DDL_I2C_ENABLE (DDL_OFF)
#define DDL_I2S_ENABLE (DDL_OFF)
#define DDL_INTERRUPTS_ENABLE (DDL_ON)
#define DDL_INTERRUPTS_SHARE_ENABLE (DDL_OFF)
#define DDL_KEYSCAN_ENABLE (DDL_OFF)
#define DDL_MPU_ENABLE (DDL_OFF)
#define DDL_OTS_ENABLE (DDL_OFF)
#define DDL_PWC_ENABLE (DDL_ON)
#define DDL_QSPI_ENABLE (DDL_OFF)
#define DDL_RMU_ENABLE (DDL_OFF)
#define DDL_RTC_ENABLE (DDL_ON)
#define DDL_SDIOC_ENABLE (DDL_ON)
#define DDL_SPI_ENABLE (DDL_ON)
#define DDL_SRAM_ENABLE (DDL_ON)
#define DDL_SWDT_ENABLE (DDL_ON)
#define DDL_TIMER0_ENABLE (DDL_OFF)
#define DDL_TIMER4_CNT_ENABLE (DDL_OFF)
#define DDL_TIMER4_EMB_ENABLE (DDL_OFF)
#define DDL_TIMER4_OCO_ENABLE (DDL_OFF)
#define DDL_TIMER4_PWM_ENABLE (DDL_OFF)
#define DDL_TIMER4_SEVT_ENABLE (DDL_OFF)
#define DDL_TIMER6_ENABLE (DDL_OFF)
#define DDL_TIMERA_ENABLE (DDL_OFF)
#define DDL_TRNG_ENABLE (DDL_OFF)
#define DDL_USART_ENABLE (DDL_ON)
#define DDL_USBFS_ENABLE (DDL_OFF)
#define DDL_WDT_ENABLE (DDL_OFF)
/*! Midware module on-off define */
#define MW_ON (1u)
#define MW_OFF (0u)
/**
*******************************************************************************
** \brief This is the list of Midware modules to use
** Select the modules you need to use to MW_ON.
******************************************************************************/
#define MW_FS_ENABLE (MW_OFF)
#define MW_SD_CARD_ENABLE (MW_OFF)
#define MW_W25QXX_ENABLE (MW_OFF)
#define MW_WM8731_ENABLE (MW_OFF)
/* BSP on-off define */
#define BSP_ON (1u)
#define BSP_OFF (0u)
/**
* @brief The following is a list of currently supported BSP boards.
*/
#define BSP_EV_HC32F460_LQFP100_V1 (1u)
#define BSP_EV_HC32F460_LQFP100_V2 (2u)
/**
* @brief The macro BSP_EV_HC32F460 is used to specify the BSP board currently
* in use.
* The value should be set to one of the list of currently supported BSP boards.
* @note If there is no supported BSP board or the BSP function is not used,
* the value needs to be set to BSP_EV_HC32F460.
*/
#define BSP_EV_HC32F460 (BSP_EV_HC32F460_LQFP100_V2)
/*******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/*******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//@} // DdlConfigGroup
#ifdef __cplusplus
}
#endif
#endif /* __DDL_CONFIG_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+24
View File
@@ -0,0 +1,24 @@
#ifndef __MAIN__H
#define __MAIN__H
#include "bsp.h"
#define USE_FILE_SYSTEM 1
#define SDCARD_BLOCK_MAX (10000)
typedef struct {
uint16_t Acc[3];
uint16_t SensorValue[4];
}SendData_t, *SendData;
typedef struct {
uint16_t ADValue[4];
uint16_t Index;
}SaveData_t, *SaveData;
#endif
+126
View File
@@ -0,0 +1,126 @@
#include "ADS1231.h"
extern float Temperature;
void ADS1231_Open(void)
{
PDWN1_SET();
PDWN2_SET();
PDWN3_SET();
PDWN4_SET();
}
void ADS1231_HighSpeedSet(void)
{
SPEED1_SET();
SPEED2_SET();
SPEED3_SET();
SPEED4_SET();
}
void ADS1231_LowSpeedSet(void)
{
SPEED1_RESET();
SPEED2_RESET();
SPEED3_RESET();
SPEED4_RESET();
}
uint32_t GpioAGetDout(en_pin_t enPin)
{
return *(uint32_t *)((uint32_t)(&M4_PORT->PIDRA)) & (enPin);
}
uint32_t GpioBGetDout(en_pin_t enPin)
{
return *(uint32_t *)((uint32_t)(&M4_PORT->PIDRB)) & (enPin);
}
bool ADS1231_Read(uint32_t *r_data, uint8_t channel) {
uint8_t i;
uint32_t data = 0;
switch(channel) {
case 0:
if(GpioAGetDout(DRDY_DOUT1_PIN) != 0)
return false;
for(i = 0; i < 24; i++) {
SCLK1_SET();
data <<= 0x01;
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
SCLK1_RESET();
if(GpioAGetDout(DRDY_DOUT1_PIN) != 0)
data |= 0x01;
}
SCLK1_SET();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
SCLK1_RESET();
break;
case 1:
if(GpioAGetDout(DRDY_DOUT2_PIN) != 0)
return false;
for(i = 0; i < 24; i++) {
SCLK2_SET();
data <<= 0x01;
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
SCLK2_RESET();
__NOP(); __NOP();
if(GpioAGetDout(DRDY_DOUT2_PIN) != 0)
data |= 0x01;
}
SCLK2_SET();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
SCLK2_RESET();
break;
case 2:
if(GpioBGetDout(DRDY_DOUT3_PIN) != 0)
return false;
for(i = 0; i < 24; i++) {
SCLK3_SET();
data <<= 0x01;
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
SCLK3_RESET();
if(GpioBGetDout(DRDY_DOUT3_PIN) != 0 )
data |= 0x01;
}
SCLK3_SET();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
SCLK3_RESET();
break;
case 3:
if(GpioBGetDout(DRDY_DOUT4_PIN) != 0 )
return false;
for(i = 0; i < 24; i++) {
SCLK4_SET();
data <<= 0x01;
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
SCLK4_RESET();
if(GpioBGetDout(DRDY_DOUT4_PIN) != 0 )
data |= 0x01;
}
SCLK4_SET();
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
SCLK4_RESET();
break;
default:
return false;
}
if(data <= 0x00ffffff) {
if(data > 0x007fffff)
*r_data = data|0xff000000;
else
*r_data = data;
}
else
return false;
return true;
}
@@ -0,0 +1,87 @@
#include "encryption.h"
//从机加密表
const unsigned char EPT_Table[32][6] = {
{1, 6, 4, 2, 3, 5}, {2, 4, 6, 3, 5, 1}, {3, 5, 6, 2, 1, 4}, {5, 3, 2, 1, 4, 6},
{4, 2, 3, 1, 5, 6}, {6, 3, 5, 1, 4, 2}, {3, 5, 2, 6, 4, 1}, {2, 5, 4, 3, 1, 6},
{2, 4, 1, 5, 3, 6}, {4, 6, 1, 3, 2, 5}, {4, 2, 1, 5, 6, 3}, {3, 2, 6, 5, 1, 4},
{2, 6, 5, 1, 4, 3}, {6, 4, 3, 1, 2, 5}, {1, 6, 3, 2, 4, 5}, {5, 3, 4, 6, 2, 1},
{5, 3, 1, 2, 6, 4}, {1, 4, 2, 6, 5, 3}, {3, 5, 2, 1, 4, 6}, {6, 1, 4, 2, 3, 5},
{4, 1, 2, 5, 3, 6}, {4, 2, 6, 3, 5, 1}, {2, 6, 1, 4, 3, 5}, {4, 3, 1, 5, 6, 2},
{5, 1, 2, 4, 6, 3}, {6, 5, 1, 3, 4, 2}, {2, 1, 6, 3, 5, 4}, {1, 5, 6, 3, 4, 2},
{3, 6, 5, 4, 2, 1}, {1, 2, 6, 3, 5, 4}, {4, 6, 5, 3, 2, 1}, {5, 3, 4, 2, 6, 1}
};
//从机解密表:
const unsigned char DPT_Table[32][5] ={
{1, 4, 2, 3, 5}, {2, 4, 3, 5, 1}, {3, 5, 2, 1, 4}, {5, 3, 2, 1, 4},
{4, 2, 3, 1, 5}, {3, 5, 1, 4, 2}, {3, 5, 2, 4, 1}, {2, 5, 4, 3, 1},
{2, 4, 1, 5, 3}, {4, 1, 3, 2, 5}, {4, 2, 1, 5, 3}, {3, 2, 5, 1, 4},
{2, 5, 1, 4, 3}, {4, 3, 1, 2, 5}, {1, 3, 2, 4, 5}, {5, 3, 4, 2, 1},
{5, 3, 1, 2, 4}, {1, 4, 2, 5, 3}, {3, 2, 1, 4, 5}, {1, 4, 5, 2, 3},
{4, 1, 2, 5, 3}, {4, 2, 3, 5, 1}, {2, 1, 4, 3, 5}, {4, 3, 1, 5, 2},
{5, 1, 2, 4, 3}, {5, 1, 3, 4, 2}, {2, 1, 3, 5, 4}, {1, 5, 3, 4, 2},
{3, 5, 4, 2, 1}, {1, 2, 3, 5, 4}, {4, 5, 3, 2, 1}, {5, 3, 4, 2, 1}
};
//数据位加密表:
const unsigned char EPT_D[32] = {
0x23, 0x4c, 0x92, 0x38, 0x52, 0xa4, 0x9a, 0x61,
0x86, 0xc8, 0x70, 0x16, 0x32, 0x58, 0x62, 0x83,
0xa5, 0x16, 0x1c, 0x49, 0x48, 0xc1, 0x8c, 0x91,
0xd0, 0x2c, 0x49, 0x42, 0xc1, 0x8c, 0x98, 0xd0
};
/****************************************************************/
/* 加密函数 */
/* */
/*函数入口: *data,未加密的普通协议数据 */
/* */
/*函数出口: *EPT_data,生成的加密协议 */
/****************************************************************/
void Encrypt_Code(unsigned char *data, unsigned char *EPT_data) {
unsigned char Edata[6];
unsigned char i = 0;
unsigned char check;
unsigned char ept_byte;
check = (data[0]+data[1]+data[2]+data[3]+data[4]+data[5]) % 0xff;
ept_byte = check % 32;
for (i = 0; i < 6; i++) {
Edata[i] = ((~(data[i] & EPT_D[ept_byte])) & EPT_D[ept_byte]) | (data[i] & (~EPT_D[ept_byte]));
}
for (i = 0; i < 6; i++) {
EPT_data[i] = Edata[EPT_Table[ept_byte][i]-1];
}
EPT_data[6] = ((~(check & 0xaa)) & 0xaa) | (check & 0x55);
}
/****************************************************************/
/* 解密函数 */
/* */
/*函数入口: *EPT_data,需要解密的加密协议 */
/* */
/*函数出口: *DPT_data,生成的普通协议 */
/****************************************************************/
void Decrypt_Code(unsigned char *EPT_data,unsigned char *DPT_data) {
unsigned char data[5];
unsigned char i = 0;
unsigned char check;
unsigned char ept_byte;
check = ((~(EPT_data[5]&0xaa))&0xaa)|(EPT_data[5]&0x55);
ept_byte = check % 32;
for(i=0;i<5;i++) {
data[i] = ((~(EPT_data[i]&EPT_D[ept_byte]))&EPT_D[ept_byte])|(EPT_data[i]&(~EPT_D[ept_byte]));
}
for(i=0;i<5;i++) {
DPT_data[DPT_Table[ept_byte][i]-1] = data[i];
}
DPT_data[5] = check;
}
File diff suppressed because it is too large Load Diff
+96
View File
@@ -0,0 +1,96 @@
#include <stdlib.h>
#include <math.h>
#include "main.h"
#include "encryption.h"
#include "Debug.h"
#define MAIN_DBG_LOG(...) DBG_LOG(__VA_ARGS__)
#define MAIN_DBG_ARRAY(ARRAY, SIZE) DBG_ARRAY(ARRAY,SIZE)
uint8_t TestData[16 * 512];
void HexToAscii(uint8_t *HexData, char *ASCData, uint8_t sLen)
{
uint8_t temp;
for(int i = 0; i < sLen; i++) {
temp = (HexData[i] >> 4) & 0x0f;
if(temp < 10)
temp += '0';
else
temp = (temp - 10) + 'A';
ASCData[i * 2] = temp;
temp = HexData[i] & 0x0f;
if(temp < 10)
temp += '0';
else
temp = (temp - 10) + 'A';
ASCData[i * 2 + 1] = temp;
}
ASCData[sLen * 2] = '\r';
ASCData[sLen * 2 + 1] = '\n';
ASCData[sLen * 2 + 2] = 0;
}
void ADC_DMA_CallBack(void)
{
}
int main(void)
{
BSP_Init();
DBG_LOG("**********************************************\r\n");
DBG_LOG("* Ver 1.0 2024-01-15 *\r\n");
DBG_LOG("**********************************************\r\n");
while(1) {
DebugLoopHandler();
}
}
/*****************************************************************************************
* 函数名称: SysTick_IrqHandler
* 功能描述: 系统滴答中断
* 参 数: 无
* 返 回 值: 无
*****************************************************************************************/
void SysTick_IrqHandler(void)
{
SysTick_IncTick();
Dbg1msRoutine();
}
/*****************************************************************************************
* 函数名称: DBG_RxPinIntCallBack
* 功能描述: DBG接收中断回调函数
* 参 数: 无
* 返 回 值: 无
*****************************************************************************************/
void DBG_RxPinIntCallBack(void)
{
PORT_Toggle(LED_Blue_PORT, LED_Blue_PIN);
}
void RtcPeriod_IrqCallback(void)
{
PORT_Toggle(LED_Green_PORT, LED_Green_PIN);
}