| | |
| | | #include "string.h" |
| | | #include "stm32f0xx_hal.h" |
| | | #if (BOARD_TYPE == 14) |
| | | #include "fp0.h" |
| | | #include "fpx.h" |
| | | #endif |
| | | extern __IO uint32_t uwTick; |
| | | //#include "Myprotocol.h" |
| | |
| | | //volatile unsigned int TotalRunTime=0; //总开机时间 |
| | | //volatile unsigned int PwrCount=0; //开机次数 |
| | | unsigned short ClkuS; //每个Clk的nS数, |
| | | |
| | | unsigned char SPI1RecvBuf[64]; |
| | | unsigned char SPI1SendBuf[64]; |
| | | |
| | | volatile unsigned char bSPI1Recving=0; |
| | | volatile unsigned char bSPI1RecvDone =0; |
| | | |
| | | volatile unsigned char nSPI1RecvPos =0; |
| | | volatile unsigned char nSPI1RecvLenInBuf=0; |
| | | |
| | | volatile unsigned char nSPI1ToSendLen=0; |
| | | volatile unsigned char nSPI1SentLen=0; |
| | | |
| | | volatile unsigned char bSPI1Sending=0; |
| | | volatile unsigned char bSPI1SendDone=0; |
| | | |
| | | |
| | | int InituS(int TickFreq1) |
| | | { |
| | |
| | | |
| | | void logData(unsigned char d) |
| | | { |
| | | KMem.WDB[128+KMem.WDT[123]] = d; |
| | | KMem.WDT[123]++; if (KMem.WDT[123]>=100) {KMem.WDT[123]=81;} |
| | | KMem.WDB[128+KMem.WDT[7]] = d; |
| | | KMem.WDT[7]++; if (KMem.WDT[7]>=100) {KMem.WDT[7]=81;} |
| | | } |
| | | |
| | | /* |
| | | const unsigned short crc16_table[256] = { |
| | | 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, |
| | | 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, |
| | |
| | | } |
| | | return(crc); |
| | | } |
| | | |
| | | */ |
| | | /* Table of CRC values for high-order byte */ |
| | | const uint8_t crctablehi[] = { |
| | | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, |
| | |
| | | 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, |
| | | 0x40 |
| | | }; |
| | | |
| | | /* |
| | | uint16_t crc16table(const uint8_t *ptr, uint16_t len) |
| | | { |
| | | uint8_t crchi = 0xff; |
| | |
| | | } |
| | | return (crchi << 8 | crclo); |
| | | } |
| | | */ |
| | | const uint16_t crctalbeabs[] = { |
| | | 0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, |
| | | 0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400 |
| | | }; |
| | | |
| | | uint16_t crc16tablefast(const uint8_t *ptr, uint16_t len) |
| | | { |
| | | uint16_t crc = 0xffff; |
| | | uint16_t i; |
| | | uint8_t ch; |
| | | |
| | | for (i = 0; i < len; i++) { |
| | | ch = *ptr++; |
| | | crc = crctalbeabs[(ch ^ crc) & 15] ^ (crc >> 4); |
| | | crc = crctalbeabs[((ch >> 4) ^ crc) & 15] ^ (crc >> 4); |
| | | } |
| | | |
| | | return crc; |
| | | } |
| | | |
| | | /* |
| | | void modbuscrc16test() |
| | | { |
| | | printf("\n"); |
| | |
| | | // printf(" modbus crc16tablefast test, expected value : 0xd825, calculate value : 0x%x\n", crc16tablefast(crc16_data, sizeof(crc16_data))); |
| | | printf(" modbus crc16bitbybit test, expected value : 0xd825, calculate value : 0x%x\n", crc16bitbybit(crc16_data, sizeof(crc16_data))); |
| | | } |
| | | |
| | | */ |
| | | int InitUartstat(stUartStat * pUartstat,void * pBufRx, int nSizeRx, void * pBufTx, int nSizeTx) |
| | | { |
| | | memset(pUartstat,sizeof(stUartStat),0); |
| | | initQueue(&pUartstat->QRx,pBufRx,nSizeRx); |
| | | initQueue(&pUartstat->QTx,pBufTx,nSizeTx); |
| | | if (pBufRx) initQueue(&pUartstat->QRx,pBufRx,nSizeRx); |
| | | if (pBufTx) initQueue(&pUartstat->QTx,pBufTx,nSizeTx); |
| | | return 0; |
| | | } |
| | | |
| | |
| | | SCB->ICSR=SCB_ICSR_PENDSVSET_Msk; //1<<SCB_ICSR_PENDSVSET_Pos; |
| | | } |
| | | |
| | | void PendSvCallBack() |
| | | { |
| | | #if (BOARD_TYPE == 14) |
| | | ///* |
| | | if (bSPI1RecvDone) |
| | | { |
| | | bSPI1RecvDone=0; |
| | | ParseFP0Pkg(SPI1RecvBuf,nSPI1RecvLenInBuf); |
| | | } |
| | | //*/ |
| | | #endif |
| | | if (Uart2Stat.bPacketRecved) |
| | | { |
| | | KBusParsePacket(2, (pKBPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); |
| | | Uart2RecvBuf1DataLen=0; |
| | | Uart2Stat.bPacketRecved=0; |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | } |
| | | } |
| | | |
| | | void SPI1_IRQ_CallBack() |
| | | { |
| | | uint8_t value; |
| | |
| | | bSPI1SendDone=1; |
| | | bSPI1Recving=1; |
| | | nSPI1RecvPos=0; |
| | | SetFP0DEPin_0(); |
| | | SetFPxDEPin_0(); |
| | | } |
| | | else { |
| | | value = SPI1SendBuf[nSPI1SentLen]; |
| | |
| | | logData(value); |
| | | } |
| | | } |
| | | #endif |
| | | #else |
| | | UNUSED(value); |
| | | #endif |
| | | } |
| | | } |
| | | |
| | |
| | | // SCB->ICSR=SCB_ICSR_PENDSVSET_Msk; //1<<SCB_ICSR_PENDSVSET_Pos; |
| | | // KLParsePacket(Uart1RecvBuf1,Uart1RecvBuf1DataLen); |
| | | // Uart1RecvBuf1DataLen=0; |
| | | TriggerPendSV(); |
| | | } |
| | | } |
| | | |
| | |
| | | #else |
| | | Uart2UnsetDE(); |
| | | #endif |
| | | Uart2Stat.bSendDone = 1; |
| | | TriggerPendSV(); |
| | | } |
| | | void Uart2RecvDone() |
| | | { |
| | |
| | | // LL_USART_EnableIT_TXE(USART1); |
| | | // LL_USART_EnableIT_TC(USART1); |
| | | Uart1TriggerSendDMA(); |
| | | Uart1Stat.SentPacket++; |
| | | return len1; |
| | | } |
| | | int PutStr2(char * str1, int len1) |
| | |
| | | // LL_USART_EnableIT_TXE(USART1); |
| | | // LL_USART_EnableIT_TC(USART1); |
| | | // Uart2TriggerSendDMA(); |
| | | Uart2Stat.SentPacket++; |
| | | return len1; |
| | | } |
| | | |
| | |
| | | PutStr1((char *)pBuf,len1); |
| | | // PushIn(&Uart1Stat.QTx,p1,len1); |
| | | // Uart1TriggerSendDMA(); |
| | | Uart1Stat.SentPacket++; |
| | | |
| | | }else if (nChn==2){ |
| | | PutStr2((char *)pBuf,len1); |
| | | // PushIn(&Uart2Stat.QTx,p1,len1); |
| | | // Uart2TriggerSendDMA(); |
| | | Uart2Stat.SentPacket++; |
| | | |
| | | } |
| | | return len1; |
| | | } |
| | |
| | | case 13: |
| | | return Input165_R(16); |
| | | case 14: |
| | | return 0; //FP0 |
| | | return 0; //FPx |
| | | case 15: |
| | | return Input165_R(16); |
| | | case 16: |
| | |
| | | case 13: |
| | | return ReadConfig_5(); |
| | | case 14: |
| | | return (~(LL_GPIO_ReadInputPort(GPIOA)>>4))&0x0f; //FP0 |
| | | return (~(LL_GPIO_ReadInputPort(GPIOA)>>4))&0x0f; //FPx |
| | | case 15: |
| | | case 16: |
| | | return ReadConfig_5(); //Wireless Master Slave 8 in 8 o |