提交 | 用户 | age
|
8b51c7
|
1 |
|
Q |
2 |
/** |
|
3 |
****************************************************************************** |
|
4 |
* @file : main.c |
|
5 |
* @brief : Main program body |
|
6 |
****************************************************************************** |
|
7 |
** This notice applies to any and all portions of this file |
|
8 |
* that are not between comment pairs USER CODE BEGIN and |
|
9 |
* USER CODE END. Other portions of this file, whether |
|
10 |
* inserted by the user or by software development tools |
|
11 |
* are owned by their respective copyright owners. |
|
12 |
* |
|
13 |
* COPYRIGHT(c) 2018 STMicroelectronics |
|
14 |
* |
|
15 |
* Redistribution and use in source and binary forms, with or without modification, |
|
16 |
* are permitted provided that the following conditions are met: |
|
17 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
18 |
* this list of conditions and the following disclaimer. |
|
19 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
20 |
* this list of conditions and the following disclaimer in the documentation |
|
21 |
* and/or other materials provided with the distribution. |
|
22 |
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
|
23 |
* may be used to endorse or promote products derived from this software |
|
24 |
* without specific prior written permission. |
|
25 |
* |
|
26 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
27 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
28 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
29 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
|
30 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
31 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
32 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
33 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
34 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
35 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
36 |
* |
|
37 |
****************************************************************************** |
|
38 |
*/ |
|
39 |
/* Includes ------------------------------------------------------------------*/ |
|
40 |
#include "main.h" |
|
41 |
#include "stm32f0xx_hal.h" |
|
42 |
|
|
43 |
/* USER CODE BEGIN Includes */ |
|
44 |
#include "Globaldef.h" |
|
45 |
#include "debug.h" |
|
46 |
#include "Functions.h" |
|
47 |
#include "KMachine.h" |
|
48 |
#include "PLCfunctions.h" |
|
49 |
//#include "KBus.h" |
|
50 |
#include "KLink.h" |
|
51 |
#include "string.h" |
|
52 |
#include "BSP.h" |
|
53 |
#include "ModbusRTU.h" |
|
54 |
#if (BOARD_TYPE == 13) |
|
55 |
#include "w5500_port.h" |
|
56 |
#include "../src/Ethernet/socket.h" |
|
57 |
#include "../src/Ethernet/loopback.h" |
|
58 |
#elif (BOARD_TYPE == 14) |
5dd1b7
|
59 |
#include "FPx.h" |
8b51c7
|
60 |
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
Q |
61 |
#include "KWireless.h" |
|
62 |
//#include "user.h" |
|
63 |
//#include "../src/radio/inc/sx126x-board.h" |
|
64 |
#endif |
|
65 |
#include "SLP.h" |
5dd1b7
|
66 |
//#include "YDLidar.h" |
Q |
67 |
#include "OrdLidar.h" |
8b51c7
|
68 |
|
Q |
69 |
/* USER CODE END Includes */ |
|
70 |
|
|
71 |
/* Private variables ---------------------------------------------------------*/ |
|
72 |
|
|
73 |
/* USER CODE BEGIN PV */ |
|
74 |
/* Private variables ---------------------------------------------------------*/ |
|
75 |
|
|
76 |
#define RX2BUFSIZE 64 |
|
77 |
#define TX2BUFSIZE 64 |
|
78 |
|
|
79 |
|
5dd1b7
|
80 |
unsigned char Uart1RxBuf[RX1BUFSIZE]; |
Q |
81 |
unsigned char Uart1TxBuf[TX1BUFSIZE]; |
8b51c7
|
82 |
|
Q |
83 |
unsigned char Uart2RxBuf[RX2BUFSIZE]; |
|
84 |
unsigned char Uart2TxBuf[TX2BUFSIZE]; |
|
85 |
|
|
86 |
unsigned char SlowFlicker=0; |
|
87 |
unsigned char FastFlicker=0; |
|
88 |
|
|
89 |
unsigned int Uart1IdelTimer = 0; |
842bb6
|
90 |
#if (ENABLE_PLC) |
8b51c7
|
91 |
stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; |
842bb6
|
92 |
#endif |
8b51c7
|
93 |
|
Q |
94 |
uint32_t us1,us2,us3,us4,us5,us6; |
|
95 |
|
842bb6
|
96 |
stKBusDef KBus1; // |
Q |
97 |
|
|
98 |
extern stDeviceInfo MyDeviceInfo; |
|
99 |
|
|
100 |
unsigned char bSLPMaster =1; |
|
101 |
unsigned char nSLPStation = 1; |
|
102 |
|
|
103 |
stSLPDef SLP1; |
8b51c7
|
104 |
/* USER CODE END PV */ |
Q |
105 |
|
|
106 |
/* Private function prototypes -----------------------------------------------*/ |
|
107 |
|
|
108 |
|
|
109 |
/* USER CODE BEGIN PFP */ |
|
110 |
/* Private function prototypes -----------------------------------------------*/ |
|
111 |
|
|
112 |
const unsigned char LEDSEGTAB[]={ |
|
113 |
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71, //0-F |
|
114 |
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1, //0.-F. |
|
115 |
0x00,0x40, // ,-,_,~,o,n,N,<,>,J,r, |
|
116 |
}; |
|
117 |
|
|
118 |
/* USER CODE END PFP */ |
|
119 |
|
|
120 |
/* USER CODE BEGIN 0 */ |
|
121 |
|
|
122 |
int HexToInt(char ch) |
|
123 |
{ |
|
124 |
if (ch>='0' && ch <='9') return ch-'0'; |
|
125 |
if (ch>='A' && ch <='F') return ch-'A'+10; |
|
126 |
if (ch>='a' && ch <='f') return ch-'a'+10; |
|
127 |
return 0; |
|
128 |
} |
|
129 |
|
|
130 |
void HAL_SYSTICK_Callback(void) |
|
131 |
{ |
|
132 |
static int Count=0; |
|
133 |
CurTickuS += 100; |
|
134 |
nCurTick++; |
842bb6
|
135 |
KBus1.nSlaveTick++; |
8b51c7
|
136 |
Count++; |
Q |
137 |
if (Count>=10000) |
|
138 |
{ |
|
139 |
Count=0; |
|
140 |
KMem.CurTimeSec++; |
|
141 |
KMem.ThisRunTime++; KMem.TotalRunTime++; |
|
142 |
if (KMRunStat.bLEDFlick) KMRunStat.bLEDFlick--; |
|
143 |
if (KMRunStat.bLEDFlick >120) KMRunStat.bLEDFlick=120; |
|
144 |
} |
|
145 |
|
|
146 |
return; |
|
147 |
} |
|
148 |
|
842bb6
|
149 |
void PendSvCallBack() |
Q |
150 |
{ |
|
151 |
#if (BOARD_TYPE == 14) |
|
152 |
///* |
|
153 |
if (bSPI1RecvDone) |
|
154 |
{ |
|
155 |
bSPI1RecvDone=0; |
|
156 |
FPxParsePkt(SPI1RecvBuf,nSPI1RecvLenInBuf); |
|
157 |
} |
|
158 |
//*/ |
|
159 |
#endif |
|
160 |
if (Uart2Stat.bPacketRecved) |
|
161 |
{ |
|
162 |
KBusParsePacket(&KBus1, (pKBPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); |
|
163 |
Uart2RecvBuf1DataLen=0; |
|
164 |
Uart2Stat.bPacketRecved=0; |
|
165 |
Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
|
166 |
} |
|
167 |
} |
|
168 |
|
|
169 |
void * KBusEvCallBackFunc(void * pParam, int nEvent, void *pBuf, int nLen1) |
5dd1b7
|
170 |
{ |
Q |
171 |
switch (nEvent){ |
|
172 |
|
|
173 |
case KBusEvNone: |
|
174 |
break; |
|
175 |
case KBusEvCreate: |
|
176 |
break; |
|
177 |
case KBusEvConnected: |
|
178 |
break; |
|
179 |
case KBusEvDisConnected: |
|
180 |
break; |
|
181 |
case KBusEvClosed: |
|
182 |
break; |
|
183 |
case KBusEvStateChange: |
|
184 |
break; |
|
185 |
case KBusEvTimeSync: |
|
186 |
break; |
|
187 |
case KBusEvDataUpdate: |
|
188 |
KMem.WY[0]=KBusMem.WLY[0]; //KBus Slave |
|
189 |
KBusMem.WLX[0]=KMem.WX[0]; |
|
190 |
KBusMem.WLX[1]=KMem.WX[1]; |
|
191 |
KBusMem.WLX[2]=KMem.WX[2]; |
|
192 |
KBusMem.WLX[3]=KMem.WX[3]; |
|
193 |
break; |
|
194 |
case KBusEvCmdResponse: |
|
195 |
break; |
|
196 |
|
|
197 |
default: |
|
198 |
break; |
|
199 |
} |
|
200 |
return 0; |
|
201 |
} |
|
202 |
|
|
203 |
//#define RAM_START_ADDR 0x20000000 // SRAM_BASE |
8b51c7
|
204 |
#define VECTOR_SIZE 46 |
Q |
205 |
#define ApplicationAddress 0x08001000 //应用程序首地址定义 |
5dd1b7
|
206 |
/* |
8b51c7
|
207 |
static void RemapIrqVector(void) |
Q |
208 |
{ |
|
209 |
memcpy((void*)RAM_START_ADDR, (void *)ApplicationAddress, VECTOR_SIZE * 4); |
|
210 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SYSCFG); |
|
211 |
LL_SYSCFG_SetRemapMemory(LL_SYSCFG_REMAP_SRAM); |
|
212 |
} |
5dd1b7
|
213 |
*/ |
8b51c7
|
214 |
/* USER CODE END 0 */ |
Q |
215 |
|
|
216 |
/** |
|
217 |
* @brief The application entry point. |
|
218 |
* |
|
219 |
* @retval None |
|
220 |
*/ |
|
221 |
int main(void) |
|
222 |
{ |
|
223 |
/* USER CODE BEGIN 1 */ |
|
224 |
// RemapIrqVector(); |
|
225 |
__set_PRIMASK(0); //打开全局中断 |
|
226 |
|
|
227 |
KMRunStat.bLEDFlick = 1; |
|
228 |
|
|
229 |
InitUartstat(&Uart1Stat,Uart1RxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf)); |
|
230 |
InitUartstat(&Uart2Stat,Uart2RxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf)); |
|
231 |
/* USER CODE END 1 */ |
|
232 |
|
|
233 |
/* MCU Configuration----------------------------------------------------------*/ |
|
234 |
|
|
235 |
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
|
236 |
HAL_Init(); |
|
237 |
|
|
238 |
/* USER CODE BEGIN Init */ |
|
239 |
|
|
240 |
|
|
241 |
KMem.LastScanTime=0; |
|
242 |
KMem.ScanTimeuS=0; |
|
243 |
KMem.MinScanTimeuS=99999; |
|
244 |
KMem.MaxScanTimeuS=0; |
|
245 |
|
|
246 |
// KMem.SDD[14]=(unsigned int)&KMStoreSysCfg; |
|
247 |
// KMem.SDD[15]=(unsigned int)&KMStoreSysCfg1; |
|
248 |
KMem.SDD[12]=((uint32_t *)UID_BASE)[0]; |
|
249 |
// KMem.SDD[13]=((uint32_t *)UID_BASE)[1]; |
|
250 |
// KMem.SDD[14]=((uint32_t *)UID_BASE)[2]; |
|
251 |
KMem.SDD[13]=PendSvCount; |
|
252 |
KMem.SDD[14]=RCC->CSR; |
|
253 |
// KMem.SDD[15]=*(uint32_t *)FLASHSIZE_BASE; |
|
254 |
// KMem.SDD[16]=(unsigned int)&KMSysCfg; |
|
255 |
|
|
256 |
/* USER CODE END Init */ |
|
257 |
|
|
258 |
/* Configure the system clock */ |
|
259 |
SystemClock_Config(); |
|
260 |
|
|
261 |
/* USER CODE BEGIN SysInit */ |
|
262 |
TickFreq=10000; //Tick频率 |
|
263 |
InituS(TickFreq); |
|
264 |
// HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq); //重新定义SysTick的频率 |
|
265 |
|
|
266 |
/* USER CODE END SysInit */ |
|
267 |
|
|
268 |
/* Initialize all configured peripherals */ |
|
269 |
MX_GPIO_Init(); |
|
270 |
MX_DMA_Init(); |
|
271 |
|
|
272 |
KMachineInit(); |
|
273 |
ReadSysCfgFromFlash(&storedKMSysCfg); |
|
274 |
|
|
275 |
KMRunStat.bLEDFlick = 1; |
842bb6
|
276 |
int bKBusMaster,bKBusSlave,bKBusRepeater;; |
Q |
277 |
int nKBusStationId; |
|
278 |
int nKBusChilds; |
8b51c7
|
279 |
KMem.CurJumperSW=ReadJumperSW(); |
Q |
280 |
KMem.EffJumperSW=KMem.CurJumperSW; |
842bb6
|
281 |
nKBusStationId=KMem.EffJumperSW&0x0f; |
Q |
282 |
|
|
283 |
nKBusChilds = nKBusStationId; |
8b51c7
|
284 |
|
Q |
285 |
bSLPMaster = 1; // KMem.EffJumperSW&0x20 ; //master? |
842bb6
|
286 |
nSLPStation = 1; |
8b51c7
|
287 |
|
Q |
288 |
// Uart2Baud = AlterUart2Baud; |
|
289 |
|
5dd1b7
|
290 |
|
Q |
291 |
|
8b51c7
|
292 |
#if (BOARD_TYPE == 14) |
Q |
293 |
KMem.EffJumperSW|=0x10; |
842bb6
|
294 |
int nKBusChilds=KMem.EffJumperSW&0x0f; |
8b51c7
|
295 |
if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
Q |
296 |
else{bKBusMaster=0;bKBusSlave=1;} |
842bb6
|
297 |
|
Q |
298 |
FPxSetCallBackFunc(&FPxCallBackFunc); |
|
299 |
FPx_Init(nKBusChilds); |
|
300 |
|
|
301 |
int IOByteCount = nKBusChilds; |
|
302 |
FPx_SetIOCount(IOByteCount,IOByteCount); |
|
303 |
|
8b51c7
|
304 |
|
Q |
305 |
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
|
306 |
nStationID=1 ;//KMem.EffJumperSW&0x0f; |
|
307 |
// if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
|
308 |
// else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
|
309 |
// else |
|
310 |
{bKBusMaster=0;bKBusSlave=1;} |
|
311 |
#else |
842bb6
|
312 |
nKBusStationId=KMem.EffJumperSW&0x0f; |
Q |
313 |
if (KMem.EffJumperSW == 0x3f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
|
314 |
else if ((KMem.EffJumperSW&0x20)!=0) {bKBusMaster=1;bKBusSlave=0;} |
8b51c7
|
315 |
else{bKBusMaster=0;bKBusSlave=1;} |
Q |
316 |
#endif |
5dd1b7
|
317 |
|
842bb6
|
318 |
if (bKBusMaster) { |
Q |
319 |
KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds); |
5dd1b7
|
320 |
|
842bb6
|
321 |
} else if (bKBusSlave) { |
Q |
322 |
KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationId,&MyDeviceInfo); |
|
323 |
} |
|
324 |
|
|
325 |
KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc); |
|
326 |
|
8b51c7
|
327 |
//if (KMem.EffJumperSW == 0x00) |
Q |
328 |
Uart1Baud = DefaultUart1Baud; |
|
329 |
MX_USART1_UART_Init(); |
|
330 |
MX_USART2_UART_Init(); |
|
331 |
|
|
332 |
MX_USART3_UART_Init(); |
|
333 |
|
|
334 |
LL_USART_EnableIT_RXNE(USART3); |
|
335 |
LL_USART_EnableIT_IDLE(USART3); |
|
336 |
|
|
337 |
MX_USART5_UART_Init(); |
|
338 |
LL_USART_EnableIT_RXNE(USART5); |
|
339 |
LL_USART_EnableIT_IDLE(USART5); |
|
340 |
|
|
341 |
MX_USART6_UART_Init(); |
|
342 |
LL_USART_EnableIT_RXNE(USART6); |
|
343 |
LL_USART_EnableIT_IDLE(USART6); |
|
344 |
|
|
345 |
|
|
346 |
// MX_SPI1_Init(); |
|
347 |
// LL_SPI_EnableIT_RXNE(SPI1); |
|
348 |
|
|
349 |
#if (BOARD_TYPE == 14) |
|
350 |
// MX_SPI2_Init(); |
|
351 |
// MX_ADC_Init(); |
|
352 |
#else |
|
353 |
// MX_SPI2_Init(); |
|
354 |
MX_ADC_Init(); |
|
355 |
#endif |
|
356 |
|
|
357 |
MX_IWDG_Init(); |
|
358 |
|
|
359 |
MX_TIM6_Init(); |
|
360 |
LL_TIM_EnableCounter(TIM6); |
|
361 |
|
|
362 |
/* USER CODE BEGIN 2 */ |
|
363 |
LL_USART_EnableIT_RXNE(USART1); |
|
364 |
LL_USART_EnableIT_IDLE(USART1); |
|
365 |
LL_USART_EnableIT_TC(USART1); |
|
366 |
|
|
367 |
// LL_USART_EnableIT_RXNE(USART2); |
|
368 |
Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
|
369 |
LL_USART_EnableIT_IDLE(USART2); |
|
370 |
LL_USART_EnableIT_TC(USART2); |
|
371 |
#if (BOARD_TYPE == 13) |
|
372 |
int res; |
|
373 |
res = w5500_init(); |
|
374 |
KMem.SDD[28]=res; |
|
375 |
|
|
376 |
// res=socket(0,Sn_MR_TCP,5000,0); |
|
377 |
KMem.SDD[29]=res; |
|
378 |
|
|
379 |
// res = listen(0); |
|
380 |
#endif |
|
381 |
// if (bKBusSlave) |
|
382 |
{ |
|
383 |
// LL_USART_EnableAutoBaudRate(USART1); |
|
384 |
// LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
385 |
// LL_USART_EnableAutoBaudRate(USART2); |
|
386 |
// LL_USART_SetAutoBaudRateMode(USART2, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
387 |
} |
|
388 |
//LL_USART_EnableIT_TXE(USART1); |
|
389 |
/* USER CODE END 2 */ |
|
390 |
|
|
391 |
|
|
392 |
/* Infinite loop */ |
|
393 |
/* USER CODE BEGIN WHILE */ |
|
394 |
|
|
395 |
HAL_Delay(10); |
|
396 |
SetRunLed(1); //Turn On Run Led |
|
397 |
SetErrLed(0); //Turn Off Err Led |
|
398 |
|
|
399 |
#if (BOARD_TYPE == 14) |
|
400 |
// PutOutput (0); //Clear all Output |
|
401 |
// Enable595(1); //Enable 595 Output |
|
402 |
#else |
|
403 |
PutOutput (0); //Clear all Output |
|
404 |
Enable595(1); //Enable 595 Output |
|
405 |
#endif |
|
406 |
|
|
407 |
if (GetBoardType() == 7 || GetBoardType() ==8 |
|
408 |
|| GetBoardType() == 9 || GetBoardType() ==10 ||GetBoardType() ==13 ||GetBoardType() ==15 || BOARD_TYPE == 16) |
|
409 |
{ |
|
410 |
displayInput(0xffff); // |
|
411 |
EnableDisIn(1); //Input Diaplay Enable 595 |
|
412 |
} |
|
413 |
SetOutStat(0); //OK Good, signal |
|
414 |
ShowInitInfo(); |
|
415 |
KMem.LastScanTime = GetuS(); |
|
416 |
|
|
417 |
KMRunStat.WorkMode=0; |
|
418 |
KMRunStat.WorkMode2=0; |
|
419 |
|
|
420 |
KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode; |
842bb6
|
421 |
#if (ENABLE_PLC) |
8b51c7
|
422 |
if (KMRunStat.WorkMode == 1){ |
Q |
423 |
InitPLC(); |
|
424 |
KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ; |
|
425 |
if (KMRunStat.WorkMode2) { |
|
426 |
StartPLC(); } |
|
427 |
} |
842bb6
|
428 |
#endif |
Q |
429 |
|
8b51c7
|
430 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
Q |
431 |
KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
|
432 |
KWireLessStart(); |
|
433 |
#endif |
|
434 |
|
5dd1b7
|
435 |
OrdLidarStart(-1); |
8b51c7
|
436 |
|
Q |
437 |
while (1) |
|
438 |
{ |
|
439 |
//int MyKeyStat1,MyKeyStat2; |
|
440 |
//MyKeyStat1=GetInput(); |
|
441 |
|
|
442 |
//*((unsigned int *)&(PLCMem.SDT[10]))=nRunCount; |
|
443 |
// KMem.nRunCount=nRunCount; |
|
444 |
SlowFlicker=0; |
|
445 |
FastFlicker=1; |
|
446 |
us1=GetuS(); |
|
447 |
int haltick=HAL_GetTick(); |
|
448 |
|
|
449 |
int thisJumperSW=ReadJumperSW(); |
842bb6
|
450 |
#if (ENABLE_PLC) |
8b51c7
|
451 |
if (KMRunStat.WorkMode&1){ |
Q |
452 |
if (thisJumperSW&0x20 && !(KMem.CurJumperSW&0x20)) // Run 开关 正 跳变。 |
|
453 |
{StartPLC();} |
|
454 |
if (!(thisJumperSW&0x20) && (KMem.CurJumperSW&0x20)) // Run 开关 负 跳变。 |
|
455 |
{StopPLC();} |
|
456 |
} |
842bb6
|
457 |
#endif |
8b51c7
|
458 |
KMem.CurJumperSW=thisJumperSW; |
Q |
459 |
KMem.haltick=haltick; |
|
460 |
// KMem.TotalRunTime=TotalRunTime; |
|
461 |
// KMem.ThisRunTime=ThisRunTime; |
|
462 |
|
|
463 |
// *((unsigned int *)&(PLCMem.SDT[2]))=nChilds; |
|
464 |
// KMem.SDD[13]=PendSvCount; |
|
465 |
// KMem.SDD[14]=RCC->CSR; |
|
466 |
|
|
467 |
int a; |
|
468 |
a = LL_GPIO_ReadInputPort(GPIOA); |
|
469 |
KMem.WDT[120]=a; |
|
470 |
a = LL_GPIO_ReadInputPort(GPIOB); |
|
471 |
KMem.WDT[121]=a; |
|
472 |
a = LL_GPIO_ReadInputPort(GPIOC); |
|
473 |
KMem.WDT[122]=a; |
|
474 |
a = LL_GPIO_ReadInputPort(GPIOD); |
|
475 |
KMem.WDT[123]=a; |
|
476 |
|
5dd1b7
|
477 |
|
8b51c7
|
478 |
KMem.WXB[0]= GetInput(); |
Q |
479 |
|
|
480 |
us2=GetuS(); |
|
481 |
if (PowerDownEvent) { KMem.WX[0]=0;} |
5dd1b7
|
482 |
// /* |
8b51c7
|
483 |
if ((KMem.nRunCount &0x1f) == 0x02) |
Q |
484 |
{ |
|
485 |
ADCProcess(); |
|
486 |
if (PowerDownEvent) |
|
487 |
{ |
|
488 |
KMem.WX[0]=0; |
|
489 |
if (!OldPowerDownEvent) |
|
490 |
{ |
|
491 |
OldPowerDownEvent = PowerDownEvent; |
|
492 |
OldPowerDownEventTime = nCurTick; |
|
493 |
PowerDownProcess(); |
|
494 |
} |
|
495 |
}else |
|
496 |
{ |
|
497 |
if (OldPowerDownEvent) |
|
498 |
{ |
|
499 |
OldPowerDownEvent=PowerDownEvent; |
|
500 |
PowerRecoverProcess(); |
|
501 |
|
|
502 |
} |
|
503 |
} |
|
504 |
} |
5dd1b7
|
505 |
// */ |
8b51c7
|
506 |
|
Q |
507 |
// pProgs = (stBinProg1 *) STORE_PRG_BASE; |
842bb6
|
508 |
#if (ENABLE_PLC) |
8b51c7
|
509 |
if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
Q |
510 |
{ |
|
511 |
if (KMRunStat.nBinProgBank == 0){ |
|
512 |
pProgs=(stBinProg1 *)STORE_PRG_BASE; |
|
513 |
}else { |
|
514 |
pProgs=(stBinProg1 *)ALT_PRG_BASE; |
|
515 |
} |
|
516 |
nSizeProg1=KMRunStat.nBinProgSize; |
|
517 |
// pProgs=(stBinProg1 *)prog1; |
|
518 |
|
|
519 |
ProcessPLCBinProg(pProgs, nSizeProg1); |
|
520 |
} |
842bb6
|
521 |
#endif |
Q |
522 |
|
8b51c7
|
523 |
KMem.ScanTimeuS=us2-KMem.LastScanTime; |
Q |
524 |
KMem.LastScanTime = us2; |
|
525 |
if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;} |
|
526 |
if (KMem.ScanTimeuS > KMem.MaxScanTimeuS) {KMem.MaxScanTimeuS = KMem.ScanTimeuS;} |
|
527 |
|
|
528 |
// if (bKBusRepeater) { KBusRepeaterFunc(); } |
|
529 |
|
|
530 |
us3=GetuS(); |
|
531 |
|
|
532 |
if (bKBusMaster) |
|
533 |
{ |
842bb6
|
534 |
KBusLoopProcess(&KBus1); |
8b51c7
|
535 |
} |
Q |
536 |
if (haltick&0x00002000) SlowFlicker=1; |
|
537 |
else SlowFlicker=0; |
|
538 |
if (haltick&0x00000800) FastFlicker=1; |
|
539 |
else FastFlicker=0; |
|
540 |
|
|
541 |
if (bKBusSlave) |
|
542 |
{ |
5dd1b7
|
543 |
|
842bb6
|
544 |
KBusLoopProcess(&KBus1); |
Q |
545 |
// if (! KBus1.RunStat) {KBusMem.WLY[0]=0;} |
5dd1b7
|
546 |
KMem.WLY[0]=KBusMem.WLY[0]; |
Q |
547 |
|
842bb6
|
548 |
if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1; |
8b51c7
|
549 |
else SlowFlicker=0; |
842bb6
|
550 |
if (KBus1.nSlaveTick&0x00000800) FastFlicker=1; |
8b51c7
|
551 |
else FastFlicker=0; |
Q |
552 |
|
|
553 |
} |
5dd1b7
|
554 |
KBusMem.WLX[0]=KMem.WX[0]; |
Q |
555 |
KMem.WY[0]=KBusMem.WLY[0]; |
|
556 |
KBusMem.WLX[1]=KMem.WX[1]; |
|
557 |
KBusMem.WLX[2]=KMem.WX[2]; |
|
558 |
KBusMem.WLX[3]=KMem.WX[3]; |
|
559 |
|
8b51c7
|
560 |
|
Q |
561 |
if (KMRunStat.bLEDFlick) |
|
562 |
{ |
|
563 |
SetRunLed(FastFlicker); |
|
564 |
SetErrLed(FastFlicker); |
|
565 |
SetErr2Led(FastFlicker); |
|
566 |
SetOutStat(!FastFlicker); |
|
567 |
//KMRunStat.bLEDFlick-- ; |
|
568 |
} |
|
569 |
else |
|
570 |
{ |
842bb6
|
571 |
#if (ENABLE_PLC) |
8b51c7
|
572 |
if (KMRunStat.WorkMode==1 ) { |
Q |
573 |
if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
|
574 |
else {SetRunLed(0);} |
|
575 |
} |
842bb6
|
576 |
else |
Q |
577 |
#endif |
|
578 |
{ |
8b51c7
|
579 |
if (!KMem.RunStat) SetRunLed(SlowFlicker); |
Q |
580 |
else SetRunLed(FastFlicker); |
|
581 |
} |
842bb6
|
582 |
KMem.ErrStat = KBus1.ErrStat + SLP1.SLPErrSign; |
8b51c7
|
583 |
if (!KMem.ErrStat) |
Q |
584 |
{ |
|
585 |
SetErrLed(0); |
|
586 |
SetErr2Led(0); |
|
587 |
SetOutStat(1); |
|
588 |
} |
|
589 |
else |
|
590 |
{ |
|
591 |
SetErrLed(FastFlicker); |
|
592 |
SetErr2Led(FastFlicker); |
|
593 |
SetOutStat(0); |
|
594 |
|
|
595 |
} |
|
596 |
} |
|
597 |
|
|
598 |
// SetRunLed(RunStat); |
|
599 |
// SetErrLed(ErrStat); |
|
600 |
|
|
601 |
us4=GetuS(); |
|
602 |
// EffJumperSW = GetInput(20)&0xff; |
|
603 |
|
|
604 |
|
|
605 |
us5=GetuS(); |
|
606 |
|
|
607 |
|
|
608 |
//PutOutput (KMem.nRunCount>>8); |
|
609 |
//PutOutput(0x0f70); |
|
610 |
|
|
611 |
// if (bKBusMaster) ShowInfo(); |
|
612 |
// if (bKBusSlave) ShowInfo(); |
|
613 |
us6=GetuS(); |
|
614 |
add1(10,10); |
|
615 |
for (int i=0;i<64;i++) |
|
616 |
{ |
|
617 |
// ProcessTimer(i); |
|
618 |
} |
|
619 |
KMem.nRunCount++; |
|
620 |
// int nSize=sizeof(stKBusChnStat); |
|
621 |
// memcpy(&KMem.SDT[64],&KBusChnStats[1],nSize); |
|
622 |
// memcpy(&KMem.SDT[64+nSize/2],&KBusChnStats[2],nSize); |
|
623 |
// for (int i=0;i<128;i++) { SDT[i]=i; } |
|
624 |
// SDT[48]=55; |
5dd1b7
|
625 |
if (Uart1Stat.bPacketRecved && Uart1RecvBuf1DataLen >0) |
8b51c7
|
626 |
{ |
Q |
627 |
int res1 = -1; |
5dd1b7
|
628 |
if (Uart1RecvBuf1[0] == KLSignStart) { |
Q |
629 |
res1 = KLParsePacket(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); |
|
630 |
}else { |
|
631 |
res1 = ModBusSlaveParsePkg(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); |
8b51c7
|
632 |
} |
Q |
633 |
Uart1Stat.bPacketRecved=0; |
5dd1b7
|
634 |
Uart1RecvBuf1DataLen=0; |
8b51c7
|
635 |
Uart1IdelTimer = 0; |
Q |
636 |
}else { |
|
637 |
if (Uart1IdelTimer>600000) { // 超过60秒没有数据传输,重新进入自适应波特率状态 |
|
638 |
LL_USART_EnableAutoBaudRate(USART1); |
|
639 |
LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
640 |
}else { |
|
641 |
Uart1IdelTimer++; |
|
642 |
} |
|
643 |
} |
|
644 |
if (bKBusSlave) HAL_Delay(0); |
|
645 |
|
|
646 |
if (Uart6Stat.bPacketRecved){ |
842bb6
|
647 |
SLPparsePacket(&SLP1,Uart6RxBuf,Uart6RecvBuf1DataLen); |
8b51c7
|
648 |
Uart6RecvBuf1DataLen =0; |
Q |
649 |
Uart6Stat.bPacketRecved = 0; |
|
650 |
} |
842bb6
|
651 |
SLP1.SLPinputB = KMem.WYB[1]; |
Q |
652 |
SLPProcess(&SLP1); |
|
653 |
KMem.WXB[1] = SLP1.SLPoutputB; |
8b51c7
|
654 |
|
Q |
655 |
// YDLiDar process; |
|
656 |
|
|
657 |
if (Uart3Stat.bPacketRecved){ |
|
658 |
KMem.WDT[8]++; |
5dd1b7
|
659 |
OrdLidarParsePkt(0,(OradarLidarFrame *)Uart3RxBuf,Uart3RecvBuf1DataLen); |
8b51c7
|
660 |
Uart3RecvBuf1DataLen =0; |
Q |
661 |
Uart3Stat.bPacketRecved = 0; |
|
662 |
} |
|
663 |
KMem.WDT[9]=pCount1; |
|
664 |
KMem.WDT[10]=dCount1; |
|
665 |
KMem.WDT[11]=vCount1; |
5dd1b7
|
666 |
|
Q |
667 |
KMem.WDT[12] = eCount1; |
|
668 |
KMem.WDT[13] = eCount2; |
8b51c7
|
669 |
|
Q |
670 |
if (Uart5Stat.bPacketRecved){ |
|
671 |
KMem.WDT[16]++; |
5dd1b7
|
672 |
OrdLidarParsePkt(1,(OradarLidarFrame *)Uart5RxBuf,Uart5RecvBuf1DataLen); |
8b51c7
|
673 |
Uart5RecvBuf1DataLen =0; |
Q |
674 |
Uart5Stat.bPacketRecved = 0; |
|
675 |
} |
|
676 |
|
|
677 |
// nPosX,nPosY,nPosZ,nPosZ1,nPosZ2; |
|
678 |
|
|
679 |
KMem.WDT[17]=pCount2; |
|
680 |
KMem.WDT[18]=dCount2; |
|
681 |
KMem.WDT[19]=vCount2; |
|
682 |
|
|
683 |
KMem.WDT[24]=nPosX; |
|
684 |
KMem.WDT[25]=nPosY; |
|
685 |
KMem.WDT[26]=nPosZ; |
|
686 |
KMem.WDT[27]=nPosZ1; |
|
687 |
KMem.WDT[28]=nPosZ2; |
|
688 |
|
5dd1b7
|
689 |
KMem.WDT[32]=results[0]; |
Q |
690 |
KMem.WDT[33]=results[1]; |
|
691 |
KMem.WDT[34]=results[2]; |
|
692 |
KMem.WDT[35]=results[3]; |
|
693 |
KMem.WDT[36]=results[4]; |
|
694 |
KMem.WDT[37]=results[5]; |
|
695 |
KMem.WDT[38]=results[6]; |
|
696 |
KMem.WDT[39]=results[7]; |
8b51c7
|
697 |
|
5dd1b7
|
698 |
|
Q |
699 |
KMem.WX[1] = nPosX ; |
|
700 |
KMem.WX[2] = nPosY ; |
|
701 |
KMem.WX[3] = nPosZ; |
|
702 |
|
|
703 |
// KMem.WX[1]++ ; |
|
704 |
// KMem.WX[2]++; |
|
705 |
|
842bb6
|
706 |
// KMem.WYB[0]=1; |
5dd1b7
|
707 |
PutOutput (KMem.WY[0]); |
8b51c7
|
708 |
|
Q |
709 |
LL_IWDG_ReloadCounter(IWDG); |
|
710 |
|
|
711 |
} //while (1) ; |
|
712 |
/* USER CODE END WHILE */ |
|
713 |
|
|
714 |
/* USER CODE BEGIN 3 */ |
|
715 |
|
|
716 |
/* USER CODE END 3 */ |
|
717 |
|
|
718 |
} |
|
719 |
|
|
720 |
|
|
721 |
/* USER CODE BEGIN 4 */ |
|
722 |
|
|
723 |
/* USER CODE END 4 */ |
|
724 |
|
|
725 |
/** |
|
726 |
* @brief This function is executed in case of error occurrence. |
|
727 |
* @param file: The file name as string. |
|
728 |
* @param line: The line in file as a number. |
|
729 |
* @retval None |
|
730 |
*/ |
|
731 |
void _Error_Handler(char *file, int line) |
|
732 |
{ |
|
733 |
/* USER CODE BEGIN Error_Handler_Debug */ |
|
734 |
/* User can add his own implementation to report the HAL error return state */ |
|
735 |
while(1) |
|
736 |
{ |
|
737 |
} |
|
738 |
/* USER CODE END Error_Handler_Debug */ |
|
739 |
} |
|
740 |
|
|
741 |
#ifdef USE_FULL_ASSERT |
|
742 |
/** |
|
743 |
* @brief Reports the name of the source file and the source line number |
|
744 |
* where the assert_param error has occurred. |
|
745 |
* @param file: pointer to the source file name |
|
746 |
* @param line: assert_param error line source number |
|
747 |
* @retval None |
|
748 |
*/ |
|
749 |
void assert_failed(uint8_t* file, uint32_t line) |
|
750 |
{ |
|
751 |
/* USER CODE BEGIN 6 */ |
|
752 |
/* User can add his own implementation to report the file name and line number, |
|
753 |
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
|
754 |
/* USER CODE END 6 */ |
|
755 |
} |
|
756 |
#endif /* USE_FULL_ASSERT */ |
|
757 |
|
|
758 |
/** |
|
759 |
* @} |
|
760 |
*/ |
|
761 |
|
|
762 |
/** |
|
763 |
* @} |
|
764 |
*/ |
|
765 |
|
|
766 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |