提交 | 用户 | age
|
5dd1b7
|
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) |
|
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 |
|
005755
|
82 |
unsigned char Uart1RxBuf1[Uart1RxBufSize]; |
Q |
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 |
|
5dd1b7
|
107 |
unsigned char SlowFlicker=0; |
Q |
108 |
unsigned char FastFlicker=0; |
|
109 |
|
|
110 |
unsigned int Uart1IdelTimer = 0; |
|
111 |
|
|
112 |
uint32_t us1,us2,us3,us4,us5,us6; |
|
113 |
|
842bb6
|
114 |
|
Q |
115 |
stKBusDef KBus1; // |
|
116 |
|
|
117 |
extern stDeviceInfo MyDeviceInfo; |
5dd1b7
|
118 |
/* USER CODE END PV */ |
Q |
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 */ |
005755
|
135 |
#define SET_SCL LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_6) |
Q |
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 |
|
5dd1b7
|
312 |
|
Q |
313 |
int HexToInt(char ch) |
|
314 |
{ |
|
315 |
if (ch>='0' && ch <='9') return ch-'0'; |
|
316 |
if (ch>='A' && ch <='F') return ch-'A'+10; |
|
317 |
if (ch>='a' && ch <='f') return ch-'a'+10; |
|
318 |
return 0; |
|
319 |
} |
|
320 |
|
|
321 |
void HAL_SYSTICK_Callback(void) |
|
322 |
{ |
|
323 |
static int Count=0; |
|
324 |
CurTickuS += 100; |
|
325 |
nCurTick++; |
842bb6
|
326 |
KBus1.nSlaveTick++; |
5dd1b7
|
327 |
Count++; |
Q |
328 |
if (Count>=10000) |
|
329 |
{ |
|
330 |
Count=0; |
|
331 |
KMem.CurTimeSec++; |
|
332 |
KMem.ThisRunTime++; KMem.TotalRunTime++; |
|
333 |
if (KMRunStat.bLEDFlick) KMRunStat.bLEDFlick--; |
|
334 |
if (KMRunStat.bLEDFlick >120) KMRunStat.bLEDFlick=120; |
|
335 |
} |
|
336 |
|
|
337 |
return; |
|
338 |
} |
|
339 |
|
842bb6
|
340 |
void PendSvCallBack() |
Q |
341 |
{ |
|
342 |
#if (BOARD_TYPE == 14) |
|
343 |
///* |
|
344 |
if (bSPI1RecvDone) |
|
345 |
{ |
|
346 |
bSPI1RecvDone=0; |
|
347 |
FPxParsePkt(SPI1RecvBuf,nSPI1RecvLenInBuf); |
|
348 |
} |
|
349 |
//*/ |
|
350 |
#endif |
|
351 |
if (Uart2Stat.bPacketRecved) |
|
352 |
{ |
005755
|
353 |
KBusParsePacket(&KBus1, (pKBPacket)Uart2RxBuf1, Uart2RxBuf1DataLen); |
Q |
354 |
Uart2RxBuf1DataLen=0; |
842bb6
|
355 |
Uart2Stat.bPacketRecved=0; |
005755
|
356 |
Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1)); |
842bb6
|
357 |
KMem.WDT[2]++; |
Q |
358 |
} |
|
359 |
} |
|
360 |
|
|
361 |
/* |
|
362 |
KBus通讯回调函数,当通讯状态改变或数据更新时被调用。 |
|
363 |
或者系统请求时。 |
|
364 |
*/ |
|
365 |
void * KBusEvCallBackFunc(void* pParam, int nEvent, void *pBuf, int nLen1) |
5dd1b7
|
366 |
{ |
Q |
367 |
switch (nEvent){ |
|
368 |
|
|
369 |
case KBusEvNone: |
|
370 |
break; |
|
371 |
case KBusEvCreate: |
|
372 |
break; |
|
373 |
case KBusEvConnected: |
|
374 |
break; |
|
375 |
case KBusEvDisConnected: |
|
376 |
break; |
|
377 |
case KBusEvClosed: |
|
378 |
break; |
|
379 |
case KBusEvStateChange: |
|
380 |
break; |
|
381 |
case KBusEvTimeSync: |
|
382 |
break; |
|
383 |
case KBusEvDataUpdate: |
842bb6
|
384 |
if (KBus1.bMaster) { |
005755
|
385 |
for (int i=0;i<16;i++) |
Q |
386 |
{ |
|
387 |
KMem.WLX[i]=KBusMem.WLX[i]; //KPLC with KBus Master |
|
388 |
KBusMem.WLY[i]=KMem.WLY[i]; |
|
389 |
} |
842bb6
|
390 |
} else if (KBus1.bSlave) { |
Q |
391 |
KMem.WLX[0]=KBusMem.WLY[0]; //KPLC with KBus Slave |
|
392 |
KBusMem.WLX[0]=KMem.WLY[0]; |
005755
|
393 |
KMem.WLX[1]=KBusMem.WLY[1]; //KPLC with KBus Slave |
Q |
394 |
KBusMem.WLX[1]=KMem.WLY[1]; |
|
395 |
KMem.WLX[2]=KBusMem.WLY[2]; //KPLC with KBus Slave |
|
396 |
KBusMem.WLX[2]=KMem.WLY[2]; |
|
397 |
KMem.WLX[3]=KBusMem.WLY[3]; //KPLC with KBus Slave |
|
398 |
KBusMem.WLX[3]=KMem.WLY[3]; |
842bb6
|
399 |
} |
005755
|
400 |
|
5dd1b7
|
401 |
break; |
Q |
402 |
case KBusEvCmdResponse: |
|
403 |
break; |
|
404 |
|
|
405 |
default: |
|
406 |
break; |
|
407 |
} |
|
408 |
return 0; |
|
409 |
} |
842bb6
|
410 |
|
5dd1b7
|
411 |
|
Q |
412 |
/* USER CODE END 0 */ |
|
413 |
|
|
414 |
/** |
|
415 |
* @brief The application entry point. |
|
416 |
* |
|
417 |
* @retval None |
|
418 |
*/ |
|
419 |
int main(void) |
|
420 |
{ |
|
421 |
/* USER CODE BEGIN 1 */ |
|
422 |
KMRunStat.bLEDFlick = 1; |
|
423 |
|
|
424 |
InitUartstat(&Uart1Stat,Uart1RxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf)); |
|
425 |
InitUartstat(&Uart2Stat,Uart2RxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf)); |
|
426 |
/* USER CODE END 1 */ |
|
427 |
|
|
428 |
/* MCU Configuration----------------------------------------------------------*/ |
|
429 |
|
|
430 |
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
|
431 |
HAL_Init(); |
|
432 |
|
|
433 |
/* USER CODE BEGIN Init */ |
|
434 |
|
|
435 |
|
|
436 |
KMem.LastScanTime=0; |
|
437 |
KMem.ScanTimeuS=0; |
|
438 |
KMem.MinScanTimeuS=99999; |
|
439 |
KMem.MaxScanTimeuS=0; |
|
440 |
|
|
441 |
// KMem.SDD[14]=(unsigned int)&KMStoreSysCfg; |
|
442 |
// KMem.SDD[15]=(unsigned int)&KMStoreSysCfg1; |
|
443 |
KMem.SDD[12]=((uint32_t *)UID_BASE)[0]; |
|
444 |
// KMem.SDD[13]=((uint32_t *)UID_BASE)[1]; |
|
445 |
// KMem.SDD[14]=((uint32_t *)UID_BASE)[2]; |
|
446 |
KMem.SDD[13]=PendSvCount; |
|
447 |
KMem.SDD[14]=RCC->CSR; |
|
448 |
// KMem.SDD[15]=*(uint32_t *)FLASHSIZE_BASE; |
|
449 |
// KMem.SDD[16]=(unsigned int)&KMSysCfg; |
|
450 |
|
|
451 |
/* USER CODE END Init */ |
|
452 |
|
|
453 |
/* Configure the system clock */ |
|
454 |
SystemClock_Config(); |
|
455 |
|
|
456 |
/* USER CODE BEGIN SysInit */ |
|
457 |
TickFreq=10000; //Tick频率 |
|
458 |
InituS(TickFreq); |
|
459 |
// HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq); //重新定义SysTick的频率 |
|
460 |
|
|
461 |
/* USER CODE END SysInit */ |
|
462 |
|
|
463 |
/* Initialize all configured peripherals */ |
|
464 |
MX_GPIO_Init(); |
|
465 |
MX_DMA_Init(); |
|
466 |
|
|
467 |
KMachineInit(); |
|
468 |
ReadSysCfgFromFlash(&storedKMSysCfg); |
|
469 |
|
|
470 |
KMRunStat.bLEDFlick = 1; |
|
471 |
|
842bb6
|
472 |
|
Q |
473 |
KLinkInit(1); |
|
474 |
unsigned char bKBusMaster, bKBusSlave, bKBusRepeater; |
|
475 |
int nKBusStationID; |
|
476 |
int nKBusChilds; |
5dd1b7
|
477 |
KMem.CurJumperSW=ReadJumperSW(); |
Q |
478 |
KMem.EffJumperSW=KMem.CurJumperSW; |
|
479 |
// Uart2Baud = AlterUart2Baud; |
842bb6
|
480 |
nKBusStationID = KMem.EffJumperSW&0x0f; |
Q |
481 |
nKBusChilds = nKBusStationID; |
5dd1b7
|
482 |
|
Q |
483 |
#if (BOARD_TYPE == 14) |
|
484 |
KMem.EffJumperSW|=0x10; |
|
485 |
nStationID=KMem.EffJumperSW&0x0f; |
|
486 |
if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
|
487 |
else{bKBusMaster=0;bKBusSlave=1;} |
|
488 |
nChilds=nStationID; |
842bb6
|
489 |
FP0_Init(nChilds); |
5dd1b7
|
490 |
|
Q |
491 |
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
|
492 |
nStationID=1 ;//KMem.EffJumperSW&0x0f; |
|
493 |
// if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
|
494 |
// else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
|
495 |
// else |
|
496 |
{bKBusMaster=0;bKBusSlave=1;} |
|
497 |
#else |
842bb6
|
498 |
nKBusStationID=KMem.EffJumperSW&0x0f; |
5dd1b7
|
499 |
if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
842bb6
|
500 |
else if ((KMem.EffJumperSW&0x10)!=0) { |
Q |
501 |
bKBusMaster=1;bKBusSlave=0; |
|
502 |
} |
|
503 |
else{ |
|
504 |
bKBusMaster=0;bKBusSlave=1; |
|
505 |
} |
5dd1b7
|
506 |
#endif |
Q |
507 |
|
842bb6
|
508 |
if (bKBusMaster) { |
Q |
509 |
KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds); |
|
510 |
} else if (bKBusSlave) { |
|
511 |
KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationID,&MyDeviceInfo); |
|
512 |
} |
|
513 |
KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc), |
|
514 |
|
|
515 |
UNUSED(bKBusRepeater); |
5dd1b7
|
516 |
|
Q |
517 |
//if (KMem.EffJumperSW == 0x00) |
|
518 |
Uart1Baud = DefaultUart1Baud; |
|
519 |
MX_USART1_UART_Init(); |
|
520 |
MX_USART2_UART_Init(); |
|
521 |
MX_SPI1_Init(); |
|
522 |
LL_SPI_EnableIT_RXNE(SPI1); |
005755
|
523 |
/* |
Q |
524 |
// MX_I2C1_Init(); |
|
525 |
Soft_I2C1_Init(); |
5dd1b7
|
526 |
|
005755
|
527 |
unsigned char buf1[10] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa}; |
Q |
528 |
unsigned char buf2[10]; |
|
529 |
// KMem.WDB[80] = soft_i2c_read_len(0xa0,0x00,8,buf2); |
|
530 |
// for (int i=0;i<8;i++){ |
|
531 |
// buf2[i]+=1; |
|
532 |
// } |
|
533 |
// soft_i2c_write_len (0xa0,0x00,8,buf2); |
|
534 |
// DelayUs(500); |
|
535 |
// KMem.WDB[80] = soft_i2c_read_len(0xa0,0x00,8,&KMem.WDB[81]); |
|
536 |
// DelayUs(500); |
|
537 |
// KMem.WDB[90] = soft_i2c_read_len(0xa0,0x00,8,&KMem.WDB[91]); |
|
538 |
|
|
539 |
int nPos = 80; |
|
540 |
int nCount =0; |
|
541 |
for (int i=0;i<256;i++) |
|
542 |
{ |
|
543 |
if (soft_i2c_check_addr(i)){ |
|
544 |
KMem.WDB[nPos + 1 + nCount ] = i; |
|
545 |
nCount+=1; |
|
546 |
} |
|
547 |
DelayUs(10); |
|
548 |
} |
|
549 |
KMem.WDB[nPos] = nCount; |
|
550 |
*/ |
5dd1b7
|
551 |
#if (BOARD_TYPE == 14) |
Q |
552 |
// MX_SPI2_Init(); |
|
553 |
// MX_ADC_Init(); |
|
554 |
#else |
|
555 |
MX_SPI2_Init(); |
|
556 |
MX_ADC_Init(); |
|
557 |
#endif |
005755
|
558 |
|
5dd1b7
|
559 |
MX_IWDG_Init(); |
Q |
560 |
|
|
561 |
MX_TIM6_Init(); |
|
562 |
LL_TIM_EnableCounter(TIM6); |
|
563 |
|
|
564 |
/* USER CODE BEGIN 2 */ |
|
565 |
LL_USART_EnableIT_RXNE(USART1); |
|
566 |
LL_USART_EnableIT_IDLE(USART1); |
|
567 |
LL_USART_EnableIT_TC(USART1); |
|
568 |
|
|
569 |
// LL_USART_EnableIT_RXNE(USART2); |
005755
|
570 |
Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1)); |
5dd1b7
|
571 |
LL_USART_EnableIT_IDLE(USART2); |
Q |
572 |
LL_USART_EnableIT_TC(USART2); |
|
573 |
#if (BOARD_TYPE == 13) |
|
574 |
int res; |
|
575 |
res = w5500_init(); |
|
576 |
KMem.SDD[28]=res; |
|
577 |
|
|
578 |
// res=socket(0,Sn_MR_TCP,5000,0); |
|
579 |
KMem.SDD[29]=res; |
|
580 |
|
|
581 |
// res = listen(0); |
|
582 |
#endif |
|
583 |
// if (bKBusSlave) |
|
584 |
{ |
|
585 |
// LL_USART_EnableAutoBaudRate(USART1); |
|
586 |
// LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
587 |
// LL_USART_EnableAutoBaudRate(USART2); |
|
588 |
// LL_USART_SetAutoBaudRateMode(USART2, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
589 |
} |
|
590 |
//LL_USART_EnableIT_TXE(USART1); |
005755
|
591 |
|
Q |
592 |
// KMem.WDT[50] = SPI_Flash_ReadID(); |
|
593 |
|
5dd1b7
|
594 |
/* USER CODE END 2 */ |
Q |
595 |
|
|
596 |
|
|
597 |
/* Infinite loop */ |
|
598 |
/* USER CODE BEGIN WHILE */ |
|
599 |
|
|
600 |
HAL_Delay(10); |
|
601 |
SetRunLed(1); //Turn On Run Led |
|
602 |
SetErrLed(0); //Turn Off Err Led |
|
603 |
|
|
604 |
#if (BOARD_TYPE == 14) |
|
605 |
// PutOutput (0); //Clear all Output |
|
606 |
// Enable595(1); //Enable 595 Output |
|
607 |
#else |
|
608 |
PutOutput (0); //Clear all Output |
|
609 |
Enable595(1); //Enable 595 Output |
|
610 |
#endif |
|
611 |
|
|
612 |
if (GetBoardType() == 7 || GetBoardType() ==8 |
|
613 |
|| GetBoardType() == 9 || GetBoardType() ==10 ||GetBoardType() ==13 ||GetBoardType() ==15 || BOARD_TYPE == 16) |
|
614 |
{ |
|
615 |
displayInput(0xffff); // |
|
616 |
EnableDisIn(1); //Input Diaplay Enable 595 |
|
617 |
} |
|
618 |
SetOutStat(0); //OK Good, signal |
|
619 |
ShowInitInfo(); |
|
620 |
KMem.LastScanTime = GetuS(); |
|
621 |
|
|
622 |
KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode; |
|
623 |
|
|
624 |
KMRunStat.WorkMode = 1; |
|
625 |
//KMRunStat.WorkMode2 = 0; |
|
626 |
|
|
627 |
if (KMRunStat.WorkMode == 1){ |
|
628 |
InitPLC(); |
|
629 |
KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ; |
|
630 |
if (KMRunStat.WorkMode2) { |
|
631 |
StartPLC(); } |
|
632 |
} |
|
633 |
KMem.WX[7]=0x5a; |
|
634 |
|
|
635 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
|
636 |
KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
|
637 |
KWireLessStart(); |
|
638 |
#endif |
005755
|
639 |
|
5dd1b7
|
640 |
|
Q |
641 |
while (1) |
|
642 |
{ |
|
643 |
//int MyKeyStat1,MyKeyStat2; |
|
644 |
//MyKeyStat1=GetInput(); |
|
645 |
|
|
646 |
//*((unsigned int *)&(PLCMem.SDT[10]))=nRunCount; |
|
647 |
// KMem.nRunCount=nRunCount; |
|
648 |
SlowFlicker=0; |
|
649 |
FastFlicker=1; |
|
650 |
us1=GetuS(); |
|
651 |
int haltick=HAL_GetTick(); |
|
652 |
|
|
653 |
int thisJumperSW=ReadJumperSW(); |
|
654 |
|
|
655 |
if (KMRunStat.WorkMode&1){ |
|
656 |
if (thisJumperSW&0x20 && !(KMem.CurJumperSW&0x20)) // Run 开关 正 跳变。 |
|
657 |
{StartPLC();} |
|
658 |
if (!(thisJumperSW&0x20) && (KMem.CurJumperSW&0x20)) // Run 开关 负 跳变。 |
|
659 |
{StopPLC();} |
|
660 |
} |
|
661 |
|
|
662 |
KMem.CurJumperSW=thisJumperSW; |
|
663 |
KMem.haltick=haltick; |
|
664 |
// KMem.TotalRunTime=TotalRunTime; |
|
665 |
// KMem.ThisRunTime=ThisRunTime; |
|
666 |
|
|
667 |
// *((unsigned int *)&(PLCMem.SDT[2]))=nChilds; |
|
668 |
// KMem.SDD[13]=PendSvCount; |
|
669 |
// KMem.SDD[14]=RCC->CSR; |
|
670 |
|
842bb6
|
671 |
KMem.WDB[0] = KBus1.MyStat; |
Q |
672 |
KMem.WDB[1] = KBus1.bMaster; |
|
673 |
KMem.WDB[2] = KBus1.bMasterSent; |
|
674 |
KMem.WDB[3] = KBus1.bMasterRecved; |
|
675 |
KMem.WDB[4] = KBus1.bMasterRecvOK; |
|
676 |
KMem.WDB[5] = KBus1.bSlaveRecved; |
|
677 |
|
|
678 |
KMem.WDB[8] = KBus1.RunStat; |
|
679 |
KMem.WDB[9] = KBus1.ErrStat; |
|
680 |
|
5dd1b7
|
681 |
int a; |
Q |
682 |
a = LL_GPIO_ReadInputPort(GPIOA); |
|
683 |
KMem.WDT[120]=a; |
|
684 |
a = LL_GPIO_ReadInputPort(GPIOB); |
|
685 |
KMem.WDT[121]=a; |
|
686 |
a = LL_GPIO_ReadInputPort(GPIOC); |
|
687 |
KMem.WDT[122]=a; |
|
688 |
a = LL_GPIO_ReadInputPort(GPIOD); |
|
689 |
KMem.WDT[123]=a; |
|
690 |
|
|
691 |
#if (BOARD_TYPE == 14) |
|
692 |
// KMem.WX[0]= GetInput(); |
|
693 |
FP0_Proc(); |
|
694 |
#else |
|
695 |
KMem.WX[0]= GetInput(); |
|
696 |
#endif |
|
697 |
|
|
698 |
if (GetBoardType() == 7 || GetBoardType() ==8 |
|
699 |
|| GetBoardType() == 9 || GetBoardType() ==10 || GetBoardType() ==15 || GetBoardType() ==16) |
|
700 |
{ |
|
701 |
displayInput(KMem.WX[0]); |
|
702 |
} |
|
703 |
us2=GetuS(); |
|
704 |
if (PowerDownEvent) { KMem.WX[0]=0;} |
|
705 |
///* |
|
706 |
if ((KMem.nRunCount &0x1f) == 0x02) |
|
707 |
{ |
|
708 |
ADCProcess(); |
|
709 |
if (PowerDownEvent) |
|
710 |
{ |
|
711 |
KMem.WX[0]=0; |
|
712 |
if (!OldPowerDownEvent) |
|
713 |
{ |
|
714 |
OldPowerDownEvent = PowerDownEvent; |
|
715 |
OldPowerDownEventTime = nCurTick; |
|
716 |
PowerDownProcess(); |
|
717 |
} |
|
718 |
}else |
|
719 |
{ |
|
720 |
if (OldPowerDownEvent) |
|
721 |
{ |
|
722 |
OldPowerDownEvent=PowerDownEvent; |
|
723 |
PowerRecoverProcess(); |
|
724 |
|
|
725 |
} |
|
726 |
} |
|
727 |
} |
|
728 |
//*/ |
|
729 |
|
|
730 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
|
731 |
Radio.IrqProcess( ); // Process Radio IRQ |
|
732 |
KWL_Process(1); |
|
733 |
|
|
734 |
#endif |
|
735 |
|
842bb6
|
736 |
// pProgs = (stBinInstrcn1 *) STORE_PRG_BASE; |
5dd1b7
|
737 |
|
Q |
738 |
if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
|
739 |
{ |
842bb6
|
740 |
stStoredBinProgs * pStoredBinProgs; |
Q |
741 |
|
|
742 |
if (storedKMSysCfg.theKMSysCfg.nProgBank == 0){ |
|
743 |
pStoredBinProgs=((stStoredBinProgs *)STORE_PRG_BASE); |
5dd1b7
|
744 |
}else { |
842bb6
|
745 |
pStoredBinProgs=((stStoredBinProgs *)ALT_PRG_BASE); ; |
5dd1b7
|
746 |
} |
842bb6
|
747 |
int nSizeProg1=pStoredBinProgs->StoredHdr.nSize ; |
Q |
748 |
// pProgs=(stBinInstrcn1 *)prog1; |
5dd1b7
|
749 |
|
842bb6
|
750 |
ProcessPLCBinProg(pStoredBinProgs->BinInstrcns, nSizeProg1); |
5dd1b7
|
751 |
} |
Q |
752 |
|
|
753 |
KMem.ScanTimeuS=us2-KMem.LastScanTime; |
|
754 |
KMem.LastScanTime = us2; |
|
755 |
if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;} |
|
756 |
if (KMem.ScanTimeuS > KMem.MaxScanTimeuS) {KMem.MaxScanTimeuS = KMem.ScanTimeuS;} |
|
757 |
|
|
758 |
// if (bKBusRepeater) { KBusRepeaterFunc(); } |
|
759 |
|
|
760 |
us3=GetuS(); |
|
761 |
|
|
762 |
if (bKBusMaster) |
|
763 |
{ |
|
764 |
|
|
765 |
KBusMem.WLY[0]=KMem.WLY[0]; |
|
766 |
|
842bb6
|
767 |
if (nKBusChilds>0) { KBusMasterFunc(&KBus1); } |
5dd1b7
|
768 |
|
Q |
769 |
KMem.WLX[0]=KBusMem.WLX[0]; |
|
770 |
|
|
771 |
} |
|
772 |
if (haltick&0x00002000) SlowFlicker=1; |
|
773 |
else SlowFlicker=0; |
|
774 |
if (haltick&0x00000800) FastFlicker=1; |
|
775 |
else FastFlicker=0; |
|
776 |
|
|
777 |
if (bKBusSlave) |
|
778 |
{ |
|
779 |
// BufferOut[0]=KMem.WX[0]; |
|
780 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
|
781 |
// KBusSlaveFunc(2); |
|
782 |
// if (! KMem.RunStat) {BufferIn[0]=0;} |
|
783 |
// KMem.WY[0]=BufferIn[0]; |
|
784 |
#else |
842bb6
|
785 |
KBusSlaveFunc(&KBus1); |
5dd1b7
|
786 |
if (! KMem.RunStat) {KMem.WLY[0]=0;} |
Q |
787 |
// KMem.WLY[0]=BufferIn[0]; |
|
788 |
#endif |
842bb6
|
789 |
if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1; |
5dd1b7
|
790 |
else SlowFlicker=0; |
842bb6
|
791 |
if (KBus1.nSlaveTick&0x00000800) FastFlicker=1; |
5dd1b7
|
792 |
else FastFlicker=0; |
Q |
793 |
|
|
794 |
} |
|
795 |
|
|
796 |
// KMem.WY[0]=nCount2>>5; |
842bb6
|
797 |
if (KBus1.RunStat) {KBus1.RunStat--;} |
Q |
798 |
if (KBus1.ErrStat) {KBus1.ErrStat--;} |
5dd1b7
|
799 |
|
Q |
800 |
if (KMRunStat.bLEDFlick) |
|
801 |
{ |
|
802 |
SetRunLed(FastFlicker); |
|
803 |
SetErrLed(FastFlicker); |
|
804 |
SetErr2Led(FastFlicker); |
|
805 |
SetOutStat(!FastFlicker); |
|
806 |
//KMRunStat.bLEDFlick-- ; |
|
807 |
} |
|
808 |
else |
|
809 |
{ |
|
810 |
if (KMRunStat.WorkMode==1 ) { |
|
811 |
if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
|
812 |
else {SetRunLed(0);} |
|
813 |
} |
|
814 |
else { |
|
815 |
if (!KMem.RunStat) SetRunLed(SlowFlicker); |
|
816 |
else SetRunLed(FastFlicker); |
|
817 |
} |
842bb6
|
818 |
KMem.ErrStat = 0 + KBus1.ErrStat; |
5dd1b7
|
819 |
if (!KMem.ErrStat) |
Q |
820 |
{ |
|
821 |
SetErrLed(0); |
|
822 |
SetErr2Led(0); |
|
823 |
SetOutStat(1); |
|
824 |
} |
|
825 |
else |
|
826 |
{ |
|
827 |
SetErrLed(FastFlicker); |
|
828 |
SetErr2Led(FastFlicker); |
|
829 |
SetOutStat(0); |
|
830 |
|
|
831 |
} |
|
832 |
} |
|
833 |
|
|
834 |
// SetRunLed(RunStat); |
|
835 |
// SetErrLed(ErrStat); |
|
836 |
|
|
837 |
us4=GetuS(); |
|
838 |
// EffJumperSW = GetInput(20)&0xff; |
|
839 |
|
|
840 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
|
841 |
|
|
842 |
if ((KMem.EffJumperSW&0x10)==0x10) { |
|
843 |
KMem.WFY[1]=KMem.WLY[0]; |
|
844 |
KMem.WLX[0]=KMem.WFX[1]; |
|
845 |
}else |
|
846 |
{ |
|
847 |
KMem.WFY[1]=KMem.WX[0]; |
|
848 |
KMem.WY[0]=KMem.WFX[1]; |
|
849 |
} |
|
850 |
// KMem.WY[0]=KMem.WLY[0]; |
|
851 |
#else |
|
852 |
// KMem.WLX[0]=KMem.WX[0]; |
|
853 |
// KMem.WY[0]=KMem.WLY[0]; |
|
854 |
#endif |
|
855 |
|
|
856 |
us5=GetuS(); |
|
857 |
|
|
858 |
#if (BOARD_TYPE == 14) |
|
859 |
// PutOutput (KMem.WY[0]); |
|
860 |
#else |
|
861 |
PutOutput (KMem.WY[0]); |
|
862 |
#endif |
|
863 |
//PutOutput (KMem.nRunCount>>8); |
|
864 |
//PutOutput(0x0f70); |
|
865 |
|
|
866 |
// if (bKBusMaster) ShowInfo(); |
|
867 |
// if (bKBusSlave) ShowInfo(); |
|
868 |
us6=GetuS(); |
|
869 |
add1(10,10); |
|
870 |
for (int i=0;i<64;i++) |
|
871 |
{ |
|
872 |
// ProcessTimer(i); |
|
873 |
} |
|
874 |
KMem.nRunCount++; |
|
875 |
// int nSize=sizeof(stKBusChnStat); |
|
876 |
// memcpy(&KMem.SDT[64],&KBusChnStats[1],nSize); |
|
877 |
// memcpy(&KMem.SDT[64+nSize/2],&KBusChnStats[2],nSize); |
|
878 |
// for (int i=0;i<128;i++) { SDT[i]=i; } |
|
879 |
// SDT[48]=55; |
005755
|
880 |
if (Uart1RxBuf1DataLen >0 && Uart1Stat.bPacketRecved) |
5dd1b7
|
881 |
{ |
Q |
882 |
int res1 = -1; |
005755
|
883 |
res1 = ModBusSlaveParsePkg(1, Uart1RxBuf1, Uart1RxBuf1DataLen); |
5dd1b7
|
884 |
if (res1 !=0) |
Q |
885 |
{ |
005755
|
886 |
KLParsePacket(1, Uart1RxBuf1, Uart1RxBuf1DataLen); |
5dd1b7
|
887 |
} |
005755
|
888 |
Uart1RxBuf1DataLen=0; |
5dd1b7
|
889 |
Uart1Stat.bPacketRecved=0; |
Q |
890 |
Uart1IdelTimer = 0; |
|
891 |
}else { |
|
892 |
if (Uart1IdelTimer>600000) { // 超过60秒没有数据传输,重新进入自适应波特率状态 |
|
893 |
LL_USART_EnableAutoBaudRate(USART1); |
|
894 |
LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
895 |
}else { |
|
896 |
Uart1IdelTimer++; |
|
897 |
} |
|
898 |
} |
|
899 |
if (bKBusSlave) HAL_Delay(0); |
|
900 |
/* |
|
901 |
if (!IsEmpty(&Uart1Stat.QRx)) |
|
902 |
{ |
|
903 |
unsigned char k=PopOne(&Uart1Stat.QRx); |
|
904 |
if (k=='L') |
|
905 |
{ |
|
906 |
clearscreen(); |
|
907 |
} |
|
908 |
} |
|
909 |
*/ |
|
910 |
|
|
911 |
#if (BOARD_TYPE == 14) |
|
912 |
const unsigned int pins[6]= { LL_GPIO_PIN_10,LL_GPIO_PIN_11,LL_GPIO_PIN_12,LL_GPIO_PIN_13,LL_GPIO_PIN_14,LL_GPIO_PIN_15}; |
|
913 |
//process 6 output |
|
914 |
{ |
|
915 |
// mapping bits. |
|
916 |
for (int i=0;i<6;i++) |
|
917 |
{ |
|
918 |
USHORT bitaddr = storedKMSysCfg.theKMSysCfg.OutMappings[i]; |
|
919 |
UCHAR type = (bitaddr&0xf000) >>12; |
|
920 |
USHORT byteaddr = (bitaddr&0x0ff0) >>4; |
|
921 |
UCHAR bitpos = bitaddr &0x0f; |
|
922 |
UCHAR bitvalue = 0 ; |
|
923 |
if (byteaddr>0) { |
|
924 |
if (type == 0) bitvalue = KMem.WXB[byteaddr-1] & ( 1 << bitpos ); |
|
925 |
else if (type == 1 ) bitvalue = KMem.WYB[byteaddr-1] & ( 1 << bitpos ); |
|
926 |
} |
|
927 |
if (bitvalue){ LL_GPIO_SetOutputPin(GPIOB,pins[i]);} |
|
928 |
else {LL_GPIO_ResetOutputPin(GPIOB,pins[i]);} |
|
929 |
} |
|
930 |
} |
|
931 |
#endif |
|
932 |
|
|
933 |
/* |
|
934 |
{ |
|
935 |
unsigned char pos,seg; |
|
936 |
unsigned short val; |
|
937 |
pos=((KMem.nRunCount)&0x3); |
|
938 |
//val=(KMem.nRunCount)&0xfff; |
|
939 |
val=KMem.ErrStat; |
|
940 |
char buf5[20]; |
|
941 |
sprintf(buf5,"%4d",val); |
|
942 |
val=buf5[3-pos]; |
|
943 |
if (val <'0' || val >'9') {seg=0;} |
|
944 |
else {seg=LEDSEGTAB[val-'0'];} |
|
945 |
|
|
946 |
pos=1<<pos; |
|
947 |
//pos=1; |
|
948 |
//seg=2; |
|
949 |
seg=~seg; |
|
950 |
// PutOutputSPI1(pos|(seg<<8)); |
|
951 |
} |
|
952 |
*/ |
|
953 |
|
|
954 |
#if (BOARD_TYPE == 13) |
|
955 |
w5500_network_info_show(); |
|
956 |
// loopback_tcps(0,str1,5000); |
|
957 |
#endif |
|
958 |
|
|
959 |
LL_IWDG_ReloadCounter(IWDG); |
|
960 |
|
|
961 |
} //while (1) ; |
|
962 |
/* USER CODE END WHILE */ |
|
963 |
|
|
964 |
/* USER CODE BEGIN 3 */ |
|
965 |
|
|
966 |
/* USER CODE END 3 */ |
|
967 |
|
|
968 |
} |
|
969 |
|
|
970 |
|
|
971 |
/* USER CODE BEGIN 4 */ |
|
972 |
|
|
973 |
/* USER CODE END 4 */ |
|
974 |
|
|
975 |
/** |
|
976 |
* @brief This function is executed in case of error occurrence. |
|
977 |
* @param file: The file name as string. |
|
978 |
* @param line: The line in file as a number. |
|
979 |
* @retval None |
|
980 |
*/ |
|
981 |
void _Error_Handler(char *file, int line) |
|
982 |
{ |
|
983 |
/* USER CODE BEGIN Error_Handler_Debug */ |
|
984 |
/* User can add his own implementation to report the HAL error return state */ |
|
985 |
while(1) |
|
986 |
{ |
|
987 |
} |
|
988 |
/* USER CODE END Error_Handler_Debug */ |
|
989 |
} |
|
990 |
|
|
991 |
#ifdef USE_FULL_ASSERT |
|
992 |
/** |
|
993 |
* @brief Reports the name of the source file and the source line number |
|
994 |
* where the assert_param error has occurred. |
|
995 |
* @param file: pointer to the source file name |
|
996 |
* @param line: assert_param error line source number |
|
997 |
* @retval None |
|
998 |
*/ |
|
999 |
void assert_failed(uint8_t* file, uint32_t line) |
|
1000 |
{ |
|
1001 |
/* USER CODE BEGIN 6 */ |
|
1002 |
/* User can add his own implementation to report the file name and line number, |
|
1003 |
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
|
1004 |
/* USER CODE END 6 */ |
|
1005 |
} |
|
1006 |
#endif /* USE_FULL_ASSERT */ |
|
1007 |
|
|
1008 |
/** |
|
1009 |
* @} |
|
1010 |
*/ |
|
1011 |
|
|
1012 |
/** |
|
1013 |
* @} |
|
1014 |
*/ |
|
1015 |
|
|
1016 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |