From f4f290279d32d3cd656472a3298345bc7418cd78 Mon Sep 17 00:00:00 2001 From: QuakeGod <QuakeGod@sina.com> Date: 星期一, 17 十月 2022 20:42:45 +0800 Subject: [PATCH] arrange again radio fp0 klink knet --- Src/BSP.c | 110 +++++++++++++++------- .gitignore | 1 Src/KBus.c | 66 ++++++------ Src/main.c | 5 Inc/KMachine.h | 3 Inc/KBus.h | 26 ++-- Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_ll_rcc.h | 2 Src/KLink.c | 2 Src/w5500_port.c | 2 Src/functions.c | 28 ++-- Inc/stm32f0xx_hal_conf.h | 2 MDK-ARM/F030C8T6_Test2.uvprojx | 4 12 files changed, 145 insertions(+), 106 deletions(-) diff --git a/.gitignore b/.gitignore index 7ed7245..1b5dba2 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,3 @@ *.uvgui.* *.uvoptx JLinkLog.txt - diff --git a/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_ll_rcc.h b/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_ll_rcc.h index 5738d95..93f2327 100644 --- a/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_ll_rcc.h +++ b/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_ll_rcc.h @@ -129,7 +129,7 @@ * @{ */ #if !defined (HSE_VALUE) -#define HSE_VALUE 12000000U /*!< Value of the HSE oscillator in Hz */ +#define HSE_VALUE 8000000U /*!< Value of the HSE oscillator in Hz */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) diff --git a/Inc/KBus.h b/Inc/KBus.h index f877f79..57fe899 100644 --- a/Inc/KBus.h +++ b/Inc/KBus.h @@ -190,13 +190,13 @@ typedef struct tagPacket { - unsigned char Sign; //锟斤拷始锟斤拷锟� - unsigned char DstHost; //目锟斤拷锟街� - unsigned char SrcAddr; //源锟斤拷址 - unsigned char nCMD; //锟斤拷锟斤拷 - unsigned char nSEQ; //锟斤拷锟叫猴拷 - unsigned char PacketLen; //锟斤拷锟斤拷锟截荷筹拷锟斤拷 锟斤拷锟斤拷锟斤拷头锟斤拷5锟斤拷锟街节o拷锟斤拷锟斤拷锟斤拷尾锟斤拷BCC锟斤拷 - unsigned char data[1]; //锟斤拷锟斤拷锟截猴拷,锟斤拷末尾锟斤拷BCC锟斤拷锟斤拷锟捷筹拷锟斤拷为0时锟斤拷实锟斤拷也锟斤拷一锟斤拷锟斤拷锟捷★拷 + unsigned char Sign; //起始标记 + unsigned char DstHost; //目标地址 + unsigned char SrcAddr; //源地址 + unsigned char nCMD; //命令 + unsigned char nSEQ; //序列号 + unsigned char PacketLen; //数据载荷长度 不包括头部5个字节,不包括尾部BCC。 + unsigned char data[1]; //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。 }stPacket,* pPacket; enum eResult @@ -207,22 +207,22 @@ } ; -unsigned char BCC(void * pData, int nSize); +unsigned char KBusBCC(void * pData, int nSize); // /* Make a Packet and return Packet Length */ -int MakePacket(pPacket p1,uchar Src, uchar Dst, uchar nType, uchar nSEQ, uchar DataLen, void *pData ); +int KBusMakePacket(pPacket p1,uchar Src, uchar Dst, uchar nType, uchar nSEQ, uchar DataLen, void *pData ); /* */ -int CheckPacket(int nChn, pPacket p1, int len1); +int KBusCheckPacket(int nChn, pPacket p1, int len1); /* */ -int ParsePacket(int nChn, pPacket p1, int Len1); +int KBusParsePacket(int nChn, pPacket p1, int Len1); typedef struct tagMachineConfig { int bKBusMaster; int nAddr; }stMachineConfig; - +/* int InitMachine(stMachineConfig * pConfig); int SetConfig(void ); @@ -238,7 +238,7 @@ int WriteData(void); int GetStat(void); - +*/ int KBusRepeaterFunc(int nChn); int KBusMasterFunc(int nChn); int KBusSlaveFunc(int nChn); diff --git a/Inc/KMachine.h b/Inc/KMachine.h index 64545c7..e3fb8a4 100644 --- a/Inc/KMachine.h +++ b/Inc/KMachine.h @@ -223,7 +223,6 @@ unsigned short EndSign1; }stStoredKMSysCfg,*pStoredKMSysCfg; - /* typedef struct tagFactData { @@ -422,7 +421,7 @@ unsigned int DTD[KLDataDTCount]; unsigned short DT[KLDataDTCount]; unsigned char DTB[KLDataDTCount*2]; -}; +}; // 配置寄存器 // 系统状态寄存器 diff --git a/Inc/stm32f0xx_hal_conf.h b/Inc/stm32f0xx_hal_conf.h index 19f4c20..a90c873 100644 --- a/Inc/stm32f0xx_hal_conf.h +++ b/Inc/stm32f0xx_hal_conf.h @@ -89,7 +89,7 @@ * (when HSE is used as system clock source, directly or through the PLL). */ #if !defined (HSE_VALUE) - #define HSE_VALUE ((uint32_t)12000000) /*!< Value of the External oscillator in Hz */ + #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ /** diff --git a/MDK-ARM/F030C8T6_Test2.uvprojx b/MDK-ARM/F030C8T6_Test2.uvprojx index 6b6559a..6199103 100644 --- a/MDK-ARM/F030C8T6_Test2.uvprojx +++ b/MDK-ARM/F030C8T6_Test2.uvprojx @@ -110,8 +110,8 @@ <DllOption> <SimDllName>SARMCM3.DLL</SimDllName> <SimDllArguments> -REMAP </SimDllArguments> - <SimDlgDll>DARMSTM.DLL</SimDlgDll> - <SimDlgDllArguments>-pSTM32F030C8</SimDlgDllArguments> + <SimDlgDll>DARMCM1.DLL</SimDlgDll> + <SimDlgDllArguments>-pCM0</SimDlgDllArguments> <TargetDllName>SARMCM3.DLL</TargetDllName> <TargetDllArguments> </TargetDllArguments> <TargetDlgDll>TARMCM1.DLL</TargetDlgDll> diff --git a/Src/BSP.c b/Src/BSP.c index 34a69bd..f2e255c 100644 --- a/Src/BSP.c +++ b/Src/BSP.c @@ -12,6 +12,9 @@ #include "Globaldef.h" #include "Functions.h" +#if (BOARD_TYPE == 14) +#include "fp0.h" +#endif /* if ((nCurTick &0xff) ==0) @@ -367,35 +370,12 @@ /* SPI1 interrupt Init */ NVIC_SetPriority(SPI1_IRQn, 0); - NVIC_EnableIRQ(SPI1_IRQn); +// NVIC_EnableIRQ(SPI1_IRQn); /* USER CODE BEGIN SPI1_Init 1 */ -#if (BOARD_TYPE == 14) +#if (BOARD_TYPE == 13) - /* USER CODE END SPI1_Init 1 */ - - /* SPI1 parameter configuration*/ - SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; - SPI_InitStruct.Mode = LL_SPI_MODE_SLAVE; - SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; - SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; //LL_SPI_POLARITY_LOW; - SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE ; //LL_SPI_PHASE_1EDGE; - SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; - SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; - SPI_InitStruct.BitOrder = LL_SPI_LSB_FIRST; - SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; - SPI_InitStruct.CRCPoly = 7; - LL_SPI_Init(SPI1, &SPI_InitStruct); - - LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA); - LL_SPI_DisableNSSPulseMgt(SPI1); - LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); -// LL_SPI_EnableNSSPulseMgt(SPI1); - - /* USER CODE BEGIN SPI1_Init 2 */ - -#elif (BOARD_TYPE == 13) - + NVIC_EnableIRQ(SPI1_IRQn); SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; @@ -413,8 +393,31 @@ LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); // LL_SPI_EnableNSSPulseMgt(SPI1); +#elif (BOARD_TYPE == 14) + + NVIC_EnableIRQ(SPI1_IRQn); + SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; + SPI_InitStruct.Mode = LL_SPI_MODE_SLAVE; + SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; + SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; //LL_SPI_POLARITY_LOW; + SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE ; //LL_SPI_PHASE_1EDGE; + SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; + SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; + SPI_InitStruct.BitOrder = LL_SPI_LSB_FIRST; + SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; + SPI_InitStruct.CRCPoly = 7; + LL_SPI_Init(SPI1, &SPI_InitStruct); + + LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA); + LL_SPI_DisableNSSPulseMgt(SPI1); + LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); +// LL_SPI_EnableNSSPulseMgt(SPI1); + #else + /* USER CODE END SPI1_Init 1 */ + + /* SPI1 parameter configuration*/ SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; @@ -428,9 +431,11 @@ LL_SPI_Init(SPI1, &SPI_InitStruct); LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA); - + LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); - LL_SPI_EnableNSSPulseMgt(SPI1); +// LL_SPI_EnableNSSPulseMgt(SPI1); + + /* USER CODE BEGIN SPI1_Init 2 */ #endif @@ -727,7 +732,7 @@ LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; } - else if (GetBoardType()==9 || GetBoardType()==10 ) + else if (GetBoardType()==9 || GetBoardType()==10 || GetBoardType()==15 ) { GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| LL_GPIO_PIN_11|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| @@ -765,8 +770,16 @@ // PWR_BackupAccessCmd( ENABLE );/* ????RTC??????*/ // RCC_LSEConfig( RCC_LSE_OFF ); /* ????????,PC14+PC15??????IO*/ // BKP_TamperPinCmd(DISABLE); /* ????????,PC13??????IO*/ - -#if (BORAD_TYPE ==12) + +#if (BORAD_TYPE == 13) + + GPIO_InitStruct.Pin = LL_GPIO_PIN_15 ; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.Pull = LL_GPIO_OUTPUT_PUSHPULL; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + +#elif (BOARD_TYPE == 14) GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7; GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; @@ -805,13 +818,40 @@ GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; LL_GPIO_Init(OE_PORT, &GPIO_InitStruct); -#elif (BOARD_TYPE == 13) +#elif (BOARD_TYPE == 15) - GPIO_InitStruct.Pin = LL_GPIO_PIN_15 ; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + // Radio Pins + // busy pin + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.Pull = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + // Dio 1 pin + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + + //Sel pin + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + + //RST pin + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); #endif diff --git a/Src/KBus.c b/Src/KBus.c index cc34e0f..d52082b 100644 --- a/Src/KBus.c +++ b/Src/KBus.c @@ -17,7 +17,7 @@ unsigned char BufferIn[16]={0}; unsigned char BufferOut[16]={0}; -stChnStat ChnStats[9]; +stChnStat ChnStats[8]; unsigned char nAddr=0; unsigned char nChilds; int ChildStat[16]; @@ -47,7 +47,7 @@ unsigned char Datas[128]; volatile int PacketLength = 0; -unsigned char BCC(void * pData, int nSize) +unsigned char KBusBCC(void * pData, int nSize) { unsigned char k; k=0; @@ -58,7 +58,7 @@ return k; } -int MakePacket(pPacket p1,unsigned char src, uchar dst, uchar nType,unsigned char nSEQ, unsigned char DataLen,void * pData ) +int KBusMakePacket(pPacket p1,unsigned char src, uchar dst, uchar nType,unsigned char nSEQ, unsigned char DataLen,void * pData ) { p1->Sign=StartSign; p1->DstHost=dst; @@ -73,7 +73,7 @@ case cmdPing: p1->PacketLen=DataLen; memcpy(p1->data,pData,DataLen); - p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1); + p1->data[DataLen]=KBusBCC(p1,sizeof(stPacket)+DataLen-1); p1->data[DataLen+1]=EndSign; PacketLenth=sizeof(stPacket)+DataLen+1; @@ -81,7 +81,7 @@ case cmdPingReply: p1->PacketLen=DataLen; memcpy(p1->data,pData,DataLen); - p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1); + p1->data[DataLen]=KBusBCC(p1,sizeof(stPacket)+DataLen-1); p1->data[DataLen+1]=EndSign; PacketLenth=sizeof(stPacket)+DataLen+1; break; @@ -94,35 +94,35 @@ case cmdWriteReply: p1->PacketLen=DataLen; if (DataLen !=0 ) memcpy(p1->data,pData,DataLen); - p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1); + p1->data[DataLen]=KBusBCC(p1,sizeof(stPacket)+DataLen-1); p1->data[DataLen+1]=EndSign; PacketLenth=sizeof(stPacket)+DataLen+1; break; case cmdGetVersion: p1->PacketLen=DataLen; memcpy(p1->data,pData,DataLen); - p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1); + p1->data[DataLen]=KBusBCC(p1,sizeof(stPacket)+DataLen-1); p1->data[DataLen+1]=EndSign; PacketLenth=sizeof(stPacket)+DataLen+1; break; case cmdVerInfo: p1->PacketLen=DataLen; memcpy(p1->data,pData,DataLen); - p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1); + p1->data[DataLen]=KBusBCC(p1,sizeof(stPacket)+DataLen-1); p1->data[DataLen+1]=EndSign; PacketLenth=sizeof(stPacket)+DataLen+1; break; case cmdExChgData: p1->PacketLen=DataLen; memcpy(p1->data,pData,DataLen); - p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1); + p1->data[DataLen]=KBusBCC(p1,sizeof(stPacket)+DataLen-1); p1->data[DataLen+1]=EndSign; PacketLenth=sizeof(stPacket)+DataLen+1; break; case cmdExChgDataReply: p1->PacketLen=DataLen; memcpy(p1->data,pData,DataLen); - p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1); + p1->data[DataLen]=KBusBCC(p1,sizeof(stPacket)+DataLen-1); p1->data[DataLen+1]=EndSign; PacketLenth=sizeof(stPacket)+DataLen+1; break; @@ -130,21 +130,21 @@ case cmdSyncRead: p1->PacketLen=DataLen; memcpy(p1->data,pData,DataLen); - p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1); + p1->data[DataLen]=KBusBCC(p1,sizeof(stPacket)+DataLen-1); p1->data[DataLen+1]=EndSign; PacketLenth=sizeof(stPacket)+DataLen+1; break; case cmdSyncWrite: p1->PacketLen=DataLen; memcpy(p1->data,pData,DataLen); - p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1); + p1->data[DataLen]=KBusBCC(p1,sizeof(stPacket)+DataLen-1); p1->data[DataLen+1]=EndSign; PacketLenth=sizeof(stPacket)+DataLen+1; break; case cmdSequenRead: p1->PacketLen=DataLen; memcpy(p1->data,pData,DataLen); - p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1); + p1->data[DataLen]=KBusBCC(p1,sizeof(stPacket)+DataLen-1); p1->data[DataLen+1]=EndSign; PacketLenth=sizeof(stPacket)+DataLen+1; break; @@ -152,7 +152,7 @@ case cmdSyncTime: p1->PacketLen=DataLen; memcpy(p1->data,pData,DataLen); - p1->data[DataLen]=BCC(p1,sizeof(stPacket)+DataLen-1); + p1->data[DataLen]=KBusBCC(p1,sizeof(stPacket)+DataLen-1); p1->data[DataLen+1]=EndSign; PacketLenth=sizeof(stPacket)+DataLen+1; break; @@ -164,7 +164,7 @@ return PacketLenth; } -int CheckPacket(int nChn, pPacket p1, int nLen1) +int KBusCheckPacket(int nChn, pPacket p1, int nLen1) { if (p1->Sign != StartSign) { @@ -193,7 +193,7 @@ // Uart2Stat.LengthErr++; // return -2; // } - unsigned char thisBCC=BCC(p1,sizeof(stPacket)+DataLen-1); + unsigned char thisBCC=KBusBCC(p1,sizeof(stPacket)+DataLen-1); if (thisBCC != p1->data[DataLen]) {//BCC Error; Uart2Stat.BCCerr++; @@ -203,7 +203,7 @@ return 0; } -int SlaveCheckPacket(int nChn, pPacket p1, int nLen1) +int KBusSlaveCheckPacket(int nChn, pPacket p1, int nLen1) { if (p1->Sign != StartSign) { @@ -232,7 +232,7 @@ // Uart2Stat.LengthErr++; // return -2; // } - unsigned char thisBCC=BCC(p1,sizeof(stPacket)+DataLen-1); + unsigned char thisBCC=KBusBCC(p1,sizeof(stPacket)+DataLen-1); if (thisBCC != p1->data[DataLen]) {//BCC Error; Uart2Stat.BCCerr++; @@ -242,7 +242,7 @@ return 0; } -int MasterParsePacket(int nChn, pPacket p1, int Len1) +int KBusMasterParsePacket(int nChn, pPacket p1, int Len1) { int DataLen=p1->PacketLen; @@ -259,7 +259,7 @@ break; case cmdPing: BufferIn[ChildId]=p1->data[0]; - PacketLen=MakePacket(p2,0,nCurPollId,cmdPingReply,p1->nSEQ,DataLen,p1->data); + PacketLen=KBusMakePacket(p2,0,nCurPollId,cmdPingReply,p1->nSEQ,DataLen,p1->data); SendPacket(nChn, p2, PacketLen); break; case cmdPingReply: @@ -294,7 +294,7 @@ //PutOutput(outputvalue); //memcpy(DispBuf,p1->data+2,8); p1->data[0]=BufferOut[0]; - PacketLen=MakePacket(p2,nAddr,0,cmdExChgDataReply,p1->nSEQ,DataLen,p1->data); + PacketLen=KBusMakePacket(p2,nAddr,0,cmdExChgDataReply,p1->nSEQ,DataLen,p1->data); SendPacket(nChn, p2, PacketLen); break; case cmdExChgDataReply: @@ -343,7 +343,7 @@ return 0; } unsigned char nClientDataIndex=0; -int SlaveParsePacket(int nChn, pPacket p1, int Len1) +int KBusSlaveParsePacket(int nChn, pPacket p1, int Len1) { Uart2Stat.OKPacket++; int DataLen=p1->PacketLen; @@ -375,7 +375,7 @@ //memcpy(DispBuf,p1->data+2,8); p1->data[0]=BufferOut[0]; RecvTimeuS=ThisuS; - PacketLen=MakePacket(p2,nAddr,0,cmdPingReply,p1->nSEQ,DataLen,p1->data); + PacketLen=KBusMakePacket(p2,nAddr,0,cmdPingReply,p1->nSEQ,DataLen,p1->data); ChnStats[0].ClientSendPkts++; SendPacket(nChn, p2, PacketLen); break; @@ -387,7 +387,7 @@ break; case cmdWrite: //memcpy(DispBuf,p1->data,DataLen); - PacketLen=MakePacket(p2,1,0,cmdWriteReply,p1->nSEQ,0,0); + PacketLen=KBusMakePacket(p2,1,0,cmdWriteReply,p1->nSEQ,0,0); ChnStats[0].ClientSendPkts++; SendPacket(nChn, p2, PacketLen); break; @@ -425,7 +425,7 @@ p1->data[7]=ChnStats[0].ClientDatas[nIndex]>>24; nClientDataIndex++; if (nClientDataIndex >= 10) { nClientDataIndex=0;} - PacketLen=MakePacket(p2,nAddr,0,cmdExChgDataReply,p1->nSEQ,DataLen,p1->data); + PacketLen=KBusMakePacket(p2,nAddr,0,cmdExChgDataReply,p1->nSEQ,DataLen,p1->data); ChnStats[0].ClientSendPkts++; SendPacket(nChn, p2, PacketLen); break; @@ -448,32 +448,32 @@ } return 0; } -int ParsePacket(int nChn, pPacket p1, int Len1) +int KBusParsePacket(int nChn, pPacket p1, int Len1) { ThisuS=GetuS(); int Result=0; if (bKBusMaster) { MasterRecved=1; - Result=CheckPacket(nChn, p1, Len1); + Result=KBusCheckPacket(nChn, p1, Len1); if (Result != S_OK) { return Result; } MasterRecvOK=1; - Result=MasterParsePacket(nChn, p1, Len1); + Result=KBusMasterParsePacket(nChn, p1, Len1); return Result; } if (bKBusSlave) { ChnStats[0].ClientRecvPkts++; - Result=SlaveCheckPacket(nChn, p1, Len1); + Result=KBusSlaveCheckPacket(nChn, p1, Len1); if (Result != S_OK) { return Result; } ChnStats[0].ClientTimeOutErr=KMem.RunStat; - Result=SlaveParsePacket(nChn, p1, Len1); + Result=KBusSlaveParsePacket(nChn, p1, Len1); return Result; } //int len1=p1->PacketLen; @@ -483,7 +483,7 @@ return Result; } - +/* int InitMachine(stMachineConfig * pConfig) { return S_OK; @@ -523,7 +523,7 @@ { return S_OK; } - +*/ int KBusRepeaterFunc(int nChn) { KMem.WY[0]=KMem.WX[0]; @@ -607,7 +607,7 @@ Datas[7]=(tick1>>24)&0xff; SendTimeuS=thisuS; - len1=MakePacket((pPacket)PacketBuf1,0,nCurPollId,cmdExChgData,nSeq,8,Datas); + len1=KBusMakePacket((pPacket)PacketBuf1,0,nCurPollId,cmdExChgData,nSeq,8,Datas); SendPacket(nChn, (pPacket)PacketBuf1, len1); ChnStats[nCurPollId].SendPackets++; ChnStats[nCurPollId].SendTimeInterval=SendTimeuS-ChnStats[nCurPollId].LastSentTimeuS; diff --git a/Src/KLink.c b/Src/KLink.c index afdc34f..da4fd03 100644 --- a/Src/KLink.c +++ b/Src/KLink.c @@ -44,7 +44,7 @@ p1->nRplyCMD=nCmd; p1->nSize1=DataLen; memcpy(p1->Datas,pData,DataLen); - p1->Datas[DataLen]=BCC(p1,sizeof(stKLRplyPktHdr)+DataLen-1); + p1->Datas[DataLen]=KLBCC(p1,sizeof(stKLRplyPktHdr)+DataLen-1); PacketLenth=sizeof(stKLRplyPktHdr)+DataLen; diff --git a/Src/functions.c b/Src/functions.c index c184345..055d62e 100644 --- a/Src/functions.c +++ b/Src/functions.c @@ -19,16 +19,16 @@ unsigned int TickPrioduS; // volatile unsigned int nCurTick=0; volatile unsigned int CurTickuS=0; -//volatile unsigned int ThisRunTime=0; //寮�鏈烘椂闂� -//volatile unsigned int TotalRunTime=0; //鎬诲紑鏈烘椂闂� -//volatile unsigned int PwrCount=0; //寮�鏈烘鏁� -unsigned short ClkuS; //姣忎釜Clk鐨刵S鏁帮紝 +//volatile unsigned int ThisRunTime=0; //开机时间 +//volatile unsigned int TotalRunTime=0; //总开机时间 +//volatile unsigned int PwrCount=0; //开机次数 +unsigned short ClkuS; //每个Clk的nS数, int InituS(int TickFreq1) { - TickPrioduS=1000000/TickFreq1; //姣忎釜SysTick鐨勫井绉掓暟 - CoreClkMHz=HAL_RCC_GetHCLKFreq()/1000000; //=SystemCoreClock/1000000;姣弖S鐨勬椂閽熸暟 - TickPriodClk=SystemCoreClock/TickFreq1; //姣忎釜SysTick鐨勬椂閽熸暟 + TickPrioduS=1000000/TickFreq1; //每个SysTick的微秒数 + CoreClkMHz=HAL_RCC_GetHCLKFreq()/1000000; //=SystemCoreClock/1000000;每uS的时钟数 + TickPriodClk=SystemCoreClock/TickFreq1; //每个SysTick的时钟数 ClkuS=(1000000LL*65536)/SystemCoreClock; CurTickuS=TickPrioduS+100u; return 0; @@ -281,7 +281,7 @@ #endif if (Uart2Stat.bPacketRecved) { - ParsePacket(2, (pPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); + KBusParsePacket(2, (pPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); Uart2RecvBuf1DataLen=0; Uart2Stat.bPacketRecved=0; Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); @@ -615,7 +615,7 @@ case 13: return Input165_R(16); case 14: - return 0; //FP0 + return 0; //FP0 case 15: return Input165_R(16); default: @@ -732,7 +732,7 @@ void Output595_8(unsigned int cc) { //unsigned char i; -;// 74HC595杈撳嚭绋嬪簭锛岃緭鍑�8浣� +;// 74HC595输出程序,输出8位 // cc=~0x3f; __disable_irq(); STRCLK2_1(); @@ -758,7 +758,7 @@ void Output595_16(unsigned int cc) { //unsigned char i; -;// 74HC595杈撳嚭绋嬪簭锛岃緭鍑�8浣� +;// 74HC595输出程序,输出8位 // cc=~0x3f; __disable_irq(); STRCLK2_1(); @@ -860,7 +860,7 @@ #if (BOARD_TYPE == 9 || BOARD_TYPE == 10 || BOARD_TYPE == 15 ) //#pragma message("9,10") - // V4.2 绠¤剼鎺掑垪鍚戝彸绉诲姩浜嗕竴浣嶃�� + // V4.2 管脚排列向右移动了一位。 #define SRCLK1_0() LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_1) #define SRCLK1_1() LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_1) #define STRCLK1_0() LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_2) @@ -869,7 +869,7 @@ #define OE1_1() LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_10) #define SER1_0() LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_11) #define SER1_1() LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_11) -#else //鎸夌収鍘熸潵鐨勭鑴氭帓鍒� +#else //按照原来的管脚排列 #define SRCLK1_0() LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_0) #define SRCLK1_1() LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_0) #define STRCLK1_0() LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_1) @@ -890,7 +890,7 @@ void displayInput(unsigned int cc) { //unsigned char i; -;// 74HC595杈撳嚭绋嬪簭锛岃緭鍑�8浣� +;// 74HC595输出程序,输出8位 // cc=~0x3f; __disable_irq(); STRCLK1_1(); diff --git a/Src/main.c b/Src/main.c index bf13c65..b6da46e 100644 --- a/Src/main.c +++ b/Src/main.c @@ -188,9 +188,9 @@ SystemClock_Config(); /* USER CODE BEGIN SysInit */ - TickFreq=10000; //Tick频锟斤拷 + TickFreq=10000; //Tick频率 InituS(TickFreq); - // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq); //锟斤拷锟铰讹拷锟斤拷SysTick锟斤拷频锟斤拷锟� + // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq); //重新定义SysTick的频率� /* USER CODE END SysInit */ @@ -313,6 +313,7 @@ { //int MyKeyStat1,MyKeyStat2; //MyKeyStat1=GetInput(); + //*((unsigned int *)&(PLCMem.SDT[10]))=nRunCount; // KMem.nRunCount=nRunCount; SlowFlicker=0; diff --git a/Src/w5500_port.c b/Src/w5500_port.c index d99eec4..c3674ef 100644 --- a/Src/w5500_port.c +++ b/Src/w5500_port.c @@ -36,7 +36,7 @@ * @param none * @return none */ -int nIndexCount=0; +static int nIndexCount=0; static void w5500_cs_select(void) { // setW5500CLK_1(); -- Gitblit v1.9.1