提交 | 用户 | age
|
bfc108
|
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"
|
d69aae
|
45 |
#include "debug.h"
|
bfc108
|
46 |
#include "Functions.h"
|
Q |
47 |
#include "KMachine.h"
|
|
48 |
#include "PLCfunctions.h"
|
|
49 |
//#include "KBus.h"
|
|
50 |
#include "KLink.h"
|
|
51 |
#include "string.h"
|
|
52 |
#include "BSP.h"
|
e1f350
|
53 |
#include "ModbusRTU.h"
|
85d591
|
54 |
#if (BOARD_TYPE == 13)
|
d69aae
|
55 |
#include "w5500_port.h"
|
Q |
56 |
#include "../src/Ethernet/socket.h"
|
|
57 |
#include "../src/Ethernet/loopback.h"
|
85d591
|
58 |
#elif (BOARD_TYPE == 14)
|
Q |
59 |
#include "FP0.h"
|
c57641
|
60 |
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
85d591
|
61 |
#include "KWireless.h"
|
Q |
62 |
//#include "user.h"
|
|
63 |
//#include "../src/radio/inc/sx126x-board.h"
|
d69aae
|
64 |
#endif
|
bfc108
|
65 |
|
Q |
66 |
/* USER CODE END Includes */
|
|
67 |
|
|
68 |
/* Private variables ---------------------------------------------------------*/
|
d69aae
|
69 |
|
bfc108
|
70 |
/* USER CODE BEGIN PV */
|
Q |
71 |
/* Private variables ---------------------------------------------------------*/
|
|
72 |
|
e1f350
|
73 |
#define RX2BUFSIZE 128
|
Q |
74 |
#define TX2BUFSIZE 128
|
bfc108
|
75 |
|
Q |
76 |
unsigned char Uart1RxBuf[256];
|
85d591
|
77 |
unsigned char Uart1TxBuf[280];
|
bfc108
|
78 |
|
e1f350
|
79 |
unsigned char Uart2RxBuf[RX2BUFSIZE];
|
Q |
80 |
unsigned char Uart2TxBuf[TX2BUFSIZE];
|
bfc108
|
81 |
|
85d591
|
82 |
unsigned char SlowFlicker=0;
|
Q |
83 |
unsigned char FastFlicker=0;
|
bfc108
|
84 |
|
e1f350
|
85 |
stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE;
|
bfc108
|
86 |
|
Q |
87 |
uint32_t us1,us2,us3,us4,us5,us6;
|
|
88 |
|
|
89 |
/* USER CODE END PV */
|
|
90 |
|
|
91 |
/* Private function prototypes -----------------------------------------------*/
|
|
92 |
|
|
93 |
|
|
94 |
/* USER CODE BEGIN PFP */
|
|
95 |
/* Private function prototypes -----------------------------------------------*/
|
e1f350
|
96 |
|
Q |
97 |
const unsigned char LEDSEGTAB[]={
|
|
98 |
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71, //0-F
|
|
99 |
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1, //0.-F.
|
|
100 |
0x00,0x40, // ,-,_,~,o,n,N,<,>,J,r,
|
|
101 |
};
|
bfc108
|
102 |
|
Q |
103 |
/* USER CODE END PFP */
|
|
104 |
|
|
105 |
/* USER CODE BEGIN 0 */
|
|
106 |
|
|
107 |
int HexToInt(char ch)
|
|
108 |
{
|
|
109 |
if (ch>='0' && ch <='9') return ch-'0';
|
|
110 |
if (ch>='A' && ch <='F') return ch-'A'+10;
|
|
111 |
if (ch>='a' && ch <='f') return ch-'a'+10;
|
|
112 |
return 0;
|
|
113 |
}
|
|
114 |
|
|
115 |
void HAL_SYSTICK_Callback(void)
|
|
116 |
{
|
|
117 |
static int Count=0;
|
|
118 |
CurTickuS += 100;
|
|
119 |
nCurTick++;
|
|
120 |
nSlaveTick++;
|
|
121 |
Count++;
|
|
122 |
if (Count>=10000)
|
|
123 |
{
|
|
124 |
Count=0;
|
|
125 |
KMem.CurTimeSec++;
|
|
126 |
KMem.ThisRunTime++; KMem.TotalRunTime++;
|
|
127 |
}
|
|
128 |
|
|
129 |
return;
|
|
130 |
}
|
|
131 |
|
|
132 |
/* USER CODE END 0 */
|
|
133 |
|
|
134 |
/**
|
|
135 |
* @brief The application entry point.
|
|
136 |
*
|
|
137 |
* @retval None
|
|
138 |
*/
|
|
139 |
int main(void)
|
|
140 |
{
|
|
141 |
/* USER CODE BEGIN 1 */
|
|
142 |
|
|
143 |
InitUartstat(&Uart1Stat,Uart1TxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf));
|
|
144 |
InitUartstat(&Uart2Stat,Uart2TxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf));
|
|
145 |
/* USER CODE END 1 */
|
|
146 |
|
|
147 |
/* MCU Configuration----------------------------------------------------------*/
|
|
148 |
|
|
149 |
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
150 |
HAL_Init();
|
|
151 |
|
|
152 |
/* USER CODE BEGIN Init */
|
|
153 |
|
d69aae
|
154 |
for (int i=0;i<9;i++)
|
bfc108
|
155 |
{
|
Q |
156 |
// memset(ChnStats[i],0,0);
|
|
157 |
ChnStats[i].SendPackets=0;
|
|
158 |
ChnStats[i].RecvPackets=0;
|
|
159 |
ChnStats[i].LostPackets=0;
|
|
160 |
ChnStats[i].CtnLstPkts=0;
|
|
161 |
ChnStats[i].MaxCtnLstPkts=0;
|
|
162 |
ChnStats[i].NotPkgErr=0;
|
|
163 |
ChnStats[i].PkgLenErr=0;
|
|
164 |
ChnStats[i].TimeOutErr=0;
|
|
165 |
ChnStats[i].BCCErr=0;
|
|
166 |
ChnStats[i].Delay=0;
|
|
167 |
ChnStats[i].MaxDelay=0;
|
|
168 |
}
|
|
169 |
|
|
170 |
KMem.LastScanTime=0;
|
|
171 |
KMem.ScanTimeuS=0;
|
|
172 |
KMem.MinScanTimeuS=99999;
|
|
173 |
KMem.MaxScanTimeuS=0;
|
|
174 |
|
|
175 |
// KMem.SDD[14]=(unsigned int)&KMStoreSysCfg;
|
|
176 |
// KMem.SDD[15]=(unsigned int)&KMStoreSysCfg1;
|
|
177 |
KMem.SDD[12]=((uint32_t *)UID_BASE)[0];
|
|
178 |
// KMem.SDD[13]=((uint32_t *)UID_BASE)[1];
|
|
179 |
// KMem.SDD[14]=((uint32_t *)UID_BASE)[2];
|
|
180 |
KMem.SDD[13]=PendSvCount;
|
|
181 |
KMem.SDD[14]=RCC->CSR;
|
|
182 |
// KMem.SDD[15]=*(uint32_t *)FLASHSIZE_BASE;
|
|
183 |
// KMem.SDD[16]=(unsigned int)&KMSysCfg;
|
|
184 |
|
|
185 |
/* USER CODE END Init */
|
|
186 |
|
|
187 |
/* Configure the system clock */
|
|
188 |
SystemClock_Config();
|
|
189 |
|
|
190 |
/* USER CODE BEGIN SysInit */
|
16eeda
|
191 |
TickFreq=10000; //Tick频率
|
bfc108
|
192 |
InituS(TickFreq);
|
16eeda
|
193 |
// HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq); //重新定义SysTick的频率�
|
bfc108
|
194 |
|
Q |
195 |
/* USER CODE END SysInit */
|
|
196 |
|
|
197 |
/* Initialize all configured peripherals */
|
|
198 |
MX_GPIO_Init();
|
|
199 |
MX_DMA_Init();
|
|
200 |
|
|
201 |
KMachineInit();
|
85d591
|
202 |
ReadSysCfgFromFlash(&storedKMSysCfg);
|
bfc108
|
203 |
|
Q |
204 |
KMem.EffJumperSW=ReadJumperSW();
|
85d591
|
205 |
#if (BOARD_TYPE == 14)
|
d69aae
|
206 |
KMem.EffJumperSW|=0x10;
|
Q |
207 |
nAddr=KMem.EffJumperSW&0x0f;
|
85d591
|
208 |
if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;}
|
Q |
209 |
else{bKBusMaster=0;bKBusSlave=1;}
|
d69aae
|
210 |
nChilds=nAddr;
|
Q |
211 |
FP0_Init();
|
c57641
|
212 |
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
85d591
|
213 |
nAddr=KMem.EffJumperSW&0x0f;
|
Q |
214 |
if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;}
|
|
215 |
else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;}
|
|
216 |
else{bKBusMaster=0;bKBusSlave=1;}
|
d69aae
|
217 |
#else
|
bfc108
|
218 |
nAddr=KMem.EffJumperSW&0x7;
|
85d591
|
219 |
if (KMem.EffJumperSW == 0x0f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;}
|
Q |
220 |
else if ((KMem.EffJumperSW&0x08)!=0) {bKBusMaster=1;bKBusSlave=0;}
|
|
221 |
else{bKBusMaster=0;bKBusSlave=1;}
|
d69aae
|
222 |
#endif
|
bfc108
|
223 |
nChilds=nAddr;
|
Q |
224 |
nCurPollId=1;
|
d69aae
|
225 |
//if (KMem.EffJumperSW == 0x00)
|
Q |
226 |
Uart1Baud = DefaultUart1Baud;
|
bfc108
|
227 |
MX_USART1_UART_Init();
|
Q |
228 |
MX_USART2_UART_Init();
|
d69aae
|
229 |
|
e1f350
|
230 |
MX_SPI1_Init();
|
d69aae
|
231 |
LL_SPI_EnableIT_RXNE(SPI1);
|
Q |
232 |
|
85d591
|
233 |
#if (BOARD_TYPE == 14)
|
d69aae
|
234 |
// MX_SPI2_Init();
|
Q |
235 |
// MX_ADC_Init();
|
|
236 |
#else
|
0aeaad
|
237 |
MX_SPI2_Init();
|
bfc108
|
238 |
MX_ADC_Init();
|
d69aae
|
239 |
#endif
|
Q |
240 |
|
bfc108
|
241 |
MX_IWDG_Init();
|
d69aae
|
242 |
|
Q |
243 |
MX_TIM6_Init();
|
|
244 |
LL_TIM_EnableCounter(TIM6);
|
bfc108
|
245 |
|
Q |
246 |
/* USER CODE BEGIN 2 */
|
|
247 |
LL_USART_EnableIT_RXNE(USART1);
|
|
248 |
LL_USART_EnableIT_IDLE(USART1);
|
|
249 |
LL_USART_EnableIT_TC(USART1);
|
|
250 |
|
e1f350
|
251 |
// LL_USART_EnableIT_RXNE(USART2);
|
Q |
252 |
Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1));
|
bfc108
|
253 |
LL_USART_EnableIT_IDLE(USART2);
|
Q |
254 |
LL_USART_EnableIT_TC(USART2);
|
d69aae
|
255 |
#if (BOARD_TYPE == 13)
|
Q |
256 |
int res;
|
|
257 |
res = w5500_init();
|
|
258 |
KMem.SDD[28]=res;
|
bfc108
|
259 |
|
d69aae
|
260 |
// res=socket(0,Sn_MR_TCP,5000,0);
|
Q |
261 |
KMem.SDD[29]=res;
|
|
262 |
|
|
263 |
// res = listen(0);
|
|
264 |
#endif
|
85d591
|
265 |
// if (bKBusSlave)
|
bfc108
|
266 |
{
|
Q |
267 |
// LL_USART_EnableAutoBaudRate(USART1);
|
|
268 |
// LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE);
|
|
269 |
// LL_USART_EnableAutoBaudRate(USART2);
|
|
270 |
// LL_USART_SetAutoBaudRateMode(USART2, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE);
|
|
271 |
}
|
|
272 |
//LL_USART_EnableIT_TXE(USART1);
|
|
273 |
/* USER CODE END 2 */
|
|
274 |
|
|
275 |
|
|
276 |
/* Infinite loop */
|
|
277 |
/* USER CODE BEGIN WHILE */
|
|
278 |
|
|
279 |
HAL_Delay(10);
|
|
280 |
SetRunLed(1); //Turn On Run Led
|
|
281 |
SetErrLed(0); //Turn Off Err Led
|
d69aae
|
282 |
|
85d591
|
283 |
#if (BOARD_TYPE == 14)
|
d69aae
|
284 |
// PutOutput (0); //Clear all Output
|
Q |
285 |
// Enable595(1); //Enable 595 Output
|
|
286 |
#else
|
bfc108
|
287 |
PutOutput (0); //Clear all Output
|
Q |
288 |
Enable595(1); //Enable 595 Output
|
d69aae
|
289 |
#endif
|
Q |
290 |
|
0aeaad
|
291 |
if (GetBoardType() == 7 || GetBoardType() ==8
|
c57641
|
292 |
|| GetBoardType() == 9 || GetBoardType() ==10 ||GetBoardType() ==13 ||GetBoardType() ==15 || BOARD_TYPE == 16)
|
0aeaad
|
293 |
{
|
Q |
294 |
displayInput(0xffff); //
|
|
295 |
EnableDisIn(1); //Input Diaplay Enable 595
|
|
296 |
}
|
bfc108
|
297 |
SetOutStat(0); //OK Good, signal
|
e1f350
|
298 |
ShowInitInfo();
|
bfc108
|
299 |
KMem.LastScanTime = GetuS();
|
d69aae
|
300 |
|
Q |
301 |
KMRunStat.WorkMode=0;
|
|
302 |
if (KMRunStat.WorkMode == 1){
|
|
303 |
InitPLC();
|
|
304 |
StartPLC();
|
e1f350
|
305 |
}
|
d69aae
|
306 |
KMem.WX[7]=0x5a;
|
c57641
|
307 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
16eeda
|
308 |
KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x1f);
|
85d591
|
309 |
KWireLessStart();
|
Q |
310 |
#endif
|
d69aae
|
311 |
|
bfc108
|
312 |
while (1)
|
Q |
313 |
{
|
|
314 |
//int MyKeyStat1,MyKeyStat2;
|
|
315 |
//MyKeyStat1=GetInput();
|
7a54c0
|
316 |
|
bfc108
|
317 |
//*((unsigned int *)&(PLCMem.SDT[10]))=nRunCount;
|
Q |
318 |
// KMem.nRunCount=nRunCount;
|
|
319 |
SlowFlicker=0;
|
|
320 |
FastFlicker=1;
|
|
321 |
us1=GetuS();
|
|
322 |
int haltick=HAL_GetTick();
|
|
323 |
|
e1f350
|
324 |
// int CurJumperSW=ReadJumperSW();
|
Q |
325 |
// KMem.CurJumperSW=CurJumperSW;
|
bfc108
|
326 |
KMem.haltick=haltick;
|
Q |
327 |
// KMem.TotalRunTime=TotalRunTime;
|
|
328 |
// KMem.ThisRunTime=ThisRunTime;
|
|
329 |
|
|
330 |
// *((unsigned int *)&(PLCMem.SDT[2]))=nChilds;
|
e1f350
|
331 |
// KMem.SDD[13]=PendSvCount;
|
Q |
332 |
// KMem.SDD[14]=RCC->CSR;
|
|
333 |
|
85d591
|
334 |
#if (BOARD_TYPE == 14)
|
d69aae
|
335 |
// KMem.WX[0]= GetInput();
|
85d591
|
336 |
FP0_Proc();
|
d69aae
|
337 |
#else
|
e1f350
|
338 |
KMem.WX[0]= GetInput();
|
d69aae
|
339 |
#endif
|
bfc108
|
340 |
|
Q |
341 |
if (GetBoardType() == 7 || GetBoardType() ==8
|
c57641
|
342 |
|| GetBoardType() == 9 || GetBoardType() ==10 || GetBoardType() ==15 || GetBoardType() ==16)
|
bfc108
|
343 |
{
|
Q |
344 |
displayInput(KMem.WX[0]);
|
|
345 |
}
|
|
346 |
us2=GetuS();
|
85d591
|
347 |
///*
|
bfc108
|
348 |
if ((KMem.nRunCount &0x1f) == 0x02)
|
Q |
349 |
{
|
|
350 |
ADCProcess();
|
|
351 |
if (PowerDownEvent)
|
|
352 |
{
|
|
353 |
if (!OldPowerDownEvent)
|
|
354 |
{
|
|
355 |
OldPowerDownEvent = PowerDownEvent;
|
|
356 |
OldPowerDownEventTime = nCurTick;
|
|
357 |
PowerDownProcess();
|
|
358 |
}
|
|
359 |
}else
|
|
360 |
{
|
|
361 |
if (OldPowerDownEvent)
|
|
362 |
{
|
|
363 |
OldPowerDownEvent=PowerDownEvent;
|
|
364 |
PowerRecoverProcess();
|
|
365 |
|
|
366 |
}
|
|
367 |
}
|
|
368 |
}
|
85d591
|
369 |
//*/
|
d69aae
|
370 |
|
c57641
|
371 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
85d591
|
372 |
Radio.IrqProcess( ); // Process Radio IRQ
|
Q |
373 |
#endif
|
|
374 |
|
|
375 |
// pProgs = (stBinProg1 *) STORE_PRG_BASE;
|
|
376 |
|
|
377 |
if ( KMRunStat.WorkMode==1 && bKBusMaster)
|
bfc108
|
378 |
{
|
85d591
|
379 |
if (KMRunStat.nBinProgBank == 0){
|
Q |
380 |
pProgs=(stBinProg1 *)STORE_PRG_BASE;
|
|
381 |
}else {
|
|
382 |
pProgs=(stBinProg1 *)ALT_PRG_BASE;
|
|
383 |
}
|
|
384 |
nSizeProg1=KMRunStat.nBinProgSize;
|
|
385 |
|
|
386 |
ProcessPLCBinProg(pProgs, nSizeProg1);
|
|
387 |
}
|
|
388 |
|
|
389 |
KMem.ScanTimeuS=us2-KMem.LastScanTime;
|
|
390 |
KMem.LastScanTime = us2;
|
|
391 |
if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;}
|
|
392 |
if (KMem.ScanTimeuS > KMem.MaxScanTimeuS) {KMem.MaxScanTimeuS = KMem.ScanTimeuS;}
|
|
393 |
|
|
394 |
// if (bKBusRepeater) { KBusRepeaterFunc(); }
|
|
395 |
|
|
396 |
us3=GetuS();
|
|
397 |
|
|
398 |
if (bKBusMaster)
|
|
399 |
{
|
|
400 |
#if (BOARD_TYPE == 14)
|
d69aae
|
401 |
for (int i=0;i<nOutputBytes;i++)
|
Q |
402 |
{BufferOut[i+1]=KMem.WYB[i];}
|
|
403 |
#else
|
e1f350
|
404 |
// BufferOut[1]=KMem.WX[0]&0xff;
|
Q |
405 |
// BufferOut[2]=(KMem.WX[0]>>8)&0xff;
|
d69aae
|
406 |
#endif
|
85d591
|
407 |
if (nChilds>0) { KBusMasterFunc(2); }
|
bfc108
|
408 |
|
85d591
|
409 |
#if (BOARD_TYPE == 14)
|
d69aae
|
410 |
// KMem.WX[0]=BufferIn[1]+(BufferIn[2]<<8);
|
Q |
411 |
#else
|
|
412 |
// KMem.WY[0]=BufferIn[1]+(BufferIn[2]<<8);
|
|
413 |
#endif
|
|
414 |
|
|
415 |
}
|
bfc108
|
416 |
if (haltick&0x00002000) SlowFlicker=1;
|
Q |
417 |
else SlowFlicker=0;
|
|
418 |
if (haltick&0x00000800) FastFlicker=1;
|
|
419 |
else FastFlicker=0;
|
d69aae
|
420 |
|
85d591
|
421 |
if (bKBusSlave)
|
bfc108
|
422 |
{
|
e1f350
|
423 |
// BufferOut[0]=KMem.WX[0];
|
c57641
|
424 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
85d591
|
425 |
// KBusSlaveFunc(2);
|
Q |
426 |
// if (! KMem.RunStat) {BufferIn[0]=0;}
|
|
427 |
// KMem.WY[0]=BufferIn[0];
|
|
428 |
#else
|
|
429 |
KBusSlaveFunc(2);
|
bfc108
|
430 |
if (! KMem.RunStat) {BufferIn[0]=0;}
|
Q |
431 |
KMem.WY[0]=BufferIn[0];
|
85d591
|
432 |
#endif
|
bfc108
|
433 |
if (nSlaveTick&0x00002000) SlowFlicker=1;
|
Q |
434 |
else SlowFlicker=0;
|
|
435 |
if (nSlaveTick&0x00000800) FastFlicker=1;
|
|
436 |
else FastFlicker=0;
|
|
437 |
|
|
438 |
}
|
d69aae
|
439 |
|
bfc108
|
440 |
// KMem.WY[0]=nCount2>>5;
|
Q |
441 |
if (KMem.RunStat) {KMem.RunStat--;}
|
|
442 |
if (KMem.ErrStat) {KMem.ErrStat--;}
|
d69aae
|
443 |
|
bfc108
|
444 |
if (!KMem.RunStat) SetRunLed(SlowFlicker);
|
Q |
445 |
else SetRunLed(FastFlicker);
|
|
446 |
|
|
447 |
if (!KMem.ErrStat)
|
|
448 |
{
|
|
449 |
SetErrLed(0);
|
|
450 |
SetOutStat(1);
|
|
451 |
}
|
|
452 |
else
|
|
453 |
{
|
|
454 |
SetErrLed(FastFlicker);
|
|
455 |
SetOutStat(0);
|
|
456 |
|
|
457 |
}
|
|
458 |
|
|
459 |
// SetRunLed(RunStat);
|
|
460 |
// SetErrLed(ErrStat);
|
|
461 |
|
|
462 |
us4=GetuS();
|
|
463 |
// EffJumperSW = GetInput(20)&0xff;
|
|
464 |
|
85d591
|
465 |
#if (BOARD_TYPE == 14)
|
d69aae
|
466 |
// PutOutput (KMem.WY[0]);
|
85d591
|
467 |
#else
|
bfc108
|
468 |
PutOutput (KMem.WY[0]);
|
d69aae
|
469 |
#endif
|
0aeaad
|
470 |
//PutOutput (KMem.nRunCount>>8);
|
bfc108
|
471 |
//PutOutput(0x0f70);
|
c57641
|
472 |
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
85d591
|
473 |
// KMem.WY[1]=KMem.nRunCount>>6;
|
Q |
474 |
KMem.WY[1]=KMem.WX[0];
|
|
475 |
KMem.WY[0]=KMem.WX[1];
|
|
476 |
#endif
|
bfc108
|
477 |
us5=GetuS();
|
85d591
|
478 |
// if (bKBusMaster) ShowInfo();
|
Q |
479 |
// if (bKBusSlave) ShowInfo();
|
bfc108
|
480 |
us6=GetuS();
|
Q |
481 |
add1(10,10);
|
|
482 |
for (int i=0;i<64;i++)
|
|
483 |
{
|
|
484 |
// ProcessTimer(i);
|
|
485 |
}
|
|
486 |
KMem.nRunCount++;
|
d69aae
|
487 |
// int nSize=sizeof(stChnStat);
|
Q |
488 |
// memcpy(&KMem.SDT[64],&ChnStats[1],nSize);
|
|
489 |
// memcpy(&KMem.SDT[64+nSize/2],&ChnStats[2],nSize);
|
bfc108
|
490 |
// for (int i=0;i<128;i++) { SDT[i]=i; }
|
Q |
491 |
// SDT[48]=55;
|
|
492 |
if (Uart1RecvBuf1DataLen >0 && Uart1Stat.bPacketRecved)
|
|
493 |
{
|
e1f350
|
494 |
int res1 = -1;
|
d69aae
|
495 |
res1 = ModBusSlaveParsePkg(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen);
|
e1f350
|
496 |
if (res1 !=0)
|
Q |
497 |
{
|
d69aae
|
498 |
KLParsePacket(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen);
|
e1f350
|
499 |
}
|
bfc108
|
500 |
Uart1RecvBuf1DataLen=0;
|
Q |
501 |
Uart1Stat.bPacketRecved=0;
|
|
502 |
}
|
85d591
|
503 |
if (bKBusSlave) HAL_Delay(0);
|
bfc108
|
504 |
/*
|
Q |
505 |
if (!IsEmpty(&Uart1Stat.QRx))
|
|
506 |
{
|
|
507 |
unsigned char k=PopOne(&Uart1Stat.QRx);
|
|
508 |
if (k=='L')
|
|
509 |
{
|
|
510 |
clearscreen();
|
|
511 |
}
|
|
512 |
}
|
d69aae
|
513 |
*/
|
Q |
514 |
|
85d591
|
515 |
#if (BOARD_TYPE == 14)
|
d69aae
|
516 |
//process 6 output
|
Q |
517 |
{
|
|
518 |
// mapping bits.
|
|
519 |
if (KMem.WXB[0]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_12);}
|
|
520 |
else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_12);}
|
|
521 |
if (KMem.WXB[1]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_13);}
|
|
522 |
else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_13);}
|
|
523 |
if (KMem.WXB[2]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_14);}
|
|
524 |
else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_14);}
|
|
525 |
if (KMem.WXB[3]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_15);}
|
|
526 |
else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_15);}
|
|
527 |
if (KMem.WXB[4]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_0);}
|
|
528 |
else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_0);}
|
|
529 |
if (KMem.WXB[5]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_1);}
|
|
530 |
else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_1);}
|
|
531 |
if (KMem.WXB[5]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_2);}
|
|
532 |
else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_2);}
|
|
533 |
}
|
|
534 |
#endif
|
|
535 |
|
85d591
|
536 |
/*
|
d69aae
|
537 |
{
|
e1f350
|
538 |
unsigned char pos,seg;
|
Q |
539 |
unsigned short val;
|
|
540 |
pos=((KMem.nRunCount)&0x3);
|
|
541 |
//val=(KMem.nRunCount)&0xfff;
|
|
542 |
val=KMem.ErrStat;
|
|
543 |
char buf5[20];
|
|
544 |
sprintf(buf5,"%4d",val);
|
|
545 |
val=buf5[3-pos];
|
|
546 |
if (val <'0' || val >'9') {seg=0;}
|
|
547 |
else {seg=LEDSEGTAB[val-'0'];}
|
|
548 |
|
|
549 |
pos=1<<pos;
|
|
550 |
//pos=1;
|
|
551 |
//seg=2;
|
|
552 |
seg=~seg;
|
d69aae
|
553 |
// PutOutputSPI1(pos|(seg<<8));
|
Q |
554 |
}
|
85d591
|
555 |
*/
|
Q |
556 |
|
d69aae
|
557 |
#if (BOARD_TYPE == 13)
|
Q |
558 |
w5500_network_info_show();
|
|
559 |
// loopback_tcps(0,str1,5000);
|
|
560 |
#endif
|
|
561 |
|
bfc108
|
562 |
LL_IWDG_ReloadCounter(IWDG);
|
Q |
563 |
|
|
564 |
} //while (1) ;
|
|
565 |
/* USER CODE END WHILE */
|
|
566 |
|
|
567 |
/* USER CODE BEGIN 3 */
|
|
568 |
|
|
569 |
/* USER CODE END 3 */
|
|
570 |
|
|
571 |
}
|
|
572 |
|
|
573 |
|
|
574 |
/* USER CODE BEGIN 4 */
|
|
575 |
|
|
576 |
/* USER CODE END 4 */
|
|
577 |
|
|
578 |
/**
|
|
579 |
* @brief This function is executed in case of error occurrence.
|
|
580 |
* @param file: The file name as string.
|
|
581 |
* @param line: The line in file as a number.
|
|
582 |
* @retval None
|
|
583 |
*/
|
|
584 |
void _Error_Handler(char *file, int line)
|
|
585 |
{
|
|
586 |
/* USER CODE BEGIN Error_Handler_Debug */
|
|
587 |
/* User can add his own implementation to report the HAL error return state */
|
|
588 |
while(1)
|
|
589 |
{
|
|
590 |
}
|
|
591 |
/* USER CODE END Error_Handler_Debug */
|
|
592 |
}
|
|
593 |
|
|
594 |
#ifdef USE_FULL_ASSERT
|
|
595 |
/**
|
|
596 |
* @brief Reports the name of the source file and the source line number
|
|
597 |
* where the assert_param error has occurred.
|
|
598 |
* @param file: pointer to the source file name
|
|
599 |
* @param line: assert_param error line source number
|
|
600 |
* @retval None
|
|
601 |
*/
|
|
602 |
void assert_failed(uint8_t* file, uint32_t line)
|
|
603 |
{
|
|
604 |
/* USER CODE BEGIN 6 */
|
|
605 |
/* User can add his own implementation to report the file name and line number,
|
|
606 |
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
607 |
/* USER CODE END 6 */
|
|
608 |
}
|
|
609 |
#endif /* USE_FULL_ASSERT */
|
|
610 |
|
|
611 |
/**
|
|
612 |
* @}
|
|
613 |
*/
|
|
614 |
|
|
615 |
/**
|
|
616 |
* @}
|
|
617 |
*/
|
|
618 |
|
|
619 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|