|
/**
|
******************************************************************************
|
* @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 "Functions.h"
|
#include "KMachine.h"
|
#include "PLCfunctions.h"
|
//#include "KBus.h"
|
#include "KLink.h"
|
#include "string.h"
|
#include "BSP.h"
|
|
/* USER CODE END Includes */
|
|
/* Private variables ---------------------------------------------------------*/
|
|
/* USER CODE BEGIN PV */
|
/* Private variables ---------------------------------------------------------*/
|
|
#define RXBUFSIZE 128
|
#define TXBUFSIZE 128
|
|
unsigned char Uart1RxBuf[256];
|
unsigned char Uart1TxBuf[512];
|
|
unsigned char Uart2RxBuf[RXBUFSIZE];
|
unsigned char Uart2TxBuf[TXBUFSIZE];
|
|
//unsigned char buf1[128];
|
|
unsigned char Datas[128];
|
|
unsigned int SlowFlicker=0;
|
unsigned int FastFlicker=0;
|
|
volatile int PacketLength = 0;
|
|
char str1[256];
|
|
int TimeOutCount=0;
|
int Clk3=0;
|
int ContinueSend=0;
|
int Uart1baudval=0;
|
int Uart2baudval=0;
|
|
int repeater=0;
|
|
int SendTime,Latancy,LatancyClk,SendClk;
|
|
int LineCount=0;
|
|
int LastCircleStartTime=0;
|
int CircleTime=0;
|
|
//volatile unsigned int nRunCount=0;
|
volatile int nCount2=0;
|
|
uint32_t us1,us2,us3,us4,us5,us6;
|
const unsigned char buf1[16]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff,0x00};
|
|
volatile int PowerDownEvent=0;
|
volatile int OldPowerDownEvent=0;
|
volatile int OldPowerDownEventTime=0;
|
|
/* USER CODE END PV */
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
/* USER CODE BEGIN PFP */
|
/* Private function prototypes -----------------------------------------------*/
|
|
/* USER CODE END PFP */
|
|
/* USER CODE BEGIN 0 */
|
__asm int add1(int a,int b)
|
{
|
add r0,r1,r0
|
BLX lr
|
}
|
|
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++;
|
nSlaveTick++;
|
Count++;
|
if (Count>=10000)
|
{
|
Count=0;
|
KMem.CurTimeSec++;
|
KMem.ThisRunTime++; KMem.TotalRunTime++;
|
}
|
|
return;
|
}
|
|
int FormatHex(char * buf1,uchar * data,int n)
|
{
|
int len1=0;
|
for (int i=0;i<n;i++)
|
{len1+=sprintf(buf1+len1,"%02X ",data[i]);}
|
len1+=sprintf(buf1+len1,"\r\n");
|
return len1;
|
}
|
|
int RepeaterFunc()
|
{
|
KMem.WY[0]=KMem.WX[0];
|
if ((KMem.nRunCount &0x7f) == 88)
|
{
|
nCount2++;
|
ToggleRunLed();
|
// int len1=sprintf(str1,"%d %d Cfg %02X Input %02X \r\n",nCount,nCount2,EffJumperSW,MyKeyStat1);
|
// PutStr(str1,len1);
|
}
|
return 0;
|
}
|
|
|
int ShowInitInfo()
|
{
|
int len1=0;
|
clearscreen();
|
// Locate(1,1);
|
|
/*
|
LoadFlashDatas();
|
|
LoadAndUpdateStoreCfg();
|
|
HAL_StatusTypeDef res;
|
stStoreCfg * pFCfg = (stStoreCfg *) GetCurStoreCfgAddr();
|
stStoreCfg * pFCfg2 = GetNextStoreCfgAddr(pFCfg);
|
|
int t11=GetuS();
|
|
for (int i=0;i<20;i++)
|
{
|
tims[i]=GetuS();
|
}
|
clearscreen();
|
len1+=sprintf(str1+len1," Ver 001 \r\n");
|
len1+=sprintf(str1+len1," Uart1Baud %d Uart2Baud %d UID %08x %08x %08x \r\n",Uart1Baud,Uart2Baud,pUID[0],pUID[1],pUID[2]);
|
len1+=sprintf(str1+len1," Flash = %d %d %d %d res = %d ",FlashDatas[0],FlashDatas[1],FlashDatas[2],FlashDatas[3],res);
|
len1+=sprintf(str1+len1,"flash operation = %u %u %u\r\n",t11-t10,t10,t11);
|
PutStr(str1,len1);
|
len1=0;
|
len1+=sprintf(str1+len1,"%08X %X %X , PowerOn %X UpTime %X %X %X %X \r\n",
|
(uint32_t)pFCfg,pFCfg[0].Sign1,pFCfg[0].SN1,pFCfg[0].PowerCount,pFCfg[0].UpTime,pFCfg[0].UserData1,pFCfg[0].CRC1,pFCfg[0].EndSign1);
|
len1+=sprintf(str1+len1,"%08X %X %X , PowerOn %X UpTime %X %X %X %X \r\n",
|
(uint32_t)pFCfg2,Cfg2.Sign1,Cfg2.SN1,Cfg2.PowerCount,Cfg2.UpTime,Cfg2.UserData1,Cfg2.CRC1,Cfg2.EndSign1);
|
PutStr(str1,len1);
|
*/
|
len1=0;
|
/*
|
for (int i=0;i<8;i++)
|
{
|
len1=0;
|
len1+=sprintf(str1+len1,"%02X:",i*32);
|
for (int j=0;j<8;j++)
|
{
|
len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]);
|
}
|
len1+=sprintf(str1+len1," %02X",pFlash1[i*32+8]);
|
for (int j=9;j<16;j++)
|
{
|
len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]);
|
}
|
len1+=sprintf(str1+len1," | %02X",pFlash1[i*32+16]);
|
for (int j=17;j<24;j++)
|
{
|
len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]);
|
}
|
len1+=sprintf(str1+len1," %02X",pFlash1[i*32+24]);
|
for (int j=25;j<32;j++)
|
{
|
len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]);
|
}
|
len1+=sprintf(str1+len1,"\r\n");
|
PutStr(str1,len1);
|
}
|
*/
|
us1=GetuS();
|
int crc1 = crc_check(buf1,16);
|
us2=GetuS();
|
int crc2 = crc16bitbybit(buf1,16);
|
us3=GetuS();
|
int crc3 = crc16table(buf1, 16);
|
us4=GetuS();
|
int crc4 = crc16tablefast(buf1, 16);
|
us5=GetuS();
|
LL_CRC_ResetCRCCalculationUnit(CRC);
|
LL_CRC_SetInitialData(CRC,0xFFFFFFFF);
|
LL_CRC_SetInitialData(CRC,0xA001);
|
for (int i=0;i<16;i++)
|
{
|
LL_CRC_FeedData8(CRC,buf1[i]);
|
}
|
int crc5 = LL_CRC_ReadData32(CRC);
|
us6=GetuS();
|
|
len1+=sprintf(str1+len1,"CRC %04X %04X %04X %04X %04X\r\n",crc1,crc2,crc3,crc4,crc5);
|
len1+=sprintf(str1+len1,"time %04d %04d %04d %04d %04d\r\n",us2-us1,us3-us2,us4-us3,us5-us4,us6-us5);
|
|
PutStr(str1,len1);
|
|
InitTimer(0,0);
|
InitTimer(1,1);
|
InitTimer(2,2);
|
InitTimer(3,3);
|
|
StartTimer(0,1000);
|
// StartTimer(2,1000);
|
Locate(13,1);LineCount=3;
|
return 0;
|
}
|
int sprintftime = 0;
|
int putstrtime = 0;
|
|
int ADCProcess()
|
{
|
uint16_t ADC_ConvertedValue=0;
|
static int CurChannel=LL_ADC_CHANNEL_0;
|
//static int waitcount = 0;
|
if (!LL_ADC_REG_IsConversionOngoing(ADC1))
|
{
|
//waitcount++;
|
//if (waitcount<2) return 0;
|
//waitcount=0;
|
ADC_ConvertedValue = LL_ADC_REG_ReadConversionData12(ADC1);
|
|
// ADC_RegularChannelConfig(LL_ADC_CHANNEL_17,);
|
int channels = CurChannel ;//LL_ADC_REG_GetSequencerChannels(ADC1);
|
int nextchannel = LL_ADC_CHANNEL_0;
|
if ((channels & LL_ADC_CHANNEL_0) == LL_ADC_CHANNEL_0)
|
{
|
KMem.ADCValues[0] = ADC_ConvertedValue;
|
nextchannel = LL_ADC_CHANNEL_7;
|
}else if ((channels & LL_ADC_CHANNEL_7) == LL_ADC_CHANNEL_7)
|
{
|
KMem.ADCValues[2] = ADC_ConvertedValue;
|
nextchannel = LL_ADC_CHANNEL_TEMPSENSOR;
|
if (KMem.ADCValues[2] < 2200)
|
{
|
PowerDownEvent=1;
|
}else
|
{
|
PowerDownEvent=0;
|
}
|
}else if ((channels & LL_ADC_CHANNEL_16) == LL_ADC_CHANNEL_16)
|
{
|
KMem.ADCValues[6] = ADC_ConvertedValue;
|
nextchannel = LL_ADC_CHANNEL_VREFINT;
|
}else if ((channels & LL_ADC_CHANNEL_17) == LL_ADC_CHANNEL_17)
|
{
|
KMem.ADCValues[7] = ADC_ConvertedValue;
|
nextchannel = LL_ADC_CHANNEL_0;
|
}else
|
{
|
//ADCValues[0] = ADC_ConvertedValue;
|
}
|
//nextchannel = LL_ADC_CHANNEL_VREFINT;
|
LL_ADC_REG_SetSequencerChannels(ADC1,nextchannel);
|
LL_ADC_REG_StartConversion(ADC1);
|
CurChannel = nextchannel;
|
}
|
return 0;
|
}
|
|
int PowerDownProcess(void )
|
{
|
AddEventLog(KMem.CurTimeSec,EventTypePowerDown,1,12345);
|
SaveRunStat(&KMRunStat);
|
KMem.PwrFailCount++;
|
KMem.LastPwrFailTime = KMem.CurTimeSec;
|
return 0;
|
}
|
|
int PowerRecoverProcess(void)
|
{
|
KMem.PwrFailCount++;
|
|
return 0;
|
}
|
int ShowRunningInfo()
|
{
|
int Clk1=SysTick->VAL;
|
if (Uart1BaudFirstGot)
|
{
|
Uart1baudval = HAL_RCC_GetPCLK1Freq() / USART1->BRR;
|
Uart1BaudFirstGot=0;
|
}
|
if (Uart2BaudFirstGot)
|
{
|
Uart2baudval = HAL_RCC_GetPCLK1Freq() / USART2->BRR;
|
Uart2BaudFirstGot=0;
|
}
|
int Reload=SysTick->LOAD;
|
|
int Clk2=SysTick->VAL;
|
//int us2=GetuS();
|
int haltick=HAL_GetTick();
|
int len1=0;
|
uint32_t theUs = GetuS();
|
int nRunCount2=KMem.nRunCount;
|
if (!Uart1Stat.QTx.bEmpty) return 0;
|
|
if ( (nRunCount2 & 0xff) == 0x03)
|
{
|
Locate(13,1);LineCount=3;
|
} else if ((nRunCount2 & 0xff) == 0x0f)
|
{
|
int timeus1;
|
int timeus2;
|
|
len1=sprintf((char *)str1," N %8d Tk %8d %9u CFG %02X R %d M %d S %d %4d IN %04X OUT %04X \r\n",
|
KMem.nRunCount, haltick, theUs, KMem.EffJumperSW, repeater, bMaster, bSlave, Clk2, KMem.WX[0],KMem.WY[0]);
|
//len1=sprintf((char *)str1,"U%02X%02XA",x2,x2);
|
// Locate(10,1);
|
timeus1=GetuS();
|
PutStr(str1,len1);
|
timeus2=GetuS();
|
sprintftime = timeus1 - theUs;
|
putstrtime = timeus2 - timeus1;
|
if (IsTimerOn(0)) {StartTimer(1,1000);StopTimer(3);}
|
if (IsTimerOn(1)) {StartTimer(2,100);StopTimer(0);}
|
if (IsTimerOn(2)) {StartTimer(3,10);StopTimer(1);}
|
if (IsTimerOn(3)) {StartTimer(0,10000);StopTimer(2);}
|
}
|
if ((nRunCount2 & 0xff) == 0x2f && 0)
|
{
|
|
}
|
if ((nRunCount2 & 0xff) == 0x0af)
|
{
|
|
}
|
return 0;
|
}
|
|
int MasterFunc()
|
{
|
uint32_t tick1=HAL_GetTick();
|
uint32_t thisuS=GetuS();
|
|
int len1=0;
|
|
if ((MasterRecved && thisuS-SendTimeuS>50) || thisuS-SendTimeuS>1500u)
|
{
|
if (!MasterRecved)
|
{
|
TimeOutCount++;
|
Uart2Stat.TimeOutErr++;
|
ChnStats[nCurPollId].LostPackets++;
|
ChnStats[nCurPollId].CtnLstPkts++;
|
if (ChnStats[nCurPollId].CtnLstPkts>ChnStats[nCurPollId].MaxCtnLstPkts)
|
{ChnStats[nCurPollId].MaxCtnLstPkts=ChnStats[nCurPollId].CtnLstPkts;}
|
if (ChnStats[nCurPollId].CtnLstPkts>3)
|
{
|
ChnStats[nCurPollId].Stat=0;
|
KMem.ErrStat=200;
|
|
{BufferIn[nCurPollId]=0;}
|
}
|
// LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_7);
|
}else
|
{
|
ChnStats[nCurPollId].Stat=1;
|
|
KMem.RunStat=100;
|
}
|
nCurPollId ++;
|
if (nCurPollId > nChilds)
|
{
|
CircleTime=thisuS-LastCircleStartTime;
|
LastCircleStartTime=thisuS;
|
nSeq++;
|
nCurPollId=1;
|
}
|
Datas[0]=BufferOut[nCurPollId];
|
Datas[1]=BufferOut[nCurPollId+1];;
|
Datas[2]=ChnStats[nCurPollId].Stat;
|
Datas[3]=0;
|
Datas[4]=tick1&0xff;
|
Datas[5]=(tick1>>8)&0xff;
|
Datas[6]=(tick1>>16)&0xff;
|
Datas[7]=(tick1>>24)&0xff;
|
|
SendTimeuS=thisuS;
|
len1=MakePacket((pPacket)PacketBuf1,0,nCurPollId,cmdExChgData,nSeq,8,Datas);
|
SendPacket2((pPacket)PacketBuf1,len1);
|
ChnStats[nCurPollId].SendPackets++;
|
ChnStats[nCurPollId].SendTimeInterval=SendTimeuS-ChnStats[nCurPollId].LastSentTimeuS;
|
ChnStats[nCurPollId].LastSentTimeuS=SendTimeuS;
|
PacketLength = len1;
|
SendTime=tick1;
|
|
MasterRecved=0;
|
// LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_5);
|
//ToggleErrLed();
|
// ToggleOut8();
|
|
}
|
|
Clk3=SysTick->VAL;
|
// LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_4);
|
// HAL_Delay(1);
|
return 0;
|
}
|
|
int SlaveFunc()
|
{
|
int ThisuS=GetuS();
|
int thisRecvTime=RecvTimeuS;
|
if (SlaveRecved)
|
{
|
KMem.RunStat=100;
|
SlaveRecved=0;
|
}else if ((ThisuS - thisRecvTime) >12000u)
|
{
|
KMem.ErrStat=200;
|
KMem.SDD[17]=1;
|
KMem.SDD[18]=ThisuS;
|
KMem.SDD[19]=RecvTimeuS;
|
}else if ( ThisuS > (thisRecvTime + 12000u))
|
{
|
KMem.ErrStat=200;
|
KMem.SDD[17]=2;
|
KMem.SDD[18]=ThisuS;
|
KMem.SDD[19]=RecvTimeuS;
|
}
|
|
return 0;
|
}
|
|
/* USER CODE END 0 */
|
|
/**
|
* @brief The application entry point.
|
*
|
* @retval None
|
*/
|
int main(void)
|
{
|
/* USER CODE BEGIN 1 */
|
|
InitUartstat(&Uart1Stat,Uart1TxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf));
|
InitUartstat(&Uart2Stat,Uart2TxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf));
|
/* USER CODE END 1 */
|
|
/* MCU Configuration----------------------------------------------------------*/
|
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
HAL_Init();
|
|
/* USER CODE BEGIN Init */
|
|
for (int i=0;i<16;i++)
|
{
|
// memset(ChnStats[i],0,0);
|
ChnStats[i].SendPackets=0;
|
ChnStats[i].RecvPackets=0;
|
ChnStats[i].LostPackets=0;
|
ChnStats[i].CtnLstPkts=0;
|
ChnStats[i].MaxCtnLstPkts=0;
|
ChnStats[i].NotPkgErr=0;
|
ChnStats[i].PkgLenErr=0;
|
ChnStats[i].TimeOutErr=0;
|
ChnStats[i].BCCErr=0;
|
ChnStats[i].Delay=0;
|
ChnStats[i].MaxDelay=0;
|
}
|
|
KMem.LastScanTime=0;
|
KMem.ScanTimeuS=0;
|
KMem.MinScanTimeuS=99999;
|
KMem.MaxScanTimeuS=0;
|
|
// KMem.SDD[14]=(unsigned int)&KMStoreSysCfg;
|
// KMem.SDD[15]=(unsigned int)&KMStoreSysCfg1;
|
KMem.SDD[12]=((uint32_t *)UID_BASE)[0];
|
// KMem.SDD[13]=((uint32_t *)UID_BASE)[1];
|
// KMem.SDD[14]=((uint32_t *)UID_BASE)[2];
|
KMem.SDD[13]=PendSvCount;
|
KMem.SDD[14]=RCC->CSR;
|
// KMem.SDD[15]=*(uint32_t *)FLASHSIZE_BASE;
|
// KMem.SDD[16]=(unsigned int)&KMSysCfg;
|
|
/* 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(&KMSysCfg);
|
|
KMem.EffJumperSW=ReadJumperSW();
|
nAddr=KMem.EffJumperSW&0x7;
|
if (KMem.EffJumperSW == 0x0f) {repeater=1;bMaster=1;bSlave=0;}
|
else if ((KMem.EffJumperSW&0x08)!=0) {bMaster=1;bSlave=0;}
|
else{bMaster=0;bSlave=1;}
|
nChilds=nAddr;
|
nCurPollId=1;
|
if (KMem.EffJumperSW == 0x00) Uart1Baud = DefaultUart1Baud;
|
MX_USART1_UART_Init();
|
MX_USART2_UART_Init();
|
// MX_SPI1_Init();
|
MX_SPI2_Init();
|
MX_ADC_Init();
|
MX_IWDG_Init();
|
|
/* USER CODE BEGIN 2 */
|
LL_USART_EnableIT_RXNE(USART1);
|
LL_USART_EnableIT_IDLE(USART1);
|
LL_USART_EnableIT_TC(USART1);
|
|
LL_USART_EnableIT_RXNE(USART2);
|
LL_USART_EnableIT_IDLE(USART2);
|
LL_USART_EnableIT_TC(USART2);
|
|
// if (bSlave)
|
{
|
// 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
|
PutOutput (0); //Clear all Output
|
Enable595(1); //Enable 595 Output
|
if (GetBoardType() == 7 || GetBoardType() ==8
|
|| GetBoardType() == 9 || GetBoardType() ==10 )
|
{
|
displayInput(0xffff); //
|
EnableDisIn(1); //Input Diaplay Enable 595
|
}
|
SetOutStat(0); //OK Good, signal
|
// ShowInitInfo();
|
KMem.LastScanTime = GetuS();
|
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 CurJumperSW=ReadJumperSW();
|
KMem.CurJumperSW=CurJumperSW;
|
KMem.haltick=haltick;
|
// KMem.TotalRunTime=TotalRunTime;
|
// KMem.ThisRunTime=ThisRunTime;
|
|
// *((unsigned int *)&(PLCMem.SDT[2]))=nChilds;
|
|
KMem.WX[0]= GetInput();
|
|
if (GetBoardType() == 7 || GetBoardType() ==8
|
|| GetBoardType() == 9 || GetBoardType() ==10 )
|
{
|
displayInput(KMem.WX[0]);
|
}
|
us2=GetuS();
|
|
// ProcessPLCPROG(prog1, nSizeProg1);
|
// ScanTimeuS=us2-LastScanTime;
|
// LastScanTime = us2;
|
if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;}
|
if (KMem.ScanTimeuS > KMem.MaxScanTimeuS) {KMem.MaxScanTimeuS = KMem.ScanTimeuS;}
|
if (repeater) { RepeaterFunc(); }
|
us3=GetuS();
|
if ((KMem.nRunCount &0x1f) == 0x02)
|
{
|
ADCProcess();
|
if (PowerDownEvent)
|
{
|
if (!OldPowerDownEvent)
|
{
|
OldPowerDownEvent = PowerDownEvent;
|
OldPowerDownEventTime = nCurTick;
|
PowerDownProcess();
|
}
|
}else
|
{
|
if (OldPowerDownEvent)
|
{
|
OldPowerDownEvent=PowerDownEvent;
|
PowerRecoverProcess();
|
|
}
|
}
|
}
|
if (bMaster)
|
{
|
BufferOut[1]=KMem.WX[0]&0xff;
|
BufferOut[2]=(KMem.WX[0]>>8)&0xff;
|
MasterFunc();
|
|
KMem.WY[0]=BufferIn[1]+(BufferIn[2]<<8);
|
|
if (haltick&0x00002000) SlowFlicker=1;
|
else SlowFlicker=0;
|
if (haltick&0x00000800) FastFlicker=1;
|
else FastFlicker=0;
|
|
}
|
if (bSlave)
|
{
|
BufferOut[0]=KMem.WX[0];
|
SlaveFunc();
|
if (! KMem.RunStat) {BufferIn[0]=0;}
|
KMem.WY[0]=BufferIn[0];
|
|
if (nSlaveTick&0x00002000) SlowFlicker=1;
|
else SlowFlicker=0;
|
if (nSlaveTick&0x00000800) FastFlicker=1;
|
else FastFlicker=0;
|
|
}
|
// KMem.WY[0]=nCount2>>5;
|
if (KMem.RunStat) {KMem.RunStat--;}
|
if (KMem.ErrStat) {KMem.ErrStat--;}
|
|
if (!KMem.RunStat) SetRunLed(SlowFlicker);
|
else SetRunLed(FastFlicker);
|
|
if (!KMem.ErrStat)
|
{
|
SetErrLed(0);
|
SetOutStat(1);
|
}
|
else
|
{
|
SetErrLed(FastFlicker);
|
SetOutStat(0);
|
|
}
|
|
// SetRunLed(RunStat);
|
// SetErrLed(ErrStat);
|
|
us4=GetuS();
|
// EffJumperSW = GetInput(20)&0xff;
|
|
PutOutput (KMem.WY[0]);
|
//PutOutput (KMem.nRunCount>>8);
|
//PutOutput(0x0f70);
|
|
us5=GetuS();
|
// if (bMaster) ShowInfo();
|
// if (bSlave) ShowInfo();
|
us6=GetuS();
|
add1(10,10);
|
for (int i=0;i<64;i++)
|
{
|
// ProcessTimer(i);
|
}
|
KMem.nRunCount++;
|
int nSize=sizeof(stChnStat);
|
memcpy(&KMem.SDT[64],&ChnStats[1],nSize);
|
memcpy(&KMem.SDT[64+nSize/2],&ChnStats[2],nSize);
|
// for (int i=0;i<128;i++) { SDT[i]=i; }
|
// SDT[48]=55;
|
if (Uart1RecvBuf1DataLen >0 && Uart1Stat.bPacketRecved)
|
{
|
KLParsePacket(Uart1RecvBuf1,Uart1RecvBuf1DataLen);
|
Uart1RecvBuf1DataLen=0;
|
Uart1Stat.bPacketRecved=0;
|
}
|
if (bSlave) HAL_Delay(0);
|
/*
|
if (!IsEmpty(&Uart1Stat.QRx))
|
{
|
unsigned char k=PopOne(&Uart1Stat.QRx);
|
if (k=='L')
|
{
|
clearscreen();
|
}
|
}
|
*/
|
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****/
|