arrange again radio fp0 klink knet
| | |
| | | *.uvgui.*
|
| | | *.uvoptx
|
| | | JLinkLog.txt
|
| | |
|
| | |
| | | * @{
|
| | | */
|
| | | #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)
|
| | |
| | |
|
| | | typedef struct tagPacket
|
| | | {
|
| | | 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ʱ��ʵ��Ҳ��һ�����ݡ�
|
| | | 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
|
| | |
| | |
|
| | | } ;
|
| | |
|
| | | 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 );
|
| | |
| | | int WriteData(void);
|
| | |
|
| | | int GetStat(void);
|
| | |
|
| | | */
|
| | | int KBusRepeaterFunc(int nChn);
|
| | | int KBusMasterFunc(int nChn);
|
| | | int KBusSlaveFunc(int nChn);
|
| | |
| | | unsigned short EndSign1;
|
| | | }stStoredKMSysCfg,*pStoredKMSysCfg;
|
| | |
|
| | |
|
| | | /*
|
| | | typedef struct tagFactData
|
| | | {
|
| | |
| | | * (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 */
|
| | |
|
| | | /**
|
| | |
| | | <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> |
| | |
| | |
|
| | | #include "Globaldef.h"
|
| | | #include "Functions.h"
|
| | | #if (BOARD_TYPE == 14)
|
| | | #include "fp0.h"
|
| | | #endif
|
| | |
|
| | | /*
|
| | | if ((nCurTick &0xff) ==0)
|
| | |
| | |
|
| | | /* 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;
|
| | |
| | | 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;
|
| | |
| | | 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
|
| | |
|
| | |
| | | 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|
|
| | |
| | | // 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;
|
| | |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
| | | LL_GPIO_Init(OE_PORT, &GPIO_InitStruct);
|
| | |
|
| | | #elif (BOARD_TYPE == 13)
|
| | | #elif (BOARD_TYPE == 15)
|
| | |
|
| | | // 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_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.Pull = LL_GPIO_OUTPUT_PUSHPULL;
|
| | | 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
|
| | |
|
| | | }
|
| | |
| | | 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];
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | return PacketLenth;
|
| | | }
|
| | |
|
| | | int CheckPacket(int nChn, pPacket p1, int nLen1)
|
| | | int KBusCheckPacket(int nChn, pPacket p1, int nLen1)
|
| | | {
|
| | | if (p1->Sign != StartSign)
|
| | | {
|
| | |
| | | // 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++;
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | int SlaveCheckPacket(int nChn, pPacket p1, int nLen1)
|
| | | int KBusSlaveCheckPacket(int nChn, pPacket p1, int nLen1)
|
| | | {
|
| | | if (p1->Sign != StartSign)
|
| | | {
|
| | |
| | | // 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++;
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | int MasterParsePacket(int nChn, pPacket p1, int Len1)
|
| | | int KBusMasterParsePacket(int nChn, pPacket p1, int Len1)
|
| | | {
|
| | |
|
| | | int DataLen=p1->PacketLen;
|
| | |
| | | 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:
|
| | |
| | | //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:
|
| | |
| | | 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;
|
| | |
| | | //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;
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | }
|
| | | 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;
|
| | |
| | |
|
| | | return Result;
|
| | | }
|
| | |
|
| | | /*
|
| | | int InitMachine(stMachineConfig * pConfig)
|
| | | {
|
| | | return S_OK;
|
| | |
| | | {
|
| | | return S_OK;
|
| | | }
|
| | |
|
| | | */
|
| | | int KBusRepeaterFunc(int nChn)
|
| | | {
|
| | | KMem.WY[0]=KMem.WX[0];
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
|
| | |
|
| | |
| | | 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的nS数,
|
| | | //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;每uS的时钟数
|
| | | 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;
|
| | |
| | | #endif
|
| | | if (Uart2Stat.bPacketRecved)
|
| | | {
|
| | | ParsePacket(2, (pPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); |
| | | KBusParsePacket(2, (pPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); |
| | | Uart2RecvBuf1DataLen=0;
|
| | | Uart2Stat.bPacketRecved=0;
|
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1));
|
| | |
| | | void Output595_8(unsigned int cc)
|
| | | {
|
| | | //unsigned char i;
|
| | | ;// 74HC595输出程序,输出8位
|
| | | ;// 74HC595输出程序,输出8位
|
| | | // cc=~0x3f;
|
| | | __disable_irq();
|
| | | STRCLK2_1();
|
| | |
| | | void Output595_16(unsigned int cc)
|
| | | {
|
| | | //unsigned char i;
|
| | | ;// 74HC595输出程序,输出8位
|
| | | ;// 74HC595输出程序,输出8位
|
| | | // cc=~0x3f;
|
| | | __disable_irq();
|
| | | STRCLK2_1();
|
| | |
| | |
|
| | | #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)
|
| | |
| | | #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)
|
| | |
| | | void displayInput(unsigned int cc)
|
| | | {
|
| | | //unsigned char i;
|
| | | ;// 74HC595输出程序,输出8位
|
| | | ;// 74HC595输出程序,输出8位
|
| | | // cc=~0x3f;
|
| | | __disable_irq();
|
| | | STRCLK1_1();
|
| | |
| | | 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 */
|
| | |
|
| | |
| | | {
|
| | | //int MyKeyStat1,MyKeyStat2;
|
| | | //MyKeyStat1=GetInput();
|
| | |
|
| | | //*((unsigned int *)&(PLCMem.SDT[10]))=nRunCount;
|
| | | // KMem.nRunCount=nRunCount;
|
| | | SlowFlicker=0;
|
| | |
| | | * @param none
|
| | | * @return none
|
| | | */
|
| | | int nIndexCount=0;
|
| | | static int nIndexCount=0;
|
| | | static void w5500_cs_select(void)
|
| | | {
|
| | | // setW5500CLK_1();
|