初始版本
This commit is contained in:
@@ -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,60 @@
|
||||
#ifndef __ALGORITHM_H
|
||||
#define __ALGORITHM_H
|
||||
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define CRC16_BASE 0xA001
|
||||
|
||||
|
||||
// 峰值谷值检查结果结构体
|
||||
typedef struct {
|
||||
bool peaks_positive; // 所有峰值是否大于0
|
||||
bool valleys_negative; // 所有谷值是否小于0
|
||||
int peak_count; // 检测到的峰值数量
|
||||
int valley_count; // 检测到的谷值数量
|
||||
} PeakValleyCheck;
|
||||
|
||||
// 趋势分析结果结构体
|
||||
typedef struct {
|
||||
double slope; // 线性斜率
|
||||
int sign_changes; // 符号变化次数
|
||||
char trend_type; // 趋势类型
|
||||
char steepness; // 陡峭度
|
||||
} TrendResult;
|
||||
|
||||
PeakValleyCheck check_peaks_valleys(int data[], int length);
|
||||
TrendResult analyze_trend(int data[], int length);
|
||||
float calculateAverage(int *arr, int size);
|
||||
double slope(int32_t *x_data, int32_t *y_data, int n) ;
|
||||
long long power(int base, unsigned int exponent);
|
||||
int IntFilter_16t(int16_t *Data, uint8_t Cnt, uint8_t FilterCnt);
|
||||
int IntFilter_32t(int32_t *Data, uint8_t Cnt, uint8_t FilterCnt);
|
||||
uint32_t IntFilter_u32t(uint32_t *Data, uint8_t Cnt, uint8_t FilterCnt);
|
||||
float IntFilter_Float(float *Data, uint8_t Cnt, uint8_t FilterCnt);
|
||||
uint32_t AverageFilter_u32t(uint32_t *Data, uint8_t Cnt);
|
||||
int AverageFilter_32t(int32_t *Data, uint8_t Cnt);
|
||||
void Fitting_Polynomial(double *AD, double *Actual, uint8_t Cnt);
|
||||
float get_K(uint8_t count , int32_t *dataCol_X, int32_t *dataRow_Y);
|
||||
int8_t TrendAnalyse(int32_t *Data, uint8_t Cnt, int32_t VPT);
|
||||
void Waveform_Up(int32_t *Data, uint8_t dCnt, uint8_t pCnt, int32_t *vlue);
|
||||
void Waveform_Down(int32_t *Data, uint8_t dCnt, uint8_t pCnt, int32_t *vlue);
|
||||
bool count_most_greater(int32_t *arr, uint8_t size, int32_t target);
|
||||
bool count_greater(int32_t *arr, uint8_t size, int32_t target);
|
||||
bool count_smaller(int32_t *arr, uint8_t size, int32_t target);
|
||||
uint16_t CRC_Modbus(uint16_t wBase, uint8_t *para, uint16_t length);
|
||||
uint8_t CRC_Sum(uint8_t *_pbuff, uint16_t _cmdLen);
|
||||
bool isAllZero(uint8_t *arr, int size);
|
||||
int fixWithMedianIterative(int arr[], int size, int windowSize, int threshold, int maxIterations, int verbose);
|
||||
int finalCheck(int arr[], int size, int threshold, int verbose);
|
||||
int weightedMovingAverageWithEnhance(int32_t arr[], int size, int windowSize,
|
||||
int enhanceStart, int enhanceEnd,
|
||||
double enhanceFactor, int verbose);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef __DEBUG_H
|
||||
#define __DEBUG_H
|
||||
|
||||
#include "bsp.h"
|
||||
|
||||
#if (USE_DEBUG != 0)
|
||||
|
||||
#define BUFSIZE 128
|
||||
#define DEBUG_BUFF_SIZE_MAX 512
|
||||
|
||||
void vcom_Send( char *format, ... );
|
||||
void vcom_Send2(uint8_t *sData, uint16_t len);
|
||||
|
||||
#define DBG_LOG2(x, y) vcom_Send2(x, y) //打印长度超过缓存DEBUG_BUFF_SIZE_MAX的信息
|
||||
#define DBG_LOG(...) vcom_Send(__VA_ARGS__)
|
||||
#define DBG_LOG_F(fmt,arg...) LOG("[%s] "fmt,__FUNCTION__,##arg)
|
||||
|
||||
#define DBG_ARRAY(ARRAY,SIZE) { \
|
||||
if(ARRAY != NULL) { \
|
||||
for(int i = 0; i < SIZE; i++) { \
|
||||
DBG_LOG("%02x ",ARRAY[i]); \
|
||||
} \
|
||||
DBG_LOG("\r\n"); \
|
||||
} \
|
||||
}
|
||||
|
||||
typedef void (*DebugExec)(int argc, char *argv[]);
|
||||
|
||||
typedef struct{
|
||||
char *DBGCmd;
|
||||
DebugExec DBGExec;
|
||||
}DBGFunType;
|
||||
|
||||
void DebugUartIRQ(char Data);
|
||||
void DebugLoopHandler(void);
|
||||
void Dbg1msRoutine(void);
|
||||
#else
|
||||
|
||||
#define DBG_LOG2(x, y)
|
||||
#define DBG_LOG(...)
|
||||
#define DBG_LOG_F(fmt,arg...)
|
||||
#define DBG_ARRAY(ARRAY,SIZE)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef __ENCRYPTION_H__
|
||||
#define __ENCRYPTION_H__
|
||||
|
||||
void Encrypt_Code(unsigned char *data, unsigned char *EPT_data);
|
||||
void Decrypt_Code(unsigned char *EPT_data,unsigned char *DPT_data);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,298 @@
|
||||
#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 USE_DEBUG 1 //DEBUG开关,0、关闭,1、启用
|
||||
#define USE_AD 1 //AD获取选择,0、关闭,1、启用
|
||||
#define USE_WDT 0 //看门狗选择,0、关闭,1启用
|
||||
#define USE_EXFALSE 0 //外部FALSE存储选择,0、关闭,1、启用
|
||||
#define USE_RTC 0 //RTC时钟开关,0、关闭,1、开启
|
||||
#define USE_LPTIM0 0 //LPTIM0开关,0、关闭,1、开启
|
||||
#define USE_DMA 1 //DMA开关,0、关闭,1、开启
|
||||
#define USE_RS485 0 //RS485开关,0、关闭,1、启用
|
||||
#define USE_I2C1 0 //I2C1开关,0、关闭,1、启用
|
||||
#define USE_SPI1 0 //SPI1开关,0、关闭,1、启用
|
||||
#define USE_SPI3 0 //SPI3开关,0、关闭,1、启用
|
||||
#define USE_USART3 1
|
||||
|
||||
#define USE_BOOTLOADER 0 //BOOTLOADER开关,0、关闭,1、启用
|
||||
|
||||
#define USE_CS1237_LEFTUP 1 //左上CS1237开关,0、关闭,1、启用
|
||||
#define USE_CS1237_LEFTLOW 1 //左下CS1237开关,0、关闭,1、启用
|
||||
#define USE_CS1237_RIGHTUP 1 //右上CS1237开关,0、关闭,1、启用
|
||||
#define USE_CS1237_RIGHTLOW 1 //右下CS1237开关,0、关闭,1、启用
|
||||
|
||||
#define USE_AGC 1 //算法控制开关,0、关闭,1、启用
|
||||
//<<---------------------------- MCU -------------------------------->>
|
||||
//< DEBUG
|
||||
#if(USE_DEBUG == 1)
|
||||
#define DBG_USART_CH (M4_USART1)
|
||||
#define DBG_USART_RX_PORT (PortA)
|
||||
#define DBG_USART_RX_PIN (Pin11)
|
||||
#define DBG_USART_TX_PORT (PortA)
|
||||
#define DBG_USART_TX_PIN (Pin12)
|
||||
#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)
|
||||
#define DBG_RX_IRQn (Int000_IRQn)
|
||||
#define DBG_ER_IRQn (Int001_IRQn)
|
||||
#endif
|
||||
//< USART3
|
||||
//#if(USE_USART3 == 1)
|
||||
//#define USAR3_CH (M4_USART3)
|
||||
//#define USAR3_RX_PORT (PortH)
|
||||
//#define USAR3_RX_PIN (Pin02)
|
||||
//#define USAR3_TX_PORT (PortC)
|
||||
//#define USAR3_TX_PIN (Pin13)
|
||||
//#define USAR3_RX_FUNC (Func_Usart3_Rx)
|
||||
//#define USAR3_TX_FUNC (Func_Usart3_Tx)
|
||||
//#define USAR3_RI_NUM (INT_USART3_RI)
|
||||
//#define USAR3_EI_NUM (INT_USART3_EI)
|
||||
//#define USAR3_TI_NUM (INT_USART3_TI)
|
||||
//#define USAR3_TCI_NUM (INT_USART3_TCI)
|
||||
//#define USAR3_FCG1_PERIPH (PWC_FCG1_PERIPH_USART3)
|
||||
//#define USAR3_RXPIN_EXIT_CH (ExtiCh14)
|
||||
//#define USAR3_RXPIN_EXIT_SRC (INT_PORT_EIRQ14)
|
||||
//#define USAR3_RX_IRQn (Int006_IRQn)
|
||||
//#define USAR3_ER_IRQn (Int007_IRQn)
|
||||
//#endif
|
||||
#if(USE_USART3 == 1)
|
||||
#define USART3_CH (M4_USART3)
|
||||
#define USART3_RX_PORT (PortH)
|
||||
#define USART3_RX_PIN (Pin02)
|
||||
#define USART3_RX_FUNC (Func_Usart3_Rx)
|
||||
#define USART3_USART_RI_NUM (INT_USART3_RI)
|
||||
#define USART3_USART_EI_NUM (INT_USART3_EI)
|
||||
#define USART3_FCG1_PERIPH (PWC_FCG1_PERIPH_USART3)
|
||||
#define USART3_RX_IRQn (Int006_IRQn)
|
||||
#define USART3_ER_IRQn (Int007_IRQn)
|
||||
//#define USART3_RXPIN_IRQn Int002_IRQn
|
||||
#endif
|
||||
|
||||
// RS485
|
||||
#if(USE_RS485 == 1)
|
||||
#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)
|
||||
#endif
|
||||
// SPI3
|
||||
#if(USE_SPI3 == 1)
|
||||
/* 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)
|
||||
#endif
|
||||
//< RTC
|
||||
#if(USE_RTC == 1)
|
||||
#define RTC_IRQn Int001_IRQn
|
||||
#endif
|
||||
//<<----------------------------- CS1237 ------------------------------->>
|
||||
//< 左上 CS1237
|
||||
#if(USE_CS1237_LEFTUP == 1)
|
||||
#define LEFTUP_CS1237_IRQn (Int001_IRQn)
|
||||
#define LEFTUP_CS1237_DOUT_PORTx (PortB)
|
||||
#define LEFTUP_CS1237_DOUT_PINx (Pin10)
|
||||
#define SET_LEFTUP_CS1237_DOUT() PORT_SetBits(LEFTUP_CS1237_DOUT_PORTx, LEFTUP_CS1237_DOUT_PINx)//拉高
|
||||
#define CLR_LEFTUP_CS1237_DOUT() PORT_ResetBits(LEFTUP_CS1237_DOUT_PORTx, LEFTUP_CS1237_DOUT_PINx)//拉低
|
||||
#define GET_LEFTUP_CS1237_DOUT() PORT_GetBit(LEFTUP_CS1237_DOUT_PORTx, LEFTUP_CS1237_DOUT_PINx)
|
||||
|
||||
#define LEFTUP_CS1237_SCLK_PORTx (PortB)
|
||||
#define LEFTUP_CS1237_SCLK_PINx (Pin02)
|
||||
#define SET_LEFTUP_CS1237_SCLK() PORT_SetBits(LEFTUP_CS1237_SCLK_PORTx, LEFTUP_CS1237_SCLK_PINx)//拉高
|
||||
#define CLR_LEFTUP_CS1237_SCLK() PORT_ResetBits(LEFTUP_CS1237_SCLK_PORTx, LEFTUP_CS1237_SCLK_PINx)//拉低
|
||||
#endif
|
||||
//< 左下 CS1237
|
||||
#if(USE_CS1237_LEFTLOW == 1)
|
||||
#define LEFTLOW_CS1237_IRQn (Int002_IRQn)
|
||||
#define LEFTLOW_CS1237_DOUT_PORTx (PortB)
|
||||
#define LEFTLOW_CS1237_DOUT_PINx (Pin01)
|
||||
#define SET_LEFTLOW_CS1237_DOUT() PORT_SetBits(LEFTLOW_CS1237_DOUT_PORTx, LEFTLOW_CS1237_DOUT_PINx)//拉高
|
||||
#define CLR_LEFTLOW_CS1237_DOUT() PORT_ResetBits(LEFTLOW_CS1237_DOUT_PORTx, LEFTLOW_CS1237_DOUT_PINx)//拉低
|
||||
#define GET_LEFTLOW_CS1237_DOUT() PORT_GetBit(LEFTLOW_CS1237_DOUT_PORTx, LEFTLOW_CS1237_DOUT_PINx)
|
||||
|
||||
#define LEFTLOW_CS1237_SCLK_PORTx (PortB)
|
||||
#define LEFTLOW_CS1237_SCLK_PINx (Pin00)
|
||||
#define SET_LEFTLOW_CS1237_SCLK() PORT_SetBits(LEFTLOW_CS1237_SCLK_PORTx, LEFTLOW_CS1237_SCLK_PINx)//拉高
|
||||
#define CLR_LEFTLOW_CS1237_SCLK() PORT_ResetBits(LEFTLOW_CS1237_SCLK_PORTx, LEFTLOW_CS1237_SCLK_PINx)//拉低
|
||||
#endif
|
||||
//< 右上 CS1237
|
||||
#if(USE_CS1237_RIGHTUP == 1)
|
||||
#define RIGHTUP_CS1237_IRQn (Int003_IRQn)
|
||||
#define RIGHTUP_CS1237_DOUT_PORTx (PortA)
|
||||
#define RIGHTUP_CS1237_DOUT_PINx (Pin04)
|
||||
#define SET_RIGHTUP_CS1237_DOUT() PORT_SetBits(RIGHTUP_CS1237_DOUT_PORTx, RIGHTUP_CS1237_DOUT_PINx)//拉高
|
||||
#define CLR_RIGHTUP_CS1237_DOUT() PORT_ResetBits(RIGHTUP_CS1237_DOUT_PORTx, RIGHTUP_CS1237_DOUT_PINx)//拉低
|
||||
#define GET_RIGHTUP_CS1237_DOUT() PORT_GetBit(RIGHTUP_CS1237_DOUT_PORTx, RIGHTUP_CS1237_DOUT_PINx)
|
||||
|
||||
#define RIGHTUP_CS1237_SCLK_PORTx (PortA)
|
||||
#define RIGHTUP_CS1237_SCLK_PINx (Pin05)
|
||||
#define SET_RIGHTUP_CS1237_SCLK() PORT_SetBits(RIGHTUP_CS1237_SCLK_PORTx, RIGHTUP_CS1237_SCLK_PINx)//拉高
|
||||
#define CLR_RIGHTUP_CS1237_SCLK() PORT_ResetBits(RIGHTUP_CS1237_SCLK_PORTx, RIGHTUP_CS1237_SCLK_PINx)//拉低
|
||||
#endif
|
||||
//< 右下 CS1237
|
||||
#if(USE_CS1237_RIGHTLOW == 1)
|
||||
#define RIGHTLOW_CS1237_IRQn (Int004_IRQn)
|
||||
#define RIGHTLOW_CS1237_DOUT_PORTx (PortA)
|
||||
#define RIGHTLOW_CS1237_DOUT_PINx (Pin06)
|
||||
#define SET_RIGHTLOW_CS1237_DOUT() PORT_SetBits(RIGHTLOW_CS1237_DOUT_PORTx, RIGHTLOW_CS1237_DOUT_PINx)//拉高
|
||||
#define CLR_RIGHTLOW_CS1237_DOUT() PORT_ResetBits(RIGHTLOW_CS1237_DOUT_PORTx, RIGHTLOW_CS1237_DOUT_PINx)//拉低
|
||||
#define GET_RIGHTLOW_CS1237_DOUT() PORT_GetBit(RIGHTLOW_CS1237_DOUT_PORTx, RIGHTLOW_CS1237_DOUT_PINx)
|
||||
|
||||
#define RIGHTLOW_CS1237_SCLK_PORTx (PortA)
|
||||
#define RIGHTLOW_CS1237_SCLK_PINx (Pin07)
|
||||
#define SET_RIGHTLOW_CS1237_SCLK() PORT_SetBits(RIGHTLOW_CS1237_SCLK_PORTx, RIGHTLOW_CS1237_SCLK_PINx)//拉高
|
||||
#define CLR_RIGHTLOW_CS1237_SCLK() PORT_ResetBits(RIGHTLOW_CS1237_SCLK_PORTx, RIGHTLOW_CS1237_SCLK_PINx)//拉低
|
||||
#endif
|
||||
|
||||
//< BIT0
|
||||
#define TWIN_BIT0_PORTx (PortB)
|
||||
#define TWIN_BIT0_PINx (Pin12)
|
||||
#define SET_TWIN_BIT0() PORT_SetBits(TWIN_BIT0_PORTx, TWIN_BIT0_PINx)//拉高
|
||||
#define CLR_TWIN_BIT0() PORT_ResetBits(TWIN_BIT0_PORTx, TWIN_BIT0_PINx)//拉低
|
||||
#define GET_BIT0_DOUT() PORT_GetBit(TWIN_BIT0_PORTx, TWIN_BIT0_PINx)
|
||||
|
||||
//< BIT1
|
||||
#define TWIN_BIT1_PORTx (PortB)
|
||||
#define TWIN_BIT1_PINx (Pin13)
|
||||
#define SET_TWIN_BIT1() PORT_SetBits(TWIN_BIT1_PORTx, TWIN_BIT1_PINx)//拉高
|
||||
#define CLR_TWIN_BIT1() PORT_ResetBits(TWIN_BIT1_PORTx, TWIN_BIT1_PINx)//拉低
|
||||
#define GET_BIT1_DOUT() PORT_GetBit(TWIN_BIT1_PORTx, TWIN_BIT1_PINx)
|
||||
|
||||
typedef struct {
|
||||
int32_t ControlLevel;//控制等级
|
||||
int32_t DBGWaveOut;//调试波形输出
|
||||
}__attribute__ ((packed))LayoutPara_t, *LayoutPara;//上位机下发的配置参数
|
||||
|
||||
typedef struct {
|
||||
LayoutPara_t Layout;
|
||||
uint32_t FactoryFlag;//出厂标志位
|
||||
}AppPara_T, *pAppPara;
|
||||
|
||||
#define SAVE_APP_PARA(addr) FlashWrite(addr, sizeof(App.Para) / 4)
|
||||
#define READ_APP_PARA(addr) FlashRead(addr, sizeof(App.Para) / 4)
|
||||
|
||||
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);
|
||||
void FlashWrite(uint32_t *wData, uint32_t wLen);
|
||||
void FlashRead(uint32_t *rData, uint32_t wLen);
|
||||
|
||||
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);
|
||||
|
||||
uint8_t Uart3Rec(void);
|
||||
void Usart3ErrIrqCallback(void);
|
||||
void Usart3_RxPinIntCallBack(void);
|
||||
void Usart3RxIrqCallback(void);
|
||||
void Usart3Send(uint8_t *sData, uint16_t sLen);
|
||||
void Uart3_Config(uint32_t BaudRate);
|
||||
|
||||
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);
|
||||
|
||||
void delay_5ns(uint32_t ns);
|
||||
|
||||
void ExtInt10IntEnable(void);
|
||||
void ExtInt10IntDisable(void);
|
||||
void ExtInt01IntEnable(void);
|
||||
void ExtInt01IntDisable(void);
|
||||
void ExtInt04IntEnable(void);
|
||||
void ExtInt04IntDisable(void);
|
||||
void ExtInt06IntEnable(void);
|
||||
void ExtInt06IntDisable(void);
|
||||
#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_OFF)
|
||||
#define DDL_SPI_ENABLE (DDL_OFF)
|
||||
#define DDL_SRAM_ENABLE (DDL_ON)
|
||||
#define DDL_SWDT_ENABLE (DDL_ON)
|
||||
#define DDL_TIMER0_ENABLE (DDL_OFF)
|
||||
#define DDL_TIMER4_CNT_ENABLE (DDL_ON)
|
||||
#define DDL_TIMER4_EMB_ENABLE (DDL_OFF)
|
||||
#define DDL_TIMER4_OCO_ENABLE (DDL_ON)
|
||||
#define DDL_TIMER4_PWM_ENABLE (DDL_ON)
|
||||
#define DDL_TIMER4_SEVT_ENABLE (DDL_OFF)
|
||||
#define DDL_TIMER6_ENABLE (DDL_ON)
|
||||
#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)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,173 @@
|
||||
#ifndef __MAIN__H
|
||||
#define __MAIN__H
|
||||
#include <stdlib.h>
|
||||
#include "bsp.h"
|
||||
|
||||
|
||||
#define USE_FILE_SYSTEM 1
|
||||
#define SDCARD_BLOCK_MAX (10000)
|
||||
|
||||
#define OSC_CNT 40
|
||||
#define SLOPE_CNT 20
|
||||
|
||||
#define SLOPE_VPT 1000
|
||||
#define PRESS_VPT 3
|
||||
#define FOLLOW_VPT 10
|
||||
#define SHIELD_VPT 5000
|
||||
#define EME_STOP_VPT 4000
|
||||
#define CENTRE_VPT 2000
|
||||
|
||||
#define STOP_TIME_MS 500
|
||||
#define RUN_TIME_MS 0
|
||||
#define EME_START_MS 0
|
||||
#define EME_STOP_MS 2000
|
||||
#define SLOPE_START_MS 3000
|
||||
|
||||
#define TRAVEL_TIME_MS 30000
|
||||
|
||||
#define PEAK 1200 //1200mm
|
||||
#define VALLEY 720 //720mm
|
||||
|
||||
#define BDC_STOP() (SET_TWIN_BIT0(),SET_TWIN_BIT1())
|
||||
#define BDC_UP() (SET_TWIN_BIT0(),CLR_TWIN_BIT1())
|
||||
#define BDC_DOWN() (SET_TWIN_BIT1(),CLR_TWIN_BIT0())
|
||||
|
||||
//#define BDC_STOP() Motor_Control(MOTOR_CMD_STOP)
|
||||
//#define BDC_UP() Motor_Control(MOTOR_CMD_FORWARD)
|
||||
//#define BDC_DOWN() Motor_Control(MOTOR_CMD_REVERSE)
|
||||
|
||||
/*控制等级*/
|
||||
typedef enum {
|
||||
LEVEL_1 = 1, // 一级
|
||||
LEVEL_2 = 2, // 二级
|
||||
LEVEL_3 = 3, // 三级
|
||||
LEVEL_4 = 4, // 四级
|
||||
LEVEL_5 = 5 // 五级
|
||||
}ControlLevel_m;
|
||||
|
||||
/*设备阈值*/
|
||||
typedef struct{
|
||||
int32_t Slope_VPT;
|
||||
int32_t Stop_VPT;
|
||||
|
||||
int32_t LeftUpVPT;//左上设备阈值
|
||||
int32_t LeftLowVPT;//左下设备阈值
|
||||
int32_t RightUpVPT;//右上设备阈值
|
||||
int32_t RightLowVPT;//右下设备阈值
|
||||
|
||||
int32_t LeftUpShieldVPT; //左上屏蔽阈值
|
||||
int32_t LeftLowShieldVPT; //左下屏蔽阈值
|
||||
int32_t RightUpShieldVPT; //右上屏蔽阈值
|
||||
int32_t RightLowShieldVPT; //右下屏蔽阈值
|
||||
|
||||
int32_t LeftUp_Org_AdZero;//左上设备原始AD零点
|
||||
int32_t LeftLow_Org_AdZero;//左下设备原始AD零点
|
||||
int32_t RightUp_Org_AdZero;//右上设备原始AD零点
|
||||
int32_t RightLow_Org_AdZero;//右下设备原始AD零点
|
||||
}ADTrack_t;
|
||||
typedef struct{//电机参数
|
||||
bool InitialFlag;//初始标志位
|
||||
bool RestFlag;
|
||||
bool CaliFlag;
|
||||
bool LoopOne;//循环一次标志位
|
||||
int16_t Current_height;//当前高度mm
|
||||
int16_t CaliNum;//标校数量
|
||||
int32_t LU_HeightStress[488];//左上传感器对应高度应力
|
||||
int32_t LL_HeightStress[488];//左下传感器对应高度应力
|
||||
int32_t RU_HeightStress[488];//右上传感器对应高度应力
|
||||
int32_t RL_HeightStress[488];//右上传感器对应高度应力
|
||||
}MotorPara_t;
|
||||
/*数据读取状态机*/
|
||||
typedef enum {
|
||||
READ_STATUS_IDLE,
|
||||
READ_STATUS_START,
|
||||
READ_STATUS_LEFTUP,
|
||||
READ_STATUS_WAIT_LEFTUP,
|
||||
READ_STATUS_LEFTLOW,
|
||||
READ_STATUS_WAIT_LEFTLOW,
|
||||
READ_STATUS_RIGHTUP,
|
||||
READ_STATUS_WAIT_RIGHTUP,
|
||||
READ_STATUS_RIGHTLOW,
|
||||
READ_STATUS_WAIT_RIGHTLOW,
|
||||
READ_STATUS_SUPPORT_CONT
|
||||
}ReadStatus_m;
|
||||
|
||||
/*主程序状态机*/
|
||||
typedef enum {
|
||||
APP_STATUS_IDLE,
|
||||
APP_STATUS_ON,
|
||||
APP_STATUS_OFF,
|
||||
APP_STATUS_MOTOR_INIT,
|
||||
APP_STATUS_WAIT_MOTOR_INIT,
|
||||
APP_STATUS_WAIT_MOTOR_CALI_UP,
|
||||
APP_STATUS_WAIT_MOTOR_CALI_DOWN,
|
||||
APP_STATUS_WAIT_STEADY,
|
||||
APP_STATUS_ZERO_MARKING,
|
||||
APP_STATUS_HEIGHT_CONTROL,
|
||||
}AppStatus_m;
|
||||
|
||||
typedef struct{
|
||||
__IO uint16_t rPayLen;
|
||||
__IO bool HeaderFrame;
|
||||
__IO uint16_t RxLen;
|
||||
uint8_t RxBuff[10];
|
||||
}Uart1Rx_t;
|
||||
|
||||
typedef struct{
|
||||
__IO uint16_t rPayLen;
|
||||
__IO bool HeaderFrame;
|
||||
__IO uint16_t RxLen;
|
||||
uint8_t RxBuff[4];
|
||||
}Uart3Rx_t;
|
||||
|
||||
typedef struct {
|
||||
AppStatus_m Status;//状态
|
||||
ReadStatus_m RStatus;
|
||||
AppPara_T Para;
|
||||
Uart1Rx_t RxUart1Data;
|
||||
Uart3Rx_t RxUart3Data;
|
||||
|
||||
ADTrack_t ADTrack;
|
||||
MotorPara_t MotorPara;
|
||||
uint32_t TD1mSDelayCnt;
|
||||
uint32_t Read1mSDelayCnt;
|
||||
uint32_t Uart1Delay1mSCnt;
|
||||
uint32_t Uart3RxTimeOut1mSCnt;
|
||||
uint32_t StopCollDelay1mSCnt;
|
||||
uint32_t RunCollDelay1mSCnt;
|
||||
uint32_t EmergencyDelay1mSCnt;
|
||||
uint32_t SlopeCollDelay1mSCnt;
|
||||
uint32_t CailUp1mSCnt;
|
||||
uint32_t HeightContRolCnt;
|
||||
uint8_t FeedDogDlyCnt;
|
||||
|
||||
bool CaliZeroFlag;//校零标志位
|
||||
bool SideFlag;//侧压标志位
|
||||
bool UpFlag;//上升标志位
|
||||
bool DownFlag;//下降标志位
|
||||
bool StopFlag;//停止标志位
|
||||
bool EmeFlag;//应急标志位
|
||||
bool LeftRunFalg;
|
||||
bool RightRunFalg;
|
||||
bool CentreRunFalg;
|
||||
|
||||
bool LeftUpCS1237ReadEndFlag;
|
||||
bool LeftLowCS1237ReadEndFlag;
|
||||
bool RightUpCS1237ReadEndFlag;
|
||||
bool RightLowCS1237ReadEndFlag;
|
||||
|
||||
int32_t LeftUpCS1237_TrendArray[OSC_CNT];
|
||||
int32_t LeftLowCS1237_TrendArray[OSC_CNT];
|
||||
int32_t RightUpCS1237_TrendArray[OSC_CNT];
|
||||
int32_t RightLowCS1237_TrendArray[OSC_CNT];
|
||||
|
||||
int32_t LeftUpCS1237_SlopeArray[SLOPE_CNT];
|
||||
int32_t LeftLowCS1237_SlopeArray[SLOPE_CNT];
|
||||
int32_t RightUpCS1237_SlopeArray[SLOPE_CNT];
|
||||
int32_t RightLowCS1237_SlopeArray[SLOPE_CNT];
|
||||
|
||||
bool WaitFlag;
|
||||
}AppDetect_t;
|
||||
extern AppDetect_t App;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user