提交 | 用户 | age
|
9aed5d
|
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_UltraSonic.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) |
|
59 |
#include "FP0.h" |
|
60 |
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
|
61 |
#include "KWireless.h" |
|
62 |
//#include "user.h" |
|
63 |
//#include "../src/radio/inc/sx126x-board.h" |
|
64 |
#endif |
|
65 |
|
|
66 |
/* USER CODE END Includes */ |
|
67 |
|
|
68 |
/* Private variables ---------------------------------------------------------*/ |
|
69 |
|
|
70 |
/* USER CODE BEGIN PV */ |
|
71 |
/* Private variables ---------------------------------------------------------*/ |
|
72 |
|
|
73 |
#define RX2BUFSIZE 64 |
|
74 |
#define TX2BUFSIZE 64 |
|
75 |
|
|
76 |
unsigned char Uart1RxBuf[128]; |
|
77 |
unsigned char Uart1TxBuf[260]; |
|
78 |
|
|
79 |
unsigned char Uart2RxBuf[RX2BUFSIZE]; |
|
80 |
unsigned char Uart2TxBuf[TX2BUFSIZE]; |
|
81 |
|
|
82 |
unsigned char Uart1RxBuf1[Uart1RxBufSize]; |
|
83 |
unsigned char Uart1TxBuf1[260]; |
|
84 |
|
|
85 |
unsigned char Uart2RxBuf1[RX2BUFSIZE]; |
|
86 |
unsigned char Uart2TxBuf1[TX2BUFSIZE]; |
|
87 |
|
|
88 |
unsigned short Uart1RxBuf1DataLen = 0; |
|
89 |
unsigned short Uart2RxBuf1DataLen = 0; |
|
90 |
|
|
91 |
unsigned char Uart1Mode = 1; //Uart1工作模式, 0 : 普通, 1 : 透传模式 |
|
92 |
|
|
93 |
unsigned int Uart1Baud = DefaultUart1Baud; |
|
94 |
unsigned int Uart2Baud = DefaultUart2Baud; |
|
95 |
|
|
96 |
//unsigned char Uart1RecvBuf1[Uart1RecvBufSize]; |
|
97 |
//unsigned short Uart1RecvBuf1DataLen=0; |
|
98 |
|
|
99 |
//unsigned char Uart2RecvBuf1[128]; |
|
100 |
//unsigned short Uart2RecvBuf1DataLen=0; |
|
101 |
|
|
102 |
volatile char Uart1BaudGot=0; |
|
103 |
volatile char Uart1BaudFirstGot=0; |
|
104 |
volatile char Uart1DmaInts=0; |
|
105 |
|
|
106 |
|
|
107 |
unsigned char SlowFlicker=0; |
|
108 |
unsigned char FastFlicker=0; |
|
109 |
|
|
110 |
unsigned int Uart1IdelTimer = 0; |
|
111 |
|
|
112 |
uint32_t us1,us2,us3,us4,us5,us6; |
|
113 |
|
|
114 |
|
|
115 |
stKBusDef KBus1; // |
|
116 |
|
|
117 |
extern stDeviceInfo MyDeviceInfo; |
|
118 |
/* USER CODE END PV */ |
|
119 |
|
|
120 |
/* Private function prototypes -----------------------------------------------*/ |
|
121 |
|
|
122 |
|
|
123 |
/* USER CODE BEGIN PFP */ |
|
124 |
/* Private function prototypes -----------------------------------------------*/ |
|
125 |
|
|
126 |
const unsigned char LEDSEGTAB[]={ |
|
127 |
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71, //0-F |
|
128 |
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1, //0.-F. |
|
129 |
0x00,0x40, // ,-,_,~,o,n,N,<,>,J,r, |
|
130 |
}; |
|
131 |
|
|
132 |
/* USER CODE END PFP */ |
|
133 |
|
|
134 |
/* USER CODE BEGIN 0 */ |
|
135 |
#define SET_SCL LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_6) |
|
136 |
#define CLR_SCL LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_6) |
|
137 |
#define GET_SCL LL_GPIO_IsInputPinSet(GPIOB,LL_GPIO_PIN_6) |
|
138 |
#define SET_SDA LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_7) |
|
139 |
#define CLR_SDA LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_7) |
|
140 |
#define GET_SDA LL_GPIO_IsInputPinSet(GPIOB,LL_GPIO_PIN_7) |
|
141 |
|
|
142 |
|
|
143 |
void soft_i2c_start() |
|
144 |
{ |
|
145 |
SET_SDA; |
|
146 |
SET_SCL; |
|
147 |
Delay100nS(1); |
|
148 |
CLR_SDA; |
|
149 |
Delay100nS(1); |
|
150 |
CLR_SCL; |
|
151 |
Delay100nS(1); |
|
152 |
} |
|
153 |
void soft_i2c_stop() |
|
154 |
{ |
|
155 |
CLR_SDA; |
|
156 |
Delay100nS(1); |
|
157 |
SET_SCL; |
|
158 |
Delay100nS(1); |
|
159 |
SET_SDA; |
|
160 |
Delay100nS(1); |
|
161 |
} |
|
162 |
void soft_i2c_send8(int nData) |
|
163 |
{ |
|
164 |
int mask; |
|
165 |
mask = 0x80; |
|
166 |
for (int j=0;j<8;j++) |
|
167 |
{ |
|
168 |
if (nData & mask) {SET_SDA;} |
|
169 |
else {CLR_SDA;} |
|
170 |
Delay100nS(1); |
|
171 |
SET_SCL; |
|
172 |
mask>>=1; |
|
173 |
Delay100nS(1); |
|
174 |
CLR_SCL; |
|
175 |
} |
|
176 |
return; |
|
177 |
} |
|
178 |
|
|
179 |
uint8_t soft_i2c_recv8() |
|
180 |
{ |
|
181 |
unsigned char nData=0; |
|
182 |
for (int j=0;j<8;j++) |
|
183 |
{ |
|
184 |
nData <<=1; |
|
185 |
Delay100nS(1); |
|
186 |
SET_SCL; |
|
187 |
nData |= GET_SDA; |
|
188 |
Delay100nS(1); |
|
189 |
CLR_SCL; |
|
190 |
} |
|
191 |
return nData; |
|
192 |
} |
|
193 |
|
|
194 |
void soft_i2c_send_ack() |
|
195 |
{ |
|
196 |
CLR_SDA; |
|
197 |
Delay100nS(2); |
|
198 |
SET_SCL; |
|
199 |
Delay100nS(2); |
|
200 |
CLR_SCL; |
|
201 |
SET_SDA; |
|
202 |
Delay100nS(2); |
|
203 |
|
|
204 |
} |
|
205 |
|
|
206 |
void soft_i2c_send_nack() |
|
207 |
{ |
|
208 |
SET_SDA; |
|
209 |
Delay100nS(1); |
|
210 |
SET_SCL; |
|
211 |
Delay100nS(1); |
|
212 |
CLR_SCL; |
|
213 |
Delay100nS(1); |
|
214 |
SET_SDA; |
|
215 |
} |
|
216 |
uint8_t soft_i2c_wait_ack(int nTime) |
|
217 |
{ |
|
218 |
SET_SDA; // Open Drain; |
|
219 |
Delay100nS(1); |
|
220 |
SET_SCL; |
|
221 |
for (int j=0;j<nTime;j++){ |
|
222 |
Delay100nS(1); |
|
223 |
if (GET_SDA == 0) break; |
|
224 |
if (j==nTime-1) return 0; |
|
225 |
} |
|
226 |
CLR_SCL; |
|
227 |
return 1; |
|
228 |
} |
|
229 |
uint8_t soft_i2c_check_addr(uint8_t Addr) |
|
230 |
{ |
|
231 |
uint8_t res=0; |
|
232 |
soft_i2c_start(); |
|
233 |
// Send Device Addr 7bit; |
|
234 |
soft_i2c_send8(Addr); |
|
235 |
if (soft_i2c_wait_ack(10)) {res=1;} |
|
236 |
//Stop |
|
237 |
soft_i2c_stop(); |
|
238 |
// */ |
|
239 |
return res; |
|
240 |
|
|
241 |
} |
|
242 |
uint8_t soft_i2c_read_len( uint8_t Addr , uint8_t Reg, uint8_t len,uint8_t *buf) |
|
243 |
{ |
|
244 |
int res=0; |
|
245 |
//Start |
|
246 |
soft_i2c_start(); |
|
247 |
// Send Device Addr 7bit; |
|
248 |
soft_i2c_send8(Addr &0xfe); |
|
249 |
// wait Ack; |
|
250 |
if (!soft_i2c_wait_ack(1000)) {soft_i2c_stop();return 1;} |
|
251 |
CLR_SCL; |
|
252 |
// Send Reg Addr 8bit; |
|
253 |
soft_i2c_send8(Reg); |
|
254 |
if (!soft_i2c_wait_ack(1000)) {soft_i2c_stop();return 2;} |
|
255 |
//Start |
|
256 |
soft_i2c_start(); |
|
257 |
// Send Device Addr 7bit; |
|
258 |
soft_i2c_send8(Addr | 1); |
|
259 |
if (!soft_i2c_wait_ack(1000)) {soft_i2c_stop();return 3;} |
|
260 |
|
|
261 |
// /* |
|
262 |
// Recv Data(s) n * 8bit; |
|
263 |
SET_SDA; // Open Drain; |
|
264 |
for (int i=0;i<len;i++) |
|
265 |
{ |
|
266 |
// recv 1 data 8bit; |
|
267 |
unsigned char nData = 0; |
|
268 |
nData = soft_i2c_recv8(); |
|
269 |
buf[i]=nData; |
|
270 |
// Send ACK / NACK; |
|
271 |
if (i != len -1) { //ACK |
|
272 |
soft_i2c_send_ack(); |
|
273 |
} else { // NACK |
|
274 |
soft_i2c_send_nack(); |
|
275 |
} |
|
276 |
} |
|
277 |
|
|
278 |
//Stop |
|
279 |
soft_i2c_stop(); |
|
280 |
// */ |
|
281 |
return res; |
|
282 |
} |
|
283 |
|
|
284 |
uint8_t soft_i2c_write_len(uint8_t Addr , uint8_t Reg, uint8_t len, uint8_t *buf) |
|
285 |
{ |
|
286 |
int res=0; |
|
287 |
//Start |
|
288 |
soft_i2c_start(); |
|
289 |
// Send Device Addr 7bit; |
|
290 |
soft_i2c_send8(Addr &0xfe); |
|
291 |
// wait Ack; |
|
292 |
if (!soft_i2c_wait_ack(1000)) return 1; |
|
293 |
CLR_SCL; |
|
294 |
// Send Reg Addr 8bit; |
|
295 |
soft_i2c_send8(Reg); |
|
296 |
if (!soft_i2c_wait_ack(1000)) return 2; |
|
297 |
for (int i=0;i<len;i++) |
|
298 |
{ |
|
299 |
// send 1 data 8bit; |
|
300 |
unsigned char nData = buf[i]; |
|
301 |
soft_i2c_send8(nData); |
|
302 |
// wait Ack; |
|
303 |
if (!soft_i2c_wait_ack(1000)) {res = 5; break;} |
|
304 |
} |
|
305 |
//Stop |
|
306 |
soft_i2c_stop(); |
|
307 |
return res; |
|
308 |
|
|
309 |
} |
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
int HexToInt(char ch) |
|
315 |
{ |
|
316 |
if (ch>='0' && ch <='9') return ch-'0'; |
|
317 |
if (ch>='A' && ch <='F') return ch-'A'+10; |
|
318 |
if (ch>='a' && ch <='f') return ch-'a'+10; |
|
319 |
return 0; |
|
320 |
} |
|
321 |
|
|
322 |
void HAL_SYSTICK_Callback(void) |
|
323 |
{ |
|
324 |
return; |
|
325 |
static int Count=0; |
|
326 |
CurTickuS += 100; |
|
327 |
nCurTick++; |
|
328 |
KBus1.nSlaveTick++; |
|
329 |
Count++; |
|
330 |
if (Count>=10000) |
|
331 |
{ |
|
332 |
Count=0; |
|
333 |
KMem.CurTimeSec++; |
|
334 |
KMem.ThisRunTime++; KMem.TotalRunTime++; |
|
335 |
if (KMRunStat.bLEDFlick) KMRunStat.bLEDFlick--; |
|
336 |
if (KMRunStat.bLEDFlick >120) KMRunStat.bLEDFlick=120; |
|
337 |
} |
|
338 |
|
|
339 |
return; |
|
340 |
} |
|
341 |
|
|
342 |
void PendSvCallBack() |
|
343 |
{ |
|
344 |
/* |
|
345 |
if (Uart2Stat.bPacketRecved) |
|
346 |
{ |
|
347 |
KBusParsePacket(&KBus1, (pKBPacket)Uart2RxBuf1, Uart2RxBuf1DataLen); |
|
348 |
Uart2RxBuf1DataLen=0; |
|
349 |
Uart2Stat.bPacketRecved=0; |
|
350 |
Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1)); |
|
351 |
KMem.WDT[2]++; |
|
352 |
} |
|
353 |
*/ |
|
354 |
} |
|
355 |
|
|
356 |
/* |
|
357 |
KBus通讯回调函数,当通讯状态改变或数据更新时被调用。 |
|
358 |
或者系统请求时。 |
|
359 |
*/ |
|
360 |
void * KBusEvCallBackFunc(void* pParam, int nEvent, void *pBuf, int nLen1) |
|
361 |
{ |
|
362 |
switch (nEvent){ |
|
363 |
|
|
364 |
case KBusEvNone: |
|
365 |
break; |
|
366 |
case KBusEvCreate: |
|
367 |
break; |
|
368 |
case KBusEvConnected: |
|
369 |
break; |
|
370 |
case KBusEvDisConnected: |
|
371 |
break; |
|
372 |
case KBusEvClosed: |
|
373 |
break; |
|
374 |
case KBusEvStateChange: |
|
375 |
break; |
|
376 |
case KBusEvTimeSync: |
|
377 |
break; |
|
378 |
case KBusEvDataUpdate: |
|
379 |
if (KBus1.bMaster) { |
|
380 |
for (int i=0;i<16;i++) |
|
381 |
{ |
|
382 |
KMem.WLX[i]=KBusMem.WLX[i]; //KPLC with KBus Master |
|
383 |
KBusMem.WLY[i]=KMem.WLY[i]; |
|
384 |
} |
|
385 |
} else if (KBus1.bSlave) { |
|
386 |
KMem.WLX[0]=KBusMem.WLY[0]; //KPLC with KBus Slave |
|
387 |
KBusMem.WLX[0]=KMem.WLY[0]; |
|
388 |
KMem.WLX[1]=KBusMem.WLY[1]; //KPLC with KBus Slave |
|
389 |
KBusMem.WLX[1]=KMem.WLY[1]; |
|
390 |
KMem.WLX[2]=KBusMem.WLY[2]; //KPLC with KBus Slave |
|
391 |
KBusMem.WLX[2]=KMem.WLY[2]; |
|
392 |
KMem.WLX[3]=KBusMem.WLY[3]; //KPLC with KBus Slave |
|
393 |
KBusMem.WLX[3]=KMem.WLY[3]; |
|
394 |
} |
|
395 |
|
|
396 |
break; |
|
397 |
case KBusEvCmdResponse: |
|
398 |
break; |
|
399 |
|
|
400 |
default: |
|
401 |
break; |
|
402 |
} |
|
403 |
return 0; |
|
404 |
} |
|
405 |
#define SET_STB() LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_15) |
|
406 |
#define CLR_STB() LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_15) |
|
407 |
#define SET_SCK() LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3) |
|
408 |
#define CLR_SCK() LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3) |
|
409 |
#define SET_DIO() LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_5) |
|
410 |
#define CLR_DIO() LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_5) |
|
411 |
#define GET_DIO() LL_GPIO_IsInputPinSet(GPIOB,LL_GPIO_PIN_5) |
|
412 |
|
|
413 |
void Set_Run_Led(uchar bOn) |
|
414 |
{ |
|
415 |
if (bOn){ LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_12); } |
|
416 |
else { LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_12);} |
|
417 |
|
|
418 |
} |
|
419 |
void TM1629_Send_Byte(uchar byte) |
|
420 |
{ |
|
421 |
CLR_STB(); |
|
422 |
unsigned char mask = 0x01; |
|
423 |
for (int i=0;i<8;i++) |
|
424 |
{ |
|
425 |
CLR_SCK(); |
|
426 |
if (byte & mask) { SET_DIO(); } |
|
427 |
else {CLR_DIO();} |
|
428 |
DelayUs(1); |
|
429 |
SET_SCK(); |
|
430 |
mask<<=1; |
|
431 |
DelayUs(1); |
|
432 |
} |
|
433 |
} |
|
434 |
uchar TM1629_Read_Byte() |
|
435 |
{ |
|
436 |
CLR_STB(); |
|
437 |
SET_DIO(); |
|
438 |
uchar byte=0; |
|
439 |
unsigned char mask = 0x01; |
|
440 |
for (int i=0;i<8;i++) |
|
441 |
{ |
|
442 |
CLR_SCK(); |
|
443 |
DelayUs(1); |
|
444 |
SET_SCK(); |
|
445 |
DelayUs(1); |
|
446 |
if (GET_DIO()) { byte|=mask; } |
|
447 |
mask<<=1; |
|
448 |
} |
|
449 |
return byte; |
|
450 |
|
|
451 |
} |
|
452 |
void TM1629_disp_on() |
|
453 |
{ |
|
454 |
SET_STB(); |
|
455 |
SET_SCK(); |
|
456 |
SET_DIO(); |
|
457 |
DelayUs(2); |
|
458 |
CLR_STB(); |
|
459 |
TM1629_Send_Byte(0x8a); |
|
460 |
SET_STB(); |
|
461 |
SET_DIO(); |
|
462 |
} |
|
463 |
|
|
464 |
void TM1629_Set_Mode_a() |
|
465 |
{ |
|
466 |
SET_STB(); |
|
467 |
SET_SCK(); |
|
468 |
SET_DIO(); |
|
469 |
DelayUs(2); |
|
470 |
CLR_STB(); |
|
471 |
TM1629_Send_Byte(0x40); |
|
472 |
SET_STB(); |
|
473 |
} |
|
474 |
void TM1629_Set_Address(uchar addr) |
|
475 |
{ |
|
476 |
SET_STB(); |
|
477 |
SET_SCK(); |
|
478 |
SET_DIO(); |
|
479 |
DelayUs(2); |
|
480 |
CLR_STB(); |
|
481 |
TM1629_Send_Byte(0xc0 | addr); |
|
482 |
} |
|
483 |
|
|
484 |
void TM1629_Send_Data(int addr, const uchar * pbuf, int len) |
|
485 |
{ |
|
486 |
TM1629_Set_Mode_a(); |
|
487 |
TM1629_Set_Address(addr); |
|
488 |
for (int i=0;i<len;i++) |
|
489 |
{ |
|
490 |
TM1629_Send_Byte(pbuf[i]); |
|
491 |
} |
|
492 |
SET_STB(); |
|
493 |
|
|
494 |
} |
|
495 |
|
|
496 |
void TM1629_Read_Keys(uchar * pkeybuf) |
|
497 |
{ |
|
498 |
SET_STB(); |
|
499 |
SET_SCK(); |
|
500 |
SET_DIO(); |
|
501 |
DelayUs(2); |
|
502 |
CLR_STB(); |
|
503 |
TM1629_Send_Byte(0x42); |
|
504 |
for (int i=0;i<4;i++) |
|
505 |
pkeybuf[i]=TM1629_Read_Byte(); |
|
506 |
SET_STB(); |
|
507 |
} |
|
508 |
__asm int bintobcd(int a,int b) |
|
509 |
{ |
|
510 |
add r0,r1,r0 |
|
511 |
|
|
512 |
BLX lr |
|
513 |
} |
|
514 |
|
|
515 |
/* USER CODE END 0 */ |
|
516 |
|
|
517 |
/** |
|
518 |
* @brief The application entry point. |
|
519 |
* |
|
520 |
* @retval None |
|
521 |
*/ |
|
522 |
int main(void) |
|
523 |
{ |
|
524 |
/* USER CODE BEGIN 1 */ |
|
525 |
KMRunStat.bLEDFlick = 1; |
|
526 |
|
|
527 |
InitUartstat(&Uart1Stat,Uart1RxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf)); |
|
528 |
InitUartstat(&Uart2Stat,Uart2RxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf)); |
|
529 |
/* USER CODE END 1 */ |
|
530 |
|
|
531 |
/* MCU Configuration----------------------------------------------------------*/ |
|
532 |
|
|
533 |
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
|
534 |
HAL_Init(); |
|
535 |
|
|
536 |
/* USER CODE BEGIN Init */ |
|
537 |
|
|
538 |
|
|
539 |
int nRunCount = 0; |
|
540 |
|
|
541 |
KMem.LastScanTime=0; |
|
542 |
KMem.ScanTimeuS=0; |
|
543 |
KMem.MinScanTimeuS=99999; |
|
544 |
KMem.MaxScanTimeuS=0; |
|
545 |
|
|
546 |
// KMem.SDD[14]=(unsigned int)&KMStoreSysCfg; |
|
547 |
// KMem.SDD[15]=(unsigned int)&KMStoreSysCfg1; |
|
548 |
KMem.SDD[12]=((uint32_t *)UID_BASE)[0]; |
|
549 |
// KMem.SDD[13]=((uint32_t *)UID_BASE)[1]; |
|
550 |
// KMem.SDD[14]=((uint32_t *)UID_BASE)[2]; |
|
551 |
KMem.SDD[13]=PendSvCount; |
|
552 |
KMem.SDD[14]=RCC->CSR; |
|
553 |
// KMem.SDD[15]=*(uint32_t *)FLASHSIZE_BASE; |
|
554 |
// KMem.SDD[16]=(unsigned int)&KMSysCfg; |
|
555 |
|
|
556 |
/* USER CODE END Init */ |
|
557 |
DelayUs(10000); |
|
558 |
/* Configure the system clock */ |
|
559 |
SystemClock_Config_New(); |
|
560 |
|
|
561 |
|
|
562 |
/* USER CODE BEGIN SysInit */ |
|
563 |
TickFreq=1000; //Tick频率 |
|
564 |
InituS(TickFreq); |
|
565 |
// HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq); //重新定义SysTick的频率 |
|
566 |
|
|
567 |
/* USER CODE END SysInit */ |
|
568 |
|
|
569 |
/* Initialize all configured peripherals */ |
|
570 |
// MX_GPIO_Init(); |
|
571 |
// MX_DMA_Init(); |
|
572 |
|
|
573 |
|
|
574 |
// KMachineInit(); |
|
575 |
// ReadSysCfgFromFlash(&storedKMSysCfg); |
|
576 |
|
|
577 |
KMRunStat.bLEDFlick = 1; |
|
578 |
|
|
579 |
|
|
580 |
KLinkInit(1); |
|
581 |
|
|
582 |
//if (KMem.EffJumperSW == 0x00) |
|
583 |
Uart1Baud = DefaultUart1Baud; |
|
584 |
// MX_USART1_UART_Init(); |
|
585 |
// MX_USART2_UART_Init(); |
|
586 |
// MX_SPI1_Init(); |
|
587 |
// LL_SPI_EnableIT_RXNE(SPI1); |
|
588 |
/* |
|
589 |
// MX_I2C1_Init(); |
|
590 |
Soft_I2C1_Init(); |
|
591 |
|
|
592 |
|
|
593 |
|
|
594 |
// MX_IWDG_Init(); |
|
595 |
|
|
596 |
MX_TIM6_Init(); |
|
597 |
LL_TIM_EnableCounter(TIM6); |
|
598 |
*/ |
|
599 |
/* USER CODE BEGIN 2 */ |
|
600 |
// LL_USART_EnableIT_RXNE(USART1); |
|
601 |
// LL_USART_EnableIT_IDLE(USART1); |
|
602 |
// LL_USART_EnableIT_TC(USART1); |
|
603 |
|
|
604 |
// LL_USART_EnableIT_RXNE(USART2); |
|
605 |
// Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1)); |
|
606 |
// LL_USART_EnableIT_IDLE(USART2); |
|
607 |
// LL_USART_EnableIT_TC(USART2); |
|
608 |
|
|
609 |
// if (bKBusSlave) |
|
610 |
{ |
|
611 |
// LL_USART_EnableAutoBaudRate(USART1); |
|
612 |
// LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
613 |
// LL_USART_EnableAutoBaudRate(USART2); |
|
614 |
// LL_USART_SetAutoBaudRateMode(USART2, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
615 |
} |
|
616 |
//LL_USART_EnableIT_TXE(USART1); |
|
617 |
|
|
618 |
// KMem.WDT[50] = SPI_Flash_ReadID(); |
|
619 |
|
|
620 |
/* USER CODE END 2 */ |
|
621 |
|
|
622 |
|
|
623 |
/* Infinite loop */ |
|
624 |
/* USER CODE BEGIN WHILE */ |
|
625 |
|
|
626 |
// HAL_Delay(10); |
|
627 |
// SetRunLed(1); //Turn On Run Led |
|
628 |
// SetErrLed(0); //Turn Off Err Led |
|
629 |
|
|
630 |
|
|
631 |
|
|
632 |
// ShowInitInfo(); |
|
633 |
KMem.LastScanTime = GetuS(); |
|
634 |
|
|
635 |
KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode; |
|
636 |
|
|
637 |
KMRunStat.WorkMode = 1; |
|
638 |
//KMRunStat.WorkMode2 = 0; |
|
639 |
|
|
640 |
|
|
641 |
|
|
642 |
MX_TIM1_Init(); |
|
643 |
|
|
644 |
LL_TIM_CC_EnableChannel(TIM1,LL_TIM_CHANNEL_CH1); |
|
645 |
LL_TIM_CC_EnableChannel(TIM1,LL_TIM_CHANNEL_CH1N); |
|
646 |
LL_TIM_EnableCounter(TIM1); |
|
647 |
LL_TIM_CC_EnableChannel(TIM1,LL_TIM_CHANNEL_CH4); |
|
648 |
|
|
649 |
// LL_TIM_OC_SetCompareCH4(TIM1,600); |
|
650 |
|
|
651 |
LL_TIM_OC_SetCompareCH2(TIM1,100); |
|
652 |
|
|
653 |
|
|
654 |
MX_TIM15_Init(); |
|
655 |
LL_TIM_CC_EnableChannel(TIM15,LL_TIM_CHANNEL_CH1); |
|
656 |
LL_TIM_CC_EnableChannel(TIM15,LL_TIM_CHANNEL_CH1N); |
|
657 |
LL_TIM_EnableCounter(TIM15); |
|
658 |
|
|
659 |
LL_TIM_EnableAllOutputs(TIM1); |
|
660 |
LL_TIM_EnableAllOutputs(TIM15); |
|
661 |
|
|
662 |
LL_TIM_DisableAllOutputs(TIM1); |
|
663 |
LL_TIM_DisableAllOutputs(TIM15); |
|
664 |
|
|
665 |
|
|
666 |
// LL_TIM_DisableCounter(TIM1); |
|
667 |
// LL_TIM_DisableCounter(TIM15); |
|
668 |
|
|
669 |
|
|
670 |
/* |
|
671 |
MX_TIM16_Init(); |
|
672 |
|
|
673 |
LL_TIM_CC_EnableChannel(TIM16,LL_TIM_CHANNEL_CH1); |
|
674 |
LL_TIM_CC_EnableChannel(TIM16,LL_TIM_CHANNEL_CH1N); |
|
675 |
LL_TIM_OC_SetCompareCH1(TIM16,600); |
|
676 |
LL_TIM_EnableCounter(TIM16); |
|
677 |
|
|
678 |
LL_TIM_EnableAllOutputs(TIM16); |
|
679 |
*/ |
|
680 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
681 |
|
|
682 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
683 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_12; |
|
684 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
685 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
686 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
687 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
688 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
689 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
690 |
|
|
691 |
LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_12); |
|
692 |
|
|
693 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_15; |
|
694 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
695 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
696 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
697 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
698 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
699 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
700 |
|
|
701 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3 ; |
|
702 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
703 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
704 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
705 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
706 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
707 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
708 |
|
|
709 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_5; |
|
710 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
711 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
712 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
|
713 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
714 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
715 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
716 |
|
|
717 |
|
|
718 |
SET_STB(); |
|
719 |
SET_SCK(); |
|
720 |
SET_DIO(); |
|
721 |
|
|
722 |
|
|
723 |
|
|
724 |
TM1629_disp_on(); |
|
725 |
|
|
726 |
KMem.WDB[128]=0x56; |
|
727 |
|
|
728 |
int nShift = 1; |
|
729 |
int nDir = 1; |
|
730 |
int nFreq = 28000; |
|
731 |
int nOrgFreqFct = (48000000 / nFreq) - 1; |
|
732 |
int nFreqFctDlt = 50 ; |
|
733 |
|
|
734 |
int nMaxFreqFct = nOrgFreqFct + nFreqFctDlt; |
|
735 |
int nMinFreqFrc = nOrgFreqFct - nFreqFctDlt; |
|
736 |
|
|
737 |
int nCurFreqFct = nOrgFreqFct; |
|
738 |
|
|
739 |
int bEnableSpan = 0; //1; |
|
740 |
int bShift = 1; |
|
741 |
|
|
742 |
uchar ledbuf1[16]; |
|
743 |
uchar line1[4]; |
|
744 |
uchar line2[4]; |
|
745 |
uchar line3[4]; |
|
746 |
uchar line4[4]; |
|
747 |
|
|
748 |
line1[0]=LEDSEGTAB[0]; |
|
749 |
line1[1]=LEDSEGTAB[1]; |
|
750 |
line1[2]=LEDSEGTAB[2]; |
|
751 |
line1[3]=LEDSEGTAB[3]; |
|
752 |
|
|
753 |
line2[0]=LEDSEGTAB[4]; |
|
754 |
line2[1]=LEDSEGTAB[5]; |
|
755 |
line2[2]=LEDSEGTAB[6]; |
|
756 |
line2[3]=LEDSEGTAB[7]; |
|
757 |
|
|
758 |
line3[0]=LEDSEGTAB[8]; |
|
759 |
line3[1]=LEDSEGTAB[9]; |
|
760 |
line3[2]=LEDSEGTAB[0xa]; |
|
761 |
line3[3]=LEDSEGTAB[0xb]; |
|
762 |
|
|
763 |
line4[0]=0x00; |
|
764 |
line4[1]=0x55; |
|
765 |
line4[2]=0xff; |
|
766 |
line4[3]=0x0; |
|
767 |
uchar keybuf[4]; |
|
768 |
int nCount1=0; |
|
769 |
union{ |
|
770 |
uchar value; |
|
771 |
struct |
|
772 |
{ |
|
773 |
uchar Finc:1; |
|
774 |
uchar sweep:1; |
|
775 |
uchar Tdec:1; |
|
776 |
uchar Pdec:1; |
|
777 |
uchar Fdec:1; |
|
778 |
uchar On:1; |
|
779 |
uchar Tinc:1; |
|
780 |
uchar Pinc:1; |
|
781 |
}; |
|
782 |
} |
|
783 |
keys,oldkeys; |
|
784 |
|
|
785 |
int value1; |
|
786 |
int value2; |
|
787 |
int value3; |
|
788 |
int value4; |
|
789 |
|
|
790 |
int bPowerOn =0; |
|
791 |
int bSweep = 0; |
|
792 |
while (1) |
|
793 |
{ |
|
794 |
Set_Run_Led((nRunCount>>8) & 1);; |
|
795 |
nRunCount ++; |
|
796 |
//int MyKeyStat1,MyKeyStat2; |
|
797 |
//MyKeyStat1=GetInput(); |
|
798 |
TM1629_disp_on(); |
|
799 |
TM1629_Read_Keys(keybuf); |
|
800 |
keys.value=keybuf[0]; |
|
801 |
|
|
802 |
|
|
803 |
// value1 = nRunCount; |
|
804 |
if (keys.Pinc && !oldkeys.Pinc) { |
|
805 |
value1++; |
|
806 |
} |
|
807 |
if (keys.Pdec && !oldkeys.Pdec) { |
|
808 |
value1--; |
|
809 |
} |
|
810 |
if (keys.Tdec && !oldkeys.Tdec) { |
|
811 |
value2--; |
|
812 |
} |
|
813 |
if (keys.Tinc && !oldkeys.Tinc) { |
|
814 |
value2++; |
|
815 |
} |
|
816 |
|
|
817 |
if (keys.On && !oldkeys.On) { |
|
818 |
bPowerOn = !bPowerOn; |
|
819 |
if (bPowerOn) { |
|
820 |
nShift=0; |
|
821 |
LL_TIM_EnableAllOutputs(TIM1); |
|
822 |
LL_TIM_EnableAllOutputs(TIM15); |
|
823 |
}else { |
|
824 |
nShift=0; |
|
825 |
LL_TIM_DisableAllOutputs(TIM1); |
|
826 |
LL_TIM_DisableAllOutputs(TIM15); |
|
827 |
} |
|
828 |
} |
|
829 |
if (keys.sweep && !oldkeys.sweep) { |
|
830 |
bSweep = !bSweep; |
|
831 |
if (bSweep) { |
|
832 |
bEnableSpan = 1; |
|
833 |
}else { |
|
834 |
bEnableSpan = 0; |
|
835 |
} |
|
836 |
} |
|
837 |
|
|
838 |
oldkeys = keys; |
|
839 |
|
|
840 |
int time1=GetuS(); |
|
841 |
// line1[0]= LEDSEGTAB[value1%10]; |
|
842 |
// line1[1]= LEDSEGTAB[value1/10%10]; |
|
843 |
// line1[2]= LEDSEGTAB[value1/100%10]; |
|
844 |
// line1[3]= LEDSEGTAB[value1/1000%10]; |
|
845 |
|
|
846 |
if (!bPowerOn) { |
|
847 |
line1[0] = LEDSEGTAB[15]; |
|
848 |
line1[1] = LEDSEGTAB[15]; |
|
849 |
line1[2] = LEDSEGTAB[0]; |
|
850 |
line1[3] = LEDSEGTAB[33]; |
|
851 |
}else { |
|
852 |
line1[3] = LEDSEGTAB[15]; |
|
853 |
line1[2] = LEDSEGTAB[2]; |
|
854 |
line1[1] = LEDSEGTAB[8+16]; |
|
855 |
line1[0] = LEDSEGTAB[0]; |
|
856 |
} |
|
857 |
|
|
858 |
ledbuf1[8]=line1[0]; |
|
859 |
ledbuf1[0xa]=line1[1]; |
|
860 |
ledbuf1[0xc]=line1[2]; |
|
861 |
ledbuf1[0xe]=line1[3]; |
|
862 |
|
|
863 |
int time2=GetuS(); |
|
864 |
int dt = time2-time1; |
|
865 |
// value2 = dt; |
|
866 |
int nCurrent = 0; |
|
867 |
value2 = nCurrent; |
|
868 |
|
|
869 |
line2[0]= LEDSEGTAB[10]; // 'A' |
|
870 |
line2[1]= LEDSEGTAB[value2%10]; // '0' - '9' |
|
871 |
line2[2]= LEDSEGTAB[value2/10%10 + 16]; // '0.' - '9.' |
|
872 |
if (value2>=100) { line2[3]= LEDSEGTAB[value2/100%10]; } |
|
873 |
else {line2[3] = keybuf[0];} |
|
874 |
ledbuf1[1]=line2[0]; |
|
875 |
ledbuf1[3]=line2[1]; |
|
876 |
ledbuf1[5]=line2[2]; |
|
877 |
ledbuf1[7]=line2[3]; |
|
878 |
|
|
879 |
int nTime = 0; |
|
880 |
value3 = nTime; |
|
881 |
line3[0]= LEDSEGTAB[value3%10]; |
|
882 |
line3[1]= LEDSEGTAB[value3/10%10]; |
|
883 |
line3[2]= LEDSEGTAB[value3/100%10]; |
|
884 |
line3[3]= LEDSEGTAB[value3/1000%10]; |
|
885 |
|
|
886 |
ledbuf1[0]=line3[0]; |
|
887 |
ledbuf1[2]=line3[1]; |
|
888 |
ledbuf1[4]=line3[2]; |
|
889 |
ledbuf1[6]=line3[3]; |
|
890 |
|
|
891 |
// ledbuf1[9]=line4[3]; |
|
892 |
|
|
893 |
int level = (1<<((nRunCount>>2) &0x1f)) - 1; |
|
894 |
level = (1<<((nShift/32+4) &0x1f)) - 1; |
|
895 |
line4[0]=level&0xff; |
|
896 |
line4[1]=(level>>8)&0xff; |
|
897 |
line4[2]=(level>>16)&0xff; |
|
898 |
ledbuf1[0xb]=line4[2]; |
|
899 |
ledbuf1[0xd]=line4[1]; |
|
900 |
ledbuf1[0xf]=line4[0]; |
|
901 |
|
|
902 |
|
|
903 |
|
|
904 |
TM1629_Send_Data(0,ledbuf1,16); |
|
905 |
DelayUs(100); |
|
906 |
//*((unsigned int *)&(PLCMem.SDT[10]))=nRunCount; |
|
907 |
// KMem.nRunCount=nRunCount; |
|
908 |
if (bEnableSpan && (nRunCount&0x1) == 0x1) { |
|
909 |
|
|
910 |
nCurFreqFct --; |
|
911 |
if (nCurFreqFct <= nMinFreqFrc) { |
|
912 |
nCurFreqFct = nMaxFreqFct; |
|
913 |
} |
|
914 |
LL_TIM_SetAutoReload(TIM15,nCurFreqFct); |
|
915 |
LL_TIM_SetAutoReload(TIM1,nCurFreqFct); |
|
916 |
LL_TIM_OC_SetCompareCH1(TIM1,(nCurFreqFct+1)/2-1); |
|
917 |
LL_TIM_OC_SetCompareCH4(TIM1,(nCurFreqFct+1)/2-1); |
|
918 |
LL_TIM_OC_SetCompareCH1(TIM15,(nCurFreqFct+1)/2-1); |
|
919 |
} |
|
920 |
|
|
921 |
if (bPowerOn&&bShift && (nRunCount&0x3) == 0x2) { |
|
922 |
if (nDir == 1) { |
|
923 |
if (nShift < 700 -1) {nShift+=1;} |
|
924 |
else {nDir = 0;} |
|
925 |
}else { |
|
926 |
if (nShift > 1) {nShift-=1;} |
|
927 |
else {nDir = 1;} |
|
928 |
} |
|
929 |
LL_TIM_OC_SetCompareCH2(TIM15,nShift); |
|
930 |
} |
|
931 |
|
|
932 |
|
|
933 |
ADCProcess(); |
|
934 |
int a; |
|
935 |
a = LL_GPIO_ReadInputPort(GPIOA); |
|
936 |
KMem.WDT[120]=a; |
|
937 |
a = LL_GPIO_ReadInputPort(GPIOB); |
|
938 |
KMem.WDT[121]=a; |
|
939 |
a = LL_GPIO_ReadInputPort(GPIOC); |
|
940 |
KMem.WDT[122]=a; |
|
941 |
a = LL_GPIO_ReadInputPort(GPIOD); |
|
942 |
KMem.WDT[123]=a; |
|
943 |
|
|
944 |
us2=GetuS(); |
|
945 |
if (PowerDownFlag) { KMem.WX[0]=0;} |
|
946 |
///* |
|
947 |
if ((KMem.nRunCount &0x1f) == 0x02) |
|
948 |
{ |
|
949 |
|
|
950 |
if (PowerDownFlag) |
|
951 |
{ |
|
952 |
KMem.WX[0]=0; |
|
953 |
if (!OldPowerDownFlag) |
|
954 |
{ |
|
955 |
OldPowerDownFlag = PowerDownFlag; |
|
956 |
OldPowerDownEventTime = nCurTick; |
|
957 |
// PowerDownProcess(); |
|
958 |
} |
|
959 |
}else |
|
960 |
{ |
|
961 |
if (OldPowerDownFlag) |
|
962 |
{ |
|
963 |
OldPowerDownFlag=PowerDownFlag; |
|
964 |
// PowerRecoverProcess(); |
|
965 |
|
|
966 |
} |
|
967 |
} |
|
968 |
} |
|
969 |
//*/ |
|
970 |
|
|
971 |
|
|
972 |
|
|
973 |
|
|
974 |
|
|
975 |
|
|
976 |
// int nSize=sizeof(stKBusChnStat); |
|
977 |
// memcpy(&KMem.SDT[64],&KBusChnStats[1],nSize); |
|
978 |
// memcpy(&KMem.SDT[64+nSize/2],&KBusChnStats[2],nSize); |
|
979 |
// for (int i=0;i<128;i++) { SDT[i]=i; } |
|
980 |
// SDT[48]=55; |
|
981 |
/* |
|
982 |
if (Uart1RxBuf1DataLen >0 && Uart1Stat.bPacketRecved) |
|
983 |
{ |
|
984 |
int res1 = -1; |
|
985 |
res1 = ModBusSlaveParsePkg(1, Uart1RxBuf1, Uart1RxBuf1DataLen); |
|
986 |
if (res1 !=0) |
|
987 |
{ |
|
988 |
KLParsePacket(1, Uart1RxBuf1, Uart1RxBuf1DataLen); |
|
989 |
} |
|
990 |
Uart1RxBuf1DataLen=0; |
|
991 |
Uart1Stat.bPacketRecved=0; |
|
992 |
Uart1IdelTimer = 0; |
|
993 |
}else { |
|
994 |
if (Uart1IdelTimer>600000) { // 超过60秒没有数据传输,重新进入自适应波特率状态 |
|
995 |
LL_USART_EnableAutoBaudRate(USART1); |
|
996 |
LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
997 |
}else { |
|
998 |
Uart1IdelTimer++; |
|
999 |
} |
|
1000 |
} |
|
1001 |
*/ |
|
1002 |
|
|
1003 |
// LL_IWDG_ReloadCounter(IWDG); |
|
1004 |
|
|
1005 |
} //while (1) ; |
|
1006 |
/* USER CODE END WHILE */ |
|
1007 |
|
|
1008 |
/* USER CODE BEGIN 3 */ |
|
1009 |
|
|
1010 |
/* USER CODE END 3 */ |
|
1011 |
|
|
1012 |
} |
|
1013 |
|
|
1014 |
|
|
1015 |
/* USER CODE BEGIN 4 */ |
|
1016 |
|
|
1017 |
/* USER CODE END 4 */ |
|
1018 |
|
|
1019 |
/** |
|
1020 |
* @brief This function is executed in case of error occurrence. |
|
1021 |
* @param file: The file name as string. |
|
1022 |
* @param line: The line in file as a number. |
|
1023 |
* @retval None |
|
1024 |
*/ |
|
1025 |
void _Error_Handler(char *file, int line) |
|
1026 |
{ |
|
1027 |
/* USER CODE BEGIN Error_Handler_Debug */ |
|
1028 |
/* User can add his own implementation to report the HAL error return state */ |
|
1029 |
while(1) |
|
1030 |
{ |
|
1031 |
} |
|
1032 |
/* USER CODE END Error_Handler_Debug */ |
|
1033 |
} |
|
1034 |
|
|
1035 |
#ifdef USE_FULL_ASSERT |
|
1036 |
/** |
|
1037 |
* @brief Reports the name of the source file and the source line number |
|
1038 |
* where the assert_param error has occurred. |
|
1039 |
* @param file: pointer to the source file name |
|
1040 |
* @param line: assert_param error line source number |
|
1041 |
* @retval None |
|
1042 |
*/ |
|
1043 |
void assert_failed(uint8_t* file, uint32_t line) |
|
1044 |
{ |
|
1045 |
/* USER CODE BEGIN 6 */ |
|
1046 |
/* User can add his own implementation to report the file name and line number, |
|
1047 |
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
|
1048 |
/* USER CODE END 6 */ |
|
1049 |
} |
|
1050 |
#endif /* USE_FULL_ASSERT */ |
|
1051 |
|
|
1052 |
/** |
|
1053 |
* @} |
|
1054 |
*/ |
|
1055 |
|
|
1056 |
/** |
|
1057 |
* @} |
|
1058 |
*/ |
|
1059 |
|
|
1060 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |