提交 | 用户 | age
|
483170
|
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 |
|
|
74 |
|
7eb19e
|
75 |
unsigned char Uart1RxBuf1[Uart1RxBufSize]; |
Q |
76 |
unsigned char Uart1TxBuf1[260]; |
|
77 |
|
|
78 |
unsigned char Uart2RxBuf1[RX2BUFSIZE]; |
|
79 |
unsigned char Uart2TxBuf1[TX2BUFSIZE]; |
|
80 |
|
|
81 |
unsigned short Uart1RxBuf1DataLen = 0; |
|
82 |
unsigned short Uart2RxBuf1DataLen = 0; |
483170
|
83 |
|
Q |
84 |
unsigned char SlowFlicker=0; |
|
85 |
unsigned char FastFlicker=0; |
|
86 |
|
|
87 |
unsigned int Uart1IdelTimer = 0; |
7eb19e
|
88 |
unsigned char Uart1Mode = 1; //Uart1工作模式, 0 : 普通, 1 : 透传模式 |
Q |
89 |
|
|
90 |
unsigned int Uart1Baud = DefaultUart1Baud; |
|
91 |
unsigned int Uart2Baud = DefaultUart2Baud; |
|
92 |
|
|
93 |
//unsigned char Uart1RecvBuf1[Uart1RecvBufSize]; |
|
94 |
//unsigned short Uart1RecvBuf1DataLen=0; |
|
95 |
|
|
96 |
//unsigned char Uart2RecvBuf1[128]; |
|
97 |
//unsigned short Uart2RecvBuf1DataLen=0; |
|
98 |
|
|
99 |
volatile char Uart1BaudGot=0; |
|
100 |
volatile char Uart1BaudFirstGot=0; |
|
101 |
volatile char Uart1DmaInts=0; |
|
102 |
|
|
103 |
|
842bb6
|
104 |
#if (ENABLE_PLC) |
483170
|
105 |
stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; |
842bb6
|
106 |
#endif |
483170
|
107 |
uint32_t us1,us2,us3,us4,us5,us6; |
842bb6
|
108 |
|
Q |
109 |
stKBusDef KBus1; // |
|
110 |
|
|
111 |
extern stDeviceInfo MyDeviceInfo; |
483170
|
112 |
|
Q |
113 |
/* USER CODE END PV */ |
|
114 |
|
|
115 |
/* Private function prototypes -----------------------------------------------*/ |
|
116 |
|
|
117 |
|
|
118 |
/* USER CODE BEGIN PFP */ |
|
119 |
/* Private function prototypes -----------------------------------------------*/ |
|
120 |
|
|
121 |
const unsigned char LEDSEGTAB[]={ |
|
122 |
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71, //0-F |
|
123 |
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1, //0.-F. |
|
124 |
0x00,0x40, // ,-,_,~,o,n,N,<,>,J,r, |
|
125 |
}; |
|
126 |
|
|
127 |
/* USER CODE END PFP */ |
|
128 |
|
|
129 |
/* USER CODE BEGIN 0 */ |
|
130 |
|
|
131 |
int HexToInt(char ch) |
|
132 |
{ |
|
133 |
if (ch>='0' && ch <='9') return ch-'0'; |
|
134 |
if (ch>='A' && ch <='F') return ch-'A'+10; |
|
135 |
if (ch>='a' && ch <='f') return ch-'a'+10; |
|
136 |
return 0; |
|
137 |
} |
|
138 |
|
|
139 |
void HAL_SYSTICK_Callback(void) |
|
140 |
{ |
|
141 |
static int Count=0; |
|
142 |
CurTickuS += 100; |
|
143 |
nCurTick++; |
842bb6
|
144 |
KBus1.nSlaveTick++; |
483170
|
145 |
Count++; |
Q |
146 |
if (Count>=10000) |
|
147 |
{ |
|
148 |
Count=0; |
|
149 |
KMem.CurTimeSec++; |
|
150 |
KMem.ThisRunTime++; KMem.TotalRunTime++; |
|
151 |
if (KMRunStat.bLEDFlick) KMRunStat.bLEDFlick--; |
|
152 |
if (KMRunStat.bLEDFlick >120) KMRunStat.bLEDFlick=120; |
|
153 |
} |
|
154 |
|
|
155 |
return; |
|
156 |
} |
842bb6
|
157 |
|
Q |
158 |
|
|
159 |
void PendSvCallBack() |
|
160 |
{ |
|
161 |
#if (BOARD_TYPE == 14) |
|
162 |
///* |
|
163 |
if (bSPI1RecvDone) |
|
164 |
{ |
|
165 |
bSPI1RecvDone=0; |
|
166 |
FPxParsePkt(SPI1RecvBuf,nSPI1RecvLenInBuf); |
|
167 |
} |
|
168 |
//*/ |
|
169 |
#endif |
|
170 |
if (Uart2Stat.bPacketRecved) |
|
171 |
{ |
7eb19e
|
172 |
KBusParsePacket(&KBus1, (pKBPacket)Uart2RxBuf1, Uart2RxBuf1DataLen); |
Q |
173 |
Uart2RxBuf1DataLen=0; |
842bb6
|
174 |
Uart2Stat.bPacketRecved=0; |
7eb19e
|
175 |
Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1)); |
842bb6
|
176 |
KMem.WDT[2]++; |
Q |
177 |
} |
7eb19e
|
178 |
if (Uart1RxBuf1DataLen >0 && Uart1Stat.bPacketRecved) |
7d8ba5
|
179 |
{ |
Q |
180 |
int res1 = -1; |
7eb19e
|
181 |
if (Uart1RxBuf1DataLen == 3 && Uart1RxBuf1[0]=='+' && Uart1RxBuf1[0]=='+' && Uart1RxBuf1[0]=='+') |
7d8ba5
|
182 |
{ |
7eb19e
|
183 |
Uart1Mode = 0; // 切换到命令模式 |
Q |
184 |
}else if (Uart1RxBuf1DataLen == 3 && Uart1RxBuf1[0]=='-' && Uart1RxBuf1[0]=='-' && Uart1RxBuf1[0]=='-') |
|
185 |
{ |
|
186 |
Uart1Mode = 1; // 切换到透传模式 |
|
187 |
}else if (Uart1Mode == 0) { |
|
188 |
|
|
189 |
res1 = ModBusSlaveParsePkg(1, Uart1RxBuf1, Uart1RxBuf1DataLen); |
|
190 |
if (res1 !=0) |
|
191 |
{ |
|
192 |
KLParsePacket(1, Uart1RxBuf1, Uart1RxBuf1DataLen); |
|
193 |
} |
|
194 |
|
|
195 |
}else if (Uart1Mode == 1) { |
|
196 |
// 透传模式 |
|
197 |
if (KwRunStat.sizetosend == 0) { |
|
198 |
memcpy( KwRunStat.ttTxBuf1,Uart1RxBuf1, Uart1RxBuf1DataLen); |
|
199 |
KwRunStat.sentsize = 0; |
|
200 |
KwRunStat.sizesending = 0; |
|
201 |
KwRunStat.sizetosend = Uart1RxBuf1DataLen; |
|
202 |
}else { |
|
203 |
return; |
|
204 |
} |
|
205 |
|
|
206 |
//SendPacket(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); |
7d8ba5
|
207 |
} |
7eb19e
|
208 |
Uart1RxBuf1DataLen=0; |
7d8ba5
|
209 |
Uart1Stat.bPacketRecved=0; |
7eb19e
|
210 |
Uart1IdelTimer = 0; |
7d8ba5
|
211 |
} |
842bb6
|
212 |
} |
Q |
213 |
|
|
214 |
/* |
|
215 |
KBus通讯回调函数,当通讯状态改变或数据更新时被调用。 |
|
216 |
或者系统请求时。 |
|
217 |
*/ |
|
218 |
void * KBusEvCallBackFunc(void* pParam, int nEvent, void *pBuf, int nLen1) |
|
219 |
{ |
|
220 |
switch (nEvent){ |
|
221 |
|
|
222 |
case KBusEvNone: |
|
223 |
break; |
|
224 |
case KBusEvCreate: |
|
225 |
break; |
|
226 |
case KBusEvConnected: |
|
227 |
break; |
|
228 |
case KBusEvDisConnected: |
|
229 |
break; |
|
230 |
case KBusEvClosed: |
|
231 |
break; |
|
232 |
case KBusEvStateChange: |
|
233 |
break; |
|
234 |
case KBusEvTimeSync: |
|
235 |
break; |
|
236 |
case KBusEvDataUpdate: |
|
237 |
KMem.WLX[0] = KBusMem.WLX[0]; |
|
238 |
KMem.WLY[0] = KBusMem.WLY[0]; |
|
239 |
|
|
240 |
if (KBus1.bMaster) { |
|
241 |
KMem.WY[0]=KBusMem.WLX[0]; //KPLC with KBus Master |
|
242 |
KBusMem.WLY[0]=KMem.WX[0]; |
|
243 |
} else if (KBus1.bSlave) { |
|
244 |
KMem.WYB[0]=KBusMem.WLYB[0]; //WireLess with KBus Slave |
|
245 |
KBusMem.WLXB[0]=KMem.WXB[0]; |
|
246 |
|
|
247 |
} |
|
248 |
break; |
|
249 |
case KBusEvCmdResponse: |
|
250 |
break; |
|
251 |
|
|
252 |
default: |
|
253 |
break; |
|
254 |
} |
|
255 |
return 0; |
|
256 |
} |
|
257 |
|
483170
|
258 |
|
Q |
259 |
/* USER CODE END 0 */ |
|
260 |
|
|
261 |
/** |
|
262 |
* @brief The application entry point. |
|
263 |
* |
|
264 |
* @retval None |
|
265 |
*/ |
|
266 |
int main(void) |
|
267 |
{ |
|
268 |
/* USER CODE BEGIN 1 */ |
|
269 |
KMRunStat.bLEDFlick = 1; |
|
270 |
|
7eb19e
|
271 |
InitUartstat(&Uart1Stat,Uart1RxBuf1,sizeof(Uart1RxBuf1),Uart1TxBuf1,sizeof(Uart1TxBuf1)); |
Q |
272 |
// InitUartstat(&Uart2Stat,Uart2RxBuf1,sizeof(Uart2RxBuf1),Uart2TxBuf1,sizeof(Uart2TxBuf1)); |
483170
|
273 |
/* USER CODE END 1 */ |
Q |
274 |
|
|
275 |
/* MCU Configuration----------------------------------------------------------*/ |
|
276 |
|
|
277 |
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
|
278 |
HAL_Init(); |
|
279 |
|
|
280 |
/* USER CODE BEGIN Init */ |
|
281 |
|
|
282 |
|
|
283 |
/* USER CODE END Init */ |
|
284 |
|
|
285 |
/* Configure the system clock */ |
|
286 |
SystemClock_Config(); |
|
287 |
|
|
288 |
/* USER CODE BEGIN SysInit */ |
|
289 |
TickFreq=10000; //Tick频率 |
|
290 |
InituS(TickFreq); |
|
291 |
// HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq); //重新定义SysTick的频率 |
|
292 |
|
|
293 |
/* USER CODE END SysInit */ |
|
294 |
|
|
295 |
/* Initialize all configured peripherals */ |
|
296 |
MX_GPIO_Init(); |
|
297 |
MX_DMA_Init(); |
|
298 |
|
|
299 |
KMachineInit(); |
|
300 |
ReadSysCfgFromFlash(&storedKMSysCfg); |
|
301 |
|
|
302 |
KMRunStat.bLEDFlick = 1; |
|
303 |
|
842bb6
|
304 |
KLinkInit(1); //注册KLink端口 |
Q |
305 |
|
|
306 |
// stPortDef PortReg1 = {.nPortHardType = 3,.nPortUseType = 2}; |
|
307 |
// KMRegisterPort(0,&PortReg1); |
|
308 |
|
|
309 |
|
|
310 |
unsigned char bKBusMaster, bKBusSlave, bKBusRepeater; |
|
311 |
int nKBusStationID; |
|
312 |
int nKBusChilds; |
|
313 |
|
483170
|
314 |
KMem.CurJumperSW=ReadJumperSW(); |
Q |
315 |
KMem.EffJumperSW=KMem.CurJumperSW; |
|
316 |
|
|
317 |
// Uart2Baud = AlterUart2Baud; |
|
318 |
|
|
319 |
#if (BOARD_TYPE == 14) |
|
320 |
KMem.EffJumperSW|=0x10; |
|
321 |
nStationID=KMem.EffJumperSW&0x0f; |
|
322 |
if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
|
323 |
else{bKBusMaster=0;bKBusSlave=1;} |
|
324 |
nChilds=nStationID; |
|
325 |
FP0_Init(); |
|
326 |
|
|
327 |
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
842bb6
|
328 |
nKBusStationID=KMem.EffJumperSW&0x0f; |
483170
|
329 |
// if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
Q |
330 |
// else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
|
331 |
// else |
|
332 |
{bKBusMaster=0;bKBusSlave=1;} |
|
333 |
#else |
|
334 |
nStationID=KMem.EffJumperSW&0x0f; |
|
335 |
if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
|
336 |
else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
|
337 |
else{bKBusMaster=0;bKBusSlave=1;} |
|
338 |
#endif |
842bb6
|
339 |
nKBusChilds=nKBusStationID; |
Q |
340 |
|
|
341 |
if (bKBusMaster) { |
|
342 |
KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds); |
|
343 |
} else if (bKBusSlave) { |
|
344 |
KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationID,&MyDeviceInfo); |
|
345 |
} |
|
346 |
KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc); |
|
347 |
|
|
348 |
UNUSED(bKBusRepeater); |
|
349 |
// 注册KBus端口 |
|
350 |
/* |
|
351 |
stPortDef PortReg2 = {.nPortHardType = 4,.nPortUseType = 3}; |
|
352 |
KMRegisterPort(1,&PortReg2); |
|
353 |
*/ |
483170
|
354 |
//if (KMem.EffJumperSW == 0x00) |
842bb6
|
355 |
Uart1Baud = DefaultUart1Baud; |
483170
|
356 |
MX_USART1_UART_Init(); |
Q |
357 |
MX_USART2_UART_Init(); |
|
358 |
|
|
359 |
MX_SPI1_Init(); |
|
360 |
LL_SPI_EnableIT_RXNE(SPI1); |
|
361 |
|
|
362 |
#if (BOARD_TYPE == 14) |
|
363 |
// MX_SPI2_Init(); |
|
364 |
// MX_ADC_Init(); |
|
365 |
#else |
|
366 |
MX_SPI2_Init(); |
|
367 |
MX_ADC_Init(); |
|
368 |
#endif |
|
369 |
|
|
370 |
MX_IWDG_Init(); |
|
371 |
|
|
372 |
MX_TIM6_Init(); |
|
373 |
LL_TIM_EnableCounter(TIM6); |
|
374 |
|
|
375 |
/* USER CODE BEGIN 2 */ |
|
376 |
LL_USART_EnableIT_RXNE(USART1); |
|
377 |
LL_USART_EnableIT_IDLE(USART1); |
|
378 |
LL_USART_EnableIT_TC(USART1); |
|
379 |
|
|
380 |
// LL_USART_EnableIT_RXNE(USART2); |
7eb19e
|
381 |
Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1)); |
483170
|
382 |
LL_USART_EnableIT_IDLE(USART2); |
Q |
383 |
LL_USART_EnableIT_TC(USART2); |
842bb6
|
384 |
|
483170
|
385 |
#if (BOARD_TYPE == 13) |
Q |
386 |
int res; |
|
387 |
res = w5500_init(); |
|
388 |
KMem.SDD[28]=res; |
|
389 |
|
|
390 |
// res=socket(0,Sn_MR_TCP,5000,0); |
|
391 |
KMem.SDD[29]=res; |
|
392 |
|
|
393 |
// res = listen(0); |
|
394 |
#endif |
|
395 |
// if (bKBusSlave) |
|
396 |
{ |
|
397 |
// LL_USART_EnableAutoBaudRate(USART1); |
|
398 |
// LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
399 |
// LL_USART_EnableAutoBaudRate(USART2); |
|
400 |
// LL_USART_SetAutoBaudRateMode(USART2, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
401 |
} |
|
402 |
//LL_USART_EnableIT_TXE(USART1); |
|
403 |
/* USER CODE END 2 */ |
|
404 |
|
|
405 |
|
|
406 |
/* Infinite loop */ |
|
407 |
/* USER CODE BEGIN WHILE */ |
|
408 |
|
|
409 |
HAL_Delay(10); |
|
410 |
SetRunLed(1); //Turn On Run Led |
|
411 |
SetErrLed(0); //Turn Off Err Led |
|
412 |
|
|
413 |
#if (BOARD_TYPE == 14) |
|
414 |
// PutOutput (0); //Clear all Output |
|
415 |
// Enable595(1); //Enable 595 Output |
|
416 |
#else |
|
417 |
PutOutput (0); //Clear all Output |
|
418 |
Enable595(1); //Enable 595 Output |
|
419 |
#endif |
|
420 |
|
|
421 |
if (GetBoardType() == 7 || GetBoardType() ==8 |
|
422 |
|| GetBoardType() == 9 || GetBoardType() ==10 ||GetBoardType() ==13 ||GetBoardType() ==15 || BOARD_TYPE == 16) |
|
423 |
{ |
|
424 |
displayInput(0xffff); // |
|
425 |
EnableDisIn(1); //Input Diaplay Enable 595 |
|
426 |
} |
|
427 |
SetOutStat(0); //OK Good, signal |
|
428 |
ShowInitInfo(); |
|
429 |
KMem.LastScanTime = GetuS(); |
|
430 |
|
|
431 |
KMRunStat.WorkMode=0; |
|
432 |
KMRunStat.WorkMode2=0; |
|
433 |
|
|
434 |
KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode; |
842bb6
|
435 |
|
Q |
436 |
#if (ENABLE_PLC) |
483170
|
437 |
if (KMRunStat.WorkMode == 1){ |
Q |
438 |
InitPLC(); |
|
439 |
KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ; |
|
440 |
if (KMRunStat.WorkMode2) { |
|
441 |
StartPLC(); } |
|
442 |
} |
842bb6
|
443 |
#endif |
Q |
444 |
|
483170
|
445 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
842bb6
|
446 |
LoadKwConfig(); |
Q |
447 |
// KWireLessInit(&KWInitStruct); |
|
448 |
|
483170
|
449 |
KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
Q |
450 |
KWireLessStart(); |
|
451 |
#endif |
842bb6
|
452 |
|
Q |
453 |
|
|
454 |
stPortDef PortReg3 = {.nPortHardType = 7,.nPortUseType = 6}; |
|
455 |
KMRegisterPort(2,&PortReg3); |
483170
|
456 |
|
Q |
457 |
while (1) |
|
458 |
{ |
|
459 |
//int MyKeyStat1,MyKeyStat2; |
|
460 |
//MyKeyStat1=GetInput(); |
|
461 |
|
|
462 |
//*((unsigned int *)&(PLCMem.SDT[10]))=nRunCount; |
|
463 |
// KMem.nRunCount=nRunCount; |
|
464 |
SlowFlicker=0; |
|
465 |
FastFlicker=1; |
|
466 |
us1=GetuS(); |
|
467 |
int haltick=HAL_GetTick(); |
|
468 |
|
|
469 |
int thisJumperSW=ReadJumperSW(); |
|
470 |
|
842bb6
|
471 |
#if (ENABLE_PLC) |
483170
|
472 |
if (KMRunStat.WorkMode&1){ |
Q |
473 |
if (thisJumperSW&0x20 && !(KMem.CurJumperSW&0x20)) // Run 开关 正 跳变。 |
|
474 |
{StartPLC();} |
|
475 |
if (!(thisJumperSW&0x20) && (KMem.CurJumperSW&0x20)) // Run 开关 负 跳变。 |
|
476 |
{StopPLC();} |
|
477 |
} |
842bb6
|
478 |
#endif |
483170
|
479 |
KMem.CurJumperSW=thisJumperSW; |
Q |
480 |
KMem.haltick=haltick; |
|
481 |
// KMem.TotalRunTime=TotalRunTime; |
|
482 |
// KMem.ThisRunTime=ThisRunTime; |
|
483 |
|
|
484 |
// *((unsigned int *)&(PLCMem.SDT[2]))=nChilds; |
|
485 |
// KMem.SDD[13]=PendSvCount; |
|
486 |
// KMem.SDD[14]=RCC->CSR; |
842bb6
|
487 |
|
483170
|
488 |
|
Q |
489 |
int a; |
|
490 |
a = LL_GPIO_ReadInputPort(GPIOA); |
|
491 |
KMem.WDT[120]=a; |
|
492 |
a = LL_GPIO_ReadInputPort(GPIOB); |
|
493 |
KMem.WDT[121]=a; |
|
494 |
a = LL_GPIO_ReadInputPort(GPIOC); |
|
495 |
KMem.WDT[122]=a; |
|
496 |
a = LL_GPIO_ReadInputPort(GPIOD); |
|
497 |
KMem.WDT[123]=a; |
|
498 |
|
|
499 |
#if (BOARD_TYPE == 14) |
|
500 |
// KMem.WX[0]= GetInput(); |
|
501 |
FP0_Proc(); |
|
502 |
#else |
|
503 |
KMem.WX[0]= GetInput(); |
|
504 |
#endif |
|
505 |
|
|
506 |
if (GetBoardType() == 7 || GetBoardType() ==8 |
|
507 |
|| GetBoardType() == 9 || GetBoardType() ==10 || GetBoardType() ==15 || GetBoardType() ==16) |
|
508 |
{ |
|
509 |
displayInput(KMem.WX[0]); |
|
510 |
} |
|
511 |
us2=GetuS(); |
|
512 |
if (PowerDownEvent) { KMem.WX[0]=0;} |
|
513 |
///* |
|
514 |
if ((KMem.nRunCount &0x1f) == 0x02) |
|
515 |
{ |
|
516 |
ADCProcess(); |
|
517 |
if (PowerDownEvent) |
|
518 |
{ |
|
519 |
KMem.WX[0]=0; |
|
520 |
if (!OldPowerDownEvent) |
|
521 |
{ |
|
522 |
OldPowerDownEvent = PowerDownEvent; |
|
523 |
OldPowerDownEventTime = nCurTick; |
|
524 |
PowerDownProcess(); |
|
525 |
} |
|
526 |
}else |
|
527 |
{ |
|
528 |
if (OldPowerDownEvent) |
|
529 |
{ |
|
530 |
OldPowerDownEvent=PowerDownEvent; |
|
531 |
PowerRecoverProcess(); |
|
532 |
|
|
533 |
} |
|
534 |
} |
|
535 |
} |
|
536 |
//*/ |
|
537 |
|
|
538 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
|
539 |
Radio.IrqProcess( ); // Process Radio IRQ |
|
540 |
KWL_Process(1); |
|
541 |
|
|
542 |
#endif |
|
543 |
|
|
544 |
// pProgs = (stBinProg1 *) STORE_PRG_BASE; |
842bb6
|
545 |
#if (ENABLE_PLC) |
483170
|
546 |
if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
Q |
547 |
{ |
|
548 |
if (KMRunStat.nBinProgBank == 0){ |
|
549 |
pProgs=(stBinProg1 *)STORE_PRG_BASE; |
|
550 |
}else { |
|
551 |
pProgs=(stBinProg1 *)ALT_PRG_BASE; |
|
552 |
} |
|
553 |
nSizeProg1=KMRunStat.nBinProgSize; |
|
554 |
// pProgs=(stBinProg1 *)prog1; |
|
555 |
|
|
556 |
ProcessPLCBinProg(pProgs, nSizeProg1); |
|
557 |
} |
842bb6
|
558 |
#endif // ENABLE_PLC |
483170
|
559 |
KMem.ScanTimeuS=us2-KMem.LastScanTime; |
Q |
560 |
KMem.LastScanTime = us2; |
|
561 |
if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;} |
|
562 |
if (KMem.ScanTimeuS > KMem.MaxScanTimeuS) {KMem.MaxScanTimeuS = KMem.ScanTimeuS;} |
|
563 |
|
|
564 |
// if (bKBusRepeater) { KBusRepeaterFunc(); } |
|
565 |
|
|
566 |
us3=GetuS(); |
|
567 |
|
|
568 |
if (bKBusMaster) |
|
569 |
{ |
|
570 |
#if (BOARD_TYPE == 14) |
|
571 |
for (int i=0;i<nOutputBytes;i++) |
|
572 |
{BufferOut[i+1]=KMem.WYB[i];} |
|
573 |
#else |
|
574 |
// BufferOut[1]=KMem.WX[0]&0xff; |
|
575 |
// BufferOut[2]=(KMem.WX[0]>>8)&0xff; |
|
576 |
#endif |
|
577 |
} |
842bb6
|
578 |
KBusLoopProcess(&KBus1); |
Q |
579 |
|
483170
|
580 |
if (haltick&0x00002000) SlowFlicker=1; |
Q |
581 |
else SlowFlicker=0; |
|
582 |
if (haltick&0x00000800) FastFlicker=1; |
|
583 |
else FastFlicker=0; |
|
584 |
|
|
585 |
if (bKBusSlave) |
|
586 |
{ |
|
587 |
// BufferOut[0]=KMem.WX[0]; |
|
588 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
|
589 |
// KBusSlaveFunc(2); |
|
590 |
// if (! KMem.RunStat) {BufferIn[0]=0;} |
|
591 |
// KMem.WY[0]=BufferIn[0]; |
|
592 |
#else |
842bb6
|
593 |
KBusSlaveFunc(&KBus1); |
483170
|
594 |
if (! KMem.RunStat) {BufferIn[0]=0;} |
Q |
595 |
KMem.WY[0]=BufferIn[0]; |
|
596 |
#endif |
842bb6
|
597 |
if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1; |
483170
|
598 |
else SlowFlicker=0; |
842bb6
|
599 |
if (KBus1.nSlaveTick&0x00000800) FastFlicker=1; |
483170
|
600 |
else FastFlicker=0; |
Q |
601 |
} |
|
602 |
|
|
603 |
// KMem.WY[0]=nCount2>>5; |
842bb6
|
604 |
|
483170
|
605 |
|
Q |
606 |
if (KMRunStat.bLEDFlick) |
|
607 |
{ |
|
608 |
SetRunLed(FastFlicker); |
|
609 |
SetErrLed(FastFlicker); |
|
610 |
SetErr2Led(FastFlicker); |
|
611 |
SetOutStat(!FastFlicker); |
|
612 |
//KMRunStat.bLEDFlick-- ; |
|
613 |
} |
|
614 |
else |
|
615 |
{ |
842bb6
|
616 |
KMem.ErrStat = KwRunStat.ErrStat; |
Q |
617 |
if ((KMem.EffJumperSW&0x10)==0x10) KMem.ErrStat += KBus1.ErrStat; |
|
618 |
#if (ENABLE_PLC) |
483170
|
619 |
if (KMRunStat.WorkMode==1 ) { |
Q |
620 |
if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
|
621 |
else {SetRunLed(0);} |
|
622 |
} |
842bb6
|
623 |
else |
Q |
624 |
#endif // ENABLE_PLC |
|
625 |
{ |
483170
|
626 |
if (!KMem.RunStat) SetRunLed(SlowFlicker); |
Q |
627 |
else SetRunLed(FastFlicker); |
|
628 |
} |
842bb6
|
629 |
|
483170
|
630 |
if (!KMem.ErrStat) |
Q |
631 |
{ |
|
632 |
SetErrLed(0); |
|
633 |
SetErr2Led(0); |
|
634 |
SetOutStat(1); |
|
635 |
} |
|
636 |
else |
|
637 |
{ |
|
638 |
SetErrLed(FastFlicker); |
|
639 |
SetErr2Led(FastFlicker); |
|
640 |
SetOutStat(0); |
|
641 |
|
|
642 |
} |
|
643 |
} |
|
644 |
|
|
645 |
// SetRunLed(RunStat); |
|
646 |
// SetErrLed(ErrStat); |
|
647 |
|
|
648 |
us4=GetuS(); |
|
649 |
// EffJumperSW = GetInput(20)&0xff; |
|
650 |
|
842bb6
|
651 |
|
483170
|
652 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
Q |
653 |
|
|
654 |
if ((KMem.EffJumperSW&0x10)==0x10) { |
842bb6
|
655 |
KMem.WFY[1]=KBusMem.WLYB[1]; |
Q |
656 |
KBusMem.WLXB[1]=KMem.WFX[1]; |
483170
|
657 |
}else |
Q |
658 |
{ |
|
659 |
KMem.WFY[1]=KMem.WX[0]; |
|
660 |
KMem.WY[0]=KMem.WFX[1]; |
|
661 |
} |
|
662 |
// KMem.WY[0]=KMem.WLY[0]; |
|
663 |
#else |
|
664 |
KMem.WLX[0]=KMem.WX[0]; |
|
665 |
KMem.WY[0]=KMem.WLY[0]; |
|
666 |
#endif |
|
667 |
|
|
668 |
us5=GetuS(); |
|
669 |
|
|
670 |
#if (BOARD_TYPE == 14) |
|
671 |
// PutOutput (KMem.WY[0]); |
|
672 |
#else |
|
673 |
PutOutput (KMem.WY[0]); |
|
674 |
#endif |
|
675 |
//PutOutput (KMem.nRunCount>>8); |
|
676 |
//PutOutput(0x0f70); |
|
677 |
|
|
678 |
// if (bKBusMaster) ShowInfo(); |
|
679 |
// if (bKBusSlave) ShowInfo(); |
|
680 |
us6=GetuS(); |
|
681 |
add1(10,10); |
|
682 |
for (int i=0;i<64;i++) |
|
683 |
{ |
|
684 |
// ProcessTimer(i); |
|
685 |
} |
|
686 |
KMem.nRunCount++; |
|
687 |
// int nSize=sizeof(stKBusChnStat); |
|
688 |
// memcpy(&KMem.SDT[64],&KBusChnStats[1],nSize); |
|
689 |
// memcpy(&KMem.SDT[64+nSize/2],&KBusChnStats[2],nSize); |
|
690 |
// for (int i=0;i<128;i++) { SDT[i]=i; } |
|
691 |
// SDT[48]=55; |
7d8ba5
|
692 |
#if (USART1_AUTO_BAUDRATE == 1) |
842bb6
|
693 |
if (Uart1IdelTimer>300000) { // 超过60秒没有数据传输,重新进入自适应波特率状态 |
483170
|
694 |
LL_USART_EnableAutoBaudRate(USART1); |
Q |
695 |
LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
696 |
}else { |
|
697 |
Uart1IdelTimer++; |
|
698 |
} |
7d8ba5
|
699 |
#endif |
842bb6
|
700 |
// if (bKBusSlave) HAL_Delay(0); |
483170
|
701 |
/* |
Q |
702 |
if (!IsEmpty(&Uart1Stat.QRx)) |
|
703 |
{ |
|
704 |
unsigned char k=PopOne(&Uart1Stat.QRx); |
|
705 |
if (k=='L') |
|
706 |
{ |
|
707 |
clearscreen(); |
|
708 |
} |
|
709 |
} |
|
710 |
*/ |
|
711 |
|
|
712 |
#if (BOARD_TYPE == 14) |
|
713 |
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}; |
|
714 |
//process 6 output |
|
715 |
{ |
|
716 |
// mapping bits. |
|
717 |
for (int i=0;i<6;i++) |
|
718 |
{ |
|
719 |
USHORT bitaddr = storedKMSysCfg.theKMSysCfg.OutMappings[i]; |
|
720 |
UCHAR type = (bitaddr&0xf000) >>12; |
|
721 |
USHORT byteaddr = (bitaddr&0x0ff0) >>4; |
|
722 |
UCHAR bitpos = bitaddr &0x0f; |
|
723 |
UCHAR bitvalue = 0 ; |
|
724 |
if (byteaddr>0) { |
|
725 |
if (type == 0) bitvalue = KMem.WXB[byteaddr-1] & ( 1 << bitpos ); |
|
726 |
else if (type == 1 ) bitvalue = KMem.WYB[byteaddr-1] & ( 1 << bitpos ); |
|
727 |
} |
|
728 |
if (bitvalue){ LL_GPIO_SetOutputPin(GPIOB,pins[i]);} |
|
729 |
else {LL_GPIO_ResetOutputPin(GPIOB,pins[i]);} |
|
730 |
} |
|
731 |
} |
|
732 |
#endif |
|
733 |
|
|
734 |
/* |
|
735 |
{ |
|
736 |
unsigned char pos,seg; |
|
737 |
unsigned short val; |
|
738 |
pos=((KMem.nRunCount)&0x3); |
|
739 |
//val=(KMem.nRunCount)&0xfff; |
|
740 |
val=KMem.ErrStat; |
|
741 |
char buf5[20]; |
|
742 |
sprintf(buf5,"%4d",val); |
|
743 |
val=buf5[3-pos]; |
|
744 |
if (val <'0' || val >'9') {seg=0;} |
|
745 |
else {seg=LEDSEGTAB[val-'0'];} |
|
746 |
|
|
747 |
pos=1<<pos; |
|
748 |
//pos=1; |
|
749 |
//seg=2; |
|
750 |
seg=~seg; |
|
751 |
// PutOutputSPI1(pos|(seg<<8)); |
|
752 |
} |
|
753 |
*/ |
|
754 |
|
|
755 |
#if (BOARD_TYPE == 13) |
|
756 |
w5500_network_info_show(); |
|
757 |
// loopback_tcps(0,str1,5000); |
|
758 |
#endif |
|
759 |
|
|
760 |
LL_IWDG_ReloadCounter(IWDG); |
|
761 |
|
|
762 |
} //while (1) ; |
|
763 |
/* USER CODE END WHILE */ |
|
764 |
|
|
765 |
/* USER CODE BEGIN 3 */ |
|
766 |
|
|
767 |
/* USER CODE END 3 */ |
|
768 |
|
|
769 |
} |
|
770 |
|
|
771 |
|
|
772 |
/* USER CODE BEGIN 4 */ |
|
773 |
|
|
774 |
/* USER CODE END 4 */ |
|
775 |
|
|
776 |
/** |
|
777 |
* @brief This function is executed in case of error occurrence. |
|
778 |
* @param file: The file name as string. |
|
779 |
* @param line: The line in file as a number. |
|
780 |
* @retval None |
|
781 |
*/ |
|
782 |
void _Error_Handler(char *file, int line) |
|
783 |
{ |
|
784 |
/* USER CODE BEGIN Error_Handler_Debug */ |
|
785 |
/* User can add his own implementation to report the HAL error return state */ |
|
786 |
while(1) |
|
787 |
{ |
|
788 |
} |
|
789 |
/* USER CODE END Error_Handler_Debug */ |
|
790 |
} |
|
791 |
|
|
792 |
#ifdef USE_FULL_ASSERT |
|
793 |
/** |
|
794 |
* @brief Reports the name of the source file and the source line number |
|
795 |
* where the assert_param error has occurred. |
|
796 |
* @param file: pointer to the source file name |
|
797 |
* @param line: assert_param error line source number |
|
798 |
* @retval None |
|
799 |
*/ |
|
800 |
void assert_failed(uint8_t* file, uint32_t line) |
|
801 |
{ |
|
802 |
/* USER CODE BEGIN 6 */ |
|
803 |
/* User can add his own implementation to report the file name and line number, |
|
804 |
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
|
805 |
/* USER CODE END 6 */ |
|
806 |
} |
|
807 |
#endif /* USE_FULL_ASSERT */ |
|
808 |
|
|
809 |
/** |
|
810 |
* @} |
|
811 |
*/ |
|
812 |
|
|
813 |
/** |
|
814 |
* @} |
|
815 |
*/ |
|
816 |
|
|
817 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |