Inc/KBus.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Inc/KMachine.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Inc/functions.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Src/KBus.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Src/ModbusRTU.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Src/functions.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Src/main.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
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���ֽڣ�������β��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 Inc/KMachine.h
@@ -49,9 +49,9 @@ #define LoHofB(x) ((x)&0xf) #define HiHofB(x) (((x)>>4)&0xf) // ��Ϣ�� // �����������ÿ� // �û�/ϵͳ�������ÿ� // 信息块 // 工厂参数配置块 // 用户/系统参数配置块 // // @@ -103,26 +103,26 @@ enum enPortType { PortType_Com = 0, //�����ͨѶ PortType_Gen = 1, //ͨ��ͨѶ�����ɿ� PortType_Com = 0, //计算机通讯 PortType_Gen = 1, //通用通讯,自由口 PortType_KLink = 2, //KlinkͨѶ PortType_KBus = 3, //KBusͨѶ PortType_KNet = 4, // KNetͨѶ PortType_ModbusRTU = 5, //Modbus RTU ͨѶ }; //ÿ��ģ���� 0/1/2/3/4/5/6/7/8�� ͨѶport //������ UART, ���ڣ����ߣ������ߵȣ�����port //���������������port //每个模块有 0/1/2/3/4/5/6/7/8个 通讯port //不限于 UART, 网口,无线,单总线等,都是port //甚至可以有虚拟的port typedef struct tagPortStat { UCHAR nWorking; //������ UCHAR nStation; //�Լ�վ�� UCHAR bBus; //����?,,ȫ˫��? UCHAR bMaster; //���� UCHAR PortType; //�˿ڹ���ģʽ UCHAR nDevices; //���ӵ��豸����//�������Լ� //device list; UCHAR nWorking; //工作中 UCHAR nStation; //自己站号 UCHAR bBus; //总线?,,全双工? UCHAR bMaster; //主机 UCHAR PortType; //端口工作模式 UCHAR nDevices; //连接的设备数量//不包括自己 //device list; }stPortStat,*pPortStat; @@ -146,11 +146,11 @@ typedef struct tagKMFuncParam { USHORT EnablePLC:1; //ʹ���ڲ�PLC���� USHORT RunMode; //����ģʽ USHORT EnablePLC:1; //使能内部PLC功能 USHORT RunMode; //工作模式 }stKMFuncParam; // ���������ַӳ�� // 输入输出地址映射 typedef struct tagComPortParam //4 Bytes { @@ -190,7 +190,7 @@ USHORT workmode; // SC1 // 2 Bytes 0=From jumper USHORT SwitchFunc; // SC2 // 2 Bytes USHORT OutMappings[6]; //12 Bytes //���ӳ�� USHORT OutMappings[6]; //12 Bytes //输出映射 stComPortParam PortParams[2]; // 8 Bytes stOutputHoldParam OutputParams[16]; //16 Bytes @@ -238,7 +238,7 @@ }stFactData; */ typedef struct tagFactoryData //������������������ typedef struct tagFactoryData //工厂量产参数,数据 { USHORT Sign1; USHORT Seq1; @@ -397,12 +397,12 @@ stTimer Timers[TOTALTIMERS]; union { unsigned short WX[KLDataWXCount]; //������X��Y unsigned short WX[KLDataWXCount]; //本机的X和Y unsigned char WXB[KLDataWXCount*2]; }; union { unsigned short WY[KLDataWYCount]; //������X��Y unsigned char WYB[KLDataWYCount*2]; //������X��Y unsigned short WY[KLDataWYCount]; //本机的X和Y unsigned char WYB[KLDataWYCount*2]; //本机的X和Y }; unsigned short WR[KLDataWRCount]; @@ -413,7 +413,7 @@ unsigned short SV[KLDataSVCount]; unsigned short WLX[16]; //�����X��Y��Զ��ͨѶʱӳ���á� unsigned short WLX[16]; //虚拟的X和Y,远程通讯时映射用。 unsigned short WLY[16]; unsigned short WLR[16]; unsigned short WSR[16]; @@ -424,10 +424,10 @@ unsigned char DTB[KLDataDTCount*2]; }; // ���üĴ��� // ϵͳ״̬�Ĵ��� // ����Ĵ��� // ���ԣ���ؼĴ��� // 配置寄存器 // 系统状态寄存器 // 特殊寄存器 // 调试,监控寄存器 union { unsigned int SDD[KLDataSDTCount/2]; unsigned short SDT[KLDataSDTCount]; Inc/functions.h
@@ -21,7 +21,7 @@ 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; @@ -74,4 +74,5 @@ void EnableDisIn(uchar bEnable); void displayInput(unsigned int cc); void PutOutputSPI1(unsigned int Y); #endif /* __MYFUNCTIONS_H__ */ Src/KBus.c
@@ -399,8 +399,6 @@ break; case cmdExChgData: BufferIn[0]=p1->data[0]; PutOutput(BufferIn[0]); PutOutput(BufferIn[0]); nSlaveTick=p1->data[4]+(p1->data[5]<<8);//+(p1->data[6]<<16)+(p1->data[7]<<24); #if (BOARD_TYPE == 14) // PutOutput(BufferIn[0]); Src/ModbusRTU.c
@@ -86,12 +86,12 @@ 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; } 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��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; @@ -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(); Src/main.c
@@ -66,7 +66,7 @@ /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ #define ADCrefAddr 0x1FFFF7BA /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ @@ -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 */