KLink update KLink and Kbus
4个文件已删除
10个文件已修改
1 文件已重命名
| | |
| | |
|
| | | 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
|
| | |
| | | /*
|
| | | typedef struct tagKLPktHdr
|
| | | {
|
| | | unsigned char StSign; //起始标记
|
| | | unsigned char SrcAddr; //源地址
|
| | | unsigned char DstHost; //目标地址
|
| | | unsigned char nCMD; //命令
|
| | | unsigned char StSign; //起始标记
|
| | | unsigned char SrcAddr; //源地址
|
| | | unsigned char DstHost; //目标地址
|
| | | unsigned char nCMD; //命令
|
| | |
|
| | | }stKLPtHdr, * pKLPktHdr;
|
| | | */
|
| | | /*
|
| | | typedef struct tagKLRdPkt
|
| | | {
|
| | | unsigned char StSign; //起始标记 |
| | | unsigned char SrcAddr; //源地址
|
| | | unsigned char DstHost; //目标地址
|
| | | unsigned char nCMD; //命令
|
| | | unsigned char StSign; //起始标记 |
| | | unsigned char SrcAddr; //源地址
|
| | | unsigned char DstHost; //目标地址
|
| | | unsigned char nCMD; //命令
|
| | | unsigned char nType;
|
| | | unsigned char nAddr; //
|
| | | }stKLRdPkt,* pKLRdKpt;
|
| | |
| | | /*
|
| | | typedef struct tagKLPacket
|
| | | {
|
| | | unsigned char StSign; //起始标记 |
| | | unsigned char SrcAddr; //源地址
|
| | | unsigned char DstHost; //目标地址
|
| | | unsigned char nCMD; //命令
|
| | | unsigned char nSEQ; //序列号
|
| | | unsigned char LoadLen; //数据载荷长度 不包括头部5个字节,不包括尾部BCC。
|
| | | unsigned char data[1]; //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。
|
| | | unsigned char StSign; //起始标记 |
| | | unsigned char SrcAddr; //源地址
|
| | | unsigned char DstHost; //目标地址
|
| | | unsigned char nCMD; //命令
|
| | | unsigned char nSEQ; //序列号
|
| | | unsigned char LoadLen; //数据载荷长度 不包括头部5个字节,不包括尾部BCC。
|
| | | unsigned char data[1]; //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。
|
| | | }stKLPacket,* pKLPacket;
|
| | | */
|
| | |
|
| | |
| | | enum enModbusRTUCmd
|
| | | {
|
| | | None =0,
|
| | | ReadCoils =1, //读线圈
|
| | | ReadInputs =2, //读离散量输入
|
| | | ReadKeepRegs =3, //读保持寄存器
|
| | | ReadInputRegs =4, //读输入寄存器
|
| | | WriteCoil = 5, //写单个线圈
|
| | | WriteReg =6, //写单个寄存器
|
| | | ReadExptStat = 7, //读取异常状态
|
| | | ReadCoils =1, //读线圈
|
| | | ReadInputs =2, //读离散量输入
|
| | | ReadKeepRegs =3, //读保持寄存器
|
| | | ReadInputRegs =4, //读输入寄存器
|
| | | WriteCoil = 5, //写单个线圈
|
| | | WriteReg =6, //写单个寄存器
|
| | | ReadExptStat = 7, //读取异常状态
|
| | | FetchCommEventCtr =11, //Fetch Comm Event Ctr
|
| | | // 12 Fetch Comm Event Log
|
| | |
|
| | | WriteCoils =15, //写多个线圈
|
| | | WriteRegs = 16, //写多个寄存器
|
| | | WriteCoils =15, //写多个线圈
|
| | | WriteRegs = 16, //写多个寄存器
|
| | | //17 Report Slave ID
|
| | | //20 Read General Reference
|
| | | //21 Write General Reference
|
| | |
| | | extern volatile unsigned int CurTickuS;
|
| | | //extern volatile unsigned int ThisRunTime;
|
| | | //extern volatile unsigned int TotalRunTime;
|
| | | //extern volatile unsigned int PwrCount; //开机次数
|
| | | //extern volatile unsigned int PwrCount; //开机次数
|
| | |
|
| | | typedef unsigned char uint8_t;
|
| | | typedef unsigned char uchar;
|
| | |
| | | * Auto generated Run-Time-Environment Component Configuration File
|
| | | * *** Do not modify ! ***
|
| | | *
|
| | | * Project: 'F030C8T6_Test2' |
| | | * Project: 'F030C8T6_KLink' |
| | | * Target: 'F030C8T6_Test2'
|
| | | */
|
| | |
|
| | |
| | | bSPI1Sending=0;
|
| | | bSPI1Recving=0;
|
| | | if (nChilds==0) {
|
| | | nInputBytes=1; //根据子机数量,报告扩展容量
|
| | | nInputBytes=1; //根据子机数量,报告扩展容量
|
| | | nOutputBytes=1;
|
| | | } else
|
| | | {
|
| | | nInputBytes=nChilds; //根据子机数量,报告扩展容量
|
| | | nInputBytes=nChilds; //根据子机数量,报告扩展容量
|
| | | nOutputBytes=nChilds;
|
| | | }
|
| | | SetACKPin_0();
|
| | |
| | |
|
| | | int ModBusSlaveCheckPkg(int nChn, void *ptr, uint16_t len1)
|
| | | {
|
| | | if (len1 <=4) return -1; //包长
|
| | | if (len1 <=4) return -1; //包长
|
| | | pModBusRTUReqPkg pPkg = (pModBusRTUReqPkg) ptr;
|
| | | if (pPkg->Dst >127) return -2; //地址码
|
| | | if ((pPkg->Cmd&0x7f) > 0x1f) return -3; //功能码
|
| | | uint16_t crc = crc16tablefast(ptr,len1); //CRC 校验
|
| | | if (crc != 0 ) return 4; //CRC 校验错误
|
| | | if (pPkg->Dst >127) return -2; //地址码
|
| | | if ((pPkg->Cmd&0x7f) > 0x1f) return -3; //功能码
|
| | | uint16_t crc = crc16tablefast(ptr,len1); //CRC 校验
|
| | | if (crc != 0 ) return 4; //CRC 校验错误
|
| | | return S_OK;
|
| | | }
|
| | |
|
| | |
| | | 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;
|
| | |
| | | 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 */
|
| | |
|