diff --git a/Project/HC32F460/MDK/HC32F460.uvoptx b/Project/HC32F460/MDK/HC32F460.uvoptx index bb5bad4..a5fd95d 100644 --- a/Project/HC32F460/MDK/HC32F460.uvoptx +++ b/Project/HC32F460/MDK/HC32F460.uvoptx @@ -103,7 +103,7 @@ 1 0 0 - 12 + 6 @@ -114,13 +114,13 @@ - BIN\CMSIS_AGDI.dll + Segger\JL2CM3.dll 0 JL2CM3 - -U2147483647 -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 -FO15 -FD1FFF8000 -FC1000 -FN2 -FF0HC32F460_512K.FLM -FS00 -FL080000 -FP0($$Device:HC32F460JETA$FlashARM\HC32F460_512K.FLM) -FF1HC32F460_otp.FLM -FS13000C00 -FL13FC -FP1($$Device:HC32F460JETA$FlashARM\HC32F460_otp.FLM) + -U4294967295 -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 -FO15 -FD1FFF8000 -FC1000 -FN2 -FF0HC32F460_512K.FLM -FS00 -FL080000 -FP0($$Device:HC32F460JETA$FlashARM\HC32F460_512K.FLM) -FF1HC32F460_otp.FLM -FS13000C00 -FL13FC -FP1($$Device:HC32F460JETA$FlashARM\HC32F460_otp.FLM) 0 @@ -245,7 +245,35 @@ 1 Orl_diff1,0x0A + + 18 + 1 + RxBuff + + + 19 + 1 + argv + + + 20 + 1 + argv[1] + + + 21 + 1 + argc + + + + 1 + 0 + 0x1FFFA910 + 0 + + 0 diff --git a/Project/HC32F460/MDK/HC32F460.uvprojx b/Project/HC32F460/MDK/HC32F460.uvprojx index 0850732..2932607 100644 --- a/Project/HC32F460/MDK/HC32F460.uvprojx +++ b/Project/HC32F460/MDK/HC32F460.uvprojx @@ -10,7 +10,7 @@ Debug 0x4 ARM-ADS - 5060528::V5.06 update 5 (build 528)::ARMCC + 5060960::V5.06 update 7 (build 960)::ARMCC 0 @@ -330,7 +330,7 @@ 0 0 3 - 3 + 5 1 1 0 @@ -1367,8 +1367,8 @@ - - + + diff --git a/Project/HC32F460/source/User/Inc/bsp.h b/Project/HC32F460/source/User/Inc/bsp.h index 30818ae..617d990 100644 --- a/Project/HC32F460/source/User/Inc/bsp.h +++ b/Project/HC32F460/source/User/Inc/bsp.h @@ -29,6 +29,7 @@ #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) @@ -167,10 +168,17 @@ #endif typedef struct { + uint32_t ControlLevel;//控制等级 + uint32_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); @@ -179,6 +187,8 @@ 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); @@ -188,7 +198,6 @@ void RS485UartSend(uint8_t *sData, uint16_t sLen); void RS485_1msRoutine(void); - void DbgUsartRxIrqCallback(void); void DBGUsartErrIrqCallback(void); void DBG_RxPinIntCallBack(void); diff --git a/Project/HC32F460/source/User/Inc/main.h b/Project/HC32F460/source/User/Inc/main.h index 7ab3222..bad8c9f 100644 --- a/Project/HC32F460/source/User/Inc/main.h +++ b/Project/HC32F460/source/User/Inc/main.h @@ -17,7 +17,17 @@ #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; @@ -27,7 +37,7 @@ typedef struct{ int32_t RightLowVPT;//右下设备阈值 int32_t LeftUpShieldVPT; //左上屏蔽阈值 - int32_t LeftLowpShieldVPT; //左下屏蔽阈值 + int32_t LeftLowShieldVPT; //左下屏蔽阈值 int32_t RightUpShieldVPT; //右上屏蔽阈值 int32_t RightLowShieldVPT; //右下屏蔽阈值 diff --git a/Project/HC32F460/source/User/Src/Debug.c b/Project/HC32F460/source/User/Src/Debug.c index 6309eb9..5b720e1 100644 --- a/Project/HC32F460/source/User/Src/Debug.c +++ b/Project/HC32F460/source/User/Src/Debug.c @@ -214,11 +214,13 @@ void DebugCmdHelp(int argc, char *argv[]) DBG_LOG("Debug Cmd:\r\n\ disp task on/off -->Open the task display.\r\n\ help\ - dcmotor\ + motor\ + level\ + wave\ "); } - +#if 0 //// 定义一个无参函数DebugReadData,用于读取数据 //void DebugReadData(int argc, char *argv[]) //{ @@ -266,7 +268,7 @@ void DebugCmdHelp(int argc, char *argv[]) // // 调用TimeSync函数,并将num作为参数传入 // TimeSync(num); //} - +#endif extern uint8_t KeyASta; extern uint8_t KeyBSta; extern uint8_t RunSta; @@ -304,12 +306,98 @@ void MotorSwitch(int argc, char *argv[]) DBG_LOG("Motor OFF\r\n"); } } +extern void GradeControl(ControlLevel_m level); +void LevelSwitch(int argc, char *argv[]) +{ + // 如果参数个数小于2,则返回 + if(argc < 2) + return; + // 如果参数为“?”,则打印帮助信息 + if(strcmp(argv[1], "?") == 0) + { + DBG_LOG("level Cmd:\r\n\ + level 1/2/3/4/5 -->Select control level.\r\n"); + return; + } + // 如果参数为“1”,则打印“Set control level: 1” + if(strcmp(argv[1], "1") == 0) + { + App.Para.Layout.ControlLevel = LEVEL_1;//等级1 + SAVE_APP_PARA((uint32_t *)&App.Para); + DBG_LOG("Set control level: 1\r\n"); + DBG_LOG("SystemReset...\r\n"); + NVIC_SystemReset(); + } + // 如果参数为“2”,则打印“Set control level: 2” + else if(strcmp(argv[1], "2") == 0) + { + App.Para.Layout.ControlLevel = LEVEL_2;//等级2 + SAVE_APP_PARA((uint32_t *)&App.Para); + DBG_LOG("Set control level: 2\r\n"); + DBG_LOG("SystemReset...\r\n"); + NVIC_SystemReset(); + } + // 如果参数为“3”,则打印“Set control level: 1” + else if(strcmp(argv[1], "3") == 0) + { + App.Para.Layout.ControlLevel = LEVEL_3;//等级3 + SAVE_APP_PARA((uint32_t *)&App.Para); + DBG_LOG("Set control level: 3\r\n"); + DBG_LOG("SystemReset...\r\n"); + NVIC_SystemReset(); + } + // 如果参数为“4”,则打印“Set control level: 4” + else if(strcmp(argv[1], "4") == 0) + { + App.Para.Layout.ControlLevel = LEVEL_4;//等级4 + SAVE_APP_PARA((uint32_t *)&App.Para); + DBG_LOG("Set control level: 4\r\n"); + DBG_LOG("SystemReset...\r\n"); + NVIC_SystemReset(); + } + // 如果参数为“5”,则打印“Set control level: 5” + else if(strcmp(argv[1], "5") == 0) + { + App.Para.Layout.ControlLevel = LEVEL_5;//等级5 + SAVE_APP_PARA((uint32_t *)&App.Para); + DBG_LOG("Set control level: 5\r\n"); + DBG_LOG("SystemReset...\r\n"); + NVIC_SystemReset(); + } +} - - +void DBGWave_on_off(int argc, char *argv[]) +{ + // 如果参数个数小于2,则返回 + if(argc < 2) + return; + // 如果参数为“?”,则打印帮助信息 + if(strcmp(argv[1], "?") == 0) + { + DBG_LOG("wave Cmd:\r\n\ + wave on/off -->Turn on or off waveform output.\r\n"); + return; + } + // 如果参数为“on”,则打印“Test ON” + if(strcmp(argv[1], "on") == 0) + { + App.Para.Layout.DBGWaveOut = true; + SAVE_APP_PARA((uint32_t *)&App.Para); + DBG_LOG("Waveform output on.\r\n"); + } + // 如果参数为“off”,则打印“Test OFF” + else if(strcmp(argv[1], "off") == 0) + { + App.Para.Layout.DBGWaveOut = false; + SAVE_APP_PARA((uint32_t *)&App.Para); + DBG_LOG("Waveform output off.\r\n"); + } +} const DBGFunType DebugFun[DEBUG_CMD_CNT] = { "help", DebugCmdHelp, - "motor", MotorSwitch, + "motor", MotorSwitch, + "level", LevelSwitch, + "wave", DBGWave_on_off, }; #endif diff --git a/Project/HC32F460/source/User/Src/main.c b/Project/HC32F460/source/User/Src/main.c index eac3b17..6d928bb 100644 --- a/Project/HC32F460/source/User/Src/main.c +++ b/Project/HC32F460/source/User/Src/main.c @@ -21,15 +21,18 @@ AppDetect_t App; static void show(uint8_t ch,int32_t ad) { + if(App.Para.Layout.DBGWaveOut == true) + { 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); + 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) { @@ -71,7 +74,39 @@ void RIGHTLOW_CS1237AinADataProcessCallBack(int32_t AD) App.RightLowCS1237_TrendArray[0] = AD; App.RightLowCS1237ReadEndFlag = true; } -#if 1 +void GradeControl(ControlLevel_m level) +{ + switch(level){ + case LEVEL_1:{ + + break;} + + case LEVEL_2:{ + + break;} + + case LEVEL_3:{ + App.ADTrack.Slope_VPT = 2000; + App.ADTrack.LeftUpVPT = 40000; + App.ADTrack.LeftLowVPT = 40000; + App.ADTrack.RightUpVPT = 40000; + App.ADTrack.RightLowVPT = 40000; + App.ADTrack.LeftUpShieldVPT = 10000; + App.ADTrack.LeftLowShieldVPT = 10000; + App.ADTrack.RightUpShieldVPT = 10000; + App.ADTrack.RightLowShieldVPT = 10000; + break;} + + case LEVEL_4:{ + + break;} + + case LEVEL_5:{ + + break;} + } +} +#if(USE_AGC == 1) void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_t *rl_ad) { int32_t lu_diff[OSC_CNT], Olu_diff1, Olu_diff2, Olu_diff3; @@ -155,7 +190,7 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_ && (Oll_diff3 <= -App.ADTrack.LeftLowVPT))) { if((abs(Olu_diff1) > abs(Orl_diff1) + App.ADTrack.LeftUpShieldVPT) - && (abs(Oll_diff1) > abs(Oru_diff1) + App.ADTrack.LeftLowpShieldVPT)) + && (abs(Oll_diff1) > abs(Oru_diff1) + App.ADTrack.LeftLowShieldVPT)) { BDC_UP(); App.UpFlag = true; @@ -404,6 +439,19 @@ void SupportControlHandle(int32_t *lu_ad, int32_t *ll_ad, int32_t *ru_ad, int32_ #endif static void AppInit(void) { + memset(&App, 0x00, sizeof(App)); + READ_APP_PARA((uint32_t *)&App.Para); + if(App.Para.FactoryFlag != 0x00){ + App.Para.FactoryFlag = 0x00; + /*参数初始化*/ + App.Para.Layout.ControlLevel = LEVEL_3;//出厂默认等级3 + App.Para.Layout.DBGWaveOut = false; + SAVE_APP_PARA((uint32_t *)&App.Para); + } + if(App.Para.Layout.ControlLevel > 5 || App.Para.Layout.ControlLevel < 1){ + App.Para.Layout.ControlLevel = LEVEL_3;//出厂默认等级3 + SAVE_APP_PARA((uint32_t *)&App.Para); + } DBG_LOG("\r\n\r\n"); DBG_LOG("****************************************************\r\n"); DBG_LOG("** **\r\n"); @@ -423,6 +471,7 @@ static void AppInit(void) App.Status = APP_STATUS_WAIT; App.TD1mSDelayCnt = 2000; App.RStatus = READ_STATUS_START; + GradeControl(App.Para.Layout.ControlLevel);//等级控制 App.WaitFlag = false; } @@ -515,7 +564,9 @@ static void ReadLoopHandler(void) App.RightLowCS1237ReadEndFlag == true && App.WaitFlag == true) { + #if(USE_AGC == 1) SupportControlHandle(App.LeftUpCS1237_TrendArray, App.LeftLowCS1237_TrendArray, App.RightUpCS1237_TrendArray, App.RightLowCS1237_TrendArray); + #endif } App.RStatus = READ_STATUS_START; break;} @@ -546,16 +597,6 @@ static void AppLoopHandler(void) App.StopFlag = true; App.EvenRunning = false; - App.ADTrack.Slope_VPT = 2000; - App.ADTrack.LeftUpVPT = 40000; - App.ADTrack.LeftLowVPT = 40000; - App.ADTrack.RightUpVPT = 40000; - App.ADTrack.RightLowVPT = 40000; - App.ADTrack.LeftUpShieldVPT = 10000; - App.ADTrack.LeftLowpShieldVPT = 10000; - App.ADTrack.RightUpShieldVPT = 10000; - App.ADTrack.RightLowShieldVPT = 10000; - 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]; @@ -606,10 +647,18 @@ int main(void) #if(USE_DEBUG == 1) DebugLoopHandler(); #endif + #if(USE_CS1237_LEFTUP == 1) LEFTUP_CS1237DataLoopCollect(); + #endif + #if(USE_CS1237_LEFTLOW == 1) LEFTLOW_CS1237DataLoopCollect(); + #endif + #if(USE_CS1237_RIGHTUP == 1) RIGHTUP_CS1237DataLoopCollect(); + #endif + #if(USE_CS1237_RIGHTLOW == 1) RIGHTLOW_CS1237DataLoopCollect(); + #endif ReadLoopHandler(); DcmotorLoopHandler(); AppLoopHandler(); @@ -627,10 +676,20 @@ void SysTick_IrqHandler(void) SysTick_IncTick(); App1mSRoutine(); Dbg1msRoutine(); + + #if(USE_CS1237_LEFTUP == 1) LEFTUP_CS12371mSRoutine(); + #endif + #if(USE_CS1237_LEFTLOW == 1) LEFTLOW_CS12371mSRoutine(); + #endif + #if(USE_CS1237_RIGHTUP == 1) RIGHTUP_CS12371mSRoutine(); + #endif + #if(USE_CS1237_RIGHTLOW == 1) RIGHTLOW_CS12371mSRoutine(); + #endif + Dcmotor1msRoutine(); }