传感器数据采集基本完成
This commit is contained in:
@@ -746,6 +746,38 @@ bool isAllZero(uint8_t *arr, int size)
|
||||
return true; // 遍历完数组后,若所有元素都为0,则返回true
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************
|
||||
* 函数名称: HexToAscii
|
||||
* 功能描述: 16进制转ASCII码
|
||||
* 参 数: HexData,16进制数组
|
||||
ASCData,ASCII码
|
||||
sLen,数据长度
|
||||
* 返 回 值: true或false
|
||||
*****************************************************************************************/
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,23 +3,21 @@
|
||||
#include "Debug.h"
|
||||
#include "hc32f460_efm.h"
|
||||
|
||||
|
||||
#include "CS1237_LEFTUP.h"
|
||||
#include "CS1237_LEFTLOW.h"
|
||||
#include "CS1237_RIGHTUP.h"
|
||||
#include "CS1237_RIGHTLOW.h"
|
||||
|
||||
|
||||
#define SPI_MASTER_MODE
|
||||
#define SPI3_MASTER_MODE
|
||||
|
||||
|
||||
#define FLASH_WRITE_ADDR (0x0003C000u)
|
||||
|
||||
|
||||
static void SystemClockConfig(void);
|
||||
uint16_t m_au16Adc1SaValue[4];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void FlashWrite(uint32_t *wData, uint32_t wLen)
|
||||
{
|
||||
EFM_Unlock();
|
||||
@@ -85,9 +83,9 @@ static void SystemClockConfig(void)
|
||||
/* Config Xtal and Enable Xtal */
|
||||
stcXtalCfg.enMode = ClkXtalModeOsc;
|
||||
stcXtalCfg.enDrv = ClkXtalLowDrv;
|
||||
stcXtalCfg.enFastStartup = Enable;
|
||||
stcXtalCfg.enFastStartup = Disable;
|
||||
CLK_XtalConfig(&stcXtalCfg);
|
||||
CLK_XtalCmd(Enable);
|
||||
CLK_XtalCmd(Disable);
|
||||
|
||||
/* Config Hrc and enable HRC */
|
||||
CLK_HrcTrim(SystemCoreClock);
|
||||
@@ -104,13 +102,13 @@ static void SystemClockConfig(void)
|
||||
EFM_SetLatency(EFM_LATENCY_5);
|
||||
EFM_Lock();
|
||||
|
||||
/* MPLL config (XTAL / pllmDiv * plln / PllpDiv = 200M). */
|
||||
/* MPLL config (HRC / pllmDiv * plln / PllpDiv = 200M). */
|
||||
stcMpllCfg.pllmDiv = 1ul;
|
||||
stcMpllCfg.plln = 50ul;
|
||||
stcMpllCfg.plln = 25ul;
|
||||
stcMpllCfg.PllpDiv = 2ul;
|
||||
stcMpllCfg.PllqDiv = 2ul;
|
||||
stcMpllCfg.PllrDiv = 2ul;
|
||||
CLK_SetPllSource(ClkPllSrcXTAL);
|
||||
CLK_SetPllSource(ClkPllSrcHRC);
|
||||
CLK_MpllConfig(&stcMpllCfg);
|
||||
|
||||
/* Enable MPLL. */
|
||||
@@ -128,14 +126,14 @@ static void SystemClockConfig(void)
|
||||
|
||||
void FeedDog(void)
|
||||
{
|
||||
#if (USE_DEBUG == 1)
|
||||
#if (USE_WDT == 1)
|
||||
SWDT_RefreshCounter();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
* 函数名称: Xtal32_ClockConfig
|
||||
* 功能描述: 系统低速时钟配置
|
||||
* 功能描述: 外部低速时钟配置
|
||||
* 参 数: 无
|
||||
* 返 回 值: 无
|
||||
*****************************************************************************************/
|
||||
@@ -158,7 +156,14 @@ static void Xtal32_ClockConfig(void)
|
||||
/* wait for xtal32 running */
|
||||
Ddl_Delay1ms(100u);
|
||||
}
|
||||
|
||||
void delay_5ns(uint32_t ns)
|
||||
{
|
||||
for(uint32_t i = 0; i < ns; i++)
|
||||
{
|
||||
__NOP();
|
||||
}
|
||||
}
|
||||
#if(USE_RS485 == 1)
|
||||
/*****************************************************************************************
|
||||
* 函数名称: RS485Uart_Config
|
||||
* 功能描述: RS485串口初始化
|
||||
@@ -244,7 +249,6 @@ static void RS485Uart_Config(uint32_t BaudRate)
|
||||
USART_FuncCmd(RS485_USART_CH, UsartRxInt, Enable);
|
||||
}
|
||||
|
||||
|
||||
void RS485UartSend(uint8_t *sData, uint16_t sLen)
|
||||
{
|
||||
RS485_TX();
|
||||
@@ -297,7 +301,9 @@ static void RS485RxWakeupInit(void)
|
||||
NVIC_EnableIRQ(stcIrqRegiConf.enIRQn); /* Enable NVIC */
|
||||
enIntWakeupEnable(Extint2WU);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if(USE_DEBUG == 1)
|
||||
static void DbgUart_Config(uint32_t BaudRate)
|
||||
{
|
||||
stc_usart_uart_init_t stcInitCfg;
|
||||
@@ -335,7 +341,7 @@ static void DbgUart_Config(uint32_t BaudRate)
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
stcIrqRegiCfg.enIRQn = DBGUART_IRQn;
|
||||
stcIrqRegiCfg.enIRQn = DBG_RX_IRQn;
|
||||
stcIrqRegiCfg.pfnCallback = &DbgUsartRxIrqCallback;
|
||||
stcIrqRegiCfg.enIntSrc = DBG_USART_RI_NUM;
|
||||
enIrqRegistration(&stcIrqRegiCfg);
|
||||
@@ -343,9 +349,8 @@ static void DbgUart_Config(uint32_t BaudRate)
|
||||
NVIC_ClearPendingIRQ(stcIrqRegiCfg.enIRQn);
|
||||
NVIC_EnableIRQ(stcIrqRegiCfg.enIRQn);
|
||||
|
||||
|
||||
/* Set USART RX error IRQ */
|
||||
stcIrqRegiCfg.enIRQn = DBGUART_EI_IRQn;
|
||||
stcIrqRegiCfg.enIRQn = DBG_ER_IRQn;
|
||||
stcIrqRegiCfg.pfnCallback = &DBGUsartErrIrqCallback;
|
||||
stcIrqRegiCfg.enIntSrc = DBG_USART_EI_NUM;
|
||||
enIrqRegistration(&stcIrqRegiCfg);
|
||||
@@ -414,7 +419,7 @@ static void DBGRxWakeupInit(void)
|
||||
stcExtiConfig.enExtiLvl = ExIntRisingEdge;
|
||||
EXINT_Init(&stcExtiConfig);
|
||||
stcIrqRegiConf.enIntSrc = DBG_RXPIN_EXIT_SRC; /* Select External Int Ch.1 */
|
||||
stcIrqRegiConf.enIRQn = DBG_RXPIN_IRQn; /* Register External Int to Vect.No.000 */
|
||||
stcIrqRegiConf.enIRQn = DBG_RX_IRQn; /* Register External Int to Vect.No.000 */
|
||||
stcIrqRegiConf.pfnCallback = &DBG_RxPinIntCallBack; /* Callback function */
|
||||
enIrqRegistration(&stcIrqRegiConf); /* Registration IRQ */
|
||||
NVIC_ClearPendingIRQ(stcIrqRegiConf.enIRQn); /* Clear pending */
|
||||
@@ -422,36 +427,314 @@ static void DBGRxWakeupInit(void)
|
||||
NVIC_EnableIRQ(stcIrqRegiConf.enIRQn); /* Enable NVIC */
|
||||
enIntWakeupEnable(Extint2WU);
|
||||
}
|
||||
|
||||
#endif
|
||||
static void GPIO_Config(void)
|
||||
{
|
||||
stc_port_init_t stcPortInit;
|
||||
stc_port_pub_set_t stcPortPub;
|
||||
// stc_exint_config_t stcExtiConfig;
|
||||
// stc_irq_regi_conf_t stcIrqRegiConf;
|
||||
|
||||
PORT_DebugPortSetting(TDO_SWO, Disable);
|
||||
PORT_DebugPortSetting(TDI, Disable);
|
||||
PORT_DebugPortSetting(TRST, Disable);
|
||||
|
||||
MEM_ZERO_STRUCT(stcPortInit);
|
||||
MEM_ZERO_STRUCT(stcPortPub);
|
||||
|
||||
stcPortPub.enReadWait = WaitCycle3;
|
||||
PORT_PubSetting(&stcPortPub);
|
||||
|
||||
/********************************** GPIO输出 ****************************************/
|
||||
stcPortInit.enPinMode = Pin_Mode_Out;
|
||||
stcPortInit.enPinOType = Pin_OType_Cmos;
|
||||
stcPortInit.enPinDrv = Pin_Drv_H;
|
||||
stcPortInit.enPullUp = Disable;
|
||||
|
||||
PORT_Init(RS485_CTRL_PORT, RS485_CTRL_PIN, &stcPortInit);
|
||||
RS485_RX();
|
||||
|
||||
PORT_Init(LED_Blue_PORT, LED_Blue_PIN, &stcPortInit);
|
||||
PORT_Init(LED_Green_PORT, LED_Green_PIN, &stcPortInit);
|
||||
}
|
||||
stcPortInit.enPullUp = Disable;//无上拉
|
||||
|
||||
PORT_Init(LEFTUP_CS1237_SCLK_PORTx, LEFTUP_CS1237_SCLK_PINx, &stcPortInit);
|
||||
PORT_Init(LEFTLOW_CS1237_SCLK_PORTx, LEFTLOW_CS1237_SCLK_PINx, &stcPortInit);
|
||||
PORT_Init(RIGHTUP_CS1237_SCLK_PORTx, RIGHTUP_CS1237_SCLK_PINx, &stcPortInit);
|
||||
PORT_Init(RIGHTLOW_CS1237_SCLK_PORTx, RIGHTLOW_CS1237_SCLK_PINx, &stcPortInit);
|
||||
|
||||
}
|
||||
/*********************************左上传感器
|
||||
*******************************************************************************
|
||||
** \brief ExtInt00 callback function
|
||||
**
|
||||
** \param None
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
******************************************************************************/
|
||||
void ExtInt10_Callback(void)
|
||||
{
|
||||
if (Set == EXINT_IrqFlgGet(ExtiCh10))
|
||||
{
|
||||
LEFTUP_CS1237_IrqCallBack();
|
||||
EXINT_IrqFlgClr(ExtiCh10);
|
||||
}
|
||||
}
|
||||
void ExtiCh10_Init(void)
|
||||
{
|
||||
stc_exint_config_t stcExtiConfig;
|
||||
stc_irq_regi_conf_t stcIrqRegiConf;
|
||||
stc_port_init_t stcPortInit;
|
||||
|
||||
/* configuration structure initialization */
|
||||
MEM_ZERO_STRUCT(stcExtiConfig);
|
||||
MEM_ZERO_STRUCT(stcIrqRegiConf);
|
||||
MEM_ZERO_STRUCT(stcPortInit);
|
||||
|
||||
/**************************************************************************/
|
||||
/* External Int Ch.10 */
|
||||
/**************************************************************************/
|
||||
stcExtiConfig.enExitCh = ExtiCh10;
|
||||
|
||||
/* Filter setting */
|
||||
stcExtiConfig.enFilterEn = Enable;
|
||||
stcExtiConfig.enFltClk = Pclk3Div8;
|
||||
stcExtiConfig.enExtiLvl = ExIntFallingEdge;
|
||||
EXINT_Init(&stcExtiConfig);
|
||||
|
||||
/* Set External Int */
|
||||
MEM_ZERO_STRUCT(stcPortInit);
|
||||
stcPortInit.enExInt = Enable;
|
||||
PORT_Init(LEFTUP_CS1237_DOUT_PORTx, LEFTUP_CS1237_DOUT_PINx, &stcPortInit);
|
||||
|
||||
/* Select External Int Ch.10 */
|
||||
stcIrqRegiConf.enIntSrc = INT_PORT_EIRQ10;
|
||||
|
||||
/* Register External Int to Vect.No.004 */
|
||||
stcIrqRegiConf.enIRQn = LEFTUP_CS1237_IRQn;
|
||||
|
||||
/* Callback function */
|
||||
stcIrqRegiConf.pfnCallback = &ExtInt10_Callback;
|
||||
|
||||
/* Registration IRQ */
|
||||
enIrqRegistration(&stcIrqRegiConf);
|
||||
|
||||
/* Clear pending */
|
||||
NVIC_ClearPendingIRQ(stcIrqRegiConf.enIRQn);
|
||||
|
||||
/* Set priority */
|
||||
NVIC_SetPriority(stcIrqRegiConf.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
|
||||
}
|
||||
void ExtInt10IntEnable(void)
|
||||
{
|
||||
/* Enable NVIC */
|
||||
NVIC_EnableIRQ(LEFTUP_CS1237_IRQn);
|
||||
}
|
||||
void ExtInt10IntDisable(void)
|
||||
{
|
||||
/* Disable NVIC */
|
||||
NVIC_DisableIRQ(LEFTUP_CS1237_IRQn);
|
||||
}
|
||||
/*******************************左下传感器
|
||||
*******************************************************************************
|
||||
** \brief ExtInt01 callback function
|
||||
**
|
||||
** \param None
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
******************************************************************************/
|
||||
void ExtInt01_Callback(void)
|
||||
{
|
||||
if (Set == EXINT_IrqFlgGet(ExtiCh01))
|
||||
{
|
||||
LEFTLOW_CS1237_IrqCallBack();
|
||||
EXINT_IrqFlgClr(ExtiCh01);
|
||||
}
|
||||
}
|
||||
void ExtiCh01_Init(void)
|
||||
{
|
||||
stc_exint_config_t stcExtiConfig;
|
||||
stc_irq_regi_conf_t stcIrqRegiConf;
|
||||
stc_port_init_t stcPortInit;
|
||||
|
||||
/* configuration structure initialization */
|
||||
MEM_ZERO_STRUCT(stcExtiConfig);
|
||||
MEM_ZERO_STRUCT(stcIrqRegiConf);
|
||||
MEM_ZERO_STRUCT(stcPortInit);
|
||||
|
||||
/**************************************************************************/
|
||||
/* External Int Ch.1 */
|
||||
/**************************************************************************/
|
||||
stcExtiConfig.enExitCh = ExtiCh01;
|
||||
|
||||
/* Filter setting */
|
||||
stcExtiConfig.enFilterEn = Enable;
|
||||
stcExtiConfig.enFltClk = Pclk3Div8;
|
||||
stcExtiConfig.enExtiLvl = ExIntFallingEdge;
|
||||
EXINT_Init(&stcExtiConfig);
|
||||
|
||||
/* Set External Int */
|
||||
MEM_ZERO_STRUCT(stcPortInit);
|
||||
stcPortInit.enExInt = Enable;
|
||||
PORT_Init(LEFTLOW_CS1237_DOUT_PORTx, LEFTLOW_CS1237_DOUT_PINx, &stcPortInit);
|
||||
|
||||
/* Select External Int Ch.1 */
|
||||
stcIrqRegiConf.enIntSrc = INT_PORT_EIRQ1;
|
||||
|
||||
/* Register External Int to Vect.No.005 */
|
||||
stcIrqRegiConf.enIRQn = LEFTLOW_CS1237_IRQn;
|
||||
|
||||
/* Callback function */
|
||||
stcIrqRegiConf.pfnCallback = &ExtInt01_Callback;
|
||||
|
||||
/* Registration IRQ */
|
||||
enIrqRegistration(&stcIrqRegiConf);
|
||||
|
||||
/* Clear pending */
|
||||
NVIC_ClearPendingIRQ(stcIrqRegiConf.enIRQn);
|
||||
|
||||
/* Set priority */
|
||||
NVIC_SetPriority(stcIrqRegiConf.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
|
||||
}
|
||||
void ExtInt01IntEnable(void)
|
||||
{
|
||||
/* Enable NVIC */
|
||||
NVIC_EnableIRQ(LEFTLOW_CS1237_IRQn);
|
||||
}
|
||||
void ExtInt01IntDisable(void)
|
||||
{
|
||||
/* Disable NVIC */
|
||||
NVIC_DisableIRQ(LEFTLOW_CS1237_IRQn);
|
||||
}
|
||||
/*******************************右上传感器
|
||||
*******************************************************************************
|
||||
** \brief ExtInt04 callback function
|
||||
**
|
||||
** \param None
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
******************************************************************************/
|
||||
void ExtInt04_Callback(void)
|
||||
{
|
||||
if (Set == EXINT_IrqFlgGet(ExtiCh04))
|
||||
{
|
||||
RIGHTUP_CS1237_IrqCallBack();
|
||||
EXINT_IrqFlgClr(ExtiCh04);
|
||||
}
|
||||
}
|
||||
void ExtiCh04_Init(void)
|
||||
{
|
||||
stc_exint_config_t stcExtiConfig;
|
||||
stc_irq_regi_conf_t stcIrqRegiConf;
|
||||
stc_port_init_t stcPortInit;
|
||||
|
||||
/* configuration structure initialization */
|
||||
MEM_ZERO_STRUCT(stcExtiConfig);
|
||||
MEM_ZERO_STRUCT(stcIrqRegiConf);
|
||||
MEM_ZERO_STRUCT(stcPortInit);
|
||||
|
||||
/**************************************************************************/
|
||||
/* External Int Ch.4 */
|
||||
/**************************************************************************/
|
||||
stcExtiConfig.enExitCh = ExtiCh04;
|
||||
|
||||
/* Filter setting */
|
||||
stcExtiConfig.enFilterEn = Enable;
|
||||
stcExtiConfig.enFltClk = Pclk3Div8;
|
||||
stcExtiConfig.enExtiLvl = ExIntFallingEdge;
|
||||
EXINT_Init(&stcExtiConfig);
|
||||
|
||||
/* Set External Int */
|
||||
MEM_ZERO_STRUCT(stcPortInit);
|
||||
stcPortInit.enExInt = Enable;
|
||||
PORT_Init(RIGHTUP_CS1237_DOUT_PORTx, RIGHTUP_CS1237_DOUT_PINx, &stcPortInit);
|
||||
|
||||
/* Select External Int Ch.4 */
|
||||
stcIrqRegiConf.enIntSrc = INT_PORT_EIRQ4;
|
||||
|
||||
/* Register External Int to Vect.No.006 */
|
||||
stcIrqRegiConf.enIRQn = RIGHTUP_CS1237_IRQn;
|
||||
|
||||
/* Callback function */
|
||||
stcIrqRegiConf.pfnCallback = &ExtInt04_Callback;
|
||||
|
||||
/* Registration IRQ */
|
||||
enIrqRegistration(&stcIrqRegiConf);
|
||||
|
||||
/* Clear pending */
|
||||
NVIC_ClearPendingIRQ(stcIrqRegiConf.enIRQn);
|
||||
|
||||
/* Set priority */
|
||||
NVIC_SetPriority(stcIrqRegiConf.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
|
||||
}
|
||||
void ExtInt04IntEnable(void)
|
||||
{
|
||||
/* Enable NVIC */
|
||||
NVIC_EnableIRQ(RIGHTUP_CS1237_IRQn);
|
||||
}
|
||||
void ExtInt04IntDisable(void)
|
||||
{
|
||||
/* Disable NVIC */
|
||||
NVIC_DisableIRQ(RIGHTUP_CS1237_IRQn);
|
||||
}
|
||||
/*******************************右下传感器
|
||||
*******************************************************************************
|
||||
** \brief ExtInt04 callback function
|
||||
**
|
||||
** \param None
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
******************************************************************************/
|
||||
void ExtInt06_Callback(void)
|
||||
{
|
||||
if (Set == EXINT_IrqFlgGet(ExtiCh06))
|
||||
{
|
||||
RIGHTLOW_CS1237_IrqCallBack();
|
||||
EXINT_IrqFlgClr(ExtiCh06);
|
||||
}
|
||||
}
|
||||
void ExtiCh06_Init(void)
|
||||
{
|
||||
stc_exint_config_t stcExtiConfig;
|
||||
stc_irq_regi_conf_t stcIrqRegiConf;
|
||||
stc_port_init_t stcPortInit;
|
||||
|
||||
/* configuration structure initialization */
|
||||
MEM_ZERO_STRUCT(stcExtiConfig);
|
||||
MEM_ZERO_STRUCT(stcIrqRegiConf);
|
||||
MEM_ZERO_STRUCT(stcPortInit);
|
||||
|
||||
/**************************************************************************/
|
||||
/* External Int Ch.6 */
|
||||
/**************************************************************************/
|
||||
stcExtiConfig.enExitCh = ExtiCh06;
|
||||
|
||||
/* Filter setting */
|
||||
stcExtiConfig.enFilterEn = Enable;
|
||||
stcExtiConfig.enFltClk = Pclk3Div8;
|
||||
stcExtiConfig.enExtiLvl = ExIntFallingEdge;
|
||||
EXINT_Init(&stcExtiConfig);
|
||||
|
||||
/* Set External Int */
|
||||
MEM_ZERO_STRUCT(stcPortInit);
|
||||
stcPortInit.enExInt = Enable;
|
||||
PORT_Init(RIGHTLOW_CS1237_DOUT_PORTx, RIGHTLOW_CS1237_DOUT_PINx, &stcPortInit);
|
||||
|
||||
/* Select External Int Ch.6 */
|
||||
stcIrqRegiConf.enIntSrc = INT_PORT_EIRQ6;
|
||||
|
||||
/* Register External Int to Vect.No.006 */
|
||||
stcIrqRegiConf.enIRQn = RIGHTLOW_CS1237_IRQn;
|
||||
|
||||
/* Callback function */
|
||||
stcIrqRegiConf.pfnCallback = &ExtInt06_Callback;
|
||||
|
||||
/* Registration IRQ */
|
||||
enIrqRegistration(&stcIrqRegiConf);
|
||||
|
||||
/* Clear pending */
|
||||
NVIC_ClearPendingIRQ(stcIrqRegiConf.enIRQn);
|
||||
|
||||
/* Set priority */
|
||||
NVIC_SetPriority(stcIrqRegiConf.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
|
||||
}
|
||||
void ExtInt06IntEnable(void)
|
||||
{
|
||||
/* Enable NVIC */
|
||||
NVIC_EnableIRQ(RIGHTLOW_CS1237_IRQn);
|
||||
}
|
||||
void ExtInt06IntDisable(void)
|
||||
{
|
||||
/* Disable NVIC */
|
||||
NVIC_DisableIRQ(RIGHTLOW_CS1237_IRQn);
|
||||
}
|
||||
#if(USE_SPI1 == 1)
|
||||
static void Spi_Config(void)
|
||||
{
|
||||
stc_spi_init_t stcSpiInit;
|
||||
@@ -546,10 +829,10 @@ uint16_t SpiSendReceive(uint16_t sData)
|
||||
|
||||
return rData;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//SPI3
|
||||
#if(USE_SPI3 == 1)
|
||||
static void Spi3_Config(void)
|
||||
{
|
||||
stc_spi_init_t stcSpiInit;
|
||||
@@ -674,9 +957,10 @@ uint8_t Spi3_RWByte(M4_SPI_TypeDef *SPIx, uint8_t u8Data)
|
||||
}
|
||||
return SPIx->DR;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if(USE_RTC == 1)
|
||||
/*****************************************************************************************
|
||||
* 函数名称: Rtc_Config
|
||||
* 功能描述: RTC配置
|
||||
@@ -805,7 +1089,8 @@ void TimeSync(time_t ts)
|
||||
DBG_LOG("TimeSync = %d-%d-%d %d:%d:%d\n", RtcDateTime.u8Year, RtcDateTime.u8Month, \
|
||||
RtcDateTime.u8Day, RtcDateTime.u8Hour, RtcDateTime.u8Minute, RtcDateTime.u8Second);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if(USE_AD == 1)
|
||||
/*****************************************************************************************
|
||||
* 函数名称: AdcInitConfig
|
||||
* 功能描述: ADC初始化配置
|
||||
@@ -957,7 +1242,8 @@ static void AdcDmaConfig(void)
|
||||
PWC_Fcg0PeriphClockCmd(PWC_FCG0_PERIPH_AOS, Enable);
|
||||
DMA_SetTriggerSrc(M4_DMA1, DmaCh0, EVT_ADC1_EOCA);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if(USE_DMA == 1)
|
||||
/*****************************************************************************************
|
||||
* 函数名称: DmaIrqRegister
|
||||
* 功能描述: DMA中断寄存器配置
|
||||
@@ -1012,7 +1298,7 @@ static void Dma_Config(void)
|
||||
AdcDmaConfig();
|
||||
DmaIrqConfig();
|
||||
}
|
||||
|
||||
#endif
|
||||
/*****************************************************************************************
|
||||
* 函数名称: ReadAdcValue
|
||||
* 功能描述: 读取AD值
|
||||
@@ -1053,26 +1339,32 @@ void ReadAdcValue(uint16_t *ADValue)
|
||||
|
||||
void BSP_Init(void)
|
||||
{
|
||||
|
||||
stc_clk_freq_t Freq;
|
||||
SystemClockConfig();
|
||||
SystemCoreClockUpdate();
|
||||
Xtal32_ClockConfig();
|
||||
//Xtal32_ClockConfig();
|
||||
GPIO_Config();
|
||||
ExtiCh10_Init();
|
||||
ExtiCh01_Init();
|
||||
ExtiCh06_Init();
|
||||
ExtiCh04_Init();
|
||||
|
||||
DbgUart_Config(500000);
|
||||
RS485Uart_Config(9600);
|
||||
Rtc_Config();
|
||||
// SdioInit();
|
||||
//RS485Uart_Config(9600);
|
||||
|
||||
//Rtc_Config();
|
||||
//SdioInit();
|
||||
//Spi_Config();
|
||||
Spi3_Config();
|
||||
// Spi3_Config();
|
||||
|
||||
Adc1_Config();
|
||||
Dma_Config();
|
||||
FeedDog();
|
||||
SysTick_Init(1000);
|
||||
//Adc1_Config();
|
||||
//Dma_Config();
|
||||
//FeedDog();
|
||||
SysTick_Init(1000u);
|
||||
SysTick_Delay(1000);
|
||||
CLK_GetClockFreq(&Freq);
|
||||
TimeSync(1705578500);
|
||||
DBG_LOG("SysFreq = %d\r\n", Freq.sysclkFreq);
|
||||
//DBG_LOG("SysFreq = %d\r\n", Freq.sysclkFreq);
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
@@ -1087,7 +1379,7 @@ void EnterStop(void)
|
||||
stc_port_init_t stcPortInit;
|
||||
uint16_t AnaPin;
|
||||
|
||||
PWC_Fcg1PeriphClockCmd(SPI3_UNIT_CLOCK, Disable);
|
||||
//PWC_Fcg1PeriphClockCmd(SPI3_UNIT_CLOCK, Disable);
|
||||
PWC_Fcg1PeriphClockCmd(DBG_FCG1_PERIPH, Disable);
|
||||
DBGRxWakeupInit();
|
||||
|
||||
@@ -1126,12 +1418,12 @@ extern uint8_t BDRxData[256];
|
||||
*****************************************************************************************/
|
||||
void Wakeup(void)
|
||||
{
|
||||
NVIC_DisableIRQ(DBG_RXPIN_IRQn);
|
||||
NVIC_DisableIRQ(DBG_RX_IRQn);
|
||||
PWC_ClkRecover();
|
||||
//SystemClockConfig();
|
||||
Spi3_Config();
|
||||
//Spi3_Config();
|
||||
DbgUart_Config(5000000);
|
||||
RS485Uart_Config(9600);
|
||||
// RS485Uart_Config(9600);
|
||||
//GPIO_Config();
|
||||
//SysTick_Resume();
|
||||
SysTick_Init(1000);
|
||||
@@ -1148,12 +1440,10 @@ void Error_Handler(void)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if(USE_RS485 == 1)
|
||||
__WEAK void RS485UsartErrIrqCallback(void)
|
||||
{
|
||||
|
||||
if(RS485_USART_CH->SR_f.ORE) {
|
||||
RS485_USART_CH->CR1_f.CORE = 1;
|
||||
USART_RecData(RS485_USART_CH);
|
||||
@@ -1164,12 +1454,8 @@ __WEAK void RS485UsartErrIrqCallback(void)
|
||||
|
||||
if(RS485_USART_CH->SR_f.FE)
|
||||
RS485_USART_CH->CR1_f.CFE = 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
__WEAK void RS485_RxPinIntCallBack(void)
|
||||
{
|
||||
|
||||
@@ -1178,6 +1464,7 @@ __WEAK void RS485_RxPinIntCallBack(void)
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
__WEAK void DBGUsartErrIrqCallback(void)
|
||||
{
|
||||
if(DBG_USART_CH->SR_f.ORE) {
|
||||
|
||||
@@ -4,62 +4,435 @@
|
||||
#include "main.h"
|
||||
#include "Encryption.h"
|
||||
#include "Debug.h"
|
||||
|
||||
#include "Algorithm.h"
|
||||
#include "CS1237_LEFTUP.h"
|
||||
#include "CS1237_LEFTLOW.h"
|
||||
#include "CS1237_RIGHTUP.h"
|
||||
#include "CS1237_RIGHTLOW.h"
|
||||
|
||||
#define MAIN_DBG_LOG(...) DBG_LOG(__VA_ARGS__)
|
||||
#define MAIN_DBG_ARRAY(ARRAY, SIZE) DBG_ARRAY(ARRAY,SIZE)
|
||||
#define MAIN_DBG_ARRAY(ARRAY, SIZE) DBG_ARRAY(ARRAY,SIZE)
|
||||
|
||||
uint8_t TestData[16 * 512];
|
||||
#define SOFTWARE_VERSION 10 //软件版本
|
||||
#define HARDWARE_VERSION 20 //硬件版本
|
||||
|
||||
AppDetect_t App;
|
||||
|
||||
|
||||
|
||||
void HexToAscii(uint8_t *HexData, char *ASCData, uint8_t sLen)
|
||||
static void show(uint8_t ch,int32_t ad)
|
||||
{
|
||||
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;
|
||||
uint8_t bao[7];
|
||||
bao[0] = 0x5A;
|
||||
bao[1] = ch;
|
||||
bao[2] = ad & 0xFF;
|
||||
bao[3] = ad >> 8 & 0xFF;
|
||||
bao[4] = ad >> 16 & 0xFF;
|
||||
bao[5] = ad >> 24 & 0xFF;
|
||||
bao[6] = 0xA5;
|
||||
DebugUartSend(bao,7);
|
||||
}
|
||||
void LEFTUP_CS1237AinADataProcessCallBack(int32_t AD)
|
||||
{
|
||||
show(1,AD);
|
||||
for(int i = OSC_CNT-1; i > 0; i--)
|
||||
{
|
||||
App.LeftUpCS1237_TrendArray[i] = App.LeftUpCS1237_TrendArray[i - 1];
|
||||
}
|
||||
ASCData[sLen * 2] = '\r';
|
||||
ASCData[sLen * 2 + 1] = '\n';
|
||||
ASCData[sLen * 2 + 2] = 0;
|
||||
App.LeftUpCS1237_TrendArray[0] = AD;
|
||||
App.LeftUpCS1237ReadEndFlag = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ADC_DMA_CallBack(void)
|
||||
void LEFTLOW_CS1237AinADataProcessCallBack(int32_t AD)
|
||||
{
|
||||
show(2,AD);
|
||||
for(int i = OSC_CNT-1; i > 0; i--)
|
||||
{
|
||||
App.LeftLowCS1237_TrendArray[i] = App.LeftLowCS1237_TrendArray[i - 1];
|
||||
}
|
||||
App.LeftLowCS1237_TrendArray[0] = AD;
|
||||
App.LeftLowCS1237ReadEndFlag = true;
|
||||
}
|
||||
void RIGHTUP_CS1237AinADataProcessCallBack(int32_t AD)
|
||||
{
|
||||
show(3,AD);
|
||||
for(int i = OSC_CNT-1; i > 0; i--)
|
||||
{
|
||||
App.RightUpCS1237_TrendArray[i] = App.RightUpCS1237_TrendArray[i - 1];
|
||||
}
|
||||
App.RightUpCS1237_TrendArray[0] = AD;
|
||||
App.RightUpCS1237ReadEndFlag = true;
|
||||
}
|
||||
void RIGHTLOW_CS1237AinADataProcessCallBack(int32_t AD)
|
||||
{
|
||||
show(4,AD);
|
||||
for(int i = OSC_CNT-1; i > 0; i--)
|
||||
{
|
||||
App.RightLowCS1237_TrendArray[i] = App.RightLowCS1237_TrendArray[i - 1];
|
||||
}
|
||||
App.RightLowCS1237_TrendArray[0] = AD;
|
||||
App.RightLowCS1237ReadEndFlag = true;
|
||||
}
|
||||
#if 0
|
||||
void SupportControlHandle(int32_t *Ain1_ad, int32_t *Ain2_ad)
|
||||
{
|
||||
int32_t A1_diff[OSC_CNT], A2_diff[OSC_CNT], O1_diff1, O1_diff2, O1_diff3, O2_diff1, O2_diff2, O2_diff3;
|
||||
O1_diff1 = Ain1_ad[0] - App.ADTrack.Ain1_Org_AdZero;
|
||||
O1_diff2 = Ain1_ad[1] - App.ADTrack.Ain1_Org_AdZero;
|
||||
O1_diff3 = Ain1_ad[2] - App.ADTrack.Ain1_Org_AdZero;
|
||||
O2_diff1 = Ain2_ad[0] - App.ADTrack.Ain2_Org_AdZero;
|
||||
O2_diff2 = Ain2_ad[1] - App.ADTrack.Ain2_Org_AdZero;
|
||||
O2_diff3 = Ain2_ad[2] - App.ADTrack.Ain2_Org_AdZero;
|
||||
for(int i = 0; i < OSC_CNT; i++)
|
||||
{
|
||||
A1_diff[i] = Ain1_ad[i] - Ain1_ad[OSC_CNT - 1];
|
||||
A2_diff[i] = Ain2_ad[i] - Ain2_ad[OSC_CNT - 1];
|
||||
}
|
||||
TrendResult result_A1 = analyze_trend(A1_diff, OSC_CNT);
|
||||
TrendResult result_A2 = analyze_trend(A2_diff, OSC_CNT);
|
||||
|
||||
int32_t A1_slope = result_A1.slope;
|
||||
int32_t A2_slope = result_A2.slope;
|
||||
//show2(A2_slope);
|
||||
|
||||
for(int i = SLOPE_CNT-1; i > 0; i--)
|
||||
{
|
||||
App.LeftUpCS1237_SlopeArray[i] = App.LeftUpCS1237_SlopeArray[i - 1];
|
||||
App.LeftLowCS1237_SlopeArray[i] = App.LeftLowCS1237_SlopeArray[i - 1];
|
||||
}
|
||||
App.LeftUpCS1237_SlopeArray[0] = A1_slope;
|
||||
App.LeftLowCS1237_SlopeArray[0] = A2_slope;
|
||||
|
||||
PeakValleyCheck result1_K = check_peaks_valleys(App.LeftUpCS1237_SlopeArray, SLOPE_CNT);
|
||||
PeakValleyCheck result2_K = check_peaks_valleys(App.LeftLowCS1237_SlopeArray, SLOPE_CNT);
|
||||
|
||||
if(App.StopFlag == true)
|
||||
{
|
||||
if(App.StopCollDelay1mSCnt <= 0)
|
||||
{
|
||||
if(((App.LeftUpCS1237_SlopeArray[0] <= -App.ADTrack.Slope_VPT)
|
||||
&& (App.LeftUpCS1237_SlopeArray[1] <= -App.ADTrack.Slope_VPT)
|
||||
&& (App.LeftUpCS1237_SlopeArray[2] <= -App.ADTrack.Slope_VPT)
|
||||
&& (App.LeftLowCS1237_SlopeArray[0] >= App.ADTrack.Slope_VPT)
|
||||
&& (App.LeftLowCS1237_SlopeArray[1] >= App.ADTrack.Slope_VPT)
|
||||
&& (App.LeftLowCS1237_SlopeArray[2] >= App.ADTrack.Slope_VPT))
|
||||
|| ((O1_diff1 >= App.ADTrack.Ain1VPT)
|
||||
&& (O1_diff2 >= App.ADTrack.Ain1VPT)
|
||||
&& (O1_diff3 >= App.ADTrack.Ain1VPT)
|
||||
&& (O2_diff1 <= -App.ADTrack.Ain2VPT)
|
||||
&& (O2_diff2 <= -App.ADTrack.Ain2VPT)
|
||||
&& (O2_diff3 <= -App.ADTrack.Ain2VPT)))
|
||||
{
|
||||
//BDC_UP();
|
||||
App.UpFlag = true;
|
||||
App.StopFlag = false;
|
||||
App.DownFlag = false;
|
||||
}
|
||||
else if(((App.Ain1_SlopeArray[0] >= App.ADTrack.Slope_VPT)
|
||||
&& (App.Ain1_SlopeArray[1] >= App.ADTrack.Slope_VPT)
|
||||
&& (App.Ain1_SlopeArray[2] >= App.ADTrack.Slope_VPT)
|
||||
&& (App.Ain2_SlopeArray[0] <= -App.ADTrack.Slope_VPT)
|
||||
&& (App.Ain2_SlopeArray[1] <= -App.ADTrack.Slope_VPT)
|
||||
&& (App.Ain2_SlopeArray[2] <= -App.ADTrack.Slope_VPT))
|
||||
|| ((O1_diff1 <= -App.ADTrack.Ain1VPT)
|
||||
&& (O1_diff2 <= -App.ADTrack.Ain1VPT)
|
||||
&& (O1_diff3 <= -App.ADTrack.Ain1VPT)
|
||||
&& (O2_diff1 >= App.ADTrack.Ain2VPT)
|
||||
&& (O2_diff2 >= App.ADTrack.Ain2VPT)
|
||||
&& (O2_diff3 >= App.ADTrack.Ain2VPT)))
|
||||
{
|
||||
//BDC_DOWN();
|
||||
App.DownFlag = true;
|
||||
App.StopFlag = false;
|
||||
App.UpFlag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(App.DownFlag == true)
|
||||
{
|
||||
if(A1_slope < -App.ADTrack.Slope_VPT
|
||||
&& A2_slope > App.ADTrack.Slope_VPT)
|
||||
{
|
||||
//BDC_STOP();
|
||||
App.StopFlag = true;
|
||||
App.DownFlag = false;
|
||||
App.UpFlag = false;
|
||||
App.StopCollDelay1mSCnt = 1000;
|
||||
}
|
||||
else if(O1_diff1 > -(App.ADTrack.Ain1VPT / 2)
|
||||
&& O2_diff1 < (App.ADTrack.Ain2VPT / 2))
|
||||
{
|
||||
//BDC_STOP();
|
||||
App.StopFlag = true;
|
||||
App.DownFlag = false;
|
||||
App.UpFlag = false;
|
||||
App.StopCollDelay1mSCnt = 1000;
|
||||
}
|
||||
}
|
||||
else if(App.UpFlag == true)
|
||||
{
|
||||
if(A1_slope > App.ADTrack.Slope_VPT
|
||||
&& A2_slope < -App.ADTrack.Slope_VPT)
|
||||
{
|
||||
//BDC_STOP();
|
||||
App.StopFlag = true;
|
||||
App.DownFlag = false;
|
||||
App.UpFlag = false;
|
||||
App.StopCollDelay1mSCnt = 1000;
|
||||
}
|
||||
else if(O1_diff1 < (App.ADTrack.Ain1VPT / 2)
|
||||
&& O2_diff1 > -(App.ADTrack.Ain2VPT / 2))
|
||||
{
|
||||
//BDC_STOP();
|
||||
App.StopFlag = true;
|
||||
App.DownFlag = false;
|
||||
App.UpFlag = false;
|
||||
App.StopCollDelay1mSCnt = 1000;
|
||||
}
|
||||
}
|
||||
|
||||
if (result1_K.peaks_positive
|
||||
&& result1_K.valleys_negative
|
||||
&& A1_diff[0] < App.ADTrack.Slope_VPT / 2
|
||||
&& A1_diff[0] > -App.ADTrack.Slope_VPT / 2
|
||||
&& A1_diff[1] < App.ADTrack.Slope_VPT / 2
|
||||
&& A1_diff[1] > -App.ADTrack.Slope_VPT / 2
|
||||
&& A1_diff[2] < App.ADTrack.Slope_VPT / 2
|
||||
&& A1_diff[2] > -App.ADTrack.Slope_VPT / 2
|
||||
&& result2_K.peaks_positive
|
||||
&& result2_K.valleys_negative
|
||||
&& A2_diff[0] < App.ADTrack.Slope_VPT / 2
|
||||
&& A2_diff[0] > -App.ADTrack.Slope_VPT / 2
|
||||
&& A2_diff[1] < App.ADTrack.Slope_VPT / 2
|
||||
&& A2_diff[1] > -App.ADTrack.Slope_VPT / 2
|
||||
&& A2_diff[2] < App.ADTrack.Slope_VPT / 2
|
||||
&& A2_diff[2] > -App.ADTrack.Slope_VPT / 2)
|
||||
{
|
||||
if(App.StopFlag == true && App.StopCollDelay1mSCnt <= 0){
|
||||
App.ADTrack.Ain1_Org_AdZero = Ain1_ad[0];
|
||||
App.ADTrack.Ain2_Org_AdZero = Ain2_ad[0];
|
||||
}
|
||||
else if(App.StopFlag == false)
|
||||
{
|
||||
App.EvenRunning = true;
|
||||
App.EvenRunDelay1mSCnt = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
App.EvenRunning = false;
|
||||
App.EvenRunDelay1mSCnt = 0;
|
||||
}
|
||||
if(App.EvenRunDelay1mSCnt >= 2000)
|
||||
{
|
||||
App.EvenRunning = false;
|
||||
App.EvenRunDelay1mSCnt = 0;
|
||||
App.ADTrack.Ain1_Org_AdZero = Ain1_ad[0];
|
||||
App.ADTrack.Ain2_Org_AdZero = Ain2_ad[0];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
static void AppInit(void)
|
||||
{
|
||||
DBG_LOG("\r\n\r\n");
|
||||
DBG_LOG("****************************************************\r\n");
|
||||
DBG_LOG("** **\r\n");
|
||||
DBG_LOG("** Acc_Support_29V **\r\n");
|
||||
DBG_LOG("** SoftWare V:%d.%d **\r\n", SOFTWARE_VERSION / 10, SOFTWARE_VERSION % 10);
|
||||
DBG_LOG("** HardWare V:%d.%d **\r\n", HARDWARE_VERSION / 10, HARDWARE_VERSION % 10);
|
||||
DBG_LOG("** Compile: %s %s **\r\n", __DATE__, __TIME__);
|
||||
DBG_LOG("** **\r\n");
|
||||
DBG_LOG("****************************************************\r\n\r\n");
|
||||
|
||||
//FeedDog();
|
||||
LEFTUP_CS1237_Init();
|
||||
LEFTLOW_CS1237_Init();
|
||||
RIGHTUP_CS1237_Init();
|
||||
RIGHTLOW_CS1237_Init();
|
||||
|
||||
App.Status = APP_STATUS_WAIT;
|
||||
App.TD1mSDelayCnt = 2000;
|
||||
App.RStatus = READ_STATUS_START;
|
||||
}
|
||||
static void ReadLoopHandler(void)
|
||||
{
|
||||
switch(App.RStatus){
|
||||
case READ_STATUS_IDLE:{
|
||||
break;}
|
||||
|
||||
case READ_STATUS_START:{
|
||||
App.LeftUpCS1237ReadEndFlag = false;
|
||||
App.LeftLowCS1237ReadEndFlag = false;
|
||||
App.RightUpCS1237ReadEndFlag = false;
|
||||
App.RightLowCS1237ReadEndFlag = false;
|
||||
App.RStatus = READ_STATUS_LEFTUP;
|
||||
break;}
|
||||
|
||||
case READ_STATUS_LEFTUP:{
|
||||
LEFTUP_CS1237Start();
|
||||
App.Read1mSDelayCnt = 50;
|
||||
App.RStatus = READ_STATUS_WAIT_LEFTUP;
|
||||
break;}
|
||||
|
||||
case READ_STATUS_WAIT_LEFTUP:{
|
||||
if(App.Read1mSDelayCnt <= 0)
|
||||
{
|
||||
App.RStatus = READ_STATUS_LEFTLOW;
|
||||
}
|
||||
else if(App.LeftUpCS1237ReadEndFlag == true)
|
||||
{
|
||||
App.RStatus = READ_STATUS_LEFTLOW;
|
||||
}
|
||||
break;}
|
||||
|
||||
case READ_STATUS_LEFTLOW:{
|
||||
LEFTLOW_CS1237Start();
|
||||
App.Read1mSDelayCnt = 50;
|
||||
App.RStatus = READ_STATUS_WAIT_LEFTLOW;
|
||||
break;}
|
||||
|
||||
case READ_STATUS_WAIT_LEFTLOW:{
|
||||
if(App.Read1mSDelayCnt <= 0)
|
||||
{
|
||||
App.RStatus = READ_STATUS_RIGHTUP;
|
||||
}
|
||||
else if(App.LeftLowCS1237ReadEndFlag == true)
|
||||
{
|
||||
App.RStatus = READ_STATUS_RIGHTUP;
|
||||
}
|
||||
break;}
|
||||
|
||||
case READ_STATUS_RIGHTUP:{
|
||||
RIGHTUP_CS1237Start();
|
||||
App.Read1mSDelayCnt = 50;
|
||||
App.RStatus = READ_STATUS_WAIT_RIGHTUP;
|
||||
break;}
|
||||
|
||||
case READ_STATUS_WAIT_RIGHTUP:{
|
||||
if(App.Read1mSDelayCnt <= 0)
|
||||
{
|
||||
App.RStatus = READ_STATUS_RIGHTLOW;
|
||||
}
|
||||
else if(App.RightUpCS1237ReadEndFlag == true)
|
||||
{
|
||||
App.RStatus = READ_STATUS_RIGHTLOW;
|
||||
}
|
||||
break;}
|
||||
|
||||
case READ_STATUS_RIGHTLOW:{
|
||||
RIGHTLOW_CS1237Start();
|
||||
App.Read1mSDelayCnt = 50;
|
||||
App.RStatus = READ_STATUS_WAIT_RIGHTLOW;
|
||||
break;}
|
||||
|
||||
case READ_STATUS_WAIT_RIGHTLOW:{
|
||||
if(App.Read1mSDelayCnt <= 0)
|
||||
{
|
||||
App.RStatus = READ_STATUS_SUPPORT_CONT;
|
||||
}
|
||||
else if(App.RightLowCS1237ReadEndFlag == true)
|
||||
{
|
||||
App.RStatus = READ_STATUS_SUPPORT_CONT;
|
||||
}
|
||||
break;}
|
||||
|
||||
case READ_STATUS_SUPPORT_CONT:{
|
||||
if(App.LeftUpCS1237ReadEndFlag == true &&
|
||||
App.LeftLowCS1237ReadEndFlag == true &&
|
||||
App.RightUpCS1237ReadEndFlag == true &&
|
||||
App.RightLowCS1237ReadEndFlag == true)
|
||||
{
|
||||
App.LeftUpCS1237ReadEndFlag = false;
|
||||
App.LeftUpCS1237ReadEndFlag = false;
|
||||
App.RightUpCS1237ReadEndFlag = false;
|
||||
App.RightLowCS1237ReadEndFlag = false;
|
||||
//SupportControlHandle(App.Ain1_TrendArray, App.Ain2_TrendArray);
|
||||
}
|
||||
App.RStatus = READ_STATUS_START;
|
||||
break;}
|
||||
}
|
||||
}
|
||||
|
||||
static void AppLoopHandler(void)
|
||||
{
|
||||
switch(App.Status) {
|
||||
case APP_STATUS_IDLE:{
|
||||
break;}
|
||||
|
||||
case APP_STATUS_ON:{
|
||||
App.Status = APP_STATUS_IDLE;
|
||||
break;}
|
||||
|
||||
case APP_STATUS_OFF:{
|
||||
|
||||
App.Status = APP_STATUS_IDLE;
|
||||
break;}
|
||||
|
||||
case APP_STATUS_WAIT:{
|
||||
if(App.TD1mSDelayCnt <= 0)
|
||||
{
|
||||
App.UpFlag = false;
|
||||
App.DownFlag = false;
|
||||
App.StopFlag = true;
|
||||
App.EvenRunning = false;
|
||||
|
||||
App.ADTrack.Slope_VPT = 1000;
|
||||
App.ADTrack.LeftUpVPT = 20000;
|
||||
App.ADTrack.LeftLowVPT = 20000;
|
||||
App.ADTrack.RightUpVPT = 20000;
|
||||
App.ADTrack.RightLowVPT = 20000;
|
||||
|
||||
App.ADTrack.LeftUp_Org_AdZero = App.LeftUpCS1237_TrendArray[0];
|
||||
App.ADTrack.LeftLow_Org_AdZero = App.LeftLowCS1237_TrendArray[0];
|
||||
App.ADTrack.RightUp_Org_AdZero = App.RightUpCS1237_TrendArray[0];
|
||||
App.ADTrack.RightLow_Org_AdZero = App.RightLowCS1237_TrendArray[0];
|
||||
DBG_LOG("Frist Pack Data LeftUp Zero AD: %08d\tLeftUp Zero AD: %08d\tRightUp Zero AD: %08d\tRightLow Zero AD: %08d\r\n",
|
||||
App.ADTrack.LeftUp_Org_AdZero,
|
||||
App.ADTrack.LeftLow_Org_AdZero,
|
||||
App.ADTrack.RightUp_Org_AdZero,
|
||||
App.ADTrack.RightLow_Org_AdZero);
|
||||
App.Status = APP_STATUS_IDLE;
|
||||
}
|
||||
break;}
|
||||
}
|
||||
}
|
||||
static void App1mSRoutine(void)
|
||||
{
|
||||
if(App.TD1mSDelayCnt > 0)
|
||||
App.TD1mSDelayCnt--;
|
||||
if(App.Read1mSDelayCnt > 0)
|
||||
App.Read1mSDelayCnt--;
|
||||
if(App.Uart1Delay1mSCnt > 0)
|
||||
App.Uart1Delay1mSCnt--;
|
||||
if(App.StopCollDelay1mSCnt > 0)
|
||||
App.StopCollDelay1mSCnt--;
|
||||
|
||||
if(App.EvenRunning == true)
|
||||
App.EvenRunDelay1mSCnt++;
|
||||
|
||||
|
||||
|
||||
|
||||
App.FeedDogDlyCnt++;
|
||||
}
|
||||
void FeedDogHandler(void)
|
||||
{
|
||||
if(App.FeedDogDlyCnt >= 200) {
|
||||
FeedDog();
|
||||
App.FeedDogDlyCnt = 0;
|
||||
}
|
||||
}
|
||||
int main(void)
|
||||
{
|
||||
BSP_Init();
|
||||
DBG_LOG("**********************************************\r\n");
|
||||
DBG_LOG("* Ver 1.0 2024-01-15 *\r\n");
|
||||
DBG_LOG("**********************************************\r\n");
|
||||
AppInit();
|
||||
while(1) {
|
||||
#if(USE_WDT == 1)
|
||||
FeedDogHandler();
|
||||
#endif
|
||||
#if(USE_DEBUG == 1)
|
||||
DebugLoopHandler();
|
||||
#endif
|
||||
LEFTUP_CS1237DataLoopCollect();
|
||||
LEFTLOW_CS1237DataLoopCollect();
|
||||
RIGHTUP_CS1237DataLoopCollect();
|
||||
RIGHTLOW_CS1237DataLoopCollect();
|
||||
ReadLoopHandler();
|
||||
AppLoopHandler();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +445,12 @@ int main(void)
|
||||
void SysTick_IrqHandler(void)
|
||||
{
|
||||
SysTick_IncTick();
|
||||
App1mSRoutine();
|
||||
Dbg1msRoutine();
|
||||
LEFTUP_CS12371mSRoutine();
|
||||
LEFTLOW_CS12371mSRoutine();
|
||||
RIGHTUP_CS12371mSRoutine();
|
||||
RIGHTLOW_CS12371mSRoutine();
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
@@ -93,4 +471,7 @@ void RtcPeriod_IrqCallback(void)
|
||||
//PORT_Toggle(LED_Green_PORT, LED_Green_PIN);
|
||||
}
|
||||
|
||||
void ADC_DMA_CallBack(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user