|
/**
|
******************************************************************************
|
* @file : main.c
|
* @brief : Main program body
|
******************************************************************************
|
** This notice applies to any and all portions of this file
|
* that are not between comment pairs USER CODE BEGIN and
|
* USER CODE END. Other portions of this file, whether
|
* inserted by the user or by software development tools
|
* are owned by their respective copyright owners.
|
*
|
* COPYRIGHT(c) 2018 STMicroelectronics
|
*
|
* Redistribution and use in source and binary forms, with or without modification,
|
* are permitted provided that the following conditions are met:
|
* 1. Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
* this list of conditions and the following disclaimer in the documentation
|
* and/or other materials provided with the distribution.
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
* may be used to endorse or promote products derived from this software
|
* without specific prior written permission.
|
*
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
*
|
******************************************************************************
|
*/
|
/* Includes ------------------------------------------------------------------*/
|
#include "main.h"
|
#include "stm32f0xx_hal.h"
|
|
/* USER CODE BEGIN Includes */
|
#include "Globaldef.h"
|
#include "debug.h"
|
#include "Functions.h"
|
#include "KMachine.h"
|
#include "PLCfunctions.h"
|
//#include "KBus.h"
|
#include "KLink.h"
|
#include "string.h"
|
#include "BSP.h"
|
#include "ModbusRTU.h"
|
#if (BOARD_TYPE == 13)
|
#include "w5500_port.h"
|
#include "../src/Ethernet/socket.h"
|
#include "../src/Ethernet/loopback.h"
|
#elif (BOARD_TYPE == 14)
|
#include "FP0.h"
|
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
#include "KWireless2.h"
|
//#include "user.h"
|
//#include "../src/radio/inc/sx126x-board.h"
|
#endif
|
|
/* USER CODE END Includes */
|
|
/* Private variables ---------------------------------------------------------*/
|
|
/* USER CODE BEGIN PV */
|
/* Private variables ---------------------------------------------------------*/
|
|
|
|
unsigned char Uart1RxBuf1[Uart1RxBufSize];
|
unsigned char Uart1TxBuf1[260];
|
|
unsigned char Uart2RxBuf1[RX2BUFSIZE];
|
unsigned char Uart2TxBuf1[TX2BUFSIZE];
|
|
unsigned short Uart1RxBuf1DataLen = 0;
|
unsigned short Uart2RxBuf1DataLen = 0;
|
|
unsigned char SlowFlicker=0;
|
unsigned char FastFlicker=0;
|
|
unsigned int Uart1IdelTimer = 0;
|
unsigned char Uart1Mode = 1; //Uart1工作模式, 0 : 普通, 1 : 透传模式
|
|
unsigned int Uart1Baud = DefaultUart1Baud;
|
unsigned int Uart2Baud = DefaultUart2Baud;
|
|
//unsigned char Uart1RecvBuf1[Uart1RecvBufSize];
|
//unsigned short Uart1RecvBuf1DataLen=0;
|
|
//unsigned char Uart2RecvBuf1[128];
|
//unsigned short Uart2RecvBuf1DataLen=0;
|
|
volatile char Uart1BaudGot=0;
|
volatile char Uart1BaudFirstGot=0;
|
volatile char Uart1DmaInts=0;
|
|
|
#if (ENABLE_PLC)
|
stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE;
|
#endif
|
uint32_t us1,us2,us3,us4,us5,us6;
|
|
stKBusDef KBus1; //
|
|
extern stDeviceInfo MyDeviceInfo;
|
|
/* USER CODE END PV */
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
/* USER CODE BEGIN PFP */
|
/* Private function prototypes -----------------------------------------------*/
|
|
const unsigned char LEDSEGTAB[]={
|
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71, //0-F
|
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1, //0.-F.
|
0x00,0x40, // ,-,_,~,o,n,N,<,>,J,r,
|
};
|
|
/* USER CODE END PFP */
|
|
/* USER CODE BEGIN 0 */
|
|
int HexToInt(char ch)
|
{
|
if (ch>='0' && ch <='9') return ch-'0';
|
if (ch>='A' && ch <='F') return ch-'A'+10;
|
if (ch>='a' && ch <='f') return ch-'a'+10;
|
return 0;
|
}
|
|
void HAL_SYSTICK_Callback(void)
|
{
|
static int Count=0;
|
CurTickuS += 100;
|
nCurTick++;
|
KBus1.nSlaveTick++;
|
Count++;
|
if (Count>=10000)
|
{
|
Count=0;
|
KMem.CurTimeSec++;
|
KMem.ThisRunTime++; KMem.TotalRunTime++;
|
if (KMRunStat.bLEDFlick) KMRunStat.bLEDFlick--;
|
if (KMRunStat.bLEDFlick >120) KMRunStat.bLEDFlick=120;
|
}
|
|
return;
|
}
|
|
|
void PendSvCallBack()
|
{
|
#if (BOARD_TYPE == 14)
|
///*
|
if (bSPI1RecvDone)
|
{
|
bSPI1RecvDone=0;
|
FPxParsePkt(SPI1RecvBuf,nSPI1RecvLenInBuf);
|
}
|
//*/
|
#endif
|
if (Uart2Stat.bPacketRecved)
|
{
|
KBusParsePacket(&KBus1, (pKBPacket)Uart2RxBuf1, Uart2RxBuf1DataLen);
|
Uart2RxBuf1DataLen=0;
|
Uart2Stat.bPacketRecved=0;
|
Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1));
|
KMem.WDT[2]++;
|
}
|
if (Uart1RxBuf1DataLen >0 && Uart1Stat.bPacketRecved)
|
{
|
int res1 = -1;
|
if (Uart1RxBuf1DataLen == 3 && Uart1RxBuf1[0]=='+' && Uart1RxBuf1[0]=='+' && Uart1RxBuf1[0]=='+')
|
{
|
Uart1Mode = 0; // 切换到命令模式
|
}else if (Uart1RxBuf1DataLen == 3 && Uart1RxBuf1[0]=='-' && Uart1RxBuf1[0]=='-' && Uart1RxBuf1[0]=='-')
|
{
|
Uart1Mode = 1; // 切换到透传模式
|
}else if (Uart1Mode == 0) {
|
|
res1 = ModBusSlaveParsePkg(1, Uart1RxBuf1, Uart1RxBuf1DataLen);
|
if (res1 !=0)
|
{
|
KLParsePacket(1, Uart1RxBuf1, Uart1RxBuf1DataLen);
|
}
|
|
}else if (Uart1Mode == 1) {
|
// 透传模式
|
if (KwRunStat.sizetosend == 0) {
|
memcpy( KwRunStat.ttTxBuf1,Uart1RxBuf1, Uart1RxBuf1DataLen);
|
KwRunStat.sentsize = 0;
|
KwRunStat.sizesending = 0;
|
KwRunStat.sizetosend = Uart1RxBuf1DataLen;
|
}else {
|
return;
|
}
|
|
//SendPacket(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen);
|
}
|
Uart1RxBuf1DataLen=0;
|
Uart1Stat.bPacketRecved=0;
|
Uart1IdelTimer = 0;
|
}
|
}
|
|
/*
|
KBus通讯回调函数,当通讯状态改变或数据更新时被调用。
|
或者系统请求时。
|
*/
|
void * KBusEvCallBackFunc(void* pParam, int nEvent, void *pBuf, int nLen1)
|
{
|
switch (nEvent){
|
|
case KBusEvNone:
|
break;
|
case KBusEvCreate:
|
break;
|
case KBusEvConnected:
|
break;
|
case KBusEvDisConnected:
|
break;
|
case KBusEvClosed:
|
break;
|
case KBusEvStateChange:
|
break;
|
case KBusEvTimeSync:
|
break;
|
case KBusEvDataUpdate:
|
KMem.WLX[0] = KBusMem.WLX[0];
|
KMem.WLY[0] = KBusMem.WLY[0];
|
|
if (KBus1.bMaster) {
|
KMem.WY[0]=KBusMem.WLX[0]; //KPLC with KBus Master
|
KBusMem.WLY[0]=KMem.WX[0];
|
} else if (KBus1.bSlave) {
|
KMem.WYB[0]=KBusMem.WLYB[0]; //WireLess with KBus Slave
|
KBusMem.WLXB[0]=KMem.WXB[0];
|
|
}
|
break;
|
case KBusEvCmdResponse:
|
break;
|
|
default:
|
break;
|
}
|
return 0;
|
}
|
|
|
/* USER CODE END 0 */
|
|
/**
|
* @brief The application entry point.
|
*
|
* @retval None
|
*/
|
int main(void)
|
{
|
/* USER CODE BEGIN 1 */
|
KMRunStat.bLEDFlick = 1;
|
|
InitUartstat(&Uart1Stat,Uart1RxBuf1,sizeof(Uart1RxBuf1),Uart1TxBuf1,sizeof(Uart1TxBuf1));
|
// InitUartstat(&Uart2Stat,Uart2RxBuf1,sizeof(Uart2RxBuf1),Uart2TxBuf1,sizeof(Uart2TxBuf1));
|
/* USER CODE END 1 */
|
|
/* MCU Configuration----------------------------------------------------------*/
|
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
HAL_Init();
|
|
/* USER CODE BEGIN Init */
|
|
|
/* USER CODE END Init */
|
|
/* Configure the system clock */
|
SystemClock_Config();
|
|
/* USER CODE BEGIN SysInit */
|
TickFreq=10000; //Tick频率
|
InituS(TickFreq);
|
// HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq); //重新定义SysTick的频率
|
|
/* USER CODE END SysInit */
|
|
/* Initialize all configured peripherals */
|
MX_GPIO_Init();
|
MX_DMA_Init();
|
|
KMachineInit();
|
ReadSysCfgFromFlash(&storedKMSysCfg);
|
|
KMRunStat.bLEDFlick = 1;
|
|
KLinkInit(1); //注册KLink端口
|
|
// stPortDef PortReg1 = {.nPortHardType = 3,.nPortUseType = 2};
|
// KMRegisterPort(0,&PortReg1);
|
|
|
unsigned char bKBusMaster, bKBusSlave, bKBusRepeater;
|
int nKBusStationID;
|
int nKBusChilds;
|
|
KMem.CurJumperSW=ReadJumperSW();
|
KMem.EffJumperSW=KMem.CurJumperSW;
|
|
// Uart2Baud = AlterUart2Baud;
|
|
#if (BOARD_TYPE == 14)
|
KMem.EffJumperSW|=0x10;
|
nStationID=KMem.EffJumperSW&0x0f;
|
if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;}
|
else{bKBusMaster=0;bKBusSlave=1;}
|
nChilds=nStationID;
|
FP0_Init();
|
|
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
nKBusStationID=KMem.EffJumperSW&0x0f;
|
// if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;}
|
// else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;}
|
// else
|
{bKBusMaster=0;bKBusSlave=1;}
|
#else
|
nStationID=KMem.EffJumperSW&0x0f;
|
if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;}
|
else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;}
|
else{bKBusMaster=0;bKBusSlave=1;}
|
#endif
|
nKBusChilds=nKBusStationID;
|
|
if (bKBusMaster) {
|
KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds);
|
} else if (bKBusSlave) {
|
KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationID,&MyDeviceInfo);
|
}
|
KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc);
|
|
UNUSED(bKBusRepeater);
|
// 注册KBus端口
|
/*
|
stPortDef PortReg2 = {.nPortHardType = 4,.nPortUseType = 3};
|
KMRegisterPort(1,&PortReg2);
|
*/
|
//if (KMem.EffJumperSW == 0x00)
|
Uart1Baud = DefaultUart1Baud;
|
MX_USART1_UART_Init();
|
MX_USART2_UART_Init();
|
|
MX_SPI1_Init();
|
LL_SPI_EnableIT_RXNE(SPI1);
|
|
#if (BOARD_TYPE == 14)
|
// MX_SPI2_Init();
|
// MX_ADC_Init();
|
#else
|
MX_SPI2_Init();
|
MX_ADC_Init();
|
#endif
|
|
MX_IWDG_Init();
|
|
MX_TIM6_Init();
|
LL_TIM_EnableCounter(TIM6);
|
|
/* USER CODE BEGIN 2 */
|
LL_USART_EnableIT_RXNE(USART1);
|
LL_USART_EnableIT_IDLE(USART1);
|
LL_USART_EnableIT_TC(USART1);
|
|
// LL_USART_EnableIT_RXNE(USART2);
|
Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1));
|
LL_USART_EnableIT_IDLE(USART2);
|
LL_USART_EnableIT_TC(USART2);
|
|
#if (BOARD_TYPE == 13)
|
int res;
|
res = w5500_init();
|
KMem.SDD[28]=res;
|
|
// res=socket(0,Sn_MR_TCP,5000,0);
|
KMem.SDD[29]=res;
|
|
// res = listen(0);
|
#endif
|
// if (bKBusSlave)
|
{
|
// LL_USART_EnableAutoBaudRate(USART1);
|
// LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE);
|
// LL_USART_EnableAutoBaudRate(USART2);
|
// LL_USART_SetAutoBaudRateMode(USART2, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE);
|
}
|
//LL_USART_EnableIT_TXE(USART1);
|
/* USER CODE END 2 */
|
|
|
/* Infinite loop */
|
/* USER CODE BEGIN WHILE */
|
|
HAL_Delay(10);
|
SetRunLed(1); //Turn On Run Led
|
SetErrLed(0); //Turn Off Err Led
|
|
#if (BOARD_TYPE == 14)
|
// PutOutput (0); //Clear all Output
|
// Enable595(1); //Enable 595 Output
|
#else
|
PutOutput (0); //Clear all Output
|
Enable595(1); //Enable 595 Output
|
#endif
|
|
if (GetBoardType() == 7 || GetBoardType() ==8
|
|| GetBoardType() == 9 || GetBoardType() ==10 ||GetBoardType() ==13 ||GetBoardType() ==15 || BOARD_TYPE == 16)
|
{
|
displayInput(0xffff); //
|
EnableDisIn(1); //Input Diaplay Enable 595
|
}
|
SetOutStat(0); //OK Good, signal
|
ShowInitInfo();
|
KMem.LastScanTime = GetuS();
|
|
KMRunStat.WorkMode=0;
|
KMRunStat.WorkMode2=0;
|
|
KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode;
|
|
#if (ENABLE_PLC)
|
if (KMRunStat.WorkMode == 1){
|
InitPLC();
|
KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ;
|
if (KMRunStat.WorkMode2) {
|
StartPLC(); }
|
}
|
#endif
|
|
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
LoadKwConfig();
|
// KWireLessInit(&KWInitStruct);
|
|
KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f,1);
|
KWireLessStart();
|
#endif
|
|
|
stPortDef PortReg3 = {.nPortHardType = 7,.nPortUseType = 6};
|
KMRegisterPort(2,&PortReg3);
|
|
while (1)
|
{
|
//int MyKeyStat1,MyKeyStat2;
|
//MyKeyStat1=GetInput();
|
|
//*((unsigned int *)&(PLCMem.SDT[10]))=nRunCount;
|
// KMem.nRunCount=nRunCount;
|
SlowFlicker=0;
|
FastFlicker=1;
|
us1=GetuS();
|
int haltick=HAL_GetTick();
|
|
int thisJumperSW=ReadJumperSW();
|
|
#if (ENABLE_PLC)
|
if (KMRunStat.WorkMode&1){
|
if (thisJumperSW&0x20 && !(KMem.CurJumperSW&0x20)) // Run 开关 正 跳变。
|
{StartPLC();}
|
if (!(thisJumperSW&0x20) && (KMem.CurJumperSW&0x20)) // Run 开关 负 跳变。
|
{StopPLC();}
|
}
|
#endif
|
KMem.CurJumperSW=thisJumperSW;
|
KMem.haltick=haltick;
|
// KMem.TotalRunTime=TotalRunTime;
|
// KMem.ThisRunTime=ThisRunTime;
|
|
// *((unsigned int *)&(PLCMem.SDT[2]))=nChilds;
|
// KMem.SDD[13]=PendSvCount;
|
// KMem.SDD[14]=RCC->CSR;
|
|
|
int a;
|
a = LL_GPIO_ReadInputPort(GPIOA);
|
KMem.WDT[120]=a;
|
a = LL_GPIO_ReadInputPort(GPIOB);
|
KMem.WDT[121]=a;
|
a = LL_GPIO_ReadInputPort(GPIOC);
|
KMem.WDT[122]=a;
|
a = LL_GPIO_ReadInputPort(GPIOD);
|
KMem.WDT[123]=a;
|
|
#if (BOARD_TYPE == 14)
|
// KMem.WX[0]= GetInput();
|
FP0_Proc();
|
#else
|
KMem.WX[0]= GetInput();
|
#endif
|
|
if (GetBoardType() == 7 || GetBoardType() ==8
|
|| GetBoardType() == 9 || GetBoardType() ==10 || GetBoardType() ==15 || GetBoardType() ==16)
|
{
|
displayInput(KMem.WX[0]);
|
}
|
us2=GetuS();
|
if (PowerDownFlag) { KMem.WX[0]=0;}
|
///*
|
if ((KMem.nRunCount &0x1f) == 0x02)
|
{
|
ADCProcess();
|
if (PowerDownFlag)
|
{
|
KMem.WX[0]=0;
|
if (!OldPowerDownFlag)
|
{
|
OldPowerDownFlag = PowerDownFlag;
|
OldPowerDownEventTime = nCurTick;
|
PowerDownProcess();
|
}
|
}else
|
{
|
if (OldPowerDownFlag)
|
{
|
OldPowerDownFlag=PowerDownFlag;
|
PowerRecoverProcess();
|
|
}
|
}
|
}
|
//*/
|
|
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
Radio.IrqProcess( ); // Process Radio IRQ
|
KWL_Process(1);
|
|
#endif
|
|
// pProgs = (stBinProg1 *) STORE_PRG_BASE;
|
#if (ENABLE_PLC)
|
if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster)
|
{
|
if (KMRunStat.nBinProgBank == 0){
|
pProgs=(stBinProg1 *)STORE_PRG_BASE;
|
}else {
|
pProgs=(stBinProg1 *)ALT_PRG_BASE;
|
}
|
nSizeProg1=KMRunStat.nBinProgSize;
|
// pProgs=(stBinProg1 *)prog1;
|
|
ProcessPLCBinProg(pProgs, nSizeProg1);
|
}
|
#endif // ENABLE_PLC
|
KMem.ScanTimeuS=us2-KMem.LastScanTime;
|
KMem.LastScanTime = us2;
|
if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;}
|
if (KMem.ScanTimeuS > KMem.MaxScanTimeuS) {KMem.MaxScanTimeuS = KMem.ScanTimeuS;}
|
|
// if (bKBusRepeater) { KBusRepeaterFunc(); }
|
|
us3=GetuS();
|
|
if (bKBusMaster)
|
{
|
#if (BOARD_TYPE == 14)
|
for (int i=0;i<nOutputBytes;i++)
|
{BufferOut[i+1]=KMem.WYB[i];}
|
#else
|
// BufferOut[1]=KMem.WX[0]&0xff;
|
// BufferOut[2]=(KMem.WX[0]>>8)&0xff;
|
#endif
|
}
|
KBusLoopProcess(&KBus1);
|
|
if (haltick&0x00002000) SlowFlicker=1;
|
else SlowFlicker=0;
|
if (haltick&0x00000800) FastFlicker=1;
|
else FastFlicker=0;
|
|
if (bKBusSlave)
|
{
|
// BufferOut[0]=KMem.WX[0];
|
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
// KBusSlaveFunc(2);
|
// if (! KMem.RunStat) {BufferIn[0]=0;}
|
// KMem.WY[0]=BufferIn[0];
|
#else
|
KBusSlaveFunc(&KBus1);
|
if (! KMem.RunStat) {BufferIn[0]=0;}
|
KMem.WY[0]=BufferIn[0];
|
#endif
|
if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1;
|
else SlowFlicker=0;
|
if (KBus1.nSlaveTick&0x00000800) FastFlicker=1;
|
else FastFlicker=0;
|
}
|
|
// KMem.WY[0]=nCount2>>5;
|
|
|
if (KMRunStat.bLEDFlick)
|
{
|
SetRunLed(FastFlicker);
|
SetErrLed(FastFlicker);
|
SetErr2Led(FastFlicker);
|
SetOutStat(!FastFlicker);
|
//KMRunStat.bLEDFlick-- ;
|
}
|
else
|
{
|
KMem.ErrStat = KwRunStat.ErrStat;
|
if ((KMem.EffJumperSW&0x10)==0x10) KMem.ErrStat += KBus1.ErrStat;
|
#if (ENABLE_PLC)
|
if (KMRunStat.WorkMode==1 ) {
|
if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);}
|
else {SetRunLed(0);}
|
}
|
else
|
#endif // ENABLE_PLC
|
{
|
if (!KMem.RunStat) SetRunLed(SlowFlicker);
|
else SetRunLed(FastFlicker);
|
}
|
|
if (!KMem.ErrStat)
|
{
|
SetErrLed(0);
|
SetErr2Led(0);
|
SetOutStat(1);
|
}
|
else
|
{
|
SetErrLed(FastFlicker);
|
SetErr2Led(FastFlicker);
|
SetOutStat(0);
|
|
}
|
}
|
|
// SetRunLed(RunStat);
|
// SetErrLed(ErrStat);
|
|
us4=GetuS();
|
// EffJumperSW = GetInput(20)&0xff;
|
|
|
#if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
|
if ((KMem.EffJumperSW&0x10)==0x10) {
|
KMem.WFY[1]=KBusMem.WLYB[1];
|
KBusMem.WLXB[1]=KMem.WFX[1];
|
}else
|
{
|
KMem.WFY[1]=KMem.WX[0];
|
KMem.WY[0]=KMem.WFX[1];
|
}
|
// KMem.WY[0]=KMem.WLY[0];
|
#else
|
KMem.WLX[0]=KMem.WX[0];
|
KMem.WY[0]=KMem.WLY[0];
|
#endif
|
|
us5=GetuS();
|
|
#if (BOARD_TYPE == 14)
|
// PutOutput (KMem.WY[0]);
|
#else
|
PutOutput (KMem.WY[0]);
|
#endif
|
//PutOutput (KMem.nRunCount>>8);
|
//PutOutput(0x0f70);
|
|
// if (bKBusMaster) ShowInfo();
|
// if (bKBusSlave) ShowInfo();
|
us6=GetuS();
|
add1(10,10);
|
for (int i=0;i<64;i++)
|
{
|
// ProcessTimer(i);
|
}
|
KMem.nRunCount++;
|
// int nSize=sizeof(stKBusChnStat);
|
// memcpy(&KMem.SDT[64],&KBusChnStats[1],nSize);
|
// memcpy(&KMem.SDT[64+nSize/2],&KBusChnStats[2],nSize);
|
// for (int i=0;i<128;i++) { SDT[i]=i; }
|
// SDT[48]=55;
|
#if (USART1_AUTO_BAUDRATE == 1)
|
if (Uart1IdelTimer>300000) { // 超过60秒没有数据传输,重新进入自适应波特率状态
|
LL_USART_EnableAutoBaudRate(USART1);
|
LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE);
|
}else {
|
Uart1IdelTimer++;
|
}
|
#endif
|
// if (bKBusSlave) HAL_Delay(0);
|
/*
|
if (!IsEmpty(&Uart1Stat.QRx))
|
{
|
unsigned char k=PopOne(&Uart1Stat.QRx);
|
if (k=='L')
|
{
|
clearscreen();
|
}
|
}
|
*/
|
|
#if (BOARD_TYPE == 14)
|
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};
|
//process 6 output
|
{
|
// mapping bits.
|
for (int i=0;i<6;i++)
|
{
|
USHORT bitaddr = storedKMSysCfg.theKMSysCfg.OutMappings[i];
|
UCHAR type = (bitaddr&0xf000) >>12;
|
USHORT byteaddr = (bitaddr&0x0ff0) >>4;
|
UCHAR bitpos = bitaddr &0x0f;
|
UCHAR bitvalue = 0 ;
|
if (byteaddr>0) {
|
if (type == 0) bitvalue = KMem.WXB[byteaddr-1] & ( 1 << bitpos );
|
else if (type == 1 ) bitvalue = KMem.WYB[byteaddr-1] & ( 1 << bitpos );
|
}
|
if (bitvalue){ LL_GPIO_SetOutputPin(GPIOB,pins[i]);}
|
else {LL_GPIO_ResetOutputPin(GPIOB,pins[i]);}
|
}
|
}
|
#endif
|
|
/*
|
{
|
unsigned char pos,seg;
|
unsigned short val;
|
pos=((KMem.nRunCount)&0x3);
|
//val=(KMem.nRunCount)&0xfff;
|
val=KMem.ErrStat;
|
char buf5[20];
|
sprintf(buf5,"%4d",val);
|
val=buf5[3-pos];
|
if (val <'0' || val >'9') {seg=0;}
|
else {seg=LEDSEGTAB[val-'0'];}
|
|
pos=1<<pos;
|
//pos=1;
|
//seg=2;
|
seg=~seg;
|
// PutOutputSPI1(pos|(seg<<8));
|
}
|
*/
|
|
#if (BOARD_TYPE == 13)
|
w5500_network_info_show();
|
// loopback_tcps(0,str1,5000);
|
#endif
|
|
LL_IWDG_ReloadCounter(IWDG);
|
|
} //while (1) ;
|
/* USER CODE END WHILE */
|
|
/* USER CODE BEGIN 3 */
|
|
/* USER CODE END 3 */
|
|
}
|
|
|
/* USER CODE BEGIN 4 */
|
|
/* USER CODE END 4 */
|
|
/**
|
* @brief This function is executed in case of error occurrence.
|
* @param file: The file name as string.
|
* @param line: The line in file as a number.
|
* @retval None
|
*/
|
void _Error_Handler(char *file, int line)
|
{
|
/* USER CODE BEGIN Error_Handler_Debug */
|
/* User can add his own implementation to report the HAL error return state */
|
while(1)
|
{
|
}
|
/* USER CODE END Error_Handler_Debug */
|
}
|
|
#ifdef USE_FULL_ASSERT
|
/**
|
* @brief Reports the name of the source file and the source line number
|
* where the assert_param error has occurred.
|
* @param file: pointer to the source file name
|
* @param line: assert_param error line source number
|
* @retval None
|
*/
|
void assert_failed(uint8_t* file, uint32_t line)
|
{
|
/* USER CODE BEGIN 6 */
|
/* User can add his own implementation to report the file name and line number,
|
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
/* USER CODE END 6 */
|
}
|
#endif /* USE_FULL_ASSERT */
|
|
/**
|
* @}
|
*/
|
|
/**
|
* @}
|
*/
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|