8个文件已删除
76个文件已修改
12 文件已重命名
13个文件已添加
| | |
| | | <AfterMake> |
| | | <RunUserProg1>1</RunUserProg1> |
| | | <RunUserProg2>0</RunUserProg2> |
| | | <UserProg1Name>fromelf --bin --output="@L.bin" "#L"</UserProg1Name> |
| | | <UserProg1Name>fromelf --bin --output="../@L.bin" "#L"</UserProg1Name> |
| | | <UserProg2Name></UserProg2Name> |
| | | <UserProg1Dos16Mode>0</UserProg1Dos16Mode> |
| | | <UserProg2Dos16Mode>0</UserProg2Dos16Mode> |
| | |
| | | <FileType>1</FileType> |
| | | <FilePath>..\..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_rtc.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_flash.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_flash.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | | </Groups> |
| | |
| | | #include "Functions.h" |
| | | #include "string.h" |
| | | #include "BSP.h" |
| | | #include "stm32f0xx_ll_flash.h" |
| | | |
| | | /* USER CODE END Includes */ |
| | | |
| | |
| | | unsigned char SlowFlicker=0; |
| | | unsigned char FastFlicker=0; |
| | | |
| | | |
| | | typedef struct tagInfoBlockHdr { |
| | | unsigned short nBlkSign; // å¼å§æ å¿ |
| | | unsigned short nBlkTypeVer; // ç±»ååçæ¬ |
| | | unsigned short nBlkSize; // Block 大å°, å
æ¬å¼å§åç»ææ å¿ |
| | | unsigned short Pad1; |
| | | }stInfoBlockHdr; |
| | | |
| | | typedef struct tagInfoBlockTail { |
| | | |
| | | unsigned short CRC16; |
| | | unsigned short EndSign; |
| | | }stInfoBlockTail; |
| | | |
| | | typedef struct tagBtLdrInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nBtldrVer; |
| | | unsigned short nBtldrDevice; |
| | | unsigned short nBtldrSize; // è®¾è®¡å¤§å° |
| | | unsigned short nBtldrDataSize; //代ç å¤§å° |
| | | unsigned int nBtldr_AppAddr; |
| | | unsigned int nBtldr_NewAppInfoAddr; |
| | | unsigned int nBtldr_NewAppAddr; |
| | | stInfoBlockTail tail; |
| | | }stBtLdrInfoBlock; |
| | | // /* |
| | | typedef struct { |
| | | uint32_t addr_Code_RO_Data_limit; |
| | | |
| | | }addr_data_def; |
| | | // */ |
| | | extern int Region$$Table$$Base; |
| | | addr_data_def const * paddr = (addr_data_def *)&Region$$Table$$Base; |
| | | |
| | | const stBtLdrInfoBlock theBtldrInfoBlock __attribute__((at(0x08000100))) = { |
| | | 0xAA55, // StartSign |
| | | 0x0101, // BlockType |
| | | sizeof(stBtLdrInfoBlock), //BlockSize |
| | | 0, // Pad, |
| | | 0x0100, //BtLdrVer |
| | | 0x0100, //BtLdrDevice; |
| | | 0x1000, //BtLdrSize; |
| | | 0x0C00, //BtLdrDataSize; |
| | | 0x08001000, //nBtldr_AppAddr |
| | | (int)&Region$$Table$$Base, //nBtldr_NewAppInfoAddr |
| | | 0x08009000, //nBtldr_NewAppAddr |
| | | 0xEEEE, //crc16; |
| | | 0xAA55 //EndSign; |
| | | }; |
| | | |
| | | // const int END_SIGN __attribute__((at(0x08000FD8))); // = 0x55aa; |
| | | |
| | | uint32_t us1,us2,us3,us4,us5,us6; |
| | | |
| | |
| | | /* USER CODE BEGIN 0 */ |
| | | |
| | | /* 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, |
| | | 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, |
| | |
| | | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, |
| | | 0x40 |
| | | }; |
| | | */ |
| | | /* Table of CRC values for low-order byte */ |
| | | /* |
| | | const uint8_t crctablelo[] = { |
| | | 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, |
| | | 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, |
| | |
| | | 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); |
| | | } |
| | | */ |
| | | |
| | | void HAL_SYSTICK_Callback(void) |
| | | { |
| | |
| | | } |
| | | |
| | | #define ApplicationAddress 0x08001000 //åºç¨ç¨åºé¦å°åå®ä¹ |
| | | #define NewAppInfoBlockAddress 0x08008000 // åå¨çæ°åºç¨ç¨åºä¿¡æ¯åçå°å |
| | | #define NewAppAddress 0x08009000 // åå¨çæ°åºç¨ç¨åºçå°å |
| | | #define NEW_APP_INFOBLOCK_ADDR 0x08008000 // åå¨çæ°åºç¨ç¨åºä¿¡æ¯åçå°å |
| | | #define NEW_APP_ADDR 0x08009000 // åå¨çæ°åºç¨ç¨åºçå°å |
| | | |
| | | typedef struct tagNewAppInfoBlock |
| | | { |
| | |
| | | |
| | | int EraseFlashMem(void * pAddrFlash, unsigned int Pages) |
| | | { |
| | | HAL_StatusTypeDef res; |
| | | res = HAL_FLASH_Unlock(); |
| | | uint32_t ErrNo; |
| | | FLASH_EraseInitTypeDef erase1; |
| | | erase1.NbPages=Pages; |
| | | erase1.PageAddress=(unsigned int)pAddrFlash; |
| | | erase1.TypeErase=FLASH_TYPEERASE_PAGES; |
| | | res = HAL_FLASHEx_Erase(&erase1,&ErrNo); |
| | | res = HAL_FLASH_Lock(); |
| | | ErrorStatus res; |
| | | res = LL_Flash_Unlock(); |
| | | // uint32_t ErrNo; |
| | | res = LL_Flash_PageErase(pAddrFlash,Pages); |
| | | LL_FLASH_Lock(FLASH); |
| | | return res; |
| | | } |
| | | |
| | | int EraseAndWriteToFlashMem(void * pBuf, void * pAddrFlash, unsigned int nByteSize) |
| | | { |
| | | |
| | | HAL_StatusTypeDef res; |
| | | res = HAL_FLASH_Unlock(); |
| | | uint32_t ErrNo; |
| | | FLASH_EraseInitTypeDef erase1; |
| | | erase1.NbPages= (nByteSize-1) / FLASH_PAGE_SIZE + 1; |
| | | erase1.PageAddress=(unsigned int)pAddrFlash; |
| | | erase1.TypeErase=FLASH_TYPEERASE_PAGES; |
| | | res = HAL_FLASHEx_Erase(&erase1,&ErrNo); |
| | | |
| | | |
| | | ErrorStatus res; |
| | | res = LL_Flash_Unlock(); |
| | | // __disable_irq(); |
| | | int NbPages = (nByteSize-1) / FLASH_PAGE_SIZE + 1; |
| | | res = LL_Flash_PageErase(pAddrFlash,NbPages); |
| | | for (int i=0;i<(nByteSize+1)/2;i++) |
| | | { |
| | | res = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, (uint32_t)pAddrFlash + i*2, ((uint16_t *)pBuf)[i]); |
| | | if ((i&0x7ff) == 0) {ToggleRunLed(); ToggleErrLed();} |
| | | unsigned short value = ((uint8_t *)pBuf)[i*2] + (((uint8_t *)pBuf)[i*2 +1] << 8); |
| | | res = LL_FLASH_Program(ProgaraType_DATA16, (uint32_t)pAddrFlash + i*2, value); |
| | | if (res == ERROR) break; |
| | | } |
| | | |
| | | res = HAL_FLASH_Lock(); |
| | | // __enable_irq(); |
| | | LL_FLASH_Lock(FLASH); |
| | | if (res == ERROR) return 1; |
| | | |
| | | return res; |
| | | } |
| | |
| | | SetErrLed(0); //Turn Off Err Led |
| | | // check for app update |
| | | ///* |
| | | int FlashSize = *(unsigned short *)FLASHSIZE_BASE; |
| | | int NewAppAddress ; |
| | | int NewAppInfoBlockAddress ; |
| | | if (FlashSize == 64) { |
| | | NewAppInfoBlockAddress = 0x08008000; |
| | | NewAppAddress = 0x08009000U; |
| | | }else if (FlashSize == 256) { |
| | | NewAppInfoBlockAddress = 0x08020000; |
| | | NewAppAddress = 0x08021000U; |
| | | } |
| | | |
| | | pNewAppInfoBlock ptheNewAppInfoBlock = (pNewAppInfoBlock) NewAppInfoBlockAddress; |
| | | if (ptheNewAppInfoBlock->Sign == 0x55AA) |
| | | { |
| | | //check length and CRC; |
| | | int length = ptheNewAppInfoBlock->Length; |
| | | int nCRC = crc16table((uint8_t *)NewAppAddress,length); |
| | | int nCRC; // = crc16table((uint8_t *)NewAppAddress,length); |
| | | nCRC = crc16bitbybit((uint8_t *)NewAppAddress,length); |
| | | if (nCRC == ptheNewAppInfoBlock->nCRC) |
| | | { |
| | | // copy program |
| | |
| | | LL_mDelay(100); |
| | | |
| | | // ToggleRunLed(); |
| | | // ToggleErrLed(); |
| | | ToggleErrLed(); |
| | | ToggleErr2Led(); |
| | | |
| | | // LL_IWDG_ReloadCounter(IWDG); |
| | |
| | | #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ |
| | | #endif |
| | | |
| | | |
| | | // #define ENABLE_PLC 0 |
| | | |
| | | #define GetBoardType() (BOARD_TYPE) |
| | | |
| | |
| | | |
| | | #include "KBusDefine.h" |
| | | |
| | | #include "KMachine.h" |
| | | //#include "KBus.h" |
| | | |
| | | |
| | | const stKMInfoBlock KMInfoBlock = |
| | | { |
| | | // sizeof(stKMInfoBlock), |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceType BOARD_VER, //nDevieVer |
| | | 0x0109, //ProgVer |
| | | 0x0102, //KLinkVer |
| | | KBUS_VER, //KBusVer |
| | | // 0x0100, //KNetVer |
| | | // 0x0100, //KWLVer |
| | | |
| | | 4, //nCapacity1 ?K |
| | | 1, //nCapacity2 ?k |
| | | |
| | | DINPUT, //nDInput; |
| | | DOUTPUT, //nDOutput |
| | | |
| | | 0, //nAInput |
| | | 0, //nAOutput |
| | | 0, //nHInput |
| | | 0, //nHOutput |
| | | 0, //nExt1; |
| | | 0, //nExt2; |
| | | 0, //nLogSize; |
| | | 0, //nPorts; |
| | | 0, //nManSize; |
| | | 0, //nAbility; |
| | | 6, //nSwitchBits; |
| | | }; |
| | | |
| | | |
| | | |
| | | const stDeviceInfo MyDeviceInfo={ |
| | | |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | |
| | | unsigned char FastFlicker=0; |
| | | |
| | | unsigned int Uart1IdelTimer = 0; |
| | | #if (ENABLE_PLC) |
| | | stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; |
| | | |
| | | #endif |
| | | uint32_t us1,us2,us3,us4,us5,us6; |
| | | |
| | | stKBusDef KBus1; |
| | |
| | | KMRunStat.WorkMode2=0; |
| | | |
| | | KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode == 1){ |
| | | InitPLC(); |
| | | KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ; |
| | | if (KMRunStat.WorkMode2) { |
| | | StartPLC(); } |
| | | } |
| | | |
| | | #endif |
| | | |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
| | | KWireLessStart(); |
| | |
| | | int haltick=HAL_GetTick(); |
| | | |
| | | int thisJumperSW=ReadJumperSW(); |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode&1){ |
| | | if (thisJumperSW&0x20 && !(KMem.CurJumperSW&0x20)) // Run å¼å
³ æ£ è·³åã |
| | | {StartPLC();} |
| | | if (!(thisJumperSW&0x20) && (KMem.CurJumperSW&0x20)) // Run å¼å
³ è´ è·³åã |
| | | {StopPLC();} |
| | | } |
| | | |
| | | #endif |
| | | KMem.CurJumperSW=thisJumperSW; |
| | | KMem.haltick=haltick; |
| | | // KMem.TotalRunTime=TotalRunTime; |
| | |
| | | #endif |
| | | |
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
| | | { |
| | | if (KMRunStat.nBinProgBank == 0){ |
| | |
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1); |
| | | } |
| | | |
| | | #endif |
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime; |
| | | KMem.LastScanTime = us2; |
| | | if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;} |
| | |
| | | } |
| | | else |
| | | { |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode==1 ) { |
| | | if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
| | | else {SetRunLed(0);} |
| | | } |
| | | else { |
| | | else |
| | | #endif |
| | | { |
| | | if (!KBus1.RunStat) SetRunLed(SlowFlicker); |
| | | else SetRunLed(FastFlicker); |
| | | } |
| | |
| | | <FileType>1</FileType> |
| | | <FilePath>..\..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_rtc.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_flash.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_flash.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | | </Groups> |
| | |
| | | #include "Functions.h" |
| | | #include "string.h" |
| | | #include "BSP.h" |
| | | #include "stm32f0xx_ll_flash.h" |
| | | |
| | | /* USER CODE END Includes */ |
| | | |
| | |
| | | } |
| | | |
| | | #define ApplicationAddress 0x08001000 //åºç¨ç¨åºé¦å°åå®ä¹ |
| | | #define NewAppInfoBlockAddress 0x08020000 // åå¨çæ°åºç¨ç¨åºä¿¡æ¯åçå°å |
| | | #define NewAppAddress 0x08021000 // åå¨çæ°åºç¨ç¨åºçå°å |
| | | #define NEW_APP_INFOBLOCK_ADDR 0x08020000 // åå¨çæ°åºç¨ç¨åºä¿¡æ¯åçå°å |
| | | #define NEW_APP_ADDR 0x08021000 // åå¨çæ°åºç¨ç¨åºçå°å |
| | | //#define FLASH_PAGESIZE (0x00000400) //Page Size = 1K |
| | | |
| | | |
| | |
| | | |
| | | int EraseFlashMem(void * pAddrFlash, unsigned int Pages) |
| | | { |
| | | HAL_StatusTypeDef res; |
| | | res = HAL_FLASH_Unlock(); |
| | | uint32_t ErrNo; |
| | | FLASH_EraseInitTypeDef erase1; |
| | | erase1.NbPages=Pages; |
| | | erase1.PageAddress=(unsigned int)pAddrFlash; |
| | | erase1.TypeErase=FLASH_TYPEERASE_PAGES; |
| | | res = HAL_FLASHEx_Erase(&erase1,&ErrNo); |
| | | res = HAL_FLASH_Lock(); |
| | | ErrorStatus res; |
| | | res = LL_Flash_Unlock(); |
| | | // uint32_t ErrNo; |
| | | res = LL_Flash_PageErase(pAddrFlash,Pages); |
| | | LL_FLASH_Lock(FLASH); |
| | | return res; |
| | | } |
| | | |
| | | int EraseAndWriteToFlashMem(void * pBuf, void * pAddrFlash, unsigned int nByteSize) |
| | | { |
| | | |
| | | HAL_StatusTypeDef res; |
| | | res = HAL_FLASH_Unlock(); |
| | | uint32_t ErrNo; |
| | | FLASH_EraseInitTypeDef erase1; |
| | | erase1.NbPages= (nByteSize-1) / FLASH_PAGE_SIZE + 1; |
| | | erase1.PageAddress=(unsigned int)pAddrFlash; |
| | | erase1.TypeErase=FLASH_TYPEERASE_PAGES; |
| | | res = HAL_FLASHEx_Erase(&erase1,&ErrNo); |
| | | |
| | | |
| | | ErrorStatus res; |
| | | res = LL_Flash_Unlock(); |
| | | // __disable_irq(); |
| | | int NbPages = (nByteSize-1) / FLASH_PAGE_SIZE + 1; |
| | | // FLASH_EraseInitTypeDef erase1; |
| | | // erase1.NbPages=(nByteSize-1) / FLASH_PAGE_SIZE + 1;; |
| | | // erase1.PageAddress=(unsigned int)pAddrFlash; |
| | | // erase1.TypeErase=FLASH_TYPEERASE_PAGES; |
| | | res = LL_Flash_PageErase(pAddrFlash,NbPages); |
| | | for (int i=0;i<(nByteSize+1)/2;i++) |
| | | { |
| | | res = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, (uint32_t)pAddrFlash + i*2, ((uint16_t *)pBuf)[i]); |
| | | if ((i&0x7ff) == 0) {ToggleRunLed(); ToggleErrLed();} |
| | | unsigned short value = ((uint8_t *)pBuf)[i*2] + (((uint8_t *)pBuf)[i*2 +1] << 8); |
| | | res = LL_FLASH_Program(ProgaraType_DATA16, (uint32_t)pAddrFlash + i*2, value); |
| | | if (res == ERROR) break; |
| | | } |
| | | |
| | | res = HAL_FLASH_Lock(); |
| | | // __enable_irq(); |
| | | LL_FLASH_Lock(FLASH); |
| | | |
| | | return res; |
| | | } |
| | |
| | | SetErrLed(0); //Turn Off Err Led |
| | | // check for app update |
| | | ///* |
| | | int FlashSize = *(unsigned short *)FLASHSIZE_BASE; |
| | | int NewAppAddress ; |
| | | int NewAppInfoBlockAddress ; |
| | | if (FlashSize == 64) { |
| | | NewAppInfoBlockAddress = 0x08008000; |
| | | NewAppAddress = 0x08009000U; |
| | | }else if (FlashSize == 256) { |
| | | NewAppInfoBlockAddress = 0x08020000; |
| | | NewAppAddress = 0x08021000U; |
| | | } |
| | | |
| | | pNewAppInfoBlock ptheNewAppInfoBlock = (pNewAppInfoBlock) NewAppInfoBlockAddress; |
| | | if (ptheNewAppInfoBlock->Sign == 0x55AA) |
| | | { |
| | | //check length and CRC; |
| | | int length = ptheNewAppInfoBlock->Length; |
| | | int nCRC = crc16table((uint8_t *)NewAppAddress,length); |
| | | int nCRC; // = crc16table((uint8_t *)NewAppAddress,length); |
| | | nCRC = crc16bitbybit((uint8_t *)NewAppAddress,length); |
| | | if (nCRC == ptheNewAppInfoBlock->nCRC) |
| | | { |
| | | // copy program |
| | |
| | | #endif |
| | | |
| | | |
| | | typedef struct tagInfoBlockHdr { |
| | | unsigned short nBlkSign; // å¼å§æ å¿ |
| | | unsigned short nBlkTypeVer; // ç±»ååçæ¬ |
| | | unsigned short nBlkSize; // Block 大å°, å
æ¬å¼å§åç»ææ å¿ |
| | | unsigned short Pad1; |
| | | }stInfoBlockHdr; |
| | | |
| | | typedef struct tagInfoBlockTail { |
| | | |
| | | unsigned short CRC16; |
| | | unsigned short EndSign; |
| | | }stInfoBlockTail; |
| | | |
| | | typedef struct tagBtLdrInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nBtldrVer; |
| | | unsigned short nBtldrDevice; |
| | | unsigned short nBtldrSize; // è®¾è®¡å¤§å° |
| | | unsigned short nBtldrDataSize; //代ç å¤§å° |
| | | unsigned int nBtldr_AppAddr; |
| | | unsigned int nBtldr_NewAppInfoAddr; |
| | | unsigned int nBtldr_NewAppAddr; |
| | | stInfoBlockTail tail; |
| | | }stBtLdrInfoBlock, *pBtLdrInfoBlock; |
| | | |
| | | typedef struct tagAppInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nAppVer; |
| | | unsigned short nAppDevice; |
| | | unsigned short nAppSize; // 代ç è®¾è®¡å¤§å° |
| | | unsigned short nAppDataSize; //å®é
代ç å¤§å° |
| | | unsigned int nAppStartAddr; |
| | | unsigned int nAppStartOffset; |
| | | unsigned int nApp; |
| | | stInfoBlockTail tail; |
| | | }stAppInfoBlock, * pAppInfoBlock; |
| | | |
| | | |
| | | |
| | | #endif /* __BOARDTYPE_H__ */ |
| | |
| | | |
| | | |
| | | #ifndef __SLP_H_V10__ |
| | | #define __SLP_H_V10__ |
| | | typedef unsigned char uchar; |
| | |
| | | // uchar ED; |
| | | }stSLPPacket; |
| | | |
| | | extern uchar bSLPMaster; |
| | | extern uchar nStation; |
| | | extern uchar SLPinputB; |
| | | extern uchar SLPoutputB; |
| | | extern uchar SLPErrSign; |
| | | //extern uchar bSLPMaster; |
| | | //extern uchar nStation; |
| | | //extern uchar SLPinputB; |
| | | //extern uchar SLPoutputB; |
| | | //extern uchar SLPErrSign; |
| | | |
| | | void SLPparsePacket(void * pBuf, uchar len1); |
| | | void SLPMasterSendPacket(void); |
| | | void SLPProcess(void); |
| | | typedef void (*SLPSendPktDef)(unsigned char * pBuf, int Len1); |
| | | |
| | | |
| | | typedef struct tagSLPDef |
| | | { |
| | | uchar bSLPMaster; |
| | | uchar nStation; |
| | | uchar SLPinputB; |
| | | uchar SLPoutputB; |
| | | uchar nCurStation; |
| | | uchar inputBuf[5]; |
| | | uchar outputBuf[5]; |
| | | |
| | | uchar SendBuf[8]; |
| | | |
| | | uchar SLPMasterRecved; //主æºæ¶å°åæºåå¤ |
| | | |
| | | SLPSendPktDef SLPSendPktFunc; |
| | | |
| | | unsigned int SLPSlaveCountOut; |
| | | |
| | | unsigned int SLPLostPkt; // 丢å
æ°é |
| | | |
| | | uchar SLPOKSign; |
| | | uchar SLPErrSign; |
| | | |
| | | int nCount; |
| | | |
| | | }stSLPDef; |
| | | |
| | | void SLPInit(stSLPDef * pSLP, SLPSendPktDef pFunc1); |
| | | void SLPSetCallBack(stSLPDef * pSLP, SLPSendPktDef pFunc1); |
| | | |
| | | void SLPparsePacket(stSLPDef * pSLP, unsigned char * pBuf, uchar len1); |
| | | void SLPMasterSendPacket(stSLPDef * pSLP); |
| | | void SLPProcess(stSLPDef * pSLP); |
| | | |
| | | |
| | | #endif /* __SLP_H_V10__ */ |
| | | |
| | |
| | | void SLPSendPacket(void * str, uchar len); |
| | | |
| | | int PutStr(char * str1, int len1); |
| | | int PutStr2(char * str1, int len1); |
| | | int SendPacket(int nChn, void * pBuf,int len1); |
| | | //int SendPacket1(void * pBuf,int len1); |
| | | //int SendPacket2(pKBPacket p1,int len1); |
| | |
| | | /* #define USE_FULL_ASSERT 1U */ |
| | | |
| | | /* USER CODE BEGIN Private defines */ |
| | | #include "KBus.h" |
| | | |
| | | extern stKBusDef KBus1; |
| | | /* USER CODE END Private defines */ |
| | | |
| | | #ifdef __cplusplus |
| | |
| | | <FilePath>..\Inc\BoardType.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>FP0.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\Inc\FP0.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>main.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\Inc\main.h</FilePath> |
| | |
| | | <Group> |
| | | <GroupName>Application/User</GroupName> |
| | | <Files> |
| | | <File> |
| | | <FileName>FP0.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Src\FP0.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>functions.c</FileName> |
| | | <FileType>1</FileType> |
| | |
| | | #include "BoardType.h" |
| | | #include "KMachine.h" |
| | | #include "KBus.h" |
| | | |
| | | #define APP_ADDR 0x08001000 //åºç¨ç¨åºé¦å°åå®ä¹ |
| | | #define APPINFOBLOCK_ADDR (APP_ADDR + 0x100) //ç¨åºä¿¡æ¯å å°å |
| | | #define INFOBLOCK_ADDR (APP_ADDR + 0x1000) //ä¿¡æ¯å å°å |
| | | |
| | | |
| | | #define APP_START_ADDR IROM1_START_ADDRESS |
| | | extern int Region$$Table$$Limit; |
| | | |
| | | const stAppInfoBlock AppInfoBlock __attribute__((at(APPINFOBLOCK_ADDR))) = |
| | | { |
| | | 0xAA55, // StartSign |
| | | 0x0301, // BlockType |
| | | sizeof(stAppInfoBlock), //BlockSize |
| | | 0, // Pad, |
| | | 0x0109, //AppVer |
| | | (BOARD_TYPE<<8) + BOARD_VER, //AppDevice; |
| | | 0x1000, //AppSize; |
| | | 0x0C00, //AppDataSize; |
| | | APP_ADDR, //nAppStartAddr |
| | | (int)&Region$$Table$$Limit, //nBtldr_NewAppInfoAddr |
| | | 0x08009000, //nBtldr_NewAppAddr |
| | | 0xCCCC, //crc16; |
| | | 0xAA55 //EndSign; |
| | | |
| | | }; |
| | | |
| | | |
| | | |
| | | const stKMInfoBlock KMInfoBlock __attribute__((at(INFOBLOCK_ADDR))) = |
| | | { |
| | | // sizeof(stKMInfoBlock), |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceType BOARD_VER, //nDevieVer |
| | | 0x0109, //ProgVer |
| | | 0x0102, //KLinkVer |
| | | KBUS_VER, //KBusVer |
| | | // 0x0100, //KNetVer |
| | | // 0x0100, //KWLVer |
| | | |
| | | 4, //nCapacity1 ?K |
| | | 1, //nCapacity2 ?k |
| | | |
| | | DINPUT, //nDInput; |
| | | DOUTPUT, //nDOutput |
| | | |
| | | 0, //nAInput |
| | | 0, //nAOutput |
| | | 0, //nHInput |
| | | 0, //nHOutput |
| | | 0, //nExt1; |
| | | 0, //nExt2; |
| | | 0, //nLogSize; |
| | | 0, //nPorts; |
| | | 0, //nManSize; |
| | | 0, //nAbility; |
| | | 6, //nSwitchBits; |
| | | }; |
| | | |
| | | const stDeviceInfo MyDeviceInfo={ |
| | | |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | 0x0109, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | }; |
| | | |
| | | const stExDeviceInfo MyExDeviceInfo ={ |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | 0x0109, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | |
| | | }; |
| | | |
| | | |
| | |
| | | |
| | | #include "SLP.h" |
| | | |
| | | void SLPSendPacket(void * buf, uchar len1); |
| | | uchar bSLPMaster; |
| | | uchar nStation; |
| | | uchar SLPinputB; |
| | | uchar SLPoutputB; |
| | | uchar nCurStation; |
| | | uchar inputBuf[5]; |
| | | uchar outputBuf[5]; |
| | | //void SLPSendPacket(char * buf, uchar len1); |
| | | |
| | | uchar SendBuf[8]; |
| | | |
| | | uchar SLPMasterRecved; //主æºæ¶å°åæºåå¤ |
| | | unsigned int SLPSlaveCountOut; |
| | | |
| | | unsigned int SLPLostPkt=0; // 丢å
æ°é |
| | | |
| | | uchar SLPOKSign; |
| | | uchar SLPErrSign; |
| | | |
| | | uchar SLPBCC(uchar * pBuf, uchar len1) |
| | | uchar SLPBCC(unsigned char * pBuf, uchar len1) |
| | | { |
| | | uchar i; |
| | | uchar BCC=0; |
| | |
| | | return BCC; |
| | | } |
| | | |
| | | void SLPparsePacket(void * pRecvBuf, uchar len1) |
| | | void SLPInit(stSLPDef * pSLP, SLPSendPktDef pFunc1) |
| | | { |
| | | pSLP->SLPLostPkt = 0; |
| | | pSLP->nCount = 0; |
| | | pSLP->SLPSendPktFunc = pFunc1; |
| | | |
| | | } |
| | | |
| | | void SLPSetCallBack(stSLPDef * pSLP, SLPSendPktDef pFunc1) |
| | | { |
| | | pSLP->SLPSendPktFunc = pFunc1; |
| | | } |
| | | |
| | | void SLPparsePacket(stSLPDef * pSLP, unsigned char * pRecvBuf, uchar len1) |
| | | { |
| | | |
| | | stSLPPacket * pPacket = (stSLPPacket *)pRecvBuf; |
| | | if (len1 != sizeof(stSLPPacket)) return; |
| | | // if (pPacket->ED != EDsign) return; |
| | | if (pPacket->BCC != SLPBCC(pRecvBuf,len1-1)) return; |
| | | if (bSLPMaster) //master |
| | | if (pSLP->bSLPMaster) //master |
| | | { |
| | | if (pPacket->ST ==ST_S) |
| | | { |
| | | //check |
| | | if (pPacket->Dst == nCurStation) { |
| | | SLPMasterRecved=1; |
| | | SLPLostPkt=0; |
| | | inputBuf[nCurStation] = pPacket->Data; |
| | | if (pPacket->Dst == pSLP->nCurStation) { |
| | | pSLP->SLPMasterRecved=1; |
| | | pSLP->SLPLostPkt=0; |
| | | pSLP->inputBuf[pSLP->nCurStation] = pPacket->Data; |
| | | } |
| | | } |
| | | // SLPoutputB = (inputBuf[1] &0x0f) | ((inputBuf[2] &0x0f) << 4); |
| | | SLPoutputB = inputBuf[1]; |
| | | pSLP->SLPoutputB = pSLP->inputBuf[1]; |
| | | }else |
| | | { //slave |
| | | if (pPacket->ST==ST_M) |
| | | { |
| | | //check |
| | | stSLPPacket * pRplyPkt = (stSLPPacket *)SendBuf; |
| | | if (pPacket->Dst == nStation) { |
| | | SLPoutputB = pPacket->Data; |
| | | SLPSlaveCountOut=0; |
| | | stSLPPacket * pRplyPkt = (stSLPPacket *)pSLP->SendBuf; |
| | | if (pPacket->Dst == pSLP->nStation) { |
| | | pSLP->SLPoutputB = pPacket->Data; |
| | | pSLP->SLPSlaveCountOut=0; |
| | | |
| | | pRplyPkt->ST = ST_S; |
| | | pRplyPkt->Dst = nStation; |
| | | pRplyPkt->Data = SLPinputB; |
| | | pRplyPkt->BCC = SLPBCC(SendBuf, sizeof(stSLPPacket)-1); |
| | | pRplyPkt->Dst = pSLP->nStation; |
| | | pRplyPkt->Data = pSLP->SLPinputB; |
| | | pRplyPkt->BCC = SLPBCC(pSLP->SendBuf, sizeof(stSLPPacket)-1); |
| | | // pRplyPkt->ED = EDsign; |
| | | |
| | | SLPSendPacket(SendBuf,sizeof(stSLPPacket)); |
| | | pSLP->SLPSendPktFunc(pSLP->SendBuf,sizeof(stSLPPacket)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | void SLPMasterSendPacket(void) |
| | | void SLPMasterSendPacket(stSLPDef * pSLP) |
| | | { |
| | | |
| | | stSLPPacket * pReqPkt = (stSLPPacket *)SendBuf; |
| | | outputBuf[1]=SLPinputB ;//&0xf; |
| | | stSLPPacket * pReqPkt = (stSLPPacket *)pSLP->SendBuf; |
| | | pSLP->outputBuf[1]=pSLP->SLPinputB ;//&0xf; |
| | | // outputBuf[2] = (SLPinputB & 0xf0) >> 4; |
| | | pReqPkt->ST = ST_M; |
| | | pReqPkt->Dst = nCurStation; |
| | | pReqPkt->Data = outputBuf[nCurStation]; ; |
| | | pReqPkt->BCC = SLPBCC(SendBuf, sizeof(stSLPPacket)-1); |
| | | pReqPkt->Dst = pSLP->nCurStation; |
| | | pReqPkt->Data = pSLP->outputBuf[pSLP->nCurStation]; ; |
| | | pReqPkt->BCC = SLPBCC(pSLP->SendBuf, sizeof(stSLPPacket)-1); |
| | | // pReqPkt->ED = EDsign; |
| | | |
| | | SLPSendPacket(SendBuf,sizeof(stSLPPacket)); |
| | | pSLP->SLPSendPktFunc(pSLP->SendBuf,sizeof(stSLPPacket)); |
| | | } |
| | | void SLPProcess(void) |
| | | |
| | | void SLPProcess(stSLPDef * pSLP) |
| | | { |
| | | static int nCount =0; |
| | | if (bSLPMaster) //master |
| | | if (pSLP->bSLPMaster) //master |
| | | { |
| | | if ( (nCount & 0x3f) == 0 ) |
| | | if ( (pSLP->nCount & 0xf) == 0 ) |
| | | { //time up |
| | | if (SLPMasterRecved) { |
| | | if (pSLP->SLPMasterRecved) { |
| | | // SLPMasterRecved=0; |
| | | SLPOKSign = 1; |
| | | if (SLPErrSign) SLPErrSign--; |
| | | pSLP->SLPOKSign = 1; |
| | | if (pSLP->SLPErrSign) pSLP->SLPErrSign--; |
| | | |
| | | }else { |
| | | SLPLostPkt++; |
| | | if (SLPLostPkt > 10) { |
| | | SLPErrSign=20; |
| | | SLPOKSign = 0; |
| | | pSLP->SLPLostPkt++; |
| | | if (pSLP->SLPLostPkt > 10) { |
| | | pSLP->SLPErrSign=20; |
| | | pSLP->SLPOKSign = 0; |
| | | } |
| | | } |
| | | if (nStation >0) { |
| | | nCurStation++; |
| | | if (nCurStation > nStation) { |
| | | nCurStation =1; |
| | | if (pSLP->nStation >0) { |
| | | pSLP->nCurStation++; |
| | | if (pSLP->nCurStation > pSLP->nStation) { |
| | | pSLP->nCurStation =1; |
| | | } |
| | | SLPMasterRecved=0; |
| | | SLPMasterSendPacket(); |
| | | pSLP->SLPMasterRecved=0; |
| | | SLPMasterSendPacket(pSLP); |
| | | } |
| | | } |
| | | }else |
| | | { |
| | | SLPSlaveCountOut ++; |
| | | if (SLPSlaveCountOut >200) // 20mS |
| | | pSLP->SLPSlaveCountOut ++; |
| | | if (pSLP->SLPSlaveCountOut >200) // 20mS |
| | | { |
| | | SLPErrSign=100; |
| | | pSLP->SLPErrSign=100; |
| | | }else { |
| | | if (SLPErrSign) SLPErrSign--; |
| | | if (pSLP->SLPErrSign) pSLP->SLPErrSign--; |
| | | } |
| | | } |
| | | nCount++; |
| | | pSLP->nCount++; |
| | | } |
| | |
| | | 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() |
| | | { |
| | |
| | | unsigned char FastFlicker=0; |
| | | |
| | | unsigned int Uart1IdelTimer = 0; |
| | | #if (ENABLE_PLC) |
| | | stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; |
| | | #endif |
| | | |
| | | uint32_t us1,us2,us3,us4,us5,us6; |
| | | |
| | | stKBusDef KBus1; // |
| | | |
| | | extern stDeviceInfo MyDeviceInfo; |
| | | |
| | | unsigned char bSLPMaster =1; |
| | | unsigned char nSLPStation = 1; |
| | | |
| | | stSLPDef SLP1; |
| | | /* USER CODE END PV */ |
| | | |
| | | /* Private function prototypes -----------------------------------------------*/ |
| | |
| | | static int Count=0; |
| | | CurTickuS += 100; |
| | | nCurTick++; |
| | | nSlaveTick++; |
| | | KBus1.nSlaveTick++; |
| | | Count++; |
| | | if (Count>=10000) |
| | | { |
| | |
| | | return; |
| | | } |
| | | |
| | | void * KBusCallBackFunc(int nChn, int nEvent, void *pBuf, int nLen1) |
| | | void PendSvCallBack() |
| | | { |
| | | #if (BOARD_TYPE == 14) |
| | | ///* |
| | | if (bSPI1RecvDone) |
| | | { |
| | | bSPI1RecvDone=0; |
| | | FPxParsePkt(SPI1RecvBuf,nSPI1RecvLenInBuf); |
| | | } |
| | | //*/ |
| | | #endif |
| | | if (Uart2Stat.bPacketRecved) |
| | | { |
| | | KBusParsePacket(&KBus1, (pKBPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); |
| | | Uart2RecvBuf1DataLen=0; |
| | | Uart2Stat.bPacketRecved=0; |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | } |
| | | } |
| | | |
| | | void * KBusEvCallBackFunc(void * pParam, int nEvent, void *pBuf, int nLen1) |
| | | { |
| | | switch (nEvent){ |
| | | |
| | |
| | | |
| | | /* Initialize all configured peripherals */ |
| | | MX_GPIO_Init(); |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct; |
| | | 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); |
| | | |
| | | MX_DMA_Init(); |
| | | |
| | | KMachineInit(); |
| | | ReadSysCfgFromFlash(&storedKMSysCfg); |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | int bKBusMaster,bKBusSlave,bKBusRepeater;; |
| | | int nKBusStationId; |
| | | int nKBusChilds; |
| | | KMem.CurJumperSW=ReadJumperSW(); |
| | | KMem.EffJumperSW=KMem.CurJumperSW; |
| | | nKBusStationId=KMem.EffJumperSW&0x0f; |
| | | |
| | | nKBusChilds = nKBusStationId; |
| | | |
| | | bSLPMaster = 1; // KMem.EffJumperSW&0x20 ; //master? |
| | | nStation = 1; |
| | | nSLPStation = 1; |
| | | |
| | | // Uart2Baud = AlterUart2Baud; |
| | | |
| | |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | KMem.EffJumperSW|=0x10; |
| | | nStationID=KMem.EffJumperSW&0x0f; |
| | | int nKBusChilds=KMem.EffJumperSW&0x0f; |
| | | if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | nChilds=nStationID; |
| | | FPx_Init(); |
| | | |
| | | FPxSetCallBackFunc(&FPxCallBackFunc); |
| | | FPx_Init(nKBusChilds); |
| | | |
| | | int IOByteCount = nKBusChilds; |
| | | FPx_SetIOCount(IOByteCount,IOByteCount); |
| | | |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | nStationID=1 ;//KMem.EffJumperSW&0x0f; |
| | |
| | | // else |
| | | {bKBusMaster=0;bKBusSlave=1;} |
| | | #else |
| | | nStationID=KMem.EffJumperSW&0x0f; |
| | | if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | nKBusStationId=KMem.EffJumperSW&0x0f; |
| | | if (KMem.EffJumperSW == 0x3f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | else if ((KMem.EffJumperSW&0x20)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | #endif |
| | | |
| | | KBusInit(2, bKBusMaster, nChilds); |
| | | KBusSetCallBackFunc(2, &KBusCallBackFunc), |
| | | if (bKBusMaster) { |
| | | KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds); |
| | | |
| | | nChilds=nStationID; |
| | | nCurPollId=1; |
| | | } else if (bKBusSlave) { |
| | | KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationId,&MyDeviceInfo); |
| | | } |
| | | |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc); |
| | | |
| | | //if (KMem.EffJumperSW == 0x00) |
| | | Uart1Baud = DefaultUart1Baud; |
| | | MX_USART1_UART_Init(); |
| | |
| | | KMRunStat.WorkMode2=0; |
| | | |
| | | KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode == 1){ |
| | | InitPLC(); |
| | | KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ; |
| | | if (KMRunStat.WorkMode2) { |
| | | StartPLC(); } |
| | | } |
| | | KMem.WX[7]=0x5a; |
| | | #endif |
| | | |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
| | | KWireLessStart(); |
| | |
| | | int haltick=HAL_GetTick(); |
| | | |
| | | int thisJumperSW=ReadJumperSW(); |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode&1){ |
| | | if (thisJumperSW&0x20 && !(KMem.CurJumperSW&0x20)) // Run å¼å
³ æ£ è·³åã |
| | | {StartPLC();} |
| | | if (!(thisJumperSW&0x20) && (KMem.CurJumperSW&0x20)) // Run å¼å
³ è´ è·³åã |
| | | {StopPLC();} |
| | | } |
| | | |
| | | #endif |
| | | KMem.CurJumperSW=thisJumperSW; |
| | | KMem.haltick=haltick; |
| | | // KMem.TotalRunTime=TotalRunTime; |
| | |
| | | // */ |
| | | |
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
| | | { |
| | | if (KMRunStat.nBinProgBank == 0){ |
| | |
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1); |
| | | } |
| | | |
| | | #endif |
| | | |
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime; |
| | | KMem.LastScanTime = us2; |
| | | if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;} |
| | |
| | | |
| | | if (bKBusMaster) |
| | | { |
| | | |
| | | if (nChilds>0) { KBusMasterFunc(2); } |
| | | |
| | | KBusLoopProcess(&KBus1); |
| | | } |
| | | if (haltick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | |
| | | if (bKBusSlave) |
| | | { |
| | | |
| | | KBusSlaveFunc(2); |
| | | if (! KMem.RunStat) {KBusMem.WLY[0]=0;} |
| | | KBusLoopProcess(&KBus1); |
| | | // if (! KBus1.RunStat) {KBusMem.WLY[0]=0;} |
| | | KMem.WLY[0]=KBusMem.WLY[0]; |
| | | |
| | | if (nSlaveTick&0x00002000) SlowFlicker=1; |
| | | if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | | if (nSlaveTick&0x00000800) FastFlicker=1; |
| | | if (KBus1.nSlaveTick&0x00000800) FastFlicker=1; |
| | | else FastFlicker=0; |
| | | |
| | | } |
| | |
| | | KBusMem.WLX[2]=KMem.WX[2]; |
| | | KBusMem.WLX[3]=KMem.WX[3]; |
| | | |
| | | // KMem.WY[0]=nCount2>>5; |
| | | if (KMem.RunStat) {KMem.RunStat--;} |
| | | if (KMem.ErrStat) {KMem.ErrStat--;} |
| | | |
| | | if (KMRunStat.bLEDFlick) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode==1 ) { |
| | | if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
| | | else {SetRunLed(0);} |
| | | } |
| | | else { |
| | | else |
| | | #endif |
| | | { |
| | | if (!KMem.RunStat) SetRunLed(SlowFlicker); |
| | | else SetRunLed(FastFlicker); |
| | | } |
| | | KMem.ErrStat = KBus1.ErrStat + SLP1.SLPErrSign; |
| | | if (!KMem.ErrStat) |
| | | { |
| | | SetErrLed(0); |
| | |
| | | if (bKBusSlave) HAL_Delay(0); |
| | | |
| | | if (Uart6Stat.bPacketRecved){ |
| | | SLPparsePacket(Uart6RxBuf,Uart6RecvBuf1DataLen); |
| | | SLPparsePacket(&SLP1,Uart6RxBuf,Uart6RecvBuf1DataLen); |
| | | Uart6RecvBuf1DataLen =0; |
| | | Uart6Stat.bPacketRecved = 0; |
| | | } |
| | | |
| | | SLPinputB = KMem.WYB[1]; |
| | | SLPProcess(); |
| | | KMem.WXB[1] = SLPoutputB; |
| | | SLP1.SLPinputB = KMem.WYB[1]; |
| | | SLPProcess(&SLP1); |
| | | KMem.WXB[1] = SLP1.SLPoutputB; |
| | | |
| | | // YDLiDar process; |
| | | |
| | |
| | | // KMem.WX[1]++ ; |
| | | // KMem.WX[2]++; |
| | | |
| | | |
| | | // KMem.WYB[0]=1; |
| | | PutOutput (KMem.WY[0]); |
| | | |
| | | LL_IWDG_ReloadCounter(IWDG); |
| | |
| | | |
| | | extern volatile int PendSvCount; |
| | | |
| | | #pragma anon_unions |
| | | typedef struct tagUartStat |
| | | { |
| | | volatile int SendBytes; |
| | | volatile int RecvBytes; |
| | | volatile char bInited; |
| | | volatile char bSending; |
| | | volatile char bRecving; |
| | | volatile char bUseAltRecvBuf; |
| | | volatile int SentPacket; |
| | | union{ |
| | | volatile unsigned char state; |
| | | struct { |
| | | volatile unsigned char bInited:1; |
| | | volatile unsigned char bSending:1; |
| | | volatile unsigned char bRecving:1; |
| | | volatile unsigned char bUseAltRecvBuf:1; |
| | | |
| | | }; |
| | | }; |
| | | volatile unsigned char bPacketRecved; |
| | | volatile unsigned char bSendDone; |
| | | volatile int IRQCount; |
| | | volatile int RXNECount; |
| | | volatile int TXECount; |
| | |
| | | volatile int OverRunCount; |
| | | volatile int TcCount; //Transmit Complete |
| | | volatile int IdelCount; //RecvIdel |
| | | volatile int LostBytes; |
| | | // volatile int LostBytes; |
| | | volatile int DMACount; |
| | | volatile int DMASendLen; |
| | | volatile int DMARecvLen; |
| | | stMyQueue QRx; |
| | | stMyQueue QTx; |
| | | volatile int SentPacket; |
| | | volatile int bPacketRecved; |
| | | volatile int OKPacket; |
| | | volatile int TimeOutErr; |
| | | volatile int NotPacketErr; |
| | | volatile int LengthErr; |
| | | volatile int BCCerr; |
| | | |
| | | |
| | | // volatile int OKPacket; |
| | | // volatile int TimeOutErr; |
| | | // volatile int NotPacketErr; |
| | | // volatile int LengthErr; |
| | | // volatile int BCCerr; |
| | | }stUartStat; |
| | | |
| | | |
| | | extern stUartStat Uart1Stat; |
| | | extern stUartStat Uart2Stat; |
| | | |
| | | #define Uart1RecvBufSize 256 |
| | | |
| | | extern unsigned int Uart1Baud; |
| | | extern unsigned int Uart2Baud; |
| | | |
| | | extern unsigned char Uart1RecvBuf1[128]; |
| | | extern unsigned char Uart1RecvBuf1[Uart1RecvBufSize]; |
| | | extern int Uart1RecvBuf1DataLen; |
| | | //extern unsigned char Uart1RecvBuf2[128]; |
| | | //extern int Uart1RecvBuf2DataLen; |
| | | |
| | | |
| | | extern unsigned char Uart2RecvBuf1[128]; |
| | | extern int Uart2RecvBuf1DataLen; |
| | | //extern unsigned char Uart2RecvBuf2[128]; |
| | | //extern int Uart2RecvBuf2DataLen; |
| | | |
| | | |
| | | extern volatile int Uart1BaudGot; |
| | | extern volatile int Uart1BaudFirstGot; |
| | |
| | | |
| | | #define MAX_CLIENT 16 //æ大æ¯æåæºæ°é |
| | | |
| | | #define KBUS_WAIT_TIME_OUT1 5 // 0.1mS ticks. |
| | | #define KBUS_WAIT_TIME_OUT2 8 // 0.1mS ticks. |
| | | |
| | | #define KBUS_SLAVE_TIME_OUT 500 // 0.1ms ticks |
| | | |
| | | //#define SYN_PREFIX 1 |
| | | typedef unsigned char uchar; |
| | | typedef volatile unsigned char vuchar; |
| | | typedef unsigned short ushort; |
| | | |
| | | enum enKBusStationType // KBuså·¥ä½ç±»å |
| | | { |
| | | KBNone = 0, // 0,æªå®ä¹ |
| | | KBusMaster = 1, // 1,ä¸»æº |
| | | KBusSlave = 2, // 2,åæº |
| | | KBusRepeater = 3, // 3,转åå¨,ä¸ç»§å¨ |
| | | }; |
| | | |
| | | // diagnosis |
| | | enum enKBusStats |
| | | { |
| | | KBusStatUnInited, // æªåå§åç¶æ |
| | | KBusStatInited, // å·²åå§åç¶æ |
| | | KBusStatConfig, // å·²é
ç½®ç¶æ |
| | | KBusStatReady, // 就绪ç¶æ |
| | | KBusStatRunning, // è¿è¡ç¶æ |
| | | KBusStatIdel, // æåç¶æ |
| | | KBusStatSafe, // å®å
¨ç¶æ |
| | | KBusStatError, // é误ç¶æ |
| | | }; |
| | | /* |
| | | enum enKBusStage |
| | | { |
| | | KBusStageInit, |
| | | KBusStageFindChild, |
| | | KBusStageConfigChild, |
| | | KBusStagePoll, |
| | | |
| | | }; |
| | | */ |
| | | typedef enum |
| | | { |
| | | KBusRunStepBroadCastCfg, |
| | | KBusRunStepTimeSync, |
| | | KBusRunStepTimeSyncWait, |
| | | KBusRunStepMultiDataPoll, |
| | | KBusRunStepMultiDataPollWait, |
| | | KBusRunStepUniDataPoll, |
| | | KBusRunStepUniDataPollWait, |
| | | KBusRunStepUniDataTranster, |
| | | KBusRunStepUniDataTransterWait, |
| | | |
| | | }enKBusRunStep; |
| | | |
| | | enum { |
| | | KB_SYN = 0x55, |
| | | KBStartSign='%', |
| | | KBEndSign=0x0D, |
| | | KBMaxPacketLength=148, |
| | | }; |
| | | |
| | | enum enCMDs |
| | | { |
| | | |
| | | cmdNone = 0x00, //Nothing |
| | | |
| | | cmdQuery = 0x01, //Query basic Info |
| | | cmdQueryRply = 0x81, //Query Info Reply |
| | | |
| | | cmdSetCfg = 0x02, // Set Configuration |
| | | cmdSetCfgRply = 0x82, // Set Configuration Response |
| | | |
| | | cmdToRunMode = 0x03, |
| | | cmdToRunModeRply = 0x83, |
| | | |
| | | cmdBroadCastCfg = 0x04, // |
| | | |
| | | cmdMuExchgData = 0x05, // |
| | | cmdMuExchgDataRply = 0x85, // |
| | | |
| | | cmdToSafeMode = 0x06, |
| | | |
| | | cmdHeartBeat = 0x07, // |
| | | cmdReHeartBeat = 0x87, // |
| | | |
| | | |
| | | cmdRemoteReq = 0x1B, |
| | | cmdRemoteReqReply = cmdRemoteReq|0x80, // |
| | | |
| | | cmdPing = '1', //Ping |
| | | cmdPingReply = '2', //PingReply |
| | | cmdRead = '3', //Read |
| | | cmdReadReply = '4', //ReadReply |
| | | cmdWrite = '5', //Write |
| | | cmdWriteReply = '6', //WriteReply |
| | | cmdGetVersion = '7', //GetVersion |
| | | cmdVerInfo = '8', //VersionReply |
| | | |
| | | cmdUniExChgData='A', //ExChangeData, = Wirte + Read |
| | | cmdExChgDataReply, //ExchangeData Reply |
| | | |
| | | cmdSyncRead='a', //SyncRead |
| | | cmdSyncWrite, //SyncWrite |
| | | cmdSequenRead, //Sequence Read |
| | | cmdSyncTime, //SyncTime |
| | | }; |
| | | |
| | | |
| | | typedef struct tagVerInfo // KBus çæ¬ä¿¡æ¯ |
| | | { |
| | | unsigned char nMainVer; |
| | | unsigned char nSubVer; |
| | | }stVerInfo; |
| | | |
| | | typedef struct tagMasterStat // KBus 主æºç¶æï¼ |
| | | { |
| | | unsigned int CycleTime; |
| | | } stMasterStat; |
| | | |
| | | typedef struct tagDeviceInfo // KBus åæºåºæ¬ä¿¡æ¯ |
| | | { |
| | | unsigned short DeviceType; // åæºç±»å |
| | | unsigned short DeviceVer; // åæºçæ¬ |
| | | unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | unsigned char ExInBitCount; // æ©å±çè¾å
¥å¼å
³éæ°é |
| | | unsigned char ExOutBitCount; // æ©å±çè¾åºå¼å
³éæ°é |
| | | unsigned char DWStartAddr; // è¾åºæ°æ®åæ° |
| | | unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | |
| | | |
| | | }stDeviceInfo; |
| | | |
| | | typedef struct tagExDeviceInfo // åæºæ©å±ä¿¡æ¯ |
| | | { |
| | | unsigned short DeviceType; // åæºç±»å |
| | | unsigned short DeviceVer; // åæºçæ¬ |
| | | |
| | | unsigned char UID[12]; // 12åè UUID |
| | | unsigned char Name[16]; // 16åè å称 |
| | | // stVerInfo ClientVer; |
| | | unsigned char InBitCount; |
| | | unsigned char OutBitCount; |
| | | unsigned char ExInBitCount; // æ©å±çè¾å
¥å¼å
³éæ°é |
| | | unsigned char ExOutBitCount; // æ©å±çè¾åºå¼å
³éæ°é |
| | | unsigned char DWStartAddr; |
| | | unsigned char OutDWCount; |
| | | unsigned char AIWCount; |
| | | unsigned char AQWCount; |
| | | // unsigned char AIBits; |
| | | // unsigned char AQbits; |
| | | |
| | | |
| | | }stExDeviceInfo; |
| | | |
| | | enum enKBusConfigStat |
| | | { |
| | | KBusUnConfiged = 0, |
| | | KBusDefaultConfiged =1, |
| | | KBusConfiged = 2, |
| | | }; |
| | | |
| | | typedef struct tagClientCfg // åæºé
ç½® |
| | | { |
| | | unsigned char Addr; // åæºå°å |
| | | unsigned char Configed; // æ¯å¦å·²é
ç½® |
| | | unsigned char bOnline; //å½åå¨çº¿ç¶æ |
| | | unsigned char InStartAddrBit; //è¾å
¥èµ·å§ä½å°å |
| | | unsigned char OutStartAddrBit; //è¾åºèµ·å§ä½å°å |
| | | unsigned char AIWStartAddrByte; //模æå
¥èµ·å§åå°å |
| | | unsigned char AQWStartAddrByte; //模æåºèµ·å§åå°å |
| | | unsigned char DIWStartAddrByte; //æ°æ®å
¥èµ·å§åå°å |
| | | unsigned char DOWStartAddrByte; //æ°æ®åºèµ·å§åå°å |
| | | unsigned char KeepOut; //Keep Output when comm err; |
| | | }stClientCfg; |
| | | |
| | | /* |
| | | typedef struct ServerStatus |
| | | { |
| | | unsigned char Addr; |
| | | unsigned char Status; |
| | | unsigned short Input[16]; |
| | | unsigned short DT[128]; |
| | | unsigned short output[16]; |
| | | |
| | | }stServerStatus,*pServerStatus; |
| | | */ |
| | | typedef struct tagMachineState // æ¬æºç¶æ |
| | | { |
| | | unsigned char Addr; // å°å |
| | | unsigned char state; //״̬ |
| | | unsigned char InStartAddrBit; //è¾å
¥èµ·å§ä½å°å |
| | | unsigned char OutStartAddrBit; //è¾åºèµ·å§ä½å°å |
| | | unsigned char InDWStartAddrByte; //åè¾å
¥èµ·å§åå°å |
| | | unsigned char OutDWStartAddrByte; //åè¾åºèµ·å§åå°å |
| | | }ClientState; |
| | | |
| | | |
| | | |
| | | #pragma anon_unions |
| | | typedef struct tagChnStat |
| | | { |
| | | union{ |
| | | unsigned char MStat; |
| | | struct{ |
| | | unsigned char bOnline:1; |
| | | unsigned char bErr1:1; |
| | | unsigned char bErr2:1; |
| | | unsigned char bReq:1; |
| | | }; |
| | | }; |
| | | unsigned char SStat; |
| | | unsigned short SendPackets; |
| | | unsigned short RecvPackets; |
| | | unsigned short LastSentTimeTick; |
| | | unsigned short LostPackets; |
| | | unsigned short CtnLstPkts; |
| | | unsigned short MaxCtnLstPkts; |
| | | unsigned short NotPkgErr; |
| | | unsigned short PkgLenErr; |
| | | unsigned short BCCErr; |
| | | unsigned short TimeOutErr; |
| | | unsigned short Delay; |
| | | unsigned short MaxDelay; |
| | | unsigned short SendTimeInterval; |
| | | union |
| | | { |
| | | unsigned short ClientDatas[10]; |
| | | struct { |
| | | unsigned short ClientRecvPkts; // |
| | | unsigned short ClientSendPkts; // |
| | | unsigned short ClientNotPktErr; // |
| | | unsigned short ClientMisIdPkts; // |
| | | // unsigned int ClientNoEndErr; // |
| | | unsigned short ClientPkgLenErr; // |
| | | unsigned short ClientBccErr; // |
| | | unsigned short ClientTimeOutErr; // |
| | | }; |
| | | }; |
| | | } stChnStat; |
| | | |
| | | |
| | | typedef struct tagSlaveStat |
| | | { |
| | | unsigned int nSlaveTick; |
| | | } stSlaveStat; |
| | | |
| | | typedef struct ServerClientListElement |
| | | { |
| | | unsigned char Addr; |
| | | unsigned char Status; |
| | | unsigned char Father; |
| | | unsigned char Childs; |
| | | |
| | | } stServerClientListElement; |
| | | |
| | | typedef struct ServerClientList |
| | | { |
| | | unsigned char Addr; |
| | | }stServerClientList,*pServerClientList; |
| | | |
| | | typedef struct tagMachineConfig |
| | | { |
| | | int bKBusMaster; |
| | | int nAddr; |
| | | }stMachineConfig; |
| | | |
| | | /* |
| | | typedef struct ClientStatus |
| | | { |
| | | unsigned char Addr; |
| | | unsigned char Status; |
| | | unsigned char Father; |
| | | unsigned char Childs; |
| | | unsigned short Input[16]; |
| | | unsigned short DT[128]; |
| | | unsigned short output[16]; |
| | | |
| | | }stChnStatus,*pClientStatus; |
| | | */ |
| | | |
| | | typedef struct tagStatusDef |
| | | { |
| | | unsigned char nSeq:2; //åºåå· |
| | | unsigned char :2; |
| | | unsigned char nErr1:1; |
| | | unsigned char nErr2:1; |
| | | unsigned char bReq:1; |
| | | |
| | | }stStatus; |
| | | |
| | | typedef union tagUnStatusDef |
| | | { |
| | | unsigned char nStatus; |
| | | stStatus; |
| | | }unStatus; |
| | | |
| | | typedef struct tagKBPacket |
| | | { |
| | | unsigned char Sign; //èµ·å§æ è®° |
| | | unsigned char DstHost; //ç®æ å°å |
| | | unsigned char SrcAddr; //æºå°å |
| | | unsigned char nCMD; //å½ä»¤ |
| | | union{ |
| | | unsigned char nStatus; //ç¶æ+åºåå· |
| | | struct{ |
| | | unsigned char nSeq:2; //åºåå· |
| | | unsigned char :2; |
| | | unsigned char nErr1:1; |
| | | unsigned char nErr2:1; |
| | | unsigned char bReq:1; |
| | | }; |
| | | }; |
| | | unsigned char DataLen; //æ°æ®è½½è·é¿åº¦ ä¸å
æ¬å¤´é¨5个åèï¼ä¸å
æ¬å°¾é¨BCCã |
| | | unsigned char data[1]; //æ°æ®è½½è·,ææ«å°¾æ¯BCCï¼æ°æ®é¿åº¦ä¸º0æ¶ï¼å®é
ä¹æä¸ä¸ªæ°æ®ã |
| | | }stKBPacket,* pKBPacket; |
| | | |
| | | typedef struct tagKBInfoBlockV1 |
| | | { |
| | | unsigned short nDeviceType; |
| | | unsigned short nProgVer; |
| | | |
| | | unsigned char InBitCount; |
| | | unsigned char OutBitCount; |
| | | |
| | | unsigned char AICount; |
| | | unsigned char AIBits; |
| | | unsigned char AQCount; |
| | | unsigned char AQbits; |
| | | |
| | | unsigned char InDWCount; |
| | | unsigned char OutDWCount; |
| | | |
| | | }stKBInfoBlockV1, *pKBInfoBlockV1; |
| | | |
| | | enum eResult |
| | | { |
| | | S_OK =0, |
| | | S_ERR=1, |
| | | S_TIMEOUT=2 |
| | | |
| | | } ; |
| | | |
| | | /* |
| | | typedef struct tagKBPacketV10 |
| | | { |
| | | unsigned char Sign; //èµ·å§æ è®° |
| | | unsigned char DstHost; //ç®æ å°å |
| | | unsigned char SrcAddr; //æºå°å |
| | | unsigned char nCMD; //å½ä»¤ |
| | | union{ |
| | | unsigned char nStatus; //ç¶æ+åºåå· |
| | | struct{ |
| | | unsigned char nSeq:2; //åºåå· |
| | | unsigned char :2; |
| | | unsigned char nErr1:1; |
| | | unsigned char nErr2:1; |
| | | |
| | | }; |
| | | }; |
| | | unsigned char DataLen; //æ°æ®è½½è·é¿åº¦ ä¸å
æ¬å¤´é¨5个åèï¼ä¸å
æ¬å°¾é¨BCCã |
| | | unsigned char data[1]; //æ°æ®è½½è·,ææ«å°¾æ¯BCCï¼æ°æ®é¿åº¦ä¸º0æ¶ï¼å®é
ä¹æä¸ä¸ªæ°æ®ã |
| | | }stKBPacketV10,* pKBPacketV10; |
| | | |
| | | typedef struct tagKBPacketV20 |
| | | { |
| | | unsigned char Sign; //èµ·å§æ è®° |
| | | unsigned char DstHost; //ç®æ å°å |
| | | unsigned char SrcAddr; //æºå°å |
| | | unsigned char nCMD; //å½ä»¤ |
| | | union{ |
| | | unsigned char nStatus; //ç¶æ+åºåå· |
| | | struct{ |
| | | unsigned char nSeq:2; //åºåå· |
| | | unsigned char :2; |
| | | unsigned char nErr1:1; |
| | | unsigned char nErr2:1; |
| | | |
| | | }; |
| | | }; |
| | | unsigned char DataLen; //æ°æ®è½½è·é¿åº¦ ä¸å
æ¬å¤´é¨5个åèï¼ä¸å
æ¬å°¾é¨BCCã |
| | | unsigned char data[1]; //æ°æ®è½½è·,ææ«å°¾æ¯BCCï¼æ°æ®é¿åº¦ä¸º0æ¶ï¼å®é
ä¹æä¸ä¸ªæ°æ®ã |
| | | }stKBPacketV20,* pKBPacketV20; |
| | | */ |
| | | |
| | | enum enumCallBackEvent |
| | | { |
| | | KBusEvNone = 0, |
| | | KBusEvCreate = 1, |
| | | KBusEvConnected = 2, |
| | | KBusEvDisConnected = 3, |
| | | KBusEvClosed = 4, |
| | | KBusEvStateChange =5, |
| | | KBusEvTimeSync=6, |
| | | KBusEvDataUpdate =7, |
| | | KBusEvCmdResponse = 8, |
| | | |
| | | }; |
| | | |
| | | typedef int (*KBusSendPktFuncDef) (uchar * pBuf, int nLen); // SendPacket CallBack func for KBus |
| | | |
| | | typedef void *(*KBusEvCBFuncDef) (void * , int nEvent, void *, int); //callback func ,prama s is void *,void *,int; return void *; |
| | | |
| | | typedef int (*KBusSvCBFuncDef) (void *, int nSvType, int ,void *, int); //Service Req callback func ,param is int ,int, int, void *,int; return int; |
| | | |
| | | /* |
| | | typedef struct tagKBusRunStat |
| | | { |
| | | unsigned char bMaster; // æ¯å¦ä¸»æº |
| | | unsigned char nStationID; // åæºå°å |
| | | unsigned char nChildren; // åæºæ°é |
| | | unsigned char nCurPollId; // å½å轮询å°çåæº å°åã |
| | | unsigned char nSeq; // å
åºåå· |
| | | |
| | | unsigned char bMasterRecved; // ç¶æï¼ ä¸»æºå·²æ¥æ¶å°è¿åçæ°æ®å
|
| | | unsigned char bMasterRecvOK; // ç¶æï¼ ä¸»æºæ¥æ¶å°çè¿åçæ°æ®å
æ£ç¡® |
| | | unsigned char bSlaveRecved; // ç¶æï¼ åæºæ¥åå°æ°æ®å
ã |
| | | unsigned int nSendTimeuS; // æ°æ®å
ååºæ¶å»ã |
| | | |
| | | }stKBusRunStat , * pstKBusRunStat; |
| | | */ |
| | | |
| | | #pragma anon_unions |
| | | typedef struct tagKBusDef // KBus å·¥ä½å
å |
| | | { |
| | | ///* |
| | | union { |
| | | uchar nConfig; |
| | | struct { |
| | | uchar bMaster:1; //KBus, æ¯å¦ä¸»æº |
| | | uchar bSlave:1; //KBus, æ¯å¦åæº |
| | | uchar bRepeater:1; //KBus, æ¯å¦è½¬åå¨,ä¸ç»§å¨ |
| | | }; |
| | | }; |
| | | // */ |
| | | /* |
| | | uchar bMaster; //KBus, æ¯å¦ä¸»æº |
| | | uchar bSlave; //KBus, æ¯å¦åæº |
| | | uchar bRepeater; //KBus, æ¯å¦è½¬åå¨,ä¸ç»§å¨ |
| | | */ |
| | | |
| | | uchar nStationId; //KBus ç«å· |
| | | |
| | | vuchar MyStat; //KBus, ç¶ææºç¶æ |
| | | vuchar nRunStep; //KBus, è¿è¡æ¥ |
| | | vuchar nSeq; //KBus, å
åºåå· |
| | | |
| | | vuchar bMasterSent; // ç¶æ 主æºå·²åé |
| | | vuchar bMasterRecved; // ç¶æ 主æºå·²æ¥æ¶ åå
|
| | | vuchar bMasterRecvOK; // ç¶æ 主æºæ¥æ¶åå
æ£ç¡® |
| | | vuchar bSlaveRecved; // ç¶æ åæºå·²æ¥æ¶å
|
| | | |
| | | vuchar nChildCount; // åæºæ°é |
| | | uchar nCurPollId; // å½å轮询åæº å· |
| | | ushort ErrStat; |
| | | ushort RunStat; |
| | | |
| | | uchar bReq; //è¿è¡ç³»ç»è¯·æ±ä¸ |
| | | uchar nReqSvrId; //请æ±å· |
| | | uchar nReqChildId; //请æ±çåæºå· |
| | | uchar nReqParam; //请æ±çåæ° |
| | | ushort nReqReCount; // |
| | | |
| | | uchar nReqDataHdr[4]; |
| | | uchar pReqDatas[140]; |
| | | uchar nReqDataOff; |
| | | uchar nReqDataLen; |
| | | |
| | | int SendTimeuS; // åå
æ¶å» |
| | | int RecvTimeuS; // æ¶å
æ¶å» |
| | | int DelayuS; // å
循ç¯å»¶è¿ |
| | | int nMaxDelayuS; // æ大å
循ç¯å»¶è¿ |
| | | |
| | | |
| | | int SendTimeTick; // åå
æ¶å» |
| | | int RecvTimeTick; // æ¶å
æ¶å» |
| | | int DelayTick; // å
循ç¯å»¶è¿ |
| | | int nMaxDelayTick; // æ大å
循ç¯å»¶è¿ |
| | | int LastCircleStartTime; //=0; |
| | | int CircleTime; //=0; |
| | | |
| | | int nSlaveTick; // åæºæ¶é´ tick |
| | | |
| | | int ThisuS; |
| | | // int ThisuS; |
| | | //volatile unsigned int nSlaveTick; //=0; |
| | | |
| | | int Clk3; //=0; |
| | |
| | | |
| | | //volatile int nCount2; //=0; |
| | | int TimeOutCount; //=0; |
| | | int LastCircleStartTime; //=0; |
| | | int CircleTime; //=0; |
| | | |
| | | |
| | | stPortDef KBusPort; |
| | | KBusSendPktFuncDef KBusSendPacket; // åéæ°æ®å
å½æ°æé |
| | | KBusEvCBFuncDef KBusEvCBFunc; // äºä»¶åè°å½æ°æé |
| | | KMSvCBDef KBusSvCBFunc; // æå¡è¯·æ±åè°æé |
| | |
| | | // uchar bKBusEvCBFuncSet; // äºä»¶åè°å½æ°æ¯å¦å·²ç»è®¾ç½® |
| | | // uchar bKBusSvCBFuncSet; // äºä»¶åè°å½æ°æ¯å¦å·²ç»è®¾ç½® |
| | | |
| | | uchar PacketBuf1[KBMaxPacketLength]; |
| | | // uchar PacketBuf1[KBMaxPacketLength]; |
| | | uchar PacketBuf2[KBMaxPacketLength]; |
| | | |
| | | |
| | |
| | | ushort DOW[16]; |
| | | }stKBusMem, *pstKBusMem; |
| | | |
| | | //extern stKBus KBus1; |
| | | extern stKBusMem KBusMem; |
| | | |
| | | /* |
| | | typedef struct tagKBusDiag |
| | | { |
| | | |
| | |
| | | }; |
| | | |
| | | }stKBusDiag, *pstKBusDiag; |
| | | |
| | | //extern unsigned char bKBusMaster,bKBusSlave,bKBusRepeater;; |
| | | //extern unsigned char PacketBuf1[KBMaxPacketLength]; |
| | | //extern unsigned char PacketBuf2[KBMaxPacketLength]; |
| | | |
| | | //extern unsigned char nStationID; |
| | | //extern unsigned char nChilds; |
| | | //extern unsigned char nCurPollId; |
| | | //extern unsigned char nSeq; |
| | | |
| | | //extern volatile unsigned char KBusMasterRecved; |
| | | //extern volatile unsigned char KBusMasterRecvOK; |
| | | //extern volatile unsigned char KBusSlaveRecved; |
| | | //extern unsigned int KBusSendTimeuS; |
| | | //extern volatile int KBusRecvTimeuS; |
| | | //extern int KBusDelayuS; |
| | | //extern int KBusMaxDelayuS; |
| | | */ |
| | | |
| | | |
| | | int KBusInit(stKBusDef * pKbusDef, KBusSendPktFuncDef KBusSendPacket, int bMaster, int nChildCount); |
| | | int KBusInit(stKBusDef * pKBus, KBusSendPktFuncDef KBusSendPacket, int bMaster, int nChildCount); |
| | | |
| | | int KBusInitMaster(stKBusDef * pKbusDef, KBusSendPktFuncDef KBusSendPacket, int nChildCount); |
| | | int KBusInitSlave(stKBusDef * pKbusDef, KBusSendPktFuncDef KBusSendPacket, int nStationId, stDeviceInfo *pClientInfo); |
| | | int KBusInitMaster(stKBusDef * pKBus, KBusSendPktFuncDef KBusSendPacket, int nChildCount); |
| | | int KBusInitSlave(stKBusDef * pKBus, KBusSendPktFuncDef KBusSendPacket, int nStationId, stDeviceInfo *pClientInfo); |
| | | |
| | | int KBusLoadSavedConfig(stKBusDef * pKbusDef); |
| | | int KBusSetEvCallBackFunc(stKBusDef * pKbusDef, KBusEvCBFuncDef CBFunc); // Set Event CallBack function |
| | | int KBusSetSvCallBackFunc(stKBusDef * pKbusDef, KMSvCBDef CBFunc); // Set ServiceReq CallBack Function |
| | | int KBusLoadSavedConfig(stKBusDef * pKBus); |
| | | int KBusSetEvCallBackFunc(stKBusDef * pKBus, KBusEvCBFuncDef CBFunc); // Set Event CallBack function |
| | | int KBusSetSvCallBackFunc(stKBusDef * pKBus, KMSvCBDef CBFunc); // Set ServiceReq CallBack Function |
| | | int KBusMakeDefaultClildInfo(stKBusDef * pKBus, int nChild); |
| | | int KBusReqService (stKBusDef * pKBus, int ReqId, int nParam1, int nParam2, void **pData, unsigned short * len1); |
| | | |
| | | int KBusStart(stKBusDef * pKBus) ; |
| | | int KBusStop(stKBusDef * pKBus) ; |
| | | int KBusDataPoll(stKBusDef * pKBus); |
| | | |
| | | int KBusStart(stKBusDef * pKbusDef) ; |
| | | int KBusStop(stKBusDef * pKbusDef) ; |
| | | int KBusDataPoll(stKBusDef * pKbusDef); |
| | | |
| | | int KBusLoopProcess(stKBusDef * pKbusDef); |
| | | int KBusMasterFunc(stKBusDef * pKbusDef); |
| | | int KBusSlaveFunc(stKBusDef * pKbusDef); |
| | | int KBusRepeaterFunc(stKBusDef * pKbusDef); |
| | | int KBusLoopProcess(stKBusDef * pKBus); |
| | | int KBusMasterFunc(stKBusDef * pKBus); |
| | | int KBusSlaveFunc(stKBusDef * pKBus); |
| | | int KBusRepeaterFunc(stKBusDef * pKBus); |
| | | |
| | | /* Make a Packet and return Packet Length */ |
| | | int KBusMakePacket(pKBPacket p1,uchar Src, uchar Dst, uchar nType, uchar nStatus, uchar DataLen, void *pData ); |
| | | |
| | | /* */ |
| | | int KBusCheckPacket(stKBusDef * pKbusDef, pKBPacket p1, int len1); |
| | | int KBusCheckPacket(stKBusDef * pKBus, pKBPacket p1, int len1); |
| | | |
| | | /* */ |
| | | int KBusParsePacket(stKBusDef * pKbusDef, pKBPacket p1, int Len1); |
| | | int KBusParsePacket(stKBusDef * pKBus, pKBPacket p1, int Len1); |
| | | |
| | | |
| | | int KBusPacketSendDone(stKBusDef * pKBus); |
| | | /* |
| | | static inline char KBGetClientNum(int nChn) { }; |
| | | static inline char KBGetClientInfo(int nChn, int nClientId) { }; |
| | |
| | | static inline char KBChangeState(int nPortNum, int nNewState){ }; |
| | | */ |
| | | |
| | | |
| | | |
| | | unsigned char KBusBCC(void * pData, int nSize); |
| | | // |
| | | |
| | | int KBusSlaveRunRemoteReq(stKBusDef * pKBus, int nReqSvrId, unsigned char * pData , int Len1); |
| | | |
| | | /* |
| | | int InitMachine(stMachineConfig * pConfig); |
| | |
| | | #ifndef __KBUSDEFINE_H__ |
| | | #define __KBUSDEFINE_H__ |
| | | |
| | | #define KBUS_VER (0x104) |
| | | |
| | | //#define SYN_PREFIX 1 |
| | | |
| | | typedef unsigned char uchar; |
| | | |
| | | enum enKBusStationType // KBuså·¥ä½ç±»å |
| | | { |
| | | KBNone = 0, // 0,æªå®ä¹ |
| | | KBusMaster = 1, // 1,ä¸»æº |
| | | KBusSlave = 2, // 2,åæº |
| | | KBusRepeater = 3, // 3,转åå¨,ä¸ç»§å¨ |
| | | }; |
| | | |
| | | // diagnosis |
| | | enum enKBusStats |
| | | { |
| | | KBusStatUnInited, // æªåå§åç¶æ |
| | | KBusStatInited, // å·²åå§åç¶æ |
| | | KBusStatConfig, // å·²é
ç½®ç¶æ |
| | | KBusStatReady, // 就绪ç¶æ |
| | | KBusStatRunning, // è¿è¡ç¶æ |
| | | KBusStatIdel, // æåç¶æ |
| | | KBusStatSafe, // å®å
¨ç¶æ |
| | | KBusStatError, // é误ç¶æ |
| | | }; |
| | | /* |
| | | enum enKBusStage |
| | | { |
| | | KBusStageInit, |
| | | KBusStageFindChild, |
| | | KBusStageConfigChild, |
| | | KBusStagePoll, |
| | | |
| | | }; |
| | | */ |
| | | enum { |
| | | KB_SYN = 0x55, |
| | | KBStartSign='%', |
| | | KBEndSign=0x0D, |
| | | KBMaxPacketLength=128, |
| | | }; |
| | | |
| | | enum enCMDs |
| | | { |
| | | |
| | | cmdNone = 0x00, //Nothing |
| | | |
| | | cmdQuery = 0x01, //Query basic Info |
| | | cmdQueryRply = 0x81, //Query Info Reply |
| | | |
| | | cmdSetCfg = 0x02, // Set Configuration |
| | | cmdSetCfgRply = 0x82, // Set Configuration Response |
| | | |
| | | cmdToRunMode = 0x03, |
| | | cmdToRunModeRply = 0x83, |
| | | |
| | | cmdBroadCastCfg = 0x04, // |
| | | |
| | | cmdMuExchgData = 0x05, // |
| | | cmdMuExchgDataRply = 0x85, // |
| | | |
| | | cmdToSafeMode = 0x06, |
| | | |
| | | cmdHeartBeat = 0x07, // |
| | | cmdReHeartBeat = 0x87, // |
| | | |
| | | cmdPing = '1', //Ping |
| | | cmdPingReply = '2', //PingReply |
| | | cmdRead = '3', //Read |
| | | cmdReadReply = '4', //ReadReply |
| | | cmdWrite = '5', //Write |
| | | cmdWriteReply = '6', //WriteReply |
| | | cmdGetVersion = '7', //GetVersion |
| | | cmdVerInfo = '8', //VersionReply |
| | | |
| | | cmdUniExChgData='A', //ExChangeData, = Wirte + Read |
| | | cmdExChgDataReply, //ExchangeData Reply |
| | | |
| | | cmdSyncRead='a', //SyncRead |
| | | cmdSyncWrite, //SyncWrite |
| | | cmdSequenRead, //Sequence Read |
| | | cmdSyncTime, //SyncTime |
| | | }; |
| | | |
| | | |
| | | |
| | | typedef struct tagKBusRunStat |
| | | { |
| | | unsigned char bMaster; // æ¯å¦ä¸»æº |
| | | unsigned char nStationID; // åæºå°å |
| | | unsigned char nChildren; // åæºæ°é |
| | | unsigned char nCurPollId; // å½å轮询å°çåæº å°åã |
| | | unsigned char nSeq; // å
åºåå· |
| | | |
| | | unsigned char bMasterRecved; // ç¶æï¼ ä¸»æºå·²æ¥æ¶å°è¿åçæ°æ®å
|
| | | unsigned char bMasterRecvOK; // ç¶æï¼ ä¸»æºæ¥æ¶å°çè¿åçæ°æ®å
æ£ç¡® |
| | | unsigned char bSlaveRecved; // ç¶æï¼ åæºæ¥åå°æ°æ®å
ã |
| | | unsigned int nSendTimeuS; // æ°æ®å
ååºæ¶å»ã |
| | | |
| | | }stKBusRunStat , * pstKBusRunStat; |
| | | |
| | | typedef struct tagVerInfo // KBus çæ¬ä¿¡æ¯ |
| | | { |
| | | unsigned char nMainVer; |
| | | unsigned char nSubVer; |
| | | }stVerInfo; |
| | | |
| | | typedef struct tagMasterStat // KBus 主æºç¶æï¼ |
| | | { |
| | | unsigned int CycleTime; |
| | | } stMasterStat; |
| | | |
| | | typedef struct tagDeviceInfo // KBus åæºåºæ¬ä¿¡æ¯ |
| | | { |
| | | unsigned short DeviceType; // åæºç±»å |
| | | unsigned short DeviceVer; // åæºçæ¬ |
| | | unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | unsigned char DWStartAddr; // è¾åºæ°æ®åæ° |
| | | unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | |
| | | |
| | | }stDeviceInfo; |
| | | |
| | | typedef struct tagExDeviceInfo // åæºæ©å±ä¿¡æ¯ |
| | | { |
| | | unsigned short DeviceType; // åæºç±»å |
| | | unsigned short DeviceVer; // åæºçæ¬ |
| | | |
| | | unsigned char UID[12]; // 12åè UUID |
| | | unsigned char Name[16]; // 16åè å称 |
| | | // stVerInfo ClientVer; |
| | | unsigned char InBitCount; |
| | | unsigned char OutBitCount; |
| | | unsigned char DWStartAddr; |
| | | unsigned char OutDWCount; |
| | | unsigned char AIWCount; |
| | | unsigned char AQWCount; |
| | | // unsigned char AIBits; |
| | | // unsigned char AQbits; |
| | | |
| | | |
| | | }stExDeviceInfo; |
| | | |
| | | enum enKBusConfigStat |
| | | { |
| | | KBusUnConfiged = 0, |
| | | KBusDefaultConfiged =1, |
| | | KBusConfiged = 2, |
| | | }; |
| | | |
| | | typedef struct tagClientCfg // åæºé
ç½® |
| | | { |
| | | unsigned char Addr; // åæºå°å |
| | | unsigned char Configed; // æ¯å¦å·²é
ç½® |
| | | unsigned char bOnline; //å½åå¨çº¿ç¶æ |
| | | unsigned char InStartAddrBit; //è¾å
¥èµ·å§ä½å°å |
| | | unsigned char OutStartAddrBit; //è¾åºèµ·å§ä½å°å |
| | | unsigned char AIWStartAddrByte; //模æå
¥èµ·å§åå°å |
| | | unsigned char AQWStartAddrByte; //模æåºèµ·å§åå°å |
| | | unsigned char DIWStartAddrByte; //æ°æ®å
¥èµ·å§åå°å |
| | | unsigned char DOWStartAddrByte; //æ°æ®åºèµ·å§åå°å |
| | | unsigned char KeepOut; //Keep Output when comm err; |
| | | }stClientCfg; |
| | | |
| | | /* |
| | | typedef struct ServerStatus |
| | | { |
| | | unsigned char Addr; |
| | | unsigned char Status; |
| | | unsigned short Input[16]; |
| | | unsigned short DT[128]; |
| | | unsigned short output[16]; |
| | | |
| | | }stServerStatus,*pServerStatus; |
| | | */ |
| | | typedef struct tagMachineState // æ¬æºç¶æ |
| | | { |
| | | unsigned char Addr; // å°å |
| | | unsigned char state; //״̬ |
| | | unsigned char InStartAddrBit; //è¾å
¥èµ·å§ä½å°å |
| | | unsigned char OutStartAddrBit; //è¾åºèµ·å§ä½å°å |
| | | unsigned char InDWStartAddrByte; //åè¾å
¥èµ·å§åå°å |
| | | unsigned char OutDWStartAddrByte; //åè¾åºèµ·å§åå°å |
| | | }ClientState; |
| | | |
| | | |
| | | |
| | | #pragma anon_unions |
| | | typedef struct tagChnStat |
| | | { |
| | | unsigned short Stat; |
| | | unsigned short SendPackets; |
| | | unsigned short RecvPackets; |
| | | unsigned short LastSentTimeuS; |
| | | unsigned short LostPackets; |
| | | unsigned short CtnLstPkts; |
| | | unsigned short MaxCtnLstPkts; |
| | | unsigned short NotPkgErr; |
| | | unsigned short PkgLenErr; |
| | | unsigned short BCCErr; |
| | | unsigned short TimeOutErr; |
| | | unsigned short Delay; |
| | | unsigned short MaxDelay; |
| | | unsigned short SendTimeInterval; |
| | | union |
| | | { |
| | | unsigned short ClientDatas[10]; |
| | | struct { |
| | | unsigned short ClientRecvPkts; // |
| | | unsigned short ClientSendPkts; // |
| | | unsigned short ClientNotPktErr; // |
| | | unsigned short ClientMisIdPkts; // |
| | | // unsigned int ClientNoEndErr; // |
| | | unsigned short ClientPkgLenErr; // |
| | | unsigned short ClientBccErr; // |
| | | unsigned short ClientTimeOutErr; // |
| | | }; |
| | | }; |
| | | } stChnStat; |
| | | |
| | | |
| | | typedef struct tagSlaveStat |
| | | { |
| | | unsigned int nSlaveTick; |
| | | } stSlaveStat; |
| | | |
| | | typedef struct ServerClientListElement |
| | | { |
| | | unsigned char Addr; |
| | | unsigned char Status; |
| | | unsigned char Father; |
| | | unsigned char Childs; |
| | | |
| | | } stServerClientListElement; |
| | | |
| | | typedef struct ServerClientList |
| | | { |
| | | unsigned char Addr; |
| | | }stServerClientList,*pServerClientList; |
| | | |
| | | typedef struct tagMachineConfig |
| | | { |
| | | int bKBusMaster; |
| | | int nAddr; |
| | | }stMachineConfig; |
| | | |
| | | /* |
| | | typedef struct ClientStatus |
| | | { |
| | | unsigned char Addr; |
| | | unsigned char Status; |
| | | unsigned char Father; |
| | | unsigned char Childs; |
| | | unsigned short Input[16]; |
| | | unsigned short DT[128]; |
| | | unsigned short output[16]; |
| | | |
| | | }stChnStatus,*pClientStatus; |
| | | */ |
| | | |
| | | typedef struct tagStatusDef |
| | | { |
| | | unsigned char nSeq:2; //åºåå· |
| | | unsigned char :2; |
| | | unsigned char nErr1:1; |
| | | unsigned char nErr2:1; |
| | | }stStatus; |
| | | |
| | | typedef union tagUnStatusDef |
| | | { |
| | | unsigned char nStatus; |
| | | stStatus; |
| | | }unStatus; |
| | | |
| | | typedef struct tagKBPacket |
| | | { |
| | | unsigned char Sign; //èµ·å§æ è®° |
| | | unsigned char DstHost; //ç®æ å°å |
| | | unsigned char SrcAddr; //æºå°å |
| | | unsigned char nCMD; //å½ä»¤ |
| | | union{ |
| | | unsigned char nStatus; //ç¶æ+åºåå· |
| | | struct{ |
| | | unsigned char nSeq:2; //åºåå· |
| | | unsigned char :2; |
| | | unsigned char nErr1:1; |
| | | unsigned char nErr2:1; |
| | | |
| | | }; |
| | | }; |
| | | unsigned char DataLen; //æ°æ®è½½è·é¿åº¦ ä¸å
æ¬å¤´é¨5个åèï¼ä¸å
æ¬å°¾é¨BCCã |
| | | unsigned char data[1]; //æ°æ®è½½è·,ææ«å°¾æ¯BCCï¼æ°æ®é¿åº¦ä¸º0æ¶ï¼å®é
ä¹æä¸ä¸ªæ°æ®ã |
| | | }stKBPacket,* pKBPacket; |
| | | |
| | | typedef struct tagKBInfoBlockV1 |
| | | { |
| | | unsigned short nDeviceType; |
| | | unsigned short nProgVer; |
| | | |
| | | unsigned char InBitCount; |
| | | unsigned char OutBitCount; |
| | | |
| | | unsigned char AICount; |
| | | unsigned char AIBits; |
| | | unsigned char AQCount; |
| | | unsigned char AQbits; |
| | | |
| | | unsigned char InDWCount; |
| | | unsigned char OutDWCount; |
| | | |
| | | }stKBInfoBlockV1, *pKBInfoBlockV1; |
| | | |
| | | enum eResult |
| | | { |
| | | S_OK =0, |
| | | S_ERR=1, |
| | | S_TIMEOUT=2 |
| | | |
| | | } ; |
| | | |
| | | /* |
| | | typedef struct tagKBPacketV10 |
| | | { |
| | | unsigned char Sign; //èµ·å§æ è®° |
| | | unsigned char DstHost; //ç®æ å°å |
| | | unsigned char SrcAddr; //æºå°å |
| | | unsigned char nCMD; //å½ä»¤ |
| | | union{ |
| | | unsigned char nStatus; //ç¶æ+åºåå· |
| | | struct{ |
| | | unsigned char nSeq:2; //åºåå· |
| | | unsigned char :2; |
| | | unsigned char nErr1:1; |
| | | unsigned char nErr2:1; |
| | | |
| | | }; |
| | | }; |
| | | unsigned char DataLen; //æ°æ®è½½è·é¿åº¦ ä¸å
æ¬å¤´é¨5个åèï¼ä¸å
æ¬å°¾é¨BCCã |
| | | unsigned char data[1]; //æ°æ®è½½è·,ææ«å°¾æ¯BCCï¼æ°æ®é¿åº¦ä¸º0æ¶ï¼å®é
ä¹æä¸ä¸ªæ°æ®ã |
| | | }stKBPacketV10,* pKBPacketV10; |
| | | |
| | | typedef struct tagKBPacketV20 |
| | | { |
| | | unsigned char Sign; //èµ·å§æ è®° |
| | | unsigned char DstHost; //ç®æ å°å |
| | | unsigned char SrcAddr; //æºå°å |
| | | unsigned char nCMD; //å½ä»¤ |
| | | union{ |
| | | unsigned char nStatus; //ç¶æ+åºåå· |
| | | struct{ |
| | | unsigned char nSeq:2; //åºåå· |
| | | unsigned char :2; |
| | | unsigned char nErr1:1; |
| | | unsigned char nErr2:1; |
| | | |
| | | }; |
| | | }; |
| | | unsigned char DataLen; //æ°æ®è½½è·é¿åº¦ ä¸å
æ¬å¤´é¨5个åèï¼ä¸å
æ¬å°¾é¨BCCã |
| | | unsigned char data[1]; //æ°æ®è½½è·,ææ«å°¾æ¯BCCï¼æ°æ®é¿åº¦ä¸º0æ¶ï¼å®é
ä¹æä¸ä¸ªæ°æ®ã |
| | | }stKBPacketV20,* pKBPacketV20; |
| | | */ |
| | | |
| | | enum enumCallBackEvent |
| | | { |
| | | KBusEvNone = 0, |
| | | KBusEvCreate = 1, |
| | | KBusEvConnected = 2, |
| | | KBusEvDisConnected = 3, |
| | | KBusEvClosed = 4, |
| | | KBusEvStateChange =5, |
| | | KBusEvTimeSync=6, |
| | | KBusEvDataUpdate =7, |
| | | KBusEvCmdResponse = 8, |
| | | |
| | | }; |
| | | |
| | | typedef int (*KBusSendPktFuncDef) (uchar * pBuf, int nLen); // SendPacket CallBack func for KBus |
| | | |
| | | typedef void *(*KBusEvCBFuncDef) (void * , int nEvent, void *, int); //callback func ,prama s is void *,void *,int; return void *; |
| | | |
| | | typedef int (*KBusSvCBFuncDef) (void *, int nSvType, int ,void *, int); //Service Req callback func ,param is int ,int, int, void *,int; return int; |
| | | |
| | | |
| | | #endif /* __KBUSDEFINE_H__ */ |
| | |
| | | enum {KLSignStart='%', //0x25 |
| | | KLSignReply='U', //0x55 |
| | | KLSignEnd=0x0D, |
| | | KLMaxPacketLength=128, |
| | | KLMaxPacketLength=256, |
| | | }; |
| | | enum enKLCMDs |
| | | { |
| | |
| | | KLCmdStartPLCProgram, |
| | | KLCmdWritePLCProgram, |
| | | KLCmdFinishPLCProgram, |
| | | |
| | | KLCmdReadPLCAnno, |
| | | KLCmdStartPLCAnno, |
| | | KLCmdWritePLCAnno, |
| | | KLCmdFinishPLCAnno, |
| | | |
| | | KLCmdRead1Bit = 0x21, //ReadSingleBit |
| | | KLCmdWrite1Bit = 0x22, //WriteSingleBit |
| | | KLCmdReadBits = 0x23, //ReadBits n = 1 - 8 |
| | |
| | | |
| | | KLCmdWriteFirmware, |
| | | KLCmdWriteFirmInfo, |
| | | KLCmdGetPortInfo, |
| | | KLCmdGetPortChnInfo, |
| | | KLCmdGetPortChildInfo, |
| | | KLCmdPortRemoteReq, |
| | | |
| | | KLCmdErrRply=0xEE, //ERRORReply |
| | | }; |
| | | |
| | |
| | | KLInfoTypeEventLogCount = 3, |
| | | }; |
| | | |
| | | extern unsigned char KLPacketBuf1[256]; |
| | | //extern unsigned char KLPacketBuf1[256]; |
| | | extern unsigned char KLPacketBuf2[256]; |
| | | |
| | | extern unsigned char KLBufferIn[16]; |
| | |
| | | extern int KLThisuS; |
| | | extern int KLRecvTimeuS; |
| | | |
| | | //PendReq ç¶æ |
| | | //0, 没æ |
| | | //1, æ§è¡ä¸ |
| | | //2, æåå®æ |
| | | //3, 失败 |
| | | #pragma anon_unions |
| | | typedef union tagKLStatDef |
| | | { |
| | |
| | | UCHAR nSEQ : 4; |
| | | UCHAR HasExt : 1; |
| | | UCHAR HasErr : 1; |
| | | UCHAR PendReqStat : 2; |
| | | }; |
| | | }unKLStat, *pKLStat; |
| | | /* |
| | |
| | | }stKLPacket,* pKLPacket; |
| | | */ |
| | | |
| | | int KLinkInit(int ); |
| | | |
| | | unsigned char KLBCC(const void * pData, int nSize); |
| | | // |
| | | |
| | |
| | | //#define STORE_RUNSTAT_PAGESIZE (0x00000400) //Page Size = 1K |
| | | #define STORE_RUNSTAT_PAGES 1 //use 1 pages |
| | | |
| | | #define STORE_PLC_ANNO_BASE (FLASH_BASE + 0x0000D000) //56k |
| | | #define STORE_PLC_ANNO_PAGES 4 // use 4 pages , 1K /page |
| | | |
| | | #define STORE_LOG_BASE (FLASH_BASE + 0x0000D000) //52k and FLASH_BANK1_END |
| | | |
| | | #define STORE_LOG_BASE (FLASH_BASE + 0x0000E000) //52k and FLASH_BANK1_END |
| | | //#define STORE_LOG_PAGESIZE (0x00000400) //Page Size = 1K |
| | | #define STORE_LOG_PAGES 4 //use 4 pages |
| | | |
| | | |
| | | typedef unsigned char uchar; |
| | | typedef unsigned char UCHAR; |
| | |
| | | // ç¨æ·/ç³»ç»åæ°é
ç½®å |
| | | // |
| | | // |
| | | |
| | | #pragma anon_unions |
| | | typedef struct tagInfoBlock // 23 bytes |
| | | { |
| | | // USHORT nBlockLenth; |
| | | USHORT nDeviceTypeVer; //device type x.y |
| | | // UCHAR nDevierVer; |
| | | USHORT ProgVer; //prog version x.y |
| | | union { |
| | | USHORT nProgVer; //prog version x.y |
| | | struct { |
| | | UCHAR nProgVerMinor; |
| | | UCHAR nProgVerMajor; |
| | | }; |
| | | }; |
| | | USHORT KLinkVer; //x.y |
| | | USHORT KBusVer; //x.y |
| | | // USHORT KNetVer; //x.y |
| | |
| | | BYTE Hold2:4; |
| | | }stOutputHoldParam; |
| | | |
| | | #pragma anon_unions |
| | | typedef struct tagOutMapping |
| | | { |
| | | USHORT bitPos:4; |
| | | USHORT byteAddr:8; |
| | | USHORT type:4; |
| | | }stOutMapping; |
| | | |
| | | typedef struct tagCfgBlockInfo |
| | | { |
| | | UCHAR nBlockType; |
| | | UCHAR nBlockSize; |
| | | }stCfgBlockInfo; |
| | | |
| | | typedef struct tagKMSysCfg //120 Bytes total |
| | | { |
| | | USHORT Version; // SC0 // 2 Bytes |
| | | USHORT workmode; // SC1 // 2 Bytes 0=From jumper |
| | | USHORT SwitchFunc; // SC2 // 2 Bytes |
| | | USHORT pad1; // 2 Bytes |
| | | USHORT nCfgBlockCount; // 2 Bytes |
| | | |
| | | stComPortParam PortParams[2]; // 8 Bytes |
| | | stInputFilterParam InputParams[16]; //16 Bytes |
| | | stOutputHoldParam OutputParams[16]; //16 Bytes |
| | | |
| | | USHORT OutMappings[6]; //12 Bytes //è¾åºæ å° |
| | | union{ |
| | | USHORT value; //12 Bytes //è¾åºæ å° |
| | | stOutMapping; |
| | | }OutMappings[8]; |
| | | |
| | | USHORT nProgBank; |
| | | USHORT nProgSize; |
| | | USHORT nAnnoSize; |
| | | USHORT nCount; |
| | | |
| | | UINT cfgvar3; // 4 Bytes |
| | | UINT cfgvar4; // 4 Bytes |
| | | UINT cfgvar5; // 4 Bytes |
| | | UINT cfgvar6; // 4 Bytes |
| | | UINT cfgvar7; // 4 Bytes |
| | | stCfgBlockInfo CfgBlockInfos[8]; |
| | | UINT cfgvar8; // 4 Bytes |
| | | UINT cfgvar9; // 4 Bytes |
| | | UINT cfgvar10; // 4 Bytes |
| | | UINT cfgvar11; // 4 Bytes |
| | | UINT cfgvar12; // 4 Bytes |
| | | // UINT cfgvar11; // 4 Bytes |
| | | // UINT cfgvar12; // 4 Bytes |
| | | // UINT cfgvar13; // 4 Bytes |
| | | // UINT cfgvar14; // 4 Bytes |
| | | // UINT cfgvar15; // 4 Bytes |
| | |
| | | KLDataTypeTest = 254 | TYPEDATA, |
| | | }; |
| | | |
| | | #define TOTAL_WDFS (32) //Total DF Count |
| | | #define TOTAL_CurVAL (16) // |
| | | #define TOTALTIMERS (64) |
| | | |
| | | enum enKLDataCounts |
| | | { |
| | | |
| | |
| | | |
| | | }; |
| | | |
| | | typedef struct tagTimerStat |
| | | |
| | | // é信端å£ï¼ 注åå° KMachine éï¼ ç»ä¸ç®¡ç |
| | | |
| | | enum enPortHardType |
| | | { |
| | | unsigned short nScale:2;//Time Scale, 0:1ms 1:10ms 2:100ms 3:1S |
| | | unsigned short nType:1; //0 : timer 1:counter ; |
| | | unsigned short nDir:1; //0 : count down. 1 count up; |
| | | unsigned short nInited:1; |
| | | unsigned short bSet:1; |
| | | unsigned short bTon:1; |
| | | PortHardType_None = 0, // 空æ¥å£,æ ç±»å |
| | | PortHardType_SOFT = 1, // 软件èææ¥å£,å¯è½æ¯é§éç. |
| | | PortHardType_UART = 2, // 串è¡æ¥å£ |
| | | PortHardType_RS232 = 3, // 232æ¥å£ |
| | | PortHardType_RS485 = 4, // 485æ¥å£ |
| | | PortHardType_SLP = 5, // åæ»çº¿æ¥å£ |
| | | PortHardType_RF = 6, // æ 线æ¥å£ |
| | | PortHardType_LORA = 7, // LoRaæ 线æ¥å£ |
| | | PortHardType_OPTI = 8, // å
纤æ¥å£ |
| | | PortHardType_ETH = 9, // 以太ç½æ¥å£ |
| | | PortHardType_WIFI = 10, // WiFiæ¥å£ |
| | | PortHardType_BT = 11, // 以太ç½æ¥å£ |
| | | |
| | | }; |
| | | enum enPortUseType |
| | | { |
| | | PortUse_Default = 0, //é»è®¤ |
| | | PortUse_Console = 1, //æ§å¶å°æ¥å£ |
| | | PortUse_KLink = 2, //KLinké讯 |
| | | PortUse_KBus = 3, //KBusé讯 |
| | | PortUse_KNet = 4, // KNeté讯 |
| | | PortUse_SLP = 5, // SLPåæ»çº¿ |
| | | PortUse_KRF = 6, // æ 线é讯 |
| | | PortUse_ModbusRTU = 7, //Modbus RTU é讯 |
| | | PortUse_ModbusTCP = 8, //Modbus TCP é讯 |
| | | PortUse_Com = 9, // 计ç®æºé讯 |
| | | PortUse_Gen = 10, //éç¨é讯ï¼èªç±å£ |
| | | }; |
| | | |
| | | typedef struct tagPortAbility |
| | | { |
| | | ushort ChildList:1; |
| | | ushort AccessChild:1; |
| | | ushort TranProg:1; |
| | | ushort TranCfg:1; |
| | | ushort Diag:1; |
| | | ushort TranOutBandData:1; |
| | | ushort Tunnel:1; |
| | | ushort TranFirmware:1; |
| | | ushort TranBlink:1; |
| | | |
| | | }stPortAbility; |
| | | |
| | | enum enServiceReqs |
| | | { |
| | | ReqNone, |
| | | ReqInit, |
| | | ReqReset, |
| | | ReqStop, |
| | | ReqRun, |
| | | ReqBlinkLED, |
| | | ReqStartDiag, |
| | | ReqStopDiag, |
| | | ReqPortChildInfo, |
| | | ReqPortChnInfo, |
| | | ReqUpdateFirm, |
| | | ReqUpdateFirmInfo, |
| | | |
| | | }stTimerStat; |
| | | ReqTransFirmware, |
| | | ReqTransCfg, |
| | | ReqTransProg, |
| | | ReqTransData, |
| | | ReqTransBlink, |
| | | ReqTransChild, |
| | | ReqTransInfo, |
| | | ReqTransOutBandData, |
| | | ReqRead1Bit, |
| | | ReqWrite1Bit, |
| | | ReqReadBits, |
| | | ReqWriteBits, |
| | | ReqReadData, |
| | | ReqWriteData, |
| | | ReqRemoteTran, |
| | | |
| | | }; |
| | | |
| | | typedef struct tagTimer |
| | | // åç«¯å£ äºè éä¿¡ |
| | | typedef int (*CommFuncDef)(void * pInstance, int ReqId , int nParam1, int nParam2, void ** pData, unsigned short * len1); |
| | | typedef struct tagPortDef |
| | | { |
| | | unsigned int LastActTime; |
| | | union { |
| | | unsigned short StatByte; |
| | | struct |
| | | { |
| | | unsigned short nScale:2; //Time Scale, 0:1ms 1:10ms 2:100ms 3:1S |
| | | unsigned short nType:1; //0 : timer 1 : counter ; |
| | | unsigned short nDir:1; //0 : count down. 1 count up; |
| | | unsigned short nInited:1; |
| | | unsigned short bSet:1; |
| | | unsigned short bTon:1; |
| | | |
| | | }; |
| | | // stTimerStat Stat; |
| | | USHORT nPortType; |
| | | struct { |
| | | UCHAR nPortHardType; |
| | | UCHAR nPortUseType; |
| | | }; |
| | | }; |
| | | }stTimer; |
| | | ushort ability; //è½å, è·ååæºä¿¡æ¯çã |
| | | uchar bEnable; |
| | | uchar bRunning; |
| | | uchar StationId; |
| | | uchar bMaster; |
| | | uchar nMaxStations; |
| | | uchar nCurStations; |
| | | uchar nHealth; |
| | | void * pPortConfig; |
| | | short PortConfigType; |
| | | short PortConfigSize; |
| | | void * pPortRunStatus; |
| | | short PortRunStatType; |
| | | short PortRunStatSize; |
| | | void * pInstance; //éä¿¡ç»æå®ä½ |
| | | CommFuncDef ReqCommFunc; //é信请æ±å½æ°æé |
| | | // func2 CommReq; |
| | | |
| | | }stPortDef,* pstPortDef; |
| | | |
| | | typedef struct tagInterComm |
| | | { |
| | | int nId; |
| | | |
| | | }stInterComm; |
| | | |
| | | typedef struct tagKMem |
| | | { |
| | | unsigned short WDFs[TOTAL_WDFS]; |
| | | unsigned char CurVALs[TOTAL_CurVAL]; |
| | | unsigned char CurVAL; |
| | | stTimer Timers[TOTALTIMERS]; |
| | | |
| | | union { |
| | | unsigned short WX[KLDataWXCount]; //æ¬æºçXåY |
| | | unsigned char WXB[KLDataWXCount*2]; |
| | |
| | | }; |
| | | unsigned short WR[KLDataWRCount]; |
| | | |
| | | unsigned short WT[16]; |
| | | |
| | | unsigned short WC[16]; |
| | | unsigned short EV[KLDataEVCount]; |
| | | unsigned short SV[KLDataSVCount]; |
| | | |
| | | |
| | | unsigned short WLX[16]; //èæçXåYï¼è¿ç¨é讯æ¶æ å°ç¨ã |
| | | unsigned short WLY[16]; |
| | | unsigned short WLR[16]; |
| | | //èæçXåYï¼è¿ç¨é讯æ¶æ å°ç¨ã |
| | | union{ |
| | | ushort WLX[16]; |
| | | uchar WLXB[32]; |
| | | }; |
| | | union{ |
| | | ushort WLY[16]; |
| | | uchar WLYB[32]; |
| | | }; |
| | | unsigned short WFX[16]; |
| | | unsigned short WFY[16]; |
| | | |
| | | unsigned short WLR[16]; |
| | | unsigned short WSR[16]; |
| | | |
| | | union { |
| | |
| | | unsigned char WDB[KLDataWDTCount*2]; |
| | | }; |
| | | |
| | | int nTotalPorts; |
| | | stPortDef * pPorts[8]; |
| | | |
| | | }stKMem; |
| | | |
| | | |
| | | // é信端å£ï¼ 注åå° KMachine éï¼ ç»ä¸ç®¡ç |
| | | |
| | | typedef struct tagPortAbility |
| | | { |
| | | ushort ChildList:1; |
| | | ushort AccessChild:1; |
| | | ushort TranProg:1; |
| | | ushort TranCfg:1; |
| | | ushort Diag:1; |
| | | ushort TranOutBandData:1; |
| | | ushort Tunnel:1; |
| | | ushort TranFirmware:1; |
| | | ushort TranBlink:1; |
| | | |
| | | |
| | | }stPortAbility; |
| | | |
| | | enum enServiceReqs |
| | | { |
| | | ReqNone, |
| | | ReqInit, |
| | | ReqReset, |
| | | ReqStop, |
| | | ReqRun, |
| | | ReqBlink, |
| | | ReqStartDiag, |
| | | ReqStopDiag, |
| | | ReqTransFirmware, |
| | | ReqTransCfg, |
| | | ReqTransProg, |
| | | ReqTransData, |
| | | ReqTransBlink, |
| | | ReqTransChild, |
| | | ReqTransInfo, |
| | | ReqTransOutBandData, |
| | | ReqRead1Bit, |
| | | ReqWrite1Bit, |
| | | ReqReadBits, |
| | | ReqWriteBits, |
| | | ReqReadData, |
| | | ReqWriteData, |
| | | ReqRemoteTran, |
| | | |
| | | }; |
| | | |
| | | // åç«¯å£ äºè éä¿¡ |
| | | typedef int (*CommFunc)(int n , void *, int len1); |
| | | typedef struct tagPortReg |
| | | { |
| | | ushort nType; |
| | | ushort nVer; |
| | | // func1 GetInfo; |
| | | // func2 CommReq; |
| | | ushort ability; //è½å, è·ååæºä¿¡æ¯çã |
| | | |
| | | }stPortReg; |
| | | |
| | | typedef struct tagInterComm |
| | | { |
| | | int nId; |
| | | |
| | | |
| | | }stInterComm; |
| | | |
| | | |
| | | extern stKMem KMem; |
| | |
| | | extern volatile int OldPowerDownEventTime; |
| | | |
| | | int KMachineInit(void); |
| | | int KMachineLoopProc(void); |
| | | |
| | | /* |
| | | åKMachine 注å é讯端å£,以便é讯端å£ä¹é´çåè½äºé |
| | | */ |
| | | int KMRegisterPort(ushort nType,stPortDef * thePortParam); |
| | | |
| | | int KMPortReqFunc(int nPortIndex,int nReqId, int nParam1, int nParam2, void ** pData, unsigned short * nlen1); |
| | | |
| | | |
| | | int ReadFlashMem(void * pBuf, void * pAddrFlash, int nByteSize); |
| | | int EraseAndWriteToFlashMem(void * pBuf, void * pAddrFlash, unsigned int nByteSize); |
| | | int WriteToFlashMemNoErase(void * pBuf, void * pAddrFlash, unsigned int nByteSize); |
| | | int WriteToFlashAutoErase(void * pBuf, void * pAddrFlash, unsigned int nByteSize); |
| | | |
| | | int ReadFactoryData(void * pDatabuf, int nByteCount); |
| | | int WriteFactoryData(void * pDataBuf, int nByteCount); |
| | | |
| | | // active Program bank |
| | | int ReadProgram(int nProgByteAddr, void *pBuf, int nByteSize, int nBank); |
| | | int WriteProgram(int nProgByteAddr, void * pBuf, int nByteSize, int nBank); |
| | | |
| | | int ReadPLCProgram(int nBank, int nProgByteAddr, void *pBuf, int nByteSize); |
| | | int StartPLCProgram(int nBank, int nByteSize, int nCRC); |
| | | int WritePLCProgram(int nBank, int nProgByteAddr, void * pBuf, int nByteSize); |
| | | int FinishiPLCProgram(int nBank, int nByteSize, int nCRC ); |
| | | |
| | | int ReadPLCAnno(int nType, int nProgByteAddr, void *pBuf, int nByteSize); |
| | | int StartPLCAnno(int nType, int nByteSize, int nCRC); |
| | | int WritePLCAnno(int nType, int nProgByteAddr, void * pBuf, int nByteSize); |
| | | int FinishiPLCAnno(int nType, int nByteSize, int nCRC ); |
| | | |
| | | int WriteSysCfgToFlash(pStoredKMSysCfg theStoredKMSysCfg); |
| | | int ReadSysCfgFromFlash(pStoredKMSysCfg theStoredKMSysCfg); |
| | | |
| | | int KMRunService(int nSvrId, int nParam1, int nParam2, void **pData, unsigned short *nled1); |
| | | |
| | | int CheckEventLog(void); |
| | | int AddEventLog(uint32_t nTime, USHORT nEvent, USHORT nParam1, UINT nParam2); |
| | | pEventLog GetEventLogAddr(int nIndex); |
| | | int ClearEventLog(void); |
| | |
| | | #ifndef __MYQUEUE_H__ |
| | | #define __MYQUEUE_H__ |
| | | |
| | | #pragma anon_unions |
| | | typedef struct |
| | | { |
| | | unsigned char * buf1; |
| | | int Caps; |
| | | volatile int wp; //Write Pointor |
| | | volatile int rp; //Read Pointor |
| | | short Caps; |
| | | volatile short wp; //Write Pointor |
| | | volatile short rp; //Read Pointor |
| | | // volatile int DataSize; |
| | | volatile int RecvBytes; |
| | | volatile int bFull; |
| | | volatile int bEmpty; |
| | | volatile int state; |
| | | // volatile short RecvBytes; |
| | | union{ |
| | | volatile unsigned char state; |
| | | struct{ |
| | | volatile unsigned char bFull:1; |
| | | volatile unsigned char bEmpty:1; |
| | | }; |
| | | }; |
| | | |
| | | }stMyQueue,* pMyQueue; |
| | | |
| | |
| | | } |
| | | static __inline int GetDataLen(pMyQueue theQueue) |
| | | { |
| | | int size=theQueue->wp -theQueue->rp; |
| | | int size=theQueue->wp - theQueue->rp; |
| | | if (theQueue->bFull) |
| | | { |
| | | return theQueue->Caps; |
| | |
| | | #include "GlobalDef.h" |
| | | #include "KMachine.h" |
| | | |
| | | #if (ENABLE_PLC) |
| | | |
| | | #define TICK_OF_MS (10) //1ms |
| | | #define TICK_OF_RS (100) //10mS |
| | | #define TICK_OF_XS (1000) //100mS |
| | | #define TICK_OF_YS (10000) //1S |
| | | |
| | | #define TOTAL_WDFS (32) //Total DF Count |
| | | #define TOTAL_CurVAL (16) // |
| | | #define TOTALTIMERS (64) |
| | | |
| | | #define PLC_PROGRAM_USE_BANK 1 |
| | | |
| | | typedef struct tagTimerStat |
| | | { |
| | | unsigned short nScale:2;//Time Scale, 0:1ms 1:10ms 2:100ms 3:1S |
| | | unsigned short nType:1; //0 : timer 1:counter ; |
| | | unsigned short nDir:1; //0 : count down. 1 count up; |
| | | unsigned short nInited:1; |
| | | unsigned short bSet:1; |
| | | unsigned short bTon:1; |
| | | |
| | | }stTimerStat; |
| | | |
| | | typedef struct tagTimer |
| | | { |
| | | unsigned int LastActTime; |
| | | union { |
| | | unsigned short StatByte; |
| | | struct |
| | | { |
| | | unsigned short nScale:2; //Time Scale, 0:1ms 1:10ms 2:100ms 3:1S |
| | | unsigned short nType:1; //0 : timer 1 : counter ; |
| | | unsigned short nDir:1; //0 : count down. 1 count up; |
| | | unsigned short nInited:1; |
| | | unsigned short bSet:1; |
| | | unsigned short bTon:1; |
| | | |
| | | }; |
| | | // stTimerStat Stat; |
| | | }; |
| | | }stTimer; |
| | | |
| | | #pragma anon_unions |
| | | |
| | |
| | | { |
| | | int bPLCRunning; |
| | | int nScanCount; |
| | | unsigned short WDFs[TOTAL_WDFS]; |
| | | unsigned char CurVALs[TOTAL_CurVAL]; |
| | | unsigned char CurVAL; |
| | | stTimer Timers[TOTALTIMERS]; |
| | | unsigned short WT[16]; |
| | | |
| | | unsigned short WC[16]; |
| | | unsigned short EV[KLDataEVCount]; |
| | | unsigned short SV[KLDataSVCount]; |
| | | |
| | | unsigned short ProgTrace[256]; |
| | | |
| | | }stPLCMem; |
| | | extern stPLCMem PLCMem; |
| | | |
| | | int InitPLC(void); |
| | | int StartPLC(void); |
| | | int StopPLC(void); |
| | | |
| | | enum enPLCOPs |
| | | { |
| | |
| | | OP_PAUSE, |
| | | OP_JP, |
| | | OP_CALL, |
| | | OP_RET, |
| | | |
| | | OP_TML = 0xC8, // |
| | | OP_TMR = 0xDC, // |
| | | OP_TMX = 0xDD, // |
| | | OP_TMY = 0xFA, // |
| | | |
| | | OP_END = 0xFF, |
| | | |
| | | }; |
| | | /* |
| | |
| | | unsigned short Addr; |
| | | }stPLCPROG; |
| | | */ |
| | | typedef struct stBinProg1 |
| | | typedef struct stBinInstrcn1 |
| | | { |
| | | unsigned char nOp; |
| | | unsigned char nParamType; |
| | | unsigned short nParamAddr; |
| | | }stBinProg1; |
| | | typedef struct stBinProg15 |
| | | }stBinInstrcn1; |
| | | typedef struct stBinInstrcn15 |
| | | { //??? |
| | | // |
| | | unsigned char nOp; |
| | |
| | | unsigned char nParamType1; |
| | | unsigned char resvr1; |
| | | unsigned short resvr2; |
| | | }stBinProg15; |
| | | typedef struct stBinProg2 |
| | | }stBinInstrcn15; |
| | | typedef struct stBinInstrcn2 |
| | | { //???? |
| | | // |
| | | unsigned char nOp; |
| | |
| | | unsigned char nParamType1; |
| | | unsigned char nParamType2; |
| | | unsigned short nParamAddr2; |
| | | }stBinProg2; |
| | | typedef struct stBinProg3 |
| | | }stBinInstrcn2; |
| | | typedef struct stBinInstrcn3 |
| | | { //??????? |
| | | unsigned char nOp; |
| | | unsigned char nOpNum; |
| | |
| | | unsigned char resvr1; |
| | | unsigned char nParamType3; |
| | | unsigned short nParamAddr3; |
| | | }stBinProg3; |
| | | |
| | | |
| | | extern stBinProg1 const prog1[]; |
| | | extern int nSizeProg1; |
| | | |
| | | //extern unsigned char CurVAL; |
| | | //extern unsigned char CurVALs[TOTAL_CurVAL]; |
| | | //extern unsigned short DFs[TOTAL_WDFS]; |
| | | |
| | | //extern unsigned short WX[13]; |
| | | //extern unsigned short WY[13]; |
| | | //extern unsigned short WR[64]; |
| | | //extern unsigned short DT[256]; |
| | | //extern unsigned short SDT[256]; |
| | | //extern const unsigned short bitMasks[16]; |
| | | //extern stTimer Timers[TOTALTIMERS]; |
| | | |
| | | ///* |
| | | }stBinInstrcn3; |
| | | |
| | | |
| | | //*/ |
| | | typedef struct tagStoredHdr |
| | | { |
| | | unsigned short nBlockSign; |
| | | unsigned char nBlockType; |
| | | unsigned char nSeq; |
| | | unsigned short nSize; |
| | | unsigned short nCRC2; |
| | | }stStoredHdr; |
| | | |
| | | |
| | | /* |
| | | typedef struct tagBinProgs |
| | | { |
| | | unsigned short nSteps; |
| | | unsigned short nOptions; |
| | | stBinInstrcn1 BinInstrcns[1]; |
| | | }stBinProgs, *pstBinProgs; |
| | | */ |
| | | typedef struct tagStoredBinProgs |
| | | { |
| | | stStoredHdr StoredHdr; |
| | | stBinInstrcn1 BinInstrcns[1]; |
| | | |
| | | }stStoredBinProgs, *pstStoredBinProgs; |
| | | |
| | | typedef struct tagStoredAnno |
| | | { |
| | | stStoredHdr StoredHdr; |
| | | unsigned char Annos[1]; |
| | | |
| | | }stStoredAnno, *pstStoredAnno; |
| | | |
| | | //extern stBinInstrcn1 const prog1[]; |
| | | //extern int nSizeProg1; |
| | | extern stPLCMem PLCMem; |
| | | |
| | | |
| | | int InitPLC(void); |
| | | int StartPLC(void); |
| | | int StopPLC(void); |
| | | |
| | | int InitTimer(int nIndex, int nType); |
| | | int RunTimer(int nIndex , int SV); |
| | |
| | | int PushInVal(void); |
| | | int PopOutVal(void); |
| | | |
| | | int ProcessPLCBinProg(const stBinProg1 * pBinprog, int nSize); |
| | | //int ProcessPLCPROG(const stBinProg1 * prog,int nSize); |
| | | int ProcessPLCBinProg(const stBinInstrcn1 * pBinProg, int nSize); |
| | | //int ProcessPLCPROG(const stBinInstrcn1 * prog,int nSize); |
| | | |
| | | |
| | | #endif // (ENABLE_PLC) |
| | | |
| | | #endif /* __PLCFUNCTIONS_H__ */ |
| | |
| | | * @retval None |
| | | */ |
| | | |
| | | void SystemClock_Config(void) |
| | | void SystemClock_Config_New(void) |
| | | { |
| | | LL_FLASH_SetLatency(LL_FLASH_LATENCY_1); |
| | | |
| | | if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_1) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | LL_RCC_HSE_Enable(); |
| | | |
| | | /* Wait till HSE is ready */ |
| | | while(LL_RCC_HSE_IsReady() != 1) |
| | | { |
| | | |
| | | } |
| | | LL_RCC_LSI_Enable(); |
| | | |
| | | /* Wait till LSI is ready */ |
| | | while(LL_RCC_LSI_IsReady() != 1) |
| | | { |
| | | |
| | | } |
| | | #if (XLAT_FREQ == 12) |
| | | LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_3, LL_RCC_PLL_MUL_12); |
| | | #else |
| | | LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_2, LL_RCC_PLL_MUL_12); |
| | | #endif |
| | | LL_RCC_PLL_Enable(); |
| | | |
| | | /* Wait till PLL is ready */ |
| | | while(LL_RCC_PLL_IsReady() != 1) |
| | | { |
| | | |
| | | } |
| | | LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); |
| | | LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); |
| | | LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); |
| | | |
| | | /* Wait till System clock is ready */ |
| | | while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) |
| | | { |
| | | |
| | | } |
| | | |
| | | LL_InitTick(48000000,10000); |
| | | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
| | | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
| | | |
| | | SysTick->CTRL = SysTick_CTRL_ENABLE_Msk |
| | | | SysTick_CTRL_TICKINT_Msk; |
| | | |
| | | LL_SetSystemCoreClock(48000000); |
| | | LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK1); |
| | | |
| | | } |
| | | |
| | | |
| | | void SystemClock_Config(void) |
| | | { |
| | | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
| | | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
| | | |
| | |
| | | LL_USART_EnableDEMode(USART2); |
| | | LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_LOW); |
| | | // LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_HIGH); |
| | | LL_USART_SetDEAssertionTime(USART2, 31); |
| | | LL_USART_SetDEDeassertionTime(USART2, 31); |
| | | LL_USART_SetDEAssertionTime(USART2, 15); |
| | | LL_USART_SetDEDeassertionTime(USART2, 15); |
| | | #else |
| | | |
| | | #endif |
| | |
| | | unsigned int Uart1Baud = DefaultUart1Baud; |
| | | unsigned int Uart2Baud = DefaultUart2Baud; |
| | | |
| | | unsigned char Uart1RecvBuf1[128]; |
| | | unsigned char Uart1RecvBuf1[Uart1RecvBufSize]; |
| | | int Uart1RecvBuf1DataLen=0; |
| | | unsigned char Uart1RecvBuf2[128]; |
| | | int Uart1RecvBuf2DataLen=0; |
| | | //unsigned char Uart1RecvBuf2[128]; |
| | | //int Uart1RecvBuf2DataLen=0; |
| | | |
| | | unsigned char Uart2RecvBuf1[128]; |
| | | int Uart2RecvBuf1DataLen=0; |
| | | unsigned char Uart2RecvBuf2[128]; |
| | | int Uart2RecvBuf2DataLen=0; |
| | | //unsigned char Uart2RecvBuf2[128]; |
| | | //int Uart2RecvBuf2DataLen=0; |
| | | |
| | | volatile int Uart1BaudGot=0; |
| | | volatile int Uart1BaudFirstGot=0; |
| | |
| | | pKBus->KBusSendPacket = KBusSendPacket; |
| | | pKBus->nCurPollId = 1; |
| | | |
| | | for (int i=0;i<MAX_CLIENT;i++) |
| | | { |
| | | memset(&pKBus->KBusChnStats[i],0,sizeof(stChnStat)); |
| | | } |
| | | for (int i=0;i<MAX_CLIENT;i++) |
| | | { |
| | | KBusMakeDefaultClildInfo(pKBus, i); |
| | | } |
| | | /* |
| | | stDeviceInfo * pDeviceInfo = &pKBus->DeviceInfos[1]; |
| | | |
| | | pDeviceInfo->DeviceType = 0; |
| | | pDeviceInfo->DeviceVer = 0; |
| | | pDeviceInfo->InBitCount = 16; |
| | | pDeviceInfo->OutBitCount = 16; |
| | | pDeviceInfo->AIWCount = 0; |
| | | pDeviceInfo->AQWCount = 0; |
| | | pDeviceInfo->DWStartAddr = 0; |
| | | pDeviceInfo->OutDWCount = 0; |
| | | */ |
| | | pKBus->KBusPort = (stPortDef){.nPortHardType = 4, .nPortUseType = 3, .bEnable = 1, .bRunning =1, .StationId = 0, .bMaster = 1, .nMaxStations = nChildCount, |
| | | .pInstance=pKBus , .ReqCommFunc = (CommFuncDef)KBusReqService}; |
| | | |
| | | KMRegisterPort(1,&pKBus->KBusPort); |
| | | return iRet; |
| | | }; |
| | | |
| | |
| | | pKBus->KBusEvCBFunc = NULL; |
| | | pKBus->KBusSvCBFunc=NULL; |
| | | pKBus->KBusSendPacket = KBusSendPacket; |
| | | |
| | | /* |
| | | for (int i=0;i<MAX_CLIENT;i++) |
| | | { |
| | | memset(&pKBus->KBusChnStats[i],0,sizeof(stChnStat)); |
| | | } |
| | | } |
| | | */ |
| | | |
| | | pKBus->KBusPort = (stPortDef){.nPortHardType = 4, .nPortUseType = 3, .bEnable = 1, .bRunning =1, .StationId = nStationId, .bMaster = 0, .pInstance = pKBus}; |
| | | KMRegisterPort(1,&pKBus->KBusPort); |
| | | |
| | | return iRet; |
| | | } |
| | | |
| | |
| | | return 0; |
| | | } |
| | | |
| | | //unsigned char tempdata [8] = {11,12,13,14,25,26,27,28}; |
| | | int KBusReqService (stKBusDef * pKBus, int ReqId, int nParam1, int nParam2, void **pData, unsigned short * len1) |
| | | { |
| | | |
| | | switch (ReqId) { |
| | | case ReqStartDiag: |
| | | break; |
| | | case ReqStopDiag: |
| | | break; |
| | | case ReqPortChnInfo: |
| | | *pData = &pKBus->KBusChnStats[nParam1]; |
| | | *len1 = sizeof(stChnStat); |
| | | break; |
| | | case ReqPortChildInfo: |
| | | *pData = &pKBus->DeviceInfos[nParam1]; |
| | | *len1 = sizeof(stDeviceInfo); |
| | | |
| | | // *pData = tempdata; |
| | | // *len1 = sizeof(tempdata); |
| | | break; |
| | | case ReqBlinkLED: |
| | | if (pKBus->bReq == 1) return -1; |
| | | if (nParam1 != 0xff && nParam1> pKBus->nChildCount) return -2; |
| | | if (pKBus->bReq != 1 ) { |
| | | pKBus->bReq=1; |
| | | pKBus->nReqSvrId = ReqId; |
| | | pKBus->nReqChildId = nParam1; |
| | | pKBus->nReqParam = nParam2; |
| | | pKBus->nReqReCount = 0; |
| | | } |
| | | break; |
| | | |
| | | case ReqTransBlink: |
| | | if (pKBus->bReq == 1) return -1; |
| | | if (nParam1 != 0xff && nParam1> pKBus->nChildCount) return -2; |
| | | if (pKBus->bReq != 1 ) { |
| | | pKBus->bReq=1; |
| | | pKBus->nReqSvrId = ReqId; |
| | | pKBus->nReqChildId = nParam1; |
| | | pKBus->nReqParam = nParam2; |
| | | pKBus->nReqReCount = 0; |
| | | } |
| | | break; |
| | | |
| | | case ReqTransCfg: |
| | | break; |
| | | case ReqUpdateFirm: |
| | | if (pKBus->bReq == 1) return -1; |
| | | if (nParam1> pKBus->nChildCount) return -2; |
| | | if (pKBus->bReq != 1 ) { |
| | | pKBus->bReq=1; |
| | | pKBus->nReqSvrId = ReqId; |
| | | pKBus->nReqChildId = nParam1; |
| | | pKBus->nReqParam = nParam2; |
| | | pKBus->nReqReCount = 0; |
| | | if (*len1>0) { |
| | | memcpy(pKBus->pReqDatas,*pData,*len1); |
| | | pKBus->nReqDataLen = *len1; |
| | | pKBus->nReqDataOff = 0; |
| | | } |
| | | } |
| | | |
| | | break; |
| | | |
| | | case ReqTransFirmware: |
| | | break; |
| | | default: |
| | | if (pKBus->bReq == 1) return -1; |
| | | if (nParam1 != 0xff && nParam1> pKBus->nChildCount) return -2; |
| | | if (pKBus->bReq != 1 ) { |
| | | pKBus->bReq=1; |
| | | pKBus->nReqSvrId = ReqId; |
| | | pKBus->nReqChildId = nParam1; |
| | | pKBus->nReqParam = nParam2; |
| | | pKBus->nReqReCount = 0; |
| | | if (*len1>0) { |
| | | memcpy(pKBus->pReqDatas,*pData,*len1); |
| | | pKBus->nReqDataLen = *len1; |
| | | pKBus->nReqDataOff = 0; |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | int KBusStart(stKBusDef * pKBus) |
| | | { |
| | | int iRet = 0; |
| | |
| | | int iRet = 0; |
| | | if (pKBus->bMaster) |
| | | { |
| | | if (pKBus->nChildCount>0) KBusMasterFunc(&KBus1); |
| | | } |
| | | if (pKBus->bSlave) |
| | | { |
| | | KBusSlaveFunc(&KBus1); |
| | | } |
| | | if (pKBus->bRepeater) |
| | | { |
| | | } |
| | | |
| | | if (pKBus->RunStat) {pKBus->RunStat--;} |
| | | if (pKBus->ErrStat) {pKBus->ErrStat--;} |
| | | return iRet; |
| | | } |
| | | |
| | |
| | | return 0; |
| | | } |
| | | |
| | | int KBusUpdateChildInfo(stKBusDef * pKBus, int nCild, stDeviceInfo * pInfoBlock) |
| | | int KBusUpdateChildInfo(stKBusDef * pKBus, int nChild, stDeviceInfo * pInfoBlock) |
| | | { |
| | | stDeviceInfo * pDeviceInfo = &pKBus->DeviceInfos[nCild]; |
| | | |
| | | pDeviceInfo->DeviceType = pInfoBlock->DeviceType; |
| | | pDeviceInfo->DeviceVer = pInfoBlock->DeviceVer; |
| | | pDeviceInfo->InBitCount = pInfoBlock->InBitCount; |
| | | pDeviceInfo->OutBitCount = pInfoBlock->OutBitCount ; |
| | | pDeviceInfo->AIWCount = pInfoBlock->AIWCount; |
| | | pDeviceInfo->AQWCount = pInfoBlock->AQWCount; |
| | | pDeviceInfo->DWStartAddr = pInfoBlock->DWStartAddr; |
| | | pDeviceInfo->OutDWCount = pInfoBlock->OutDWCount; |
| | | |
| | | pKBus->DeviceInfos[nChild] = *pInfoBlock; |
| | | return 0; |
| | | } |
| | | |
| | | int KBusMakeDefaultClildInfo(stKBusDef * pKBus, int nCild) |
| | | int KBusMakeDefaultClildInfo(stKBusDef * pKBus, int nChild) |
| | | { |
| | | unsigned DefaultInBitCount = 8; |
| | | unsigned DefaultOutBitCount = 8; |
| | | stDeviceInfo * pDeviceInfo = &pKBus->DeviceInfos[nCild]; |
| | | // unsigned DefaultInBitCount = 8; |
| | | // unsigned DefaultOutBitCount = 8; |
| | | |
| | | // stDeviceInfo * pDeviceInfo = &pKBus->DeviceInfos[nChild]; |
| | | pKBus->DeviceInfos[nChild] = (stDeviceInfo){ |
| | | .DeviceType=0, |
| | | .DeviceVer=0, |
| | | .InBitCount=8, |
| | | .OutBitCount=8, |
| | | .AIWCount=0, |
| | | .AQWCount=0, |
| | | .DWStartAddr=0, |
| | | .OutDWCount=0 |
| | | }; |
| | | |
| | | pDeviceInfo->DeviceType = 0; |
| | | pDeviceInfo->DeviceVer = 0; |
| | | pDeviceInfo->InBitCount = DefaultInBitCount; |
| | | pDeviceInfo->OutBitCount = DefaultOutBitCount; |
| | | pDeviceInfo->AIWCount = 0; |
| | | pDeviceInfo->AQWCount = 0; |
| | | pDeviceInfo->DWStartAddr = 0; |
| | | pDeviceInfo->OutDWCount = 0; |
| | | return 0; |
| | | } |
| | | |
| | |
| | | int KBusSearchChildProc(stKBusDef * pKBus) |
| | | { |
| | | int iRet = 0; |
| | | uint32_t tick1=HAL_GetTick(); |
| | | uint32_t thisuS=GetuS(); |
| | | |
| | | pKBus->MyStat = KBusStatReady; |
| | | return iRet; |
| | | if (!pKBus->bMasterSent) { |
| | | // Sent Query Packet for CurPollId; |
| | | //pKBus->nCurPollId; |
| | | pKBus->bMasterSent=1; |
| | | pKBus->SendTimeuS = thisuS; |
| | | } |
| | | uint32_t tick1=GetTick(); |
| | | // uint32_t thisuS=GetuS(); |
| | | int nThisPollId = pKBus->nCurPollId; |
| | | if (pKBus->bMasterSent) { |
| | | if (pKBus->bMasterRecved) { |
| | | |
| | | } |
| | | |
| | | if (!pKBus->bMasterRecved && thisuS- pKBus->SendTimeuS > 1000) |
| | | { |
| | | // timeOut, |
| | | pKBus->bMasterSent=0; // no wait any more; |
| | | if (pKBus->RetryCount <3) { |
| | | // resent query packet for curPollId; |
| | | pKBus->bMasterSent=1; |
| | | pKBus->SendTimeuS = thisuS; |
| | | } |
| | | if (pKBus->RetryCount >3 ) { |
| | | // Set Cur Child As Default |
| | | KBusMakeDefaultClildInfo(pKBus,pKBus->nCurPollId); |
| | | KBusAddChildAddrByInfo(pKBus,pKBus->nCurPollId,&pKBus->DeviceInfos[pKBus->nCurPollId]); |
| | | |
| | | // Next Child; |
| | | pKBus->nCurPollId++; |
| | | if (pKBus->nCurPollId > pKBus->nChildCount) |
| | | pKBus->bMasterSent=0; |
| | | pKBus->RetryCount=0; |
| | | nThisPollId++; |
| | | pKBus->nCurPollId = nThisPollId; |
| | | if (nThisPollId > pKBus->nChildCount) |
| | | { |
| | | // all query done, next stage |
| | | pKBus->nCurPollId = 1; |
| | | pKBus->MyStat = KBusStatReady; |
| | | // CallBack |
| | | if (pKBus->KBusEvCBFunc) pKBus->KBusEvCBFunc(pKBus, KBusEvStateChange,0,0); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | if (!pKBus->bMasterRecved && tick1- pKBus->SendTimeTick > KBUS_WAIT_TIME_OUT1) |
| | | { |
| | | /* |
| | | // timeOut, |
| | | if (pKBus->RetryCount <3) { |
| | | pKBus->RetryCount++; |
| | | // resent query packet for curPollId; |
| | | pKBus->bMasterSent=0; // no wait any more; |
| | | // pKBus->bMasterSent=1; |
| | | // pKBus->SendTimeTick = tick1; |
| | | } |
| | | if (pKBus->RetryCount >3 ) |
| | | // */ |
| | | { |
| | | // Set Cur Child As Default |
| | | KBusMakeDefaultClildInfo(pKBus,nThisPollId); |
| | | KBusAddChildAddrByInfo(pKBus,nThisPollId,&pKBus->DeviceInfos[nThisPollId]); |
| | | |
| | | // Next Child; |
| | | pKBus->RetryCount=0; |
| | | nThisPollId++; |
| | | pKBus->nCurPollId = nThisPollId; |
| | | if (nThisPollId > pKBus->nChildCount) |
| | | { |
| | | // all query done, next stage |
| | | pKBus->nCurPollId = 1; |
| | | pKBus->MyStat = KBusStatReady; |
| | | // CallBack |
| | | if (pKBus->KBusEvCBFunc) pKBus->KBusEvCBFunc(pKBus, KBusEvStateChange,0,0); |
| | | } |
| | | pKBus->bMasterSent=0; |
| | | } |
| | | |
| | | } |
| | | }else { // ! pKBus->bMasterSent è¿æ²¡æåé |
| | | // Sent Query Packet for CurPollId; |
| | | //pKBus->nCurPollId; |
| | | |
| | | unStatus ThisStatus; |
| | | ThisStatus.nSeq = pKBus->nSeq; |
| | | ThisStatus.nErr1 = (pKBus->KBusChnStats[nThisPollId].MStat==0); |
| | | |
| | | int len1=KBusMakePacket((pKBPacket)pKBus->PacketBuf2,0,nThisPollId,cmdQuery,ThisStatus.nStatus,0,NULL); |
| | | // LL_USART_SetBaudRate(USART2,48000000,LL_USART_OVERSAMPLING_8,DefaultUart2Baud); |
| | | pKBus->KBusSendPacket(pKBus->PacketBuf2, len1); |
| | | pKBus->KBusChnStats[nThisPollId].SendPackets++; |
| | | pKBus->KBusChnStats[nThisPollId].SendTimeInterval=pKBus->SendTimeTick-pKBus->KBusChnStats[nThisPollId].LastSentTimeTick; |
| | | pKBus->KBusChnStats[nThisPollId].LastSentTimeTick=pKBus->SendTimeTick; |
| | | // PacketLength = len1; |
| | | pKBus->SendTime=tick1; |
| | | |
| | | pKBus->bMasterRecved=0; |
| | | pKBus->bMasterRecvOK=0; |
| | | |
| | | pKBus->bMasterSent=1; |
| | | pKBus->SendTimeTick = tick1; |
| | | } |
| | | |
| | | |
| | | // pKBus->MyStat = KBusStatReady; |
| | | |
| | | return iRet; |
| | | } |
| | | |
| | | int KBusPacketSendDone(stKBusDef * pKBus) |
| | | { |
| | | switch (pKBus->MyStat){ |
| | | case KBusStatUnInited: |
| | | break; |
| | | case KBusStatInited: |
| | | break; |
| | | case KBusStatConfig: |
| | | break; |
| | | case KBusStatReady: |
| | | break; |
| | | case KBusStatRunning: |
| | | switch(pKBus->nRunStep) { |
| | | case KBusRunStepBroadCastCfg: |
| | | pKBus->nRunStep = KBusRunStepTimeSync; |
| | | break; |
| | | case KBusRunStepTimeSync: |
| | | pKBus->nRunStep = KBusRunStepMultiDataPoll; |
| | | break; |
| | | case KBusRunStepMultiDataPoll: |
| | | pKBus->nRunStep = KBusRunStepUniDataPoll; |
| | | break; |
| | | case KBusRunStepUniDataPoll: |
| | | |
| | | break; |
| | | case KBusRunStepUniDataTranster: |
| | | |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | // KBusDataPoll(pKBus); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | |
| | | int GoStep(stKBusDef * pKBus, enKBusRunStep NextStep) |
| | | { |
| | | pKBus->nRunStep = NextStep; |
| | | pKBus->TimeOutCount=0; |
| | | return 0; |
| | | } |
| | | |
| | | int KBusMasterFunc(stKBusDef * pKBus) |
| | | { |
| | | int len1; |
| | | uint32_t tick1=GetTick(); |
| | | ushort DataLen = 0; |
| | | switch (pKBus->MyStat){ |
| | | case KBusStatUnInited: |
| | | KBusLoadSavedConfig(pKBus); |
| | | pKBus->MyStat = KBusStatInited; |
| | | pKBus->TimeOutCount=0; |
| | | break; |
| | | case KBusStatInited: |
| | | pKBus->TimeOutCount++; |
| | | if (pKBus->TimeOutCount>30){ |
| | | pKBus->MyStat = KBusStatConfig; |
| | | pKBus->TimeOutCount = 0; |
| | | } |
| | | break; |
| | | case KBusStatConfig: |
| | | KBusSearchChildProc(pKBus); |
| | | break; |
| | | case KBusStatReady: |
| | | pKBus->MyStat = KBusStatRunning; |
| | | pKBus->nRunStep = KBusRunStepBroadCastCfg; |
| | | pKBus->TimeOutCount=0; |
| | | break; |
| | | case KBusStatRunning: |
| | | KBusDataPoll(pKBus); |
| | | switch(pKBus->nRunStep) { |
| | | case KBusRunStepBroadCastCfg: |
| | | pKBus->TimeOutCount++; |
| | | if (pKBus->TimeOutCount>4){ |
| | | pKBus->nRunStep = KBusRunStepTimeSync; |
| | | pKBus->TimeOutCount = 0; |
| | | } |
| | | break; |
| | | case KBusRunStepTimeSync: |
| | | pKBus->Datas[0]=tick1&0xff; |
| | | pKBus->Datas[1]=(tick1>>8)&0xff; |
| | | pKBus->Datas[2]=(tick1>>16)&0xff; |
| | | pKBus->Datas[3]=(tick1>>24)&0xff; |
| | | len1=KBusMakePacket((pKBPacket)pKBus->PacketBuf2,0,0xff,cmdSyncTime,pKBus->nSeq,4,pKBus->Datas); |
| | | pKBus->KBusSendPacket(pKBus->PacketBuf2, len1); |
| | | |
| | | pKBus->nRunStep = KBusRunStepTimeSyncWait; |
| | | pKBus->TimeOutCount=0; |
| | | break; |
| | | case KBusRunStepTimeSyncWait: |
| | | pKBus->TimeOutCount++; |
| | | if (pKBus->TimeOutCount>2){ |
| | | pKBus->nRunStep = KBusRunStepMultiDataPoll; |
| | | pKBus->TimeOutCount=0; |
| | | } |
| | | break; |
| | | case KBusRunStepMultiDataPoll: |
| | | pKBus->TimeOutCount++; |
| | | if (pKBus->TimeOutCount>1){ |
| | | pKBus->nCurPollId = 1; |
| | | pKBus->nRunStep = KBusRunStepUniDataPoll; |
| | | pKBus->TimeOutCount=0; |
| | | } |
| | | break; |
| | | case KBusRunStepUniDataPoll: |
| | | KBusDataPoll(pKBus); |
| | | break; |
| | | case KBusRunStepUniDataTranster: |
| | | // çæ¯å¦æè¿ç¨è¯·æ± |
| | | if (pKBus->bReq &&pKBus->nReqReCount<1) |
| | | { |
| | | pKBus->nReqDataHdr[0]=0; |
| | | pKBus->nReqDataHdr[1]=0; |
| | | pKBus->nReqDataHdr[2]=pKBus->nReqSvrId; |
| | | pKBus->nReqDataHdr[3]=pKBus->nReqParam; |
| | | // [4] Addr |
| | | // [5] Addr |
| | | // [6] nCount |
| | | DataLen = pKBus->nReqDataLen+2; |
| | | len1=KBusMakePacket((pKBPacket)pKBus->PacketBuf2,0,pKBus->nReqChildId,cmdRemoteReq,pKBus->nSeq,DataLen,&pKBus->nReqDataHdr[2]); |
| | | pKBus->KBusSendPacket(pKBus->PacketBuf2, len1); |
| | | pKBus->nReqReCount++; |
| | | }else { |
| | | |
| | | } |
| | | pKBus->nRunStep = KBusRunStepUniDataTransterWait; |
| | | pKBus->TimeOutCount=0; |
| | | break; |
| | | case KBusRunStepUniDataTransterWait: |
| | | pKBus->TimeOutCount++; |
| | | if (pKBus->TimeOutCount>4){ |
| | | if (pKBus->bReq ==1) {pKBus->bReq = 3;} |
| | | pKBus->nRunStep = KBusRunStepBroadCastCfg; |
| | | pKBus->TimeOutCount=0; |
| | | |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | int KBusDataPoll(stKBusDef * pKBus) |
| | | { |
| | | int iRet = 0; |
| | | uint32_t tick1=HAL_GetTick(); |
| | | uint32_t thisuS=GetuS(); |
| | | uint32_t tick1=GetTick(); |
| | | // uint32_t thisuS=GetuS(); |
| | | int len1=0; |
| | | int nThisPollId = pKBus->nCurPollId; |
| | | |
| | | stChnStat * pChnStat = &pKBus->KBusChnStats[nThisPollId]; |
| | | if ((pKBus->bMasterRecved && pKBus->bMasterRecvOK && thisuS-pKBus->SendTimeuS>50) || thisuS-pKBus->SendTimeuS>1000u) |
| | | if (!pKBus->bMasterSent){ |
| | | pKBus->Datas[0]=KBusMem.WLYB[nThisPollId -1 ]; |
| | | for (int i=1; i*8 < pKBus->DeviceInfos[nThisPollId].OutBitCount;i++){ |
| | | pKBus->Datas[0+i]=KBusMem.WLYB[nThisPollId -1 + i]; |
| | | } |
| | | |
| | | // pKBus->Datas[1]=KBusMem.WLYB[nThisPollId ];; |
| | | // pKBus->Datas[2]=KBusMem.WLYB[nThisPollId + 1 ]; //KBusChnStats[nCurPollId].Stat; |
| | | // pKBus->Datas[3]=KBusMem.WLYB[nThisPollId + 2 ]; |
| | | pKBus->Datas[4]=tick1&0xff; |
| | | pKBus->Datas[5]=(tick1>>8)&0xff; |
| | | pKBus->Datas[6]=(tick1>>16)&0xff; |
| | | pKBus->Datas[7]=(tick1>>24)&0xff; |
| | | |
| | | pKBus->SendTimeTick=tick1; |
| | | unStatus ThisStatus; |
| | | ThisStatus.nStatus= pChnStat->MStat; |
| | | ThisStatus.nSeq = pKBus->nSeq; |
| | | //ThisStatus.nErr1 = (pChnStat->MStat==0); |
| | | // ThisStatus.nErr1 = 0; |
| | | len1=KBusMakePacket((pKBPacket)pKBus->PacketBuf2,0,nThisPollId,cmdUniExChgData,ThisStatus.nStatus,8,pKBus->Datas); |
| | | // LL_USART_SetBaudRate(USART2,48000000,LL_USART_OVERSAMPLING_8,DefaultUart2Baud); |
| | | |
| | | pKBus->KBusSendPacket(pKBus->PacketBuf2, len1); |
| | | pChnStat->SendPackets++; |
| | | pChnStat->SendTimeInterval=pKBus->SendTimeTick - pChnStat->LastSentTimeTick; |
| | | pChnStat->LastSentTimeTick=pKBus->SendTimeTick; |
| | | // PacketLength = len1; |
| | | pKBus->SendTime=tick1; |
| | | pKBus->bMasterSent = 1; |
| | | pKBus->bMasterRecved=0; |
| | | pKBus->bMasterRecvOK=0; |
| | | // LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_5); |
| | | //ToggleErrLed(); |
| | | // ToggleOut8(); |
| | | }else |
| | | { |
| | | |
| | | if ((pKBus->bMasterRecved && pKBus->bMasterRecvOK && tick1-pKBus->SendTimeTick>1) || tick1-pKBus->SendTimeTick>KBUS_WAIT_TIME_OUT2) |
| | | { |
| | | if (!pKBus->bMasterRecvOK) |
| | | { |
| | | pKBus->TimeOutCount++; |
| | | Uart2Stat.TimeOutErr++; |
| | | // Uart2Stat.TimeOutErr++; |
| | | pChnStat->LostPackets++; |
| | | pChnStat->CtnLstPkts++; |
| | | if (!pKBus->bMasterRecved) {pChnStat->TimeOutErr++;} |
| | |
| | | {pChnStat->MaxCtnLstPkts = pChnStat->CtnLstPkts;} |
| | | if (pChnStat->CtnLstPkts>3) |
| | | { |
| | | pChnStat->Stat = 0; |
| | | pChnStat->MStat = 0; |
| | | pKBus->ErrStat=200; |
| | | KBusMem.WLXB[nThisPollId]=0; |
| | | if (pKBus->KBusEvCBFunc) pKBus->KBusEvCBFunc(pKBus, KBusEvStateChange,0,0); |
| | |
| | | // LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_7); |
| | | }else |
| | | { |
| | | pChnStat->Stat=1; |
| | | // pChnStat->CtnLstPkts = 0; |
| | | // pKBus->KBusChnStats[nThisPollId].CtnLstPkts=0; |
| | | pChnStat->MStat=1; |
| | | |
| | | pKBus->RunStat=100; |
| | | } |
| | | if (pKBus->DeviceInfos[nThisPollId].InBitCount >8 || pKBus->DeviceInfos[nThisPollId].OutBitCount > 8) { |
| | | //nThisPollId += 2; |
| | | nThisPollId ++; |
| | | nThisPollId += 2; |
| | | //nThisPollId ++; |
| | | }else { |
| | | nThisPollId ++; |
| | | } |
| | |
| | | // æ°æ®è½®è¯¢å®, å¨æé´é,æå
¥å
¶ä»å¤çæ°æ®. æ¯æ¬¡å¤ççæ¶é´é´é, ä¸é® ä¸ç æ¶é´. |
| | | // åæå ç§ç±»å, è½®æµè¿è¡ |
| | | // æ¶é´åæ¥, æ¥è¯¢æ°åæº, å¤ç带å¤æ°æ®, ,å¤çé¢å¤çäºæ
, æè
è·³è¿. |
| | | pKBus->CircleTime=thisuS-pKBus->LastCircleStartTime; |
| | | pKBus->LastCircleStartTime=thisuS; |
| | | pKBus->CircleTime=tick1-pKBus->LastCircleStartTime; |
| | | pKBus->LastCircleStartTime=tick1; |
| | | pKBus->nSeq++; |
| | | nThisPollId=1; |
| | | GoStep(pKBus,KBusRunStepUniDataTranster); |
| | | //nThisPollId=1; |
| | | }else { |
| | | pKBus->nCurPollId = nThisPollId; |
| | | } |
| | | pKBus->nCurPollId = nThisPollId; |
| | | |
| | | pKBus->Datas[0]=KBusMem.WLYB[nThisPollId -1 ]; |
| | | pKBus->Datas[1]=KBusMem.WLYB[nThisPollId ];; |
| | | |
| | | pKBus->Datas[2]=KBusMem.WLYB[nThisPollId + 1 ]; //KBusChnStats[nCurPollId].Stat; |
| | | pKBus->Datas[3]=KBusMem.WLYB[nThisPollId + 2 ]; |
| | | pKBus->Datas[4]=tick1&0xff; |
| | | pKBus->Datas[5]=(tick1>>8)&0xff; |
| | | pKBus->Datas[6]=(tick1>>16)&0xff; |
| | | pKBus->Datas[7]=(tick1>>24)&0xff; |
| | | |
| | | pKBus->SendTimeuS=thisuS; |
| | | unStatus nStatus; |
| | | nStatus.nSeq = pKBus->nSeq; |
| | | nStatus.nErr1 = (pKBus->KBusChnStats[nThisPollId].Stat==0); |
| | | |
| | | |
| | | len1=KBusMakePacket((pKBPacket)pKBus->PacketBuf1,0,nThisPollId,cmdUniExChgData,nStatus.nStatus,8,pKBus->Datas); |
| | | // LL_USART_SetBaudRate(USART2,48000000,LL_USART_OVERSAMPLING_8,DefaultUart2Baud); |
| | | |
| | | pKBus->KBusSendPacket(pKBus->PacketBuf1, len1); |
| | | pKBus->KBusChnStats[pKBus->nCurPollId].SendPackets++; |
| | | pKBus->KBusChnStats[pKBus->nCurPollId].SendTimeInterval=pKBus->SendTimeuS-pKBus->KBusChnStats[pKBus->nCurPollId].LastSentTimeuS; |
| | | pKBus->KBusChnStats[pKBus->nCurPollId].LastSentTimeuS=pKBus->SendTimeuS; |
| | | // PacketLength = len1; |
| | | pKBus->SendTime=tick1; |
| | | |
| | | pKBus->bMasterRecved=0; |
| | | pKBus->bMasterRecvOK=0; |
| | | // LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_5); |
| | | //ToggleErrLed(); |
| | | // ToggleOut8(); |
| | | |
| | | pKBus->bMasterSent = 0; |
| | | } |
| | | |
| | | } |
| | | return iRet; |
| | | } |
| | | |
| | | int KBusSlaveFunc(stKBusDef * pKBus) |
| | | { |
| | | int ThisuS=GetuS(); |
| | | int thisRecvTime=pKBus->RecvTimeuS; |
| | | // int ThisuS=GetuS(); |
| | | int ThisTick = GetTick(); |
| | | int thisRecvTime=pKBus->RecvTimeTick; |
| | | if (pKBus->nStationId >0) { |
| | | if (pKBus->bSlaveRecved) |
| | | { |
| | | pKBus->RunStat=8000; |
| | | pKBus->bSlaveRecved=0; |
| | | }else if ((ThisuS - thisRecvTime) >12000u) |
| | | }else if ((ThisTick - thisRecvTime) > KBUS_SLAVE_TIME_OUT) // 30u |
| | | { |
| | | pKBus->ErrStat=8000; |
| | | }else if ( ThisuS > (thisRecvTime + 12000u)) |
| | | pKBus->ErrStat=7000; |
| | | }else if ( ThisTick > (thisRecvTime + KBUS_SLAVE_TIME_OUT)) // 30u |
| | | { |
| | | pKBus->ErrStat=8000; |
| | | pKBus->ErrStat=7100; |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | |
| | | int KBusCheckPacket(stKBusDef * pKBus, pKBPacket p1, int nLen1) |
| | | { |
| | |
| | | |
| | | if (p3->Sign != KBStartSign) |
| | | { |
| | | Uart2Stat.NotPacketErr++; |
| | | // pKBus->NotPacketErr++; |
| | | KMem.WDB[0x40]=pKBus->nCurPollId; |
| | | KMem.WDB[0x41]=nLen1; |
| | | memcpy(&KMem.WDB[0x42],p1,nLen1); |
| | | |
| | | pKBus->KBusChnStats[pKBus->nCurPollId].NotPkgErr++; |
| | | if (pKBus->KBusDiagnosis) { |
| | | if (pKBus->KBusSnapPos == 0) { |
| | |
| | | int DataLen=p3->DataLen; |
| | | if (DataLen>KBMaxPacketLength) |
| | | { |
| | | Uart2Stat.LengthErr++; |
| | | // Uart2Stat.LengthErr++; |
| | | pKBus->KBusChnStats[pKBus->nCurPollId].PkgLenErr++; |
| | | return -1; |
| | | } |
| | |
| | | //len4=sprintf(str3,"%d < %d + %d \r\n",len2,DataLen,sizeof(stKBPacket)); |
| | | //PutStr(str3,len4); |
| | | pKBus->KBusChnStats[pKBus->nCurPollId].PkgLenErr++; |
| | | Uart2Stat.LengthErr++; |
| | | // Uart2Stat.LengthErr++; |
| | | return -3; //not long enough |
| | | } |
| | | // if (p3->data[DataLen+1] != EndSign) |
| | |
| | | unsigned char thisBCC=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | if (thisBCC != p3->data[DataLen]) |
| | | {//BCC Error; |
| | | Uart2Stat.BCCerr++; |
| | | // Uart2Stat.BCCerr++; |
| | | pKBus->KBusChnStats[pKBus->nCurPollId].BCCErr++; |
| | | return -4; |
| | | } |
| | |
| | | |
| | | if (p3->Sign != KBStartSign) |
| | | { |
| | | Uart2Stat.NotPacketErr++; |
| | | // Uart2Stat.NotPacketErr++; |
| | | pKBus->KBusChnStats[0].ClientNotPktErr++; |
| | | return -1; |
| | | } |
| | | int DataLen=p3->DataLen; |
| | | if (DataLen>KBMaxPacketLength) |
| | | { |
| | | Uart2Stat.LengthErr++; |
| | | // Uart2Stat.LengthErr++; |
| | | pKBus->KBusChnStats[0].ClientPkgLenErr++; |
| | | return -1; |
| | | } |
| | |
| | | //len4=sprintf(str3,"%d < %d + %d \r\n",len2,DataLen,sizeof(stKBPacket)); |
| | | //PutStr(str3,len4); |
| | | pKBus->KBusChnStats[0].ClientPkgLenErr++; |
| | | Uart2Stat.LengthErr++; |
| | | // Uart2Stat.LengthErr++; |
| | | return -3; //not long enough |
| | | } |
| | | // if (p3->data[DataLen+1] != EndSign) |
| | |
| | | unsigned char thisBCC=KBusBCC(p1,sizeof(stKBPacket)+DataLen-1); |
| | | if (thisBCC != p3->data[DataLen]) |
| | | {//BCC Error; |
| | | Uart2Stat.BCCerr++; |
| | | // Uart2Stat.BCCerr++; |
| | | pKBus->KBusChnStats[0].ClientBccErr++; |
| | | return -4; |
| | | } |
| | |
| | | //LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_6); |
| | | int nCurPollId = pKBus->nCurPollId; |
| | | int ChildId=p1->SrcAddr; |
| | | int ThisuS = GetuS(); |
| | | // int ThisuS = GetuS(); |
| | | int ThisTick = GetTick(); |
| | | unsigned char nIndex; |
| | | switch (p1->nCMD) |
| | | { |
| | |
| | | break; |
| | | case cmdQueryRply: |
| | | DataLen=sizeof(stDeviceInfo); |
| | | KBusUpdateChildInfo(pKBus,pKBus->nCurPollId,(stDeviceInfo *)&p1->data[0]); |
| | | pKBus->KBusChnStats[0].ClientSendPkts++; |
| | | KBusUpdateChildInfo(pKBus,nCurPollId,(stDeviceInfo *)&p1->data[0]); |
| | | pKBus->KBusChnStats[nCurPollId].ClientSendPkts++; |
| | | break; |
| | | case cmdSetCfgRply: |
| | | break; |
| | |
| | | case cmdPing: |
| | | break; |
| | | case cmdPingReply: |
| | | pKBus->DelayuS=ThisuS-pKBus->SendTimeuS; |
| | | if (pKBus->DelayuS > pKBus->nMaxDelayuS) pKBus->nMaxDelayuS = pKBus->DelayuS; |
| | | pKBus->DelayTick = ThisTick - pKBus->SendTimeTick; |
| | | if (pKBus->DelayTick > pKBus->nMaxDelayTick) pKBus->nMaxDelayTick = pKBus->DelayTick; |
| | | |
| | | KBusMem.WLXB[ChildId]=p1->data[0]; |
| | | |
| | | //RunStat=100; |
| | | pKBus->KBusChnStats[pKBus->nCurPollId].CtnLstPkts=0; |
| | | pKBus->KBusChnStats[pKBus->nCurPollId].Delay=pKBus->DelayuS; |
| | | if (pKBus->DelayuS > pKBus->KBusChnStats[pKBus->nCurPollId].MaxDelay) |
| | | pKBus->KBusChnStats[pKBus->nCurPollId].MaxDelay=pKBus->DelayuS; |
| | | pKBus->KBusChnStats[nCurPollId].CtnLstPkts=0; |
| | | pKBus->KBusChnStats[nCurPollId].Delay=pKBus->DelayTick; |
| | | if (pKBus->DelayTick > pKBus->KBusChnStats[nCurPollId].MaxDelay) |
| | | pKBus->KBusChnStats[nCurPollId].MaxDelay=pKBus->DelayTick; |
| | | //PutOutput(outputvalue); |
| | | pKBus->bMasterRecvOK=1; |
| | | break; |
| | |
| | | |
| | | break; |
| | | case cmdExChgDataReply: |
| | | pKBus->DelayuS=ThisuS-pKBus->SendTimeuS; |
| | | if (pKBus->DelayuS > pKBus->nMaxDelayuS) pKBus->nMaxDelayuS = pKBus->DelayuS; |
| | | |
| | | KBusMem.WLXB[ChildId-1]=p1->data[0];; |
| | | KBusMem.WLXB[ChildId ]=p1->data[1]; |
| | | KBusMem.WLXB[ChildId+1]=p1->data[2]; |
| | | KBusMem.WLXB[ChildId+2]=p1->data[3];; |
| | | KBusMem.WLXB[ChildId+3]=p1->data[4]; |
| | | KBusMem.WLXB[ChildId+4]=p1->data[5]; |
| | | KBusMem.WLXB[ChildId+5]=p1->data[6]; |
| | | KBusMem.WLXB[ChildId+6]=p1->data[7]; |
| | | |
| | | pKBus->DelayTick = ThisTick - pKBus->SendTimeTick; |
| | | if (pKBus->DelayTick > pKBus->nMaxDelayTick) pKBus->nMaxDelayTick = pKBus->DelayTick; |
| | | KBusMem.WLXB[ChildId - 1 ]=p1->data[0]; |
| | | for (int i=1; i*8 < pKBus->DeviceInfos[ChildId].InBitCount;i++){ |
| | | KBusMem.WLXB[ChildId - 1 + i]=p1->data[0 + i];; |
| | | } |
| | | // KBusMem.WLXB[ChildId+0]=p1->data[1]; |
| | | // KBusMem.WLXB[ChildId+1]=p1->data[2]; |
| | | // KBusMem.WLXB[ChildId+2]=p1->data[3];; |
| | | // KBusMem.WLXB[ChildId+3]=p1->data[4]; |
| | | // KBusMem.WLXB[ChildId+4]=p1->data[5]; |
| | | // KBusMem.WLXB[ChildId+5]=p1->data[6]; |
| | | // KBusMem.WLXB[ChildId+6]=p1->data[7]; |
| | | //Call Back |
| | | if (pKBus->KBusEvCBFunc) pKBus->KBusEvCBFunc(pKBus, KBusEvDataUpdate,0,0); |
| | | //RunStat=100; |
| | | pKBus->KBusChnStats[nCurPollId].CtnLstPkts=0; |
| | | pKBus->KBusChnStats[nCurPollId].Delay=pKBus->DelayuS; |
| | | if (pKBus->DelayuS > pKBus->KBusChnStats[nCurPollId].MaxDelay) |
| | | pKBus->KBusChnStats[nCurPollId].MaxDelay=pKBus->DelayuS; |
| | | pKBus->KBusChnStats[nCurPollId].Delay=pKBus->DelayTick; |
| | | if (pKBus->DelayTick > pKBus->KBusChnStats[nCurPollId].MaxDelay) |
| | | pKBus->KBusChnStats[nCurPollId].MaxDelay=pKBus->DelayTick; |
| | | //PutOutput(outputvalue); |
| | | |
| | | if (DataLen>=14) { |
| | |
| | | pKBus->bMasterRecvOK=1; |
| | | |
| | | break; |
| | | |
| | | case cmdRemoteReqReply: |
| | | pKBus->bReq = 2; |
| | | |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | |
| | | Len1--; |
| | | } |
| | | |
| | | Uart2Stat.OKPacket++; |
| | | int DataLen=p1->DataLen; |
| | | // Uart2Stat.OKPacket++; |
| | | unsigned short Addr; |
| | | unsigned short DataLen=p1->DataLen; |
| | | //int nSrcAddr=p1->SrcAddr; |
| | | int nDstHost=p1->DstHost; |
| | | |
| | |
| | | // KBusSlaveRecved=1; |
| | | |
| | | pKBPacket p2=(pKBPacket)pKBus->PacketBuf2; |
| | | |
| | | void * pData = 0; |
| | | int PacketLen=0; |
| | | unsigned char nIndex;// = p1->nStatus & 0x07; |
| | | if (nDstHost!=pKBus->nStationId && nDstHost != 0xff) |
| | |
| | | pKBus->KBusChnStats[0].ClientMisIdPkts++; |
| | | return -1; |
| | | } |
| | | int ThisuS = GetuS(); |
| | | if (nDstHost==pKBus->nStationId || nDstHost==0xff) |
| | | // int ThisuS = GetuS(); |
| | | int ThisTick = GetTick(); |
| | | if (nDstHost==0xff){ |
| | | pKBus->RecvTimeTick=ThisTick; |
| | | pKBus->bSlaveRecved=1; |
| | | switch (p1->nCMD) |
| | | { |
| | | case cmdNone: |
| | | break; |
| | | case cmdBroadCastCfg: |
| | | |
| | | break; |
| | | case cmdMuExchgData: |
| | | |
| | | break; |
| | | case cmdToSafeMode: |
| | | |
| | | break; |
| | | case cmdHeartBeat: |
| | | break; |
| | | case cmdSyncRead: |
| | | break; |
| | | case cmdSyncWrite: |
| | | break; |
| | | case cmdSequenRead: |
| | | break; |
| | | case cmdSyncTime: |
| | | pKBus->nSlaveTick=p1->data[0]+(p1->data[1]<<8)+(p1->data[2]<<16)+(p1->data[3]<<24); |
| | | if (pKBus->KBusEvCBFunc) pKBus->KBusEvCBFunc(pKBus, KBusEvTimeSync,0,0); |
| | | break; |
| | | case cmdRemoteReq: //æ¶å°Remoteè¯·æ± |
| | | // KBusSlaveRunRemoteReq(pKBus,p1->data[0],p1->data, DataLen); |
| | | // data[0] -> reqSvr; |
| | | // data[1] -> param; |
| | | switch (p1->data[0]) { |
| | | case ReqBlinkLED: |
| | | case ReqTransBlink: |
| | | KMRunStat.bLEDFlick=p1->data[1]; |
| | | DataLen = 0; |
| | | PacketLen=KBusMakePacket(p2,pKBus->nStationId,0,cmdRemoteReqReply,p1->nStatus,DataLen,p1->data); |
| | | pKBus->KBusSendPacket((uchar *)p2, PacketLen); |
| | | break; |
| | | case ReqUpdateFirm: //37个åè |
| | | DataLen = 0; |
| | | PacketLen=KBusMakePacket(p2,pKBus->nStationId,0,cmdRemoteReqReply,p1->nStatus,DataLen,p1->data); |
| | | pKBus->KBusSendPacket((uchar *)p2, PacketLen); |
| | | pData = &p1->data[5]; |
| | | Addr = p1->data[2] + (p1->data[3] <<8); |
| | | DataLen = p1->data[4] ; |
| | | KMRunService(p1->data[0],Addr,0,&pData,&DataLen); |
| | | DataLen=0; |
| | | break; |
| | | case ReqUpdateFirmInfo: |
| | | DataLen = 0; |
| | | PacketLen=KBusMakePacket(p2,pKBus->nStationId,0,cmdRemoteReqReply,p1->nStatus,DataLen,p1->data); |
| | | pKBus->KBusSendPacket((uchar *)p2, PacketLen); |
| | | pData = &p1->data[5]; |
| | | Addr = p1->data[2] + (p1->data[3] <<8); |
| | | DataLen = p1->data[4] ; |
| | | KMRunService(p1->data[0],Addr,0,&pData,&DataLen); |
| | | DataLen=0; |
| | | break; |
| | | default: |
| | | pData = &p1->data[5]; |
| | | Addr = p1->data[2] + (p1->data[3] <<8); |
| | | DataLen = p1->data[4] ; |
| | | KMRunService(p1->data[0],p1->data[1],0,&pData,&DataLen); |
| | | DataLen = 0; |
| | | PacketLen=KBusMakePacket(p2,pKBus->nStationId,0,cmdRemoteReqReply,p1->nStatus,DataLen,p1->data); |
| | | pKBus->KBusSendPacket((uchar *)p2, PacketLen); |
| | | DataLen=0; |
| | | |
| | | break; |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | if (nDstHost==pKBus->nStationId) |
| | | { |
| | | pKBus->RecvTimeuS=ThisuS; |
| | | pKBus->RecvTimeTick=ThisTick; |
| | | pKBus->bSlaveRecved=1; |
| | | switch (p1->nCMD) |
| | | { |
| | |
| | | //PutOutput(outputvalue); |
| | | //memcpy(DispBuf,p1->data+2,8); |
| | | p1->data[0]=KBusMem.WLXB[0]; |
| | | pKBus->RecvTimeuS=ThisuS; |
| | | //pKBus->RecvTimeuS=ThisuS; |
| | | PacketLen=KBusMakePacket(p2,pKBus->nStationId,0,cmdPingReply,p1->nStatus,DataLen,p1->data); |
| | | pKBus->KBusChnStats[0].ClientSendPkts++; |
| | | pKBus->KBusSendPacket((uchar *)p2, PacketLen); |
| | |
| | | KBusMem.WLYB[2]=p1->data[2]; |
| | | KBusMem.WLYB[3]=p1->data[3]; |
| | | |
| | | pKBus->nSlaveTick=p1->data[4]+(p1->data[5]<<8);//+(p1->data[6]<<16)+(p1->data[7]<<24); |
| | | // pKBus->nSlaveTick=p1->data[4]+(p1->data[5]<<8);//+(p1->data[6]<<16)+(p1->data[7]<<24); |
| | | |
| | | if (pKBus->KBusEvCBFunc) pKBus->KBusEvCBFunc(pKBus, KBusEvTimeSync,0,0); |
| | | |
| | |
| | | if (pKBus->nClientDataIndex >= 10) { pKBus->nClientDataIndex=0;} |
| | | unStatus nStatus; |
| | | nStatus.nStatus = p1->nStatus; |
| | | if (nStatus.nErr1) { pKBus->ErrStat=8000;} |
| | | if (nStatus.nErr1) { pKBus->ErrStat=8100;} |
| | | PacketLen=KBusMakePacket(p2,pKBus->nStationId,0,cmdExChgDataReply,p1->nStatus,DataLen,p1->data); |
| | | pKBus->KBusChnStats[0].ClientSendPkts++; |
| | | pKBus->KBusSendPacket((uchar *)p2, PacketLen); |
| | |
| | | case cmdSequenRead: |
| | | break; |
| | | case cmdSyncTime: |
| | | pKBus->nSlaveTick=p1->data[0]+(p1->data[1]<<8)+(p1->data[2]<<16)+(p1->data[3]<<24); |
| | | if (pKBus->KBusEvCBFunc) pKBus->KBusEvCBFunc(pKBus, KBusEvTimeSync,0,0); |
| | | break; |
| | | |
| | | case cmdRemoteReq: //æ¶å°Remoteè¯·æ± |
| | | // KBusSlaveRunRemoteReq(pKBus,p1->data[0],p1->data, DataLen); |
| | | // data[0] -> reqSvr; |
| | | // data[1] -> param; |
| | | switch (p1->data[0]) { |
| | | case ReqBlinkLED: |
| | | case ReqTransBlink: |
| | | KMRunStat.bLEDFlick=p1->data[1]; |
| | | DataLen = 0; |
| | | PacketLen=KBusMakePacket(p2,pKBus->nStationId,0,cmdRemoteReqReply,p1->nStatus,DataLen,p1->data); |
| | | pKBus->KBusSendPacket((uchar *)p2, PacketLen); |
| | | break; |
| | | case ReqUpdateFirm: //37个åè |
| | | DataLen = 0; |
| | | PacketLen=KBusMakePacket(p2,pKBus->nStationId,0,cmdRemoteReqReply,p1->nStatus,DataLen,p1->data); |
| | | pKBus->KBusSendPacket((uchar *)p2, PacketLen); |
| | | pData = &p1->data[5]; |
| | | Addr = p1->data[2] + (p1->data[3] <<8); |
| | | DataLen = p1->data[4] ; |
| | | KMRunService(p1->data[0],Addr,0,&pData,&DataLen); |
| | | DataLen=0; |
| | | break; |
| | | case ReqUpdateFirmInfo: |
| | | DataLen = 0; |
| | | PacketLen=KBusMakePacket(p2,pKBus->nStationId,0,cmdRemoteReqReply,p1->nStatus,DataLen,p1->data); |
| | | pKBus->KBusSendPacket((uchar *)p2, PacketLen); |
| | | pData = &p1->data[5]; |
| | | Addr = p1->data[2] + (p1->data[3] <<8); |
| | | DataLen = p1->data[4] ; |
| | | KMRunService(p1->data[0],Addr,0,&pData,&DataLen); |
| | | DataLen=0; |
| | | break; |
| | | default: |
| | | pData = &p1->data[5]; |
| | | Addr = p1->data[2] + (p1->data[3] <<8); |
| | | DataLen = p1->data[4] ; |
| | | KMRunService(p1->data[0],p1->data[1],0,&pData,&DataLen); |
| | | DataLen = 0; |
| | | PacketLen=KBusMakePacket(p2,pKBus->nStationId,0,cmdRemoteReqReply,p1->nStatus,DataLen,p1->data); |
| | | pKBus->KBusSendPacket((uchar *)p2, PacketLen); |
| | | DataLen=0; |
| | | |
| | | break; |
| | | } |
| | | break; |
| | | |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | int KBusSlaveRunRemoteReq(stKBusDef * pKBus, int nReqSvrId, unsigned char * pData , int Len1) |
| | | { |
| | | int PacketLen; |
| | | switch (nReqSvrId) { |
| | | case ReqTransBlink: |
| | | KMRunStat.bLEDFlick=5; |
| | | // PacketLen=KBusMakePacket(pKBus->PacketBuf2,pKBus->nStationId,0,cmdRemoteReq,p1->nStatus,DataLen,p1->data); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | |
| | | Result=KBusCheckPacket(pKBus, p1, Len1); |
| | | if (Result != S_OK) |
| | | { |
| | | |
| | | return Result; |
| | | } |
| | | pKBus->bMasterRecvOK=1; |
| | |
| | | #endif |
| | | //extern stWLRunStat KwRunStat; |
| | | |
| | | unsigned char KLPacketBuf1[256]; |
| | | //unsigned char KLPacketBuf1[256]; |
| | | unsigned char KLPacketBuf2[256]; |
| | | |
| | | unsigned char KLBufferIn[16]={0}; |
| | |
| | | int KLThisuS=0; |
| | | int KLRecvTimeuS=0; |
| | | |
| | | stPortDef KLinkPortReg1 = {.nPortHardType = 3,.nPortUseType = 2, .bEnable = 1, .bRunning =1, .StationId = 1, .bMaster = 0}; |
| | | |
| | | int KLinkInit(int n) |
| | | { |
| | | |
| | | KMRegisterPort(0,&KLinkPortReg1); |
| | | return 0; |
| | | } |
| | | unsigned char KLBCC(void const * pData, int nSize) |
| | | { |
| | | unsigned char k; |
| | |
| | | unsigned short nByteAddr=0; |
| | | unsigned short nBitAddr=0; |
| | | unsigned short DataLen=0; //p1->LoadLen; |
| | | unsigned short nValue=0; |
| | | //int nSrcAddr=p1->SrcAddr; |
| | | |
| | | nKLStatus.nSEQ = ((pKLStat)(&(p1->Stat)))->nSEQ;; |
| | |
| | | else if (nDataType == KLDataTypeWR) { pData=KMem.WR+nWordAddr; } |
| | | else if (nDataType == KLDataTypeWLX) { pData=KMem.WLX+nWordAddr; } |
| | | else if (nDataType == KLDataTypeWLY) { pData=KMem.WLY+nWordAddr; } |
| | | else if (nDataType == KLDataTypeSV) { pData=KMem.SV+nWordAddr; } |
| | | else if (nDataType == KLDataTypeEV) { pData=KMem.EV+nWordAddr; } |
| | | #if (ENABLE_PLC) |
| | | else if (nDataType == KLDataTypeSV) { pData=PLCMem.SV+nWordAddr; } |
| | | else if (nDataType == KLDataTypeEV) { pData=PLCMem.EV+nWordAddr; } |
| | | #endif |
| | | else if (nDataType == KLDataTypeTest) { pData=KMem.SDT+nWordAddr; } |
| | | else if (nDataType == KLDataTypeWDT) { pData=KMem.WDT+nWordAddr; } |
| | | else if (nDataType == KLDataTypeKBD) { pData=(unsigned short *)&KBus1.KBusChnStats +nWordAddr; } |
| | |
| | | else if (nDataType == KLDataTypeWR) { pData=KMem.WR+nWordAddr; } |
| | | else if (nDataType == KLDataTypeWLX) { pData=KMem.WLX+nWordAddr; } |
| | | else if (nDataType == KLDataTypeWLY) { pData=KMem.WLY+nWordAddr; } |
| | | else if (nDataType == KLDataTypeSV) { pData=KMem.SV+nWordAddr; DataLen=0;} |
| | | else if (nDataType == KLDataTypeEV) { pData=KMem.EV+nWordAddr; DataLen=0;} |
| | | #if (ENABLE_PLC) |
| | | else if (nDataType == KLDataTypeSV) { pData=PLCMem.SV+nWordAddr; DataLen=0;} |
| | | else if (nDataType == KLDataTypeEV) { pData=PLCMem.EV+nWordAddr; DataLen=0;} |
| | | #endif |
| | | else if (nDataType == KLDataTypeTest) { pData=KMem.SDT+nWordAddr; DataLen=0;} |
| | | else if (nDataType == KLDataTypeWDT) { pData=KMem.WDT+nWordAddr; DataLen=0;} |
| | | else if (nDataType == KLDataTypeKBD) { pData=(unsigned short *)KBus1.KBusChnStats +nWordAddr; DataLen=0;} |
| | |
| | | else if (nDataType == KLCoilTypeR) { rData[0] = ((KMem.WR[nBitAddr>>4]&(1<<(nBitAddr&0x0f)))>0);} |
| | | else if (nDataType == KLCoilTypeLX) { rData[0] = ((KMem.WLX[nBitAddr>>4]&(1<<(nBitAddr&0x0f)))>0);} |
| | | else if (nDataType == KLCoilTypeLY) { rData[0] = ((KMem.WLY[nBitAddr>>4]&(1<<(nBitAddr&0x0f)))>0);} |
| | | else if (nDataType == KLCoilTypeT) { rData[0] = KMem.Timers[nBitAddr].bTon;} |
| | | else if (nDataType == KLCoilTypeC) { rData[0] = KMem.Timers[nBitAddr].bTon;} |
| | | #if (ENABLE_PLC) |
| | | else if (nDataType == KLCoilTypeT) { rData[0] = PLCMem.Timers[nBitAddr].bTon;} |
| | | else if (nDataType == KLCoilTypeC) { rData[0] = PLCMem.Timers[nBitAddr].bTon;} |
| | | #endif |
| | | else if (nDataType == KLCoilTypeSR) {rData[0] = ((KMem.WSR[nBitAddr>>4]&(1<<(nBitAddr&0x0f)))>0);} |
| | | |
| | | else if (nDataType == KLCoilTypeLR) { rData[0] = 0;} |
| | |
| | | else if (nDataType == KLCoilTypeR) { SetBitValue( &KMem.WR[nBitAddr>>4],nBitAddr&0x0f,p1->Params[2]);} |
| | | else if (nDataType == KLCoilTypeLX) {SetBitValue( &KMem.WLX[nBitAddr>>4],nBitAddr&0x0f,p1->Params[2]);} |
| | | else if (nDataType == KLCoilTypeLY) {SetBitValue( &KMem.WLY[nBitAddr>>4],nBitAddr&0x0f,p1->Params[2]);} |
| | | else if (nDataType == KLCoilTypeT) { KMem.Timers[nBitAddr].bTon = p1->Params[2];} |
| | | else if (nDataType == KLCoilTypeC) { KMem.Timers[nBitAddr].bTon = p1->Params[2];} |
| | | else if (nDataType == KLCoilTypeC) { KMem.Timers[nBitAddr].bTon = p1->Params[2];} |
| | | #if (ENABLE_PLC) |
| | | else if (nDataType == KLCoilTypeT) { PLCMem.Timers[nBitAddr].bTon = p1->Params[2];} |
| | | else if (nDataType == KLCoilTypeC) { PLCMem.Timers[nBitAddr].bTon = p1->Params[2];} |
| | | #endif |
| | | else if (nDataType == KLCoilTypeLR) { SetBitValue( &KMem.WSR[nBitAddr>>4],nBitAddr&0x0f,p1->Params[2]);;} |
| | | else {rData[0]=0;} |
| | | DataLen=0; |
| | |
| | | case KLCmdReadBits: |
| | | break; |
| | | case KLCmdWriteBits: |
| | | break; |
| | | #if (ENABLE_PLC) |
| | | case KLCmdGetMode: |
| | | rData[0]= PLCMem.bPLCRunning; |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,p1->nCMD,1,rData); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | break; |
| | | case KLCmdChgMode: |
| | | if (nDataType ==0) {StopPLC();} |
| | |
| | | nWordAddr=p1->Params[0]+ (p1->Params[1]<<8); |
| | | DataLen= p1->Params[2]; |
| | | if (nDataType==0){ |
| | | pData = (unsigned short *)STORE_PRG_BASE + nWordAddr; |
| | | pData = (unsigned short *)(&((stStoredBinProgs *)STORE_PRG_BASE)->BinInstrcns) + nWordAddr; |
| | | } else if (nDataType==1){ |
| | | pData = (unsigned short *)ALT_PRG_BASE + nWordAddr; |
| | | pData = (unsigned short *)(&((stStoredBinProgs *)ALT_PRG_BASE)->BinInstrcns) + nWordAddr; |
| | | } else if (KMRunStat.nBinProgBank == 0) { |
| | | pData = (unsigned short *)STORE_PRG_BASE + nWordAddr; |
| | | pData = (unsigned short *)(&((stStoredBinProgs *)STORE_PRG_BASE)->BinInstrcns) + nWordAddr; |
| | | }else { |
| | | pData = (unsigned short *)ALT_PRG_BASE + nWordAddr; |
| | | pData = (unsigned short *)(&((stStoredBinProgs *)ALT_PRG_BASE)->BinInstrcns) + nWordAddr; |
| | | } |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,p1->nCMD,DataLen,pData); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | |
| | | break; |
| | | case KLCmdStartPLCProgram: |
| | | DataLen=nDataType; |
| | | // KLBufferIn[0]=p1->Params[0]; |
| | | // p1->Params[0]=KLBufferOut[0]; |
| | | if (PLCMem.bPLCRunning) PLCMem.bPLCRunning=0; |
| | | |
| | | DataLen=p1->Params[0] + (p1->Params[1] <<8); //Program Size |
| | | nValue = p1->Params[2] + (p1->Params[3] <<8); // CRC |
| | | //if (PLCMem.bPLCRunning) StopPLC(); |
| | | StartPLCProgram(nDataType, DataLen, nValue); |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,KLCmdStartPLCProgram,0,0); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | |
| | | |
| | | break; |
| | | case KLCmdWritePLCProgram: |
| | | if (PLCMem.bPLCRunning) PLCMem.bPLCRunning=0; |
| | | nWordAddr=p1->Params[0]+ (p1->Params[1]<<8); |
| | | DataLen= p1->Params[2]; |
| | | |
| | | //DataLen=16; |
| | | for (int i=0;i<DataLen;i++) |
| | | {KLPacketBuf2[i]=p1->Params[4+i];} |
| | | WriteProgram(nWordAddr, KLPacketBuf2, DataLen,nDataType); |
| | | WritePLCProgram(nDataType, nWordAddr, &p1->Params[4], DataLen); |
| | | DataLen=4; |
| | | *((int *)(&rData[0]))=(long)(p1->Params+4); |
| | | // *((int *)(&rData[0]))=(long)(p1->Params+4); |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,KLCmdWritePLCProgram,0,0); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | break; |
| | | case KLCmdFinishPLCProgram: |
| | | nWordAddr=p1->Params[0]+ (p1->Params[1]<<8); //Program Size; |
| | | DataLen=nDataType; |
| | | KMRunStat.nBinProgSize=nWordAddr; |
| | | if (KMRunStat.nBinProgBank ==0) {KMRunStat.nBinProgBank=1;} |
| | | else {KMRunStat.nBinProgBank=0;} |
| | | SaveRunStat(&KMRunStat); |
| | | //PLCMem.bPLCRunning=1; |
| | | // KLBufferIn[0]=p1->Params[0]; |
| | | // p1->Params[0]=KLBufferOut[0]; |
| | | DataLen=p1->Params[0]+ (p1->Params[1]<<8); //Program Size; |
| | | nValue = p1->Params[2] + (p1->Params[3] <<8); //CRC |
| | | FinishiPLCProgram(nDataType, DataLen, nValue); |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,KLCmdFinishPLCProgram,0,0); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | break; |
| | | |
| | | case KLCmdReadPLCAnno: |
| | | nByteAddr=p1->Params[0]+ (p1->Params[1]<<8); |
| | | DataLen= p1->Params[2]; |
| | | pData = ((stStoredAnno *)STORE_PLC_ANNO_BASE)->Annos + nByteAddr; |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,p1->nCMD,DataLen,pData); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | break; |
| | | case KLCmdStartPLCAnno: |
| | | nWordAddr=p1->Params[0]+ (p1->Params[1]<<8); |
| | | DataLen= p1->Params[2]; |
| | | StartPLCAnno(nDataType, DataLen, nValue); |
| | | DataLen=4; |
| | | // *((int *)(&rData[0]))=(long)(p1->Params+4); |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,KLCmdStartPLCAnno,0,0); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | break; |
| | | case KLCmdWritePLCAnno: |
| | | nByteAddr=p1->Params[0]+ (p1->Params[1]<<8); ; |
| | | DataLen = p1->Params[2]; //CRC |
| | | WritePLCAnno(nDataType, nByteAddr, &p1->Params[4], DataLen); |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,KLCmdWritePLCAnno,0,0); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | break; |
| | | case KLCmdFinishPLCAnno: |
| | | DataLen=p1->Params[0]+ (p1->Params[1]<<8); //Program Size; |
| | | nValue = p1->Params[2] + (p1->Params[3] <<8); //CRC |
| | | FinishiPLCAnno(nDataType, DataLen, nValue); |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,KLCmdFinishPLCAnno,0,0); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | break; |
| | | #endif // ENABLE_PLC |
| | | case KLCmdBlinkLED: |
| | | DataLen=nDataType; |
| | | KMRunStat.bLEDFlick=DataLen; |
| | |
| | | |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,KLCmdClearEventLog,0,0); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | __set_PRIMASK(1); //å
³éå
¨å±ä¸æ |
| | | NVIC_SystemReset(); |
| | | KMRunService(ReqReset,0,0,0,0); |
| | | break; |
| | | case KLCmdWriteFirmware: |
| | | nByteAddr=p1->Params[0]+ (p1->Params[1]<<8); |
| | | //pData=(UCHAR *)(&storedKMSysCfg.theKMSysCfg)+nByteAddr; |
| | | DataLen = p1->Params[2]; |
| | | res = WriteNewApp(nByteAddr,p1->Params+4,DataLen); |
| | | pData = p1->Params + 4 ; |
| | | res = KMRunService(ReqUpdateFirm,nByteAddr,0,&pData,&DataLen); |
| | | |
| | | // res = WriteNewApp(nByteAddr,p1->Params+4,DataLen); |
| | | // res = 0; |
| | | if (res) { |
| | | PacketLen=KLMakeRplyPacket(p2,nKLStationId,nKLStatus.StatByte,KLCmdErrRply,res,rData); |
| | | }else { |
| | |
| | | } |
| | | SendPacket(nChn, p2, PacketLen); |
| | | |
| | | |
| | | break; |
| | | case KLCmdWriteFirmInfo: |
| | | nByteAddr=p1->Params[0]+ (p1->Params[1]<<8); |
| | | //pData=(UCHAR *)(&storedKMSysCfg.theKMSysCfg)+nByteAddr; |
| | | DataLen = p1->Params[2]; |
| | | pData = p1->Params + 4 ; |
| | | res = KMRunService(ReqUpdateFirmInfo,nByteAddr,0,&pData,&DataLen); |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,p1->nCMD,0,0); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | WriteNewAppInfo(nByteAddr,p1->Params+4,DataLen); |
| | | // WriteNewAppInfo(nByteAddr,p1->Params+4,DataLen); |
| | | break; |
| | | case KLCmdGetPortInfo: |
| | | |
| | | nByteAddr=p1->Params[0] + (p1->Params[1]<<8); |
| | | //pData=(UCHAR *)(&storedKMSysCfg.theKMSysCfg)+nByteAddr; |
| | | pData = KMem.pPorts[nDataType]; |
| | | DataLen = sizeof(stPortDef); |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,p1->nCMD,DataLen,pData); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | break; |
| | | case KLCmdGetPortChnInfo: |
| | | |
| | | nByteAddr=p1->Params[0] + (p1->Params[1]<<8); |
| | | // nDataType --> port |
| | | // nByteAddr --> ChildId |
| | | //pData=(UCHAR *)(&storedKMSysCfg.theKMSysCfg)+nByteAddr; |
| | | KMPortReqFunc(nDataType,ReqPortChnInfo,nByteAddr,0,&pData,&DataLen); |
| | | |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,p1->nCMD,DataLen,pData); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | break; |
| | | |
| | | case KLCmdGetPortChildInfo: |
| | | nByteAddr=p1->Params[0] + (p1->Params[1]<<8); |
| | | // nDataType --> port |
| | | // nByteAddr --> ChildId |
| | | //pData=(UCHAR *)(&storedKMSysCfg.theKMSysCfg)+nByteAddr; |
| | | KMPortReqFunc(nDataType,ReqPortChildInfo,nByteAddr,0,&pData,&DataLen); |
| | | |
| | | //DataLen = sizeof(stPortDef); |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,p1->nCMD,DataLen,pData); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | break; |
| | | |
| | | case KLCmdPortRemoteReq: // è¿ç¨æå¡è¯·æ± |
| | | //p1->nType1 -> ReqId; |
| | | //p1->Params[0] -> Port; |
| | | //p1->Params[1] -> Child; |
| | | //p1->params[2] -> Param; |
| | | //p1->params[3] -> nAddr % 256; |
| | | //p1->params[4] -> nAddr / 256; |
| | | //p1->params[5] -> nCount; |
| | | pData = &p1->Params[3]; |
| | | DataLen = p1->Params[5]+3; |
| | | |
| | | KMPortReqFunc(p1->Params[0],nDataType,p1->Params[1],p1->Params[2],&pData,&DataLen); |
| | | DataLen=0; |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,p1->nCMD,DataLen,pData); |
| | | SendPacket(nChn, p2, PacketLen); |
| | | break; |
| | | default: |
| | | //DataLen=1; |
| | |
| | | #include "Globaldef.h" |
| | | #include "stm32f0xx.h" |
| | | #include "stm32f0xx_ll_flash.h" |
| | | #include "PLCFunctions.h" |
| | | |
| | | //#include "stm32f0xx_hal.h" |
| | | |
| | |
| | | //#define FLASH_BANK1_END ((uint32_t)0x0800FFFFU) /*!< FLASH END address of bank1 */ |
| | | #define ApplicationAddress 0x08001000 //åºç¨ç¨åºé¦å°åå®ä¹ |
| | | #if defined(STM32F030x8) |
| | | #define NewAppInfoBlockAddress 0x08008000 // åå¨çæ°åºç¨ç¨åºä¿¡æ¯åçå°å |
| | | #define NewAppAddress ((uint32_t)0x08009000U) // åå¨çæ°åºç¨ç¨åºçå°å |
| | | #define NEW_APP_INFOBLOCK_ADDR 0x08008000 // åå¨çæ°åºç¨ç¨åºä¿¡æ¯åçå°å |
| | | #define NEW_APP_ADDR ((uint32_t)0x08009000U) // åå¨çæ°åºç¨ç¨åºçå°å |
| | | #endif /* STM32F030x6 || STM32F030x8 || STM32F031x6 || STM32F051x8 || STM32F042x6 || STM32F048xx || STM32F058xx || STM32F070x6 */ |
| | | |
| | | #if defined(STM32F030xC) |
| | | #define NewAppInfoBlockAddress 0x08020000 // åå¨çæ°åºç¨ç¨åºä¿¡æ¯åçå°å |
| | | #define NewAppAddress ((uint32_t)0x08021000U) // åå¨çæ°åºç¨ç¨åºçå°å |
| | | #define NEW_APP_INFOBLOCK_ADDR 0x08020000 // åå¨çæ°åºç¨ç¨åºä¿¡æ¯åçå°å |
| | | #define NEW_APP_ADDR ((uint32_t)0x08021000U) // åå¨çæ°åºç¨ç¨åºçå°å |
| | | #endif /* STM32F071xB || STM32F072xB || STM32F078xx || STM32F091xC || STM32F098xx || STM32F030xC */ |
| | | |
| | | |
| | | stStoredKMSysCfg storedKMSysCfg ; |
| | | stKMem KMem; |
| | | stRunStat KMRunStat; |
| | | |
| | | |
| | | extern void SetErrLed(uchar bOn); |
| | | |
| | | //uint8_t * pFlash1 = (uint8_t *)(STORECFGBASE); |
| | | |
| | |
| | | //uint16_t FlashDatas[16]; |
| | | |
| | | //uint32_t * pUID = (uint32_t *)(UID_BASE); |
| | | const stKMInfoBlock KMInfoBlock = |
| | | { |
| | | // sizeof(stKMInfoBlock), |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceType BOARD_VER, //nDevieVer |
| | | 0x0109, //ProgVer |
| | | 0x0102, //KLinkVer |
| | | KBUS_VER, //KBusVer |
| | | // 0x0100, //KNetVer |
| | | // 0x0100, //KWLVer |
| | | |
| | | 4, //nCapacity1 ?K |
| | | 1, //nCapacity2 ?k |
| | | |
| | | DINPUT, //nDInput; |
| | | DOUTPUT, //nDOutput |
| | | |
| | | 0, //nAInput |
| | | 0, //nAOutput |
| | | 0, //nHInput |
| | | 0, //nHOutput |
| | | 0, //nExt1; |
| | | 0, //nExt2; |
| | | 0, //nLogSize; |
| | | 0, //nPorts; |
| | | 0, //nManSize; |
| | | 0, //nAbility; |
| | | 6, //nSwitchBits; |
| | | }; |
| | | |
| | | /* |
| | | const char VersionStr[] __attribute__((at(FLASH_BASE + 0X2000))) //__attribute__((at(0X8001000))) |
| | | = "3.00"; |
| | |
| | | CFG_VER, |
| | | 0x0000, //workmode |
| | | 0x0000, //switchfunc |
| | | 0x0000, //pad1; |
| | | 4, //nCfgBlockCount; |
| | | { //comportparam[2] |
| | | { |
| | | PortType_KLink, //PorttType |
| | | 1, //Station |
| | | 2304, //Buadrate = * 100; |
| | | 0, //ByteSize |
| | | 1152, //Buadrate = * 100; |
| | | 1, //ByteSize |
| | | 0, //Parity |
| | | 0, //StopBits |
| | | 0, //endType |
| | | 1, //endType |
| | | 0, //EofChar |
| | | 0, //SofChar |
| | | 0, //endtime |
| | | 9, //endtime |
| | | 0, //recvbuf |
| | | 0, //bufsize |
| | | }, |
| | |
| | | PortType_KBus, //PorttType |
| | | 0, //Station |
| | | 2304, //Buadrate = * 100; |
| | | 0, //ByteSize |
| | | 1, //ByteSize |
| | | 0, //Parity |
| | | 0, //StopBits |
| | | 0, //endType |
| | | 1, //endType |
| | | 0, //EofChar |
| | | 0, //SofChar |
| | | 0, //endtime |
| | | 1, //endtime |
| | | 0, //recvbuf |
| | | 0, //bufsize |
| | | } |
| | |
| | | 0x0030, |
| | | 0x0040, |
| | | 0x0050, |
| | | 0x0060 |
| | | 0x0060, |
| | | 0x0070, |
| | | 0x0080, |
| | | }, |
| | | 0x0003, //padding s |
| | | 0x0004, |
| | | 0x0005, |
| | | 0x0006, |
| | | 0x0007, |
| | | 0x0008, |
| | | 0,0,0,0, |
| | | { |
| | | {0,sizeof(stKMSysCfg)}, |
| | | {1,100}, |
| | | {2,100}, |
| | | {3,32}, |
| | | {4,32}, |
| | | }, |
| | | 0x0008, //padding s |
| | | 0x0009, |
| | | 0x000a, |
| | | 0x000b, |
| | | 0x000c, |
| | | }, |
| | | 0x0011, //CRC16 |
| | | END_SIGN, |
| | | }; |
| | | |
| | | int nEventCount=0; |
| | | int nEventMinIndex; |
| | | int nEventMaxIndex; |
| | | unsigned int nEventMaxSeq=0; |
| | | int nEventNextSpace; |
| | | int nMaxCurTime=0; |
| | | volatile int PowerState = 0; |
| | | |
| | | volatile int PowerDownEvent=0; |
| | | volatile int OldPowerDownEvent=0; |
| | | volatile int OldPowerDownEventTime=0; |
| | | int nMaxRunStatIndex=-1; |
| | | unsigned int nMaxRunStatSeq=0; |
| | | int nNextRunStatSpace=0; |
| | | |
| | | int KMRegisterPort(ushort nType,stPortDef * theParam) |
| | | { |
| | | int curPortId = KMem.nTotalPorts; |
| | | |
| | | KMem.pPorts[curPortId] = theParam; |
| | | |
| | | KMem.nTotalPorts++; |
| | | return curPortId; |
| | | } |
| | | |
| | | int KMPortReqFunc(int nPortIndex,int nReqId, int nParam1, int nParam2, void ** pData, unsigned short * nlen1) |
| | | { |
| | | if (KMem.pPorts[nPortIndex]->ReqCommFunc) |
| | | return KMem.pPorts[nPortIndex]->ReqCommFunc(KMem.pPorts[nPortIndex]->pInstance, nReqId, nParam1, nParam2, pData, nlen1); |
| | | else return -1; |
| | | } |
| | | |
| | | int KMRunService(int nSvrId, int nParam1, int nParam2, void **pData, unsigned short *nlen1) |
| | | { |
| | | int res; |
| | | switch(nSvrId) |
| | | { |
| | | case ReqNone: |
| | | break; |
| | | |
| | | case ReqInit: |
| | | break; |
| | | case ReqReset: |
| | | __set_PRIMASK(1); //å
³éå
¨å±ä¸æ |
| | | NVIC_SystemReset(); |
| | | break; |
| | | case ReqStop: |
| | | break; |
| | | case ReqRun: |
| | | break; |
| | | case ReqBlinkLED: |
| | | break; |
| | | case ReqStartDiag: |
| | | break; |
| | | case ReqStopDiag: |
| | | break; |
| | | case ReqUpdateFirm: |
| | | |
| | | res = WriteNewApp(nParam1,*pData,*nlen1); |
| | | |
| | | break; |
| | | case ReqUpdateFirmInfo: |
| | | res = WriteNewAppInfo(nParam1,*pData,*nlen1); |
| | | break; |
| | | |
| | | default: |
| | | res = -1; |
| | | break; |
| | | |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | int KMachineInit(void) |
| | | { |
| | | // ClearEventLog(); |
| | | KMem.LastScanTime=0; |
| | | KMem.ScanTimeuS=0; |
| | | KMem.MinScanTimeuS=99999; |
| | | KMem.MaxScanTimeuS=0; |
| | | |
| | | // KMem.SDD[14]=(unsigned int)&KMStoreSysCfg; |
| | | // KMem.SDD[15]=(unsigned int)&KMStoreSysCfg1; |
| | | KMem.SDD[12]=((uint32_t *)UID_BASE)[0]; |
| | | // KMem.SDD[13]=((uint32_t *)UID_BASE)[1]; |
| | | // KMem.SDD[14]=((uint32_t *)UID_BASE)[2]; |
| | | KMem.SDD[13]=PendSvCount; |
| | | KMem.SDD[14]=RCC->CSR; |
| | | // KMem.SDD[15]=*(uint32_t *)FLASHSIZE_BASE; |
| | | // KMem.SDD[16]=(unsigned int)&KMSysCfg; |
| | | |
| | | KMem.nTotalPorts = 0; |
| | | CheckEventLog(); |
| | | LoadRunStat(&KMRunStat); |
| | | KMem.CurTimeSec=nMaxCurTime; |
| | | KMem.TotalRunTime=KMRunStat.UpTime; |
| | | KMRunStat.PowerCount++; |
| | | KMem.PwrOnCount=KMRunStat.PowerCount; |
| | | SaveRunStat(&KMRunStat); |
| | | KMem.SDD[15]=nMaxRunStatIndex; |
| | | KMem.SDD[16]=nMaxRunStatSeq; |
| | | KMem.SDD[17]=nNextRunStatSpace; |
| | | |
| | | |
| | | AddEventLog(KMem.CurTimeSec,EventTypePowerUp,1,12345); |
| | | KMem.SDD[19]=nEventCount; |
| | | KMem.SDD[20]=nEventMinIndex; |
| | | KMem.SDD[21]=nEventMaxIndex; |
| | | KMem.SDD[22]=nEventMaxSeq; |
| | | KMem.SDD[23]=nEventNextSpace; |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | int KMachineLoopProc(void) |
| | | { |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | //const stKMSysCfg KMDefaultSysCfg2[7] /*__attribute__((at(STORECFGBASE+sizeof(stKMSysCfg))))*/; |
| | | |
| | |
| | | } |
| | | return nByteSize; |
| | | } |
| | | |
| | | int EraseFlashMem(void * pAddrFlash, unsigned int Pages) |
| | | { |
| | | ErrorStatus res; |
| | |
| | | // uint32_t ErrNo; |
| | | res = LL_Flash_PageErase(pAddrFlash,Pages); |
| | | LL_FLASH_Lock(FLASH); |
| | | return 0; |
| | | return res; |
| | | } |
| | | |
| | | int WriteToFlashMemNoErase(void * pBuf, void * pAddrFlash, unsigned int nByteSize) |
| | | { |
| | | ErrorStatus res; |
| | | SetErrLed(1); |
| | | res = LL_Flash_Unlock(); |
| | | // __disable_irq(); |
| | | ///* |
| | |
| | | if (res == ERROR) return 1; |
| | | return 0; |
| | | } |
| | | |
| | | int EraseAndWriteToFlashMem(void * pBuf, void * pAddrFlash, unsigned int nByteSize) |
| | | { |
| | | |
| | | SetErrLed(1); |
| | | ErrorStatus res; |
| | | res = LL_Flash_Unlock(); |
| | | // __disable_irq(); |
| | |
| | | return 0; |
| | | } |
| | | |
| | | /* ç§å½Flashï¼å¹¶èªå¨æ¦é¤ï¼é¡µèµ·å§å跨页æ¶èªå¨æ¦é¤ 页é¢ä¸é¨åä¸æ¦é¤ */ |
| | | int WriteToFlashAutoErase(void * pBuf, void * pAddrFlash, unsigned int nByteSize) |
| | | { |
| | | SetErrLed(1); |
| | | ErrorStatus res; |
| | | res = LL_Flash_Unlock(); |
| | | // __disable_irq(); |
| | | |
| | | int StartPage = (int)pAddrFlash / FLASH_PAGE_SIZE; |
| | | int EndPage = ((int)pAddrFlash + nByteSize) / FLASH_PAGE_SIZE; |
| | | int StartOffset = (int)pAddrFlash & (FLASH_PAGE_SIZE-1); |
| | | |
| | | int NbPages = EndPage -StartPage + 1; |
| | | |
| | | if (StartOffset == 0) { // ä»æå¼å§ , å
¨é¨æ¦é¤,ç¶åååå¨. |
| | | res = LL_Flash_PageErase(pAddrFlash,NbPages); |
| | | for (int i=0;i<(nByteSize+1)/2;i++) |
| | | { |
| | | unsigned short value = ((uint8_t *)pBuf)[i*2] + (((uint8_t *)pBuf)[i*2 +1] << 8); |
| | | res = LL_FLASH_Program(ProgaraType_DATA16, (uint32_t)pAddrFlash + i*2, value); |
| | | if (res == ERROR) break; |
| | | } |
| | | }else if (NbPages > 1){ // 跨页åå¨ |
| | | // å
åé¢çé¨å |
| | | int i; |
| | | for (i=0;i<(nByteSize+1)/2 && (((int)pAddrFlash + i*2) &(FLASH_PAGE_SIZE -1))!=0 ;i++) |
| | | { |
| | | unsigned short value = ((uint8_t *)pBuf)[i*2] + (((uint8_t *)pBuf)[i*2 +1] << 8); |
| | | res = LL_FLASH_Program(ProgaraType_DATA16, (uint32_t)pAddrFlash + i*2, value); |
| | | if (res == ERROR) break; |
| | | } |
| | | // æ¦é¤åé¢çé¨å. |
| | | res = LL_Flash_PageErase((void *)((int)pAddrFlash + i*2),NbPages - 1); |
| | | // 继ç»åå¨ |
| | | for ( ;i<(nByteSize+1)/2;i++) |
| | | { |
| | | unsigned short value = ((uint8_t *)pBuf)[i*2] + (((uint8_t *)pBuf)[i*2 +1] << 8); |
| | | res = LL_FLASH_Program(ProgaraType_DATA16, (uint32_t)pAddrFlash + i*2, value); |
| | | if (res == ERROR) break; |
| | | } |
| | | }else { |
| | | // æ£å¸¸åå
¥,ä¸éè¦æ¦é¤ |
| | | for (int i=0;i<(nByteSize+1)/2;i++) |
| | | { |
| | | unsigned short value = ((uint8_t *)pBuf)[i*2] + (((uint8_t *)pBuf)[i*2 +1] << 8); |
| | | res = LL_FLASH_Program(ProgaraType_DATA16, (uint32_t)pAddrFlash + i*2, value); |
| | | if (res == ERROR) break; |
| | | } |
| | | } |
| | | // __enable_irq(); |
| | | LL_FLASH_Lock(FLASH); |
| | | if (res == ERROR) return 1; |
| | | return 0; |
| | | } |
| | | |
| | | int ReadFactoryData(void * pDatabuf, int nByteCount) |
| | | { |
| | | memcpy(pDatabuf,(stFactoryData *)FACTORY_DATA_BASE,nByteCount); |
| | |
| | | EraseAndWriteToFlashMem(pDataBuf, (stFactoryData *)FACTORY_DATA_BASE,nByteCount); |
| | | return 0; |
| | | } |
| | | |
| | | int ReadProgram(int nProgByteAddr, void *pBuf, int nByteSize, int nBank) |
| | | #if (ENABLE_PLC) |
| | | int ReadPLCProgram(int nBank, int nProgByteAddr, void *pBuf, int nByteSize) |
| | | { |
| | | stStoredBinProgs * pStoredProg; |
| | | if (nBank==0) { |
| | | ReadFlashMem(pBuf, (void *)(STORE_PRG_BASE+nProgByteAddr), nByteSize); |
| | | pStoredProg = (void *)(STORE_PRG_BASE); |
| | | }else if (nBank ==1) { |
| | | ReadFlashMem(pBuf, (void *)(ALT_PRG_BASE+nProgByteAddr), nByteSize); |
| | | }else if (KMRunStat.nBinProgBank==0) { |
| | | ReadFlashMem(pBuf, (void *)(STORE_PRG_BASE+nProgByteAddr), nByteSize); |
| | | pStoredProg = (void *)(ALT_PRG_BASE); |
| | | }else if (storedKMSysCfg.theKMSysCfg.nProgBank==0) { |
| | | pStoredProg = (void *)(STORE_PRG_BASE); |
| | | } else { |
| | | ReadFlashMem(pBuf, (void *)(ALT_PRG_BASE+nProgByteAddr), nByteSize); |
| | | pStoredProg = (void *)(ALT_PRG_BASE); |
| | | } |
| | | void * progByteAddr; |
| | | progByteAddr =(unsigned char *)&pStoredProg->BinInstrcns + nProgByteAddr; |
| | | |
| | | ReadFlashMem(pBuf, (void *)(progByteAddr), nByteSize); |
| | | return 0; |
| | | } |
| | | int WriteProgram(int nProgAddress, void * pBuf, int nByteSize, int nBank) |
| | | |
| | | int StartPLCProgram(int nBank, int nByteSize, int nCRC) |
| | | { |
| | | void * progHdrAddr; |
| | | int nRes = 0; |
| | | if (nBank == 0) { |
| | | progHdrAddr=(void *)(STORE_PRG_BASE); |
| | | }else if (nBank==1) { |
| | | progHdrAddr=(void *)(ALT_PRG_BASE); |
| | | } else if (storedKMSysCfg.theKMSysCfg.nProgBank==0) { |
| | | progHdrAddr=(void *)(ALT_PRG_BASE); |
| | | }else{ |
| | | progHdrAddr=(void *)(STORE_PRG_BASE); |
| | | } |
| | | |
| | | stStoredHdr theHdr; |
| | | theHdr.nBlockSign = 0xAA55; |
| | | theHdr.nBlockType = 0; |
| | | theHdr.nSeq = 1; |
| | | theHdr.nSize = nByteSize; |
| | | theHdr.nCRC2 = nCRC; |
| | | |
| | | WriteToFlashAutoErase(&theHdr,(void *)progHdrAddr,sizeof(stStoredHdr)); |
| | | |
| | | return nRes; |
| | | } |
| | | int WritePLCProgram(int nBank, int nProgAddress, void * pBuf, int nByteSize) |
| | | { |
| | | // Program Save Address;// |
| | | // Program 2 Save Address; // |
| | | void * progByteAddr; |
| | | stStoredBinProgs * pStoredProg; |
| | | |
| | | if (nBank == 0) { |
| | | progByteAddr=(void *)(STORE_PRG_BASE+nProgAddress); |
| | | pStoredProg=(stStoredBinProgs *)(STORE_PRG_BASE); |
| | | }else if (nBank==1) { |
| | | progByteAddr=(void *)(ALT_PRG_BASE+nProgAddress); |
| | | } else if (KMRunStat.nBinProgBank==0) { |
| | | progByteAddr=(void *)(ALT_PRG_BASE+nProgAddress); |
| | | pStoredProg=(stStoredBinProgs *)(ALT_PRG_BASE); |
| | | } else if (storedKMSysCfg.theKMSysCfg.nProgBank==0) { |
| | | pStoredProg=(stStoredBinProgs *)(ALT_PRG_BASE); |
| | | }else{ |
| | | progByteAddr=(void *)(STORE_PRG_BASE+nProgAddress); |
| | | pStoredProg=(stStoredBinProgs *)(STORE_PRG_BASE); |
| | | } |
| | | if ( (nProgAddress & (FLASH_PAGE_SIZE - 1)) ==0) { |
| | | EraseAndWriteToFlashMem(pBuf, progByteAddr, nByteSize); |
| | | }else{ |
| | | WriteToFlashMemNoErase(pBuf, progByteAddr, nByteSize); |
| | | } |
| | | void * progByteAddr; |
| | | progByteAddr =(unsigned char *)&pStoredProg->BinInstrcns + nProgAddress; |
| | | WriteToFlashAutoErase(pBuf,progByteAddr,nByteSize); |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | int FinishiPLCProgram(int nBank, int nProgSteps,int nCRC ) |
| | | { |
| | | int nRes = 0; |
| | | |
| | | if (storedKMSysCfg.theKMSysCfg.nProgBank == 0 ) { |
| | | storedKMSysCfg.theKMSysCfg.nProgBank = 1; |
| | | }else { |
| | | storedKMSysCfg.theKMSysCfg.nProgBank = 0; |
| | | } |
| | | storedKMSysCfg.theKMSysCfg.nProgSize = nProgSteps; |
| | | |
| | | WriteSysCfgToFlash(&storedKMSysCfg); |
| | | |
| | | KMRunStat.nBinProgSize=nProgSteps; |
| | | KMRunStat.nBinProgBank=storedKMSysCfg.theKMSysCfg.nProgBank; |
| | | |
| | | SaveRunStat(&KMRunStat); |
| | | |
| | | return nRes; |
| | | } |
| | | int ReadPLCAnno(int nBank, int nProgByteAddr, void *pBuf, int nByteSize) |
| | | { |
| | | stStoredBinProgs * pStoredProg; |
| | | if (nBank==0) { |
| | | pStoredProg = (void *)(STORE_PRG_BASE); |
| | | }else if (nBank ==1) { |
| | | pStoredProg = (void *)(ALT_PRG_BASE); |
| | | }else if (storedKMSysCfg.theKMSysCfg.nProgBank==0) { |
| | | pStoredProg = (void *)(STORE_PRG_BASE); |
| | | } else { |
| | | pStoredProg = (void *)(ALT_PRG_BASE); |
| | | } |
| | | void * progByteAddr; |
| | | progByteAddr =(unsigned char *)&pStoredProg->BinInstrcns + nProgByteAddr; |
| | | |
| | | ReadFlashMem(pBuf, (void *)(progByteAddr), nByteSize); |
| | | return 0; |
| | | } |
| | | |
| | | int StartPLCAnno(int nBank, int nByteSize, int nCRC) |
| | | { |
| | | void * StoredAnnoHdrAddr; |
| | | int nRes = 0; |
| | | |
| | | StoredAnnoHdrAddr=(void *)(STORE_PLC_ANNO_BASE); |
| | | |
| | | |
| | | stStoredHdr theHdr; |
| | | theHdr.nBlockSign = 0xAA55; |
| | | theHdr.nBlockType = 3; |
| | | theHdr.nSeq = 1; |
| | | theHdr.nSize = nByteSize; |
| | | theHdr.nCRC2 = nCRC; |
| | | |
| | | WriteToFlashAutoErase(&theHdr,(void *)StoredAnnoHdrAddr,sizeof(stStoredHdr)); |
| | | |
| | | return nRes; |
| | | } |
| | | int WritePLCAnno(int nBank, int nByteAddress, void * pBuf, int nByteSize) |
| | | { |
| | | // Program Save Address;// |
| | | // Program 2 Save Address; // |
| | | stStoredAnno * pStoredAnno; |
| | | pStoredAnno=(stStoredAnno *)(STORE_PLC_ANNO_BASE); |
| | | |
| | | void * nByteAddr; |
| | | nByteAddr =pStoredAnno->Annos + nByteAddress; |
| | | WriteToFlashAutoErase(pBuf,nByteAddr,nByteSize); |
| | | |
| | | return 0; |
| | | } |
| | | int FinishiPLCAnno(int nBank, int nByteSize,int nCRC ) |
| | | { |
| | | int nRes = 0; |
| | | |
| | | storedKMSysCfg.theKMSysCfg.nAnnoSize = nByteSize; |
| | | WriteSysCfgToFlash(&storedKMSysCfg); |
| | | /* |
| | | KMRunStat.nBinProgSize=nProgSteps; |
| | | KMRunStat.nBinProgBank=storedKMSysCfg.theKMSysCfg.nProgBank; |
| | | |
| | | SaveRunStat(&KMRunStat); |
| | | */ |
| | | return nRes; |
| | | } |
| | | |
| | | #endif //ENABLE_PLC |
| | | int LoadDefaultSysCfg(pStoredKMSysCfg theStoredKMSysCfg) |
| | | { |
| | | memcpy(theStoredKMSysCfg,&KMDefaultSysCfg,sizeof(stStoredKMSysCfg)); |
| | |
| | | return 0; |
| | | }; |
| | | |
| | | |
| | | int nMaxRunStatIndex=-1; |
| | | unsigned int nMaxRunStatSeq=0; |
| | | int nNextRunStatSpace=0; |
| | | int LoadDefaultRunStat(pRunStat theRunStat) |
| | | { |
| | | theRunStat->PowerCount=1; |
| | |
| | | // theRunStat->WorkMode=0; |
| | | // theRunStat->WorkMode2=0; |
| | | // theRunStat->nBinProgBank=0; |
| | | // theRunStat->nBinProgSize=0; |
| | | // theRunStat->nBinInstrcnSize=0; |
| | | return 0; |
| | | } |
| | | int LoadRunStat(pRunStat theRunStat) |
| | |
| | | return 0; |
| | | } |
| | | |
| | | int WriteNewApp(int nProgByteAddr, void *pBuf, int nByteSize) |
| | | int WriteNewApp(int nProgByteOffset, void *pBuf, int nByteSize) |
| | | { |
| | | |
| | | int res = -1; |
| | | if ((nProgByteAddr&(FLASH_PAGE_SIZE-1)) ==0){ |
| | | int FlashSize = *(ushort *)FLASHSIZE_BASE; |
| | | int NewAppAddress ; |
| | | if (FlashSize == 64) { |
| | | NewAppAddress = 0x08009000U; |
| | | }else if (FlashSize == 256) { |
| | | NewAppAddress = 0x08021000U; |
| | | } |
| | | if ((nProgByteOffset&(FLASH_PAGE_SIZE-1)) ==0){ |
| | | // EraseFlashMem((void *)(NewAppAddress + nProgByteAddr),1); |
| | | res = EraseAndWriteToFlashMem(pBuf,(void *)(NewAppAddress + nProgByteAddr),nByteSize); |
| | | |
| | | res = EraseAndWriteToFlashMem(pBuf,(void *)(NewAppAddress + nProgByteOffset),nByteSize); |
| | | }else { |
| | | // if (nByteSize>64) return 0; |
| | | res = WriteToFlashMemNoErase(pBuf,(void *)(NewAppAddress + nProgByteAddr),nByteSize); |
| | | res = WriteToFlashMemNoErase(pBuf,(void *)(NewAppAddress + nProgByteOffset),nByteSize); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | int WriteNewAppInfo(int nProgByteAddr, void *pBuf, int nByteSize) |
| | | { |
| | | int FlashSize = *(ushort *)FLASHSIZE_BASE; |
| | | int NewAppInfoBlockAddress ; |
| | | if (FlashSize == 64) { |
| | | NewAppInfoBlockAddress = 0x08008000; |
| | | }else if (FlashSize == 256) { |
| | | NewAppInfoBlockAddress = 0x08020000; |
| | | } |
| | | |
| | | int res = EraseAndWriteToFlashMem(pBuf,(void *)(NewAppInfoBlockAddress + nProgByteAddr),nByteSize); |
| | | return res; |
| | | } |
| | | |
| | | int nEventCount=0; |
| | | int nEventMinIndex; |
| | | int nEventMaxIndex; |
| | | unsigned int nEventMaxSeq=0; |
| | | int nEventNextSpace; |
| | | int nMaxCurTime=0; |
| | | volatile int PowerState = 0; |
| | | |
| | | volatile int PowerDownEvent=0; |
| | | volatile int OldPowerDownEvent=0; |
| | | volatile int OldPowerDownEventTime=0; |
| | | |
| | | int CheckEventLog() |
| | | { |
| | |
| | | nEventNextSpace=0; |
| | | return 0; |
| | | } |
| | | int KMachineInit(void) |
| | | { |
| | | // ClearEventLog(); |
| | | CheckEventLog(); |
| | | LoadRunStat(&KMRunStat); |
| | | KMem.CurTimeSec=nMaxCurTime; |
| | | KMem.TotalRunTime=KMRunStat.UpTime; |
| | | KMRunStat.PowerCount++; |
| | | KMem.PwrOnCount=KMRunStat.PowerCount; |
| | | SaveRunStat(&KMRunStat); |
| | | KMem.SDD[15]=nMaxRunStatIndex; |
| | | KMem.SDD[16]=nMaxRunStatSeq; |
| | | KMem.SDD[17]=nNextRunStatSpace; |
| | | |
| | | |
| | | AddEventLog(KMem.CurTimeSec,EventTypePowerUp,1,12345); |
| | | KMem.SDD[19]=nEventCount; |
| | | KMem.SDD[20]=nEventMinIndex; |
| | | KMem.SDD[21]=nEventMaxIndex; |
| | | KMem.SDD[22]=nEventMaxSeq; |
| | | KMem.SDD[23]=nEventNextSpace; |
| | | |
| | | return 0; |
| | | inline void SetAddrBit(unsigned short * pW, unsigned char bitPos) |
| | | { |
| | | (*pW)|=1<<(bitPos&0xf); |
| | | } |
| | | |
| | | inline void SetAddrBit(unsigned short * pW, unsigned char bitAddr) |
| | | inline void ResetBit(unsigned short * pW, unsigned char bitPos) |
| | | { |
| | | (*pW)|=1<<(bitAddr&0xf); |
| | | (*pW)&=~(1<<(bitPos&0xf)); |
| | | } |
| | | |
| | | inline void ResetBit(unsigned short * pW, unsigned char bitAddr) |
| | | static inline void SetBitValue(unsigned short * pW, unsigned char bitPos, unsigned char Value) |
| | | { |
| | | (*pW)&=~(1<<(bitAddr&0xf)); |
| | | if (Value) { SetAddrBit(pW, bitPos);} |
| | | else {ResetBit(pW, bitPos);} |
| | | } |
| | | |
| | | static inline void SetBitValue(unsigned short * pW, unsigned char bitAddr, unsigned char Value) |
| | | static inline unsigned char GetBitValue(unsigned short W, unsigned char bitPos) |
| | | { |
| | | if (Value) { SetAddrBit(pW, bitAddr);} |
| | | else {ResetBit(pW, bitAddr);} |
| | | } |
| | | |
| | | static inline unsigned char GetBitValue(unsigned short W, unsigned char bitAddr) |
| | | { |
| | | if (W&(1<<(bitAddr&0xf))) return 1; |
| | | if (W&(1<<(bitPos&0xf))) return 1; |
| | | else return 0; |
| | | } |
| | | |
| | |
| | | { |
| | | unsigned char thisValue=0; |
| | | unsigned short nWordAddr=(nCoilAddr&0xff0)>>4; |
| | | unsigned char nBitAddr=nCoilAddr&0xf; |
| | | unsigned char nBitPos=nCoilAddr&0xf; |
| | | switch(nCoilType) |
| | | { |
| | | case KLCoilTypeX: |
| | | if (nCoilAddr >= KLCoilXCount) return 0; |
| | | thisValue = GetBitValue(KMem.WX[nWordAddr], nBitAddr); |
| | | thisValue = GetBitValue(KMem.WX[nWordAddr], nBitPos); |
| | | break; |
| | | case KLCoilTypeY: |
| | | if (nCoilAddr >= KLCoilYCount) return 0; |
| | | thisValue = GetBitValue(KMem.WY[nWordAddr], nBitAddr); |
| | | thisValue = GetBitValue(KMem.WY[nWordAddr], nBitPos); |
| | | break; |
| | | case KLCoilTypeR: |
| | | if (nCoilAddr >= KLCoilRCount) return 0; |
| | | thisValue = GetBitValue(KMem.WR[nWordAddr], nBitAddr); |
| | | |
| | | if (nCoilAddr < KLCoilRCount) { |
| | | thisValue = GetBitValue(KMem.WR[nWordAddr], nBitPos); |
| | | }else if (nCoilAddr > 9000) { |
| | | if (nCoilAddr == 9010) thisValue = 1; |
| | | if (nCoilAddr == 9011) thisValue = 0; |
| | | if (nCoilAddr == 9013) thisValue = GetBitValue(KMem.WSR[nWordAddr], 13); |
| | | } |
| | | // return thisValue; |
| | | break; |
| | | case KLCoilTypeLX: |
| | | if (nCoilAddr >= KLCoilLXCount) return 0; |
| | | thisValue = GetBitValue(KMem.WLX[nWordAddr], nBitAddr); |
| | | thisValue = GetBitValue(KMem.WLX[nWordAddr], nBitPos); |
| | | break; |
| | | case KLCoilTypeLY: |
| | | if (nCoilAddr >= KLCoilLYCount) return 0; |
| | | thisValue = GetBitValue(KMem.WLY[nWordAddr], nBitAddr); |
| | | thisValue = GetBitValue(KMem.WLY[nWordAddr], nBitPos); |
| | | break; |
| | | #if (ENABLE_PLC) |
| | | case KLCoilTypeT: |
| | | if (nCoilAddr >= KLCoilTCount) return 0; |
| | | thisValue = GetBitValue(KMem.WT[nWordAddr], nBitAddr); |
| | | thisValue = GetBitValue(PLCMem.WT[nWordAddr], nBitPos); |
| | | break; |
| | | case KLCoilTypeC: |
| | | if (nCoilAddr >= KLCoilCCount) return 0; |
| | | thisValue = GetBitValue(KMem.WC[nWordAddr], nBitAddr); |
| | | thisValue = GetBitValue(PLCMem.WC[nWordAddr], nBitPos); |
| | | break; |
| | | #endif |
| | | case KLCoilTypeLR: |
| | | if (nCoilAddr >= KLCoilLRCount) return 0; |
| | | thisValue = GetBitValue(KMem.WLR[nWordAddr], nBitAddr); |
| | | thisValue = GetBitValue(KMem.WLR[nWordAddr], nBitPos); |
| | | break; |
| | | case KLCoilTypeSR: |
| | | if (nCoilAddr >= KLCoilSRCount) return 0; |
| | | thisValue = GetBitValue(KMem.WSR[nWordAddr], nBitAddr); |
| | | thisValue = GetBitValue(KMem.WSR[nWordAddr], nBitPos); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | if (nCoilAddr >= KLCoilLYCount) return 0; |
| | | SetBitValue(&KMem.WLY[nWordAddr], nBitAddr, nCoilValue); |
| | | break; |
| | | #if (ENABLE_PLC) |
| | | case KLCoilTypeT: |
| | | if (nCoilAddr >= KLCoilTCount) return 0; |
| | | SetBitValue(&KMem.WT[nWordAddr], nBitAddr, nCoilValue); |
| | | SetBitValue(&PLCMem.WT[nWordAddr], nBitAddr, nCoilValue); |
| | | break; |
| | | case KLCoilTypeC: |
| | | if (nCoilAddr >= KLCoilCCount) return 0; |
| | | SetBitValue(&KMem.WC[nWordAddr], nBitAddr, nCoilValue); |
| | | SetBitValue(&PLCMem.WC[nWordAddr], nBitAddr, nCoilValue); |
| | | break; |
| | | #endif |
| | | case KLCoilTypeLR: |
| | | if (nCoilAddr >= KLCoilLRCount) return 0; |
| | | SetBitValue(&KMem.WLR[nWordAddr], nBitAddr, nCoilValue); |
| | |
| | | if (nDataAddr >= KLCoilLRCount) return 0; |
| | | thisValue = KMem.WSR[nDataAddr]; |
| | | break; |
| | | #if (ENABLE_PLC) |
| | | case KLDataTypeSV: |
| | | if (nDataAddr >= KLDataSVCount) return 0; |
| | | thisValue = KMem.SV[nDataAddr]; |
| | | thisValue = PLCMem.SV[nDataAddr]; |
| | | break; |
| | | case KLDataTypeEV: |
| | | if (nDataAddr >= KLDataEVCount) return 0; |
| | | thisValue = KMem.EV[nDataAddr]; |
| | | thisValue = PLCMem.EV[nDataAddr]; |
| | | break; |
| | | #endif |
| | | case KLDataTypeLD: |
| | | if (nDataAddr >= KLDataLDCount) return 0; |
| | | thisValue = KMem.DT[nDataAddr]; |
| | |
| | | if (nDataAddr >= KLCoilLRCount) return 0; |
| | | KMem.WSR[nDataAddr] = nDataValue; |
| | | break; |
| | | #if (ENABLE_PLC) |
| | | case KLDataTypeSV: |
| | | if (nDataAddr >= KLDataSVCount) return 0; |
| | | KMem.SV[nDataAddr] = nDataValue; |
| | | PLCMem.SV[nDataAddr] = nDataValue; |
| | | break; |
| | | case KLDataTypeEV: |
| | | if (nDataAddr >= KLDataEVCount) return 0; |
| | | KMem.EV[nDataAddr] = nDataValue; |
| | | PLCMem.EV[nDataAddr] = nDataValue; |
| | | break; |
| | | #endif |
| | | case KLDataTypeLD: |
| | | if (nDataAddr >= KLDataLDCount) return 0; |
| | | KMem.DT[nDataAddr] = nDataValue; |
| | |
| | | break; |
| | | case ReqRun: |
| | | break; |
| | | case ReqBlink: |
| | | case ReqBlinkLED: |
| | | KMRunStat.bLEDFlick=nParam; |
| | | break; |
| | | case ReqStartDiag: |
| | | break; |
| | |
| | | case WriteCoil: //5 bit |
| | | //Store Datas; |
| | | //SetBitValue(&KMem.WR[Addr1],bitAddr,pPkg->nCount); |
| | | Addr1=(Addr&0xfff0)>>4; |
| | | bitAddr=Addr&0xf; |
| | | if (nCount == 0) // set to 0 |
| | | { |
| | | ResetBit(&KMem.WY[Addr1],bitAddr); |
| | | if (Addr < 2048) { ResetBit(&KMem.WY[Addr1],bitAddr);} |
| | | else {ResetBit(&KMem.WR[Addr1-128],bitAddr);} |
| | | }else if (nCount == 0xFF00) // set to 1 |
| | | { |
| | | SetAddrBit(&KMem.WY[Addr1],bitAddr); |
| | | }else |
| | | { |
| | | //error |
| | | if (Addr < 2048) { SetAddrBit(&KMem.WY[Addr1],bitAddr);} |
| | | else {SetAddrBit(&KMem.WR[Addr1-128],bitAddr);} |
| | | |
| | | } |
| | | memcpy(Pkgbuf,ptr,len); |
| | | needcrc=0; |
| | |
| | | theQueue->Caps=nSize; |
| | | theQueue->wp=0; |
| | | theQueue->rp=0; |
| | | theQueue->RecvBytes=0; |
| | | // theQueue->RecvBytes=0; |
| | | //theQueue->state=0; |
| | | theQueue->bFull=0; |
| | | theQueue->bEmpty=1; |
| | | theQueue->state=0; |
| | | return 0; |
| | | } |
| | | int EmptyQueue(stMyQueue * theQueue) |
| | | { |
| | | theQueue->wp=0; |
| | | theQueue->rp=0; |
| | | //theQueue->state=0; |
| | | theQueue->bFull=0; |
| | | theQueue->bEmpty=1; |
| | | theQueue->state=0; |
| | | return 0; |
| | | } |
| | | int GetContinueEmptyRoom(stMyQueue * theQueue) |
| | |
| | | theQueue->bEmpty=0; |
| | | if (wp == theQueue->rp) theQueue->bFull=1; |
| | | theQueue->wp = wp; |
| | | theQueue->RecvBytes+=nSize; |
| | | // theQueue->RecvBytes+=nSize; |
| | | return nSize; |
| | | } |
| | | |
| | |
| | | theQueue->rp = rp; |
| | | if (rp == theQueue->wp) |
| | | { |
| | | theQueue->bEmpty=1; |
| | | theQueue->wp=0; |
| | | theQueue->rp=0; |
| | | theQueue->state=0; |
| | | // theQueue->state=0; |
| | | theQueue->bEmpty=1; |
| | | } |
| | | return nSize; |
| | | } |
| | |
| | | #include "stm32f0xx_hal.h" |
| | | #include <core_cmInstr.h> |
| | | |
| | | #if (ENABLE_PLC) |
| | | extern __IO uint32_t uwTick; |
| | | |
| | | //unsigned short WDFs[TOTAL_WDFS]; |
| | |
| | | int InitTimer(int nIndex, int nType) |
| | | { |
| | | if (nIndex >= TOTALTIMERS) return -1; |
| | | KMem.Timers[nIndex].StatByte = 0x0010 | nType; |
| | | PLCMem.Timers[nIndex].StatByte = 0x0010 | nType; |
| | | // Timers[nIndex].nType = 0; |
| | | KMem.SV[nIndex] = 0; |
| | | KMem.EV[nIndex] = 0; |
| | | KMem.Timers[nIndex].LastActTime = GetTick(); |
| | | PLCMem.SV[nIndex] = 0; |
| | | PLCMem.EV[nIndex] = 0; |
| | | PLCMem.Timers[nIndex].LastActTime = GetTick(); |
| | | return 0; |
| | | } |
| | | |
| | | int RunTimer(int nIndex , int SV) |
| | | { |
| | | if (nIndex >= TOTALTIMERS) return -1; |
| | | if (!KMem.Timers[nIndex].bSet) |
| | | if (!PLCMem.Timers[nIndex].bSet) |
| | | { |
| | | KMem.SV[nIndex] = SV; |
| | | KMem.EV[nIndex]= 0; |
| | | KMem.Timers[nIndex].LastActTime = GetTick(); |
| | | KMem.Timers[nIndex].bSet = 1; |
| | | PLCMem.SV[nIndex] = SV; |
| | | PLCMem.EV[nIndex]= 0; |
| | | PLCMem.Timers[nIndex].LastActTime = GetTick(); |
| | | PLCMem.Timers[nIndex].bSet = 1; |
| | | } |
| | | return 0; |
| | | } |
| | |
| | | int StopTimer(int nIndex) |
| | | { |
| | | if (nIndex >= TOTALTIMERS) return -1; |
| | | if (KMem.Timers[nIndex].bSet) |
| | | if (PLCMem.Timers[nIndex].bSet) |
| | | { |
| | | KMem.EV[nIndex] = 0; |
| | | KMem.Timers[nIndex].LastActTime = GetTick(); |
| | | KMem.Timers[nIndex].bSet = 0; |
| | | PLCMem.EV[nIndex] = 0; |
| | | PLCMem.Timers[nIndex].LastActTime = GetTick(); |
| | | PLCMem.Timers[nIndex].bSet = 0; |
| | | } |
| | | return 0; |
| | | } |
| | | int ResetTimer(int nIndex) |
| | | { |
| | | if (nIndex >= TOTALTIMERS) return -1; |
| | | KMem.EV[nIndex] = 0; |
| | | KMem.Timers[nIndex].bTon = 0; |
| | | KMem.Timers[nIndex].LastActTime=GetTick(); |
| | | PLCMem.EV[nIndex] = 0; |
| | | PLCMem.Timers[nIndex].bTon = 0; |
| | | PLCMem.Timers[nIndex].LastActTime=GetTick(); |
| | | return 0; |
| | | } |
| | | |
| | |
| | | if (nIndex >= TOTALTIMERS) return -1; |
| | | if (bSet) {RunTimer(nIndex, SV);} |
| | | else {StopTimer(nIndex);} |
| | | return KMem.Timers[nIndex].bTon; |
| | | return PLCMem.Timers[nIndex].bTon; |
| | | } |
| | | |
| | | int ProcessTimer(int nIndex) |
| | | { |
| | | if (nIndex >= TOTALTIMERS) return -1; |
| | | if (!KMem.Timers[nIndex].nInited) return 0; |
| | | if (KMem.Timers[nIndex].bSet) // bSet =1; |
| | | if (!PLCMem.Timers[nIndex].nInited) return 0; |
| | | if (PLCMem.Timers[nIndex].bSet) // bSet =1; |
| | | { |
| | | if (!KMem.Timers[nIndex].bTon) |
| | | if (!PLCMem.Timers[nIndex].bTon) |
| | | { |
| | | int TimeDiff = GetTick() - KMem.Timers[nIndex].LastActTime; |
| | | int nScale = TICK_OF_MS; |
| | | if (KMem.Timers[nIndex].nScale == 0) |
| | | if (PLCMem.Timers[nIndex].nScale == 0) |
| | | {nScale = TICK_OF_MS; |
| | | }else if (KMem.Timers[nIndex].nScale == 1) |
| | | }else if (PLCMem.Timers[nIndex].nScale == 1) |
| | | {nScale = TICK_OF_RS; |
| | | }else if (KMem.Timers[nIndex].nScale == 2) |
| | | }else if (PLCMem.Timers[nIndex].nScale == 2) |
| | | {nScale = TICK_OF_XS; |
| | | }else if (KMem.Timers[nIndex].nScale == 3) |
| | | }else if (PLCMem.Timers[nIndex].nScale == 3) |
| | | {nScale = TICK_OF_YS; |
| | | }else {} |
| | | |
| | | |
| | | int TimeDiff = GetTick() - PLCMem.Timers[nIndex].LastActTime; |
| | | if (TimeDiff < 0) { TimeDiff = nScale;} |
| | | if (TimeDiff >= nScale) |
| | | { |
| | | int TimeDiffmS = TimeDiff / nScale; |
| | | unsigned short NextEV = KMem.EV[nIndex] + TimeDiffmS; |
| | | KMem.Timers[nIndex].LastActTime += TimeDiffmS*nScale; |
| | | unsigned short NextEV = PLCMem.EV[nIndex] + TimeDiffmS; |
| | | PLCMem.Timers[nIndex].LastActTime += TimeDiffmS*nScale; |
| | | |
| | | if (NextEV >= KMem.SV[nIndex]) |
| | | if (NextEV >= PLCMem.SV[nIndex]) |
| | | { |
| | | NextEV = KMem.SV[nIndex]; |
| | | KMem.Timers[nIndex].bTon =1; |
| | | NextEV = PLCMem.SV[nIndex]; |
| | | PLCMem.Timers[nIndex].bTon =1; |
| | | } |
| | | KMem.EV[nIndex] = NextEV; |
| | | PLCMem.EV[nIndex] = NextEV; |
| | | } |
| | | } |
| | | }else //bSet=0; |
| | | { |
| | | if(KMem.Timers[nIndex].bTon) |
| | | if(PLCMem.Timers[nIndex].bTon) |
| | | { |
| | | KMem.Timers[nIndex].bTon = 0; |
| | | PLCMem.Timers[nIndex].bTon = 0; |
| | | } |
| | | } |
| | | SetCoilValue(KLCoilTypeT, nIndex, KMem.Timers[nIndex].bTon); |
| | | return KMem.Timers[nIndex].bTon; |
| | | SetCoilValue(KLCoilTypeT, nIndex, PLCMem.Timers[nIndex].bTon); |
| | | return PLCMem.Timers[nIndex].bTon; |
| | | } |
| | | |
| | | int IsTimerOn(int nIndex) |
| | | { |
| | | if (nIndex >= TOTALTIMERS) return 0; |
| | | ProcessTimer(nIndex); |
| | | return KMem.Timers[nIndex].bTon; |
| | | return PLCMem.Timers[nIndex].bTon; |
| | | |
| | | } |
| | | |
| | |
| | | { |
| | | if (nIndex >= TOTALTIMERS) return 0; |
| | | // ProcessTimer(nIndex); |
| | | return KMem.SV[nIndex]; |
| | | return PLCMem.SV[nIndex]; |
| | | // return 0; |
| | | } |
| | | int GetTimerEV(int nIndex) |
| | | { |
| | | if (nIndex >= TOTALTIMERS) return 0; |
| | | // ProcessTimer(nIndex); |
| | | return KMem.EV[nIndex]; |
| | | return PLCMem.EV[nIndex]; |
| | | // return 0; |
| | | } |
| | | |
| | |
| | | { |
| | | for (int i=TOTAL_CurVAL -1 ;i>0;i--) |
| | | { |
| | | KMem.CurVALs[i]=KMem.CurVALs[i-1]; |
| | | PLCMem.CurVALs[i]=PLCMem.CurVALs[i-1]; |
| | | } |
| | | KMem.CurVALs[0]=KMem.CurVAL; |
| | | return KMem.CurVAL; |
| | | PLCMem.CurVALs[0]=PLCMem.CurVAL; |
| | | return PLCMem.CurVAL; |
| | | } |
| | | |
| | | int PopOutVal(void) |
| | | { |
| | | unsigned char theVAL=KMem.CurVALs[0]; |
| | | unsigned char theVAL=PLCMem.CurVALs[0]; |
| | | for (int i=0;i<TOTAL_CurVAL-1;i++) |
| | | { |
| | | KMem.CurVALs[i]=KMem.CurVALs[i+1]; |
| | | PLCMem.CurVALs[i]=PLCMem.CurVALs[i+1]; |
| | | } |
| | | return theVAL; |
| | | } |
| | | |
| | | stBinProg1 const prog1[]= //__attribute__((at(0X8008000))) |
| | | { |
| | | {OP_ST,KLCoilTypeSR,13}, |
| | | {OP_MV,0,50}, {KLDataTypeDEC,KLDataTypeDT,1}, |
| | | {OP_MV,0,20}, {KLDataTypeDEC,KLDataTypeDT,2}, |
| | | {OP_MV,0,30}, {KLDataTypeDEC,KLDataTypeDT,3}, |
| | | {OP_MV,0,40}, {KLDataTypeDEC,KLDataTypeDT,4}, |
| | | {OP_SET,KLCoilTypeR,0}, |
| | | // {OP_SET,KLCoilTypeY,0}, |
| | | |
| | | {OP_ST,KLCoilTypeR,0}, |
| | | {OP_TMX,1,1}, {KLDataTypeDT,0,0}, |
| | | {OP_DF}, |
| | | {OP_SET,KLCoilTypeR,10}, |
| | | |
| | | {OP_ST,KLCoilTypeX,0}, |
| | | {OP_DF}, |
| | | {OP_SET,KLCoilTypeR,10}, |
| | | |
| | | {OP_ST,KLCoilTypeX,1}, |
| | | {OP_DF}, |
| | | {OP_RESET,KLCoilTypeR,10}, |
| | | /* |
| | | {OP_ST,KLCoilTypeR,10}, |
| | | {OP_AN,KLCoilTypeR,51}, |
| | | {OP_AN,KLCoilTypeR,52}, |
| | | {OP_AN,KLCoilTypeR,53}, |
| | | {OP_ADD3,0,21}, {KLDataTypeDT,KLDataTypeDT,31}, {0,KLDataTypeDT,32}, |
| | | |
| | | {OP_ST,KLCoilTypeR,10}, |
| | | {OP_AN,KLCoilTypeR,54}, |
| | | {OP_AN,KLCoilTypeR,55}, |
| | | {OP_AN,KLCoilTypeR,56}, |
| | | {OP_ADD3,0,23}, {KLDataTypeDT,KLDataTypeDT,33}, {0,KLDataTypeDT,34}, |
| | | */ |
| | | {OP_ST,KLCoilTypeSR,1}, |
| | | {OP_PSHS}, |
| | | {OP_AN,KLCoilTypeR,51}, |
| | | {OP_OUT,KLCoilTypeY,1}, |
| | | {OP_RDS}, |
| | | {OP_AN,KLCoilTypeR,52}, |
| | | {OP_OUT,KLCoilTypeY,2}, |
| | | {OP_RDS}, |
| | | {OP_AN,KLCoilTypeR,53}, |
| | | {OP_OUT,KLCoilTypeY,3}, |
| | | {OP_RDS}, |
| | | {OP_AN,KLCoilTypeR,54}, |
| | | {OP_OUT,KLCoilTypeY,4}, |
| | | {OP_RDS}, |
| | | {OP_AN,KLCoilTypeR,55}, |
| | | {OP_OUT,KLCoilTypeY,5}, |
| | | {OP_POPS}, |
| | | {OP_AN,KLCoilTypeR,56}, |
| | | {OP_OUT,KLCoilTypeY,6}, |
| | | |
| | | {OP_ST,KLCoilTypeR,10}, |
| | | {OP_DF}, |
| | | {OP_PSHS}, |
| | | {OP_MV,0,150}, {KLDataTypeDEC,KLDataTypeDT,11}, |
| | | {OP_MV,0,30}, {KLDataTypeDEC,KLDataTypeDT,12}, |
| | | {OP_RDS}, |
| | | {OP_MV,0,150}, {KLDataTypeDEC,KLDataTypeDT,13}, |
| | | {OP_MV,0,30}, {KLDataTypeDEC,KLDataTypeDT,14}, |
| | | {OP_POPS}, |
| | | {OP_AN_,KLCoilTypeR,11}, |
| | | {OP_AN_,KLCoilTypeR,12}, |
| | | {OP_AN_,KLCoilTypeR,13}, |
| | | {OP_AN_,KLCoilTypeR,14}, |
| | | {OP_SET,KLCoilTypeR,14}, |
| | | |
| | | {OP_ST,KLCoilTypeR,10}, |
| | | {OP_PSHS}, |
| | | {OP_AN,KLCoilTypeR,11}, |
| | | {OP_DF}, |
| | | {OP_SET,KLCoilTypeR,51}, |
| | | {OP_RESET,KLCoilTypeR,52}, |
| | | {OP_RESET,KLCoilTypeR,53}, |
| | | {OP_RESET,KLCoilTypeR,54}, |
| | | {OP_RESET,KLCoilTypeR,55}, |
| | | {OP_SET,KLCoilTypeR,56}, |
| | | |
| | | {OP_RDS}, |
| | | {OP_AN,KLCoilTypeR,11}, |
| | | |
| | | {OP_PSHS}, |
| | | {OP_TMX,11,11}, {KLDataTypeDT,0,0}, |
| | | {OP_RESET,KLCoilTypeR,11}, |
| | | {OP_SET,KLCoilTypeR,12}, |
| | | {OP_POPS}, |
| | | {OP_SUB3,0,11}, {KLDataTypeSV,KLDataTypeEV,11}, {0,KLDataTypeDT,21}, |
| | | {OP_AN_LE,0,21},{KLDataTypeDT,KLDataTypeDEC,30}, |
| | | {OP_PSHS}, |
| | | {OP_DIV,0,21}, {KLDataTypeDT,KLDataTypeDEC,10}, {0,KLDataTypeDT,31}, |
| | | {OP_RDS}, |
| | | {OP_AN_GE,0,32},{KLDataTypeDT,KLDataTypeDEC,5}, |
| | | {OP_SET,KLCoilTypeR,51}, |
| | | {OP_POPS}, |
| | | {OP_AN_LT,0,32},{KLDataTypeDT,KLDataTypeDEC,5}, |
| | | {OP_RESET,KLCoilTypeR,51}, |
| | | {OP_RDS}, |
| | | {OP_AN,KLCoilTypeR,12}, |
| | | {OP_DF}, |
| | | {OP_RESET,KLCoilTypeR,51}, |
| | | {OP_SET,KLCoilTypeR,52}, |
| | | {OP_RDS}, |
| | | {OP_AN,KLCoilTypeR,12}, |
| | | {OP_TMX,12,12}, {KLDataTypeDT,0,0}, |
| | | {OP_RESET,KLCoilTypeR,12}, |
| | | {OP_SET,KLCoilTypeR,13}, |
| | | {OP_POPS}, |
| | | {OP_AN,KLCoilTypeR,12}, |
| | | {OP_OUT,KLCoilTypeR,52}, |
| | | |
| | | {OP_ST,KLCoilTypeR,10}, |
| | | {OP_PSHS}, |
| | | {OP_AN,KLCoilTypeR,13}, |
| | | {OP_DF}, |
| | | {OP_RESET,KLCoilTypeR,52}, |
| | | {OP_SET,KLCoilTypeR,53}, |
| | | {OP_SET,KLCoilTypeR,54}, |
| | | {OP_RESET,KLCoilTypeR,56}, |
| | | {OP_RDS}, |
| | | {OP_AN,KLCoilTypeR,13}, |
| | | {OP_TMX,13,13}, {KLDataTypeDT,0,0}, |
| | | {OP_RESET,KLCoilTypeR,13}, |
| | | {OP_SET,KLCoilTypeR,14}, |
| | | {OP_RDS}, |
| | | {OP_AN,KLCoilTypeR,13}, |
| | | {OP_SUB3,0,13}, {KLDataTypeSV,KLDataTypeEV,13}, {0,KLDataTypeDT,23}, |
| | | {OP_AN_LE,0,23},{KLDataTypeDT,KLDataTypeDEC,30}, |
| | | {OP_PSHS}, |
| | | {OP_DIV,0,23}, {KLDataTypeDT,KLDataTypeDEC,10}, {0,KLDataTypeDT,33}, |
| | | {OP_RDS}, |
| | | {OP_AN_GE,0,34},{KLDataTypeDT,KLDataTypeDEC,5}, |
| | | {OP_SET,KLCoilTypeR,54}, |
| | | {OP_POPS}, |
| | | {OP_AN_LT,0,34},{KLDataTypeDT,KLDataTypeDEC,5}, |
| | | {OP_RESET,KLCoilTypeR,54}, |
| | | {OP_RDS}, |
| | | {OP_AN,KLCoilTypeR,14}, |
| | | {OP_DF}, |
| | | {OP_RESET,KLCoilTypeR,54}, |
| | | {OP_SET,KLCoilTypeR,55}, |
| | | {OP_POPS}, |
| | | {OP_AN,KLCoilTypeR,14}, |
| | | {OP_TMX,14,14}, {KLDataTypeDT,0,0}, |
| | | {OP_RESET,KLCoilTypeR,14}, |
| | | {OP_SET,KLCoilTypeR,11}, |
| | | }; |
| | | |
| | | /* |
| | | |
| | | {OP_ST,Addr_R,1}, |
| | | {OP_PSHS,0,0}, |
| | | {OP_AN_,Addr_Y,1}, |
| | | {OP_TMR,5,200}, |
| | | {OP_SET,Addr_Y,1}, |
| | | {OP_POPS,0,0}, |
| | | {OP_AN,Addr_Y,1}, |
| | | {OP_TMR,6,200}, |
| | | {OP_RESET,Addr_Y,1}, |
| | | |
| | | */ |
| | | int nSizeProg1=sizeof(prog1)/sizeof(stBinProg1); |
| | | |
| | | int InitPLC() |
| | | { |
| | |
| | | KMem.DT[i]=0; |
| | | } |
| | | for (int i=0;i<TOTALTIMERS;i++){ |
| | | KMem.Timers[i].nInited=0; |
| | | PLCMem.Timers[i].nInited=0; |
| | | } |
| | | |
| | | PLCMem.bPLCRunning=1; |
| | |
| | | PLCMem.bPLCRunning=0; |
| | | for (int i=0;i<KLDataWXCount;i++) KMem.WY[i]=0; |
| | | for (int i=0;i<KLDataWLCount;i++) KMem.WLY[i]=0; |
| | | KMRunStat.WorkMode2=PLCMem.bPLCRunning; |
| | | return 0; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | int ProcessPLCBinProg(const stBinProg1 * pBinprog, int nStepSize) |
| | | int ProcessPLCBinProg(const stBinInstrcn1 * pBinProg, int nProgSteps) |
| | | { |
| | | if (!PLCMem.bPLCRunning) return 0; |
| | | |
| | | if (PLCMem.nScanCount == 0) { |
| | | SetCoilValue(KLCoilTypeSR, 13, 1); |
| | | SetCoilValue(KLCoilTypeSR, 0, 0); |
| | | SetCoilValue(KLCoilTypeSR, 1, 1); |
| | | SetCoilValue(KLCoilTypeSR, 10, 1); |
| | | SetCoilValue(KLCoilTypeSR, 11, 0); |
| | | SetCoilValue(KLCoilTypeSR, 13, 1); |
| | | } |
| | | else |
| | | { |
| | | SetCoilValue(KLCoilTypeSR, 13, 0); |
| | | SetCoilValue(KLCoilTypeSR, 0, 0); |
| | | SetCoilValue(KLCoilTypeSR, 1, 1); |
| | | SetCoilValue(KLCoilTypeSR, 10, 1); |
| | | SetCoilValue(KLCoilTypeSR, 11, 0); |
| | | SetCoilValue(KLCoilTypeSR, 13, 0); |
| | | } |
| | | for (int i = 0; i < TOTAL_CurVAL; i++) { |
| | | KMem.CurVALs[i] = 0; |
| | | PLCMem.CurVALs[i] = 0; |
| | | } |
| | | int CurPos = 0; |
| | | // stBinProg1 * pBinProg1; |
| | | stBinProg15 * pBinProg15; |
| | | stBinProg2 * pBinProg2; |
| | | stBinProg3 * pBinProg3; |
| | | // stBinInstrcn1 * pBinInstrcn1; |
| | | stBinInstrcn15 * pBinInstrcn15; |
| | | stBinInstrcn2 * pBinInstrcn2; |
| | | stBinInstrcn3 * pBinInstrcn3; |
| | | |
| | | int lastScanInputVal = 1;//??????,????????,? ?? ??? |
| | | |
| | | while (CurPos < nStepSize) |
| | | const stBinInstrcn1 * pBinInstrcn = pBinProg; |
| | | |
| | | while (CurPos < nProgSteps) |
| | | { |
| | | unsigned int nNextPos = 1; |
| | | unsigned int thisOP = pBinprog[CurPos].nOp; |
| | | unsigned int thisOP = pBinInstrcn[CurPos].nOp; |
| | | // unsigned int nParamCount = 0 |
| | | unsigned char thisAddrType = pBinprog[CurPos].nParamType; |
| | | unsigned short thisAddr = pBinprog[CurPos].nParamAddr; |
| | | unsigned char thisAddrType = pBinInstrcn[CurPos].nParamType; |
| | | unsigned short thisAddr = pBinInstrcn[CurPos].nParamAddr; |
| | | |
| | | |
| | | switch (thisOP) |
| | |
| | | case OP_NOP: |
| | | break; |
| | | //??? ?? |
| | | case OP_END: |
| | | nNextPos = nProgSteps; |
| | | break; |
| | | case OP_NOT: |
| | | case OP_ANS: |
| | | case OP_ORS: |
| | |
| | | switch (thisOP) |
| | | { |
| | | case OP_NOT: |
| | | KMem.CurVAL = !KMem.CurVAL; |
| | | PLCMem.CurVAL = !PLCMem.CurVAL; |
| | | break; |
| | | case OP_ANS: |
| | | KMem.CurVAL = PopOutVal() && KMem.CurVAL; |
| | | PLCMem.CurVAL = PopOutVal() && PLCMem.CurVAL; |
| | | break; |
| | | case OP_ORS: |
| | | KMem.CurVAL = PopOutVal() || KMem.CurVAL; |
| | | PLCMem.CurVAL = PopOutVal() || PLCMem.CurVAL; |
| | | break; |
| | | case OP_PSHS: |
| | | PushInVal(); |
| | | break; |
| | | case OP_RDS: |
| | | KMem.CurVAL = KMem.CurVALs[0] != 0; |
| | | PLCMem.CurVAL = PLCMem.CurVALs[0] != 0; |
| | | break; |
| | | case OP_POPS: |
| | | KMem.CurVAL = PopOutVal(); |
| | | PLCMem.CurVAL = PopOutVal(); |
| | | break; |
| | | case OP_DF: |
| | | KMem.CurVAL = KMem.CurVAL && !lastScanInputVal; |
| | | PLCMem.CurVAL = PLCMem.CurVAL && !lastScanInputVal; |
| | | break; |
| | | case OP_DF_: |
| | | KMem.CurVAL = !KMem.CurVAL && lastScanInputVal; |
| | | PLCMem.CurVAL = !PLCMem.CurVAL && lastScanInputVal; |
| | | break; |
| | | |
| | | default: |
| | |
| | | { |
| | | case OP_ST: |
| | | PushInVal(); |
| | | KMem.CurVAL = GetCoilValue(thisAddrType, thisAddr); |
| | | PLCMem.CurVAL = GetCoilValue(thisAddrType, thisAddr); |
| | | break; |
| | | case OP_ST_: |
| | | PushInVal(); |
| | | KMem.CurVAL = !GetCoilValue(thisAddrType, thisAddr); |
| | | PLCMem.CurVAL = !GetCoilValue(thisAddrType, thisAddr); |
| | | break; |
| | | case OP_AN: |
| | | KMem.CurVAL = KMem.CurVAL&&GetCoilValue(thisAddrType, thisAddr); |
| | | PLCMem.CurVAL = PLCMem.CurVAL&&GetCoilValue(thisAddrType, thisAddr); |
| | | break; |
| | | case OP_AN_: |
| | | KMem.CurVAL = KMem.CurVAL && (!GetCoilValue(thisAddrType, thisAddr)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL && (!GetCoilValue(thisAddrType, thisAddr)); |
| | | break; |
| | | case OP_OR: |
| | | KMem.CurVAL = KMem.CurVAL || GetCoilValue(thisAddrType, thisAddr); |
| | | PLCMem.CurVAL = PLCMem.CurVAL || GetCoilValue(thisAddrType, thisAddr); |
| | | break; |
| | | case OP_OR_: |
| | | KMem.CurVAL = KMem.CurVAL || (!GetCoilValue(thisAddrType, thisAddr)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL || (!GetCoilValue(thisAddrType, thisAddr)); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | switch (thisOP) |
| | | { |
| | | case OP_OUT: |
| | | SetCoilValue(thisAddrType, thisAddr, KMem.CurVAL); |
| | | SetCoilValue(thisAddrType, thisAddr, PLCMem.CurVAL); |
| | | break; |
| | | case OP_SET: |
| | | if (KMem.CurVAL) SetCoilValue(thisAddrType, thisAddr, 1); |
| | | if (PLCMem.CurVAL) SetCoilValue(thisAddrType, thisAddr, 1); |
| | | break; |
| | | case OP_RESET: |
| | | if (KMem.CurVAL) SetCoilValue(thisAddrType, thisAddr, 0); |
| | | if (PLCMem.CurVAL) SetCoilValue(thisAddrType, thisAddr, 0); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | case OP_OR_GT: |
| | | case OP_OR_LE: |
| | | case OP_OR_GE: |
| | | pBinProg2 = (stBinProg2 *)&pBinprog[CurPos]; |
| | | thisAddrType = pBinProg2->nParamType1; |
| | | pBinInstrcn2 = (stBinInstrcn2 *)&pBinInstrcn[CurPos]; |
| | | thisAddrType = pBinInstrcn2->nParamType1; |
| | | |
| | | switch (thisOP) |
| | | { |
| | | case OP_ST_EQ: |
| | | PushInVal(); |
| | | KMem.CurVAL = (GetVarData(thisAddrType, thisAddr) == GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = (GetVarData(thisAddrType, thisAddr) == GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_ST_NE: |
| | | PushInVal(); |
| | | KMem.CurVAL = (GetVarData(thisAddrType, thisAddr) != GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = (GetVarData(thisAddrType, thisAddr) != GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_ST_LT: |
| | | PushInVal(); |
| | | KMem.CurVAL = (GetVarData(thisAddrType, thisAddr) < GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = (GetVarData(thisAddrType, thisAddr) < GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_ST_GT: |
| | | PushInVal(); |
| | | KMem.CurVAL = (GetVarData(thisAddrType, thisAddr) > GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = (GetVarData(thisAddrType, thisAddr) > GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_ST_LE: |
| | | PushInVal(); |
| | | KMem.CurVAL = (GetVarData(thisAddrType, thisAddr) <= GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = (GetVarData(thisAddrType, thisAddr) <= GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_ST_GE: |
| | | PushInVal(); |
| | | KMem.CurVAL = (GetVarData(thisAddrType, thisAddr) >= GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = (GetVarData(thisAddrType, thisAddr) >= GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_AN_EQ: |
| | | KMem.CurVAL = KMem.CurVAL && (GetVarData(thisAddrType, thisAddr) == GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL && (GetVarData(thisAddrType, thisAddr) == GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_AN_NE: |
| | | KMem.CurVAL = KMem.CurVAL && (GetVarData(thisAddrType, thisAddr) != GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL && (GetVarData(thisAddrType, thisAddr) != GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_AN_LT: |
| | | KMem.CurVAL = KMem.CurVAL && (GetVarData(thisAddrType, thisAddr) < GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL && (GetVarData(thisAddrType, thisAddr) < GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_AN_GT: |
| | | KMem.CurVAL = KMem.CurVAL && (GetVarData(thisAddrType, thisAddr) > GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL && (GetVarData(thisAddrType, thisAddr) > GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_AN_LE: |
| | | KMem.CurVAL = KMem.CurVAL && (GetVarData(thisAddrType, thisAddr) <= GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL && (GetVarData(thisAddrType, thisAddr) <= GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_AN_GE: |
| | | KMem.CurVAL = KMem.CurVAL && (GetVarData(thisAddrType, thisAddr) >= GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL && (GetVarData(thisAddrType, thisAddr) >= GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | |
| | | case OP_OR_EQ: |
| | | KMem.CurVAL = KMem.CurVAL || (GetVarData(thisAddrType, thisAddr) == GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL || (GetVarData(thisAddrType, thisAddr) == GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_OR_NE: |
| | | KMem.CurVAL = KMem.CurVAL || (GetVarData(thisAddrType, thisAddr) != GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL || (GetVarData(thisAddrType, thisAddr) != GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_OR_LT: |
| | | KMem.CurVAL = KMem.CurVAL || (GetVarData(thisAddrType, thisAddr) < GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL || (GetVarData(thisAddrType, thisAddr) < GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_OR_GT: |
| | | KMem.CurVAL = KMem.CurVAL || (GetVarData(thisAddrType, thisAddr) > GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL || (GetVarData(thisAddrType, thisAddr) > GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_OR_LE: |
| | | KMem.CurVAL = KMem.CurVAL || (GetVarData(thisAddrType, thisAddr) <= GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL || (GetVarData(thisAddrType, thisAddr) <= GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | case OP_OR_GE: |
| | | KMem.CurVAL = KMem.CurVAL || (GetVarData(thisAddrType, thisAddr) >= GetVarData(pBinProg2->nParamType2, pBinProg2->nParamAddr2)); |
| | | PLCMem.CurVAL = PLCMem.CurVAL || (GetVarData(thisAddrType, thisAddr) >= GetVarData(pBinInstrcn2->nParamType2, pBinInstrcn2->nParamAddr2)); |
| | | break; |
| | | |
| | | default: |
| | |
| | | case OP_TMR: |
| | | case OP_TMX: |
| | | case OP_TMY: |
| | | pBinProg15 = (stBinProg15 *)(&pBinprog[CurPos]); |
| | | pBinInstrcn15 = (stBinInstrcn15 *)(&pBinInstrcn[CurPos]); |
| | | { |
| | | unsigned char thisNum= pBinProg15->nOpNum; |
| | | thisAddrType = pBinProg15->nParamType1; |
| | | thisAddr = pBinProg15->nParamAddr1; |
| | | unsigned char thisNum= pBinInstrcn15->nOpNum; |
| | | thisAddrType = pBinInstrcn15->nParamType1; |
| | | thisAddr = pBinInstrcn15->nParamAddr1; |
| | | switch (thisOP) |
| | | { |
| | | case OP_TML: |
| | | if (!KMem.Timers[thisNum].nInited) InitTimer(thisNum, 0); |
| | | if (KMem.CurVAL) RunTimer(thisNum, GetVarData(thisAddrType, thisAddr)); |
| | | if (!PLCMem.Timers[thisNum].nInited) InitTimer(thisNum, 0); |
| | | if (PLCMem.CurVAL) RunTimer(thisNum, GetVarData(thisAddrType, thisAddr)); |
| | | else StopTimer(thisNum); |
| | | KMem.CurVAL = ProcessTimer(thisNum); |
| | | PLCMem.CurVAL = ProcessTimer(thisNum); |
| | | |
| | | break; |
| | | case OP_TMR: |
| | | if (!KMem.Timers[thisNum].nInited) InitTimer(thisNum, 1); |
| | | if (KMem.CurVAL) RunTimer(thisNum, GetVarData(thisAddrType, thisAddr)); |
| | | if (!PLCMem.Timers[thisNum].nInited) InitTimer(thisNum, 1); |
| | | if (PLCMem.CurVAL) RunTimer(thisNum, GetVarData(thisAddrType, thisAddr)); |
| | | else StopTimer(thisNum); |
| | | KMem.CurVAL = ProcessTimer(thisNum); |
| | | PLCMem.CurVAL = ProcessTimer(thisNum); |
| | | break; |
| | | case OP_TMX: |
| | | if (!KMem.Timers[thisNum].nInited) InitTimer(thisNum, 2); |
| | | if (KMem.CurVAL) RunTimer(thisNum, GetVarData(thisAddrType, thisAddr)); |
| | | if (!PLCMem.Timers[thisNum].nInited) InitTimer(thisNum, 2); |
| | | if (PLCMem.CurVAL) RunTimer(thisNum, GetVarData(thisAddrType, thisAddr)); |
| | | else StopTimer(thisNum); |
| | | KMem.CurVAL = ProcessTimer(thisNum); |
| | | PLCMem.CurVAL = ProcessTimer(thisNum); |
| | | |
| | | break; |
| | | case OP_TMY: |
| | | if (!KMem.Timers[thisNum].nInited) InitTimer(thisNum, 3); |
| | | if (KMem.CurVAL) RunTimer(thisNum, GetVarData(thisAddrType, thisAddr)); |
| | | if (!PLCMem.Timers[thisNum].nInited) InitTimer(thisNum, 3); |
| | | if (PLCMem.CurVAL) RunTimer(thisNum, GetVarData(thisAddrType, thisAddr)); |
| | | else StopTimer(thisNum); |
| | | KMem.CurVAL = ProcessTimer(thisNum); |
| | | PLCMem.CurVAL = ProcessTimer(thisNum); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | // 1 ?????? |
| | | case OP_INC: |
| | | case OP_DEC: |
| | | pBinProg15 = (stBinProg15 *)(&pBinprog[CurPos]); |
| | | thisAddrType = pBinProg15->nParamType1; |
| | | thisAddr = pBinProg15->nParamAddr1; |
| | | pBinInstrcn15 = (stBinInstrcn15 *)(&pBinInstrcn[CurPos]); |
| | | thisAddrType = pBinInstrcn15->nParamType1; |
| | | thisAddr = pBinInstrcn15->nParamAddr1; |
| | | nNextPos = 2; |
| | | switch (thisOP) |
| | | { |
| | | case OP_INC: |
| | | if (KMem.CurVAL) SetVarData(thisAddrType, thisAddr, GetVarData(thisAddrType, thisAddr) + 1); |
| | | if (PLCMem.CurVAL) SetVarData(thisAddrType, thisAddr, GetVarData(thisAddrType, thisAddr) + 1); |
| | | break; |
| | | case OP_DEC: |
| | | if (KMem.CurVAL) SetVarData(thisAddrType, thisAddr, GetVarData(thisAddrType, thisAddr) - 1); |
| | | if (PLCMem.CurVAL) SetVarData(thisAddrType, thisAddr, GetVarData(thisAddrType, thisAddr) - 1); |
| | | break; |
| | | |
| | | default: |
| | |
| | | case OP_MV: |
| | | case OP_ADD2: |
| | | case OP_SUB2: |
| | | pBinProg2 = (stBinProg2 *)(&pBinprog[CurPos]); |
| | | pBinInstrcn2 = (stBinInstrcn2 *)(&pBinInstrcn[CurPos]); |
| | | { |
| | | int nParamType2, nParamAddr2; |
| | | thisAddrType = pBinProg2->nParamType1; |
| | | thisAddr = pBinProg2->nParamAddr1; |
| | | nParamType2 = pBinProg2->nParamType2; |
| | | nParamAddr2 = pBinProg2->nParamAddr2; |
| | | thisAddrType = pBinInstrcn2->nParamType1; |
| | | thisAddr = pBinInstrcn2->nParamAddr1; |
| | | nParamType2 = pBinInstrcn2->nParamType2; |
| | | nParamAddr2 = pBinInstrcn2->nParamAddr2; |
| | | |
| | | switch (thisOP) |
| | | { |
| | | case OP_MV: |
| | | if (KMem.CurVAL) SetVarData(nParamType2, nParamAddr2, GetVarData(thisAddrType, thisAddr)); |
| | | if (PLCMem.CurVAL) SetVarData(nParamType2, nParamAddr2, GetVarData(thisAddrType, thisAddr)); |
| | | break; |
| | | case OP_ADD2: |
| | | if (KMem.CurVAL) SetVarData(nParamType2, nParamAddr2, GetVarData(thisAddrType, thisAddr) + GetVarData(nParamType2, nParamAddr2)); |
| | | if (PLCMem.CurVAL) SetVarData(nParamType2, nParamAddr2, GetVarData(thisAddrType, thisAddr) + GetVarData(nParamType2, nParamAddr2)); |
| | | break; |
| | | case OP_SUB2: |
| | | if (KMem.CurVAL) SetVarData(nParamType2, nParamAddr2, GetVarData(nParamType2, nParamAddr2) - GetVarData(thisAddrType, thisAddr)); |
| | | if (PLCMem.CurVAL) SetVarData(nParamType2, nParamAddr2, GetVarData(nParamType2, nParamAddr2) - GetVarData(thisAddrType, thisAddr)); |
| | | break; |
| | | |
| | | default: |
| | |
| | | case OP_SUB3: |
| | | case OP_MUL: |
| | | case OP_DIV: |
| | | pBinProg3 = (stBinProg3 *)(&pBinprog[CurPos]); |
| | | pBinInstrcn3 = (stBinInstrcn3 *)(&pBinInstrcn[CurPos]); |
| | | int nParamType2, nParamAddr2; |
| | | int nParamType3, nParamAddr3; |
| | | thisAddrType = pBinProg3->nParamType1; |
| | | thisAddr = pBinProg3->nParamAddr1; |
| | | nParamType2 = pBinProg3->nParamType2; |
| | | nParamAddr2 = pBinProg3->nParamAddr2; |
| | | nParamType3 = pBinProg3->nParamType3; |
| | | nParamAddr3 = pBinProg3->nParamAddr3; |
| | | thisAddrType = pBinInstrcn3->nParamType1; |
| | | thisAddr = pBinInstrcn3->nParamAddr1; |
| | | nParamType2 = pBinInstrcn3->nParamType2; |
| | | nParamAddr2 = pBinInstrcn3->nParamAddr2; |
| | | nParamType3 = pBinInstrcn3->nParamType3; |
| | | nParamAddr3 = pBinInstrcn3->nParamAddr3; |
| | | switch (thisOP) |
| | | { |
| | | case OP_ADD3: |
| | | if (KMem.CurVAL) SetVarData(nParamType3, nParamAddr3, GetVarData(thisAddrType, thisAddr) + GetVarData(nParamType2, nParamAddr2)); |
| | | if (PLCMem.CurVAL) SetVarData(nParamType3, nParamAddr3, GetVarData(thisAddrType, thisAddr) + GetVarData(nParamType2, nParamAddr2)); |
| | | break; |
| | | case OP_SUB3: |
| | | if (KMem.CurVAL) SetVarData(nParamType3, nParamAddr3, GetVarData(thisAddrType, thisAddr) - GetVarData(nParamType2, nParamAddr2)); |
| | | if (PLCMem.CurVAL) SetVarData(nParamType3, nParamAddr3, GetVarData(thisAddrType, thisAddr) - GetVarData(nParamType2, nParamAddr2)); |
| | | break; |
| | | case OP_MUL: |
| | | if (KMem.CurVAL) { |
| | | if (PLCMem.CurVAL) { |
| | | short multiplicand = GetVarData(thisAddrType, thisAddr); |
| | | short multiplier = GetVarData(nParamType2, nParamAddr2); |
| | | int product = multiplicand * multiplier; |
| | |
| | | } |
| | | break; |
| | | case OP_DIV: |
| | | if (KMem.CurVAL) { |
| | | if (PLCMem.CurVAL) { |
| | | short dividend = GetVarData(thisAddrType, thisAddr); |
| | | short divisor = GetVarData(nParamType2, nParamAddr2); |
| | | short quotient = dividend / divisor; |
| | |
| | | default: |
| | | break; |
| | | } |
| | | lastScanInputVal = GetBitValue( PLCMem.ProgTrace[CurPos>>4],CurPos&0xf); //GetBitValue(KMem.WDFs); |
| | | SetBitValue( &PLCMem.ProgTrace[CurPos>>4],CurPos&0xf, KMem.CurVAL); |
| | | lastScanInputVal = GetBitValue( PLCMem.ProgTrace[CurPos>>4],CurPos&0xf); //GetBitValue(PLCMem.WDFs); |
| | | SetBitValue( &PLCMem.ProgTrace[CurPos>>4],CurPos&0xf, PLCMem.CurVAL); |
| | | |
| | | // lastScanInputVal = PLCMem.ProgTrace[CurPos]; //GetBitValue(KMem.WDFs); |
| | | // PLCMem.ProgTrace[CurPos] = KMem.CurVAL; |
| | | // lastScanInputVal = PLCMem.ProgTrace[CurPos]; //GetBitValue(PLCMem.WDFs); |
| | | // PLCMem.ProgTrace[CurPos] = PLCMem.CurVAL; |
| | | CurPos += nNextPos; |
| | | } |
| | | PLCMem.nScanCount++; |
| | | return 0; |
| | | return CurPos; |
| | | } |
| | | #endif // ENABLE_PLC |
| | |
| | | int sprintftime = 0; |
| | | int putstrtime = 0; |
| | | const unsigned char buf1[16]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff,0x00}; |
| | | char str1[256]; |
| | | char str1[128]; |
| | | int LineCount=0; |
| | | int Uart1baudval=0; |
| | | int Uart2baudval=0; |
| | |
| | | |
| | | int ShowInitInfo() |
| | | { |
| | | /* |
| | | int len1=0; |
| | | clearscreen(); |
| | | uint32_t us1,us2,us3,us4,us5,us6; |
| | | |
| | | // Locate(1,1); |
| | | |
| | | /* |
| | | LoadFlashDatas(); |
| | | |
| | | LoadAndUpdateStoreCfg(); |
| | | |
| | | HAL_StatusTypeDef res; |
| | | stStoreCfg * pFCfg = (stStoreCfg *) GetCurStoreCfgAddr(); |
| | | stStoreCfg * pFCfg2 = GetNextStoreCfgAddr(pFCfg); |
| | | |
| | | int t11=GetuS(); |
| | | |
| | | for (int i=0;i<20;i++) |
| | | { |
| | | tims[i]=GetuS(); |
| | | } |
| | | clearscreen(); |
| | | len1+=sprintf(str1+len1," Ver 001 \r\n"); |
| | | len1+=sprintf(str1+len1," Uart1Baud %d Uart2Baud %d UID %08x %08x %08x \r\n",Uart1Baud,Uart2Baud,pUID[0],pUID[1],pUID[2]); |
| | | len1+=sprintf(str1+len1," Flash = %d %d %d %d res = %d ",FlashDatas[0],FlashDatas[1],FlashDatas[2],FlashDatas[3],res); |
| | | len1+=sprintf(str1+len1,"flash operation = %u %u %u\r\n",t11-t10,t10,t11); |
| | | PutStr(str1,len1); |
| | | len1=0; |
| | | len1+=sprintf(str1+len1,"%08X %X %X , PowerOn %X UpTime %X %X %X %X \r\n", |
| | | (uint32_t)pFCfg,pFCfg[0].Sign1,pFCfg[0].SN1,pFCfg[0].PowerCount,pFCfg[0].UpTime,pFCfg[0].UserData1,pFCfg[0].CRC1,pFCfg[0].EndSign1); |
| | | len1+=sprintf(str1+len1,"%08X %X %X , PowerOn %X UpTime %X %X %X %X \r\n", |
| | | (uint32_t)pFCfg2,Cfg2.Sign1,Cfg2.SN1,Cfg2.PowerCount,Cfg2.UpTime,Cfg2.UserData1,Cfg2.CRC1,Cfg2.EndSign1); |
| | | PutStr(str1,len1); |
| | | */ |
| | | len1=0; |
| | | /* |
| | | for (int i=0;i<8;i++) |
| | | { |
| | | len1=0; |
| | | len1+=sprintf(str1+len1,"%02X:",i*32); |
| | | for (int j=0;j<8;j++) |
| | | { |
| | | len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]); |
| | | } |
| | | len1+=sprintf(str1+len1," %02X",pFlash1[i*32+8]); |
| | | for (int j=9;j<16;j++) |
| | | { |
| | | len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]); |
| | | } |
| | | len1+=sprintf(str1+len1," | %02X",pFlash1[i*32+16]); |
| | | for (int j=17;j<24;j++) |
| | | { |
| | | len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]); |
| | | } |
| | | len1+=sprintf(str1+len1," %02X",pFlash1[i*32+24]); |
| | | for (int j=25;j<32;j++) |
| | | { |
| | | len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]); |
| | | } |
| | | len1+=sprintf(str1+len1,"\r\n"); |
| | | PutStr(str1,len1); |
| | | } |
| | | */ |
| | | us1=GetuS(); |
| | | int crc1 = crc_check(buf1,16); //7us |
| | | us2=GetuS(); |
| | |
| | | // RunTimer(0,1000); |
| | | // StartTimer(2,1000); |
| | | Locate(13,1);LineCount=3; |
| | | */ |
| | | return 0; |
| | | } |
| | | |
| | |
| | | |
| | | 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, |
| | |
| | | } |
| | | return (crchi << 8 | crclo); |
| | | } |
| | | |
| | | /* |
| | | 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; |
| | | } |
| | | |
| | |
| | | logData(value); |
| | | } |
| | | } |
| | | #endif |
| | | #else |
| | | UNUSED(value); |
| | | #endif |
| | | } |
| | | } |
| | | |
| | |
| | | #else |
| | | Uart2UnsetDE(); |
| | | #endif |
| | | Uart2Stat.bSendDone = 1; |
| | | TriggerPendSV(); |
| | | } |
| | | void Uart2RecvDone() |
| | | { |
| | |
| | | #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ |
| | | #endif |
| | | |
| | | |
| | | #define ENABLE_FPX 1 |
| | | //#define ENABLE_PLC 0 |
| | | //#define ENABLE_RF 0 |
| | | //#define ENABLE_NET 0 |
| | | |
| | | #define GetBoardType() (BOARD_TYPE) |
| | | |
| | |
| | | #define DOUTPUT 0 |
| | | #endif |
| | | |
| | | typedef struct tagInfoBlockHdr { |
| | | unsigned short nBlkSign; // å¼å§æ å¿ |
| | | unsigned short nBlkTypeVer; // ç±»ååçæ¬ |
| | | unsigned short nBlkSize; // Block 大å°, å
æ¬å¼å§åç»ææ å¿ |
| | | unsigned short Pad1; |
| | | }stInfoBlockHdr; |
| | | |
| | | typedef struct tagInfoBlockTail { |
| | | |
| | | unsigned short CRC16; |
| | | unsigned short EndSign; |
| | | }stInfoBlockTail; |
| | | |
| | | typedef struct tagBtLdrInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nBtldrVer; |
| | | unsigned short nBtldrDevice; |
| | | unsigned short nBtldrSize; // è®¾è®¡å¤§å° |
| | | unsigned short nBtldrDataSize; //代ç å¤§å° |
| | | unsigned int nBtldr_AppAddr; |
| | | unsigned int nBtldr_NewAppInfoAddr; |
| | | unsigned int nBtldr_NewAppAddr; |
| | | stInfoBlockTail tail; |
| | | }stBtLdrInfoBlock, *pBtLdrInfoBlock; |
| | | |
| | | typedef struct tagAppInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nAppVer; |
| | | unsigned short nAppDevice; |
| | | unsigned short nAppSize; // 代ç è®¾è®¡å¤§å° |
| | | unsigned short nAppDataSize; //å®é
代ç å¤§å° |
| | | unsigned int nAppStartAddr; |
| | | unsigned int nAppStartOffset; |
| | | unsigned int nApp; |
| | | stInfoBlockTail tail; |
| | | }stAppInfoBlock, * pAppInfoBlock; |
| | | |
| | | |
| | | #endif /* __BOARDTYPE_H__ */ |
| | |
| | | #define SetFPxDEPin_0() LL_GPIO_ResetOutputPin(FPxDE_PORT,FPxDE_PIN) |
| | | #define SetFPxDEPin_1() LL_GPIO_SetOutputPin(FPxDE_PORT,FPxDE_PIN) |
| | | |
| | | typedef void *(*FPxCBFuncDef) (int nEvent, void * pBuf, int); //callback func ,prama s is void *,void *,int; return void *; |
| | | typedef void *(*FPxEvCBFuncDef) (int nEvent, void * pBuf, int); //callback func ,prama s is void *,void *,int; return void *; |
| | | |
| | | // extern uint8_t PktBuf1[64]; |
| | | |
| | |
| | | volatile uint8_t oldSYN; |
| | | int RSTCount0; |
| | | int bFirstReq; |
| | | FPxCBFuncDef FPxCBFunc; |
| | | uint8_t bFPxCallBackFuncSet; |
| | | FPxEvCBFuncDef FPxEvCBFunc; |
| | | // uint8_t bFPxCallBackFuncSet; |
| | | |
| | | |
| | | |
| | |
| | | uint8_t FPx_SetIOCount(int nInputBytes, int nOutputBytes); |
| | | uint8_t FPx_Proc(void); |
| | | |
| | | uint8_t FPxCalBCC(uint8_t* pBuf, uint8_t len1); |
| | | uint8_t FPxBCC(uint8_t* pBuf, uint8_t len1); |
| | | uint8_t FPxCheckPkt(uint8_t * pBuf, uint8_t len1); |
| | | uint8_t FPxParsePkt(uint8_t * pBuf, uint8_t len1); |
| | | uint8_t FPxSendPkt(uint8_t * pBuf, uint8_t len1); |
| | | |
| | | |
| | | int FPxSetCallBackFunc(FPxCBFuncDef Func1); |
| | | int FPxSetCallBackFunc(FPxEvCBFuncDef Func1); |
| | | |
| | | enum enumFPxCallBackEvent |
| | | { |
File was renamed from MDK-ARM/F030C8T6_Ext_FPx.uvprojx |
| | |
| | | |
| | | <Targets> |
| | | <Target> |
| | | <TargetName>F030C8T6_Ext_FPx</TargetName> |
| | | <TargetName>Ext_FPx_F030C8T6</TargetName> |
| | | <ToolsetNumber>0x4</ToolsetNumber> |
| | | <ToolsetName>ARM-ADS</ToolsetName> |
| | | <pCCUsed>5060422::V5.06 update 4 (build 422)::ARMCC</pCCUsed> |
| | |
| | | <InvalidFlash>1</InvalidFlash> |
| | | </TargetStatus> |
| | | <OutputDirectory>.\EXT_FPX\</OutputDirectory> |
| | | <OutputName>F030C8T6_Ext_FPx</OutputName> |
| | | <OutputName>Ext_FPx</OutputName> |
| | | <CreateExecutable>1</CreateExecutable> |
| | | <CreateLib>0</CreateLib> |
| | | <CreateHexFile>1</CreateHexFile> |
| | | <DebugInformation>1</DebugInformation> |
| | | <BrowseInformation>1</BrowseInformation> |
| | | <ListingPath>.\F030C8T6_Test2\</ListingPath> |
| | | <ListingPath>.\</ListingPath> |
| | | <HexFormatSelection>1</HexFormatSelection> |
| | | <Merge32K>0</Merge32K> |
| | | <CreateBatchFile>0</CreateBatchFile> |
| | |
| | | <MiscControls></MiscControls> |
| | | <Define>USE_FULL_LL_DRIVER,USE_HAL_DRIVER</Define> |
| | | <Undefine></Undefine> |
| | | <IncludePath>../Ext_FPx/Inc;../Ext_FPx/Src;../Drivers/STM32F0xx_HAL_Driver/Inc;../Drivers/CMSIS/Device/ST/STM32F0xx/Include;../Drivers/CMSIS/Include;../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy;../Comlib/Inc</IncludePath> |
| | | <IncludePath>../Inc;../Src;../../Drivers/STM32F0xx_HAL_Driver/Inc;../../Drivers/CMSIS/Device/ST/STM32F0xx/Include;../../Drivers/CMSIS/Include;../../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy;../../Comlib/Inc</IncludePath> |
| | | </VariousControls> |
| | | </Cads> |
| | | <Aads> |
| | |
| | | <File> |
| | | <FileName>BSP.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\BSP.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\BSP.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>debug.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\debug.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\debug.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>functions.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\functions.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\functions.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>GlobalDef.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\GlobalDef.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\GlobalDef.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KBus.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\KBus.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\KBus.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KLink.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\KLink.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\KLink.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KMachine.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\KMachine.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\KMachine.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>ModbusRTU.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\ModbusRTU.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\ModbusRTU.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>MyQueue.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\MyQueue.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\MyQueue.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>PLCfunctions.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\PLCfunctions.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\PLCfunctions.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>shell.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\shell.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\shell.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32_assert.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\stm32_assert.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\stm32_assert.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_it.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\stm32f0xx_it.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\stm32f0xx_it.h</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <File> |
| | | <FileName>debug.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\debug.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\debug.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>functions.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\functions.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\functions.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>GlobalDef.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\GlobalDef.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\GlobalDef.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KBus.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\KBus.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\KBus.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KLink.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\KLink.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\KLink.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>ModbusRTU.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\ModbusRTU.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\ModbusRTU.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>MyQueue.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\MyQueue.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\MyQueue.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>PLCfunctions.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\PLCfunctions.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\PLCfunctions.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>shell.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\shell.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\shell.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_msp.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\stm32f0xx_hal_msp.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\stm32f0xx_hal_msp.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KMachine.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\KMachine.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\KMachine.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>BSP.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\BSP.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\BSP.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_it.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\stm32f0xx_it.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\stm32f0xx_it.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <File> |
| | | <FileName>BoardType.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\Ext_FPx\Inc\BoardType.h</FilePath> |
| | | <FilePath>..\Inc\BoardType.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>main.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\Ext_FPx\Inc\main.h</FilePath> |
| | | <FilePath>..\Inc\main.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_rcc.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\Ext_FPx\Inc\stm32f0xx_ll_rcc.h</FilePath> |
| | | <FilePath>..\Inc\stm32f0xx_ll_rcc.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_conf.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\Ext_FPx\Inc\stm32f0xx_hal_conf.h</FilePath> |
| | | <FilePath>..\Inc\stm32f0xx_hal_conf.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>FPx.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\Ext_FPx\Inc\FPx.h</FilePath> |
| | | <FilePath>..\Inc\FPx.h</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <File> |
| | | <FileName>main.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Ext_FPx\Src\main.c</FilePath> |
| | | <FilePath>..\Src\main.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>BoardType.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Ext_FPx\Src\BoardType.c</FilePath> |
| | | <FilePath>..\Src\BoardType.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>FPx.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Ext_FPx\Src\FPx.c</FilePath> |
| | | <FilePath>..\Src\FPx.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <File> |
| | | <FileName>system_stm32f0xx.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\system_stm32f0xx.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\system_stm32f0xx.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <File> |
| | | <FileName>stm32f0xx_ll_gpio.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_gpio.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_gpio.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_exti.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_exti.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_exti.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_adc.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_adc.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_adc.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_dma.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_dma.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_dma.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_spi.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_spi.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_spi.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_tim.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_tim_ex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_usart.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_usart.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_usart.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_rcc.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_rcc.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_rcc.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_rcc.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_rcc_ex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_i2c.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_i2c_ex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_gpio.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_dma.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_cortex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_pwr.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_pwr_ex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_flash.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_flash_ex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_utils.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_utils.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_utils.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_tim.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_tim.c</FilePath> |
| | | <FilePath>..\..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_tim.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_flash.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_flash.c</FilePath> |
| | | <FilePath>..\..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_flash.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.4.0" condition="ARMv6_7_8-M Device"> |
| | | <package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.7.0"/> |
| | | <targetInfos> |
| | | <targetInfo name="F030C8T6_Ext_FPx"/> |
| | | <targetInfo name="Ext_FPx_F030C8T6"/> |
| | | </targetInfos> |
| | | </component> |
| | | </components> |
New file |
| | |
| | | ;******************** (C) COPYRIGHT 2016 STMicroelectronics ******************** |
| | | ;* File Name : startup_stm32f030x8.s |
| | | ;* Author : MCD Application Team |
| | | ;* Description : STM32F030x8 devices vector table for MDK-ARM toolchain. |
| | | ;* This module performs: |
| | | ;* - Set the initial SP |
| | | ;* - Set the initial PC == Reset_Handler |
| | | ;* - Set the vector table entries with the exceptions ISR address |
| | | ;* - Branches to __main in the C library (which eventually |
| | | ;* calls main()). |
| | | ;* After Reset the CortexM0 processor is in Thread mode, |
| | | ;* priority is Privileged, and the Stack is set to Main. |
| | | ;* <<< Use Configuration Wizard in Context Menu >>> |
| | | ;******************************************************************************* |
| | | ;* |
| | | ;* Redistribution and use in source and binary forms, with or without modification, |
| | | ;* are permitted provided that the following conditions are met: |
| | | ;* 1. Redistributions of source code must retain the above copyright notice, |
| | | ;* this list of conditions and the following disclaimer. |
| | | ;* 2. Redistributions in binary form must reproduce the above copyright notice, |
| | | ;* this list of conditions and the following disclaimer in the documentation |
| | | ;* and/or other materials provided with the distribution. |
| | | ;* 3. Neither the name of STMicroelectronics nor the names of its contributors |
| | | ;* may be used to endorse or promote products derived from this software |
| | | ;* without specific prior written permission. |
| | | ;* |
| | | ;* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| | | ;* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| | | ;* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| | | ;* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| | | ;* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| | | ;* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| | | ;* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| | | ;* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| | | ;* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| | | ;* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| | | ; |
| | | ;******************************************************************************* |
| | | |
| | | ; Amount of memory (in bytes) allocated for Stack |
| | | ; Tailor this value to your application needs |
| | | ; <h> Stack Configuration |
| | | ; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> |
| | | ; </h> |
| | | |
| | | Stack_Size EQU 0x400 |
| | | |
| | | AREA STACK, NOINIT, READWRITE, ALIGN=3 |
| | | Stack_Mem SPACE Stack_Size |
| | | __initial_sp |
| | | |
| | | |
| | | ; <h> Heap Configuration |
| | | ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> |
| | | ; </h> |
| | | |
| | | Heap_Size EQU 0x200 |
| | | |
| | | AREA HEAP, NOINIT, READWRITE, ALIGN=3 |
| | | __heap_base |
| | | Heap_Mem SPACE Heap_Size |
| | | __heap_limit |
| | | |
| | | PRESERVE8 |
| | | THUMB |
| | | |
| | | |
| | | ; Vector Table Mapped to Address 0 at Reset |
| | | AREA RESET, DATA, READONLY |
| | | EXPORT __Vectors |
| | | EXPORT __Vectors_End |
| | | EXPORT __Vectors_Size |
| | | |
| | | __Vectors DCD __initial_sp ; Top of Stack |
| | | DCD Reset_Handler ; Reset Handler |
| | | DCD NMI_Handler ; NMI Handler |
| | | DCD HardFault_Handler ; Hard Fault Handler |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD SVC_Handler ; SVCall Handler |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD PendSV_Handler ; PendSV Handler |
| | | DCD SysTick_Handler ; SysTick Handler |
| | | |
| | | ; External Interrupts |
| | | DCD WWDG_IRQHandler ; Window Watchdog |
| | | DCD 0 ; Reserved |
| | | DCD RTC_IRQHandler ; RTC through EXTI Line |
| | | DCD FLASH_IRQHandler ; FLASH |
| | | DCD RCC_IRQHandler ; RCC |
| | | DCD EXTI0_1_IRQHandler ; EXTI Line 0 and 1 |
| | | DCD EXTI2_3_IRQHandler ; EXTI Line 2 and 3 |
| | | DCD EXTI4_15_IRQHandler ; EXTI Line 4 to 15 |
| | | DCD 0 ; Reserved |
| | | DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1 |
| | | DCD DMA1_Channel2_3_IRQHandler ; DMA1 Channel 2 and Channel 3 |
| | | DCD DMA1_Channel4_5_IRQHandler ; DMA1 Channel 4 and Channel 5 |
| | | DCD ADC1_IRQHandler ; ADC1 |
| | | DCD TIM1_BRK_UP_TRG_COM_IRQHandler ; TIM1 Break, Update, Trigger and Commutation |
| | | DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare |
| | | DCD 0 ; Reserved |
| | | DCD TIM3_IRQHandler ; TIM3 |
| | | DCD TIM6_IRQHandler ; TIM6 |
| | | DCD 0 ; Reserved |
| | | DCD TIM14_IRQHandler ; TIM14 |
| | | DCD TIM15_IRQHandler ; TIM15 |
| | | DCD TIM16_IRQHandler ; TIM16 |
| | | DCD TIM17_IRQHandler ; TIM17 |
| | | DCD I2C1_IRQHandler ; I2C1 |
| | | DCD I2C2_IRQHandler ; I2C2 |
| | | DCD SPI1_IRQHandler ; SPI1 |
| | | DCD SPI2_IRQHandler ; SPI2 |
| | | DCD USART1_IRQHandler ; USART1 |
| | | DCD USART2_IRQHandler ; USART2 |
| | | |
| | | __Vectors_End |
| | | |
| | | __Vectors_Size EQU __Vectors_End - __Vectors |
| | | |
| | | AREA |.text|, CODE, READONLY |
| | | |
| | | ; Reset handler routine |
| | | Reset_Handler PROC |
| | | EXPORT Reset_Handler [WEAK] |
| | | IMPORT __main |
| | | IMPORT SystemInit |
| | | LDR R0, =SystemInit |
| | | BLX R0 |
| | | LDR R0, =__main |
| | | BX R0 |
| | | ENDP |
| | | |
| | | ; Dummy Exception Handlers (infinite loops which can be modified) |
| | | |
| | | NMI_Handler PROC |
| | | EXPORT NMI_Handler [WEAK] |
| | | B . |
| | | ENDP |
| | | HardFault_Handler\ |
| | | PROC |
| | | EXPORT HardFault_Handler [WEAK] |
| | | B . |
| | | ENDP |
| | | SVC_Handler PROC |
| | | EXPORT SVC_Handler [WEAK] |
| | | B . |
| | | ENDP |
| | | PendSV_Handler PROC |
| | | EXPORT PendSV_Handler [WEAK] |
| | | B . |
| | | ENDP |
| | | SysTick_Handler PROC |
| | | EXPORT SysTick_Handler [WEAK] |
| | | B . |
| | | ENDP |
| | | |
| | | Default_Handler PROC |
| | | |
| | | EXPORT WWDG_IRQHandler [WEAK] |
| | | EXPORT RTC_IRQHandler [WEAK] |
| | | EXPORT FLASH_IRQHandler [WEAK] |
| | | EXPORT RCC_IRQHandler [WEAK] |
| | | EXPORT EXTI0_1_IRQHandler [WEAK] |
| | | EXPORT EXTI2_3_IRQHandler [WEAK] |
| | | EXPORT EXTI4_15_IRQHandler [WEAK] |
| | | EXPORT DMA1_Channel1_IRQHandler [WEAK] |
| | | EXPORT DMA1_Channel2_3_IRQHandler [WEAK] |
| | | EXPORT DMA1_Channel4_5_IRQHandler [WEAK] |
| | | EXPORT ADC1_IRQHandler [WEAK] |
| | | EXPORT TIM1_BRK_UP_TRG_COM_IRQHandler [WEAK] |
| | | EXPORT TIM1_CC_IRQHandler [WEAK] |
| | | EXPORT TIM3_IRQHandler [WEAK] |
| | | EXPORT TIM6_IRQHandler [WEAK] |
| | | EXPORT TIM14_IRQHandler [WEAK] |
| | | EXPORT TIM15_IRQHandler [WEAK] |
| | | EXPORT TIM16_IRQHandler [WEAK] |
| | | EXPORT TIM17_IRQHandler [WEAK] |
| | | EXPORT I2C1_IRQHandler [WEAK] |
| | | EXPORT I2C2_IRQHandler [WEAK] |
| | | EXPORT SPI1_IRQHandler [WEAK] |
| | | EXPORT SPI2_IRQHandler [WEAK] |
| | | EXPORT USART1_IRQHandler [WEAK] |
| | | EXPORT USART2_IRQHandler [WEAK] |
| | | |
| | | |
| | | WWDG_IRQHandler |
| | | RTC_IRQHandler |
| | | FLASH_IRQHandler |
| | | RCC_IRQHandler |
| | | EXTI0_1_IRQHandler |
| | | EXTI2_3_IRQHandler |
| | | EXTI4_15_IRQHandler |
| | | DMA1_Channel1_IRQHandler |
| | | DMA1_Channel2_3_IRQHandler |
| | | DMA1_Channel4_5_IRQHandler |
| | | ADC1_IRQHandler |
| | | TIM1_BRK_UP_TRG_COM_IRQHandler |
| | | TIM1_CC_IRQHandler |
| | | TIM3_IRQHandler |
| | | TIM6_IRQHandler |
| | | TIM14_IRQHandler |
| | | TIM15_IRQHandler |
| | | TIM16_IRQHandler |
| | | TIM17_IRQHandler |
| | | I2C1_IRQHandler |
| | | I2C2_IRQHandler |
| | | SPI1_IRQHandler |
| | | SPI2_IRQHandler |
| | | USART1_IRQHandler |
| | | USART2_IRQHandler |
| | | |
| | | B . |
| | | |
| | | ENDP |
| | | |
| | | ALIGN |
| | | |
| | | ;******************************************************************************* |
| | | ; User Stack and Heap initialization |
| | | ;******************************************************************************* |
| | | IF :DEF:__MICROLIB |
| | | |
| | | EXPORT __initial_sp |
| | | EXPORT __heap_base |
| | | EXPORT __heap_limit |
| | | |
| | | ELSE |
| | | |
| | | IMPORT __use_two_region_memory |
| | | EXPORT __user_initial_stackheap |
| | | |
| | | __user_initial_stackheap |
| | | |
| | | LDR R0, = Heap_Mem |
| | | LDR R1, =(Stack_Mem + Stack_Size) |
| | | LDR R2, = (Heap_Mem + Heap_Size) |
| | | LDR R3, = Stack_Mem |
| | | BX LR |
| | | |
| | | ALIGN |
| | | |
| | | ENDIF |
| | | |
| | | END |
| | | |
| | | ;************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE***** |
| | |
| | | #include "BoardType.h" |
| | | #include "KMachine.h" |
| | | #include "KBus.h" |
| | | |
| | | #define APP_ADDR 0x08001000 //åºç¨ç¨åºé¦å°åå®ä¹ |
| | | #define APPINFOBLOCK_ADDR (APP_ADDR + 0x100) //ç¨åºä¿¡æ¯å å°å |
| | | #define INFOBLOCK_ADDR (APP_ADDR + 0x1000) //ä¿¡æ¯å å°å |
| | | |
| | | #define APP_START_ADDR IROM1_START_ADDRESS |
| | | extern int Region$$Table$$Limit; |
| | | |
| | | #define MAKE_VER(x,y) ((x<<8)|y) |
| | | #define APP_VER MAKE_VER(1,16) |
| | | |
| | | const stAppInfoBlock AppInfoBlock __attribute__((at(APPINFOBLOCK_ADDR))) = |
| | | { |
| | | 0xAA55, // StartSign |
| | | 0x0301, // BlockType |
| | | sizeof(stAppInfoBlock), //BlockSize |
| | | 0, // Pad, |
| | | APP_VER, //AppVer |
| | | (BOARD_TYPE<<8) + BOARD_VER, //AppDevice; |
| | | 0x1000, //AppSize; |
| | | 0x0C00, //AppDataSize; |
| | | APP_ADDR, //nAppStartAddr |
| | | (int)&Region$$Table$$Limit, //nBtldr_NewAppInfoAddr |
| | | 0x08009000, //nBtldr_NewAppAddr |
| | | 0xCCCC, //crc16; |
| | | 0xAA55 //EndSign; |
| | | |
| | | }; |
| | | |
| | | |
| | | const stKMInfoBlock KMInfoBlock __attribute__((at(INFOBLOCK_ADDR))) = |
| | | { |
| | | // sizeof(stKMInfoBlock), |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceType BOARD_VER, //nDevieVer |
| | | APP_VER, //ProgVer |
| | | 0x0102, //KLinkVer |
| | | KBUS_VER, //KBusVer |
| | | // 0x0100, //KNetVer |
| | | // 0x0100, //KWLVer |
| | | |
| | | 4, //nCapacity1 ?K |
| | | 1, //nCapacity2 ?k |
| | | |
| | | DINPUT, //nDInput; |
| | | DOUTPUT, //nDOutput |
| | | |
| | | 0, //nAInput |
| | | 0, //nAOutput |
| | | 0, //nHInput |
| | | 0, //nHOutput |
| | | 0, //nExt1; |
| | | 0, //nExt2; |
| | | 0, //nLogSize; |
| | | 3, //nPorts; |
| | | 0, //nManSize; |
| | | 0, //nAbility; |
| | | 6, //nSwitchBits; |
| | | }; |
| | | |
| | | const stDeviceInfo MyDeviceInfo={ |
| | | |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | APP_VER, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | }; |
| | | |
| | | const stExDeviceInfo MyExDeviceInfo ={ |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | APP_VER, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | |
| | | }; |
| | | |
| | | |
| | |
| | | stFPxStat FPxStat; |
| | | stFPxMem FPxMem; |
| | | |
| | | |
| | | |
| | | uint8_t FPx_Init(int nChilds) |
| | | { |
| | | bSPI1Sending=0; |
| | |
| | | FPxStat.nOutputBytes=2; |
| | | } else |
| | | { |
| | | FPxStat.nInputBytes=nChilds+1; //æ ¹æ®åæºæ°éï¼æ¥åæ©å±å®¹é |
| | | FPxStat.nInputBytes=nChilds; //æ ¹æ®åæºæ°éï¼æ¥åæ©å±å®¹é |
| | | FPxStat.nOutputBytes=nChilds; |
| | | } |
| | | SetACKPin_0(); |
| | |
| | | return 0; |
| | | } |
| | | |
| | | int FPxSetCallBackFunc(FPxCBFuncDef func1) |
| | | int FPxSetCallBackFunc(FPxEvCBFuncDef func1) |
| | | { |
| | | FPxStat.FPxCBFunc = func1; |
| | | FPxStat.bFPxCallBackFuncSet = 1; |
| | | FPxStat.FPxEvCBFunc = func1; |
| | | // FPxStat.bFPxCallBackFuncSet = 1; |
| | | return 0; |
| | | } |
| | | |
| | |
| | | // KMem.WY[5]=CurSEL; |
| | | // KMem.WY[6]=CurSYN; |
| | | // KMem.WY[7]=CurACK; |
| | | if (CurOE) { |
| | | if (CurOE) { // disable output |
| | | for (int j=0;j<FPxStat.nOutputBytes;j++) |
| | | { |
| | | FPxMem.WLYB[j]=0; |
| | | } |
| | | if (FPxStat.bFPxCallBackFuncSet) FPxStat.FPxCBFunc(evFPxStateChange,0,0); |
| | | if (FPxStat.bFPxCallBackFuncSet) FPxStat.FPxCBFunc(evFPxDataUpdate,0,0); |
| | | if (FPxStat.FPxEvCBFunc) FPxStat.FPxEvCBFunc(evFPxStateChange,0,0); |
| | | if (FPxStat.FPxEvCBFunc) FPxStat.FPxEvCBFunc(evFPxDataUpdate,0,0); |
| | | } |
| | | |
| | | if (!CurRST) {FPxStat.RSTCount0=GetuS();} |
| | | if (!CurRST) { // in reset |
| | | FPxStat.RSTCount0=GetuS(); |
| | | SetACKPin_0(); |
| | | FPxStat.bFirstReq=0; |
| | | LL_SPI_Disable(SPI2); |
| | | FPxStat.bConfiged = 0; |
| | | nSPI1RecvPos=0; |
| | | |
| | | } |
| | | if (!FPxStat.bFirstReq && CurRST) |
| | | { |
| | | { // after Reset; |
| | | int RSTCount = GetuS() - FPxStat.RSTCount0 ; |
| | | if (RSTCount>=10000) |
| | | if (RSTCount>=1000) |
| | | { |
| | | logData(0x11); |
| | | |
| | | SetACKPin_1(); |
| | | FPxStat.bFirstReq=1; |
| | | // RSTCount=0; |
| | | // bSPI1Recving=1; |
| | | // KMem.WX[7]=RSTCount/1000; |
| | | LL_SPI_Disable(SPI2); |
| | | LL_SPI_Enable(SPI2); |
| | | nSPI1RecvPos=0; |
| | | } |
| | | } |
| | | if (CurSYN ==0 && FPxStat.oldSYN != 0) { |
| | | KMem.WDT[121] = KMem.WDT[122]; |
| | | KMem.WDT[122]=0; |
| | | nSPI1RecvPos=0; |
| | | logData(0x12); |
| | | } |
| | | if (CurSEL && CurSYN !=0 && FPxStat.oldSYN == 0){ |
| | | bSPI1Recving=1; |
| | | nSPI1RecvPos=0; |
| | | // nSPI1RecvPos=0; |
| | | LL_SPI_Disable(SPI2); |
| | | nSPI1RecvPos=0; |
| | | // nSPI1RecvPos=0; |
| | | LL_SPI_Enable(SPI2); |
| | | logData(0x13); |
| | | } |
| | | if (CurSEL && CurSYN && !bSPI1Sending && !bSPI1Recving) |
| | | { |
| | | bSPI1Recving=1; |
| | | nSPI1RecvPos=0; |
| | | logData(0x14); |
| | | } |
| | | |
| | | if (CurSYN == 0){ |
| | |
| | | return 0; |
| | | } |
| | | |
| | | uint8_t FPxCalBCC(uint8_t* pBuf, uint8_t len1) |
| | | uint8_t FPxBCC(uint8_t* pBuf, uint8_t len1) |
| | | { |
| | | uint8_t BCC=0; |
| | | for (int i=0;i<len1;i++) |
| | |
| | | if (!FPxStat.bConfiged || (FPxStat.bConfiged && nStationID == FPxStat.nConfigStationId)) |
| | | { |
| | | KMem.WDT[8]++; |
| | | |
| | | KMem.WDT[0]= nST; |
| | | KMem.WDT[1]= len1; |
| | | KMem.WDT[2] = FPxStat.nConfigStationId; |
| | | |
| | | KMem.WDT[4]= FPxStat.nInputBytes; |
| | | KMem.WDT[5]= FPxStat.nOutputBytes; |
| | | |
| | | pFPxQuRplyPkt p1 = (pFPxQuRplyPkt)PktBuf2; |
| | | p1->Hdr1=nST; |
| | | p1->nInputBytes=0x30|FPxStat.nInputBytes; |
| | | p1->nOutputBytes=0x30|FPxStat.nOutputBytes; |
| | | p1->nParam1=0x30|0x05; |
| | | p1->nBCC= 0x30|FPxCalBCC(PktBuf2,4); |
| | | p1->nBCC= 0x30|FPxBCC(PktBuf2,4); |
| | | p1->End1=0x0d; |
| | | |
| | | logData(0x11); |
| | | logData(0x22); |
| | | |
| | | FPxSendPkt(PktBuf2,sizeof(stFPxQuRplyPkt)); |
| | | FPxStat.nConfigStationId=nStationID; |
| | | FPxStat.bConfiged=1; |
| | | if (FPxStat.bFPxCallBackFuncSet) FPxStat.FPxCBFunc(evFPxStateChange,0,0); |
| | | if (FPxStat.FPxEvCBFunc) FPxStat.FPxEvCBFunc(evFPxStateChange,0,0); |
| | | } |
| | | bSPI1Recving=1; |
| | | break; |
| | |
| | | KMem.WYB[j]=(0xff); |
| | | } |
| | | // */ |
| | | if (FPxStat.bFPxCallBackFuncSet) FPxStat.FPxCBFunc(evFPxDataUpdate,0,0); |
| | | if (FPxStat.FPxEvCBFunc) FPxStat.FPxEvCBFunc(evFPxDataUpdate,0,0); |
| | | |
| | | // KMem.WDT[2]=((pBuf[1]&0xf)<<4) + ((pBuf[2]&0xf)<<0) + ((pBuf[3]&0xf)<<12) + ((pBuf[4]&0xf)<<8); |
| | | pFPxEXGRplyPkt p1 = (pFPxEXGRplyPkt)PktBuf2; |
| | |
| | | //p1->nInputBytes[3]=0x30|LoHofB(HiBofW(KMem.DT[0])); //((KMem.DT[0]>>8)&0x0f); |
| | | //p1->nInputBytes[4]=0x30|((KMem.DT[1]>>4)&0x0f); |
| | | //p1->nInputBytes[5]=0x30|((KMem.DT[1]>>0)&0x0f); |
| | | PktBuf2[FPxStat.nInputBytes*2 + 1 ]=0x30|FPxCalBCC(PktBuf2,FPxStat.nInputBytes*2+1); // p1->nBCC= 0x30|CalBCC(PktBuf2,7); |
| | | PktBuf2[FPxStat.nInputBytes*2 + 1 ]=0x30|FPxBCC(PktBuf2,FPxStat.nInputBytes*2+1); // p1->nBCC= 0x30|CalBCC(PktBuf2,7); |
| | | PktBuf2[FPxStat.nInputBytes*2 + 2 ]=0x0d; // p1->End1=0x0d; |
| | | FPxSendPkt(PktBuf2,FPxStat.nInputBytes*2 + 3); |
| | | } |
| | |
| | | #include "debug.h" |
| | | #include "Functions.h" |
| | | #include "KMachine.h" |
| | | #if (ENABLE_PLC) |
| | | #include "PLCfunctions.h" |
| | | #endif |
| | | //#include "KBus.h" |
| | | #include "KLink.h" |
| | | #include "string.h" |
| | | #include "BSP.h" |
| | | #include "ModbusRTU.h" |
| | | #if (BOARD_TYPE == 13) |
| | | #if (ENABLE_NET) |
| | | #include "w5500_port.h" |
| | | #include "../src/Ethernet/socket.h" |
| | | #include "../src/Ethernet/loopback.h" |
| | | #elif (BOARD_TYPE == 14) |
| | | #endif |
| | | |
| | | #if (ENABLE_FPX) |
| | | #include "FPx.h" |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | #endif |
| | | |
| | | #if (ENABLE_RF) |
| | | #include "KWireless.h" |
| | | #endif |
| | | //#include "user.h" |
| | | //#include "../src/radio/inc/sx126x-board.h" |
| | | #endif |
| | | |
| | | |
| | | /* USER CODE END Includes */ |
| | | |
| | |
| | | unsigned char FastFlicker=0; |
| | | |
| | | unsigned int Uart1IdelTimer = 0; |
| | | #if (ENABLE_PLC) |
| | | stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; |
| | | |
| | | #endif |
| | | uint32_t us1,us2,us3,us4,us5,us6; |
| | | |
| | | stKBusDef KBus1; |
| | | stKBusDef KBus1; // |
| | | |
| | | #define RAM_START_ADDR 0x20000000 |
| | | #define VECTOR_SIZE 45 |
| | |
| | | Uart2Stat.bPacketRecved=0; |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | } |
| | | if (Uart2Stat.bPacketRecved) |
| | | { |
| | | KBusPacketSendDone(&KBus1); |
| | | } |
| | | } |
| | | |
| | | /* |
| | |
| | | case evFPxDataUpdate: |
| | | for (int i=0;i<16;i++){ |
| | | KBusMem.WLY[i]=FPxMem.WLY[i]; |
| | | KMem.WLY[i]=FPxMem.WLY[i]; |
| | | KMem.WY[i]=FPxMem.WLY[i]; |
| | | } |
| | | for (int i=0;i<16;i++) { |
| | | FPxMem.WLX[i]=KBusMem.WLX[i]; |
| | |
| | | case KBusEvDataUpdate: |
| | | for (int i=0;i<16;i++){ |
| | | KBusMem.WLY[i]=FPxMem.WLY[i]; |
| | | KMem.WLY[i]=FPxMem.WLY[i]; |
| | | } |
| | | |
| | | for (int i=0;i<16;i++) { |
| | | KMem.WLX[i]=KBusMem.WLX[i]; |
| | | FPxMem.WLX[i]=KBusMem.WLX[i]; |
| | | KMem.WX[i]=KBusMem.WLX[i]; |
| | | } |
| | | |
| | | // KBusMem.WLY[0]=0x0301; |
| | | break; |
| | | |
| | | default: |
| | | break; |
| | | } |
| | | KMem.DT[2]++; |
| | | return 0; |
| | | } |
| | | |
| | |
| | | // RemapIrqVector(); |
| | | ///* |
| | | __set_PRIMASK(0); //æå¼å
¨å±ä¸æ |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | InitUartstat(&Uart1Stat,Uart1RxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf)); |
| | | InitUartstat(&Uart2Stat,Uart2RxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf)); |
| | |
| | | ReadSysCfgFromFlash(&storedKMSysCfg); |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | |
| | | KLinkInit(1); //注åKLinkç«¯å£ |
| | | |
| | | // stPortDef PortReg1 = {.nPortHardType = 3,.nPortUseType = 2}; |
| | | // KMRegisterPort(0,&PortReg1); |
| | | |
| | | |
| | | int bKBusMaster,bKBusSlave,bKBusRepeater;; |
| | | int nChilds; |
| | | int nKBusStationId; |
| | | int nKBusChilds; |
| | | KMem.CurJumperSW=ReadJumperSW(); |
| | | KMem.EffJumperSW=KMem.CurJumperSW; |
| | | nChilds=KMem.EffJumperSW&0x0f; |
| | | |
| | | nKBusStationId=KMem.EffJumperSW&0x0f; |
| | | |
| | | nKBusChilds = nKBusStationId; |
| | | // Uart2Baud = AlterUart2Baud; |
| | | |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc), |
| | | KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nChilds); |
| | | |
| | | KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds); |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc); |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | KMem.EffJumperSW|=0x10; |
| | | nChilds=KMem.EffJumperSW&0x0f; |
| | | if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | KMem.EffJumperSW|=0x40; |
| | | |
| | | if ((KMem.EffJumperSW&0x40)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | |
| | | FPxSetCallBackFunc(&FPxCallBackFunc); |
| | | FPx_Init(nChilds); |
| | | FPx_SetIOCount(8,5); |
| | | FPx_Init(nKBusChilds); |
| | | |
| | | int IOByteCount = nKBusChilds; |
| | | FPx_SetIOCount(IOByteCount,IOByteCount); |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | nStationID=1 ;//KMem.EffJumperSW&0x0f; |
| | |
| | | {bKBusMaster=0;bKBusSlave=1;} |
| | | #else |
| | | nStationID=KMem.EffJumperSW&0x0f; |
| | | if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | if (KMem.EffJumperSW == 0x3f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | else if ((KMem.EffJumperSW&0x20)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | #endif |
| | | |
| | | UNUSED(bKBusRepeater); |
| | | //if (KMem.EffJumperSW == 0x00) |
| | | Uart1Baud = DefaultUart1Baud; |
| | | MX_USART1_UART_Init(); |
| | |
| | | KMRunStat.WorkMode2=0; |
| | | |
| | | KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode == 1){ |
| | | InitPLC(); |
| | | KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ; |
| | | if (KMRunStat.WorkMode2) { |
| | | StartPLC(); } |
| | | } |
| | | |
| | | #endif |
| | | |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
| | | KWireLessStart(); |
| | |
| | | int haltick=HAL_GetTick(); |
| | | |
| | | int thisJumperSW=ReadJumperSW(); |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode&1){ |
| | | if (thisJumperSW&0x20 && !(KMem.CurJumperSW&0x20)) // Run å¼å
³ æ£ è·³åã |
| | | {StartPLC();} |
| | | if (!(thisJumperSW&0x20) && (KMem.CurJumperSW&0x20)) // Run å¼å
³ è´ è·³åã |
| | | {StopPLC();} |
| | | } |
| | | |
| | | #endif |
| | | KMem.CurJumperSW=thisJumperSW; |
| | | KMem.haltick=haltick; |
| | | // KMem.TotalRunTime=TotalRunTime; |
| | |
| | | #endif |
| | | |
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
| | | { |
| | | if (KMRunStat.nBinProgBank == 0){ |
| | |
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1); |
| | | } |
| | | |
| | | #endif |
| | | |
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime; |
| | | KMem.LastScanTime = us2; |
| | | if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;} |
| | |
| | | for (int i=0;i<FPxStat.nOutputBytes;i++) |
| | | {KBusMem.WLYB[i]=FPxMem.WLYB[i];} |
| | | #endif |
| | | if (nChilds>0) { KBusMasterFunc(&KBus1); } |
| | | KBusLoopProcess(&KBus1); |
| | | |
| | | } |
| | | if (haltick&0x00002000) SlowFlicker=1; |
| | |
| | | if (bKBusSlave) |
| | | { |
| | | |
| | | KBusSlaveFunc(&KBus1); |
| | | KBusLoopProcess(&KBus1); |
| | | if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | | if (KBus1.nSlaveTick&0x00000800) FastFlicker=1; |
| | | else FastFlicker=0; |
| | | } |
| | | |
| | | // KMem.WY[0]=nCount2>>5; |
| | | if (KMem.RunStat) {KMem.RunStat--;} |
| | | if (KMem.ErrStat) {KMem.ErrStat--;} |
| | | |
| | | if (KMRunStat.bLEDFlick) |
| | | { |
| | | SetRunLed(FastFlicker); |
| | |
| | | } |
| | | else |
| | | { |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode==1 ) { |
| | | if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
| | | else {SetRunLed(0);} |
| | | } |
| | | else { |
| | | else |
| | | #endif |
| | | { |
| | | if (!KBus1.RunStat) SetRunLed(SlowFlicker); |
| | | else SetRunLed(FastFlicker); |
| | | } |
| | | if (FPxStat.bConfiged) { |
| | | SetErrLed(0); |
| | | } |
| | | else { |
| | | SetErrLed(FastFlicker); |
| | | } |
| | | if (!KBus1.ErrStat) |
| | | { |
| | | SetErrLed(0); |
| | |
| | | } |
| | | // KMem.WY[0]=KMem.WLY[0]; |
| | | #elif (BOARD_TYPE == 14) |
| | | |
| | | for (int i=0;i<16;i++) { |
| | | KMem.WLX[i]=KBusMem.WLX[i]; |
| | | FPxMem.WLX[i]=KBusMem.WLX[i]; |
| | | KMem.WX[i]=KBusMem.WLX[i]; |
| | | } |
| | | #else |
| | | |
| | | KMem.WLX[0]=KMem.WX[0]; |
| | |
| | | // mapping bits. |
| | | for (int i=0;i<6;i++) |
| | | { |
| | | USHORT bitaddr = storedKMSysCfg.theKMSysCfg.OutMappings[i]; |
| | | USHORT bitaddr = storedKMSysCfg.theKMSysCfg.OutMappings[i].value; |
| | | UCHAR type = (bitaddr&0xf000) >>12; |
| | | USHORT byteaddr = (bitaddr&0x0ff0) >>4; |
| | | UCHAR bitpos = bitaddr &0x0f; |
| | | UCHAR bitvalue = 0 ; |
| | | if (byteaddr>0) { |
| | | if (type == 0) bitvalue = KMem.WXB[byteaddr-1] & ( 1 << bitpos ); |
| | | else if (type == 1 ) bitvalue = KMem.WYB[byteaddr-1] & ( 1 << bitpos ); |
| | | if (type == 0) {bitvalue = KMem.WXB[byteaddr-1] & ( 1 << bitpos );} |
| | | else if (type == 1 ) {bitvalue = KMem.WYB[byteaddr-1] & ( 1 << bitpos );} |
| | | //else if (type == 2 ) {bitvalue = KMem.WRB[byteaddr-1] & ( 1 << bitpos );} |
| | | else if (type == 3 ) {bitvalue = KMem.WLXB[byteaddr-1] & ( 1 << bitpos );} |
| | | else if (type == 4 ) {bitvalue = KMem.WLYB[byteaddr-1] & ( 1 << bitpos );} |
| | | // else if (type == 5 ) {bitvalue = KMem.WYB[byteaddr-1] & ( 1 << bitpos );} |
| | | } |
| | | if (bitvalue){ LL_GPIO_SetOutputPin(GPIOB,pins[i]);} |
| | | else {LL_GPIO_ResetOutputPin(GPIOB,pins[i]);} |
| | |
| | | |
| | | }; |
| | | |
| | | #define BOARD_TYPE 10 |
| | | #define BOARD_TYPE 8 |
| | | #define BOARD_VER 2 |
| | | |
| | | |
| | | #if (BOARD_TYPE == 11) |
| | | #define XLAT_FREQ 12 |
| | |
| | | #define DOUTPUT 0 |
| | | #endif |
| | | |
| | | typedef struct tagInfoBlockHdr { |
| | | unsigned short nBlkSign; // å¼å§æ å¿ |
| | | unsigned short nBlkTypeVer; // ç±»ååçæ¬ |
| | | unsigned short nBlkSize; // Block 大å°, å
æ¬å¼å§åç»ææ å¿ |
| | | unsigned short Pad1; |
| | | }stInfoBlockHdr; |
| | | |
| | | typedef struct tagInfoBlockTail { |
| | | |
| | | unsigned short CRC16; |
| | | unsigned short EndSign; |
| | | }stInfoBlockTail; |
| | | |
| | | typedef struct tagBtLdrInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nBtldrVer; |
| | | unsigned short nBtldrDevice; |
| | | unsigned short nBtldrSize; // è®¾è®¡å¤§å° |
| | | unsigned short nBtldrDataSize; //代ç å¤§å° |
| | | unsigned int nBtldr_AppAddr; |
| | | unsigned int nBtldr_NewAppInfoAddr; |
| | | unsigned int nBtldr_NewAppAddr; |
| | | stInfoBlockTail tail; |
| | | }stBtLdrInfoBlock, *pBtLdrInfoBlock; |
| | | |
| | | typedef struct tagAppInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nAppVer; |
| | | unsigned short nAppDevice; |
| | | unsigned short nAppSize; // 代ç è®¾è®¡å¤§å° |
| | | unsigned short nAppDataSize; //å®é
代ç å¤§å° |
| | | unsigned int nAppStartAddr; |
| | | unsigned int nAppStartOffset; |
| | | unsigned int nApp; |
| | | stInfoBlockTail tail; |
| | | }stAppInfoBlock, * pAppInfoBlock; |
| | | |
| | | |
| | | #endif /* __BOARDTYPE_H__ */ |
| | |
| | | /* #define USE_FULL_ASSERT 1U */ |
| | | |
| | | /* USER CODE BEGIN Private defines */ |
| | | #include "KBus.h" |
| | | |
| | | extern stKBusDef KBus1; |
| | | /* USER CODE END Private defines */ |
| | | |
| | | #ifdef __cplusplus |
File was renamed from MDK-ARM/F030C8T6_KBus.uvprojx |
| | |
| | | <NotGenerated>0</NotGenerated> |
| | | <InvalidFlash>1</InvalidFlash> |
| | | </TargetStatus> |
| | | <OutputDirectory>.\F030C8T6_KBus\</OutputDirectory> |
| | | <OutputDirectory>.\KBus_C8T6\</OutputDirectory> |
| | | <OutputName>F030C8T6_KBus</OutputName> |
| | | <CreateExecutable>1</CreateExecutable> |
| | | <CreateLib>0</CreateLib> |
| | |
| | | </OCR_RVCT3> |
| | | <OCR_RVCT4> |
| | | <Type>1</Type> |
| | | <StartAddress>0x8000000</StartAddress> |
| | | <Size>0x10000</Size> |
| | | <StartAddress>0x8001000</StartAddress> |
| | | <Size>0xf000</Size> |
| | | </OCR_RVCT4> |
| | | <OCR_RVCT5> |
| | | <Type>1</Type> |
| | |
| | | </OCR_RVCT8> |
| | | <OCR_RVCT9> |
| | | <Type>0</Type> |
| | | <StartAddress>0x20000000</StartAddress> |
| | | <Size>0x2000</Size> |
| | | <StartAddress>0x200000c0</StartAddress> |
| | | <Size>0x1f40</Size> |
| | | </OCR_RVCT9> |
| | | <OCR_RVCT10> |
| | | <Type>0</Type> |
| | |
| | | <MiscControls></MiscControls> |
| | | <Define>USE_FULL_LL_DRIVER,USE_HAL_DRIVER</Define> |
| | | <Undefine></Undefine> |
| | | <IncludePath>../KBus/Inc;../KBus/Src;../Drivers/STM32F0xx_HAL_Driver/Inc;../Drivers/CMSIS/Device/ST/STM32F0xx/Include;../Drivers/CMSIS/Include;../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy;..\ComLib\Inc</IncludePath> |
| | | <IncludePath>../Inc;../Src;../../Drivers/STM32F0xx_HAL_Driver/Inc;../../Drivers/CMSIS/Device/ST/STM32F0xx/Include;../../Drivers/CMSIS/Include;../../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy;..\..\ComLib\Inc</IncludePath> |
| | | </VariousControls> |
| | | </Cads> |
| | | <Aads> |
| | |
| | | <File> |
| | | <FileName>BSP.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\BSP.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\BSP.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>debug.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\debug.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\debug.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>functions.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\functions.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\functions.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>GlobalDef.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\GlobalDef.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\GlobalDef.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KBus.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\KBus.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\KBus.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KLink.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\KLink.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\KLink.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KMachine.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\KMachine.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\KMachine.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>ModbusRTU.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\ModbusRTU.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\ModbusRTU.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>MyQueue.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\MyQueue.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\MyQueue.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>PLCfunctions.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\PLCfunctions.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\PLCfunctions.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>shell.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\shell.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\shell.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32_assert.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\stm32_assert.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\stm32_assert.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_it.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\ComLib\Inc\stm32f0xx_it.h</FilePath> |
| | | <FilePath>..\..\ComLib\Inc\stm32f0xx_it.h</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <File> |
| | | <FileName>debug.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\debug.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\debug.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>functions.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\functions.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\functions.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>GlobalDef.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\GlobalDef.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\GlobalDef.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KBus.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\KBus.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\KBus.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KLink.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\KLink.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\KLink.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>ModbusRTU.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\ModbusRTU.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\ModbusRTU.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>MyQueue.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\MyQueue.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\MyQueue.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>PLCfunctions.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\PLCfunctions.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\PLCfunctions.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>shell.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\shell.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\shell.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_msp.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\stm32f0xx_hal_msp.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\stm32f0xx_hal_msp.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>KMachine.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\KMachine.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\KMachine.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>BSP.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\BSP.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\BSP.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_it.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\stm32f0xx_it.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\stm32f0xx_it.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <File> |
| | | <FileName>main.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\KBus\Inc\main.h</FilePath> |
| | | <FilePath>..\Inc\main.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_conf.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\KBus\Inc\stm32f0xx_hal_conf.h</FilePath> |
| | | <FilePath>..\Inc\stm32f0xx_hal_conf.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>BoardType.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\KBus\Inc\BoardType.h</FilePath> |
| | | <FilePath>..\Inc\BoardType.h</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <File> |
| | | <FileName>main.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\KBus\Src\main.c</FilePath> |
| | | <FilePath>..\Src\main.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>BoardType.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\KBus\Src\BoardType.c</FilePath> |
| | | <FilePath>..\Src\BoardType.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <File> |
| | | <FileName>system_stm32f0xx.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\ComLib\Src\system_stm32f0xx.c</FilePath> |
| | | <FilePath>..\..\ComLib\Src\system_stm32f0xx.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <File> |
| | | <FileName>stm32f0xx_ll_gpio.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_gpio.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_gpio.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_exti.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_exti.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_exti.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_adc.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_adc.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_adc.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_dma.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_dma.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_dma.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_spi.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_spi.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_spi.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_tim.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_tim_ex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_usart.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_usart.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_usart.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_rcc.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_rcc.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_rcc.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_rcc.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_rcc_ex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_i2c.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_i2c_ex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_gpio.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_dma.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_cortex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_pwr.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_pwr_ex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_flash.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_hal_flash_ex.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_utils.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_utils.c</FilePath> |
| | | <FilePath>../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_utils.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_tim.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_tim.c</FilePath> |
| | | <FilePath>..\..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_tim.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_flash.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_flash.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | | <Group> |
| | | <GroupName>::CMSIS</GroupName> |
| | | </Group> |
| | | </Groups> |
| | | </Target> |
| | |
| | | <component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.6.0" condition="ARMv6_7_8-M Device"> |
| | | <package name="CMSIS" schemaVersion="1.7.7" url="http://www.keil.com/pack/" vendor="ARM" version="5.9.0"/> |
| | | <targetInfos> |
| | | <targetInfo name="F030C8T6_KBus"/> |
| | | <targetInfo name="KBus_C8T6"/> |
| | | </targetInfos> |
| | | </component> |
| | | </components> |
New file |
| | |
| | | ;******************** (C) COPYRIGHT 2016 STMicroelectronics ******************** |
| | | ;* File Name : startup_stm32f030x8.s |
| | | ;* Author : MCD Application Team |
| | | ;* Description : STM32F030x8 devices vector table for MDK-ARM toolchain. |
| | | ;* This module performs: |
| | | ;* - Set the initial SP |
| | | ;* - Set the initial PC == Reset_Handler |
| | | ;* - Set the vector table entries with the exceptions ISR address |
| | | ;* - Branches to __main in the C library (which eventually |
| | | ;* calls main()). |
| | | ;* After Reset the CortexM0 processor is in Thread mode, |
| | | ;* priority is Privileged, and the Stack is set to Main. |
| | | ;* <<< Use Configuration Wizard in Context Menu >>> |
| | | ;******************************************************************************* |
| | | ;* |
| | | ;* Redistribution and use in source and binary forms, with or without modification, |
| | | ;* are permitted provided that the following conditions are met: |
| | | ;* 1. Redistributions of source code must retain the above copyright notice, |
| | | ;* this list of conditions and the following disclaimer. |
| | | ;* 2. Redistributions in binary form must reproduce the above copyright notice, |
| | | ;* this list of conditions and the following disclaimer in the documentation |
| | | ;* and/or other materials provided with the distribution. |
| | | ;* 3. Neither the name of STMicroelectronics nor the names of its contributors |
| | | ;* may be used to endorse or promote products derived from this software |
| | | ;* without specific prior written permission. |
| | | ;* |
| | | ;* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| | | ;* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| | | ;* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| | | ;* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| | | ;* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| | | ;* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| | | ;* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| | | ;* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| | | ;* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| | | ;* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| | | ; |
| | | ;******************************************************************************* |
| | | |
| | | ; Amount of memory (in bytes) allocated for Stack |
| | | ; Tailor this value to your application needs |
| | | ; <h> Stack Configuration |
| | | ; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> |
| | | ; </h> |
| | | |
| | | Stack_Size EQU 0x400 |
| | | |
| | | AREA STACK, NOINIT, READWRITE, ALIGN=3 |
| | | Stack_Mem SPACE Stack_Size |
| | | __initial_sp |
| | | |
| | | |
| | | ; <h> Heap Configuration |
| | | ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> |
| | | ; </h> |
| | | |
| | | Heap_Size EQU 0x200 |
| | | |
| | | AREA HEAP, NOINIT, READWRITE, ALIGN=3 |
| | | __heap_base |
| | | Heap_Mem SPACE Heap_Size |
| | | __heap_limit |
| | | |
| | | PRESERVE8 |
| | | THUMB |
| | | |
| | | |
| | | ; Vector Table Mapped to Address 0 at Reset |
| | | AREA RESET, DATA, READONLY |
| | | EXPORT __Vectors |
| | | EXPORT __Vectors_End |
| | | EXPORT __Vectors_Size |
| | | |
| | | __Vectors DCD __initial_sp ; Top of Stack |
| | | DCD Reset_Handler ; Reset Handler |
| | | DCD NMI_Handler ; NMI Handler |
| | | DCD HardFault_Handler ; Hard Fault Handler |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD SVC_Handler ; SVCall Handler |
| | | DCD 0 ; Reserved |
| | | DCD 0 ; Reserved |
| | | DCD PendSV_Handler ; PendSV Handler |
| | | DCD SysTick_Handler ; SysTick Handler |
| | | |
| | | ; External Interrupts |
| | | DCD WWDG_IRQHandler ; Window Watchdog |
| | | DCD 0 ; Reserved |
| | | DCD RTC_IRQHandler ; RTC through EXTI Line |
| | | DCD FLASH_IRQHandler ; FLASH |
| | | DCD RCC_IRQHandler ; RCC |
| | | DCD EXTI0_1_IRQHandler ; EXTI Line 0 and 1 |
| | | DCD EXTI2_3_IRQHandler ; EXTI Line 2 and 3 |
| | | DCD EXTI4_15_IRQHandler ; EXTI Line 4 to 15 |
| | | DCD 0 ; Reserved |
| | | DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1 |
| | | DCD DMA1_Channel2_3_IRQHandler ; DMA1 Channel 2 and Channel 3 |
| | | DCD DMA1_Channel4_5_IRQHandler ; DMA1 Channel 4 and Channel 5 |
| | | DCD ADC1_IRQHandler ; ADC1 |
| | | DCD TIM1_BRK_UP_TRG_COM_IRQHandler ; TIM1 Break, Update, Trigger and Commutation |
| | | DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare |
| | | DCD 0 ; Reserved |
| | | DCD TIM3_IRQHandler ; TIM3 |
| | | DCD TIM6_IRQHandler ; TIM6 |
| | | DCD 0 ; Reserved |
| | | DCD TIM14_IRQHandler ; TIM14 |
| | | DCD TIM15_IRQHandler ; TIM15 |
| | | DCD TIM16_IRQHandler ; TIM16 |
| | | DCD TIM17_IRQHandler ; TIM17 |
| | | DCD I2C1_IRQHandler ; I2C1 |
| | | DCD I2C2_IRQHandler ; I2C2 |
| | | DCD SPI1_IRQHandler ; SPI1 |
| | | DCD SPI2_IRQHandler ; SPI2 |
| | | DCD USART1_IRQHandler ; USART1 |
| | | DCD USART2_IRQHandler ; USART2 |
| | | |
| | | __Vectors_End |
| | | |
| | | __Vectors_Size EQU __Vectors_End - __Vectors |
| | | |
| | | AREA |.text|, CODE, READONLY |
| | | |
| | | ; Reset handler routine |
| | | Reset_Handler PROC |
| | | EXPORT Reset_Handler [WEAK] |
| | | IMPORT __main |
| | | IMPORT SystemInit |
| | | LDR R0, =SystemInit |
| | | BLX R0 |
| | | LDR R0, =__main |
| | | BX R0 |
| | | ENDP |
| | | |
| | | ; Dummy Exception Handlers (infinite loops which can be modified) |
| | | |
| | | NMI_Handler PROC |
| | | EXPORT NMI_Handler [WEAK] |
| | | B . |
| | | ENDP |
| | | HardFault_Handler\ |
| | | PROC |
| | | EXPORT HardFault_Handler [WEAK] |
| | | B . |
| | | ENDP |
| | | SVC_Handler PROC |
| | | EXPORT SVC_Handler [WEAK] |
| | | B . |
| | | ENDP |
| | | PendSV_Handler PROC |
| | | EXPORT PendSV_Handler [WEAK] |
| | | B . |
| | | ENDP |
| | | SysTick_Handler PROC |
| | | EXPORT SysTick_Handler [WEAK] |
| | | B . |
| | | ENDP |
| | | |
| | | Default_Handler PROC |
| | | |
| | | EXPORT WWDG_IRQHandler [WEAK] |
| | | EXPORT RTC_IRQHandler [WEAK] |
| | | EXPORT FLASH_IRQHandler [WEAK] |
| | | EXPORT RCC_IRQHandler [WEAK] |
| | | EXPORT EXTI0_1_IRQHandler [WEAK] |
| | | EXPORT EXTI2_3_IRQHandler [WEAK] |
| | | EXPORT EXTI4_15_IRQHandler [WEAK] |
| | | EXPORT DMA1_Channel1_IRQHandler [WEAK] |
| | | EXPORT DMA1_Channel2_3_IRQHandler [WEAK] |
| | | EXPORT DMA1_Channel4_5_IRQHandler [WEAK] |
| | | EXPORT ADC1_IRQHandler [WEAK] |
| | | EXPORT TIM1_BRK_UP_TRG_COM_IRQHandler [WEAK] |
| | | EXPORT TIM1_CC_IRQHandler [WEAK] |
| | | EXPORT TIM3_IRQHandler [WEAK] |
| | | EXPORT TIM6_IRQHandler [WEAK] |
| | | EXPORT TIM14_IRQHandler [WEAK] |
| | | EXPORT TIM15_IRQHandler [WEAK] |
| | | EXPORT TIM16_IRQHandler [WEAK] |
| | | EXPORT TIM17_IRQHandler [WEAK] |
| | | EXPORT I2C1_IRQHandler [WEAK] |
| | | EXPORT I2C2_IRQHandler [WEAK] |
| | | EXPORT SPI1_IRQHandler [WEAK] |
| | | EXPORT SPI2_IRQHandler [WEAK] |
| | | EXPORT USART1_IRQHandler [WEAK] |
| | | EXPORT USART2_IRQHandler [WEAK] |
| | | |
| | | |
| | | WWDG_IRQHandler |
| | | RTC_IRQHandler |
| | | FLASH_IRQHandler |
| | | RCC_IRQHandler |
| | | EXTI0_1_IRQHandler |
| | | EXTI2_3_IRQHandler |
| | | EXTI4_15_IRQHandler |
| | | DMA1_Channel1_IRQHandler |
| | | DMA1_Channel2_3_IRQHandler |
| | | DMA1_Channel4_5_IRQHandler |
| | | ADC1_IRQHandler |
| | | TIM1_BRK_UP_TRG_COM_IRQHandler |
| | | TIM1_CC_IRQHandler |
| | | TIM3_IRQHandler |
| | | TIM6_IRQHandler |
| | | TIM14_IRQHandler |
| | | TIM15_IRQHandler |
| | | TIM16_IRQHandler |
| | | TIM17_IRQHandler |
| | | I2C1_IRQHandler |
| | | I2C2_IRQHandler |
| | | SPI1_IRQHandler |
| | | SPI2_IRQHandler |
| | | USART1_IRQHandler |
| | | USART2_IRQHandler |
| | | |
| | | B . |
| | | |
| | | ENDP |
| | | |
| | | ALIGN |
| | | |
| | | ;******************************************************************************* |
| | | ; User Stack and Heap initialization |
| | | ;******************************************************************************* |
| | | IF :DEF:__MICROLIB |
| | | |
| | | EXPORT __initial_sp |
| | | EXPORT __heap_base |
| | | EXPORT __heap_limit |
| | | |
| | | ELSE |
| | | |
| | | IMPORT __use_two_region_memory |
| | | EXPORT __user_initial_stackheap |
| | | |
| | | __user_initial_stackheap |
| | | |
| | | LDR R0, = Heap_Mem |
| | | LDR R1, =(Stack_Mem + Stack_Size) |
| | | LDR R2, = (Heap_Mem + Heap_Size) |
| | | LDR R3, = Stack_Mem |
| | | BX LR |
| | | |
| | | ALIGN |
| | | |
| | | ENDIF |
| | | |
| | | END |
| | | |
| | | ;************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE***** |
| | |
| | | #include "BoardType.h" |
| | | #include "KMachine.h" |
| | | #include "KBus.h" |
| | | |
| | | |
| | | #define APP_ADDR 0x08001000 //åºç¨ç¨åºé¦å°åå®ä¹ |
| | | #define APPINFOBLOCK_ADDR (APP_ADDR + 0x100) //ç¨åºä¿¡æ¯å å°å |
| | | #define INFOBLOCK_ADDR (APP_ADDR + 0x1000) //ä¿¡æ¯å å°å |
| | | |
| | | #define APP_START_ADDR IROM1_START_ADDRESS |
| | | extern int Region$$Table$$Limit; |
| | | |
| | | #define MAKE_VER(x,y) ((x<<8)|y) |
| | | |
| | | #define APP_VER MAKE_VER(1,13) |
| | | |
| | | |
| | | const stAppInfoBlock AppInfoBlock __attribute__((at(APPINFOBLOCK_ADDR))) = |
| | | { |
| | | 0xAA55, // StartSign |
| | | 0x0301, // BlockType |
| | | sizeof(stAppInfoBlock), //BlockSize |
| | | 0, // Pad, |
| | | APP_VER, //AppVer |
| | | (BOARD_TYPE<<8) + BOARD_VER, //AppDevice; |
| | | 0x1000, //AppSize; |
| | | 0x0C00, //AppDataSize; |
| | | APP_ADDR, //nAppStartAddr |
| | | (int)&Region$$Table$$Limit, //nBtldr_NewAppInfoAddr |
| | | 0x08009000, //nBtldr_NewAppAddr |
| | | 0xCCCC, //crc16; |
| | | 0xAA55 //EndSign; |
| | | |
| | | }; |
| | | |
| | | |
| | | |
| | | |
| | | const stKMInfoBlock KMInfoBlock __attribute__((at(INFOBLOCK_ADDR))) = |
| | | { |
| | | // sizeof(stKMInfoBlock), |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceType BOARD_VER, //nDevieVer |
| | | APP_VER, //ProgVer |
| | | 0x0102, //KLinkVer |
| | | KBUS_VER, //KBusVer |
| | | // 0x0100, //KNetVer |
| | | // 0x0100, //KWLVer |
| | | |
| | | 4, //nCapacity1 ?K |
| | | 1, //nCapacity2 ?k |
| | | |
| | | DINPUT, //nDInput; |
| | | DOUTPUT, //nDOutput |
| | | |
| | | 0, //nAInput |
| | | 0, //nAOutput |
| | | 0, //nHInput |
| | | 0, //nHOutput |
| | | 0, //nExt1; |
| | | 0, //nExt2; |
| | | 0, //nLogSize; |
| | | 2, //nPorts; |
| | | 0, //nManSize; |
| | | 0, //nAbility; |
| | | 6, //nSwitchBits; |
| | | }; |
| | | |
| | | |
| | | const stDeviceInfo MyDeviceInfo={ |
| | | |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | APP_VER, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | 0, // unsigned char ExInBitCount; // æ©å±çè¾å
¥å¼å
³éæ°é |
| | | 0, // unsigned char ExOutBitCount; // æ©å±çè¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | }; |
| | | |
| | | const stExDeviceInfo MyExDeviceInfo ={ |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | APP_VER, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | 0, // unsigned char ExInBitCount; // æ©å±çè¾å
¥å¼å
³éæ°é |
| | | 0, // unsigned char ExOutBitCount; // æ©å±çè¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | |
| | | }; |
| | | |
| | |
| | | #include "debug.h" |
| | | #include "Functions.h" |
| | | #include "KMachine.h" |
| | | #if (ENABLE_PLC) |
| | | #include "PLCfunctions.h" |
| | | #endif |
| | | //#include "KBus.h" |
| | | #include "KLink.h" |
| | | #include "string.h" |
| | | #include "BSP.h" |
| | | #include "ModbusRTU.h" |
| | | #if (BOARD_TYPE == 13) |
| | | #if (ENABLE_NET) |
| | | #include "w5500_port.h" |
| | | #include "../src/Ethernet/socket.h" |
| | | #include "../src/Ethernet/loopback.h" |
| | | #elif (BOARD_TYPE == 14) |
| | | #include "FP0.h" |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | #endif |
| | | |
| | | #if (ENABLE_FPX) |
| | | #include "FPx.h" |
| | | #endif |
| | | |
| | | #if (ENABLE_RF) |
| | | #include "KWireless.h" |
| | | #endif |
| | | //#include "user.h" |
| | | //#include "../src/radio/inc/sx126x-board.h" |
| | | #endif |
| | | |
| | | |
| | | /* USER CODE END Includes */ |
| | | |
| | |
| | | unsigned char FastFlicker=0; |
| | | |
| | | unsigned int Uart1IdelTimer = 0; |
| | | #if (ENABLE_PLC) |
| | | stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; |
| | | |
| | | #endif |
| | | uint32_t us1,us2,us3,us4,us5,us6; |
| | | |
| | | |
| | | stKBusDef KBus1; // |
| | | |
| | | /* USER CODE END PV */ |
| | | |
| | |
| | | static int Count=0; |
| | | CurTickuS += 100; |
| | | nCurTick++; |
| | | nSlaveTick++; |
| | | KBus1.nSlaveTick++; |
| | | Count++; |
| | | if (Count>=10000) |
| | | if (Count>=10000) // 0.1mS, 10000次, ç§èå² |
| | | { |
| | | Count=0; |
| | | KMem.CurTimeSec++; |
| | |
| | | return; |
| | | } |
| | | |
| | | void * KBusCallBackFunc(int nChn, int nEvent, void *pBuf, int nLen1) |
| | | void PendSvCallBack() |
| | | { |
| | | #if (ENABLE_FPX) |
| | | ///* |
| | | if (bSPI1RecvDone) |
| | | { |
| | | bSPI1RecvDone=0; |
| | | FPxParsePkt(SPI1RecvBuf,nSPI1RecvLenInBuf); |
| | | } |
| | | //*/ |
| | | #endif |
| | | if (Uart2Stat.bPacketRecved) |
| | | { |
| | | KBusParsePacket(&KBus1, (pKBPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); |
| | | Uart2RecvBuf1DataLen=0; |
| | | Uart2Stat.bPacketRecved=0; |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | KMem.WDT[2]++; |
| | | } |
| | | } |
| | | |
| | | /* |
| | | KBusé讯åè°å½æ°ï¼å½é讯ç¶ææ¹åææ°æ®æ´æ°æ¶è¢«è°ç¨ã |
| | | æè
ç³»ç»è¯·æ±æ¶ã |
| | | */ |
| | | void * KBusEvCallBackFunc(void* pParam, int nEvent, void *pBuf, int nLen1) |
| | | { |
| | | switch (nEvent){ |
| | | |
| | |
| | | case KBusEvTimeSync: |
| | | break; |
| | | case KBusEvDataUpdate: |
| | | KMem.WDT[10]++; |
| | | if (KBus1.bMaster) { |
| | | KMem.WY[0]=KBusMem.WLX[0]; //KBus Master |
| | | KBusMem.WLY[0]=KMem.WX[0]; |
| | |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | extern stDeviceInfo MyDeviceInfo; |
| | | |
| | | /* USER CODE END 0 */ |
| | | |
| | |
| | | |
| | | /* USER CODE BEGIN Init */ |
| | | |
| | | for (int i=0;i<9;i++) |
| | | { |
| | | // memset(KBusChnStats[i],0,0); |
| | | KBusChnStats[i].SendPackets=0; |
| | | KBusChnStats[i].RecvPackets=0; |
| | | KBusChnStats[i].LostPackets=0; |
| | | KBusChnStats[i].CtnLstPkts=0; |
| | | KBusChnStats[i].MaxCtnLstPkts=0; |
| | | KBusChnStats[i].NotPkgErr=0; |
| | | KBusChnStats[i].PkgLenErr=0; |
| | | KBusChnStats[i].TimeOutErr=0; |
| | | KBusChnStats[i].BCCErr=0; |
| | | KBusChnStats[i].Delay=0; |
| | | KBusChnStats[i].MaxDelay=0; |
| | | } |
| | | |
| | | KMem.LastScanTime=0; |
| | | KMem.ScanTimeuS=0; |
| | | KMem.MinScanTimeuS=99999; |
| | |
| | | ReadSysCfgFromFlash(&storedKMSysCfg); |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | |
| | | int bKBusMaster,bKBusSlave,bKBusRepeater;; |
| | | int nChilds; |
| | | int nKBusStationID; |
| | | KMem.CurJumperSW=ReadJumperSW(); |
| | | KMem.EffJumperSW=KMem.CurJumperSW; |
| | | |
| | | // Uart2Baud = AlterUart2Baud; nChilds=KMem.EffJumperSW&0x0f; |
| | | // Uart2Baud = AlterUart2Baud; |
| | | |
| | | nKBusStationID = KMem.EffJumperSW&0x0f; |
| | | nChilds=nKBusStationID; |
| | | |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | KMem.EffJumperSW|=0x10; |
| | | nStationID=KMem.EffJumperSW&0x0f; |
| | | if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | nChilds=nStationID; |
| | | FP0_Init(); |
| | | FPxSetCallBackFunc(&FPxCallBackFunc); |
| | | FPx_Init(nChilds); |
| | | |
| | | int IOByteCount = nChilds; |
| | | FPx_SetIOCount(IOByteCount,IOByteCount); |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | nStationID=1 ;//KMem.EffJumperSW&0x0f; |
| | | // if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | |
| | | // else |
| | | {bKBusMaster=0;bKBusSlave=1;} |
| | | #else |
| | | nStationID=KMem.EffJumperSW&0x0f; |
| | | nKBusStationID=nChilds; |
| | | if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | #endif |
| | | nChilds=nStationID; |
| | | nCurPollId=1; |
| | | else if ((KMem.EffJumperSW&0x10)!=0) { |
| | | bKBusMaster=1;bKBusSlave=0; |
| | | } |
| | | else{ |
| | | bKBusMaster=0;bKBusSlave=1; |
| | | } |
| | | |
| | | KBusInit(2, bKBusMaster, nChilds); |
| | | KBusSetCallBackFunc(2, &KBusCallBackFunc), |
| | | #endif |
| | | UNUSED(bKBusRepeater); |
| | | |
| | | if (bKBusMaster) { |
| | | KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nChilds); |
| | | |
| | | } else if (bKBusSlave) { |
| | | KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationID,&MyDeviceInfo); |
| | | } |
| | | |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc); |
| | | |
| | | KMem.WDT[0]= nKBusStationID; |
| | | KMem.WDT[1] = KBus1.nStationId; |
| | | |
| | | //if (KMem.EffJumperSW == 0x00) |
| | | Uart1Baud = DefaultUart1Baud; |
| | |
| | | KMRunStat.WorkMode2=0; |
| | | |
| | | KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode == 1){ |
| | | InitPLC(); |
| | | KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ; |
| | | if (KMRunStat.WorkMode2) { |
| | | StartPLC(); } |
| | | } |
| | | #endif |
| | | KMem.WX[7]=0x5a; |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
| | | KWireLessStart(); |
| | | #endif |
| | | |
| | | KMem.WY[0]=0; |
| | | while (1) |
| | | { |
| | | //int MyKeyStat1,MyKeyStat2; |
| | |
| | | int haltick=HAL_GetTick(); |
| | | |
| | | int thisJumperSW=ReadJumperSW(); |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode&1){ |
| | | if (thisJumperSW&0x20 && !(KMem.CurJumperSW&0x20)) // Run å¼å
³ æ£ è·³åã |
| | | {StartPLC();} |
| | | if (!(thisJumperSW&0x20) && (KMem.CurJumperSW&0x20)) // Run å¼å
³ è´ è·³åã |
| | | {StopPLC();} |
| | | } |
| | | |
| | | #endif |
| | | KMem.CurJumperSW=thisJumperSW; |
| | | KMem.haltick=haltick; |
| | | // KMem.TotalRunTime=TotalRunTime; |
| | |
| | | #else |
| | | KMem.WX[0]= GetInput(); |
| | | #endif |
| | | |
| | | if (GetBoardType() == 7 || GetBoardType() ==8 |
| | | || GetBoardType() == 9 || GetBoardType() ==10 || GetBoardType() ==15 || GetBoardType() ==16) |
| | | { |
| | |
| | | #endif |
| | | |
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
| | | { |
| | | if (KMRunStat.nBinProgBank == 0){ |
| | |
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1); |
| | | } |
| | | |
| | | #endif |
| | | |
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime; |
| | | KMem.LastScanTime = us2; |
| | | if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;} |
| | |
| | | #if (BOARD_TYPE == 14) |
| | | for (int i=0;i<nOutputBytes;i++) |
| | | {BufferOut[i+1]=KMem.WYB[i];} |
| | | #else |
| | | // BufferOut[1]=KMem.WX[0]&0xff; |
| | | // BufferOut[2]=(KMem.WX[0]>>8)&0xff; |
| | | #endif |
| | | KBusMem.WLY[0]=KMem.WX[0]; |
| | | if (nChilds>0) { KBusMasterFunc(2); } |
| | | KBusLoopProcess(&KBus1); |
| | | KMem.WY[0]=KBusMem.WLX[0]; //KBus Slave |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | // KMem.WX[0]=BufferIn[1]+(BufferIn[2]<<8); |
| | | #else |
| | | // KMem.WY[0]=BufferIn[1]+(BufferIn[2]<<8); |
| | | #endif |
| | | |
| | | } |
| | | if (haltick&0x00002000) SlowFlicker=1; |
| | |
| | | // if (! KMem.RunStat) {BufferIn[0]=0;} |
| | | // KMem.WY[0]=BufferIn[0]; |
| | | #else |
| | | KBusSlaveFunc(2); |
| | | // KBusSlaveFunc(&KBus1); |
| | | KBusLoopProcess(&KBus1); |
| | | // if (! KMem.RunStat) {BufferIn[0]=0;} |
| | | // KMem.WLY[0]=BufferIn[0]; |
| | | KMem.WDT[2] = KBus1.KBusChnStats[0].ClientRecvPkts; |
| | | |
| | | KMem.WDT[3] = KBus1.KBusChnStats[0].ClientSendPkts; |
| | | |
| | | |
| | | KMem.WDT[8] = KBus1.RunStat; |
| | | KMem.WDT[9] = KBus1.ErrStat; |
| | | |
| | | KMem.WDD[20] = KBus1.RecvTimeTick; |
| | | |
| | | #endif |
| | | if (nSlaveTick&0x00002000) SlowFlicker=1; |
| | | if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | | if (nSlaveTick&0x00000800) FastFlicker=1; |
| | | if (KBus1.nSlaveTick&0x00000800) FastFlicker=1; |
| | | else FastFlicker=0; |
| | | KBusMem.WLX[0]=KMem.WX[0]; |
| | | KMem.WY[0]=KBusMem.WLY[0]; |
| | | // KBusMem.WLX[0]=KMem.WX[0]; |
| | | // KMem.WY[0]=KBusMem.WLY[0]; |
| | | } |
| | | |
| | | // KMem.WY[0]=nCount2>>5; |
| | | if (KMem.RunStat) {KMem.RunStat--;} |
| | | if (KMem.ErrStat) {KMem.ErrStat--;} |
| | | |
| | | if (KMRunStat.bLEDFlick) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | KMem.ErrStat = KBus1.ErrStat; // + KwRunStat.ErrStat; |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode==1 ) { |
| | | if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
| | | else {SetRunLed(0);} |
| | | } |
| | | else { |
| | | else |
| | | #endif |
| | | { |
| | | if (!KMem.RunStat) SetRunLed(SlowFlicker); |
| | | else SetRunLed(FastFlicker); |
| | | } |
| | |
| | | SetErrLed(FastFlicker); |
| | | SetErr2Led(FastFlicker); |
| | | SetOutStat(0); |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | #endif |
| | | |
| | | us5=GetuS(); |
| | | us5=GetTick(); |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | // PutOutput (KMem.WY[0]); |
| | |
| | | void MX_DMA_Init(void); |
| | | void MX_USART1_UART_Init(void); |
| | | void MX_USART2_UART_Init(void); |
| | | void MX_USART3_UART_Init(void); |
| | | void MX_USART5_UART_Init(void); |
| | | void MX_USART6_UART_Init(void); |
| | | |
| | |
| | | #define DOUTPUT 0 |
| | | #endif |
| | | |
| | | typedef struct tagInfoBlockHdr { |
| | | unsigned short nBlkSign; // å¼å§æ å¿ |
| | | unsigned short nBlkTypeVer; // ç±»ååçæ¬ |
| | | unsigned short nBlkSize; // Block 大å°, å
æ¬å¼å§åç»ææ å¿ |
| | | unsigned short Pad1; |
| | | }stInfoBlockHdr; |
| | | |
| | | typedef struct tagInfoBlockTail { |
| | | |
| | | unsigned short CRC16; |
| | | unsigned short EndSign; |
| | | }stInfoBlockTail; |
| | | |
| | | typedef struct tagBtLdrInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nBtldrVer; |
| | | unsigned short nBtldrDevice; |
| | | unsigned short nBtldrSize; // è®¾è®¡å¤§å° |
| | | unsigned short nBtldrDataSize; //代ç å¤§å° |
| | | unsigned int nBtldr_AppAddr; |
| | | unsigned int nBtldr_NewAppInfoAddr; |
| | | unsigned int nBtldr_NewAppAddr; |
| | | stInfoBlockTail tail; |
| | | }stBtLdrInfoBlock, *pBtLdrInfoBlock; |
| | | |
| | | typedef struct tagAppInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nAppVer; |
| | | unsigned short nAppDevice; |
| | | unsigned short nAppSize; // 代ç è®¾è®¡å¤§å° |
| | | unsigned short nAppDataSize; //å®é
代ç å¤§å° |
| | | unsigned int nAppStartAddr; |
| | | unsigned int nAppStartOffset; |
| | | unsigned int nApp; |
| | | stInfoBlockTail tail; |
| | | }stAppInfoBlock, * pAppInfoBlock; |
| | | |
| | | |
| | | #endif /* __BOARDTYPE_H__ */ |
New file |
| | |
| | | /** |
| | | ****************************************************************************** |
| | | * @file : FP0.h |
| | | * @brief : Header for FP0.c file. |
| | | * This file contains the function defines of the FP0 . |
| | | ****************************************************************************** |
| | | */ |
| | | #ifndef __FP0_H__ |
| | | #define __FP0_H__ |
| | | #include "main.h" |
| | | |
| | | enum enCMD_TYPE |
| | | { |
| | | CMD_0_QUERY =0, |
| | | CMD_1=0x1, // |
| | | CMD_2=0x2, // |
| | | CMD_3_EXCHG=0x3, // |
| | | CMD_4=0x4, // |
| | | CMD_5=0x5, // |
| | | CMD_6=0x6, // |
| | | CMD_7_END=0x7, // |
| | | }; |
| | | |
| | | typedef struct tagFP0PinStat |
| | | { |
| | | unsigned short OE:1; |
| | | unsigned short RST:1; |
| | | unsigned short SYN:1; |
| | | unsigned short ACK:1; |
| | | unsigned short SEL:1; |
| | | |
| | | }stFP0PinStat; |
| | | |
| | | |
| | | #define RST_PORT GPIOB |
| | | #define RST_PIN LL_GPIO_PIN_9 |
| | | |
| | | #define SYN_PORT GPIOF |
| | | #define SYN_PIN LL_GPIO_PIN_6 |
| | | |
| | | #define ACK_PORT GPIOA |
| | | #define ACK_PIN LL_GPIO_PIN_11 |
| | | |
| | | |
| | | #define FP0DE_PORT GPIOF |
| | | #define FP0DE_PIN LL_GPIO_PIN_7 |
| | | |
| | | #define OE_PORT GPIOB |
| | | #define OE_PIN LL_GPIO_PIN_6 |
| | | |
| | | #define SEL_PORT GPIOB |
| | | #define SEL_PIN LL_GPIO_PIN_8 |
| | | |
| | | |
| | | #define GetRSTPin() LL_GPIO_IsInputPinSet(RST_PORT,RST_PIN) |
| | | |
| | | #define GetSYNPin() LL_GPIO_IsInputPinSet(SYN_PORT,SYN_PIN) |
| | | |
| | | #define GetOEPin() LL_GPIO_IsInputPinSet(OE_PORT,OE_PIN) |
| | | |
| | | #define GetSELPin() (1) //LL_GPIO_IsInputPinSet(SEL_PORT,SEL_PIN) |
| | | |
| | | #define GetACKPin() LL_GPIO_IsInputPinSet(ACK_PORT,ACK_PIN) |
| | | |
| | | |
| | | #define SetACKPin_0() LL_GPIO_ResetOutputPin(ACK_PORT,ACK_PIN) |
| | | #define SetACKPin_1() LL_GPIO_SetOutputPin(ACK_PORT,ACK_PIN) |
| | | |
| | | #define SetFP0DEPin_0() LL_GPIO_ResetOutputPin(FP0DE_PORT,FP0DE_PIN) |
| | | #define SetFP0DEPin_1() LL_GPIO_SetOutputPin(FP0DE_PORT,FP0DE_PIN) |
| | | |
| | | |
| | | extern uint8_t PkgBuf1[32]; |
| | | extern uint8_t PkgBuf2[32]; |
| | | extern uint8_t PkgLen1; |
| | | extern uint8_t PkgLen2; |
| | | extern uint8_t bReceiving; |
| | | extern uint8_t nReceivedLen; |
| | | extern uint8_t bSending; |
| | | extern uint8_t bSentLen; |
| | | |
| | | extern uint8_t bConfiged; |
| | | |
| | | extern uint8_t nInputBytes; |
| | | extern uint8_t nOutputBytes; |
| | | |
| | | extern unsigned char SPI1RecvBuf[32]; |
| | | extern unsigned char SPI1SendBuf[32]; |
| | | |
| | | extern volatile unsigned char bSPI1Recving; |
| | | extern volatile unsigned char bSPI1RecvDone; |
| | | |
| | | extern volatile unsigned char nSPI1RecvPos; |
| | | extern volatile unsigned char nSPI1RecvLenInBuf; |
| | | |
| | | extern volatile unsigned char nSPI1ToSendLen; |
| | | extern volatile unsigned char nSPI1SentLen; |
| | | |
| | | extern volatile unsigned char bSPI1Sending; |
| | | extern volatile unsigned char bSPI1SendDone; |
| | | |
| | | extern volatile int oldSYN; |
| | | |
| | | typedef struct tagFP0QuRplyPkg |
| | | { |
| | | uint8_t Hdr1; |
| | | uint8_t nInputBytes; |
| | | uint8_t nOutputBytes; |
| | | uint8_t nParam1; |
| | | uint8_t nBCC; |
| | | uint8_t End1; |
| | | }stFP0QuRplyPkg, *pFP0QuRplyPkg; |
| | | |
| | | typedef struct tagFP0EXGRplyPkg |
| | | { |
| | | uint8_t Hdr1; |
| | | uint8_t nInputBytes[6]; |
| | | uint8_t nBCC; |
| | | uint8_t End1; |
| | | }stFP0EXGRplyPkg, * pFP0EXGRplyPkg; |
| | | |
| | | uint8_t FP0_Init(void); |
| | | uint8_t FP0_Proc(void); |
| | | |
| | | uint8_t CalFP0BCC(uint8_t* pBuf, uint8_t len1); |
| | | uint8_t CheckFP0Pkg(uint8_t * pBuf, uint8_t len1); |
| | | uint8_t ParseFP0Pkg(uint8_t * pBuf, uint8_t len1); |
| | | uint8_t SendFP0Pkg(uint8_t * pBuf, uint8_t len1); |
| | | |
| | | #endif /* __FP0_H__ */ |
New file |
| | |
| | | /** |
| | | ****************************************************************************** |
| | | * @file : OrdLidar.h |
| | | * @brief : Header for OrdLidar.c file. |
| | | * This file contains the Lidar defines of the application. |
| | | ****************************************************************************** |
| | | */ |
| | | |
| | | #ifndef __ORDLIDAR_H__ |
| | | #define __ORDLIDAR_H__ |
| | | |
| | | #define ORDLIDAR_VER (0x100) |
| | | #pragma anon_unions |
| | | |
| | | #include <stdint.h> |
| | | #include <stdlib.h> |
| | | |
| | | #define TMPBUFF_SIZE (1024) |
| | | #define MAX_BLOCK_POINT_NUM (100) |
| | | #define MAX_BLOCK_SIZE (MAX_BLOCK_POINT_NUM * 4) |
| | | #define POINT_CIRCLE_MAX_SIZE (4096) |
| | | #define POINT_PKG_MAX_SIZE (200) |
| | | #define POINT_PER_PACK (12) |
| | | |
| | | #define SET_TIME_OUT (10) //unit:s |
| | | #define HEAD_FLAG (0xF5A5) |
| | | #define TAIL_FLAG (0x31F2) |
| | | #define HEAD_LEN (5) |
| | | |
| | | typedef enum |
| | | { |
| | | ORADAR_MS200 = 1, |
| | | ORADAR_MS300 = 2, |
| | | }oradar_lidar_type_id; |
| | | |
| | | typedef enum { |
| | | ORADAR_TYPE_SERIAL = 0x0,/**< serial type.*/ |
| | | ORADAR_TYPC_UDP = 0x1,/**< socket udp type.*/ |
| | | ORADAR_TYPE_TCP = 0x1,/**< socket tcp type.*/ |
| | | } device_type_id; |
| | | |
| | | typedef enum |
| | | { |
| | | SET_ROTATION_SPEED = 0xA1, |
| | | SET_RUN_MODE = 0xA2, |
| | | }CMD; |
| | | |
| | | typedef enum |
| | | { |
| | | WRITE_PARAM = 0xC1, |
| | | WRITE_PARAM_RESPONSE = 0xC2, |
| | | READ_PARAM = 0xC3, |
| | | READ_PARAM_RESPONSE = 0xC4, |
| | | }CMD_TYPE; |
| | | |
| | | typedef struct uart_comm_st |
| | | { |
| | | uint16_t head_flag; |
| | | uint8_t cmd; |
| | | uint8_t cmd_type; |
| | | uint8_t payload_len; |
| | | uint8_t data[10]; |
| | | }uart_comm_t; |
| | | |
| | | typedef struct point_data_st |
| | | { |
| | | unsigned short distance; |
| | | unsigned short intensity; |
| | | float angle; |
| | | } point_data_t; |
| | | |
| | | typedef enum frame_head_flag_et |
| | | { |
| | | HEAD_FLAG_NONE, |
| | | HEAD_FLAG_OK, |
| | | } frame_head_flag_t; |
| | | |
| | | typedef enum protocol_version_et |
| | | { |
| | | VERSION_NONE = 0, |
| | | VERSION_MS200, |
| | | } protocol_version_t; |
| | | |
| | | typedef struct __attribute__((packed)) |
| | | { |
| | | uint16_t distance; |
| | | uint8_t confidence; |
| | | } OradarLidarPoint; |
| | | |
| | | typedef struct __attribute__((packed)) |
| | | { |
| | | uint8_t header; |
| | | uint8_t ver_len; |
| | | uint16_t speed; |
| | | uint16_t start_angle; |
| | | OradarLidarPoint point[POINT_PER_PACK]; |
| | | uint16_t end_angle; |
| | | uint16_t timestamp; |
| | | uint8_t crc8; |
| | | } OradarLidarFrame; |
| | | |
| | | |
| | | |
| | | typedef struct LidarDotData |
| | | { |
| | | unsigned char intensity; |
| | | unsigned char s1; |
| | | /* |
| | | struct { |
| | | unsigned char flag:2; |
| | | unsigned char s1:6; |
| | | }; |
| | | */ |
| | | unsigned char s2; |
| | | }stLidarDotData; |
| | | |
| | | typedef struct tagLidarDotsPkt |
| | | { |
| | | unsigned short StSign; |
| | | unsigned char CT; |
| | | unsigned char LSN; |
| | | unsigned short FSA; |
| | | unsigned short LSA; |
| | | unsigned short CS; |
| | | stLidarDotData LidarDotDatas[40]; |
| | | |
| | | }stLidarDotsPkt, *pLidarDotsPkt; |
| | | |
| | | |
| | | typedef struct tagLidarVector |
| | | { |
| | | int intensit; |
| | | int angle; |
| | | int value; |
| | | }stLidarVector; |
| | | |
| | | typedef struct tagLidarDot |
| | | { |
| | | int x; |
| | | int y; |
| | | unsigned int distance; |
| | | }stLidarDot; |
| | | |
| | | |
| | | extern int nPosX; |
| | | extern int nPosY; |
| | | extern int nPosZ; |
| | | extern int nPosZ1, nPosZ2; |
| | | |
| | | extern int pCount1; |
| | | extern int pCount2; |
| | | |
| | | extern int eCount1; |
| | | extern int eCount2; |
| | | |
| | | extern int dCount1; |
| | | extern int dCount2; |
| | | |
| | | extern int vCount1; |
| | | extern int vCount2; |
| | | |
| | | extern int results[32]; |
| | | |
| | | |
| | | int OrdLidarStart(int nIdx); /* Start LiDar Running , nIde = 0 , 1 , -1 == ALL */ |
| | | int OrdLidarStop(int nIdx); /* stop Lidar Running , nIde = 0 , 1 , -1 == ALL */ |
| | | |
| | | |
| | | int OrdLidarParsePkt(int nLidarIdx, OradarLidarFrame * pLindarPkt, int len1); |
| | | |
| | | int ProcessPos(int nLidarIdx, stLidarDot * pLindarDots, int nCount); |
| | | |
| | | #endif /* __ORDLIDAR_H__ */ |
| | | |
| | |
| | | |
| | | |
| | | #ifndef __SLP_H_V10__ |
| | | #define __SLP_H_V10__ |
| | | typedef unsigned char uchar; |
| | |
| | | // uchar ED; |
| | | }stSLPPacket; |
| | | |
| | | extern uchar bSLPMaster; |
| | | extern uchar nStation; |
| | | extern uchar SLPinputB; |
| | | extern uchar SLPoutputB; |
| | | extern uchar SLPErrSign; |
| | | //extern uchar bSLPMaster; |
| | | //extern uchar nStation; |
| | | //extern uchar SLPinputB; |
| | | //extern uchar SLPoutputB; |
| | | //extern uchar SLPErrSign; |
| | | |
| | | void SLPparsePacket(char * pBuf, uchar len1); |
| | | void SLPMasterSendPacket(void); |
| | | void SLPProcess(void); |
| | | typedef void (*SLPSendPktDef)(unsigned char * pBuf, int Len1); |
| | | |
| | | |
| | | typedef struct tagSLPDef |
| | | { |
| | | uchar bSLPMaster; |
| | | uchar nStation; |
| | | uchar SLPinputB; |
| | | uchar SLPoutputB; |
| | | uchar nCurStation; |
| | | uchar inputBuf[5]; |
| | | uchar outputBuf[5]; |
| | | |
| | | uchar SendBuf[8]; |
| | | |
| | | uchar SLPMasterRecved; //主æºæ¶å°åæºåå¤ |
| | | |
| | | SLPSendPktDef SLPSendPktFunc; |
| | | |
| | | unsigned int SLPSlaveCountOut; |
| | | |
| | | unsigned int SLPLostPkt; // 丢å
æ°é |
| | | |
| | | uchar SLPOKSign; |
| | | uchar SLPErrSign; |
| | | |
| | | int nCount; |
| | | |
| | | }stSLPDef; |
| | | |
| | | void SLPInit(stSLPDef * pSLP, SLPSendPktDef pFunc1); |
| | | void SLPSetCallBack(stSLPDef * pSLP, SLPSendPktDef pFunc1); |
| | | |
| | | void SLPparsePacket(stSLPDef * pSLP, unsigned char * pBuf, uchar len1); |
| | | void SLPMasterSendPacket(stSLPDef * pSLP); |
| | | void SLPProcess(stSLPDef * pSLP); |
| | | |
| | | |
| | | #endif /* __SLP_H_V10__ */ |
| | | |
New file |
| | |
| | | /** |
| | | ****************************************************************************** |
| | | * @file : YDLidar.h |
| | | * @brief : Header for YDLidar.c file. |
| | | * This file contains the Lidar defines of the application. |
| | | ****************************************************************************** |
| | | */ |
| | | |
| | | #ifndef __YDLIDAR_H__ |
| | | #define __YDLIDAR_H__ |
| | | |
| | | #define YDLIDAR_VER (0x100) |
| | | #pragma anon_unions |
| | | |
| | | typedef struct LidarDotData |
| | | { |
| | | unsigned char intensity; |
| | | unsigned char s1; |
| | | /* |
| | | struct { |
| | | unsigned char flag:2; |
| | | unsigned char s1:6; |
| | | }; |
| | | */ |
| | | unsigned char s2; |
| | | }stLidarDotData; |
| | | |
| | | typedef struct tagLidarDotsPkt |
| | | { |
| | | unsigned short StSign; |
| | | unsigned char CT; |
| | | unsigned char LSN; |
| | | unsigned short FSA; |
| | | unsigned short LSA; |
| | | unsigned short CS; |
| | | stLidarDotData LidarDotDatas[40]; |
| | | |
| | | }stLidarDotsPkt, *pLidarDotsPkt; |
| | | |
| | | |
| | | typedef struct tagLidarVector |
| | | { |
| | | int intensit; |
| | | int angle; |
| | | int value; |
| | | }stLidarVector; |
| | | |
| | | typedef struct tagLidarDot |
| | | { |
| | | int x; |
| | | int y; |
| | | int distance; |
| | | }stLidarDot; |
| | | |
| | | |
| | | extern int nPosX; |
| | | extern int nPosY; |
| | | extern int nPosZ; |
| | | extern int nPosZ1, nPosZ2; |
| | | |
| | | extern int pCount1; |
| | | extern int pCount2; |
| | | |
| | | extern int dCount1; |
| | | extern int dCount2; |
| | | |
| | | extern int vCount1; |
| | | extern int vCount2; |
| | | |
| | | |
| | | int YdLidarStart(int nIdx); /* Start LiDar Running , nIde = 0 , 1 , -1 == ALL */ |
| | | int YdLidarStop(int nIdx); /* stop Lidar Running , nIde = 0 , 1 , -1 == ALL */ |
| | | |
| | | |
| | | int YdLidarParsePkt(int nLidarIdx, stLidarDotsPkt * pLindarPkt, int len1); |
| | | |
| | | |
| | | #endif /* __YDLIDAR_H__ */ |
| | | |
| | |
| | | }; |
| | | }shortbits; |
| | | |
| | | #define RX5BUFSIZE 64 |
| | | #define TX5BUFSIZE 64 |
| | | #define RX1BUFSIZE 160 |
| | | #define TX1BUFSIZE 260 |
| | | |
| | | #define UART3RXBUFSIZE 256 |
| | | #define UART3TXBUFSIZE 64 |
| | | |
| | | extern stUartStat Uart3Stat; |
| | | extern unsigned char Uart3RxBuf[UART3RXBUFSIZE]; |
| | | extern unsigned char Uart3TxBuf[UART3TXBUFSIZE]; |
| | | extern unsigned int Uart3RecvBuf1DataLen; |
| | | extern unsigned int Uart3ToSendLen; |
| | | extern unsigned int Uart3SentLen; |
| | | |
| | | #define UART5RXBUFSIZE 256 |
| | | #define UART5TXBUFSIZE 64 |
| | | |
| | | extern stUartStat Uart5Stat; |
| | | extern unsigned char Uart5RxBuf[RX5BUFSIZE]; |
| | | extern unsigned char Uart5TxBuf[TX5BUFSIZE]; |
| | | extern unsigned char Uart5RxBuf[UART5RXBUFSIZE]; |
| | | extern unsigned char Uart5TxBuf[UART5TXBUFSIZE]; |
| | | extern unsigned int Uart5RecvBuf1DataLen; |
| | | extern unsigned int Uart5ToSendLen; |
| | | extern unsigned int Uart5SentLen; |
| | | |
| | | |
| | | #define RX6BUFSIZE 64 |
| | | #define TX6BUFSIZE 64 |
| | | #define UART6RXBUFSIZE 64 |
| | | #define UART6TXBUFSIZE 64 |
| | | |
| | | extern stUartStat Uart6Stat; |
| | | extern unsigned char Uart6RxBuf[RX6BUFSIZE]; |
| | | extern unsigned char Uart6TxBuf[TX6BUFSIZE]; |
| | | extern unsigned char Uart6RxBuf[UART6RXBUFSIZE]; |
| | | extern unsigned char Uart6TxBuf[UART6TXBUFSIZE]; |
| | | extern unsigned int Uart6RecvBuf1DataLen; |
| | | extern unsigned int Uart6ToSendLen; |
| | | extern unsigned int Uart6SentLen; |
| | |
| | | void Uart1RecvDone(void); |
| | | void Uart2SendDone(void); |
| | | void Uart2RecvDone(void); |
| | | |
| | | void Uart3SendDone(void); |
| | | void Uart3RecvDone(void); |
| | | void Uart3SendPacket(char * str, int len); |
| | | |
| | | void Uart5SendDone(void); |
| | | void Uart5RecvDone(void); |
| | | void Uart5SendPacket(char * str, int len); |
| | | |
| | | void Uart6SendDone(void); |
| | | void Uart6RecvDone(void); |
| | | void Uart6SendPacket(char * str, int len); |
| | | void Uart6SendPacket(unsigned char * str, int len); |
| | | |
| | | void SLPSendPacket(char * str, uchar len); |
| | | void SLPSendPacket(void * str, uchar len); |
| | | |
| | | int PutStr(char * str1, int len1); |
| | | int PutStr2(char * str1, int len1); |
| | | int SendPacket(int nChn, void * pBuf,int len1); |
| | | //int SendPacket1(void * pBuf,int len1); |
| | | //int SendPacket2(pKBPacket p1,int len1); |
| | |
| | | #include "stm32f0xx_ll_tim.h" |
| | | #include "stm32f0xx_ll_utils.h" |
| | | #include "stm32f0xx_ll_pwr.h" |
| | | #include "stm32f0xx_ll_flash.h" |
| | | |
| | | /* USER CODE BEGIN Includes */ |
| | | |
| | |
| | | /* #define USE_FULL_ASSERT 1U */ |
| | | |
| | | /* USER CODE BEGIN Private defines */ |
| | | #include "KBus.h" |
| | | |
| | | extern stKBusDef KBus1; |
| | | /* USER CODE END Private defines */ |
| | | |
| | | #ifdef __cplusplus |
| | |
| | | /*#define HAL_EXTI_MODULE_ENABLED */ |
| | | #define HAL_CORTEX_MODULE_ENABLED |
| | | #define HAL_DMA_MODULE_ENABLED |
| | | #define HAL_FLASH_MODULE_ENABLED |
| | | #define HAL_FLASH_MODULE_ENABLED |
| | | #define HAL_GPIO_MODULE_ENABLED |
| | | #define HAL_PWR_MODULE_ENABLED |
| | | #define HAL_RCC_MODULE_ENABLED |
New file |
| | |
| | | /** |
| | | ****************************************************************************** |
| | | * @file stm32f0xx_ll_rcc.h |
| | | * @author MCD Application Team |
| | | * @brief Header file of RCC LL module. |
| | | ****************************************************************************** |
| | | * @attention |
| | | * |
| | | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without modification, |
| | | * are permitted provided that the following conditions are met: |
| | | * 1. Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| | | * this list of conditions and the following disclaimer in the documentation |
| | | * and/or other materials provided with the distribution. |
| | | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| | | * may be used to endorse or promote products derived from this software |
| | | * without specific prior written permission. |
| | | * |
| | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| | | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| | | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| | | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| | | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| | | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| | | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| | | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| | | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| | | * |
| | | ****************************************************************************** |
| | | */ |
| | | |
| | | /* Define to prevent recursive inclusion -------------------------------------*/ |
| | | #ifndef __STM32F0xx_LL_RCC_H |
| | | #define __STM32F0xx_LL_RCC_H |
| | | |
| | | #ifdef __cplusplus |
| | | extern "C" { |
| | | #endif |
| | | |
| | | /* Includes ------------------------------------------------------------------*/ |
| | | #include "stm32f0xx.h" |
| | | |
| | | /** @addtogroup STM32F0xx_LL_Driver |
| | | * @{ |
| | | */ |
| | | |
| | | #if defined(RCC) |
| | | |
| | | /** @defgroup RCC_LL RCC |
| | | * @{ |
| | | */ |
| | | |
| | | /* Private types -------------------------------------------------------------*/ |
| | | /* Private variables ---------------------------------------------------------*/ |
| | | /* Private constants ---------------------------------------------------------*/ |
| | | /** @defgroup RCC_LL_Private_Constants RCC Private Constants |
| | | * @{ |
| | | */ |
| | | /* Defines used for the bit position in the register and perform offsets*/ |
| | | #define RCC_POSITION_HPRE (uint32_t)4U /*!< field position in register RCC_CFGR */ |
| | | #define RCC_POSITION_PPRE1 (uint32_t)8U /*!< field position in register RCC_CFGR */ |
| | | #define RCC_POSITION_PLLMUL (uint32_t)18U /*!< field position in register RCC_CFGR */ |
| | | #define RCC_POSITION_HSICAL (uint32_t)8U /*!< field position in register RCC_CR */ |
| | | #define RCC_POSITION_HSITRIM (uint32_t)3U /*!< field position in register RCC_CR */ |
| | | #define RCC_POSITION_HSI14TRIM (uint32_t)3U /*!< field position in register RCC_CR2 */ |
| | | #define RCC_POSITION_HSI14CAL (uint32_t)8U /*!< field position in register RCC_CR2 */ |
| | | #if defined(RCC_HSI48_SUPPORT) |
| | | #define RCC_POSITION_HSI48CAL (uint32_t)24U /*!< field position in register RCC_CR2 */ |
| | | #endif /* RCC_HSI48_SUPPORT */ |
| | | #define RCC_POSITION_USART1SW (uint32_t)0U /*!< field position in register RCC_CFGR3 */ |
| | | #define RCC_POSITION_USART2SW (uint32_t)16U /*!< field position in register RCC_CFGR3 */ |
| | | #define RCC_POSITION_USART3SW (uint32_t)18U /*!< field position in register RCC_CFGR3 */ |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /* Private macros ------------------------------------------------------------*/ |
| | | #if defined(USE_FULL_LL_DRIVER) |
| | | /** @defgroup RCC_LL_Private_Macros RCC Private Macros |
| | | * @{ |
| | | */ |
| | | /** |
| | | * @} |
| | | */ |
| | | #endif /*USE_FULL_LL_DRIVER*/ |
| | | /* Exported types ------------------------------------------------------------*/ |
| | | #if defined(USE_FULL_LL_DRIVER) |
| | | /** @defgroup RCC_LL_Exported_Types RCC Exported Types |
| | | * @{ |
| | | */ |
| | | |
| | | /** @defgroup LL_ES_CLOCK_FREQ Clocks Frequency Structure |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief RCC Clocks Frequency Structure |
| | | */ |
| | | typedef struct |
| | | { |
| | | uint32_t SYSCLK_Frequency; /*!< SYSCLK clock frequency */ |
| | | uint32_t HCLK_Frequency; /*!< HCLK clock frequency */ |
| | | uint32_t PCLK1_Frequency; /*!< PCLK1 clock frequency */ |
| | | } LL_RCC_ClocksTypeDef; |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | #endif /* USE_FULL_LL_DRIVER */ |
| | | |
| | | /* Exported constants --------------------------------------------------------*/ |
| | | /** @defgroup RCC_LL_Exported_Constants RCC Exported Constants |
| | | * @{ |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_OSC_VALUES Oscillator Values adaptation |
| | | * @brief Defines used to adapt values of different oscillators |
| | | * @note These values could be modified in the user environment according to |
| | | * HW set-up. |
| | | * @{ |
| | | */ |
| | | #if !defined (HSE_VALUE) |
| | | #define HSE_VALUE 12000000U /*!< Value of the HSE oscillator in Hz */ |
| | | #endif /* HSE_VALUE */ |
| | | |
| | | #if !defined (HSI_VALUE) |
| | | #define HSI_VALUE 8000000U /*!< Value of the HSI oscillator in Hz */ |
| | | #endif /* HSI_VALUE */ |
| | | |
| | | #if !defined (LSE_VALUE) |
| | | #define LSE_VALUE 32768U /*!< Value of the LSE oscillator in Hz */ |
| | | #endif /* LSE_VALUE */ |
| | | |
| | | #if !defined (LSI_VALUE) |
| | | #define LSI_VALUE 32000U /*!< Value of the LSI oscillator in Hz */ |
| | | #endif /* LSI_VALUE */ |
| | | #if defined(RCC_HSI48_SUPPORT) |
| | | |
| | | #if !defined (HSI48_VALUE) |
| | | #define HSI48_VALUE 48000000U /*!< Value of the HSI48 oscillator in Hz */ |
| | | #endif /* HSI48_VALUE */ |
| | | #endif /* RCC_HSI48_SUPPORT */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_CLEAR_FLAG Clear Flags Defines |
| | | * @brief Flags defines which can be used with LL_RCC_WriteReg function |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_CIR_LSIRDYC RCC_CIR_LSIRDYC /*!< LSI Ready Interrupt Clear */ |
| | | #define LL_RCC_CIR_LSERDYC RCC_CIR_LSERDYC /*!< LSE Ready Interrupt Clear */ |
| | | #define LL_RCC_CIR_HSIRDYC RCC_CIR_HSIRDYC /*!< HSI Ready Interrupt Clear */ |
| | | #define LL_RCC_CIR_HSERDYC RCC_CIR_HSERDYC /*!< HSE Ready Interrupt Clear */ |
| | | #define LL_RCC_CIR_PLLRDYC RCC_CIR_PLLRDYC /*!< PLL Ready Interrupt Clear */ |
| | | #define LL_RCC_CIR_HSI14RDYC RCC_CIR_HSI14RDYC /*!< HSI14 Ready Interrupt Clear */ |
| | | #if defined(RCC_HSI48_SUPPORT) |
| | | #define LL_RCC_CIR_HSI48RDYC RCC_CIR_HSI48RDYC /*!< HSI48 Ready Interrupt Clear */ |
| | | #endif /* RCC_HSI48_SUPPORT */ |
| | | #define LL_RCC_CIR_CSSC RCC_CIR_CSSC /*!< Clock Security System Interrupt Clear */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_GET_FLAG Get Flags Defines |
| | | * @brief Flags defines which can be used with LL_RCC_ReadReg function |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_CIR_LSIRDYF RCC_CIR_LSIRDYF /*!< LSI Ready Interrupt flag */ |
| | | #define LL_RCC_CIR_LSERDYF RCC_CIR_LSERDYF /*!< LSE Ready Interrupt flag */ |
| | | #define LL_RCC_CIR_HSIRDYF RCC_CIR_HSIRDYF /*!< HSI Ready Interrupt flag */ |
| | | #define LL_RCC_CIR_HSERDYF RCC_CIR_HSERDYF /*!< HSE Ready Interrupt flag */ |
| | | #define LL_RCC_CIR_PLLRDYF RCC_CIR_PLLRDYF /*!< PLL Ready Interrupt flag */ |
| | | #define LL_RCC_CIR_HSI14RDYF RCC_CIR_HSI14RDYF /*!< HSI14 Ready Interrupt flag */ |
| | | #if defined(RCC_HSI48_SUPPORT) |
| | | #define LL_RCC_CIR_HSI48RDYF RCC_CIR_HSI48RDYF /*!< HSI48 Ready Interrupt flag */ |
| | | #endif /* RCC_HSI48_SUPPORT */ |
| | | #define LL_RCC_CIR_CSSF RCC_CIR_CSSF /*!< Clock Security System Interrupt flag */ |
| | | #define LL_RCC_CSR_OBLRSTF RCC_CSR_OBLRSTF /*!< OBL reset flag */ |
| | | #define LL_RCC_CSR_PINRSTF RCC_CSR_PINRSTF /*!< PIN reset flag */ |
| | | #define LL_RCC_CSR_PORRSTF RCC_CSR_PORRSTF /*!< POR/PDR reset flag */ |
| | | #define LL_RCC_CSR_SFTRSTF RCC_CSR_SFTRSTF /*!< Software Reset flag */ |
| | | #define LL_RCC_CSR_IWDGRSTF RCC_CSR_IWDGRSTF /*!< Independent Watchdog reset flag */ |
| | | #define LL_RCC_CSR_WWDGRSTF RCC_CSR_WWDGRSTF /*!< Window watchdog reset flag */ |
| | | #define LL_RCC_CSR_LPWRRSTF RCC_CSR_LPWRRSTF /*!< Low-Power reset flag */ |
| | | #if defined(RCC_CSR_V18PWRRSTF) |
| | | #define LL_RCC_CSR_V18PWRRSTF RCC_CSR_V18PWRRSTF /*!< Reset flag of the 1.8 V domain. */ |
| | | #endif /* RCC_CSR_V18PWRRSTF */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_IT IT Defines |
| | | * @brief IT defines which can be used with LL_RCC_ReadReg and LL_RCC_WriteReg functions |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_CIR_LSIRDYIE RCC_CIR_LSIRDYIE /*!< LSI Ready Interrupt Enable */ |
| | | #define LL_RCC_CIR_LSERDYIE RCC_CIR_LSERDYIE /*!< LSE Ready Interrupt Enable */ |
| | | #define LL_RCC_CIR_HSIRDYIE RCC_CIR_HSIRDYIE /*!< HSI Ready Interrupt Enable */ |
| | | #define LL_RCC_CIR_HSERDYIE RCC_CIR_HSERDYIE /*!< HSE Ready Interrupt Enable */ |
| | | #define LL_RCC_CIR_PLLRDYIE RCC_CIR_PLLRDYIE /*!< PLL Ready Interrupt Enable */ |
| | | #define LL_RCC_CIR_HSI14RDYIE RCC_CIR_HSI14RDYIE /*!< HSI14 Ready Interrupt Enable */ |
| | | #if defined(RCC_HSI48_SUPPORT) |
| | | #define LL_RCC_CIR_HSI48RDYIE RCC_CIR_HSI48RDYIE /*!< HSI48 Ready Interrupt Enable */ |
| | | #endif /* RCC_HSI48_SUPPORT */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_LSEDRIVE LSE oscillator drive capability |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_LSEDRIVE_LOW ((uint32_t)0x00000000U) /*!< Xtal mode lower driving capability */ |
| | | #define LL_RCC_LSEDRIVE_MEDIUMLOW RCC_BDCR_LSEDRV_1 /*!< Xtal mode medium low driving capability */ |
| | | #define LL_RCC_LSEDRIVE_MEDIUMHIGH RCC_BDCR_LSEDRV_0 /*!< Xtal mode medium high driving capability */ |
| | | #define LL_RCC_LSEDRIVE_HIGH RCC_BDCR_LSEDRV /*!< Xtal mode higher driving capability */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_SYS_CLKSOURCE System clock switch |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_SYS_CLKSOURCE_HSI RCC_CFGR_SW_HSI /*!< HSI selection as system clock */ |
| | | #define LL_RCC_SYS_CLKSOURCE_HSE RCC_CFGR_SW_HSE /*!< HSE selection as system clock */ |
| | | #define LL_RCC_SYS_CLKSOURCE_PLL RCC_CFGR_SW_PLL /*!< PLL selection as system clock */ |
| | | #if defined(RCC_CFGR_SW_HSI48) |
| | | #define LL_RCC_SYS_CLKSOURCE_HSI48 RCC_CFGR_SW_HSI48 /*!< HSI48 selection as system clock */ |
| | | #endif /* RCC_CFGR_SW_HSI48 */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_SYS_CLKSOURCE_STATUS System clock switch status |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_SYS_CLKSOURCE_STATUS_HSI RCC_CFGR_SWS_HSI /*!< HSI used as system clock */ |
| | | #define LL_RCC_SYS_CLKSOURCE_STATUS_HSE RCC_CFGR_SWS_HSE /*!< HSE used as system clock */ |
| | | #define LL_RCC_SYS_CLKSOURCE_STATUS_PLL RCC_CFGR_SWS_PLL /*!< PLL used as system clock */ |
| | | #if defined(RCC_CFGR_SWS_HSI48) |
| | | #define LL_RCC_SYS_CLKSOURCE_STATUS_HSI48 RCC_CFGR_SWS_HSI48 /*!< HSI48 used as system clock */ |
| | | #endif /* RCC_CFGR_SWS_HSI48 */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_SYSCLK_DIV AHB prescaler |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_SYSCLK_DIV_1 RCC_CFGR_HPRE_DIV1 /*!< SYSCLK not divided */ |
| | | #define LL_RCC_SYSCLK_DIV_2 RCC_CFGR_HPRE_DIV2 /*!< SYSCLK divided by 2 */ |
| | | #define LL_RCC_SYSCLK_DIV_4 RCC_CFGR_HPRE_DIV4 /*!< SYSCLK divided by 4 */ |
| | | #define LL_RCC_SYSCLK_DIV_8 RCC_CFGR_HPRE_DIV8 /*!< SYSCLK divided by 8 */ |
| | | #define LL_RCC_SYSCLK_DIV_16 RCC_CFGR_HPRE_DIV16 /*!< SYSCLK divided by 16 */ |
| | | #define LL_RCC_SYSCLK_DIV_64 RCC_CFGR_HPRE_DIV64 /*!< SYSCLK divided by 64 */ |
| | | #define LL_RCC_SYSCLK_DIV_128 RCC_CFGR_HPRE_DIV128 /*!< SYSCLK divided by 128 */ |
| | | #define LL_RCC_SYSCLK_DIV_256 RCC_CFGR_HPRE_DIV256 /*!< SYSCLK divided by 256 */ |
| | | #define LL_RCC_SYSCLK_DIV_512 RCC_CFGR_HPRE_DIV512 /*!< SYSCLK divided by 512 */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_APB1_DIV APB low-speed prescaler (APB1) |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_APB1_DIV_1 RCC_CFGR_PPRE_DIV1 /*!< HCLK not divided */ |
| | | #define LL_RCC_APB1_DIV_2 RCC_CFGR_PPRE_DIV2 /*!< HCLK divided by 2 */ |
| | | #define LL_RCC_APB1_DIV_4 RCC_CFGR_PPRE_DIV4 /*!< HCLK divided by 4 */ |
| | | #define LL_RCC_APB1_DIV_8 RCC_CFGR_PPRE_DIV8 /*!< HCLK divided by 8 */ |
| | | #define LL_RCC_APB1_DIV_16 RCC_CFGR_PPRE_DIV16 /*!< HCLK divided by 16 */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_MCO1SOURCE MCO1 SOURCE selection |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_MCO1SOURCE_NOCLOCK RCC_CFGR_MCOSEL_NOCLOCK /*!< MCO output disabled, no clock on MCO */ |
| | | #define LL_RCC_MCO1SOURCE_HSI14 RCC_CFGR_MCOSEL_HSI14 /*!< HSI14 oscillator clock selected */ |
| | | #define LL_RCC_MCO1SOURCE_SYSCLK RCC_CFGR_MCOSEL_SYSCLK /*!< SYSCLK selection as MCO source */ |
| | | #define LL_RCC_MCO1SOURCE_HSI RCC_CFGR_MCOSEL_HSI /*!< HSI selection as MCO source */ |
| | | #define LL_RCC_MCO1SOURCE_HSE RCC_CFGR_MCOSEL_HSE /*!< HSE selection as MCO source */ |
| | | #define LL_RCC_MCO1SOURCE_LSI RCC_CFGR_MCOSEL_LSI /*!< LSI selection as MCO source */ |
| | | #define LL_RCC_MCO1SOURCE_LSE RCC_CFGR_MCOSEL_LSE /*!< LSE selection as MCO source */ |
| | | #if defined(RCC_CFGR_MCOSEL_HSI48) |
| | | #define LL_RCC_MCO1SOURCE_HSI48 RCC_CFGR_MCOSEL_HSI48 /*!< HSI48 selection as MCO source */ |
| | | #endif /* RCC_CFGR_MCOSEL_HSI48 */ |
| | | #define LL_RCC_MCO1SOURCE_PLLCLK_DIV_2 RCC_CFGR_MCOSEL_PLL_DIV2 /*!< PLL clock divided by 2*/ |
| | | #if defined(RCC_CFGR_PLLNODIV) |
| | | #define LL_RCC_MCO1SOURCE_PLLCLK (RCC_CFGR_MCOSEL_PLL_DIV2 | RCC_CFGR_PLLNODIV) /*!< PLL clock selected*/ |
| | | #endif /* RCC_CFGR_PLLNODIV */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_MCO1_DIV MCO1 prescaler |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_MCO1_DIV_1 ((uint32_t)0x00000000U)/*!< MCO Clock divided by 1 */ |
| | | #if defined(RCC_CFGR_MCOPRE) |
| | | #define LL_RCC_MCO1_DIV_2 RCC_CFGR_MCOPRE_DIV2 /*!< MCO Clock divided by 2 */ |
| | | #define LL_RCC_MCO1_DIV_4 RCC_CFGR_MCOPRE_DIV4 /*!< MCO Clock divided by 4 */ |
| | | #define LL_RCC_MCO1_DIV_8 RCC_CFGR_MCOPRE_DIV8 /*!< MCO Clock divided by 8 */ |
| | | #define LL_RCC_MCO1_DIV_16 RCC_CFGR_MCOPRE_DIV16 /*!< MCO Clock divided by 16 */ |
| | | #define LL_RCC_MCO1_DIV_32 RCC_CFGR_MCOPRE_DIV32 /*!< MCO Clock divided by 32 */ |
| | | #define LL_RCC_MCO1_DIV_64 RCC_CFGR_MCOPRE_DIV64 /*!< MCO Clock divided by 64 */ |
| | | #define LL_RCC_MCO1_DIV_128 RCC_CFGR_MCOPRE_DIV128 /*!< MCO Clock divided by 128 */ |
| | | #endif /* RCC_CFGR_MCOPRE */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | #if defined(USE_FULL_LL_DRIVER) |
| | | /** @defgroup RCC_LL_EC_PERIPH_FREQUENCY Peripheral clock frequency |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_PERIPH_FREQUENCY_NO 0x00000000U /*!< No clock enabled for the peripheral */ |
| | | #define LL_RCC_PERIPH_FREQUENCY_NA 0xFFFFFFFFU /*!< Frequency cannot be provided as external clock */ |
| | | /** |
| | | * @} |
| | | */ |
| | | #endif /* USE_FULL_LL_DRIVER */ |
| | | |
| | | /** @defgroup RCC_LL_EC_USART1_CLKSOURCE Peripheral USART clock source selection |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_USART1_CLKSOURCE_PCLK1 (uint32_t)((RCC_POSITION_USART1SW << 24) | RCC_CFGR3_USART1SW_PCLK) /*!< PCLK1 clock used as USART1 clock source */ |
| | | #define LL_RCC_USART1_CLKSOURCE_SYSCLK (uint32_t)((RCC_POSITION_USART1SW << 24) | RCC_CFGR3_USART1SW_SYSCLK) /*!< System clock selected as USART1 clock source */ |
| | | #define LL_RCC_USART1_CLKSOURCE_LSE (uint32_t)((RCC_POSITION_USART1SW << 24) | RCC_CFGR3_USART1SW_LSE) /*!< LSE oscillator clock used as USART1 clock source */ |
| | | #define LL_RCC_USART1_CLKSOURCE_HSI (uint32_t)((RCC_POSITION_USART1SW << 24) | RCC_CFGR3_USART1SW_HSI) /*!< HSI oscillator clock used as USART1 clock source */ |
| | | #if defined(RCC_CFGR3_USART2SW) |
| | | #define LL_RCC_USART2_CLKSOURCE_PCLK1 (uint32_t)((RCC_POSITION_USART2SW << 24) | RCC_CFGR3_USART2SW_PCLK) /*!< PCLK1 clock used as USART2 clock source */ |
| | | #define LL_RCC_USART2_CLKSOURCE_SYSCLK (uint32_t)((RCC_POSITION_USART2SW << 24) | RCC_CFGR3_USART2SW_SYSCLK) /*!< System clock selected as USART2 clock source */ |
| | | #define LL_RCC_USART2_CLKSOURCE_LSE (uint32_t)((RCC_POSITION_USART2SW << 24) | RCC_CFGR3_USART2SW_LSE) /*!< LSE oscillator clock used as USART2 clock source */ |
| | | #define LL_RCC_USART2_CLKSOURCE_HSI (uint32_t)((RCC_POSITION_USART2SW << 24) | RCC_CFGR3_USART2SW_HSI) /*!< HSI oscillator clock used as USART2 clock source */ |
| | | #endif /* RCC_CFGR3_USART2SW */ |
| | | #if defined(RCC_CFGR3_USART3SW) |
| | | #define LL_RCC_USART3_CLKSOURCE_PCLK1 (uint32_t)((RCC_POSITION_USART3SW << 24) | RCC_CFGR3_USART3SW_PCLK) /*!< PCLK1 clock used as USART3 clock source */ |
| | | #define LL_RCC_USART3_CLKSOURCE_SYSCLK (uint32_t)((RCC_POSITION_USART3SW << 24) | RCC_CFGR3_USART3SW_SYSCLK) /*!< System clock selected as USART3 clock source */ |
| | | #define LL_RCC_USART3_CLKSOURCE_LSE (uint32_t)((RCC_POSITION_USART3SW << 24) | RCC_CFGR3_USART3SW_LSE) /*!< LSE oscillator clock used as USART3 clock source */ |
| | | #define LL_RCC_USART3_CLKSOURCE_HSI (uint32_t)((RCC_POSITION_USART3SW << 24) | RCC_CFGR3_USART3SW_HSI) /*!< HSI oscillator clock used as USART3 clock source */ |
| | | #endif /* RCC_CFGR3_USART3SW */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_I2C1_CLKSOURCE Peripheral I2C clock source selection |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_I2C1_CLKSOURCE_HSI RCC_CFGR3_I2C1SW_HSI /*!< HSI oscillator clock used as I2C1 clock source */ |
| | | #define LL_RCC_I2C1_CLKSOURCE_SYSCLK RCC_CFGR3_I2C1SW_SYSCLK /*!< System clock selected as I2C1 clock source */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | #if defined(CEC) |
| | | /** @defgroup RCC_LL_EC_CEC_CLKSOURCE Peripheral CEC clock source selection |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_CEC_CLKSOURCE_HSI_DIV244 RCC_CFGR3_CECSW_HSI_DIV244 /*!< HSI clock divided by 244 selected as HDMI CEC entry clock source */ |
| | | #define LL_RCC_CEC_CLKSOURCE_LSE RCC_CFGR3_CECSW_LSE /*!< LSE clock selected as HDMI CEC entry clock source */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | #endif /* CEC */ |
| | | |
| | | #if defined(USB) |
| | | /** @defgroup RCC_LL_EC_USB_CLKSOURCE Peripheral USB clock source selection |
| | | * @{ |
| | | */ |
| | | #if defined(RCC_CFGR3_USBSW_HSI48) |
| | | #define LL_RCC_USB_CLKSOURCE_HSI48 RCC_CFGR3_USBSW_HSI48 /*!< HSI48 oscillator clock used as USB clock source */ |
| | | #else |
| | | #define LL_RCC_USB_CLKSOURCE_NONE ((uint32_t)0x00000000) /*!< USB Clock disabled */ |
| | | #endif /*RCC_CFGR3_USBSW_HSI48*/ |
| | | #define LL_RCC_USB_CLKSOURCE_PLL RCC_CFGR3_USBSW_PLLCLK /*!< PLL selected as USB clock source */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | #endif /* USB */ |
| | | |
| | | /** @defgroup RCC_LL_EC_USART1 Peripheral USART get clock source |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_USART1_CLKSOURCE RCC_POSITION_USART1SW /*!< USART1 Clock source selection */ |
| | | #if defined(RCC_CFGR3_USART2SW) |
| | | #define LL_RCC_USART2_CLKSOURCE RCC_POSITION_USART2SW /*!< USART2 Clock source selection */ |
| | | #endif /* RCC_CFGR3_USART2SW */ |
| | | #if defined(RCC_CFGR3_USART3SW) |
| | | #define LL_RCC_USART3_CLKSOURCE RCC_POSITION_USART3SW /*!< USART3 Clock source selection */ |
| | | #endif /* RCC_CFGR3_USART3SW */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_I2C1 Peripheral I2C get clock source |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_I2C1_CLKSOURCE RCC_CFGR3_I2C1SW /*!< I2C1 Clock source selection */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | #if defined(CEC) |
| | | /** @defgroup RCC_LL_EC_CEC Peripheral CEC get clock source |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_CEC_CLKSOURCE RCC_CFGR3_CECSW /*!< CEC Clock source selection */ |
| | | /** |
| | | * @} |
| | | */ |
| | | #endif /* CEC */ |
| | | |
| | | #if defined(USB) |
| | | /** @defgroup RCC_LL_EC_USB Peripheral USB get clock source |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_USB_CLKSOURCE RCC_CFGR3_USBSW /*!< USB Clock source selection */ |
| | | /** |
| | | * @} |
| | | */ |
| | | #endif /* USB */ |
| | | |
| | | /** @defgroup RCC_LL_EC_RTC_CLKSOURCE RTC clock source selection |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_RTC_CLKSOURCE_NONE 0x00000000U /*!< No clock used as RTC clock */ |
| | | #define LL_RCC_RTC_CLKSOURCE_LSE RCC_BDCR_RTCSEL_0 /*!< LSE oscillator clock used as RTC clock */ |
| | | #define LL_RCC_RTC_CLKSOURCE_LSI RCC_BDCR_RTCSEL_1 /*!< LSI oscillator clock used as RTC clock */ |
| | | #define LL_RCC_RTC_CLKSOURCE_HSE_DIV32 RCC_BDCR_RTCSEL /*!< HSE oscillator clock divided by 32 used as RTC clock */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_PLL_MUL PLL Multiplicator factor |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_PLL_MUL_2 RCC_CFGR_PLLMUL2 /*!< PLL input clock*2 */ |
| | | #define LL_RCC_PLL_MUL_3 RCC_CFGR_PLLMUL3 /*!< PLL input clock*3 */ |
| | | #define LL_RCC_PLL_MUL_4 RCC_CFGR_PLLMUL4 /*!< PLL input clock*4 */ |
| | | #define LL_RCC_PLL_MUL_5 RCC_CFGR_PLLMUL5 /*!< PLL input clock*5 */ |
| | | #define LL_RCC_PLL_MUL_6 RCC_CFGR_PLLMUL6 /*!< PLL input clock*6 */ |
| | | #define LL_RCC_PLL_MUL_7 RCC_CFGR_PLLMUL7 /*!< PLL input clock*7 */ |
| | | #define LL_RCC_PLL_MUL_8 RCC_CFGR_PLLMUL8 /*!< PLL input clock*8 */ |
| | | #define LL_RCC_PLL_MUL_9 RCC_CFGR_PLLMUL9 /*!< PLL input clock*9 */ |
| | | #define LL_RCC_PLL_MUL_10 RCC_CFGR_PLLMUL10 /*!< PLL input clock*10 */ |
| | | #define LL_RCC_PLL_MUL_11 RCC_CFGR_PLLMUL11 /*!< PLL input clock*11 */ |
| | | #define LL_RCC_PLL_MUL_12 RCC_CFGR_PLLMUL12 /*!< PLL input clock*12 */ |
| | | #define LL_RCC_PLL_MUL_13 RCC_CFGR_PLLMUL13 /*!< PLL input clock*13 */ |
| | | #define LL_RCC_PLL_MUL_14 RCC_CFGR_PLLMUL14 /*!< PLL input clock*14 */ |
| | | #define LL_RCC_PLL_MUL_15 RCC_CFGR_PLLMUL15 /*!< PLL input clock*15 */ |
| | | #define LL_RCC_PLL_MUL_16 RCC_CFGR_PLLMUL16 /*!< PLL input clock*16 */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_PLLSOURCE PLL SOURCE |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_PLLSOURCE_HSE RCC_CFGR_PLLSRC_HSE_PREDIV /*!< HSE/PREDIV clock selected as PLL entry clock source */ |
| | | #if defined(RCC_PLLSRC_PREDIV1_SUPPORT) |
| | | #define LL_RCC_PLLSOURCE_HSI RCC_CFGR_PLLSRC_HSI_PREDIV /*!< HSI/PREDIV clock selected as PLL entry clock source */ |
| | | #if defined(RCC_CFGR_SW_HSI48) |
| | | #define LL_RCC_PLLSOURCE_HSI48 RCC_CFGR_PLLSRC_HSI48_PREDIV /*!< HSI48/PREDIV clock selected as PLL entry clock source */ |
| | | #endif /* RCC_CFGR_SW_HSI48 */ |
| | | #else |
| | | #define LL_RCC_PLLSOURCE_HSI_DIV_2 RCC_CFGR_PLLSRC_HSI_DIV2 /*!< HSI clock divided by 2 selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_1 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV1) /*!< HSE clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_2 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV2) /*!< HSE/2 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_3 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV3) /*!< HSE/3 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_4 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV4) /*!< HSE/4 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_5 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV5) /*!< HSE/5 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_6 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV6) /*!< HSE/6 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_7 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV7) /*!< HSE/7 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_8 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV8) /*!< HSE/8 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_9 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV9) /*!< HSE/9 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_10 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV10) /*!< HSE/10 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_11 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV11) /*!< HSE/11 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_12 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV12) /*!< HSE/12 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_13 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV13) /*!< HSE/13 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_14 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV14) /*!< HSE/14 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_15 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV15) /*!< HSE/15 clock selected as PLL entry clock source */ |
| | | #define LL_RCC_PLLSOURCE_HSE_DIV_16 (RCC_CFGR_PLLSRC_HSE_PREDIV | RCC_CFGR2_PREDIV_DIV16) /*!< HSE/16 clock selected as PLL entry clock source */ |
| | | #endif /* RCC_PLLSRC_PREDIV1_SUPPORT */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EC_PREDIV_DIV PREDIV Division factor |
| | | * @{ |
| | | */ |
| | | #define LL_RCC_PREDIV_DIV_1 RCC_CFGR2_PREDIV_DIV1 /*!< PREDIV input clock not divided */ |
| | | #define LL_RCC_PREDIV_DIV_2 RCC_CFGR2_PREDIV_DIV2 /*!< PREDIV input clock divided by 2 */ |
| | | #define LL_RCC_PREDIV_DIV_3 RCC_CFGR2_PREDIV_DIV3 /*!< PREDIV input clock divided by 3 */ |
| | | #define LL_RCC_PREDIV_DIV_4 RCC_CFGR2_PREDIV_DIV4 /*!< PREDIV input clock divided by 4 */ |
| | | #define LL_RCC_PREDIV_DIV_5 RCC_CFGR2_PREDIV_DIV5 /*!< PREDIV input clock divided by 5 */ |
| | | #define LL_RCC_PREDIV_DIV_6 RCC_CFGR2_PREDIV_DIV6 /*!< PREDIV input clock divided by 6 */ |
| | | #define LL_RCC_PREDIV_DIV_7 RCC_CFGR2_PREDIV_DIV7 /*!< PREDIV input clock divided by 7 */ |
| | | #define LL_RCC_PREDIV_DIV_8 RCC_CFGR2_PREDIV_DIV8 /*!< PREDIV input clock divided by 8 */ |
| | | #define LL_RCC_PREDIV_DIV_9 RCC_CFGR2_PREDIV_DIV9 /*!< PREDIV input clock divided by 9 */ |
| | | #define LL_RCC_PREDIV_DIV_10 RCC_CFGR2_PREDIV_DIV10 /*!< PREDIV input clock divided by 10 */ |
| | | #define LL_RCC_PREDIV_DIV_11 RCC_CFGR2_PREDIV_DIV11 /*!< PREDIV input clock divided by 11 */ |
| | | #define LL_RCC_PREDIV_DIV_12 RCC_CFGR2_PREDIV_DIV12 /*!< PREDIV input clock divided by 12 */ |
| | | #define LL_RCC_PREDIV_DIV_13 RCC_CFGR2_PREDIV_DIV13 /*!< PREDIV input clock divided by 13 */ |
| | | #define LL_RCC_PREDIV_DIV_14 RCC_CFGR2_PREDIV_DIV14 /*!< PREDIV input clock divided by 14 */ |
| | | #define LL_RCC_PREDIV_DIV_15 RCC_CFGR2_PREDIV_DIV15 /*!< PREDIV input clock divided by 15 */ |
| | | #define LL_RCC_PREDIV_DIV_16 RCC_CFGR2_PREDIV_DIV16 /*!< PREDIV input clock divided by 16 */ |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /* Exported macro ------------------------------------------------------------*/ |
| | | /** @defgroup RCC_LL_Exported_Macros RCC Exported Macros |
| | | * @{ |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EM_WRITE_READ Common Write and read registers Macros |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Write a value in RCC register |
| | | * @param __REG__ Register to be written |
| | | * @param __VALUE__ Value to be written in the register |
| | | * @retval None |
| | | */ |
| | | #define LL_RCC_WriteReg(__REG__, __VALUE__) WRITE_REG(RCC->__REG__, (__VALUE__)) |
| | | |
| | | /** |
| | | * @brief Read a value in RCC register |
| | | * @param __REG__ Register to be read |
| | | * @retval Register value |
| | | */ |
| | | #define LL_RCC_ReadReg(__REG__) READ_REG(RCC->__REG__) |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EM_CALC_FREQ Calculate frequencies |
| | | * @{ |
| | | */ |
| | | |
| | | #if defined(RCC_PLLSRC_PREDIV1_SUPPORT) |
| | | /** |
| | | * @brief Helper macro to calculate the PLLCLK frequency |
| | | * @note ex: @ref __LL_RCC_CALC_PLLCLK_FREQ (HSE_VALUE, @ref LL_RCC_PLL_GetMultiplicator() |
| | | * , @ref LL_RCC_PLL_GetPrediv()); |
| | | * @param __INPUTFREQ__ PLL Input frequency (based on HSE/HSI/HSI48) |
| | | * @param __PLLMUL__ This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_PLL_MUL_2 |
| | | * @arg @ref LL_RCC_PLL_MUL_3 |
| | | * @arg @ref LL_RCC_PLL_MUL_4 |
| | | * @arg @ref LL_RCC_PLL_MUL_5 |
| | | * @arg @ref LL_RCC_PLL_MUL_6 |
| | | * @arg @ref LL_RCC_PLL_MUL_7 |
| | | * @arg @ref LL_RCC_PLL_MUL_8 |
| | | * @arg @ref LL_RCC_PLL_MUL_9 |
| | | * @arg @ref LL_RCC_PLL_MUL_10 |
| | | * @arg @ref LL_RCC_PLL_MUL_11 |
| | | * @arg @ref LL_RCC_PLL_MUL_12 |
| | | * @arg @ref LL_RCC_PLL_MUL_13 |
| | | * @arg @ref LL_RCC_PLL_MUL_14 |
| | | * @arg @ref LL_RCC_PLL_MUL_15 |
| | | * @arg @ref LL_RCC_PLL_MUL_16 |
| | | * @param __PLLPREDIV__ This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_PREDIV_DIV_1 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_2 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_3 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_4 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_5 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_6 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_7 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_8 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_9 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_10 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_11 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_12 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_13 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_14 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_15 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_16 |
| | | * @retval PLL clock frequency (in Hz) |
| | | */ |
| | | #define __LL_RCC_CALC_PLLCLK_FREQ(__INPUTFREQ__, __PLLMUL__, __PLLPREDIV__) \ |
| | | (((__INPUTFREQ__) / ((((__PLLPREDIV__) & RCC_CFGR2_PREDIV) + 1U))) * ((((__PLLMUL__) & RCC_CFGR_PLLMUL) >> RCC_POSITION_PLLMUL) + 2U)) |
| | | |
| | | #else |
| | | /** |
| | | * @brief Helper macro to calculate the PLLCLK frequency |
| | | * @note ex: @ref __LL_RCC_CALC_PLLCLK_FREQ (HSE_VALUE / (@ref LL_RCC_PLL_GetPrediv () + 1), @ref LL_RCC_PLL_GetMultiplicator()); |
| | | * @param __INPUTFREQ__ PLL Input frequency (based on HSE div Prediv / HSI div 2) |
| | | * @param __PLLMUL__ This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_PLL_MUL_2 |
| | | * @arg @ref LL_RCC_PLL_MUL_3 |
| | | * @arg @ref LL_RCC_PLL_MUL_4 |
| | | * @arg @ref LL_RCC_PLL_MUL_5 |
| | | * @arg @ref LL_RCC_PLL_MUL_6 |
| | | * @arg @ref LL_RCC_PLL_MUL_7 |
| | | * @arg @ref LL_RCC_PLL_MUL_8 |
| | | * @arg @ref LL_RCC_PLL_MUL_9 |
| | | * @arg @ref LL_RCC_PLL_MUL_10 |
| | | * @arg @ref LL_RCC_PLL_MUL_11 |
| | | * @arg @ref LL_RCC_PLL_MUL_12 |
| | | * @arg @ref LL_RCC_PLL_MUL_13 |
| | | * @arg @ref LL_RCC_PLL_MUL_14 |
| | | * @arg @ref LL_RCC_PLL_MUL_15 |
| | | * @arg @ref LL_RCC_PLL_MUL_16 |
| | | * @retval PLL clock frequency (in Hz) |
| | | */ |
| | | #define __LL_RCC_CALC_PLLCLK_FREQ(__INPUTFREQ__, __PLLMUL__) \ |
| | | ((__INPUTFREQ__) * ((((__PLLMUL__) & RCC_CFGR_PLLMUL) >> RCC_POSITION_PLLMUL) + 2U)) |
| | | #endif /* RCC_PLLSRC_PREDIV1_SUPPORT */ |
| | | /** |
| | | * @brief Helper macro to calculate the HCLK frequency |
| | | * @note: __AHBPRESCALER__ be retrieved by @ref LL_RCC_GetAHBPrescaler |
| | | * ex: __LL_RCC_CALC_HCLK_FREQ(LL_RCC_GetAHBPrescaler()) |
| | | * @param __SYSCLKFREQ__ SYSCLK frequency (based on HSE/HSI/PLLCLK) |
| | | * @param __AHBPRESCALER__ This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_1 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_2 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_4 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_8 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_16 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_64 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_128 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_256 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_512 |
| | | * @retval HCLK clock frequency (in Hz) |
| | | */ |
| | | #define __LL_RCC_CALC_HCLK_FREQ(__SYSCLKFREQ__, __AHBPRESCALER__) ((__SYSCLKFREQ__) >> AHBPrescTable[((__AHBPRESCALER__) & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos]) |
| | | |
| | | /** |
| | | * @brief Helper macro to calculate the PCLK1 frequency (ABP1) |
| | | * @note: __APB1PRESCALER__ be retrieved by @ref LL_RCC_GetAPB1Prescaler |
| | | * ex: __LL_RCC_CALC_PCLK1_FREQ(LL_RCC_GetAPB1Prescaler()) |
| | | * @param __HCLKFREQ__ HCLK frequency |
| | | * @param __APB1PRESCALER__ This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_APB1_DIV_1 |
| | | * @arg @ref LL_RCC_APB1_DIV_2 |
| | | * @arg @ref LL_RCC_APB1_DIV_4 |
| | | * @arg @ref LL_RCC_APB1_DIV_8 |
| | | * @arg @ref LL_RCC_APB1_DIV_16 |
| | | * @retval PCLK1 clock frequency (in Hz) |
| | | */ |
| | | #define __LL_RCC_CALC_PCLK1_FREQ(__HCLKFREQ__, __APB1PRESCALER__) ((__HCLKFREQ__) >> APBPrescTable[(__APB1PRESCALER__) >> RCC_CFGR_PPRE_Pos]) |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /* Exported functions --------------------------------------------------------*/ |
| | | /** @defgroup RCC_LL_Exported_Functions RCC Exported Functions |
| | | * @{ |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_HSE HSE |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Enable the Clock Security System. |
| | | * @rmtoll CR CSSON LL_RCC_HSE_EnableCSS |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSE_EnableCSS(void) |
| | | { |
| | | SET_BIT(RCC->CR, RCC_CR_CSSON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable the Clock Security System. |
| | | * @note Cannot be disabled in HSE is ready (only by hardware) |
| | | * @rmtoll CR CSSON LL_RCC_HSE_DisableCSS |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSE_DisableCSS(void) |
| | | { |
| | | CLEAR_BIT(RCC->CR, RCC_CR_CSSON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Enable HSE external oscillator (HSE Bypass) |
| | | * @rmtoll CR HSEBYP LL_RCC_HSE_EnableBypass |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSE_EnableBypass(void) |
| | | { |
| | | SET_BIT(RCC->CR, RCC_CR_HSEBYP); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable HSE external oscillator (HSE Bypass) |
| | | * @rmtoll CR HSEBYP LL_RCC_HSE_DisableBypass |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSE_DisableBypass(void) |
| | | { |
| | | CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP); |
| | | } |
| | | |
| | | /** |
| | | * @brief Enable HSE crystal oscillator (HSE ON) |
| | | * @rmtoll CR HSEON LL_RCC_HSE_Enable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSE_Enable(void) |
| | | { |
| | | SET_BIT(RCC->CR, RCC_CR_HSEON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable HSE crystal oscillator (HSE ON) |
| | | * @rmtoll CR HSEON LL_RCC_HSE_Disable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSE_Disable(void) |
| | | { |
| | | CLEAR_BIT(RCC->CR, RCC_CR_HSEON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if HSE oscillator Ready |
| | | * @rmtoll CR HSERDY LL_RCC_HSE_IsReady |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_HSE_IsReady(void) |
| | | { |
| | | return (READ_BIT(RCC->CR, RCC_CR_HSERDY) == (RCC_CR_HSERDY)); |
| | | } |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_HSI HSI |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Enable HSI oscillator |
| | | * @rmtoll CR HSION LL_RCC_HSI_Enable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSI_Enable(void) |
| | | { |
| | | SET_BIT(RCC->CR, RCC_CR_HSION); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable HSI oscillator |
| | | * @rmtoll CR HSION LL_RCC_HSI_Disable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSI_Disable(void) |
| | | { |
| | | CLEAR_BIT(RCC->CR, RCC_CR_HSION); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if HSI clock is ready |
| | | * @rmtoll CR HSIRDY LL_RCC_HSI_IsReady |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_HSI_IsReady(void) |
| | | { |
| | | return (READ_BIT(RCC->CR, RCC_CR_HSIRDY) == (RCC_CR_HSIRDY)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get HSI Calibration value |
| | | * @note When HSITRIM is written, HSICAL is updated with the sum of |
| | | * HSITRIM and the factory trim value |
| | | * @rmtoll CR HSICAL LL_RCC_HSI_GetCalibration |
| | | * @retval Between Min_Data = 0x00 and Max_Data = 0xFF |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_HSI_GetCalibration(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CR, RCC_CR_HSICAL) >> RCC_CR_HSICAL_Pos); |
| | | } |
| | | |
| | | /** |
| | | * @brief Set HSI Calibration trimming |
| | | * @note user-programmable trimming value that is added to the HSICAL |
| | | * @note Default value is 16, which, when added to the HSICAL value, |
| | | * should trim the HSI to 16 MHz +/- 1 % |
| | | * @rmtoll CR HSITRIM LL_RCC_HSI_SetCalibTrimming |
| | | * @param Value between Min_Data = 0x00 and Max_Data = 0x1F |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSI_SetCalibTrimming(uint32_t Value) |
| | | { |
| | | MODIFY_REG(RCC->CR, RCC_CR_HSITRIM, Value << RCC_CR_HSITRIM_Pos); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get HSI Calibration trimming |
| | | * @rmtoll CR HSITRIM LL_RCC_HSI_GetCalibTrimming |
| | | * @retval Between Min_Data = 0x00 and Max_Data = 0x1F |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_HSI_GetCalibTrimming(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CR, RCC_CR_HSITRIM) >> RCC_CR_HSITRIM_Pos); |
| | | } |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | #if defined(RCC_HSI48_SUPPORT) |
| | | /** @defgroup RCC_LL_EF_HSI48 HSI48 |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Enable HSI48 |
| | | * @rmtoll CR2 HSI48ON LL_RCC_HSI48_Enable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSI48_Enable(void) |
| | | { |
| | | SET_BIT(RCC->CR2, RCC_CR2_HSI48ON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable HSI48 |
| | | * @rmtoll CR2 HSI48ON LL_RCC_HSI48_Disable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSI48_Disable(void) |
| | | { |
| | | CLEAR_BIT(RCC->CR2, RCC_CR2_HSI48ON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if HSI48 oscillator Ready |
| | | * @rmtoll CR2 HSI48RDY LL_RCC_HSI48_IsReady |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_HSI48_IsReady(void) |
| | | { |
| | | return (READ_BIT(RCC->CR2, RCC_CR2_HSI48RDY) == (RCC_CR2_HSI48RDY)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get HSI48 Calibration value |
| | | * @rmtoll CR2 HSI48CAL LL_RCC_HSI48_GetCalibration |
| | | * @retval Between Min_Data = 0x00 and Max_Data = 0xFF |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_HSI48_GetCalibration(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CR2, RCC_CR2_HSI48CAL) >> RCC_POSITION_HSI48CAL); |
| | | } |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | #endif /* RCC_HSI48_SUPPORT */ |
| | | |
| | | /** @defgroup RCC_LL_EF_HSI14 HSI14 |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Enable HSI14 |
| | | * @rmtoll CR2 HSI14ON LL_RCC_HSI14_Enable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSI14_Enable(void) |
| | | { |
| | | SET_BIT(RCC->CR2, RCC_CR2_HSI14ON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable HSI14 |
| | | * @rmtoll CR2 HSI14ON LL_RCC_HSI14_Disable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSI14_Disable(void) |
| | | { |
| | | CLEAR_BIT(RCC->CR2, RCC_CR2_HSI14ON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if HSI14 oscillator Ready |
| | | * @rmtoll CR2 HSI14RDY LL_RCC_HSI14_IsReady |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_HSI14_IsReady(void) |
| | | { |
| | | return (READ_BIT(RCC->CR2, RCC_CR2_HSI14RDY) == (RCC_CR2_HSI14RDY)); |
| | | } |
| | | |
| | | /** |
| | | * @brief ADC interface can turn on the HSI14 oscillator |
| | | * @rmtoll CR2 HSI14DIS LL_RCC_HSI14_EnableADCControl |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSI14_EnableADCControl(void) |
| | | { |
| | | CLEAR_BIT(RCC->CR2, RCC_CR2_HSI14DIS); |
| | | } |
| | | |
| | | /** |
| | | * @brief ADC interface can not turn on the HSI14 oscillator |
| | | * @rmtoll CR2 HSI14DIS LL_RCC_HSI14_DisableADCControl |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSI14_DisableADCControl(void) |
| | | { |
| | | SET_BIT(RCC->CR2, RCC_CR2_HSI14DIS); |
| | | } |
| | | |
| | | /** |
| | | * @brief Set HSI14 Calibration trimming |
| | | * @note user-programmable trimming value that is added to the HSI14CAL |
| | | * @note Default value is 16, which, when added to the HSI14CAL value, |
| | | * should trim the HSI14 to 14 MHz +/- 1 % |
| | | * @rmtoll CR2 HSI14TRIM LL_RCC_HSI14_SetCalibTrimming |
| | | * @param Value between Min_Data = 0x00 and Max_Data = 0xFF |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_HSI14_SetCalibTrimming(uint32_t Value) |
| | | { |
| | | MODIFY_REG(RCC->CR2, RCC_CR2_HSI14TRIM, Value << RCC_POSITION_HSI14TRIM); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get HSI14 Calibration value |
| | | * @note When HSI14TRIM is written, HSI14CAL is updated with the sum of |
| | | * HSI14TRIM and the factory trim value |
| | | * @rmtoll CR2 HSI14TRIM LL_RCC_HSI14_GetCalibTrimming |
| | | * @retval Between Min_Data = 0x00 and Max_Data = 0x1F |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_HSI14_GetCalibTrimming(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CR2, RCC_CR2_HSI14TRIM) >> RCC_POSITION_HSI14TRIM); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get HSI14 Calibration trimming |
| | | * @rmtoll CR2 HSI14CAL LL_RCC_HSI14_GetCalibration |
| | | * @retval Between Min_Data = 0x00 and Max_Data = 0x1F |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_HSI14_GetCalibration(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CR2, RCC_CR2_HSI14CAL) >> RCC_POSITION_HSI14CAL); |
| | | } |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_LSE LSE |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Enable Low Speed External (LSE) crystal. |
| | | * @rmtoll BDCR LSEON LL_RCC_LSE_Enable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_LSE_Enable(void) |
| | | { |
| | | SET_BIT(RCC->BDCR, RCC_BDCR_LSEON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable Low Speed External (LSE) crystal. |
| | | * @rmtoll BDCR LSEON LL_RCC_LSE_Disable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_LSE_Disable(void) |
| | | { |
| | | CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Enable external clock source (LSE bypass). |
| | | * @rmtoll BDCR LSEBYP LL_RCC_LSE_EnableBypass |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_LSE_EnableBypass(void) |
| | | { |
| | | SET_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable external clock source (LSE bypass). |
| | | * @rmtoll BDCR LSEBYP LL_RCC_LSE_DisableBypass |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_LSE_DisableBypass(void) |
| | | { |
| | | CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEBYP); |
| | | } |
| | | |
| | | /** |
| | | * @brief Set LSE oscillator drive capability |
| | | * @note The oscillator is in Xtal mode when it is not in bypass mode. |
| | | * @rmtoll BDCR LSEDRV LL_RCC_LSE_SetDriveCapability |
| | | * @param LSEDrive This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_LSEDRIVE_LOW |
| | | * @arg @ref LL_RCC_LSEDRIVE_MEDIUMLOW |
| | | * @arg @ref LL_RCC_LSEDRIVE_MEDIUMHIGH |
| | | * @arg @ref LL_RCC_LSEDRIVE_HIGH |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_LSE_SetDriveCapability(uint32_t LSEDrive) |
| | | { |
| | | MODIFY_REG(RCC->BDCR, RCC_BDCR_LSEDRV, LSEDrive); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get LSE oscillator drive capability |
| | | * @rmtoll BDCR LSEDRV LL_RCC_LSE_GetDriveCapability |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_LSEDRIVE_LOW |
| | | * @arg @ref LL_RCC_LSEDRIVE_MEDIUMLOW |
| | | * @arg @ref LL_RCC_LSEDRIVE_MEDIUMHIGH |
| | | * @arg @ref LL_RCC_LSEDRIVE_HIGH |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_LSE_GetDriveCapability(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->BDCR, RCC_BDCR_LSEDRV)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if LSE oscillator Ready |
| | | * @rmtoll BDCR LSERDY LL_RCC_LSE_IsReady |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_LSE_IsReady(void) |
| | | { |
| | | return (READ_BIT(RCC->BDCR, RCC_BDCR_LSERDY) == (RCC_BDCR_LSERDY)); |
| | | } |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_LSI LSI |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Enable LSI Oscillator |
| | | * @rmtoll CSR LSION LL_RCC_LSI_Enable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_LSI_Enable(void) |
| | | { |
| | | SET_BIT(RCC->CSR, RCC_CSR_LSION); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable LSI Oscillator |
| | | * @rmtoll CSR LSION LL_RCC_LSI_Disable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_LSI_Disable(void) |
| | | { |
| | | CLEAR_BIT(RCC->CSR, RCC_CSR_LSION); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if LSI is Ready |
| | | * @rmtoll CSR LSIRDY LL_RCC_LSI_IsReady |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_LSI_IsReady(void) |
| | | { |
| | | return (READ_BIT(RCC->CSR, RCC_CSR_LSIRDY) == (RCC_CSR_LSIRDY)); |
| | | } |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_System System |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Configure the system clock source |
| | | * @rmtoll CFGR SW LL_RCC_SetSysClkSource |
| | | * @param Source This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_SYS_CLKSOURCE_HSI |
| | | * @arg @ref LL_RCC_SYS_CLKSOURCE_HSE |
| | | * @arg @ref LL_RCC_SYS_CLKSOURCE_PLL |
| | | * @arg @ref LL_RCC_SYS_CLKSOURCE_HSI48 (*) |
| | | * |
| | | * (*) value not defined in all devices |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_SetSysClkSource(uint32_t Source) |
| | | { |
| | | MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, Source); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get the system clock source |
| | | * @rmtoll CFGR SWS LL_RCC_GetSysClkSource |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_SYS_CLKSOURCE_STATUS_HSI |
| | | * @arg @ref LL_RCC_SYS_CLKSOURCE_STATUS_HSE |
| | | * @arg @ref LL_RCC_SYS_CLKSOURCE_STATUS_PLL |
| | | * @arg @ref LL_RCC_SYS_CLKSOURCE_STATUS_HSI48 (*) |
| | | * |
| | | * (*) value not defined in all devices |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_GetSysClkSource(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_SWS)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Set AHB prescaler |
| | | * @rmtoll CFGR HPRE LL_RCC_SetAHBPrescaler |
| | | * @param Prescaler This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_1 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_2 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_4 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_8 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_16 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_64 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_128 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_256 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_512 |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_SetAHBPrescaler(uint32_t Prescaler) |
| | | { |
| | | MODIFY_REG(RCC->CFGR, RCC_CFGR_HPRE, Prescaler); |
| | | } |
| | | |
| | | /** |
| | | * @brief Set APB1 prescaler |
| | | * @rmtoll CFGR PPRE LL_RCC_SetAPB1Prescaler |
| | | * @param Prescaler This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_APB1_DIV_1 |
| | | * @arg @ref LL_RCC_APB1_DIV_2 |
| | | * @arg @ref LL_RCC_APB1_DIV_4 |
| | | * @arg @ref LL_RCC_APB1_DIV_8 |
| | | * @arg @ref LL_RCC_APB1_DIV_16 |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_SetAPB1Prescaler(uint32_t Prescaler) |
| | | { |
| | | MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE, Prescaler); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get AHB prescaler |
| | | * @rmtoll CFGR HPRE LL_RCC_GetAHBPrescaler |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_1 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_2 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_4 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_8 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_16 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_64 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_128 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_256 |
| | | * @arg @ref LL_RCC_SYSCLK_DIV_512 |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_GetAHBPrescaler(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_HPRE)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get APB1 prescaler |
| | | * @rmtoll CFGR PPRE LL_RCC_GetAPB1Prescaler |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_APB1_DIV_1 |
| | | * @arg @ref LL_RCC_APB1_DIV_2 |
| | | * @arg @ref LL_RCC_APB1_DIV_4 |
| | | * @arg @ref LL_RCC_APB1_DIV_8 |
| | | * @arg @ref LL_RCC_APB1_DIV_16 |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_GetAPB1Prescaler(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_PPRE)); |
| | | } |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_MCO MCO |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Configure MCOx |
| | | * @rmtoll CFGR MCO LL_RCC_ConfigMCO\n |
| | | * CFGR MCOPRE LL_RCC_ConfigMCO\n |
| | | * CFGR PLLNODIV LL_RCC_ConfigMCO |
| | | * @param MCOxSource This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_MCO1SOURCE_NOCLOCK |
| | | * @arg @ref LL_RCC_MCO1SOURCE_HSI14 |
| | | * @arg @ref LL_RCC_MCO1SOURCE_SYSCLK |
| | | * @arg @ref LL_RCC_MCO1SOURCE_HSI |
| | | * @arg @ref LL_RCC_MCO1SOURCE_HSE |
| | | * @arg @ref LL_RCC_MCO1SOURCE_LSI |
| | | * @arg @ref LL_RCC_MCO1SOURCE_LSE |
| | | * @arg @ref LL_RCC_MCO1SOURCE_HSI48 (*) |
| | | * @arg @ref LL_RCC_MCO1SOURCE_PLLCLK (*) |
| | | * @arg @ref LL_RCC_MCO1SOURCE_PLLCLK_DIV_2 |
| | | * |
| | | * (*) value not defined in all devices |
| | | * @param MCOxPrescaler This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_MCO1_DIV_1 |
| | | * @arg @ref LL_RCC_MCO1_DIV_2 (*) |
| | | * @arg @ref LL_RCC_MCO1_DIV_4 (*) |
| | | * @arg @ref LL_RCC_MCO1_DIV_8 (*) |
| | | * @arg @ref LL_RCC_MCO1_DIV_16 (*) |
| | | * @arg @ref LL_RCC_MCO1_DIV_32 (*) |
| | | * @arg @ref LL_RCC_MCO1_DIV_64 (*) |
| | | * @arg @ref LL_RCC_MCO1_DIV_128 (*) |
| | | * |
| | | * (*) value not defined in all devices |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ConfigMCO(uint32_t MCOxSource, uint32_t MCOxPrescaler) |
| | | { |
| | | #if defined(RCC_CFGR_MCOPRE) |
| | | #if defined(RCC_CFGR_PLLNODIV) |
| | | MODIFY_REG(RCC->CFGR, RCC_CFGR_MCOSEL | RCC_CFGR_MCOPRE | RCC_CFGR_PLLNODIV, MCOxSource | MCOxPrescaler); |
| | | #else |
| | | MODIFY_REG(RCC->CFGR, RCC_CFGR_MCOSEL | RCC_CFGR_MCOPRE, MCOxSource | MCOxPrescaler); |
| | | #endif /* RCC_CFGR_PLLNODIV */ |
| | | #else |
| | | MODIFY_REG(RCC->CFGR, RCC_CFGR_MCOSEL, MCOxSource); |
| | | #endif /* RCC_CFGR_MCOPRE */ |
| | | } |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_Peripheral_Clock_Source Peripheral Clock Source |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Configure USARTx clock source |
| | | * @rmtoll CFGR3 USART1SW LL_RCC_SetUSARTClockSource\n |
| | | * CFGR3 USART2SW LL_RCC_SetUSARTClockSource\n |
| | | * CFGR3 USART3SW LL_RCC_SetUSARTClockSource |
| | | * @param USARTxSource This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_USART1_CLKSOURCE_PCLK1 |
| | | * @arg @ref LL_RCC_USART1_CLKSOURCE_SYSCLK |
| | | * @arg @ref LL_RCC_USART1_CLKSOURCE_LSE |
| | | * @arg @ref LL_RCC_USART1_CLKSOURCE_HSI |
| | | * @arg @ref LL_RCC_USART2_CLKSOURCE_PCLK1 (*) |
| | | * @arg @ref LL_RCC_USART2_CLKSOURCE_SYSCLK (*) |
| | | * @arg @ref LL_RCC_USART2_CLKSOURCE_LSE (*) |
| | | * @arg @ref LL_RCC_USART2_CLKSOURCE_HSI (*) |
| | | * @arg @ref LL_RCC_USART3_CLKSOURCE_PCLK1 (*) |
| | | * @arg @ref LL_RCC_USART3_CLKSOURCE_SYSCLK (*) |
| | | * @arg @ref LL_RCC_USART3_CLKSOURCE_LSE (*) |
| | | * @arg @ref LL_RCC_USART3_CLKSOURCE_HSI (*) |
| | | * |
| | | * (*) value not defined in all devices. |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_SetUSARTClockSource(uint32_t USARTxSource) |
| | | { |
| | | MODIFY_REG(RCC->CFGR3, (RCC_CFGR3_USART1SW << ((USARTxSource & 0xFF000000U) >> 24U)), (USARTxSource & 0x00FFFFFFU)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Configure I2Cx clock source |
| | | * @rmtoll CFGR3 I2C1SW LL_RCC_SetI2CClockSource |
| | | * @param I2CxSource This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_I2C1_CLKSOURCE_HSI |
| | | * @arg @ref LL_RCC_I2C1_CLKSOURCE_SYSCLK |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_SetI2CClockSource(uint32_t I2CxSource) |
| | | { |
| | | MODIFY_REG(RCC->CFGR3, RCC_CFGR3_I2C1SW, I2CxSource); |
| | | } |
| | | |
| | | #if defined(CEC) |
| | | /** |
| | | * @brief Configure CEC clock source |
| | | * @rmtoll CFGR3 CECSW LL_RCC_SetCECClockSource |
| | | * @param CECxSource This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_CEC_CLKSOURCE_HSI_DIV244 |
| | | * @arg @ref LL_RCC_CEC_CLKSOURCE_LSE |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_SetCECClockSource(uint32_t CECxSource) |
| | | { |
| | | MODIFY_REG(RCC->CFGR3, RCC_CFGR3_CECSW, CECxSource); |
| | | } |
| | | #endif /* CEC */ |
| | | |
| | | #if defined(USB) |
| | | /** |
| | | * @brief Configure USB clock source |
| | | * @rmtoll CFGR3 USBSW LL_RCC_SetUSBClockSource |
| | | * @param USBxSource This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_USB_CLKSOURCE_HSI48 (*) |
| | | * @arg @ref LL_RCC_USB_CLKSOURCE_NONE (*) |
| | | * @arg @ref LL_RCC_USB_CLKSOURCE_PLL |
| | | * |
| | | * (*) value not defined in all devices. |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_SetUSBClockSource(uint32_t USBxSource) |
| | | { |
| | | MODIFY_REG(RCC->CFGR3, RCC_CFGR3_USBSW, USBxSource); |
| | | } |
| | | #endif /* USB */ |
| | | |
| | | /** |
| | | * @brief Get USARTx clock source |
| | | * @rmtoll CFGR3 USART1SW LL_RCC_GetUSARTClockSource\n |
| | | * CFGR3 USART2SW LL_RCC_GetUSARTClockSource\n |
| | | * CFGR3 USART3SW LL_RCC_GetUSARTClockSource |
| | | * @param USARTx This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_USART1_CLKSOURCE |
| | | * @arg @ref LL_RCC_USART2_CLKSOURCE (*) |
| | | * @arg @ref LL_RCC_USART3_CLKSOURCE (*) |
| | | * |
| | | * (*) value not defined in all devices. |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_USART1_CLKSOURCE_PCLK1 |
| | | * @arg @ref LL_RCC_USART1_CLKSOURCE_SYSCLK |
| | | * @arg @ref LL_RCC_USART1_CLKSOURCE_LSE |
| | | * @arg @ref LL_RCC_USART1_CLKSOURCE_HSI |
| | | * @arg @ref LL_RCC_USART2_CLKSOURCE_PCLK1 (*) |
| | | * @arg @ref LL_RCC_USART2_CLKSOURCE_SYSCLK (*) |
| | | * @arg @ref LL_RCC_USART2_CLKSOURCE_LSE (*) |
| | | * @arg @ref LL_RCC_USART2_CLKSOURCE_HSI (*) |
| | | * @arg @ref LL_RCC_USART3_CLKSOURCE_PCLK1 (*) |
| | | * @arg @ref LL_RCC_USART3_CLKSOURCE_SYSCLK (*) |
| | | * @arg @ref LL_RCC_USART3_CLKSOURCE_LSE (*) |
| | | * @arg @ref LL_RCC_USART3_CLKSOURCE_HSI (*) |
| | | * |
| | | * (*) value not defined in all devices. |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_GetUSARTClockSource(uint32_t USARTx) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CFGR3, (RCC_CFGR3_USART1SW << USARTx)) | (USARTx << 24U)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get I2Cx clock source |
| | | * @rmtoll CFGR3 I2C1SW LL_RCC_GetI2CClockSource |
| | | * @param I2Cx This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_I2C1_CLKSOURCE |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_I2C1_CLKSOURCE_HSI |
| | | * @arg @ref LL_RCC_I2C1_CLKSOURCE_SYSCLK |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_GetI2CClockSource(uint32_t I2Cx) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CFGR3, I2Cx)); |
| | | } |
| | | |
| | | #if defined(CEC) |
| | | /** |
| | | * @brief Get CEC clock source |
| | | * @rmtoll CFGR3 CECSW LL_RCC_GetCECClockSource |
| | | * @param CECx This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_CEC_CLKSOURCE |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_CEC_CLKSOURCE_HSI_DIV244 |
| | | * @arg @ref LL_RCC_CEC_CLKSOURCE_LSE |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_GetCECClockSource(uint32_t CECx) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CFGR3, CECx)); |
| | | } |
| | | #endif /* CEC */ |
| | | |
| | | #if defined(USB) |
| | | /** |
| | | * @brief Get USBx clock source |
| | | * @rmtoll CFGR3 USBSW LL_RCC_GetUSBClockSource |
| | | * @param USBx This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_USB_CLKSOURCE |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_USB_CLKSOURCE_HSI48 (*) |
| | | * @arg @ref LL_RCC_USB_CLKSOURCE_NONE (*) |
| | | * @arg @ref LL_RCC_USB_CLKSOURCE_PLL |
| | | * |
| | | * (*) value not defined in all devices. |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_GetUSBClockSource(uint32_t USBx) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CFGR3, USBx)); |
| | | } |
| | | #endif /* USB */ |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_RTC RTC |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Set RTC Clock Source |
| | | * @note Once the RTC clock source has been selected, it cannot be changed any more unless |
| | | * the Backup domain is reset. The BDRST bit can be used to reset them. |
| | | * @rmtoll BDCR RTCSEL LL_RCC_SetRTCClockSource |
| | | * @param Source This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_RTC_CLKSOURCE_NONE |
| | | * @arg @ref LL_RCC_RTC_CLKSOURCE_LSE |
| | | * @arg @ref LL_RCC_RTC_CLKSOURCE_LSI |
| | | * @arg @ref LL_RCC_RTC_CLKSOURCE_HSE_DIV32 |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_SetRTCClockSource(uint32_t Source) |
| | | { |
| | | MODIFY_REG(RCC->BDCR, RCC_BDCR_RTCSEL, Source); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get RTC Clock Source |
| | | * @rmtoll BDCR RTCSEL LL_RCC_GetRTCClockSource |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_RTC_CLKSOURCE_NONE |
| | | * @arg @ref LL_RCC_RTC_CLKSOURCE_LSE |
| | | * @arg @ref LL_RCC_RTC_CLKSOURCE_LSI |
| | | * @arg @ref LL_RCC_RTC_CLKSOURCE_HSE_DIV32 |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_GetRTCClockSource(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->BDCR, RCC_BDCR_RTCSEL)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Enable RTC |
| | | * @rmtoll BDCR RTCEN LL_RCC_EnableRTC |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_EnableRTC(void) |
| | | { |
| | | SET_BIT(RCC->BDCR, RCC_BDCR_RTCEN); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable RTC |
| | | * @rmtoll BDCR RTCEN LL_RCC_DisableRTC |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_DisableRTC(void) |
| | | { |
| | | CLEAR_BIT(RCC->BDCR, RCC_BDCR_RTCEN); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if RTC has been enabled or not |
| | | * @rmtoll BDCR RTCEN LL_RCC_IsEnabledRTC |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsEnabledRTC(void) |
| | | { |
| | | return (READ_BIT(RCC->BDCR, RCC_BDCR_RTCEN) == (RCC_BDCR_RTCEN)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Force the Backup domain reset |
| | | * @rmtoll BDCR BDRST LL_RCC_ForceBackupDomainReset |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ForceBackupDomainReset(void) |
| | | { |
| | | SET_BIT(RCC->BDCR, RCC_BDCR_BDRST); |
| | | } |
| | | |
| | | /** |
| | | * @brief Release the Backup domain reset |
| | | * @rmtoll BDCR BDRST LL_RCC_ReleaseBackupDomainReset |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ReleaseBackupDomainReset(void) |
| | | { |
| | | CLEAR_BIT(RCC->BDCR, RCC_BDCR_BDRST); |
| | | } |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_PLL PLL |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Enable PLL |
| | | * @rmtoll CR PLLON LL_RCC_PLL_Enable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_PLL_Enable(void) |
| | | { |
| | | SET_BIT(RCC->CR, RCC_CR_PLLON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable PLL |
| | | * @note Cannot be disabled if the PLL clock is used as the system clock |
| | | * @rmtoll CR PLLON LL_RCC_PLL_Disable |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_PLL_Disable(void) |
| | | { |
| | | CLEAR_BIT(RCC->CR, RCC_CR_PLLON); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if PLL Ready |
| | | * @rmtoll CR PLLRDY LL_RCC_PLL_IsReady |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_PLL_IsReady(void) |
| | | { |
| | | return (READ_BIT(RCC->CR, RCC_CR_PLLRDY) == (RCC_CR_PLLRDY)); |
| | | } |
| | | |
| | | #if defined(RCC_PLLSRC_PREDIV1_SUPPORT) |
| | | /** |
| | | * @brief Configure PLL used for SYSCLK Domain |
| | | * @rmtoll CFGR PLLSRC LL_RCC_PLL_ConfigDomain_SYS\n |
| | | * CFGR PLLMUL LL_RCC_PLL_ConfigDomain_SYS\n |
| | | * CFGR2 PREDIV LL_RCC_PLL_ConfigDomain_SYS |
| | | * @param Source This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSI |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSI48 (*) |
| | | * |
| | | * (*) value not defined in all devices |
| | | * @param PLLMul This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_PLL_MUL_2 |
| | | * @arg @ref LL_RCC_PLL_MUL_3 |
| | | * @arg @ref LL_RCC_PLL_MUL_4 |
| | | * @arg @ref LL_RCC_PLL_MUL_5 |
| | | * @arg @ref LL_RCC_PLL_MUL_6 |
| | | * @arg @ref LL_RCC_PLL_MUL_7 |
| | | * @arg @ref LL_RCC_PLL_MUL_8 |
| | | * @arg @ref LL_RCC_PLL_MUL_9 |
| | | * @arg @ref LL_RCC_PLL_MUL_10 |
| | | * @arg @ref LL_RCC_PLL_MUL_11 |
| | | * @arg @ref LL_RCC_PLL_MUL_12 |
| | | * @arg @ref LL_RCC_PLL_MUL_13 |
| | | * @arg @ref LL_RCC_PLL_MUL_14 |
| | | * @arg @ref LL_RCC_PLL_MUL_15 |
| | | * @arg @ref LL_RCC_PLL_MUL_16 |
| | | * @param PLLDiv This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_PREDIV_DIV_1 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_2 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_3 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_4 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_5 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_6 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_7 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_8 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_9 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_10 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_11 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_12 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_13 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_14 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_15 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_16 |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_PLL_ConfigDomain_SYS(uint32_t Source, uint32_t PLLMul, uint32_t PLLDiv) |
| | | { |
| | | MODIFY_REG(RCC->CFGR, RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL, Source | PLLMul); |
| | | MODIFY_REG(RCC->CFGR2, RCC_CFGR2_PREDIV, PLLDiv); |
| | | } |
| | | |
| | | #else |
| | | |
| | | /** |
| | | * @brief Configure PLL used for SYSCLK Domain |
| | | * @rmtoll CFGR PLLSRC LL_RCC_PLL_ConfigDomain_SYS\n |
| | | * CFGR PLLMUL LL_RCC_PLL_ConfigDomain_SYS\n |
| | | * CFGR2 PREDIV LL_RCC_PLL_ConfigDomain_SYS |
| | | * @param Source This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSI_DIV_2 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_1 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_2 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_3 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_4 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_5 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_6 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_7 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_8 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_9 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_10 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_11 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_12 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_13 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_14 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_15 |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE_DIV_16 |
| | | * @param PLLMul This parameter can be one of the following values: |
| | | * @arg @ref LL_RCC_PLL_MUL_2 |
| | | * @arg @ref LL_RCC_PLL_MUL_3 |
| | | * @arg @ref LL_RCC_PLL_MUL_4 |
| | | * @arg @ref LL_RCC_PLL_MUL_5 |
| | | * @arg @ref LL_RCC_PLL_MUL_6 |
| | | * @arg @ref LL_RCC_PLL_MUL_7 |
| | | * @arg @ref LL_RCC_PLL_MUL_8 |
| | | * @arg @ref LL_RCC_PLL_MUL_9 |
| | | * @arg @ref LL_RCC_PLL_MUL_10 |
| | | * @arg @ref LL_RCC_PLL_MUL_11 |
| | | * @arg @ref LL_RCC_PLL_MUL_12 |
| | | * @arg @ref LL_RCC_PLL_MUL_13 |
| | | * @arg @ref LL_RCC_PLL_MUL_14 |
| | | * @arg @ref LL_RCC_PLL_MUL_15 |
| | | * @arg @ref LL_RCC_PLL_MUL_16 |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_PLL_ConfigDomain_SYS(uint32_t Source, uint32_t PLLMul) |
| | | { |
| | | MODIFY_REG(RCC->CFGR, RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL, (Source & RCC_CFGR_PLLSRC) | PLLMul); |
| | | MODIFY_REG(RCC->CFGR2, RCC_CFGR2_PREDIV, (Source & RCC_CFGR2_PREDIV)); |
| | | } |
| | | #endif /* RCC_PLLSRC_PREDIV1_SUPPORT */ |
| | | |
| | | /** |
| | | * @brief Get the oscillator used as PLL clock source. |
| | | * @rmtoll CFGR PLLSRC LL_RCC_PLL_GetMainSource |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSI (*) |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSI_DIV_2 (*) |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSE |
| | | * @arg @ref LL_RCC_PLLSOURCE_HSI48 (*) |
| | | * |
| | | * (*) value not defined in all devices |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_PLL_GetMainSource(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_PLLSRC)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get PLL multiplication Factor |
| | | * @rmtoll CFGR PLLMUL LL_RCC_PLL_GetMultiplicator |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_PLL_MUL_2 |
| | | * @arg @ref LL_RCC_PLL_MUL_3 |
| | | * @arg @ref LL_RCC_PLL_MUL_4 |
| | | * @arg @ref LL_RCC_PLL_MUL_5 |
| | | * @arg @ref LL_RCC_PLL_MUL_6 |
| | | * @arg @ref LL_RCC_PLL_MUL_7 |
| | | * @arg @ref LL_RCC_PLL_MUL_8 |
| | | * @arg @ref LL_RCC_PLL_MUL_9 |
| | | * @arg @ref LL_RCC_PLL_MUL_10 |
| | | * @arg @ref LL_RCC_PLL_MUL_11 |
| | | * @arg @ref LL_RCC_PLL_MUL_12 |
| | | * @arg @ref LL_RCC_PLL_MUL_13 |
| | | * @arg @ref LL_RCC_PLL_MUL_14 |
| | | * @arg @ref LL_RCC_PLL_MUL_15 |
| | | * @arg @ref LL_RCC_PLL_MUL_16 |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_PLL_GetMultiplicator(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CFGR, RCC_CFGR_PLLMUL)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Get PREDIV division factor for the main PLL |
| | | * @note They can be written only when the PLL is disabled |
| | | * @rmtoll CFGR2 PREDIV LL_RCC_PLL_GetPrediv |
| | | * @retval Returned value can be one of the following values: |
| | | * @arg @ref LL_RCC_PREDIV_DIV_1 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_2 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_3 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_4 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_5 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_6 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_7 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_8 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_9 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_10 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_11 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_12 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_13 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_14 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_15 |
| | | * @arg @ref LL_RCC_PREDIV_DIV_16 |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_PLL_GetPrediv(void) |
| | | { |
| | | return (uint32_t)(READ_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV)); |
| | | } |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_FLAG_Management FLAG Management |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Clear LSI ready interrupt flag |
| | | * @rmtoll CIR LSIRDYC LL_RCC_ClearFlag_LSIRDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ClearFlag_LSIRDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_LSIRDYC); |
| | | } |
| | | |
| | | /** |
| | | * @brief Clear LSE ready interrupt flag |
| | | * @rmtoll CIR LSERDYC LL_RCC_ClearFlag_LSERDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ClearFlag_LSERDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_LSERDYC); |
| | | } |
| | | |
| | | /** |
| | | * @brief Clear HSI ready interrupt flag |
| | | * @rmtoll CIR HSIRDYC LL_RCC_ClearFlag_HSIRDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ClearFlag_HSIRDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_HSIRDYC); |
| | | } |
| | | |
| | | /** |
| | | * @brief Clear HSE ready interrupt flag |
| | | * @rmtoll CIR HSERDYC LL_RCC_ClearFlag_HSERDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ClearFlag_HSERDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_HSERDYC); |
| | | } |
| | | |
| | | /** |
| | | * @brief Clear PLL ready interrupt flag |
| | | * @rmtoll CIR PLLRDYC LL_RCC_ClearFlag_PLLRDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ClearFlag_PLLRDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_PLLRDYC); |
| | | } |
| | | |
| | | /** |
| | | * @brief Clear HSI14 ready interrupt flag |
| | | * @rmtoll CIR HSI14RDYC LL_RCC_ClearFlag_HSI14RDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ClearFlag_HSI14RDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_HSI14RDYC); |
| | | } |
| | | |
| | | #if defined(RCC_HSI48_SUPPORT) |
| | | /** |
| | | * @brief Clear HSI48 ready interrupt flag |
| | | * @rmtoll CIR HSI48RDYC LL_RCC_ClearFlag_HSI48RDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ClearFlag_HSI48RDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_HSI48RDYC); |
| | | } |
| | | #endif /* RCC_HSI48_SUPPORT */ |
| | | |
| | | /** |
| | | * @brief Clear Clock security system interrupt flag |
| | | * @rmtoll CIR CSSC LL_RCC_ClearFlag_HSECSS |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ClearFlag_HSECSS(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_CSSC); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if LSI ready interrupt occurred or not |
| | | * @rmtoll CIR LSIRDYF LL_RCC_IsActiveFlag_LSIRDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_LSIRDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_LSIRDYF) == (RCC_CIR_LSIRDYF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if LSE ready interrupt occurred or not |
| | | * @rmtoll CIR LSERDYF LL_RCC_IsActiveFlag_LSERDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_LSERDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_LSERDYF) == (RCC_CIR_LSERDYF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if HSI ready interrupt occurred or not |
| | | * @rmtoll CIR HSIRDYF LL_RCC_IsActiveFlag_HSIRDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_HSIRDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_HSIRDYF) == (RCC_CIR_HSIRDYF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if HSE ready interrupt occurred or not |
| | | * @rmtoll CIR HSERDYF LL_RCC_IsActiveFlag_HSERDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_HSERDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_HSERDYF) == (RCC_CIR_HSERDYF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if PLL ready interrupt occurred or not |
| | | * @rmtoll CIR PLLRDYF LL_RCC_IsActiveFlag_PLLRDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_PLLRDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_PLLRDYF) == (RCC_CIR_PLLRDYF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if HSI14 ready interrupt occurred or not |
| | | * @rmtoll CIR HSI14RDYF LL_RCC_IsActiveFlag_HSI14RDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_HSI14RDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_HSI14RDYF) == (RCC_CIR_HSI14RDYF)); |
| | | } |
| | | |
| | | #if defined(RCC_HSI48_SUPPORT) |
| | | /** |
| | | * @brief Check if HSI48 ready interrupt occurred or not |
| | | * @rmtoll CIR HSI48RDYF LL_RCC_IsActiveFlag_HSI48RDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_HSI48RDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_HSI48RDYF) == (RCC_CIR_HSI48RDYF)); |
| | | } |
| | | #endif /* RCC_HSI48_SUPPORT */ |
| | | |
| | | /** |
| | | * @brief Check if Clock security system interrupt occurred or not |
| | | * @rmtoll CIR CSSF LL_RCC_IsActiveFlag_HSECSS |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_HSECSS(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_CSSF) == (RCC_CIR_CSSF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if RCC flag Independent Watchdog reset is set or not. |
| | | * @rmtoll CSR IWDGRSTF LL_RCC_IsActiveFlag_IWDGRST |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_IWDGRST(void) |
| | | { |
| | | return (READ_BIT(RCC->CSR, RCC_CSR_IWDGRSTF) == (RCC_CSR_IWDGRSTF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if RCC flag Low Power reset is set or not. |
| | | * @rmtoll CSR LPWRRSTF LL_RCC_IsActiveFlag_LPWRRST |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_LPWRRST(void) |
| | | { |
| | | return (READ_BIT(RCC->CSR, RCC_CSR_LPWRRSTF) == (RCC_CSR_LPWRRSTF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if RCC flag is set or not. |
| | | * @rmtoll CSR OBLRSTF LL_RCC_IsActiveFlag_OBLRST |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_OBLRST(void) |
| | | { |
| | | return (READ_BIT(RCC->CSR, RCC_CSR_OBLRSTF) == (RCC_CSR_OBLRSTF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if RCC flag Pin reset is set or not. |
| | | * @rmtoll CSR PINRSTF LL_RCC_IsActiveFlag_PINRST |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_PINRST(void) |
| | | { |
| | | return (READ_BIT(RCC->CSR, RCC_CSR_PINRSTF) == (RCC_CSR_PINRSTF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if RCC flag POR/PDR reset is set or not. |
| | | * @rmtoll CSR PORRSTF LL_RCC_IsActiveFlag_PORRST |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_PORRST(void) |
| | | { |
| | | return (READ_BIT(RCC->CSR, RCC_CSR_PORRSTF) == (RCC_CSR_PORRSTF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if RCC flag Software reset is set or not. |
| | | * @rmtoll CSR SFTRSTF LL_RCC_IsActiveFlag_SFTRST |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_SFTRST(void) |
| | | { |
| | | return (READ_BIT(RCC->CSR, RCC_CSR_SFTRSTF) == (RCC_CSR_SFTRSTF)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Check if RCC flag Window Watchdog reset is set or not. |
| | | * @rmtoll CSR WWDGRSTF LL_RCC_IsActiveFlag_WWDGRST |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_WWDGRST(void) |
| | | { |
| | | return (READ_BIT(RCC->CSR, RCC_CSR_WWDGRSTF) == (RCC_CSR_WWDGRSTF)); |
| | | } |
| | | |
| | | #if defined(RCC_CSR_V18PWRRSTF) |
| | | /** |
| | | * @brief Check if RCC Reset flag of the 1.8 V domain is set or not. |
| | | * @rmtoll CSR V18PWRRSTF LL_RCC_IsActiveFlag_V18PWRRST |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsActiveFlag_V18PWRRST(void) |
| | | { |
| | | return (READ_BIT(RCC->CSR, RCC_CSR_V18PWRRSTF) == (RCC_CSR_V18PWRRSTF)); |
| | | } |
| | | #endif /* RCC_CSR_V18PWRRSTF */ |
| | | |
| | | /** |
| | | * @brief Set RMVF bit to clear the reset flags. |
| | | * @rmtoll CSR RMVF LL_RCC_ClearResetFlags |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_ClearResetFlags(void) |
| | | { |
| | | SET_BIT(RCC->CSR, RCC_CSR_RMVF); |
| | | } |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_IT_Management IT Management |
| | | * @{ |
| | | */ |
| | | |
| | | /** |
| | | * @brief Enable LSI ready interrupt |
| | | * @rmtoll CIR LSIRDYIE LL_RCC_EnableIT_LSIRDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_EnableIT_LSIRDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_LSIRDYIE); |
| | | } |
| | | |
| | | /** |
| | | * @brief Enable LSE ready interrupt |
| | | * @rmtoll CIR LSERDYIE LL_RCC_EnableIT_LSERDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_EnableIT_LSERDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_LSERDYIE); |
| | | } |
| | | |
| | | /** |
| | | * @brief Enable HSI ready interrupt |
| | | * @rmtoll CIR HSIRDYIE LL_RCC_EnableIT_HSIRDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_EnableIT_HSIRDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_HSIRDYIE); |
| | | } |
| | | |
| | | /** |
| | | * @brief Enable HSE ready interrupt |
| | | * @rmtoll CIR HSERDYIE LL_RCC_EnableIT_HSERDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_EnableIT_HSERDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_HSERDYIE); |
| | | } |
| | | |
| | | /** |
| | | * @brief Enable PLL ready interrupt |
| | | * @rmtoll CIR PLLRDYIE LL_RCC_EnableIT_PLLRDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_EnableIT_PLLRDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_PLLRDYIE); |
| | | } |
| | | |
| | | /** |
| | | * @brief Enable HSI14 ready interrupt |
| | | * @rmtoll CIR HSI14RDYIE LL_RCC_EnableIT_HSI14RDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_EnableIT_HSI14RDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_HSI14RDYIE); |
| | | } |
| | | |
| | | #if defined(RCC_HSI48_SUPPORT) |
| | | /** |
| | | * @brief Enable HSI48 ready interrupt |
| | | * @rmtoll CIR HSI48RDYIE LL_RCC_EnableIT_HSI48RDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_EnableIT_HSI48RDY(void) |
| | | { |
| | | SET_BIT(RCC->CIR, RCC_CIR_HSI48RDYIE); |
| | | } |
| | | #endif /* RCC_HSI48_SUPPORT */ |
| | | |
| | | /** |
| | | * @brief Disable LSI ready interrupt |
| | | * @rmtoll CIR LSIRDYIE LL_RCC_DisableIT_LSIRDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_DisableIT_LSIRDY(void) |
| | | { |
| | | CLEAR_BIT(RCC->CIR, RCC_CIR_LSIRDYIE); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable LSE ready interrupt |
| | | * @rmtoll CIR LSERDYIE LL_RCC_DisableIT_LSERDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_DisableIT_LSERDY(void) |
| | | { |
| | | CLEAR_BIT(RCC->CIR, RCC_CIR_LSERDYIE); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable HSI ready interrupt |
| | | * @rmtoll CIR HSIRDYIE LL_RCC_DisableIT_HSIRDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_DisableIT_HSIRDY(void) |
| | | { |
| | | CLEAR_BIT(RCC->CIR, RCC_CIR_HSIRDYIE); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable HSE ready interrupt |
| | | * @rmtoll CIR HSERDYIE LL_RCC_DisableIT_HSERDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_DisableIT_HSERDY(void) |
| | | { |
| | | CLEAR_BIT(RCC->CIR, RCC_CIR_HSERDYIE); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable PLL ready interrupt |
| | | * @rmtoll CIR PLLRDYIE LL_RCC_DisableIT_PLLRDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_DisableIT_PLLRDY(void) |
| | | { |
| | | CLEAR_BIT(RCC->CIR, RCC_CIR_PLLRDYIE); |
| | | } |
| | | |
| | | /** |
| | | * @brief Disable HSI14 ready interrupt |
| | | * @rmtoll CIR HSI14RDYIE LL_RCC_DisableIT_HSI14RDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_DisableIT_HSI14RDY(void) |
| | | { |
| | | CLEAR_BIT(RCC->CIR, RCC_CIR_HSI14RDYIE); |
| | | } |
| | | |
| | | #if defined(RCC_HSI48_SUPPORT) |
| | | /** |
| | | * @brief Disable HSI48 ready interrupt |
| | | * @rmtoll CIR HSI48RDYIE LL_RCC_DisableIT_HSI48RDY |
| | | * @retval None |
| | | */ |
| | | __STATIC_INLINE void LL_RCC_DisableIT_HSI48RDY(void) |
| | | { |
| | | CLEAR_BIT(RCC->CIR, RCC_CIR_HSI48RDYIE); |
| | | } |
| | | #endif /* RCC_HSI48_SUPPORT */ |
| | | |
| | | /** |
| | | * @brief Checks if LSI ready interrupt source is enabled or disabled. |
| | | * @rmtoll CIR LSIRDYIE LL_RCC_IsEnabledIT_LSIRDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsEnabledIT_LSIRDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_LSIRDYIE) == (RCC_CIR_LSIRDYIE)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Checks if LSE ready interrupt source is enabled or disabled. |
| | | * @rmtoll CIR LSERDYIE LL_RCC_IsEnabledIT_LSERDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsEnabledIT_LSERDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_LSERDYIE) == (RCC_CIR_LSERDYIE)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Checks if HSI ready interrupt source is enabled or disabled. |
| | | * @rmtoll CIR HSIRDYIE LL_RCC_IsEnabledIT_HSIRDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsEnabledIT_HSIRDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_HSIRDYIE) == (RCC_CIR_HSIRDYIE)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Checks if HSE ready interrupt source is enabled or disabled. |
| | | * @rmtoll CIR HSERDYIE LL_RCC_IsEnabledIT_HSERDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsEnabledIT_HSERDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_HSERDYIE) == (RCC_CIR_HSERDYIE)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Checks if PLL ready interrupt source is enabled or disabled. |
| | | * @rmtoll CIR PLLRDYIE LL_RCC_IsEnabledIT_PLLRDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsEnabledIT_PLLRDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_PLLRDYIE) == (RCC_CIR_PLLRDYIE)); |
| | | } |
| | | |
| | | /** |
| | | * @brief Checks if HSI14 ready interrupt source is enabled or disabled. |
| | | * @rmtoll CIR HSI14RDYIE LL_RCC_IsEnabledIT_HSI14RDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsEnabledIT_HSI14RDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_HSI14RDYIE) == (RCC_CIR_HSI14RDYIE)); |
| | | } |
| | | |
| | | #if defined(RCC_HSI48_SUPPORT) |
| | | /** |
| | | * @brief Checks if HSI48 ready interrupt source is enabled or disabled. |
| | | * @rmtoll CIR HSI48RDYIE LL_RCC_IsEnabledIT_HSI48RDY |
| | | * @retval State of bit (1 or 0). |
| | | */ |
| | | __STATIC_INLINE uint32_t LL_RCC_IsEnabledIT_HSI48RDY(void) |
| | | { |
| | | return (READ_BIT(RCC->CIR, RCC_CIR_HSI48RDYIE) == (RCC_CIR_HSI48RDYIE)); |
| | | } |
| | | #endif /* RCC_HSI48_SUPPORT */ |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | #if defined(USE_FULL_LL_DRIVER) |
| | | /** @defgroup RCC_LL_EF_Init De-initialization function |
| | | * @{ |
| | | */ |
| | | ErrorStatus LL_RCC_DeInit(void); |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** @defgroup RCC_LL_EF_Get_Freq Get system and peripherals clocks frequency functions |
| | | * @{ |
| | | */ |
| | | void LL_RCC_GetSystemClocksFreq(LL_RCC_ClocksTypeDef *RCC_Clocks); |
| | | uint32_t LL_RCC_GetUSARTClockFreq(uint32_t USARTxSource); |
| | | uint32_t LL_RCC_GetI2CClockFreq(uint32_t I2CxSource); |
| | | #if defined(USB_OTG_FS) || defined(USB) |
| | | uint32_t LL_RCC_GetUSBClockFreq(uint32_t USBxSource); |
| | | #endif /* USB_OTG_FS || USB */ |
| | | #if defined(CEC) |
| | | uint32_t LL_RCC_GetCECClockFreq(uint32_t CECxSource); |
| | | #endif /* CEC */ |
| | | /** |
| | | * @} |
| | | */ |
| | | #endif /* USE_FULL_LL_DRIVER */ |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | #endif /* RCC */ |
| | | |
| | | /** |
| | | * @} |
| | | */ |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | | #endif |
| | | |
| | | #endif /* __STM32F0xx_LL_RCC_H */ |
| | | |
| | | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
| | |
| | | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
| | | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
| | | |
| | | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
| | | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_ACR_LATENCY) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | |
| | | LL_USART_Enable(USART2); |
| | | } |
| | | |
| | | /* USART3 init function */ |
| | | void MX_USART3_UART_Init(void) |
| | | { |
| | | |
| | | |
| | | LL_USART_InitTypeDef USART_InitStruct = {0}; |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | |
| | | /* Peripheral clock enable */ |
| | | LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3); |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | |
| | | /**USART3 GPIO Configuration |
| | | PB5 ------> USART3_DE |
| | | PB3 ------> USART3_TX |
| | | PB4 ------> USART3_RX |
| | | */ |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_10|LL_GPIO_PIN_11; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_4; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | |
| | | /* USART3 interrupt Init */ |
| | | NVIC_SetPriority(USART3_6_IRQn, 0); |
| | | NVIC_EnableIRQ(USART3_6_IRQn); |
| | | |
| | | USART_InitStruct.BaudRate = 230400; |
| | | USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; |
| | | USART_InitStruct.StopBits = LL_USART_STOPBITS_1; |
| | | USART_InitStruct.Parity = LL_USART_PARITY_NONE; |
| | | USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; |
| | | USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; |
| | | USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_8; |
| | | LL_USART_Init(USART3, &USART_InitStruct); |
| | | |
| | | /* |
| | | LL_USART_EnableDEMode(USART3); |
| | | LL_USART_SetDESignalPolarity(USART3, LL_USART_DE_POLARITY_LOW); |
| | | // LL_USART_SetDESignalPolarity(USART3, LL_USART_DE_POLARITY_HIGH); |
| | | LL_USART_SetDEAssertionTime(USART3, 3); |
| | | LL_USART_SetDEDeassertionTime(USART3, 3); |
| | | LL_USART_EnableOneBitSamp(USART3); |
| | | // LL_USART_EnableAutoBaudRate(USART3); |
| | | // LL_USART_SetAutoBaudRateMode(USART3, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
| | | */ |
| | | LL_USART_DisableOverrunDetect(USART3); |
| | | LL_USART_ConfigAsyncMode(USART3); |
| | | LL_USART_Enable(USART3); |
| | | } |
| | | |
| | | |
| | | /* USART5 init function */ |
| | | void MX_USART5_UART_Init(void) |
| | |
| | | NVIC_SetPriority(USART3_6_IRQn, 0); |
| | | NVIC_EnableIRQ(USART3_6_IRQn); |
| | | |
| | | USART_InitStruct.BaudRate = 57600; |
| | | USART_InitStruct.BaudRate = 230400; |
| | | USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; |
| | | USART_InitStruct.StopBits = LL_USART_STOPBITS_1; |
| | | USART_InitStruct.Parity = LL_USART_PARITY_NONE; |
| | |
| | | #include "BoardType.h" |
| | | #include "KMachine.h" |
| | | #include "KBus.h" |
| | | |
| | | #define APP_ADDR 0x08001000 //åºç¨ç¨åºé¦å°åå®ä¹ |
| | | #define APPINFOBLOCK_ADDR (APP_ADDR + 0x100) //ç¨åºä¿¡æ¯å å°å |
| | | #define INFOBLOCK_ADDR (APP_ADDR + 0x1000) //ä¿¡æ¯å å°å |
| | | |
| | | |
| | | #define APP_START_ADDR IROM1_START_ADDRESS |
| | | extern int Region$$Table$$Limit; |
| | | |
| | | const stAppInfoBlock AppInfoBlock __attribute__((at(APPINFOBLOCK_ADDR))) = |
| | | { |
| | | 0xAA55, // StartSign |
| | | 0x0301, // BlockType |
| | | sizeof(stAppInfoBlock), //BlockSize |
| | | 0, // Pad, |
| | | 0x0109, //AppVer |
| | | (BOARD_TYPE<<8) + BOARD_VER, //AppDevice; |
| | | 0x1000, //AppSize; |
| | | 0x0C00, //AppDataSize; |
| | | APP_ADDR, //nAppStartAddr |
| | | (int)&Region$$Table$$Limit, //nBtldr_NewAppInfoAddr |
| | | 0x08009000, //nBtldr_NewAppAddr |
| | | 0xCCCC, //crc16; |
| | | 0xAA55 //EndSign; |
| | | |
| | | }; |
| | | |
| | | |
| | | |
| | | const stKMInfoBlock KMInfoBlock __attribute__((at(INFOBLOCK_ADDR))) = |
| | | { |
| | | // sizeof(stKMInfoBlock), |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceType BOARD_VER, //nDevieVer |
| | | 0x0109, //ProgVer |
| | | 0x0102, //KLinkVer |
| | | KBUS_VER, //KBusVer |
| | | // 0x0100, //KNetVer |
| | | // 0x0100, //KWLVer |
| | | |
| | | 4, //nCapacity1 ?K |
| | | 1, //nCapacity2 ?k |
| | | |
| | | DINPUT, //nDInput; |
| | | DOUTPUT, //nDOutput |
| | | |
| | | 0, //nAInput |
| | | 0, //nAOutput |
| | | 0, //nHInput |
| | | 0, //nHOutput |
| | | 0, //nExt1; |
| | | 0, //nExt2; |
| | | 0, //nLogSize; |
| | | 0, //nPorts; |
| | | 0, //nManSize; |
| | | 0, //nAbility; |
| | | 6, //nSwitchBits; |
| | | }; |
| | | |
| | | const stDeviceInfo MyDeviceInfo={ |
| | | |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | 0x0109, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | }; |
| | | |
| | | const stExDeviceInfo MyExDeviceInfo ={ |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | 0x0109, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | |
| | | }; |
| | | |
| | | |
New file |
| | |
| | | #include "LindarPos.h" |
| | | #include "OrdLidar.h" |
| | | #include "KMachine.h" |
| | | |
| | | int ProcessPos(int nLidarIdx, stLidarDot * pLindarDots, int nCount) |
| | | { |
| | | int nValidCount0 = nCount; |
| | | int minDisIndex = 0; int minDistance = 55555; |
| | | int minZ = 10000; int minZIndex= -1; |
| | | int planeCount =0; // æåºå±å¹³é¢çç¹æ°éã |
| | | int firstmin = 1000,firstmax = -1000; |
| | | int secondmin = 1000, secondmax = -1000; |
| | | |
| | | int firstCount=0; int secondCount =0; int midCount =0; |
| | | results[0]=0; |
| | | // æ± minZ å minDistance; |
| | | for (int j = 0;j < nValidCount0;j++){ |
| | | if (pLindarDots[j].distance < 50) continue; // skip too small points; |
| | | if (pLindarDots[j].y < 40) continue; // skip too small points; |
| | | if (pLindarDots[j].x < -200 || pLindarDots[j].x > 500) continue; |
| | | if (pLindarDots[j].y < minZ) { minZIndex = j; minZ = pLindarDots[j].y; } |
| | | if (pLindarDots[j].distance < minDistance) { |
| | | minDisIndex = j; minDistance = pLindarDots[j].distance; |
| | | } |
| | | } |
| | | |
| | | for (int j = nValidCount0 -1 ;j>=0 && minZ < 500;j--) |
| | | { |
| | | int x = pLindarDots[j].x; |
| | | int y = pLindarDots[j].y; |
| | | int d = pLindarDots[j].distance; |
| | | |
| | | if (d < 50) continue; // skip too small points; |
| | | if (y < 40) continue; // skip too small points; |
| | | if (x < -200 || x > 500) continue; |
| | | // åªæ¥æ¾ åºé¨ 50mm æ°æ® |
| | | |
| | | //results[0]++; |
| | | if (y >= minZ + 50) { |
| | | if ((firstCount >0 && secondCount == 0) |
| | | || (secondCount >0 && firstCount == 0)) { |
| | | midCount++; |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | if (planeCount < 40) { |
| | | KMem.WDT[40+2 * planeCount]=d; |
| | | KMem.WDT[40+2 * planeCount +1 ]=x; |
| | | } |
| | | |
| | | planeCount++; |
| | | if (x > -200 && x < 500) |
| | | { |
| | | if (x < firstmin) firstmin = x; |
| | | if (x > secondmax) secondmax = x; |
| | | } |
| | | // å沿 |
| | | if (x > -200 && x < 100 && y < minZ + 40 ) |
| | | { |
| | | if (x > firstmax) firstmax = x; |
| | | firstCount++; |
| | | } |
| | | // å沿 |
| | | if (x > 200 && x < 500 && y < minZ + 40 ) |
| | | { |
| | | if (x < secondmin) secondmin = x; |
| | | secondCount ++; |
| | | } |
| | | |
| | | } |
| | | results[0]=planeCount; |
| | | results[1]=firstCount; |
| | | results[2]=midCount; |
| | | results[3]=secondCount; |
| | | |
| | | results[4]=firstmin; |
| | | results[5]=firstmax; |
| | | results[6]=secondmin; |
| | | results[7]=secondmax; |
| | | int avg=0; |
| | | if (firstCount > 0 && secondCount > 0 && midCount > 0 ){ |
| | | avg = (secondmin + firstmax) / 2; |
| | | }else if (planeCount>10) { |
| | | avg = (firstmin + secondmax) /2; |
| | | } |
| | | |
| | | nPosX = (nPosX *3 + avg) /4; |
| | | if (minZ < 9999) nPosZ1 = (minZ + nPosZ1 * 3)/4; |
| | | return 0; |
| | | |
| | | |
| | | |
| | | } |
New file |
| | |
| | | #include "OrdLidar.h" |
| | | |
| | | #include "KMachine.h" |
| | | |
| | | int nPosX; |
| | | int nPosY; |
| | | int nPosZ; |
| | | |
| | | int nPosZ1,nPosZ2; |
| | | |
| | | int pCount1=0; |
| | | int pCount2=0; |
| | | |
| | | int eCount1; |
| | | int eCount2; |
| | | |
| | | int dCount1=0; |
| | | int dCount2=0; |
| | | |
| | | int vCount1=0; |
| | | int vCount2=0; |
| | | |
| | | int results[32]; |
| | | |
| | | |
| | | void Uart3SendPacket(char * str, int len); |
| | | void Uart5SendPacket(char * str, int len); |
| | | |
| | | //æ£å¼¦è¡¨ï¼0 - 360 代表 0 - 2PI,ç»æ0 - 1000 表示0 - 1ï¼è¡¨ä¸åªæ0 - PI/2å³1/4å¨æçæ°æ®ï¼å
¶ä»çæ°æ®ç¨å¯¹ç§°åéåå¾å°ã |
| | | const int SinTable[] = |
| | | { |
| | | 0,17,35, 52, 70, 87, 105, 122, 139, 156, 174, 191, 208, 225, 242, 259, 276, 292, |
| | | 309, 326, 342, 358, 375, 391, 407, 423, 438, 454, 469, 485, 500, 515, 530, 545, |
| | | 559, 574, 588, 602, 616, 629, 643, 656, 669, 682, 695, 707, 719, 731, 743, 755, |
| | | 766, 777, 788, 799, 809, 819, 829, 839, 848, 857, 866, 875, 883, 891, 899, 906, |
| | | 914, 921, 927, 934, 940, 946, 951, 956, 961, 966, 970, 974, 978, 982, 985, 988, |
| | | 990, 993, 995, 996, 998, 999, 999, 1000, 1000, |
| | | 1000, 999, 999, 998, 996, 995, |
| | | 993, 990, 988, 985, 982, 978, 974, 970, 966, 961, 956, 951, 946, 940, 934, 927, |
| | | 921, 914, 906, 899, 891, 883, 875, 866, 857, 848, 839, 829, 819, 809, 799, 788, |
| | | 777, 766, 755, 743, 731, 719, 707, 695, 682, 669, 656, 643, 629, 616, 602, 588, |
| | | 574, 559, 545, 530, 515, 500, 485, 469, 454, 438, 423, 407, 391, 375, 358, 342, |
| | | 326, 309, 292, 276, 259, 242, 225, 208, 191, 174, 156, 139, 122, 105, 87, 70, |
| | | 52, 35, 17, 0, -17, -35, -52, -70, -87, -105, -122, -139, -156, -174, -191, |
| | | -208, -225, -242, -259, -276, -292, -309, -326, -342, -358, -375, -391, -407, |
| | | -423, -438, -454, -469, -485, -500, -515, -530, -545, -559, -574, -588, -602, |
| | | -616, -629, -643, -656, -669, -682, -695, -707, -719, -731, -743, -755, -766, |
| | | -777, -788, -799, -809, -819, -829, -839, -848, -857, -866, -875, -883, -891, |
| | | -899, -906, -914, -921, -927, -934, -940, -946, -951, -956, -961, -966, -970, |
| | | -974, -978, -982, -985, -988, -990, -993, -995, -996, -998, -999, -999, -1000, |
| | | -1000, -1000, -999, -999, -998, -996, -995, -993, -990, -988, -985, -982, -978, |
| | | -974, -970, -966, -961, -956, -951, -946, -940, -934, -927, -921, -914, -906, |
| | | -899, -891, -883, -875, -866, -857, -848, -839, -829, -819, -809, -799, -788, |
| | | -777, -766, -755, -743, -731, -719, -707, -695, -682, -669, -656, -643, -629, |
| | | -616, -602, -588, -574, -559, -545, -530, -515, -500, -485, -469, -454, -438, |
| | | -423, -407, -391, -375, -358, -342, -326, -309, -292, -276, -259, -242, -225, |
| | | -208, -191, -174, -156, -139, -122, -105, -87, -70, -52, -35, -17 |
| | | }; |
| | | |
| | | |
| | | |
| | | char StartCMD[2] = { 0xA5,0x60 }; |
| | | char StopCMD[2] = { 0xA5,0x65 }; |
| | | |
| | | |
| | | int StartAngle; |
| | | int EndAngle; |
| | | |
| | | int OrdLidarStart(int nIdx) |
| | | { |
| | | if (nIdx == 0 || nIdx == -1 ) { |
| | | Uart3SendPacket(StartCMD,sizeof(StartCMD)); |
| | | } |
| | | if (nIdx == 1 || nIdx == -1) { |
| | | Uart5SendPacket(StartCMD,sizeof(StartCMD)); |
| | | } |
| | | return 0; |
| | | }; |
| | | |
| | | |
| | | int OrdLidarStop(int nIdx){ |
| | | if (nIdx == 0 || nIdx == -1 ) { |
| | | Uart3SendPacket(StopCMD,sizeof(StopCMD)); |
| | | } |
| | | if (nIdx == 1 || nIdx == -1) { |
| | | Uart5SendPacket(StopCMD,sizeof(StopCMD)); |
| | | } |
| | | return 0; |
| | | }; |
| | | |
| | | char startFlag0 = 0; |
| | | char startFlag1 = 0; |
| | | |
| | | #define VALID_DATA_MAX 400 |
| | | stLidarDot validData0[400]; |
| | | stLidarDot validData1[400]; |
| | | |
| | | int nValidCount0 = 0; |
| | | int nValidCount1 = 0; |
| | | |
| | | #define ORG_SUB_DEGREE 100 |
| | | #define SUB_DEGREE 64 //64 |
| | | |
| | | #define START_DEGREE 110 |
| | | #define END_DEGREE 250 |
| | | |
| | | #define MAX_DISTANCE 500 //mm |
| | | |
| | | //æ´æ°æ±SINå¼ï¼å¸¦çº¿æ§æå¼åè½ï¼ è¾å
¥0 - 360*64 为 0 - 2PI,ä¸ä¸ªå¨æ;è¾åº-1000 è³ +1000,代表-1å°+1; |
| | | int sini(int a) |
| | | { |
| | | if (a <0) {a += 360 * SUB_DEGREE;} |
| | | a = a % (360 * SUB_DEGREE); |
| | | int b; |
| | | b=a / SUB_DEGREE; |
| | | int xx = a % SUB_DEGREE; |
| | | if (b< 90 ) |
| | | { |
| | | int d1= SinTable[b ]; |
| | | int d2 =SinTable[b+1 ]; |
| | | int d; |
| | | d = ((SUB_DEGREE-xx) * d1 + xx * d2 ) / SUB_DEGREE; |
| | | |
| | | return (d); |
| | | } |
| | | else if (b<180 ) |
| | | { |
| | | int c; |
| | | c=180-b; |
| | | |
| | | int d1= SinTable[c ]; |
| | | int d2 =SinTable[c-1 ]; |
| | | int d; |
| | | d = ((SUB_DEGREE-xx) * d1 + xx * d2 ) / SUB_DEGREE; |
| | | |
| | | return (d); |
| | | } |
| | | |
| | | else if (b<270) |
| | | { |
| | | int c; |
| | | c=b-180; |
| | | int d1= SinTable[c ]; |
| | | int d2 =SinTable[c+1 ]; |
| | | int d; |
| | | d = ((SUB_DEGREE-xx) * d1 + xx * d2 ) / SUB_DEGREE; |
| | | |
| | | return (-d); |
| | | } |
| | | else |
| | | { |
| | | int c; |
| | | c=360 -b; |
| | | int d1= SinTable[c ]; |
| | | int d2 =SinTable[c-1 ]; |
| | | int d; |
| | | d = ((SUB_DEGREE-xx) * d1 + xx * d2 ) / SUB_DEGREE; |
| | | |
| | | return (-d); |
| | | } |
| | | |
| | | // return a; |
| | | } |
| | | |
| | | int cosi(int a) |
| | | { |
| | | return sini(a+90*SUB_DEGREE); |
| | | } |
| | | |
| | | int OrdLidarParsePkt(int nLidarIdx, OradarLidarFrame * pLindarPkt, int len1) |
| | | { |
| | | int iRet = 0; |
| | | if (pLindarPkt->header != 0x54) return 0; // check for start sign |
| | | int nDotNum = pLindarPkt->ver_len &0x1f; |
| | | if (len1 != nDotNum*3 +11) return -1; |
| | | if (nDotNum<2) return 0; |
| | | |
| | | int startAngle = (pLindarPkt->start_angle) * SUB_DEGREE / ORG_SUB_DEGREE; // degree * 100; |
| | | int endAngle = (pLindarPkt->end_angle ) * SUB_DEGREE / ORG_SUB_DEGREE; // degree * 100; |
| | | if (startAngle >= endAngle) {eCount1++; return 0;} |
| | | int diffAngle = (endAngle - startAngle); |
| | | int eachAngle = diffAngle / (nDotNum - 1); |
| | | |
| | | if (nLidarIdx == 0) |
| | | { |
| | | pCount1++; |
| | | for (int i = 0;i < nDotNum && i < 40 ;i++) |
| | | { |
| | | unsigned char confidence = pLindarPkt->point[i].confidence; |
| | | int angle = eachAngle * i + startAngle; // degree * 64 |
| | | dCount1++; |
| | | |
| | | if (angle < START_DEGREE * SUB_DEGREE ) startFlag0 = 1; |
| | | if (angle >= START_DEGREE * SUB_DEGREE && angle < END_DEGREE * SUB_DEGREE) // &&x>100000&&x<250000) |
| | | { |
| | | if (pLindarPkt->point[i].confidence < 30) continue; |
| | | int value = pLindarPkt->point[i].distance; // distance |
| | | |
| | | int x = value * sini(angle )/1000; // mm |
| | | int z = -value * cosi(angle )/1000; // mm |
| | | |
| | | //vectorX.push_back(x); |
| | | //vectorY.push_back(y); |
| | | validData0[nValidCount0].distance = value; |
| | | validData0[nValidCount0].x = x; |
| | | validData0[nValidCount0].y = z; |
| | | if (nValidCount0 < VALID_DATA_MAX - 1 ) nValidCount0 ++; |
| | | //vCount1++; |
| | | } |
| | | |
| | | if (angle > END_DEGREE * SUB_DEGREE) |
| | | { |
| | | if (startFlag0 == 1 && nValidCount0 > 0) |
| | | { |
| | | vCount1 = nValidCount0; |
| | | ProcessPos(0,validData0,nValidCount0); |
| | | |
| | | |
| | | } |
| | | startFlag0 = 0; |
| | | nValidCount0 = 0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (nLidarIdx == 1) |
| | | { |
| | | pCount2++; |
| | | for (int i = 0;i < nDotNum && i < 40 ;i++) |
| | | { |
| | | unsigned char confidence = pLindarPkt->point[i].confidence; |
| | | int angle = eachAngle * i + startAngle; |
| | | |
| | | dCount2++; |
| | | |
| | | if (angle < START_DEGREE * SUB_DEGREE) startFlag1 = 1; |
| | | if (angle >= START_DEGREE * SUB_DEGREE && angle < END_DEGREE * SUB_DEGREE ) // &&x>100000&&x<250000) |
| | | { |
| | | if (confidence < 30) continue; |
| | | int value = pLindarPkt->point[i].distance; // distance |
| | | |
| | | int x = value * sini(angle - 180 * SUB_DEGREE )/1000; // mm |
| | | int y = value * cosi(angle - 180 * SUB_DEGREE )/1000; // mm //vectorX.push_back(x); |
| | | //vectorY.push_back(y); |
| | | validData1[nValidCount1].distance = value; |
| | | validData1[nValidCount1].x = x; |
| | | validData1[nValidCount1].y = y; |
| | | if (nValidCount1 < VALID_DATA_MAX - 1 ) nValidCount1 ++; |
| | | //vCount2 ++; |
| | | } |
| | | |
| | | if (angle > END_DEGREE * SUB_DEGREE) |
| | | { |
| | | if (startFlag1 == 1 && nValidCount1 > 0 ) |
| | | { |
| | | vCount2 = nValidCount1; |
| | | |
| | | int minDisIndex = 0; int minDistance = 55555; |
| | | int minZ = 9999; int minZIndex= -1; |
| | | int planeCount =0; |
| | | int firstmin =1000, firstmax = -1000; |
| | | int secondmin = 1000, secondmax = -1000; |
| | | |
| | | int firstCount=0; int secondCount =0; int midCount =0; |
| | | |
| | | // æ± minZ å minDistance; |
| | | for (int j = 0;j < nValidCount1;j++){ |
| | | if (validData1[j].distance < 50) continue; // skip too small points; |
| | | if (validData1[j].y < 40) continue; // skip too small points; |
| | | if (validData1[j].x < -200 || validData1[j].x > 500) continue; |
| | | if (validData1[j].y < minZ) { minZIndex = j; minZ = validData1[j].y; } |
| | | if (validData1[j].distance < minDistance) { |
| | | minDisIndex = j; minDistance = validData1[j].distance; |
| | | } |
| | | } |
| | | |
| | | for (int j = 0;j < nValidCount1 && minZ<500;j++) |
| | | { |
| | | int x = validData1[j].x; |
| | | int y = validData1[j].y; |
| | | int d = validData1[j].distance; |
| | | |
| | | if (d < 50) continue; // skip too small points; |
| | | if (y < 40) continue; // skip too small points; |
| | | if (x < -200 || x > 500) continue; |
| | | |
| | | // åªæ¥æ¾ åºé¨ 50mm æ°æ® |
| | | |
| | | if (y > minZ + 50) { |
| | | if ((firstCount >0 && secondCount ==0) |
| | | || (secondCount >0 && firstCount ==0)) { |
| | | midCount++; |
| | | } |
| | | continue; |
| | | } |
| | | planeCount++; |
| | | if (x > -200 && x < 500) |
| | | { |
| | | if (x < firstmin) firstmin = x; |
| | | if (x > secondmax) secondmax = x; |
| | | } |
| | | |
| | | // å沿 |
| | | if (x > -200 && x < 100) |
| | | { |
| | | if (validData1[j].x > firstmax) firstmax =x; |
| | | firstCount++; |
| | | } |
| | | // å沿 |
| | | if (x > 200 && x < 500 ) |
| | | { |
| | | if (x < secondmin) secondmin = x; |
| | | secondCount++; |
| | | } |
| | | |
| | | } |
| | | int avg=0; |
| | | if (firstCount > 0 && secondCount > 0 && midCount > 0 ){ |
| | | avg = (secondmin + firstmax) / 2; |
| | | }else if (planeCount>10) { |
| | | avg = (firstmin + secondmax) /2; |
| | | } |
| | | |
| | | nPosY = (nPosY *3 + avg) /4; |
| | | if (minZ < 9999) { |
| | | nPosZ2 = (minZ + nPosZ2 *3)/4; |
| | | } else { |
| | | // results[4]= nValidCount1; |
| | | // results[5]= minDistance; |
| | | |
| | | } |
| | | // nPosY = validData1[minDisIndex].x /1000; |
| | | // nPosZ2 = validData1[minDisIndex].x /1000; |
| | | // nPosZ2 = midcount; |
| | | } |
| | | startFlag1 = 0; |
| | | nValidCount1 = 0; |
| | | } |
| | | } |
| | | } |
| | | nPosZ = ((nPosZ1 + nPosZ2) + nPosZ *2)/4; |
| | | |
| | | // nPosX = pCount1; |
| | | // nPosY = pCount2; |
| | | return iRet; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | #include "SLP.h" |
| | | |
| | | void SLPSendPacket(char * buf, uchar len1); |
| | | uchar bSLPMaster; |
| | | uchar nStation; |
| | | uchar SLPinputB; |
| | | uchar SLPoutputB; |
| | | uchar nCurStation; |
| | | uchar inputBuf[5]; |
| | | uchar outputBuf[5]; |
| | | //void SLPSendPacket(char * buf, uchar len1); |
| | | |
| | | uchar SendBuf[8]; |
| | | |
| | | uchar SLPMasterRecved; //主æºæ¶å°åæºåå¤ |
| | | unsigned int SLPSlaveCountOut; |
| | | |
| | | unsigned int SLPLostPkt=0; // 丢å
æ°é |
| | | |
| | | uchar SLPOKSign; |
| | | uchar SLPErrSign; |
| | | |
| | | uchar SLPBCC(char * pBuf, uchar len1) |
| | | uchar SLPBCC(unsigned char * pBuf, uchar len1) |
| | | { |
| | | uchar i; |
| | | uchar BCC=0; |
| | |
| | | return BCC; |
| | | } |
| | | |
| | | void SLPparsePacket(char * pRecvBuf, uchar len1) |
| | | void SLPInit(stSLPDef * pSLP, SLPSendPktDef pFunc1) |
| | | { |
| | | pSLP->SLPLostPkt = 0; |
| | | pSLP->nCount = 0; |
| | | pSLP->SLPSendPktFunc = pFunc1; |
| | | |
| | | } |
| | | |
| | | void SLPSetCallBack(stSLPDef * pSLP, SLPSendPktDef pFunc1) |
| | | { |
| | | pSLP->SLPSendPktFunc = pFunc1; |
| | | } |
| | | |
| | | void SLPparsePacket(stSLPDef * pSLP, unsigned char * pRecvBuf, uchar len1) |
| | | { |
| | | |
| | | stSLPPacket * pPacket = (stSLPPacket *)pRecvBuf; |
| | | if (len1 != sizeof(stSLPPacket)) return; |
| | | // if (pPacket->ED != EDsign) return; |
| | | if (pPacket->BCC != SLPBCC(pRecvBuf,len1-1)) return; |
| | | if (bSLPMaster) //master |
| | | if (pSLP->bSLPMaster) //master |
| | | { |
| | | if (pPacket->ST ==ST_S) |
| | | { |
| | | //check |
| | | if (pPacket->Dst == nCurStation) { |
| | | SLPMasterRecved=1; |
| | | SLPLostPkt=0; |
| | | inputBuf[nCurStation] = pPacket->Data; |
| | | if (pPacket->Dst == pSLP->nCurStation) { |
| | | pSLP->SLPMasterRecved=1; |
| | | pSLP->SLPLostPkt=0; |
| | | pSLP->inputBuf[pSLP->nCurStation] = pPacket->Data; |
| | | } |
| | | } |
| | | // SLPoutputB = (inputBuf[1] &0x0f) | ((inputBuf[2] &0x0f) << 4); |
| | | SLPoutputB = inputBuf[1]; |
| | | pSLP->SLPoutputB = pSLP->inputBuf[1]; |
| | | }else |
| | | { //slave |
| | | if (pPacket->ST==ST_M) |
| | | { |
| | | //check |
| | | stSLPPacket * pRplyPkt = (stSLPPacket *)SendBuf; |
| | | if (pPacket->Dst == nStation) { |
| | | SLPoutputB = pPacket->Data; |
| | | SLPSlaveCountOut=0; |
| | | stSLPPacket * pRplyPkt = (stSLPPacket *)pSLP->SendBuf; |
| | | if (pPacket->Dst == pSLP->nStation) { |
| | | pSLP->SLPoutputB = pPacket->Data; |
| | | pSLP->SLPSlaveCountOut=0; |
| | | |
| | | pRplyPkt->ST = ST_S; |
| | | pRplyPkt->Dst = nStation; |
| | | pRplyPkt->Data = SLPinputB; |
| | | pRplyPkt->BCC = SLPBCC(SendBuf, sizeof(stSLPPacket)-1); |
| | | pRplyPkt->Dst = pSLP->nStation; |
| | | pRplyPkt->Data = pSLP->SLPinputB; |
| | | pRplyPkt->BCC = SLPBCC(pSLP->SendBuf, sizeof(stSLPPacket)-1); |
| | | // pRplyPkt->ED = EDsign; |
| | | |
| | | SLPSendPacket(SendBuf,sizeof(stSLPPacket)); |
| | | pSLP->SLPSendPktFunc(pSLP->SendBuf,sizeof(stSLPPacket)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | void SLPMasterSendPacket(void) |
| | | void SLPMasterSendPacket(stSLPDef * pSLP) |
| | | { |
| | | |
| | | stSLPPacket * pReqPkt = (stSLPPacket *)SendBuf; |
| | | outputBuf[1]=SLPinputB ;//&0xf; |
| | | stSLPPacket * pReqPkt = (stSLPPacket *)pSLP->SendBuf; |
| | | pSLP->outputBuf[1]=pSLP->SLPinputB ;//&0xf; |
| | | // outputBuf[2] = (SLPinputB & 0xf0) >> 4; |
| | | pReqPkt->ST = ST_M; |
| | | pReqPkt->Dst = nCurStation; |
| | | pReqPkt->Data = outputBuf[nCurStation]; ; |
| | | pReqPkt->BCC = SLPBCC(SendBuf, sizeof(stSLPPacket)-1); |
| | | pReqPkt->Dst = pSLP->nCurStation; |
| | | pReqPkt->Data = pSLP->outputBuf[pSLP->nCurStation]; ; |
| | | pReqPkt->BCC = SLPBCC(pSLP->SendBuf, sizeof(stSLPPacket)-1); |
| | | // pReqPkt->ED = EDsign; |
| | | |
| | | SLPSendPacket(SendBuf,sizeof(stSLPPacket)); |
| | | pSLP->SLPSendPktFunc(pSLP->SendBuf,sizeof(stSLPPacket)); |
| | | } |
| | | void SLPProcess(void) |
| | | |
| | | void SLPProcess(stSLPDef * pSLP) |
| | | { |
| | | static int nCount =0; |
| | | if (bSLPMaster) //master |
| | | if (pSLP->bSLPMaster) //master |
| | | { |
| | | if ( (nCount & 0x3f) == 0 ) |
| | | if ( (pSLP->nCount & 0x7f) == 0 ) |
| | | { //time up |
| | | if (SLPMasterRecved) { |
| | | if (pSLP->SLPMasterRecved) { |
| | | // SLPMasterRecved=0; |
| | | SLPOKSign = 1; |
| | | if (SLPErrSign) SLPErrSign--; |
| | | pSLP->SLPOKSign = 1; |
| | | if (pSLP->SLPErrSign) pSLP->SLPErrSign--; |
| | | |
| | | }else { |
| | | SLPLostPkt++; |
| | | if (SLPLostPkt > 10) { |
| | | SLPErrSign=20; |
| | | SLPOKSign = 0; |
| | | pSLP->SLPLostPkt++; |
| | | if (pSLP->SLPLostPkt > 10) { |
| | | pSLP->SLPErrSign=20; |
| | | pSLP->SLPOKSign = 0; |
| | | } |
| | | } |
| | | if (nStation >0) { |
| | | nCurStation++; |
| | | if (nCurStation > nStation) { |
| | | nCurStation =1; |
| | | if (pSLP->nStation >0) { |
| | | pSLP->nCurStation++; |
| | | if (pSLP->nCurStation > pSLP->nStation) { |
| | | pSLP->nCurStation =1; |
| | | } |
| | | SLPMasterRecved=0; |
| | | SLPMasterSendPacket(); |
| | | pSLP->SLPMasterRecved=0; |
| | | SLPMasterSendPacket(pSLP); |
| | | } |
| | | } |
| | | }else |
| | | { |
| | | SLPSlaveCountOut ++; |
| | | if (SLPSlaveCountOut >200) // 20mS |
| | | pSLP->SLPSlaveCountOut ++; |
| | | if (pSLP->SLPSlaveCountOut >200) // 20mS |
| | | { |
| | | SLPErrSign=100; |
| | | pSLP->SLPErrSign=100; |
| | | }else { |
| | | if (SLPErrSign) SLPErrSign--; |
| | | if (pSLP->SLPErrSign) pSLP->SLPErrSign--; |
| | | } |
| | | } |
| | | nCount++; |
| | | pSLP->nCount++; |
| | | } |
New file |
| | |
| | | #include "YDLidar.h" |
| | | |
| | | int nPosX; |
| | | int nPosY; |
| | | int nPosZ; |
| | | |
| | | int nPosZ1,nPosZ2; |
| | | |
| | | int pCount1=0; |
| | | int pCount2=0; |
| | | |
| | | int dCount1=0; |
| | | int dCount2=0; |
| | | |
| | | int vCount1=0; |
| | | int vCount2=0; |
| | | |
| | | |
| | | void Uart3SendPacket(char * str, int len); |
| | | void Uart5SendPacket(char * str, int len); |
| | | |
| | | //æ£å¼¦è¡¨ï¼0 - 360 代表 0 - 2PI,ç»æ0 - 1000 表示0 - 1ï¼è¡¨ä¸åªæ0 - PI/2å³1/4å¨æçæ°æ®ï¼å
¶ä»çæ°æ®ç¨å¯¹ç§°åéåå¾å°ã |
| | | const int SinTable[] = |
| | | { |
| | | 0,17,35, 52, 70, 87, 105, 122, 139, 156, 174, 191, 208, 225, 242, 259, 276, 292, |
| | | 309, 326, 342, 358, 375, 391, 407, 423, 438, 454, 469, 485, 500, 515, 530, 545, |
| | | 559, 574, 588, 602, 616, 629, 643, 656, 669, 682, 695, 707, 719, 731, 743, 755, |
| | | 766, 777, 788, 799, 809, 819, 829, 839, 848, 857, 866, 875, 883, 891, 899, 906, |
| | | 914, 921, 927, 934, 940, 946, 951, 956, 961, 966, 970, 974, 978, 982, 985, 988, |
| | | 990, 993, 995, 996, 998, 999, 999, 1000, 1000, |
| | | 1000, 999, 999, 998, 996, 995, |
| | | 993, 990, 988, 985, 982, 978, 974, 970, 966, 961, 956, 951, 946, 940, 934, 927, |
| | | 921, 914, 906, 899, 891, 883, 875, 866, 857, 848, 839, 829, 819, 809, 799, 788, |
| | | 777, 766, 755, 743, 731, 719, 707, 695, 682, 669, 656, 643, 629, 616, 602, 588, |
| | | 574, 559, 545, 530, 515, 500, 485, 469, 454, 438, 423, 407, 391, 375, 358, 342, |
| | | 326, 309, 292, 276, 259, 242, 225, 208, 191, 174, 156, 139, 122, 105, 87, 70, |
| | | 52, 35, 17, 0, -17, -35, -52, -70, -87, -105, -122, -139, -156, -174, -191, |
| | | -208, -225, -242, -259, -276, -292, -309, -326, -342, -358, -375, -391, -407, |
| | | -423, -438, -454, -469, -485, -500, -515, -530, -545, -559, -574, -588, -602, |
| | | -616, -629, -643, -656, -669, -682, -695, -707, -719, -731, -743, -755, -766, |
| | | -777, -788, -799, -809, -819, -829, -839, -848, -857, -866, -875, -883, -891, |
| | | -899, -906, -914, -921, -927, -934, -940, -946, -951, -956, -961, -966, -970, |
| | | -974, -978, -982, -985, -988, -990, -993, -995, -996, -998, -999, -999, -1000, |
| | | -1000, -1000, -999, -999, -998, -996, -995, -993, -990, -988, -985, -982, -978, |
| | | -974, -970, -966, -961, -956, -951, -946, -940, -934, -927, -921, -914, -906, |
| | | -899, -891, -883, -875, -866, -857, -848, -839, -829, -819, -809, -799, -788, |
| | | -777, -766, -755, -743, -731, -719, -707, -695, -682, -669, -656, -643, -629, |
| | | -616, -602, -588, -574, -559, -545, -530, -515, -500, -485, -469, -454, -438, |
| | | -423, -407, -391, -375, -358, -342, -326, -309, -292, -276, -259, -242, -225, |
| | | -208, -191, -174, -156, -139, -122, -105, -87, -70, -52, -35, -17 |
| | | }; |
| | | const int CosTable[] = |
| | | { |
| | | 1000 ,999 ,999 ,998 ,996 ,995 ,993 ,990 ,988 ,985 ,982 ,978 ,974 ,970 ,966 ,961 |
| | | ,956 ,951 ,946 ,940 ,934 ,927 ,921 ,914 ,906 ,899 ,891 ,883 ,875 ,866 ,857 ,848 |
| | | ,839 ,829 ,819 ,809 ,799 ,788 ,777 ,766 ,755 ,743 ,731 ,719 ,707 ,695 ,682 ,669 |
| | | ,656 ,643 ,629 ,616 ,602 ,588 ,574 ,559 ,545 ,530 ,515 ,500 ,485 ,469 ,454 ,438 |
| | | ,423 ,407 ,391 ,375 ,358 ,342 ,326 ,309 ,292 ,276 ,259 ,242 ,225 ,208 ,191 ,174 |
| | | ,156 ,139 ,122 ,105 ,87 ,70 ,52 ,35 ,17 ,0 ,-17 ,-35 ,-52 ,-70 ,-87 ,-105 ,-122 |
| | | ,-139 ,-156 ,-174 ,-191 ,-208 ,-225 ,-242 ,-259 ,-276 ,-292 ,-309 ,-326 ,-342 |
| | | ,-358 ,-375 ,-391 ,-407 ,-423 ,-438 ,-454 ,-469 ,-485 ,-500 ,-515 ,-530 ,-545 |
| | | ,-559 ,-574 ,-588 ,-602 ,-616 ,-629 ,-643 ,-656 ,-669 ,-682 ,-695 ,-707 ,-719 |
| | | ,-731 ,-743 ,-755 ,-766 ,-777 ,-788 ,-799 ,-809 ,-819 ,-829 ,-839 ,-848 ,-857 |
| | | ,-866 ,-875 ,-883 ,-891 ,-899 ,-906 ,-914 ,-921 ,-927 ,-934 ,-940 ,-946 ,-951 |
| | | ,-956 ,-961 ,-966 ,-970 ,-974 ,-978 ,-982 ,-985 ,-988 ,-990 ,-993 ,-995 ,-996 |
| | | ,-998 ,-999 ,-999 ,-1000 ,-1000 ,-1000 ,-999 ,-999 ,-998 ,-996 ,-995 ,-993 ,-990 |
| | | ,-988 ,-985 ,-982 ,-978 ,-974 ,-970 ,-966 ,-961 ,-956 ,-951 ,-946 ,-940 ,-934 |
| | | ,-927 ,-921 ,-914 ,-906 ,-899 ,-891 ,-883 ,-875 ,-866 ,-857 ,-848 ,-839 ,-829 |
| | | ,-819 ,-809 ,-799 ,-788 ,-777 ,-766 ,-755 ,-743 ,-731 ,-719 ,-707 ,-695 ,-682 |
| | | ,-669 ,-656 ,-643 ,-629 ,-616 ,-602 ,-588 ,-574 ,-559 ,-545 ,-530 ,-515 ,-500 |
| | | ,-485 ,-469 ,-454 ,-438 ,-423 ,-407 ,-391 ,-375 ,-358 ,-342 ,-326 ,-309 ,-292 |
| | | ,-276 ,-259 ,-242 ,-225 ,-208 ,-191 ,-174 ,-156 ,-139 ,-122 ,-105 ,-87 ,-70 ,-52 |
| | | ,-35 ,-17 ,0 ,17 ,35 ,52 ,70 ,87 ,105 ,122 ,139 ,156 ,174 ,191 ,208 ,225 ,242 |
| | | ,259 ,276 ,292 ,309 ,326 ,342 ,358 ,375 ,391 ,407 ,423 ,438 ,454 ,469 ,485 ,500 |
| | | ,515 ,530 ,545 ,559 ,574 ,588 ,602 ,616 ,629 ,643 ,656 ,669 ,682 ,695 ,707 ,719 |
| | | ,731 ,743 ,755 ,766 ,777 ,788 ,799 ,809 ,819 ,829 ,839 ,848 ,857 ,866 ,875 ,883 |
| | | ,891 ,899 ,906 ,914 ,921 ,927 ,934 ,940 ,946 ,951 ,956 ,961 ,966 ,970 ,974 ,978 |
| | | ,982 ,985 ,988 ,990 ,993 ,995 ,996 ,998 ,999 ,999 ,1000 ,1000 |
| | | }; |
| | | |
| | | |
| | | const unsigned char sintab[256]={ //æ£å¼¦è¡¨ï¼0 - 1024代表 0 - 2PI,ç»æ0 - 255表示0 - 1ï¼è¡¨ä¸åªæ0 - PI/2å³1/4å¨æçæ°æ®ï¼å
¶ä»çæ°æ®ç¨å¯¹ç§°åéåå¾å°ã |
| | | 0, 1, 3, 4, 6, 7, 9, 10, 12, 14, 15, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 32, 34, 36, 37, 39, 40, 42, 43, 45, 46, |
| | | 48, 49, 51, 53, 54, 56, 57, 59, 60, 62, 63, 65, 66, 68, 69, 71, 72, 74, 75, 77, 78, 80, 81, 83, 84, 86, 87, 89, 90, |
| | | 92, 93, 95, 96, 97, 99, 100, 102, 103, 105, 106, 108, 109, 110, 112, 113, 115, 116, 117, 119, 120, 122, 123, 124, |
| | | 126, 127, 128, 130, 131, 132, 134, 135, 136, 138, 139, 140, 142, 143, 144, 146, 147, 148, 149, 151, 152, 153, 155, |
| | | 156, 157, 158, 159, 161, 162, 163, 164, 166, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 179, 181, 182, |
| | | 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, |
| | | 205, 206, 207, 208, 209, 210, 211, 211, 212, 213, 214, 215, 216, 217, 217, 218, 219, 220, 221, 221, 222, 223, |
| | | 224, 225, 225, 226, 227, 227, 228, 229, 230, 230, 231, 232, 232, 233, 234, 234, 235, 235, 236, 237, 237, 238, |
| | | 238, 239, 239, 240, 241, 241, 242, 242, 243, 243, 244, 244, 244, 245, 245, 246, 246, 247, 247, 247, 248, 248, |
| | | 249, 249, 249, 250, 250, 250, 251, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, |
| | | 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,// 255 |
| | | }; |
| | | |
| | | |
| | | |
| | | |
| | | char StartCMD[2] = { 0xA5,0x60 }; |
| | | char StopCMD[2] = { 0xA5,0x65 }; |
| | | |
| | | |
| | | int StartAngle; |
| | | int EndAngle; |
| | | |
| | | int YdLidarStart(int nIdx) |
| | | { |
| | | if (nIdx == 0 || nIdx == -1 ) { |
| | | Uart3SendPacket(StartCMD,sizeof(StartCMD)); |
| | | } |
| | | if (nIdx == 1 || nIdx == -1) { |
| | | Uart5SendPacket(StartCMD,sizeof(StartCMD)); |
| | | } |
| | | return 0; |
| | | }; |
| | | |
| | | |
| | | int YdLidarStop(int nIdx){ |
| | | if (nIdx == 0 || nIdx == -1 ) { |
| | | Uart3SendPacket(StopCMD,sizeof(StopCMD)); |
| | | } |
| | | if (nIdx == 1 || nIdx == -1) { |
| | | Uart5SendPacket(StopCMD,sizeof(StopCMD)); |
| | | } |
| | | return 0; |
| | | }; |
| | | |
| | | char startFlag0 = 0; |
| | | char startFlag1 = 0; |
| | | |
| | | #define VALID_DATA_MAX 200 |
| | | stLidarDot validData0[200]; |
| | | stLidarDot validData1[200]; |
| | | |
| | | int nValidCount0 = 0; |
| | | int nValidCount1 = 0; |
| | | |
| | | #define SUB_DEGREE 64 |
| | | |
| | | #define START_DEGREE 135 |
| | | #define END_DEGREE 225 |
| | | |
| | | #define MAX_DISTANCE 500 //mm |
| | | |
| | | //æ´æ°æ±SINå¼ï¼å¸¦çº¿æ§æå¼åè½ï¼ è¾å
¥0 - 360*64 为 0 - 2PI,ä¸ä¸ªå¨æ;è¾åº-1000 è³ +1000,代表-1å°+1; |
| | | int sini(int a) |
| | | { |
| | | |
| | | a = a % (360 * SUB_DEGREE); |
| | | int b; |
| | | b=a / SUB_DEGREE; |
| | | int xx = a % SUB_DEGREE; |
| | | if (b< 90 ) |
| | | { |
| | | int d1= SinTable[b ]; |
| | | int d2 =SinTable[b+1 ]; |
| | | int d; |
| | | d = ((SUB_DEGREE-xx) * d1 + xx * d2 ) / SUB_DEGREE; |
| | | |
| | | return (d); |
| | | } |
| | | else if (b<180 ) |
| | | { |
| | | int c; |
| | | c=180-b; |
| | | |
| | | int d1= SinTable[c ]; |
| | | int d2 =SinTable[c-1 ]; |
| | | int d; |
| | | d = ((SUB_DEGREE-xx) * d1 + xx * d2 ) / SUB_DEGREE; |
| | | |
| | | return (d); |
| | | } |
| | | |
| | | else if (b<270) |
| | | { |
| | | int c; |
| | | c=b-180; |
| | | int d1= SinTable[c ]; |
| | | int d2 =SinTable[c+1 ]; |
| | | int d; |
| | | d = ((SUB_DEGREE-xx) * d1 + xx * d2 ) / SUB_DEGREE; |
| | | |
| | | return (-d); |
| | | } |
| | | else |
| | | { |
| | | int c; |
| | | c=360 -b; |
| | | int d1= SinTable[c ]; |
| | | int d2 =SinTable[c-1 ]; |
| | | int d; |
| | | d = ((SUB_DEGREE-xx) * d1 + xx * d2 ) / SUB_DEGREE; |
| | | |
| | | return (-d); |
| | | } |
| | | |
| | | // return a; |
| | | } |
| | | |
| | | int cosi(int a) |
| | | { |
| | | return sini(a+90*SUB_DEGREE); |
| | | } |
| | | |
| | | int YdLidarParsePkt(int nLidarIdx, stLidarDotsPkt * pLindarPkt, int len1) |
| | | { |
| | | int iRet = 0; |
| | | if (pLindarPkt->StSign != 0x55AA) return 0; // check for start sign |
| | | if ((pLindarPkt->CT & 0x01) != 0x00) return 0; // check for CT bit0. |
| | | if (pLindarPkt->LSN<2) return 0; |
| | | |
| | | int startAngle = (pLindarPkt->FSA >> 1); // degree * 64; |
| | | int endAngle = (pLindarPkt->LSA >> 1); // degree * 64; |
| | | if (startAngle >= endAngle)return 0; |
| | | int nCount = pLindarPkt->LSN; |
| | | int diffAngle = (endAngle - startAngle); |
| | | int eachAngle = diffAngle / (nCount - 1); |
| | | |
| | | if (nLidarIdx == 0) |
| | | { |
| | | pCount1++; |
| | | for (int i = 0;i < nCount && i < 40 ;i++) |
| | | { |
| | | float intensity = pLindarPkt->LidarDotDatas[i].intensity; |
| | | int angle = eachAngle * i + startAngle; // degree * 64 |
| | | dCount1++; |
| | | |
| | | if (angle < START_DEGREE * SUB_DEGREE ) startFlag0 = 1; |
| | | if (angle > START_DEGREE * SUB_DEGREE && angle < END_DEGREE * SUB_DEGREE) // &&x>100000&&x<250000) |
| | | { |
| | | int value = (pLindarPkt->LidarDotDatas[i].s2 << 6) + (pLindarPkt->LidarDotDatas[i].s1 >> 2); // distance |
| | | |
| | | int x = value * sini(angle - 90 * SUB_DEGREE ); // uM |
| | | int y = value * cosi(angle - 90 * SUB_DEGREE ); // uM |
| | | |
| | | //vectorX.push_back(x); |
| | | //vectorY.push_back(y); |
| | | validData0[nValidCount0].distance = value; |
| | | validData0[nValidCount0].x = x; |
| | | validData0[nValidCount0].y = y; |
| | | if (nValidCount0 < 200 - 1 ) nValidCount0 ++; |
| | | vCount1++; |
| | | } |
| | | |
| | | if (angle > END_DEGREE * SUB_DEGREE) |
| | | { |
| | | if (startFlag0 == 1 && nValidCount0 > 0) |
| | | { |
| | | |
| | | int min = 1000000, max = -1000000; |
| | | int minX = 1000000; |
| | | for (int i = 0;i < nValidCount0;i++) |
| | | { |
| | | if (validData0[i].distance < 5000) continue; |
| | | |
| | | if (validData0[i].y > 0) |
| | | { |
| | | if (validData0[i].y < min) |
| | | min = validData0[i].y; |
| | | } |
| | | if (validData0[i].y < 0) |
| | | { |
| | | if (validData0[i].y > max) |
| | | max = validData0[i].y; |
| | | } |
| | | } |
| | | float avg=0; |
| | | for (int i = 0;i < nValidCount0;i++) |
| | | { |
| | | if (validData0[i].x < minX) |
| | | { |
| | | minX = validData0[i].x; |
| | | } |
| | | } |
| | | if (min != 0 && max != 0) |
| | | { |
| | | avg = (min + max) / 2000; |
| | | } |
| | | |
| | | nPosX = avg; |
| | | nPosZ1 = minX/1000; |
| | | } |
| | | startFlag0 = 0; |
| | | nValidCount0 = 0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (nLidarIdx == 1) |
| | | { |
| | | pCount2++; |
| | | for (int i = 0;i < nCount && i < 40 ;i++) |
| | | { |
| | | float intensity = pLindarPkt->LidarDotDatas[i].intensity; |
| | | int angle = eachAngle * i + startAngle; |
| | | |
| | | dCount2++; |
| | | |
| | | if (angle < START_DEGREE * SUB_DEGREE) startFlag1 = 1; |
| | | if (angle > START_DEGREE * SUB_DEGREE && angle < END_DEGREE * SUB_DEGREE ) // &&x>100000&&x<250000) |
| | | { |
| | | int value = (pLindarPkt->LidarDotDatas[i].s2 << 6) + (pLindarPkt->LidarDotDatas[i].s1 >> 2); |
| | | |
| | | int x = value * sini(angle - 90 * SUB_DEGREE ); // uM |
| | | int y = value * cosi(angle - 90 * SUB_DEGREE ); // uM //vectorX.push_back(x); |
| | | //vectorY.push_back(y); |
| | | validData1[nValidCount1].distance = value; |
| | | validData1[nValidCount1].x = x; |
| | | validData1[nValidCount1].y = y; |
| | | nValidCount1 ++; |
| | | vCount2 ++; |
| | | } |
| | | |
| | | if (angle > END_DEGREE * SUB_DEGREE) |
| | | { |
| | | if (startFlag1 == 1 && nValidCount1 > 0 ) |
| | | { |
| | | int minDisIndex = 0; |
| | | int minDistance = 99999999; |
| | | |
| | | int min = 1000000, max = -1000000; |
| | | int minX = 1000000; |
| | | for (int i = 0;i < nValidCount1;i++) |
| | | { |
| | | if (validData1[i].distance < 30) continue; // skip too small points; |
| | | |
| | | if (validData1[i].distance < minDistance) { |
| | | minDisIndex = i; |
| | | minDistance = validData1[i].distance; |
| | | } |
| | | |
| | | if (validData1[i].x < minX) |
| | | { |
| | | minX = validData1[i].x; |
| | | } |
| | | |
| | | if (validData1[i].y > 0) |
| | | { |
| | | if (validData1[i].y < min) |
| | | min = validData1[i].y; |
| | | } |
| | | if (validData1[i].y < 0) |
| | | { |
| | | if (validData1[i].y > max) |
| | | max = validData1[i].y; |
| | | } |
| | | |
| | | } |
| | | int avg=0; |
| | | int leftcount = 0; |
| | | int midcount = 0; |
| | | int rightcount =0; |
| | | for (int i = 0;i < nValidCount1;i++) |
| | | { |
| | | if (validData1[i].distance < 30) continue; // skip too small points; |
| | | // æ¾ä¸é´ç©ºæ´; |
| | | if (validData1[i].x > minX + 50000) { |
| | | // points, 50mm higher that minX; |
| | | if (leftcount>5 && rightcount <5) midcount++; |
| | | |
| | | continue; //skip |
| | | }else { |
| | | if (midcount ==0) {leftcount++;} |
| | | else {rightcount++;} |
| | | } |
| | | } |
| | | if (min != 0 && max != 0) |
| | | { |
| | | avg = (min + max) / 2000; |
| | | } |
| | | |
| | | nPosY = avg; |
| | | nPosZ1 = minX/1000; |
| | | nPosY = validData1[minDisIndex].y /1000; |
| | | // nPosZ2 = validData1[minDisIndex].x /1000; |
| | | nPosZ2 = midcount; |
| | | } |
| | | startFlag1 = 0; |
| | | nValidCount1 = 0; |
| | | } |
| | | } |
| | | } |
| | | nPosZ = (nPosZ1 + nPosZ2) /2; |
| | | |
| | | return iRet; |
| | | } |
| | | |
| | | |
| | |
| | | #endif |
| | | extern __IO uint32_t uwTick; |
| | | |
| | | unsigned char Uart5RxBuf[RX5BUFSIZE]; |
| | | unsigned char Uart5TxBuf[TX5BUFSIZE]; |
| | | unsigned char Uart3RxBuf[UART3RXBUFSIZE]; |
| | | unsigned char Uart3TxBuf[UART3TXBUFSIZE]; |
| | | stUartStat Uart3Stat={0}; |
| | | unsigned int Uart3RecvBuf1DataLen =0; |
| | | unsigned int Uart3ToSendLen =0 ; |
| | | unsigned int Uart3SentLen = 0; |
| | | |
| | | unsigned char Uart5RxBuf[UART5RXBUFSIZE]; |
| | | unsigned char Uart5TxBuf[UART5TXBUFSIZE]; |
| | | stUartStat Uart5Stat={0}; |
| | | unsigned int Uart5RecvBuf1DataLen =0; |
| | | unsigned int Uart5ToSendLen =0 ; |
| | | unsigned int Uart5SentLen = 0; |
| | | |
| | | unsigned char Uart6RxBuf[RX6BUFSIZE]; |
| | | unsigned char Uart6TxBuf[TX6BUFSIZE]; |
| | | unsigned char Uart6RxBuf[UART6RXBUFSIZE]; |
| | | unsigned char Uart6TxBuf[UART6TXBUFSIZE]; |
| | | stUartStat Uart6Stat={0}; |
| | | unsigned int Uart6RecvBuf1DataLen =0; |
| | | unsigned int Uart6ToSendLen =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() |
| | | { |
| | |
| | | bSPI1RecvDone=1; |
| | | nSPI1RecvPos=0; |
| | | bSPI1Recving=0; |
| | | |
| | | |
| | | TriggerPendSV(); |
| | | } |
| | |
| | | // ParsePacket((pKBPacket)Uart2RecvBuf1,Uart2RecvBuf1DataLen); |
| | | } |
| | | |
| | | void Uart3SendDone() |
| | | { |
| | | // Uart1Stat.TcCount++; |
| | | return; |
| | | } |
| | | |
| | | void Uart3RecvDone() |
| | | { |
| | | // Uart3Stat.IdelCount++; |
| | | // NVIC_SetPendingIRQ(PendSV_IRQn); |
| | | // SCB->ICSR=SCB_ICSR_PENDSVSET_Msk; //1<<SCB_ICSR_PENDSVSET_Pos; |
| | | |
| | | if (Uart3RecvBuf1DataLen >0) |
| | | { |
| | | Uart3Stat.bPacketRecved=1; |
| | | // SCB->ICSR=SCB_ICSR_PENDSVSET_Msk; //1<<SCB_ICSR_PENDSVSET_Pos; |
| | | // KLParsePacket(Uart1RecvBuf1,Uart1RecvBuf1DataLen); |
| | | // Uart1RecvBuf1DataLen=0; |
| | | } |
| | | } |
| | | void Uart3SendPacket(char * str, int len) |
| | | { |
| | | memcpy(Uart3TxBuf,str,len); |
| | | Uart3ToSendLen = len; |
| | | LL_USART_EnableIT_TXE(USART3); |
| | | } |
| | | |
| | | void Uart5SendDone() |
| | | { |
| | | // Uart1Stat.TcCount++; |
| | |
| | | // Uart1RecvBuf1DataLen=0; |
| | | } |
| | | } |
| | | void Uart6SendPacket(char * str, int len) |
| | | void Uart6SendPacket(unsigned char * str, int len) |
| | | { |
| | | memcpy(Uart6TxBuf,str,len); |
| | | Uart6ToSendLen = len; |
| | |
| | | LL_USART_EnableIT_TXE(USART6); |
| | | } |
| | | |
| | | void SLPSendPacket(char * str, uchar len) |
| | | void SLPSendPacket(void * str, uchar len) |
| | | { |
| | | Uart6SendPacket(str,len); |
| | | } |
| | |
| | | #include "../src/Ethernet/socket.h" |
| | | #include "../src/Ethernet/loopback.h" |
| | | #elif (BOARD_TYPE == 14) |
| | | #include "FP0.h" |
| | | #include "FPx.h" |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | #include "KWireless.h" |
| | | //#include "user.h" |
| | | //#include "../src/radio/inc/sx126x-board.h" |
| | | #endif |
| | | #include "SLP.h" |
| | | //#include "YDLidar.h" |
| | | #include "OrdLidar.h" |
| | | |
| | | /* USER CODE END Includes */ |
| | | |
| | |
| | | #define TX2BUFSIZE 64 |
| | | |
| | | |
| | | unsigned char Uart1RxBuf[128]; |
| | | unsigned char Uart1TxBuf[260]; |
| | | unsigned char Uart1RxBuf[RX1BUFSIZE]; |
| | | unsigned char Uart1TxBuf[TX1BUFSIZE]; |
| | | |
| | | unsigned char Uart2RxBuf[RX2BUFSIZE]; |
| | | unsigned char Uart2TxBuf[TX2BUFSIZE]; |
| | |
| | | unsigned char FastFlicker=0; |
| | | |
| | | unsigned int Uart1IdelTimer = 0; |
| | | #if (ENABLE_PLC) |
| | | stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; |
| | | #endif |
| | | |
| | | uint32_t us1,us2,us3,us4,us5,us6; |
| | | |
| | | stKBusDef KBus1; // |
| | | |
| | | extern stDeviceInfo MyDeviceInfo; |
| | | |
| | | unsigned char bSLPMaster =1; |
| | | unsigned char nSLPStation = 1; |
| | | |
| | | stSLPDef SLP1; |
| | | /* USER CODE END PV */ |
| | | |
| | | /* Private function prototypes -----------------------------------------------*/ |
| | |
| | | static int Count=0; |
| | | CurTickuS += 100; |
| | | nCurTick++; |
| | | nSlaveTick++; |
| | | KBus1.nSlaveTick++; |
| | | Count++; |
| | | if (Count>=10000) |
| | | { |
| | |
| | | return; |
| | | } |
| | | |
| | | void PendSvCallBack() |
| | | { |
| | | #if (BOARD_TYPE == 14) |
| | | ///* |
| | | if (bSPI1RecvDone) |
| | | { |
| | | bSPI1RecvDone=0; |
| | | FPxParsePkt(SPI1RecvBuf,nSPI1RecvLenInBuf); |
| | | } |
| | | //*/ |
| | | #endif |
| | | if (Uart2Stat.bPacketRecved) |
| | | { |
| | | KBusParsePacket(&KBus1, (pKBPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); |
| | | Uart2RecvBuf1DataLen=0; |
| | | Uart2Stat.bPacketRecved=0; |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | } |
| | | } |
| | | |
| | | void * KBusEvCallBackFunc(void * pParam, int nEvent, void *pBuf, int nLen1) |
| | | { |
| | | switch (nEvent){ |
| | | |
| | | case KBusEvNone: |
| | | break; |
| | | case KBusEvCreate: |
| | | break; |
| | | case KBusEvConnected: |
| | | break; |
| | | case KBusEvDisConnected: |
| | | break; |
| | | case KBusEvClosed: |
| | | break; |
| | | case KBusEvStateChange: |
| | | break; |
| | | case KBusEvTimeSync: |
| | | break; |
| | | case KBusEvDataUpdate: |
| | | KMem.WY[0]=KBusMem.WLY[0]; //KBus Slave |
| | | KBusMem.WLX[0]=KMem.WX[0]; |
| | | KBusMem.WLX[1]=KMem.WX[1]; |
| | | KBusMem.WLX[2]=KMem.WX[2]; |
| | | KBusMem.WLX[3]=KMem.WX[3]; |
| | | break; |
| | | case KBusEvCmdResponse: |
| | | break; |
| | | |
| | | default: |
| | | break; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | //#define RAM_START_ADDR 0x20000000 // SRAM_BASE |
| | | #define VECTOR_SIZE 46 |
| | | #define ApplicationAddress 0x08001000 //åºç¨ç¨åºé¦å°åå®ä¹ |
| | | /* |
| | | static void RemapIrqVector(void) |
| | | { |
| | | memcpy((void*)RAM_START_ADDR, (void *)ApplicationAddress, VECTOR_SIZE * 4); |
| | | LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SYSCFG); |
| | | LL_SYSCFG_SetRemapMemory(LL_SYSCFG_REMAP_SRAM); |
| | | } |
| | | */ |
| | | /* USER CODE END 0 */ |
| | | |
| | | /** |
| | |
| | | int main(void) |
| | | { |
| | | /* USER CODE BEGIN 1 */ |
| | | // RemapIrqVector(); |
| | | __set_PRIMASK(0); //æå¼å
¨å±ä¸æ |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | InitUartstat(&Uart1Stat,Uart1RxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf)); |
| | |
| | | |
| | | /* USER CODE BEGIN Init */ |
| | | |
| | | for (int i=0;i<9;i++) |
| | | { |
| | | // memset(KBusChnStats[i],0,0); |
| | | KBusChnStats[i].SendPackets=0; |
| | | KBusChnStats[i].RecvPackets=0; |
| | | KBusChnStats[i].LostPackets=0; |
| | | KBusChnStats[i].CtnLstPkts=0; |
| | | KBusChnStats[i].MaxCtnLstPkts=0; |
| | | KBusChnStats[i].NotPkgErr=0; |
| | | KBusChnStats[i].PkgLenErr=0; |
| | | KBusChnStats[i].TimeOutErr=0; |
| | | KBusChnStats[i].BCCErr=0; |
| | | KBusChnStats[i].Delay=0; |
| | | KBusChnStats[i].MaxDelay=0; |
| | | } |
| | | |
| | | KMem.LastScanTime=0; |
| | | KMem.ScanTimeuS=0; |
| | |
| | | |
| | | /* Initialize all configured peripherals */ |
| | | MX_GPIO_Init(); |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct; |
| | | 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); |
| | | |
| | | MX_DMA_Init(); |
| | | |
| | | KMachineInit(); |
| | | ReadSysCfgFromFlash(&storedKMSysCfg); |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | int bKBusMaster,bKBusSlave,bKBusRepeater;; |
| | | int nKBusStationId; |
| | | int nKBusChilds; |
| | | KMem.CurJumperSW=ReadJumperSW(); |
| | | KMem.EffJumperSW=KMem.CurJumperSW; |
| | | nKBusStationId=KMem.EffJumperSW&0x0f; |
| | | |
| | | nKBusChilds = nKBusStationId; |
| | | |
| | | bSLPMaster = 1; // KMem.EffJumperSW&0x20 ; //master? |
| | | nStation = 1; |
| | | |
| | | nSLPStation = 1; |
| | | SLP1.bSLPMaster = 1; |
| | | SLP1.nStation = 1; |
| | | SLPInit(&SLP1,Uart6SendPacket); |
| | | // Uart2Baud = AlterUart2Baud; |
| | | |
| | | |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | KMem.EffJumperSW|=0x10; |
| | | nStationID=KMem.EffJumperSW&0x0f; |
| | | int nKBusChilds=KMem.EffJumperSW&0x0f; |
| | | if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | nChilds=nStationID; |
| | | FP0_Init(); |
| | | |
| | | FPxSetCallBackFunc(&FPxCallBackFunc); |
| | | FPx_Init(nKBusChilds); |
| | | |
| | | int IOByteCount = nKBusChilds; |
| | | FPx_SetIOCount(IOByteCount,IOByteCount); |
| | | |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | nStationID=1 ;//KMem.EffJumperSW&0x0f; |
| | |
| | | // else |
| | | {bKBusMaster=0;bKBusSlave=1;} |
| | | #else |
| | | nStationID=KMem.EffJumperSW&0x0f; |
| | | if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | nKBusStationId=KMem.EffJumperSW&0x0f; |
| | | if (KMem.EffJumperSW == 0x3f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | else if ((KMem.EffJumperSW&0x20)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | #endif |
| | | nChilds=nStationID; |
| | | nCurPollId=1; |
| | | |
| | | if (bKBusMaster) { |
| | | KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds); |
| | | |
| | | } else if (bKBusSlave) { |
| | | KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationId,&MyDeviceInfo); |
| | | } |
| | | |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc); |
| | | |
| | | //if (KMem.EffJumperSW == 0x00) |
| | | Uart1Baud = DefaultUart1Baud; |
| | | MX_USART1_UART_Init(); |
| | | MX_USART2_UART_Init(); |
| | | // MX_USART5_UART_Init(); |
| | | // LL_USART_EnableIT_RXNE(USART5); |
| | | // LL_USART_EnableIT_IDLE(USART5); |
| | | |
| | | MX_USART3_UART_Init(); |
| | | |
| | | LL_USART_EnableIT_RXNE(USART3); |
| | | LL_USART_EnableIT_IDLE(USART3); |
| | | |
| | | MX_USART5_UART_Init(); |
| | | LL_USART_EnableIT_RXNE(USART5); |
| | | LL_USART_EnableIT_IDLE(USART5); |
| | | |
| | | MX_USART6_UART_Init(); |
| | | LL_USART_EnableIT_RXNE(USART6); |
| | |
| | | KMRunStat.WorkMode2=0; |
| | | |
| | | KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode == 1){ |
| | | InitPLC(); |
| | | KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ; |
| | | if (KMRunStat.WorkMode2) { |
| | | StartPLC(); } |
| | | } |
| | | KMem.WX[7]=0x5a; |
| | | #endif |
| | | |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
| | | KWireLessStart(); |
| | | #endif |
| | | |
| | | OrdLidarStart(-1); |
| | | |
| | | while (1) |
| | | { |
| | |
| | | int haltick=HAL_GetTick(); |
| | | |
| | | int thisJumperSW=ReadJumperSW(); |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode&1){ |
| | | if (thisJumperSW&0x20 && !(KMem.CurJumperSW&0x20)) // Run å¼å
³ æ£ è·³åã |
| | | {StartPLC();} |
| | | if (!(thisJumperSW&0x20) && (KMem.CurJumperSW&0x20)) // Run å¼å
³ è´ è·³åã |
| | | {StopPLC();} |
| | | } |
| | | |
| | | #endif |
| | | KMem.CurJumperSW=thisJumperSW; |
| | | KMem.haltick=haltick; |
| | | // KMem.TotalRunTime=TotalRunTime; |
| | |
| | | a = LL_GPIO_ReadInputPort(GPIOD); |
| | | KMem.WDT[123]=a; |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | // KMem.WX[0]= GetInput(); |
| | | FP0_Proc(); |
| | | #else |
| | | |
| | | KMem.WXB[0]= GetInput(); |
| | | #endif |
| | | |
| | | if (GetBoardType() == 7 || GetBoardType() ==8 |
| | | || GetBoardType() == 9 || GetBoardType() ==10 || GetBoardType() ==15 || GetBoardType() ==16) |
| | | { |
| | | displayInput(KMem.WX[0]); |
| | | } |
| | | us2=GetuS(); |
| | | if (PowerDownEvent) { KMem.WX[0]=0;} |
| | | ///* |
| | | // /* |
| | | if ((KMem.nRunCount &0x1f) == 0x02) |
| | | { |
| | | ADCProcess(); |
| | |
| | | } |
| | | } |
| | | } |
| | | //*/ |
| | | |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | Radio.IrqProcess( ); // Process Radio IRQ |
| | | KWL_Process(1); |
| | | |
| | | #endif |
| | | // */ |
| | | |
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
| | | { |
| | | if (KMRunStat.nBinProgBank == 0){ |
| | |
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1); |
| | | } |
| | | |
| | | #endif |
| | | |
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime; |
| | | KMem.LastScanTime = us2; |
| | | if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;} |
| | |
| | | |
| | | if (bKBusMaster) |
| | | { |
| | | #if (BOARD_TYPE == 14) |
| | | for (int i=0;i<nOutputBytes;i++) |
| | | {BufferOut[i+1]=KMem.WYB[i];} |
| | | #else |
| | | // BufferOut[1]=KMem.WX[0]&0xff; |
| | | // BufferOut[2]=(KMem.WX[0]>>8)&0xff; |
| | | #endif |
| | | if (nChilds>0) { KBusMasterFunc(2); } |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | // KMem.WX[0]=BufferIn[1]+(BufferIn[2]<<8); |
| | | #else |
| | | // KMem.WY[0]=BufferIn[1]+(BufferIn[2]<<8); |
| | | #endif |
| | | |
| | | KBusLoopProcess(&KBus1); |
| | | } |
| | | if (haltick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | |
| | | |
| | | if (bKBusSlave) |
| | | { |
| | | // BufferOut[0]=KMem.WX[0]; |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | // KBusSlaveFunc(2); |
| | | // if (! KMem.RunStat) {BufferIn[0]=0;} |
| | | // KMem.WY[0]=BufferIn[0]; |
| | | #else |
| | | KBusSlaveFunc(2); |
| | | if (! KMem.RunStat) {BufferIn[0]=0;} |
| | | KMem.WLY[0]=BufferIn[0]; |
| | | #endif |
| | | if (nSlaveTick&0x00002000) SlowFlicker=1; |
| | | |
| | | KBusLoopProcess(&KBus1); |
| | | // if (! KBus1.RunStat) {KBusMem.WLY[0]=0;} |
| | | KMem.WLY[0]=KBusMem.WLY[0]; |
| | | |
| | | if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | | if (nSlaveTick&0x00000800) FastFlicker=1; |
| | | if (KBus1.nSlaveTick&0x00000800) FastFlicker=1; |
| | | else FastFlicker=0; |
| | | |
| | | } |
| | | |
| | | // KMem.WY[0]=nCount2>>5; |
| | | if (KMem.RunStat) {KMem.RunStat--;} |
| | | if (KMem.ErrStat) {KMem.ErrStat--;} |
| | | KBusMem.WLX[0]=KMem.WX[0]; |
| | | KMem.WY[0]=KBusMem.WLY[0]; |
| | | KBusMem.WLX[1]=KMem.WX[1]; |
| | | KBusMem.WLX[2]=KMem.WX[2]; |
| | | KBusMem.WLX[3]=KMem.WX[3]; |
| | | |
| | | |
| | | if (KMRunStat.bLEDFlick) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode==1 ) { |
| | | if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
| | | else {SetRunLed(0);} |
| | | } |
| | | else { |
| | | else |
| | | #endif |
| | | { |
| | | if (!KMem.RunStat) SetRunLed(SlowFlicker); |
| | | else SetRunLed(FastFlicker); |
| | | } |
| | | KMem.ErrStat = KBus1.ErrStat + SLP1.SLPErrSign; |
| | | if (!KMem.ErrStat) |
| | | { |
| | | SetErrLed(0); |
| | |
| | | us4=GetuS(); |
| | | // EffJumperSW = GetInput(20)&0xff; |
| | | |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | |
| | | if ((KMem.EffJumperSW&0x10)==0x10) { |
| | | KMem.WFY[1]=KMem.WLY[0]; |
| | | KMem.WLX[0]=KMem.WFX[1]; |
| | | }else |
| | | { |
| | | KMem.WFY[1]=KMem.WX[0]; |
| | | KMem.WY[0]=KMem.WFX[1]; |
| | | } |
| | | // KMem.WY[0]=KMem.WLY[0]; |
| | | #else |
| | | KMem.WLX[0]=KMem.WX[0]; |
| | | KMem.WY[0]=KMem.WLY[0]; |
| | | #endif |
| | | |
| | | us5=GetuS(); |
| | | |
| | |
| | | // memcpy(&KMem.SDT[64+nSize/2],&KBusChnStats[2],nSize); |
| | | // for (int i=0;i<128;i++) { SDT[i]=i; } |
| | | // SDT[48]=55; |
| | | if (Uart1RecvBuf1DataLen >0 && Uart1Stat.bPacketRecved) |
| | | if (Uart1Stat.bPacketRecved && Uart1RecvBuf1DataLen >0) |
| | | { |
| | | int res1 = -1; |
| | | res1 = ModBusSlaveParsePkg(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); |
| | | if (res1 !=0) |
| | | { |
| | | KLParsePacket(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); |
| | | if (Uart1RecvBuf1[0] == KLSignStart) { |
| | | res1 = KLParsePacket(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); |
| | | }else { |
| | | res1 = ModBusSlaveParsePkg(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); |
| | | } |
| | | Uart1RecvBuf1DataLen=0; |
| | | Uart1Stat.bPacketRecved=0; |
| | | Uart1RecvBuf1DataLen=0; |
| | | Uart1IdelTimer = 0; |
| | | }else { |
| | | if (Uart1IdelTimer>600000) { // è¶
è¿60ç§æ²¡ææ°æ®ä¼ è¾ï¼éæ°è¿å
¥èªéåºæ³¢ç¹çç¶æ |
| | |
| | | if (bKBusSlave) HAL_Delay(0); |
| | | |
| | | if (Uart6Stat.bPacketRecved){ |
| | | SLPparsePacket(Uart6RxBuf,Uart6RecvBuf1DataLen); |
| | | SLPparsePacket(&SLP1,Uart6RxBuf,Uart6RecvBuf1DataLen); |
| | | Uart6RecvBuf1DataLen =0; |
| | | Uart6Stat.bPacketRecved = 0; |
| | | } |
| | | |
| | | SLPinputB = KMem.WYB[1]; |
| | | SLPProcess(); |
| | | KMem.WXB[1] = SLPoutputB; |
| | | |
| | | /* |
| | | if ((KMem.nRunCount&0x7f)==1) { |
| | | |
| | | SLPSendPacket("ABCDEF",6); |
| | | |
| | | }; |
| | | */ |
| | | |
| | | /* |
| | | if (!IsEmpty(&Uart1Stat.QRx)) |
| | | { |
| | | unsigned char k=PopOne(&Uart1Stat.QRx); |
| | | if (k=='L') |
| | | { |
| | | clearscreen(); |
| | | } |
| | | } |
| | | */ |
| | | #if (BOARD_TYPE == 14) |
| | | // PutOutput (KMem.WY[0]); |
| | | #else |
| | | PutOutput (KMem.WY[0]); |
| | | SLP1.SLPinputB = KMem.WYB[1]; |
| | | SLPProcess(&SLP1); |
| | | KMem.WXB[1] = SLP1.SLPoutputB; |
| | | |
| | | #endif |
| | | // YDLiDar process; |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | const unsigned int pins[6]= { LL_GPIO_PIN_10,LL_GPIO_PIN_11,LL_GPIO_PIN_12,LL_GPIO_PIN_13,LL_GPIO_PIN_14,LL_GPIO_PIN_15}; |
| | | //process 6 output |
| | | { |
| | | // mapping bits. |
| | | for (int i=0;i<6;i++) |
| | | { |
| | | USHORT bitaddr = storedKMSysCfg.theKMSysCfg.OutMappings[i]; |
| | | UCHAR type = (bitaddr&0xf000) >>12; |
| | | USHORT byteaddr = (bitaddr&0x0ff0) >>4; |
| | | UCHAR bitpos = bitaddr &0x0f; |
| | | UCHAR bitvalue = 0 ; |
| | | if (byteaddr>0) { |
| | | if (type == 0) bitvalue = KMem.WXB[byteaddr-1] & ( 1 << bitpos ); |
| | | else if (type == 1 ) bitvalue = KMem.WYB[byteaddr-1] & ( 1 << bitpos ); |
| | | } |
| | | if (bitvalue){ LL_GPIO_SetOutputPin(GPIOB,pins[i]);} |
| | | else {LL_GPIO_ResetOutputPin(GPIOB,pins[i]);} |
| | | } |
| | | } |
| | | #endif |
| | | |
| | | /* |
| | | { |
| | | unsigned char pos,seg; |
| | | unsigned short val; |
| | | pos=((KMem.nRunCount)&0x3); |
| | | //val=(KMem.nRunCount)&0xfff; |
| | | val=KMem.ErrStat; |
| | | char buf5[20]; |
| | | sprintf(buf5,"%4d",val); |
| | | val=buf5[3-pos]; |
| | | if (val <'0' || val >'9') {seg=0;} |
| | | else {seg=LEDSEGTAB[val-'0'];} |
| | | |
| | | pos=1<<pos; |
| | | //pos=1; |
| | | //seg=2; |
| | | seg=~seg; |
| | | // PutOutputSPI1(pos|(seg<<8)); |
| | | if (Uart3Stat.bPacketRecved){ |
| | | KMem.WDT[8]++; |
| | | OrdLidarParsePkt(0,(OradarLidarFrame *)Uart3RxBuf,Uart3RecvBuf1DataLen); |
| | | Uart3RecvBuf1DataLen =0; |
| | | Uart3Stat.bPacketRecved = 0; |
| | | } |
| | | */ |
| | | |
| | | #if (BOARD_TYPE == 13) |
| | | w5500_network_info_show(); |
| | | // loopback_tcps(0,str1,5000); |
| | | #endif |
| | | KMem.WDT[9]=pCount1; |
| | | KMem.WDT[10]=dCount1; |
| | | KMem.WDT[11]=vCount1; |
| | | |
| | | KMem.WDT[12] = eCount1; |
| | | KMem.WDT[13] = eCount2; |
| | | |
| | | if (Uart5Stat.bPacketRecved){ |
| | | KMem.WDT[16]++; |
| | | OrdLidarParsePkt(1,(OradarLidarFrame *)Uart5RxBuf,Uart5RecvBuf1DataLen); |
| | | Uart5RecvBuf1DataLen =0; |
| | | Uart5Stat.bPacketRecved = 0; |
| | | } |
| | | |
| | | // nPosX,nPosY,nPosZ,nPosZ1,nPosZ2; |
| | | |
| | | KMem.WDT[17]=pCount2; |
| | | KMem.WDT[18]=dCount2; |
| | | KMem.WDT[19]=vCount2; |
| | | |
| | | KMem.WDT[24]=nPosX; |
| | | KMem.WDT[25]=nPosY; |
| | | KMem.WDT[26]=nPosZ; |
| | | KMem.WDT[27]=nPosZ1; |
| | | KMem.WDT[28]=nPosZ2; |
| | | |
| | | KMem.WDT[32]=results[0]; |
| | | KMem.WDT[33]=results[1]; |
| | | KMem.WDT[34]=results[2]; |
| | | KMem.WDT[35]=results[3]; |
| | | KMem.WDT[36]=results[4]; |
| | | KMem.WDT[37]=results[5]; |
| | | KMem.WDT[38]=results[6]; |
| | | KMem.WDT[39]=results[7]; |
| | | |
| | | |
| | | KMem.WX[1] = nPosX ; |
| | | KMem.WX[2] = nPosY ; |
| | | KMem.WX[3] = nPosZ; |
| | | |
| | | // KMem.WX[1]++ ; |
| | | // KMem.WX[2]++; |
| | | |
| | | // KMem.WYB[0]=1; |
| | | PutOutput (KMem.WY[0]); |
| | | |
| | | LL_IWDG_ReloadCounter(IWDG); |
| | | |
| | |
| | | |
| | | if (LL_USART_IsActiveFlag_RXNE(USART1)) |
| | | { |
| | | Uart1BaudGot=1; |
| | | Uart1BaudFirstGot=1; |
| | | Uart1Stat.RXNECount++; |
| | | // Uart1BaudGot=1; |
| | | // Uart1BaudFirstGot=1; |
| | | // Uart1Stat.RXNECount++; |
| | | unsigned char ch=LL_USART_ReceiveData8(USART1); |
| | | // PushOne(&Uart1Stat.QRx,ch); |
| | | Uart1Stat.RecvBytes++; |
| | | Uart1RecvBuf1[Uart1RecvBuf1DataLen++]=ch; |
| | | Uart1RecvBuf1[Uart1RecvBuf1DataLen]=ch; |
| | | if (Uart1RecvBuf1DataLen <RX1BUFSIZE -1 ) { |
| | | Uart1RecvBuf1DataLen++; |
| | | } |
| | | //LL_USART_TransmitData8(USART1,ch); |
| | | } |
| | | if (LL_USART_IsActiveFlag_ORE(USART1)) |
| | | { |
| | | LL_USART_ClearFlag_ORE(USART1); |
| | | LL_USART_DisableOverrunDetect(USART1); |
| | | Uart1Stat.OverRunCount++; |
| | | } |
| | | if (LL_USART_IsEnabledIT_IDLE(USART1)&&LL_USART_IsActiveFlag_IDLE(USART1)) |
| | |
| | | if (LL_USART_IsActiveFlag_ORE(USART2)) |
| | | { |
| | | LL_USART_ClearFlag_ORE(USART2); |
| | | LL_USART_DisableOverrunDetect(USART2); |
| | | Uart2Stat.OverRunCount++; |
| | | } |
| | | if (LL_USART_IsEnabledIT_IDLE(USART2)&&LL_USART_IsActiveFlag_IDLE(USART2)) |
| | |
| | | { |
| | | /* USER CODE BEGIN USART3_6_IRQn 0 */ |
| | | |
| | | if (LL_USART_IsActiveFlag_RXNE(USART3)) |
| | | { |
| | | unsigned char ch=LL_USART_ReceiveData8(USART3); |
| | | // Uart3Stat.RXNECount++; |
| | | // Uart3Stat.RecvBytes++; |
| | | if (Uart3RecvBuf1DataLen < UART3RXBUFSIZE -1) { |
| | | Uart3RxBuf[Uart3RecvBuf1DataLen++]=ch; |
| | | } |
| | | } |
| | | if (LL_USART_IsActiveFlag_TXE(USART3)) |
| | | { |
| | | if (Uart3SentLen >= Uart3ToSendLen) |
| | | { |
| | | Uart3SentLen = 0; |
| | | Uart3ToSendLen = 0; |
| | | LL_USART_DisableIT_TXE(USART3); |
| | | }else |
| | | { |
| | | unsigned char ch=Uart3TxBuf[Uart3SentLen++]; |
| | | LL_USART_TransmitData8(USART3,ch); |
| | | } |
| | | } |
| | | if (LL_USART_IsActiveFlag_ORE(USART3)) |
| | | { |
| | | LL_USART_ClearFlag_ORE(USART3); |
| | | LL_USART_DisableOverrunDetect(USART3); |
| | | // Uart3Stat.OverRunCount++; |
| | | } |
| | | if (LL_USART_IsEnabledIT_IDLE(USART3)&&LL_USART_IsActiveFlag_IDLE(USART3)) |
| | | {//æ¥æ¶å®æ |
| | | LL_USART_ClearFlag_IDLE(USART3); |
| | | Uart3RecvDone(); |
| | | } |
| | | if (LL_USART_IsActiveFlag_TC(USART3)) |
| | | {//åéå®æ |
| | | LL_USART_ClearFlag_TC(USART3); |
| | | Uart3SendDone(); |
| | | } |
| | | |
| | | if (LL_USART_IsActiveFlag_RXNE(USART5)) |
| | | { |
| | | unsigned char ch=LL_USART_ReceiveData8(USART5); |
| | | // Uart5Stat.RXNECount++; |
| | | // Uart5Stat.RecvBytes++; |
| | | if (Uart5RecvBuf1DataLen < RX5BUFSIZE -1) { |
| | | if (Uart5RecvBuf1DataLen < UART5RXBUFSIZE -1) { |
| | | Uart5RxBuf[Uart5RecvBuf1DataLen++]=ch; |
| | | } |
| | | } |
| | |
| | | unsigned char ch=LL_USART_ReceiveData8(USART6); |
| | | // Uart6Stat.RXNECount++; |
| | | // Uart6Stat.RecvBytes++; |
| | | if (Uart6RecvBuf1DataLen < RX6BUFSIZE -1) { |
| | | if (Uart6RecvBuf1DataLen < UART6RXBUFSIZE -1) { |
| | | Uart6RxBuf[Uart6RecvBuf1DataLen++]=ch; |
| | | } |
| | | } |
| | |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\Ext_FPx\MDK-ARM\Ext_FPx_C8T6_æ¾ä¸æ©å±.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\KPLC_C8T6_ç®æPLC.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\KBus\MDK-ARM\KBus_C8T6_åå¸IO模å_8è·¯16è·¯.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\Radio_LLCC68_C8T6_8è·¯æ 线模å.uvprojx</PathAndName> |
| | | <NodeIsActive>1</NodeIsActive> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\KMini_New_CCT6.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\KMini_C8T6.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\KLink_C8T6.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_KNet_ç½å£æ¨¡å.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_KBox_æ§å¶çå.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_KAD_4路模æé.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\KSingleLineBus\KSingleLineBus_åæ»çº¿.uvproj</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\C8T6_TestApp1\MDK-ARM\F030C8T6_Ext_FPx_New.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | |
| | | |
| | | <project> |
| | | <PathAndName>.\CCT6_TestApp1\MDK-ARM\F030CCT6_TestApp1.uvprojx</PathAndName> |
| | | <NodeIsExpanded>1</NodeIsExpanded> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_Ext_FPx.uvprojx</PathAndName> |
| | | <NodeIsActive>1</NodeIsActive> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_KBus.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_KMini.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030CCT6_KMini.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_KLink.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_KNet.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_Radio_LLCC68.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_KBox.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_KAD.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\MDK-ARM\F030C8T6_KPLC.uvprojx</PathAndName> |
| | | </project> |
| | | |
| | | <project> |
| | | <PathAndName>.\KSingleLineBus\KSingleLineBus.uvproj</PathAndName> |
| | | </project> |
| | | |
| | | </ProjectWorkspace> |
| | |
| | | #define BOARD_TYPE 7 |
| | | #define BOARD_VER 1 |
| | | |
| | | #define ENABLE_PLC 1 |
| | | |
| | | #if (BOARD_TYPE == 11) |
| | | #define XLAT_FREQ 12 |
| | | #elif (BOARD_TYPE == 14) |
| | |
| | | #endif |
| | | |
| | | |
| | | typedef struct tagInfoBlockHdr { |
| | | unsigned short nBlkSign; // å¼å§æ å¿ |
| | | unsigned short nBlkTypeVer; // ç±»ååçæ¬ |
| | | unsigned short nBlkSize; // Block 大å°, å
æ¬å¼å§åç»ææ å¿ |
| | | unsigned short Pad1; |
| | | }stInfoBlockHdr; |
| | | |
| | | typedef struct tagInfoBlockTail { |
| | | |
| | | unsigned short CRC16; |
| | | unsigned short EndSign; |
| | | }stInfoBlockTail; |
| | | |
| | | typedef struct tagBtLdrInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nBtldrVer; |
| | | unsigned short nBtldrDevice; |
| | | unsigned short nBtldrSize; // è®¾è®¡å¤§å° |
| | | unsigned short nBtldrDataSize; //代ç å¤§å° |
| | | unsigned int nBtldr_AppAddr; |
| | | unsigned int nBtldr_NewAppInfoAddr; |
| | | unsigned int nBtldr_NewAppAddr; |
| | | stInfoBlockTail tail; |
| | | }stBtLdrInfoBlock, *pBtLdrInfoBlock; |
| | | |
| | | typedef struct tagAppInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nAppVer; |
| | | unsigned short nAppDevice; |
| | | unsigned short nAppSize; // 代ç è®¾è®¡å¤§å° |
| | | unsigned short nAppDataSize; //å®é
代ç å¤§å° |
| | | unsigned int nAppStartAddr; |
| | | unsigned int nAppStartOffset; |
| | | unsigned int nApp; |
| | | stInfoBlockTail tail; |
| | | }stAppInfoBlock, * pAppInfoBlock; |
| | | |
| | | |
| | | |
| | | #endif /* __BOARDTYPE_H__ */ |
| | |
| | | /* #define USE_FULL_ASSERT 1U */ |
| | | |
| | | /* USER CODE BEGIN Private defines */ |
| | | #include "KBus.h" |
| | | |
| | | extern stKBusDef KBus1; |
| | | /* USER CODE END Private defines */ |
| | | |
| | | #ifdef __cplusplus |
| | |
| | | #include "BoardType.h" |
| | | #include "KMachine.h" |
| | | #include "KBus.h" |
| | | |
| | | extern int __Vectors; |
| | | |
| | | #define APP_ADDR 0x08001000 //åºç¨ç¨åºé¦å°åå®ä¹ (int)(unsigned char *)(&__Vectors) |
| | | #define APPINFOBLOCK_ADDR (APP_ADDR + 0x100) //ç¨åºä¿¡æ¯å å°å |
| | | #define INFOBLOCK_ADDR (APP_ADDR + 0x1000) //ä¿¡æ¯å å°å |
| | | |
| | | #define APP_START_ADDR IROM1_START_ADDRESS |
| | | extern int Region$$Table$$Limit; |
| | | |
| | | #define MAKE_VER(x,y) ((x<<8)|y) |
| | | #define APP_VER MAKE_VER(1,15) |
| | | |
| | | const stAppInfoBlock AppInfoBlock __attribute__((at(APPINFOBLOCK_ADDR))) = |
| | | { |
| | | 0xAA55, // StartSign |
| | | 0x0301, // BlockType |
| | | sizeof(stAppInfoBlock), //BlockSize |
| | | 0, // Pad, |
| | | APP_VER, //AppVer |
| | | (BOARD_TYPE<<8) + BOARD_VER, //AppDevice; |
| | | 0x1000, //AppSize; |
| | | 0x0C00, //AppDataSize; |
| | | APP_ADDR, //nAppStartAddr |
| | | (int)&Region$$Table$$Limit, //nBtldr_NewAppInfoAddr |
| | | 0x08009000, //nBtldr_NewAppAddr |
| | | 0xCCCC, //crc16; |
| | | 0xAA55 //EndSign; |
| | | |
| | | }; |
| | | |
| | | |
| | | const stKMInfoBlock KMInfoBlock __attribute__((at(INFOBLOCK_ADDR))) = |
| | | { |
| | | // sizeof(stKMInfoBlock), |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceType BOARD_VER, //nDevieVer |
| | | APP_VER, //ProgVer |
| | | 0x0102, //KLinkVer |
| | | KBUS_VER, //KBusVer |
| | | // 0x0100, //KNetVer |
| | | // 0x0100, //KWLVer |
| | | |
| | | 4, //nCapacity1 ?K |
| | | 1, //nCapacity2 ?k |
| | | |
| | | DINPUT, //nDInput; |
| | | DOUTPUT, //nDOutput |
| | | |
| | | 0, //nAInput |
| | | 0, //nAOutput |
| | | 0, //nHInput |
| | | 0, //nHOutput |
| | | 0, //nExt1; |
| | | 0, //nExt2; |
| | | 0, //nLogSize; |
| | | 2, //nPorts; |
| | | 0, //nManSize; |
| | | 0, //nAbility; |
| | | 6, //nSwitchBits; |
| | | }; |
| | | |
| | | |
| | | const stDeviceInfo MyDeviceInfo={ |
| | | |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | APP_VER, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | }; |
| | | |
| | | const stExDeviceInfo MyExDeviceInfo ={ |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | APP_VER, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | |
| | | }; |
| | | |
| | |
| | | unsigned char FastFlicker=0; |
| | | |
| | | unsigned int Uart1IdelTimer = 0; |
| | | stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; |
| | | |
| | | uint32_t us1,us2,us3,us4,us5,us6; |
| | | |
| | | |
| | | stKBusDef KBus1; // |
| | | |
| | | extern stDeviceInfo MyDeviceInfo; |
| | | /* USER CODE END PV */ |
| | | |
| | | /* Private function prototypes -----------------------------------------------*/ |
| | |
| | | static int Count=0; |
| | | CurTickuS += 100; |
| | | nCurTick++; |
| | | nSlaveTick++; |
| | | KBus1.nSlaveTick++; |
| | | Count++; |
| | | if (Count>=10000) |
| | | { |
| | |
| | | return; |
| | | } |
| | | |
| | | void * KBusCallBackFunc(int nChn, int nEvent, void *pBuf, int nLen1) |
| | | void PendSvCallBack() |
| | | { |
| | | #if (BOARD_TYPE == 14) |
| | | ///* |
| | | if (bSPI1RecvDone) |
| | | { |
| | | bSPI1RecvDone=0; |
| | | FPxParsePkt(SPI1RecvBuf,nSPI1RecvLenInBuf); |
| | | } |
| | | //*/ |
| | | #endif |
| | | if (Uart2Stat.bPacketRecved) |
| | | { |
| | | KBusParsePacket(&KBus1, (pKBPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); |
| | | Uart2RecvBuf1DataLen=0; |
| | | Uart2Stat.bPacketRecved=0; |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | KMem.WDT[2]++; |
| | | } |
| | | } |
| | | |
| | | /* |
| | | KBusé讯åè°å½æ°ï¼å½é讯ç¶ææ¹åææ°æ®æ´æ°æ¶è¢«è°ç¨ã |
| | | æè
ç³»ç»è¯·æ±æ¶ã |
| | | */ |
| | | void * KBusEvCallBackFunc(void* pParam, int nEvent, void *pBuf, int nLen1) |
| | | { |
| | | switch (nEvent){ |
| | | |
| | |
| | | case KBusEvTimeSync: |
| | | break; |
| | | case KBusEvDataUpdate: |
| | | // KMem.WY[0]=KBusMem.WLY[0]; //KBus Slave |
| | | // KBusMem.WLX[0]=KMem.WX[0]; |
| | | if (KBus1.bMaster) { |
| | | KMem.WLX[0]=KBusMem.WLX[0]; //KPLC with KBus Master |
| | | KBusMem.WLY[0]=KMem.WLY[0]; |
| | | } else if (KBus1.bSlave) { |
| | | KMem.WLX[0]=KBusMem.WLY[0]; //KPLC with KBus Slave |
| | | KBusMem.WLX[0]=KMem.WLY[0]; |
| | | } |
| | | break; |
| | | case KBusEvCmdResponse: |
| | | break; |
| | |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | /* USER CODE END 0 */ |
| | | |
| | |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | |
| | | KLinkInit(1); |
| | | unsigned char bKBusMaster, bKBusSlave, bKBusRepeater; |
| | | int nKBusStationID; |
| | | int nKBusChilds; |
| | | KMem.CurJumperSW=ReadJumperSW(); |
| | | KMem.EffJumperSW=KMem.CurJumperSW; |
| | | |
| | | // Uart2Baud = AlterUart2Baud; |
| | | nKBusStationID = KMem.EffJumperSW&0x0f; |
| | | nKBusChilds = nKBusStationID; |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | KMem.EffJumperSW|=0x10; |
| | |
| | | if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | nChilds=nStationID; |
| | | FP0_Init(); |
| | | FP0_Init(nChilds); |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | nStationID=1 ;//KMem.EffJumperSW&0x0f; |
| | |
| | | // else |
| | | {bKBusMaster=0;bKBusSlave=1;} |
| | | #else |
| | | nStationID=KMem.EffJumperSW&0x0f; |
| | | nKBusStationID=KMem.EffJumperSW&0x0f; |
| | | if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | else if ((KMem.EffJumperSW&0x10)!=0) { |
| | | bKBusMaster=1;bKBusSlave=0; |
| | | } |
| | | else{ |
| | | bKBusMaster=0;bKBusSlave=1; |
| | | } |
| | | #endif |
| | | |
| | | KBusInit(2, bKBusMaster, nChilds); |
| | | KBusSetCallBackFunc(2, &KBusCallBackFunc), |
| | | if (bKBusMaster) { |
| | | KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds); |
| | | } else if (bKBusSlave) { |
| | | KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationID,&MyDeviceInfo); |
| | | } |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc), |
| | | |
| | | UNUSED(bKBusRepeater); |
| | | |
| | | nChilds=nStationID; |
| | | nCurPollId=1; |
| | | //if (KMem.EffJumperSW == 0x00) |
| | | Uart1Baud = DefaultUart1Baud; |
| | | MX_USART1_UART_Init(); |
| | |
| | | // KMem.SDD[13]=PendSvCount; |
| | | // KMem.SDD[14]=RCC->CSR; |
| | | |
| | | KMem.WDB[0] = KBus1.MyStat; |
| | | KMem.WDB[1] = KBus1.bMaster; |
| | | KMem.WDB[2] = KBus1.bMasterSent; |
| | | KMem.WDB[3] = KBus1.bMasterRecved; |
| | | KMem.WDB[4] = KBus1.bMasterRecvOK; |
| | | KMem.WDB[5] = KBus1.bSlaveRecved; |
| | | |
| | | KMem.WDB[8] = KBus1.RunStat; |
| | | KMem.WDB[9] = KBus1.ErrStat; |
| | | |
| | | int a; |
| | | a = LL_GPIO_ReadInputPort(GPIOA); |
| | | KMem.WDT[120]=a; |
| | |
| | | |
| | | #endif |
| | | |
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE; |
| | | // pProgs = (stBinInstrcn1 *) STORE_PRG_BASE; |
| | | |
| | | if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
| | | { |
| | | if (KMRunStat.nBinProgBank == 0){ |
| | | pProgs=(stBinProg1 *)STORE_PRG_BASE; |
| | | stStoredBinProgs * pStoredBinProgs; |
| | | |
| | | if (storedKMSysCfg.theKMSysCfg.nProgBank == 0){ |
| | | pStoredBinProgs=((stStoredBinProgs *)STORE_PRG_BASE); |
| | | }else { |
| | | pProgs=(stBinProg1 *)ALT_PRG_BASE; |
| | | pStoredBinProgs=((stStoredBinProgs *)ALT_PRG_BASE); ; |
| | | } |
| | | nSizeProg1=KMRunStat.nBinProgSize; |
| | | // pProgs=(stBinProg1 *)prog1; |
| | | int nSizeProg1=pStoredBinProgs->StoredHdr.nSize ; |
| | | // pProgs=(stBinInstrcn1 *)prog1; |
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1); |
| | | ProcessPLCBinProg(pStoredBinProgs->BinInstrcns, nSizeProg1); |
| | | } |
| | | |
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime; |
| | |
| | | |
| | | KBusMem.WLY[0]=KMem.WLY[0]; |
| | | |
| | | if (nChilds>0) { KBusMasterFunc(2); } |
| | | if (nKBusChilds>0) { KBusMasterFunc(&KBus1); } |
| | | |
| | | KMem.WLX[0]=KBusMem.WLX[0]; |
| | | |
| | |
| | | // if (! KMem.RunStat) {BufferIn[0]=0;} |
| | | // KMem.WY[0]=BufferIn[0]; |
| | | #else |
| | | KBusSlaveFunc(2); |
| | | KBusSlaveFunc(&KBus1); |
| | | if (! KMem.RunStat) {KMem.WLY[0]=0;} |
| | | // KMem.WLY[0]=BufferIn[0]; |
| | | #endif |
| | | if (nSlaveTick&0x00002000) SlowFlicker=1; |
| | | if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | | if (nSlaveTick&0x00000800) FastFlicker=1; |
| | | if (KBus1.nSlaveTick&0x00000800) FastFlicker=1; |
| | | else FastFlicker=0; |
| | | |
| | | } |
| | | |
| | | // KMem.WY[0]=nCount2>>5; |
| | | if (KMem.RunStat) {KMem.RunStat--;} |
| | | if (KMem.ErrStat) {KMem.ErrStat--;} |
| | | if (KBus1.RunStat) {KBus1.RunStat--;} |
| | | if (KBus1.ErrStat) {KBus1.ErrStat--;} |
| | | |
| | | if (KMRunStat.bLEDFlick) |
| | | { |
| | |
| | | if (!KMem.RunStat) SetRunLed(SlowFlicker); |
| | | else SetRunLed(FastFlicker); |
| | | } |
| | | KMem.ErrStat = 0 + KBus1.ErrStat; |
| | | if (!KMem.ErrStat) |
| | | { |
| | | SetErrLed(0); |
File was renamed from KSingleLineBus/KSingleLineBus.uvopt |
| | |
| | | <tIfile></tIfile> |
| | | <pMon></pMon> |
| | | </DebugOpt> |
| | | <Breakpoint/> |
| | | <Breakpoint> |
| | | <Bp> |
| | | <Number>0</Number> |
| | | <Type>0</Type> |
| | | <LineNumber>267</LineNumber> |
| | | <EnabledFlag>1</EnabledFlag> |
| | | <Address>0</Address> |
| | | <ByteObject>0</ByteObject> |
| | | <HtxType>0</HtxType> |
| | | <ManyObjects>0</ManyObjects> |
| | | <SizeOfObject>0</SizeOfObject> |
| | | <BreakByAccess>0</BreakByAccess> |
| | | <BreakIfRCount>0</BreakIfRCount> |
| | | <Filename>E:\WORK\MCU&PCB\DIST_IO\ComLib\Src\stm32f0xx_it.c</Filename> |
| | | <ExecCommand></ExecCommand> |
| | | <Expression></Expression> |
| | | </Bp> |
| | | <Bp> |
| | | <Number>1</Number> |
| | | <Type>0</Type> |
| | | <LineNumber>301</LineNumber> |
| | | <EnabledFlag>1</EnabledFlag> |
| | | <Address>0</Address> |
| | | <ByteObject>0</ByteObject> |
| | | <HtxType>0</HtxType> |
| | | <ManyObjects>0</ManyObjects> |
| | | <SizeOfObject>0</SizeOfObject> |
| | | <BreakByAccess>0</BreakByAccess> |
| | | <BreakIfRCount>0</BreakIfRCount> |
| | | <Filename><5>../Radio_LLCC68\Radio\src\sx126x.c</Filename> |
| | | <ExecCommand></ExecCommand> |
| | | <Expression></Expression> |
| | | </Bp> |
| | | <Bp> |
| | | <Number>2</Number> |
| | | <Type>0</Type> |
| | | <LineNumber>611</LineNumber> |
| | | <EnabledFlag>1</EnabledFlag> |
| | | <Address>0</Address> |
| | | <ByteObject>0</ByteObject> |
| | | <HtxType>0</HtxType> |
| | | <ManyObjects>0</ManyObjects> |
| | | <SizeOfObject>0</SizeOfObject> |
| | | <BreakByAccess>0</BreakByAccess> |
| | | <BreakIfRCount>0</BreakIfRCount> |
| | | <Filename><5>../Radio_LLCC68\Radio\src\sx126x.c</Filename> |
| | | <ExecCommand></ExecCommand> |
| | | <Expression></Expression> |
| | | </Bp> |
| | | </Breakpoint> |
| | | <Tracepoint> |
| | | <THDelay>0</THDelay> |
| | | </Tracepoint> |
| | |
| | | BL51 BANKED LINKER/LOCATER V6.22 03/17/2024 12:33:27 PAGE 1 |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 1 |
| | | |
| | | |
| | | BL51 BANKED LINKER/LOCATER V6.22, INVOKED BY: |
| | |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C_INIT) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?CLDPTR) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?CLDOPTR) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?CILDOPTR) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?CSTPTR) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?CSTOPTR) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?ILDOPTR) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?IILDOPTR) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?ISTOPTR) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?PLDOPTR) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?PSTOPTR) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?ICALL) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?IILDX) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?PLDIDATA) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?PSTIDATA) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?PLDXDATA) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?PSTXDATA) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?PLDPDATA) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?PSTPDATA) |
| | | D:\KEIL_V5\C51\LIB\C51S.LIB (?C?PLDCODE) |
| | | |
| | | |
| | | LINK MAP OF MODULE: .\Objects\demo (?C_STARTUP) |
| | |
| | | |
| | | * * * * * * * D A T A M E M O R Y * * * * * * * |
| | | REG 0000H 0008H ABSOLUTE "REG BANK 0" |
| | | DATA 0008H 0017H UNIT ?DT?MAIN |
| | | DATA 0008H 0011H UNIT _DATA_GROUP_ |
| | | DATA 0019H 0006H UNIT ?DT?_SLPSETCALLBACK?SLP |
| | | 001FH 0001H *** GAP *** |
| | | BIT 0020H.0 0000H.2 UNIT ?BI?MAIN |
| | | 0020H.2 0000H.6 *** GAP *** |
| | | DATA 0021H 0020H UNIT ?DT?SLP |
| | | DATA 0041H 000AH UNIT _DATA_GROUP_ |
| | | IDATA 004BH 0001H UNIT ?STACK |
| | | DATA 0021H 003CH UNIT ?DT?MAIN |
| | | IDATA 005DH 0001H UNIT ?STACK |
| | | |
| | | * * * * * * * C O D E M E M O R Y * * * * * * * |
| | | CODE 0000H 0003H ABSOLUTE |
| | | CODE 0003H 0005H UNIT ?PR?GETINPUT?MAIN |
| | | CODE 0008H 0003H UNIT ?PR?_PUTOUTPUT?MAIN |
| | | CODE 000BH 0003H ABSOLUTE |
| | | CODE 000EH 000BH UNIT ?PR?DELAY1MS?MAIN |
| | | CODE 0019H 0001H UNIT ?PR?TIMER0_ISR?MAIN |
| | | CODE 001AH 0001H UNIT ?PR?TIMER1_ISR?MAIN |
| | | CODE 000EH 0009H UNIT ?PR?_MODBUSPARSEPACKET?MODBUS |
| | | CODE 0017H 0001H UNIT ?PR?TIMER0_ISR?MAIN |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 2 |
| | | |
| | | |
| | | CODE 0018H 0001H UNIT ?PR?TIMER1_ISR?MAIN |
| | | CODE 0019H 0001H UNIT ?PR?OTHERPROCESS?MAIN |
| | | CODE 001AH 0001H UNIT ?PR?MODBUSPROCESS?MODBUS |
| | | CODE 001BH 0003H ABSOLUTE |
| | | CODE 001EH 005AH UNIT ?PR?MAIN?MAIN |
| | | CODE 0078H 0013H UNIT ?PR?_DELAY_US?MAIN |
| | | CODE 001EH 0035H UNIT ?PR?UART3_ISR?MAIN |
| | | CODE 0053H 0031H UNIT ?PR?_SLPINIT?SLP |
| | | 0084H 0007H *** GAP *** |
| | | CODE 008BH 0003H ABSOLUTE |
| | | CODE 008EH 00B8H UNIT ?PR?_SLPPARSEPACKET?SLP |
| | | CODE 0146H 008CH UNIT ?C_C51STARTUP |
| | | CODE 01D2H 0083H UNIT ?PR?GETJUMPER?MAIN |
| | | CODE 0255H 007AH UNIT ?C?LIB_CODE |
| | | CODE 02CFH 0070H UNIT ?PR?SLPPROCESS?SLP |
| | | CODE 033FH 0048H UNIT ?PR?SLPMASTERSENDPACKET?SLP |
| | | CODE 0387H 0035H UNIT ?PR?UART3_ISR?MAIN |
| | | CODE 03BCH 002DH UNIT ?PR?_SLPBCC?SLP |
| | | CODE 03E9H 0026H UNIT ?PR?_UART3SENDPACKET?MAIN |
| | | CODE 040FH 0023H UNIT ?PR?IO_INIT?MAIN |
| | | BL51 BANKED LINKER/LOCATER V6.22 03/17/2024 12:33:27 PAGE 2 |
| | | |
| | | |
| | | CODE 0432H 001BH UNIT ?PR?UART3RECVPACKET?MAIN |
| | | CODE 044DH 001BH UNIT ?PR?UART1RECVPACKET?MAIN |
| | | CODE 0468H 0019H UNIT ?PR?UART3INIT?MAIN |
| | | CODE 0481H 0019H UNIT ?C_INITSEG |
| | | CODE 049AH 0014H UNIT ?PR?_DELAY_MS?MAIN |
| | | CODE 04AEH 0009H UNIT ?PR?_MODBUSPARSEPACKET?MODBUS |
| | | CODE 04B7H 0003H UNIT ?PR?_SLPSENDPACKET?MAIN |
| | | CODE 04BAH 0001H UNIT ?PR?OTHERPROCESS?MAIN |
| | | CODE 04BBH 0001H UNIT ?PR?MODBUSPROCESS?MODBUS |
| | | CODE 008EH 0246H UNIT ?C?LIB_CODE |
| | | CODE 02D4H 019DH UNIT ?PR?_SLPPARSEPACKET?SLP |
| | | CODE 0471H 0119H UNIT ?PR?_SLPPROCESS?SLP |
| | | CODE 058AH 00B6H UNIT ?PR?_SLPMASTERSENDPACKET?SLP |
| | | CODE 0640H 008CH UNIT ?C_C51STARTUP |
| | | CODE 06CCH 0083H UNIT ?PR?GETJUMPER?MAIN |
| | | CODE 074FH 0078H UNIT ?PR?MAIN?MAIN |
| | | CODE 07C7H 0026H UNIT ?PR?_UART3SENDPACKET?MAIN |
| | | CODE 07EDH 0025H UNIT ?PR?UART3RECVPACKET?MAIN |
| | | CODE 0812H 0023H UNIT ?PR?IO_INIT?MAIN |
| | | CODE 0835H 0022H UNIT ?PR?_SLPBCC?SLP |
| | | CODE 0857H 001FH UNIT ?PR?_SLPSETCALLBACK?SLP |
| | | CODE 0876H 001BH UNIT ?PR?UART1RECVPACKET?MAIN |
| | | CODE 0891H 0019H UNIT ?PR?UART3INIT?MAIN |
| | | CODE 08AAH 0013H UNIT ?PR?_DELAY_US?MAIN |
| | | CODE 08BDH 0011H UNIT ?C_INITSEG |
| | | |
| | | |
| | | |
| | |
| | | +--> ?PR?MAIN?MAIN |
| | | +--> ?C_INITSEG |
| | | |
| | | ?PR?MAIN?MAIN 0041H 0001H |
| | | ?PR?MAIN?MAIN 0008H 0001H |
| | | +--> ?PR?IO_INIT?MAIN |
| | | +--> ?PR?UART3INIT?MAIN |
| | | +--> ?PR?GETJUMPER?MAIN |
| | | +--> ?PR?_UART3SENDPACKET?MAIN |
| | | +--> ?PR?_SLPINIT?SLP |
| | | +--> ?PR?GETINPUT?MAIN |
| | | +--> ?PR?UART3RECVPACKET?MAIN |
| | | +--> ?PR?SLPPROCESS?SLP |
| | | +--> ?PR?_SLPPROCESS?SLP |
| | | +--> ?PR?_PUTOUTPUT?MAIN |
| | | +--> ?PR?UART1RECVPACKET?MAIN |
| | | +--> ?PR?MODBUSPROCESS?MODBUS |
| | | +--> ?PR?OTHERPROCESS?MAIN |
| | | +--> ?PR?_DELAY_US?MAIN |
| | | |
| | | ?PR?GETJUMPER?MAIN 0042H 0001H |
| | | ?PR?GETJUMPER?MAIN 0009H 0001H |
| | | |
| | | ?PR?_UART3SENDPACKET?MAIN 0009H 0003H |
| | | |
| | | ?PR?_SLPINIT?SLP 0009H 0006H |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 3 |
| | | |
| | | |
| | | |
| | | ?PR?UART3RECVPACKET?MAIN ----- ----- |
| | | +--> ?PR?_SLPPARSEPACKET?SLP |
| | | |
| | | ?PR?_SLPPARSEPACKET?SLP 0042H 0006H |
| | | ?PR?_SLPPARSEPACKET?SLP 0009H 000DH |
| | | +--> ?PR?_SLPBCC?SLP |
| | | +--> ?PR?_SLPSENDPACKET?MAIN |
| | | |
| | | ?PR?_SLPBCC?SLP 0048H 0003H |
| | | ?PR?_SLPBCC?SLP 0016H 0003H |
| | | |
| | | ?PR?_SLPSENDPACKET?MAIN ----- ----- |
| | | +--> ?PR?_UART3SENDPACKET?MAIN |
| | | ?PR?_SLPPROCESS?SLP 0009H 0003H |
| | | +--> ?PR?_SLPMASTERSENDPACKET?SLP |
| | | |
| | | ?PR?_UART3SENDPACKET?MAIN 0048H 0003H |
| | | |
| | | ?PR?SLPPROCESS?SLP ----- ----- |
| | | +--> ?PR?SLPMASTERSENDPACKET?SLP |
| | | |
| | | ?PR?SLPMASTERSENDPACKET?SLP 0042H 0003H |
| | | ?PR?_SLPMASTERSENDPACKET?SLP 000CH 0006H |
| | | +--> ?PR?_SLPBCC?SLP |
| | | +--> ?PR?_SLPSENDPACKET?MAIN |
| | | BL51 BANKED LINKER/LOCATER V6.22 03/17/2024 12:33:27 PAGE 3 |
| | | |
| | | |
| | | |
| | | ?PR?UART1RECVPACKET?MAIN ----- ----- |
| | | +--> ?PR?_MODBUSPARSEPACKET?MODBUS |
| | | |
| | | ?PR?_MODBUSPARSEPACKET?MODBUS 0042H 0004H |
| | | ?PR?_MODBUSPARSEPACKET?MODBUS 0009H 0004H |
| | | |
| | | |
| | | |
| | |
| | | ---------------------------------- |
| | | |
| | | ------- MODULE ?C_STARTUP |
| | | C:0146H SEGMENT ?C_C51STARTUP |
| | | I:004BH SEGMENT ?STACK |
| | | C:0640H SEGMENT ?C_C51STARTUP |
| | | I:005DH SEGMENT ?STACK |
| | | C:0000H PUBLIC ?C_STARTUP |
| | | D:00E0H SYMBOL ACC |
| | | D:00F0H SYMBOL B |
| | |
| | | N:0000H SYMBOL IBPSTACK |
| | | N:0100H SYMBOL IBPSTACKTOP |
| | | N:0080H SYMBOL IDATALEN |
| | | C:0149H SYMBOL IDATALOOP |
| | | C:0643H SYMBOL IDATALOOP |
| | | N:0000H SYMBOL PBPSTACK |
| | | N:0100H SYMBOL PBPSTACKTOP |
| | | N:0000H SYMBOL PDATALEN |
| | |
| | | N:0000H SYMBOL PPAGEENABLE |
| | | D:00A0H SYMBOL PPAGE_SFR |
| | | D:0081H SYMBOL SP |
| | | C:0146H SYMBOL STARTUP1 |
| | | C:0640H SYMBOL STARTUP1 |
| | | N:0000H SYMBOL XBPSTACK |
| | | N:0000H SYMBOL XBPSTACKTOP |
| | | N:0000H SYMBOL XDATALEN |
| | | N:0000H SYMBOL XDATASTART |
| | | C:0000H LINE# 126 |
| | | C:0146H LINE# 133 |
| | | C:0148H LINE# 134 |
| | | C:0149H LINE# 135 |
| | | C:014AH LINE# 136 |
| | | C:014CH LINE# 185 |
| | | C:014FH LINE# 196 |
| | | C:0640H LINE# 133 |
| | | C:0642H LINE# 134 |
| | | C:0643H LINE# 135 |
| | | C:0644H LINE# 136 |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 4 |
| | | |
| | | |
| | | C:0646H LINE# 185 |
| | | C:0649H LINE# 196 |
| | | ------- ENDMOD ?C_STARTUP |
| | | |
| | | ------- MODULE MAIN |
| | |
| | | D:0096H PUBLIC P2M0 |
| | | D:0091H PUBLIC P1M1 |
| | | D:0080H PUBLIC P0 |
| | | C:0387H PUBLIC UART3_Isr |
| | | C:001EH PUBLIC UART3_Isr |
| | | D:00B2H PUBLIC P3M0 |
| | | D:0095H PUBLIC P2M1 |
| | | BL51 BANKED LINKER/LOCATER V6.22 03/17/2024 12:33:27 PAGE 4 |
| | | |
| | | |
| | | D:0090H PUBLIC P1 |
| | | D:00B4H PUBLIC P4M0 |
| | | D:00B1H PUBLIC P3M1 |
| | |
| | | D:00CCH PUBLIC P6M0 |
| | | D:00C9H PUBLIC P5M1 |
| | | D:00C0H PUBLIC P4 |
| | | C:000EH PUBLIC Delay1ms |
| | | D:00E2H PUBLIC P7M0 |
| | | D:00CBH PUBLIC P6M1 |
| | | D:00C8H PUBLIC P5 |
| | |
| | | D:00F8H PUBLIC P7 |
| | | D:00BAH PUBLIC P_SW2 |
| | | D:00A8H PUBLIC IE |
| | | C:040FH PUBLIC IO_Init |
| | | C:0812H PUBLIC IO_Init |
| | | B:00A8H.4 PUBLIC ES |
| | | C:01D2H PUBLIC GetJumper |
| | | C:06CCH PUBLIC GetJumper |
| | | D:00B8H PUBLIC IP |
| | | B:00B0H.6 PUBLIC KEY1 |
| | | B:00B0H.7 PUBLIC KEY2 |
| | |
| | | B:00C0H.2 PUBLIC KEY4 |
| | | B:00C0H.3 PUBLIC KEY5 |
| | | B:00C0H.4 PUBLIC KEY6 |
| | | D:0021H PUBLIC SLP1 |
| | | D:00D8H PUBLIC CCON |
| | | C:001EH PUBLIC main |
| | | D:0008H PUBLIC uart1recvtimeout |
| | | D:0009H PUBLIC uart3recvtimeout |
| | | C:049AH PUBLIC _Delay_ms |
| | | C:074FH PUBLIC main |
| | | D:0044H PUBLIC uart1recvtimeout |
| | | D:0045H PUBLIC uart3recvtimeout |
| | | D:0098H PUBLIC SCON |
| | | C:0003H PUBLIC GetInput |
| | | D:0088H PUBLIC TCON |
| | | B:0020H.0 PUBLIC uart1busy |
| | | B:0020H.1 PUBLIC uart3busy |
| | | C:03E9H PUBLIC _Uart3SendPacket |
| | | C:0078H PUBLIC _Delay_us |
| | | C:044DH PUBLIC Uart1RecvPacket |
| | | C:07C7H PUBLIC _Uart3SendPacket |
| | | C:08AAH PUBLIC _Delay_us |
| | | C:0876H PUBLIC Uart1RecvPacket |
| | | D:00AFH PUBLIC IE2 |
| | | C:0432H PUBLIC Uart3RecvPacket |
| | | C:0019H PUBLIC Timer0_Isr |
| | | C:001AH PUBLIC Timer1_Isr |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 5 |
| | | |
| | | |
| | | C:07EDH PUBLIC Uart3RecvPacket |
| | | D:0046H PUBLIC bSLPMaster |
| | | C:0017H PUBLIC Timer0_Isr |
| | | C:0018H PUBLIC Timer1_Isr |
| | | D:0047H PUBLIC nSLPStation |
| | | D:00D4H PUBLIC T3H |
| | | D:000AH PUBLIC inputdata |
| | | D:0048H PUBLIC inputdata |
| | | C:0008H PUBLIC _PutOutput |
| | | D:00D5H PUBLIC T3L |
| | | C:04B7H PUBLIC _SLPSendPacket |
| | | D:0083H PUBLIC DPH |
| | | D:00D1H PUBLIC T4T3M |
| | | D:000BH PUBLIC uart1recvbuf |
| | | D:0013H PUBLIC uart3recvbuf |
| | | D:001BH PUBLIC uart1recvlen |
| | | BL51 BANKED LINKER/LOCATER V6.22 03/17/2024 12:33:27 PAGE 5 |
| | | |
| | | |
| | | D:0049H PUBLIC uart1recvbuf |
| | | D:0051H PUBLIC uart3recvbuf |
| | | D:0059H PUBLIC uart1recvlen |
| | | D:00ADH PUBLIC S3BUF |
| | | D:001CH PUBLIC uart3recvlen |
| | | D:005AH PUBLIC uart3recvlen |
| | | D:00ACH PUBLIC S3CON |
| | | C:0468H PUBLIC Uart3Init |
| | | C:04BAH PUBLIC OtherProcess |
| | | C:0891H PUBLIC Uart3Init |
| | | C:0019H PUBLIC OtherProcess |
| | | B:00C0H.5 PUBLIC ERR |
| | | B:00C0H.6 PUBLIC RUN |
| | | D:001DH PUBLIC nCount |
| | | D:005BH PUBLIC nCount |
| | | D:00D0H PUBLIC PSW |
| | | D:0094H PUBLIC P0M0 |
| | | ------- PROC DELAY1MS |
| | | ------- DO |
| | | D:0007H SYMBOL i |
| | | D:0006H SYMBOL j |
| | | ------- ENDDO |
| | | C:000EH LINE# 97 |
| | | C:000EH LINE# 98 |
| | | C:000EH LINE# 101 |
| | | C:000FH LINE# 102 |
| | | C:0010H LINE# 103 |
| | | C:0012H LINE# 104 |
| | | C:0014H LINE# 106 |
| | | C:0014H LINE# 107 |
| | | C:0016H LINE# 108 |
| | | C:0018H LINE# 109 |
| | | ------- ENDPROC DELAY1MS |
| | | ------- PROC _DELAY_MS |
| | | D:0004H SYMBOL n |
| | | C:049AH LINE# 112 |
| | | C:049EH LINE# 113 |
| | | C:049EH LINE# 114 |
| | | C:04A8H LINE# 115 |
| | | C:04A8H LINE# 116 |
| | | C:04ABH LINE# 117 |
| | | C:04ADH LINE# 119 |
| | | ------- ENDPROC _DELAY_MS |
| | | ------- PROC _DELAY_US |
| | | D:0006H SYMBOL n |
| | | ------- DO |
| | | D:0005H SYMBOL j |
| | | ------- ENDDO |
| | | C:0078H LINE# 121 |
| | | C:0078H LINE# 122 |
| | | C:0078H LINE# 124 |
| | | C:0082H LINE# 125 |
| | | C:0084H LINE# 126 |
| | | C:008AH LINE# 128 |
| | | C:08AAH LINE# 126 |
| | | C:08AAH LINE# 127 |
| | | C:08AAH LINE# 129 |
| | | C:08B4H LINE# 130 |
| | | C:08B6H LINE# 131 |
| | | C:08BCH LINE# 133 |
| | | ------- ENDPROC _DELAY_US |
| | | ------- PROC TIMER0_ISR |
| | | C:0019H LINE# 130 |
| | | C:0019H LINE# 131 |
| | | C:0017H LINE# 135 |
| | | C:0017H LINE# 136 |
| | | ------- ENDPROC TIMER0_ISR |
| | | ------- PROC TIMER1_ISR |
| | | C:001AH LINE# 145 |
| | | C:001AH LINE# 146 |
| | | C:0018H LINE# 150 |
| | | C:0018H LINE# 151 |
| | | ------- ENDPROC TIMER1_ISR |
| | | ------- PROC UART3INIT |
| | | BL51 BANKED LINKER/LOCATER V6.22 03/17/2024 12:33:27 PAGE 6 |
| | | |
| | | |
| | | C:0468H LINE# 187 |
| | | C:0468H LINE# 188 |
| | | C:0468H LINE# 189 |
| | | C:046BH LINE# 190 |
| | | C:046EH LINE# 191 |
| | | C:0471H LINE# 192 |
| | | C:0474H LINE# 193 |
| | | C:0477H LINE# 194 |
| | | C:047AH LINE# 195 |
| | | C:047DH LINE# 196 |
| | | C:0480H LINE# 198 |
| | | C:0891H LINE# 192 |
| | | C:0891H LINE# 193 |
| | | C:0891H LINE# 194 |
| | | C:0894H LINE# 195 |
| | | C:0897H LINE# 196 |
| | | C:089AH LINE# 197 |
| | | C:089DH LINE# 198 |
| | | C:08A0H LINE# 199 |
| | | C:08A3H LINE# 200 |
| | | C:08A6H LINE# 201 |
| | | C:08A9H LINE# 203 |
| | | ------- ENDPROC UART3INIT |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 6 |
| | | |
| | | |
| | | ------- PROC UART3_ISR |
| | | C:0387H LINE# 201 |
| | | C:0390H LINE# 203 |
| | | C:0395H LINE# 204 |
| | | C:0395H LINE# 205 |
| | | C:0398H LINE# 207 |
| | | C:039FH LINE# 208 |
| | | C:03A8H LINE# 209 |
| | | C:03ABH LINE# 213 |
| | | C:03ABH LINE# 214 |
| | | C:03B0H LINE# 215 |
| | | C:03B0H LINE# 216 |
| | | C:03B3H LINE# 217 |
| | | C:03B5H LINE# 218 |
| | | C:03B5H LINE# 219 |
| | | C:001EH LINE# 206 |
| | | C:0027H LINE# 208 |
| | | C:002CH LINE# 209 |
| | | C:002CH LINE# 210 |
| | | C:002FH LINE# 212 |
| | | C:0036H LINE# 213 |
| | | C:003FH LINE# 214 |
| | | C:0042H LINE# 218 |
| | | C:0042H LINE# 219 |
| | | C:0047H LINE# 220 |
| | | C:0047H LINE# 221 |
| | | C:004AH LINE# 222 |
| | | C:004CH LINE# 223 |
| | | C:004CH LINE# 224 |
| | | ------- ENDPROC UART3_ISR |
| | | ------- PROC IO_INIT |
| | | C:040FH LINE# 222 |
| | | C:040FH LINE# 223 |
| | | C:040FH LINE# 224 |
| | | C:0414H LINE# 225 |
| | | C:0418H LINE# 226 |
| | | C:041DH LINE# 227 |
| | | C:0421H LINE# 228 |
| | | C:0425H LINE# 229 |
| | | C:0429H LINE# 230 |
| | | C:042DH LINE# 231 |
| | | C:0431H LINE# 234 |
| | | C:0812H LINE# 227 |
| | | C:0812H LINE# 228 |
| | | C:0812H LINE# 229 |
| | | C:0817H LINE# 230 |
| | | C:081BH LINE# 231 |
| | | C:0820H LINE# 232 |
| | | C:0824H LINE# 233 |
| | | C:0828H LINE# 234 |
| | | C:082CH LINE# 235 |
| | | C:0830H LINE# 236 |
| | | C:0834H LINE# 239 |
| | | ------- ENDPROC IO_INIT |
| | | ------- PROC GETINPUT |
| | | C:0003H LINE# 249 |
| | | C:0003H LINE# 250 |
| | | C:0003H LINE# 252 |
| | | C:0007H LINE# 269 |
| | | C:0003H LINE# 254 |
| | | C:0003H LINE# 255 |
| | | C:0003H LINE# 257 |
| | | C:0007H LINE# 274 |
| | | ------- ENDPROC GETINPUT |
| | | ------- PROC _PUTOUTPUT |
| | | D:0007H SYMBOL out |
| | | C:0008H LINE# 271 |
| | | C:0008H LINE# 272 |
| | | C:0008H LINE# 273 |
| | | C:000AH LINE# 289 |
| | | C:0008H LINE# 276 |
| | | C:0008H LINE# 277 |
| | | C:0008H LINE# 278 |
| | | C:000AH LINE# 294 |
| | | ------- ENDPROC _PUTOUTPUT |
| | | ------- PROC _UART3SENDPACKET |
| | | D:0048H SYMBOL str |
| | | D:0009H SYMBOL str |
| | | D:0005H SYMBOL len |
| | | BL51 BANKED LINKER/LOCATER V6.22 03/17/2024 12:33:27 PAGE 7 |
| | | |
| | | |
| | | ------- DO |
| | | D:0007H SYMBOL i |
| | | ------- ENDDO |
| | | C:03E9H LINE# 291 |
| | | C:03EFH LINE# 292 |
| | | C:03EFH LINE# 294 |
| | | C:03F6H LINE# 295 |
| | | C:03F6H LINE# 296 |
| | | C:03F9H LINE# 297 |
| | | C:0409H LINE# 298 |
| | | C:040BH LINE# 299 |
| | | C:040EH LINE# 300 |
| | | C:07C7H LINE# 296 |
| | | C:07CDH LINE# 297 |
| | | C:07CDH LINE# 299 |
| | | C:07D4H LINE# 300 |
| | | C:07D4H LINE# 301 |
| | | C:07D7H LINE# 302 |
| | | C:07E7H LINE# 303 |
| | | C:07E9H LINE# 304 |
| | | C:07ECH LINE# 305 |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 7 |
| | | |
| | | |
| | | ------- ENDPROC _UART3SENDPACKET |
| | | ------- PROC _SLPSENDPACKET |
| | | D:0001H SYMBOL str |
| | | D:0005H SYMBOL len |
| | | C:04B7H LINE# 301 |
| | | C:04B7H LINE# 302 |
| | | C:04B7H LINE# 303 |
| | | ------- ENDPROC _SLPSENDPACKET |
| | | ------- PROC UART3RECVPACKET |
| | | C:0432H LINE# 306 |
| | | C:0432H LINE# 307 |
| | | C:0432H LINE# 308 |
| | | C:0439H LINE# 309 |
| | | C:043BH LINE# 310 |
| | | C:043CH LINE# 311 |
| | | C:043CH LINE# 312 |
| | | C:043EH LINE# 313 |
| | | C:0449H LINE# 314 |
| | | C:044CH LINE# 315 |
| | | C:044CH LINE# 316 |
| | | C:07EDH LINE# 312 |
| | | C:07EDH LINE# 313 |
| | | C:07EDH LINE# 314 |
| | | C:07F4H LINE# 315 |
| | | C:07F6H LINE# 316 |
| | | C:07F7H LINE# 317 |
| | | C:07F7H LINE# 318 |
| | | C:07F9H LINE# 319 |
| | | C:080EH LINE# 320 |
| | | C:0811H LINE# 321 |
| | | C:0811H LINE# 322 |
| | | ------- ENDPROC UART3RECVPACKET |
| | | ------- PROC UART1RECVPACKET |
| | | C:044DH LINE# 318 |
| | | C:044DH LINE# 319 |
| | | C:044DH LINE# 320 |
| | | C:0454H LINE# 321 |
| | | C:0456H LINE# 322 |
| | | C:0457H LINE# 323 |
| | | C:0457H LINE# 324 |
| | | C:0459H LINE# 325 |
| | | C:0464H LINE# 326 |
| | | C:0467H LINE# 327 |
| | | C:0467H LINE# 328 |
| | | C:0876H LINE# 324 |
| | | C:0876H LINE# 325 |
| | | C:0876H LINE# 326 |
| | | C:087DH LINE# 327 |
| | | C:087FH LINE# 328 |
| | | C:0880H LINE# 329 |
| | | C:0880H LINE# 330 |
| | | C:0882H LINE# 331 |
| | | C:088DH LINE# 332 |
| | | C:0890H LINE# 333 |
| | | C:0890H LINE# 334 |
| | | ------- ENDPROC UART1RECVPACKET |
| | | ------- PROC OTHERPROCESS |
| | | C:04BAH LINE# 330 |
| | | C:04BAH LINE# 331 |
| | | C:04BAH LINE# 346 |
| | | C:0019H LINE# 336 |
| | | C:0019H LINE# 337 |
| | | C:0019H LINE# 352 |
| | | ------- ENDPROC OTHERPROCESS |
| | | ------- PROC GETJUMPER |
| | | ------- DO |
| | | D:0042H SYMBOL keys |
| | | D:0009H SYMBOL keys |
| | | ------- ENDDO |
| | | C:01D2H LINE# 348 |
| | | C:01D2H LINE# 349 |
| | | BL51 BANKED LINKER/LOCATER V6.22 03/17/2024 12:33:27 PAGE 8 |
| | | |
| | | |
| | | C:01D2H LINE# 351 |
| | | C:01E2H LINE# 352 |
| | | C:01F4H LINE# 353 |
| | | C:0208H LINE# 354 |
| | | C:021DH LINE# 355 |
| | | C:0230H LINE# 356 |
| | | C:0244H LINE# 357 |
| | | C:024BH LINE# 358 |
| | | C:0252H LINE# 360 |
| | | C:0254H LINE# 361 |
| | | C:06CCH LINE# 354 |
| | | C:06CCH LINE# 355 |
| | | C:06CCH LINE# 357 |
| | | C:06DCH LINE# 358 |
| | | C:06EEH LINE# 359 |
| | | C:0702H LINE# 360 |
| | | C:0717H LINE# 361 |
| | | C:072AH LINE# 362 |
| | | C:073EH LINE# 363 |
| | | C:0745H LINE# 364 |
| | | C:074CH LINE# 366 |
| | | C:074EH LINE# 367 |
| | | ------- ENDPROC GETJUMPER |
| | | ------- PROC MAIN |
| | | ------- DO |
| | | D:0041H SYMBOL daa |
| | | D:0008H SYMBOL daa |
| | | ------- ENDDO |
| | | C:001EH LINE# 362 |
| | | C:001EH LINE# 363 |
| | | C:001EH LINE# 365 |
| | | C:0021H LINE# 368 |
| | | C:0024H LINE# 370 |
| | | C:0027H LINE# 374 |
| | | C:0029H LINE# 375 |
| | | C:002BH LINE# 379 |
| | | C:0030H LINE# 380 |
| | | C:0039H LINE# 381 |
| | | C:003FH LINE# 384 |
| | | C:003FH LINE# 385 |
| | | C:003FH LINE# 391 |
| | | C:0044H LINE# 392 |
| | | C:0047H LINE# 393 |
| | | C:0049H LINE# 396 |
| | | C:004CH LINE# 398 |
| | | C:004FH LINE# 400 |
| | | C:0053H LINE# 401 |
| | | C:0055H LINE# 402 |
| | | C:0057H LINE# 403 |
| | | C:0059H LINE# 405 |
| | | C:0059H LINE# 408 |
| | | C:005EH LINE# 412 |
| | | C:0061H LINE# 414 |
| | | C:0064H LINE# 418 |
| | | C:0067H LINE# 421 |
| | | C:006EH LINE# 423 |
| | | C:0076H LINE# 424 |
| | | C:074FH LINE# 368 |
| | | C:074FH LINE# 369 |
| | | C:074FH LINE# 371 |
| | | C:0752H LINE# 374 |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 8 |
| | | |
| | | |
| | | C:0755H LINE# 376 |
| | | C:0758H LINE# 380 |
| | | C:075AH LINE# 381 |
| | | C:075CH LINE# 385 |
| | | C:0761H LINE# 386 |
| | | C:076AH LINE# 387 |
| | | C:0770H LINE# 388 |
| | | C:0782H LINE# 389 |
| | | C:0785H LINE# 390 |
| | | C:0788H LINE# 394 |
| | | C:0788H LINE# 395 |
| | | C:0788H LINE# 401 |
| | | C:078DH LINE# 402 |
| | | C:0790H LINE# 403 |
| | | C:0792H LINE# 406 |
| | | C:0795H LINE# 408 |
| | | C:079EH LINE# 410 |
| | | C:07A2H LINE# 411 |
| | | C:07A4H LINE# 412 |
| | | C:07A6H LINE# 413 |
| | | C:07A8H LINE# 415 |
| | | C:07A8H LINE# 418 |
| | | C:07ADH LINE# 422 |
| | | C:07B0H LINE# 424 |
| | | C:07B3H LINE# 428 |
| | | C:07B6H LINE# 431 |
| | | C:07BDH LINE# 433 |
| | | C:07C5H LINE# 434 |
| | | ------- ENDPROC MAIN |
| | | ------- ENDMOD MAIN |
| | | |
| | | ------- MODULE SLP |
| | | C:0000H SYMBOL _ICE_DUMMY_ |
| | | D:0023H PUBLIC nCurStation |
| | | D:0024H PUBLIC SLPOKSign |
| | | D:0025H PUBLIC SendBuf |
| | | D:002DH PUBLIC SLPErrSign |
| | | D:002EH PUBLIC SLPSlaveCountOut |
| | | C:03C7H PUBLIC _SLPBCC |
| | | D:0030H PUBLIC SLPMasterRecved |
| | | D:0031H PUBLIC bSLPMaster |
| | | BL51 BANKED LINKER/LOCATER V6.22 03/17/2024 12:33:27 PAGE 9 |
| | | |
| | | |
| | | D:0032H PUBLIC SLPLostPkt |
| | | C:033FH PUBLIC SLPMasterSendPacket |
| | | D:0034H PUBLIC inputBuf |
| | | D:0039H PUBLIC outputBuf |
| | | C:02CFH PUBLIC SLPProcess |
| | | D:003EH PUBLIC nStation |
| | | D:003FH PUBLIC SLPinputB |
| | | D:0040H PUBLIC SLPoutputB |
| | | C:008EH PUBLIC _SLPparsePacket |
| | | ------- PROC L?0031 |
| | | ------- ENDPROC L?0031 |
| | | C:0053H PUBLIC _SLPInit |
| | | C:0857H PUBLIC _SLPSetCallBack |
| | | C:0835H PUBLIC _SLPBCC |
| | | C:058AH PUBLIC _SLPMasterSendPacket |
| | | C:0471H PUBLIC _SLPProcess |
| | | C:02D4H PUBLIC _SLPparsePacket |
| | | ------- PROC _SLPBCC |
| | | D:0048H SYMBOL pBuf |
| | | D:0016H SYMBOL pBuf |
| | | D:0005H SYMBOL len1 |
| | | ------- DO |
| | | D:0006H SYMBOL i |
| | | D:0007H SYMBOL BCC |
| | | ------- ENDDO |
| | | C:03C7H LINE# 23 |
| | | C:03CDH LINE# 24 |
| | | C:03CDH LINE# 26 |
| | | C:03CFH LINE# 27 |
| | | C:03D5H LINE# 28 |
| | | C:03D5H LINE# 29 |
| | | C:03E5H LINE# 30 |
| | | C:03E8H LINE# 31 |
| | | C:03E8H LINE# 32 |
| | | C:0835H LINE# 5 |
| | | C:083BH LINE# 6 |
| | | C:083BH LINE# 8 |
| | | C:083DH LINE# 9 |
| | | C:0843H LINE# 10 |
| | | C:0843H LINE# 11 |
| | | C:0853H LINE# 12 |
| | | C:0856H LINE# 13 |
| | | C:0856H LINE# 14 |
| | | ------- ENDPROC _SLPBCC |
| | | ------- PROC _SLPINIT |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 9 |
| | | |
| | | |
| | | D:0009H SYMBOL pSLP |
| | | D:000CH SYMBOL pFunc1 |
| | | C:0053H LINE# 16 |
| | | C:0059H LINE# 17 |
| | | C:0059H LINE# 18 |
| | | C:0062H LINE# 19 |
| | | C:006BH LINE# 20 |
| | | C:0083H LINE# 22 |
| | | ------- ENDPROC _SLPINIT |
| | | ------- PROC _SLPSETCALLBACK |
| | | D:0019H SYMBOL pSLP |
| | | D:001CH SYMBOL pFunc1 |
| | | C:0857H LINE# 24 |
| | | C:085DH LINE# 25 |
| | | C:085DH LINE# 26 |
| | | C:0875H LINE# 27 |
| | | ------- ENDPROC _SLPSETCALLBACK |
| | | ------- PROC _SLPPARSEPACKET |
| | | D:0001H SYMBOL pRecvBuf |
| | | D:0005H SYMBOL len1 |
| | | D:0009H SYMBOL pSLP |
| | | D:000CH SYMBOL pRecvBuf |
| | | D:000FH SYMBOL len1 |
| | | ------- DO |
| | | D:0042H SYMBOL pPacket |
| | | D:0010H SYMBOL pPacket |
| | | ------- DO |
| | | D:0045H SYMBOL pRplyPkt |
| | | D:0013H SYMBOL pRplyPkt |
| | | ------- ENDDO |
| | | ------- ENDDO |
| | | C:008EH LINE# 34 |
| | | C:008EH LINE# 35 |
| | | C:008EH LINE# 37 |
| | | C:0094H LINE# 38 |
| | | C:009CH LINE# 40 |
| | | C:00B4H LINE# 41 |
| | | C:00B8H LINE# 42 |
| | | C:00B8H LINE# 43 |
| | | C:00BEH LINE# 44 |
| | | C:00BEH LINE# 46 |
| | | C:00C7H LINE# 47 |
| | | C:00CAH LINE# 48 |
| | | C:00CFH LINE# 49 |
| | | C:00DDH LINE# 50 |
| | | C:00DDH LINE# 51 |
| | | C:00DDH LINE# 53 |
| | | C:00E0H LINE# 54 |
| | | C:00E1H LINE# 55 |
| | | C:00E1H LINE# 56 |
| | | C:00E8H LINE# 57 |
| | | BL51 BANKED LINKER/LOCATER V6.22 03/17/2024 12:33:27 PAGE 10 |
| | | C:02D4H LINE# 29 |
| | | C:02DAH LINE# 30 |
| | | C:02DAH LINE# 32 |
| | | C:02E6H LINE# 33 |
| | | C:02EFH LINE# 35 |
| | | C:0308H LINE# 36 |
| | | C:0316H LINE# 37 |
| | | C:0316H LINE# 38 |
| | | C:0323H LINE# 39 |
| | | C:0323H LINE# 41 |
| | | C:033FH LINE# 42 |
| | | C:034CH LINE# 43 |
| | | C:0355H LINE# 44 |
| | | C:0382H LINE# 45 |
| | | C:0382H LINE# 46 |
| | | C:0382H LINE# 48 |
| | | C:0394H LINE# 49 |
| | | C:0394H LINE# 50 |
| | | C:0394H LINE# 51 |
| | | C:03A4H LINE# 52 |
| | | C:03A4H LINE# 54 |
| | | C:03B3H LINE# 55 |
| | | C:03D2H LINE# 56 |
| | | C:03E4H LINE# 57 |
| | | C:03EDH LINE# 59 |
| | | C:03F8H LINE# 60 |
| | | C:0410H LINE# 61 |
| | | C:0428H LINE# 62 |
| | | C:0445H LINE# 65 |
| | | C:0470H LINE# 66 |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 10 |
| | | |
| | | |
| | | C:00E8H LINE# 59 |
| | | C:00F0H LINE# 60 |
| | | C:0100H LINE# 61 |
| | | C:0108H LINE# 62 |
| | | C:010DH LINE# 64 |
| | | C:0118H LINE# 65 |
| | | C:0126H LINE# 66 |
| | | C:012BH LINE# 67 |
| | | C:013BH LINE# 70 |
| | | C:0145H LINE# 71 |
| | | C:0145H LINE# 72 |
| | | C:0145H LINE# 73 |
| | | C:0145H LINE# 74 |
| | | C:0470H LINE# 67 |
| | | C:0470H LINE# 68 |
| | | C:0470H LINE# 69 |
| | | ------- ENDPROC _SLPPARSEPACKET |
| | | ------- PROC SLPMASTERSENDPACKET |
| | | ------- PROC _SLPMASTERSENDPACKET |
| | | D:000CH SYMBOL pSLP |
| | | ------- DO |
| | | D:0042H SYMBOL pReqPkt |
| | | D:000FH SYMBOL pReqPkt |
| | | ------- ENDDO |
| | | C:033FH LINE# 76 |
| | | C:033FH LINE# 77 |
| | | C:033FH LINE# 79 |
| | | C:0348H LINE# 80 |
| | | C:034BH LINE# 82 |
| | | C:0356H LINE# 83 |
| | | C:0364H LINE# 84 |
| | | C:036DH LINE# 85 |
| | | C:037DH LINE# 88 |
| | | ------- ENDPROC SLPMASTERSENDPACKET |
| | | ------- PROC SLPPROCESS |
| | | ------- DO |
| | | D:0021H SYMBOL nCount |
| | | ------- ENDDO |
| | | C:02CFH LINE# 90 |
| | | C:02CFH LINE# 91 |
| | | C:02CFH LINE# 93 |
| | | C:02D3H LINE# 94 |
| | | C:02D3H LINE# 95 |
| | | C:02D9H LINE# 96 |
| | | C:02D9H LINE# 97 |
| | | C:02DDH LINE# 99 |
| | | C:02E0H LINE# 100 |
| | | C:02E6H LINE# 102 |
| | | C:02E8H LINE# 103 |
| | | C:02F0H LINE# 104 |
| | | C:02F9H LINE# 105 |
| | | C:02FCH LINE# 106 |
| | | C:02FFH LINE# 107 |
| | | C:02FFH LINE# 108 |
| | | C:02FFH LINE# 109 |
| | | C:0306H LINE# 110 |
| | | C:0308H LINE# 111 |
| | | C:030FH LINE# 112 |
| | | C:0312H LINE# 113 |
| | | C:0312H LINE# 114 |
| | | C:0315H LINE# 115 |
| | | C:0318H LINE# 116 |
| | | C:0318H LINE# 117 |
| | | BL51 BANKED LINKER/LOCATER V6.22 03/17/2024 12:33:27 PAGE 11 |
| | | C:058AH LINE# 71 |
| | | C:0590H LINE# 72 |
| | | C:0590H LINE# 74 |
| | | C:059CH LINE# 75 |
| | | C:05AAH LINE# 77 |
| | | C:05B5H LINE# 78 |
| | | C:05CDH LINE# 79 |
| | | C:05F8H LINE# 80 |
| | | C:0615H LINE# 83 |
| | | ------- ENDPROC _SLPMASTERSENDPACKET |
| | | ------- PROC _SLPPROCESS |
| | | D:0009H SYMBOL pSLP |
| | | C:0471H LINE# 86 |
| | | C:0477H LINE# 87 |
| | | C:0477H LINE# 88 |
| | | C:047FH LINE# 89 |
| | | C:047FH LINE# 90 |
| | | C:048CH LINE# 91 |
| | | C:048CH LINE# 92 |
| | | C:0494H LINE# 94 |
| | | C:049CH LINE# 95 |
| | | C:04B2H LINE# 97 |
| | | C:04B4H LINE# 98 |
| | | C:04C4H LINE# 99 |
| | | C:04D3H LINE# 100 |
| | | C:04E1H LINE# 101 |
| | | C:04E8H LINE# 102 |
| | | C:04E8H LINE# 103 |
| | | C:04E8H LINE# 104 |
| | | C:04FCH LINE# 105 |
| | | C:0504H LINE# 106 |
| | | C:0515H LINE# 107 |
| | | C:0523H LINE# 108 |
| | | C:0523H LINE# 109 |
| | | C:0530H LINE# 110 |
| | | C:0533H LINE# 111 |
| | | C:0533H LINE# 112 |
| | | C:0533H LINE# 113 |
| | | C:0535H LINE# 114 |
| | | C:0535H LINE# 115 |
| | | C:0545H LINE# 116 |
| | | C:0554H LINE# 117 |
| | | C:0554H LINE# 118 |
| | | C:0562H LINE# 119 |
| | | C:0564H LINE# 120 |
| | | C:057AH LINE# 121 |
| | | C:057AH LINE# 122 |
| | | C:057AH LINE# 123 |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 11 |
| | | |
| | | |
| | | C:0318H LINE# 118 |
| | | C:031AH LINE# 119 |
| | | C:031AH LINE# 120 |
| | | C:0322H LINE# 121 |
| | | C:032BH LINE# 122 |
| | | C:032BH LINE# 123 |
| | | C:032EH LINE# 124 |
| | | C:0330H LINE# 125 |
| | | C:0336H LINE# 126 |
| | | C:0336H LINE# 127 |
| | | C:0336H LINE# 128 |
| | | C:033EH LINE# 129 |
| | | ------- ENDPROC SLPPROCESS |
| | | ------- ENDPROC _SLPPROCESS |
| | | ------- ENDMOD SLP |
| | | |
| | | ------- MODULE MODBUS |
| | | C:0000H SYMBOL _ICE_DUMMY_ |
| | | C:04BBH PUBLIC ModbusProcess |
| | | C:04AEH PUBLIC _ModbusparsePacket |
| | | C:001AH PUBLIC ModbusProcess |
| | | C:000EH PUBLIC _ModbusparsePacket |
| | | ------- PROC _MODBUSPARSEPACKET |
| | | D:0042H SYMBOL pBuf |
| | | D:0045H SYMBOL len1 |
| | | C:04AEH LINE# 4 |
| | | C:04B6H LINE# 5 |
| | | C:04B6H LINE# 6 |
| | | D:0009H SYMBOL pBuf |
| | | D:000CH SYMBOL len1 |
| | | C:000EH LINE# 4 |
| | | C:0016H LINE# 5 |
| | | C:0016H LINE# 6 |
| | | ------- ENDPROC _MODBUSPARSEPACKET |
| | | ------- PROC MODBUSPROCESS |
| | | C:04BBH LINE# 8 |
| | | C:04BBH LINE# 9 |
| | | C:04BBH LINE# 12 |
| | | C:001AH LINE# 8 |
| | | C:001AH LINE# 9 |
| | | C:001AH LINE# 12 |
| | | ------- ENDPROC MODBUSPROCESS |
| | | ------- ENDMOD MODBUS |
| | | |
| | | ------- MODULE ?C?CLDPTR |
| | | C:0255H PUBLIC ?C?CLDPTR |
| | | C:008EH PUBLIC ?C?CLDPTR |
| | | ------- ENDMOD ?C?CLDPTR |
| | | |
| | | ------- MODULE ?C?CLDOPTR |
| | | C:026EH PUBLIC ?C?CLDOPTR |
| | | C:00A7H PUBLIC ?C?CLDOPTR |
| | | ------- ENDMOD ?C?CLDOPTR |
| | | |
| | | ------- MODULE ?C?CILDOPTR |
| | | C:00D4H PUBLIC ?C?CILDOPTR |
| | | ------- ENDMOD ?C?CILDOPTR |
| | | |
| | | ------- MODULE ?C?CSTPTR |
| | | C:029BH PUBLIC ?C?CSTPTR |
| | | C:0107H PUBLIC ?C?CSTPTR |
| | | ------- ENDMOD ?C?CSTPTR |
| | | |
| | | ------- MODULE ?C?CSTOPTR |
| | | C:02ADH PUBLIC ?C?CSTOPTR |
| | | C:0119H PUBLIC ?C?CSTOPTR |
| | | ------- ENDMOD ?C?CSTOPTR |
| | | |
| | | *** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS |
| | | SEGMENT: ?PR?_DELAY_MS?MAIN |
| | | ------- MODULE ?C?ILDOPTR |
| | | C:013BH PUBLIC ?C?ILDOPTR |
| | | ------- ENDMOD ?C?ILDOPTR |
| | | |
| | | Program Size: data=74.2 xdata=0 code=1212 |
| | | ------- MODULE ?C?IILDOPTR |
| | | C:0173H PUBLIC ?C?IILDOPTR |
| | | ------- ENDMOD ?C?IILDOPTR |
| | | |
| | | ------- MODULE ?C?ISTOPTR |
| | | C:01C0H PUBLIC ?C?ISTOPTR |
| | | ------- ENDMOD ?C?ISTOPTR |
| | | |
| | | ------- MODULE ?C?PLDOPTR |
| | | C:01EDH PUBLIC ?C?PLDOPTR |
| | | ------- ENDMOD ?C?PLDOPTR |
| | | |
| | | BL51 BANKED LINKER/LOCATER V6.22 06/13/2024 13:47:31 PAGE 12 |
| | | |
| | | |
| | | ------- MODULE ?C?PSTOPTR |
| | | C:021DH PUBLIC ?C?PSTOPTR |
| | | ------- ENDMOD ?C?PSTOPTR |
| | | |
| | | ------- MODULE ?C?ICALL |
| | | C:0276H PUBLIC ?C?ICALL |
| | | C:027AH PUBLIC ?C?ICALL2 |
| | | ------- ENDMOD ?C?ICALL |
| | | |
| | | ------- MODULE ?C?IILDX |
| | | C:027CH PUBLIC ?C?IILDX |
| | | ------- ENDMOD ?C?IILDX |
| | | |
| | | ------- MODULE ?C?PLDIDATA |
| | | C:0292H PUBLIC ?C?PLDIDATA |
| | | ------- ENDMOD ?C?PLDIDATA |
| | | |
| | | ------- MODULE ?C?PSTIDATA |
| | | C:029BH PUBLIC ?C?PSTIDATA |
| | | ------- ENDMOD ?C?PSTIDATA |
| | | |
| | | ------- MODULE ?C?PLDXDATA |
| | | C:02A4H PUBLIC ?C?PLDXDATA |
| | | ------- ENDMOD ?C?PLDXDATA |
| | | |
| | | ------- MODULE ?C?PSTXDATA |
| | | C:02ADH PUBLIC ?C?PSTXDATA |
| | | ------- ENDMOD ?C?PSTXDATA |
| | | |
| | | ------- MODULE ?C?PLDPDATA |
| | | C:02B6H PUBLIC ?C?PLDPDATA |
| | | ------- ENDMOD ?C?PLDPDATA |
| | | |
| | | ------- MODULE ?C?PSTPDATA |
| | | C:02BFH PUBLIC ?C?PSTPDATA |
| | | ------- ENDMOD ?C?PSTPDATA |
| | | |
| | | ------- MODULE ?C?PLDCODE |
| | | C:02C8H PUBLIC ?C?PLDCODE |
| | | ------- ENDMOD ?C?PLDCODE |
| | | |
| | | *** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS |
| | | SEGMENT: ?PR?_SLPSETCALLBACK?SLP |
| | | |
| | | Program Size: data=92.2 xdata=0 code=2247 |
| | | LINK/LOCATE RUN COMPLETE. 1 WARNING(S), 0 ERROR(S) |
New file |
| | |
| | | "SLP.c" OPTIMIZE (8,SPEED) BROWSE INCDIR(.\user;.\drivers) DEBUG OBJECTEXTEND PRINT(.\Listings\SLP.lst) TABS (2) OBJECT(.\Objects\SLP.obj) |
| | |
| | | |
| | | #include "SLP.h" |
| | | |
| | | void SLPSendPacket(char * buf, uchar len1); |
| | | uchar bSLPMaster; |
| | | uchar nStation; |
| | | uchar SLPinputB; |
| | | uchar SLPoutputB; |
| | | uchar nCurStation; |
| | | uchar inputBuf[5]; |
| | | uchar outputBuf[5]; |
| | | |
| | | uchar SendBuf[8]; |
| | | |
| | | uchar SLPMasterRecved; //主æºæ¶å°åæºåå¤ |
| | | unsigned int SLPSlaveCountOut; |
| | | |
| | | unsigned int SLPLostPkt=0; // 丢å
æ°é |
| | | |
| | | uchar SLPOKSign; |
| | | uchar SLPErrSign; |
| | | //void SLPSendPacket(char * buf, uchar len1); |
| | | |
| | | uchar SLPBCC(char * pBuf, uchar len1) |
| | | { |
| | |
| | | return BCC; |
| | | } |
| | | |
| | | void SLPparsePacket(char * pRecvBuf, uchar len1) |
| | | void SLPInit(stSLPDef * pSLP, SLPSendPktDef pFunc1) |
| | | { |
| | | pSLP->SLPLostPkt = 0; |
| | | pSLP->nCount = 0; |
| | | pSLP->SLPSendPktFunc = pFunc1; |
| | | |
| | | } |
| | | |
| | | void SLPSetCallBack(stSLPDef * pSLP, SLPSendPktDef pFunc1) |
| | | { |
| | | pSLP->SLPSendPktFunc = pFunc1; |
| | | } |
| | | |
| | | void SLPparsePacket(stSLPDef * pSLP, char * pRecvBuf, uchar len1) |
| | | { |
| | | |
| | | stSLPPacket * pPacket = (stSLPPacket *)pRecvBuf; |
| | | if (len1 != sizeof(stSLPPacket)) return; |
| | | // if (pPacket->ED != EDsign) return; |
| | | if (pPacket->BCC != SLPBCC(pRecvBuf,len1-1)) return; |
| | | if (bSLPMaster) //master |
| | | if (pSLP->bSLPMaster) //master |
| | | { |
| | | if (pPacket->ST ==ST_S) |
| | | { |
| | | //check |
| | | if (pPacket->Dst == nCurStation) { |
| | | SLPMasterRecved=1; |
| | | SLPLostPkt=0; |
| | | inputBuf[nCurStation] = pPacket->Data; |
| | | if (pPacket->Dst == pSLP->nCurStation) { |
| | | pSLP->SLPMasterRecved=1; |
| | | pSLP->SLPLostPkt=0; |
| | | pSLP->inputBuf[pSLP->nCurStation] = pPacket->Data; |
| | | } |
| | | } |
| | | // SLPoutputB = (inputBuf[1] &0x0f) | ((inputBuf[2] &0x0f) << 4); |
| | | SLPoutputB = inputBuf[1]; |
| | | pSLP->SLPoutputB = pSLP->inputBuf[1]; |
| | | }else |
| | | { //slave |
| | | if (pPacket->ST==ST_M) |
| | | { |
| | | //check |
| | | stSLPPacket * pRplyPkt = (stSLPPacket *)SendBuf; |
| | | if (pPacket->Dst == nStation) { |
| | | SLPoutputB = pPacket->Data; |
| | | SLPSlaveCountOut=0; |
| | | stSLPPacket * pRplyPkt = (stSLPPacket *)pSLP->SendBuf; |
| | | if (pPacket->Dst == pSLP->nStation) { |
| | | pSLP->SLPoutputB = pPacket->Data; |
| | | pSLP->SLPSlaveCountOut=0; |
| | | |
| | | pRplyPkt->ST = ST_S; |
| | | pRplyPkt->Dst = nStation; |
| | | pRplyPkt->Data = SLPinputB; |
| | | pRplyPkt->BCC = SLPBCC(SendBuf, sizeof(stSLPPacket)-1); |
| | | pRplyPkt->Dst = pSLP->nStation; |
| | | pRplyPkt->Data = pSLP->SLPinputB; |
| | | pRplyPkt->BCC = SLPBCC(pSLP->SendBuf, sizeof(stSLPPacket)-1); |
| | | // pRplyPkt->ED = EDsign; |
| | | |
| | | SLPSendPacket(SendBuf,sizeof(stSLPPacket)); |
| | | pSLP->SLPSendPktFunc(pSLP->SendBuf,sizeof(stSLPPacket)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | void SLPMasterSendPacket(void) |
| | | void SLPMasterSendPacket(stSLPDef * pSLP) |
| | | { |
| | | |
| | | stSLPPacket * pReqPkt = (stSLPPacket *)SendBuf; |
| | | outputBuf[1]=SLPinputB ;//&0xf; |
| | | stSLPPacket * pReqPkt = (stSLPPacket *)pSLP->SendBuf; |
| | | pSLP->outputBuf[1]=pSLP->SLPinputB ;//&0xf; |
| | | // outputBuf[2] = (SLPinputB & 0xf0) >> 4; |
| | | pReqPkt->ST = ST_M; |
| | | pReqPkt->Dst = nCurStation; |
| | | pReqPkt->Data = outputBuf[nCurStation]; ; |
| | | pReqPkt->BCC = SLPBCC(SendBuf, sizeof(stSLPPacket)-1); |
| | | pReqPkt->Dst = pSLP->nCurStation; |
| | | pReqPkt->Data = pSLP->outputBuf[pSLP->nCurStation]; ; |
| | | pReqPkt->BCC = SLPBCC(pSLP->SendBuf, sizeof(stSLPPacket)-1); |
| | | // pReqPkt->ED = EDsign; |
| | | |
| | | SLPSendPacket(SendBuf,sizeof(stSLPPacket)); |
| | | pSLP->SLPSendPktFunc(pSLP->SendBuf,sizeof(stSLPPacket)); |
| | | } |
| | | void SLPProcess(void) |
| | | |
| | | void SLPProcess(stSLPDef * pSLP) |
| | | { |
| | | static int nCount =0; |
| | | if (bSLPMaster) //master |
| | | if (pSLP->bSLPMaster) //master |
| | | { |
| | | if ( (nCount & 0xf) == 0 ) |
| | | if ( (pSLP->nCount & 0xf) == 0 ) |
| | | { //time up |
| | | if (SLPMasterRecved) { |
| | | if (pSLP->SLPMasterRecved) { |
| | | // SLPMasterRecved=0; |
| | | SLPOKSign = 1; |
| | | if (SLPErrSign) SLPErrSign--; |
| | | pSLP->SLPOKSign = 1; |
| | | if (pSLP->SLPErrSign) pSLP->SLPErrSign--; |
| | | |
| | | }else { |
| | | SLPLostPkt++; |
| | | if (SLPLostPkt > 10) { |
| | | SLPErrSign=20; |
| | | SLPOKSign = 0; |
| | | pSLP->SLPLostPkt++; |
| | | if (pSLP->SLPLostPkt > 10) { |
| | | pSLP->SLPErrSign=20; |
| | | pSLP->SLPOKSign = 0; |
| | | } |
| | | } |
| | | if (nStation >0) { |
| | | nCurStation++; |
| | | if (nCurStation > nStation) { |
| | | nCurStation =1; |
| | | if (pSLP->nStation >0) { |
| | | pSLP->nCurStation++; |
| | | if (pSLP->nCurStation > pSLP->nStation) { |
| | | pSLP->nCurStation =1; |
| | | } |
| | | SLPMasterRecved=0; |
| | | SLPMasterSendPacket(); |
| | | pSLP->SLPMasterRecved=0; |
| | | SLPMasterSendPacket(pSLP); |
| | | } |
| | | } |
| | | }else |
| | | { |
| | | SLPSlaveCountOut ++; |
| | | if (SLPSlaveCountOut >200) // 20mS |
| | | pSLP->SLPSlaveCountOut ++; |
| | | if (pSLP->SLPSlaveCountOut >200) // 20mS |
| | | { |
| | | SLPErrSign=100; |
| | | pSLP->SLPErrSign=100; |
| | | }else { |
| | | if (SLPErrSign) SLPErrSign--; |
| | | if (pSLP->SLPErrSign) pSLP->SLPErrSign--; |
| | | } |
| | | } |
| | | nCount++; |
| | | pSLP->nCount++; |
| | | } |
| | |
| | | // uchar ED; |
| | | }stSLPPacket; |
| | | |
| | | extern uchar bSLPMaster; |
| | | extern uchar nStation; |
| | | extern uchar SLPinputB; |
| | | extern uchar SLPoutputB; |
| | | extern uchar SLPErrSign; |
| | | //extern uchar bSLPMaster; |
| | | //extern uchar nStation; |
| | | //extern uchar SLPinputB; |
| | | //extern uchar SLPoutputB; |
| | | //extern uchar SLPErrSign; |
| | | |
| | | void SLPparsePacket(char * pBuf, uchar len1); |
| | | void SLPMasterSendPacket(void); |
| | | void SLPProcess(void); |
| | | typedef void (*SLPSendPktDef)(char * pBuf, int Len1); |
| | | |
| | | |
| | | typedef struct tagSLPDef |
| | | { |
| | | uchar bSLPMaster; |
| | | uchar nStation; |
| | | uchar SLPinputB; |
| | | uchar SLPoutputB; |
| | | uchar nCurStation; |
| | | uchar inputBuf[5]; |
| | | uchar outputBuf[5]; |
| | | |
| | | uchar SendBuf[8]; |
| | | |
| | | uchar SLPMasterRecved; //主æºæ¶å°åæºåå¤ |
| | | |
| | | SLPSendPktDef SLPSendPktFunc; |
| | | |
| | | unsigned int SLPSlaveCountOut; |
| | | |
| | | unsigned int SLPLostPkt; // 丢å
æ°é |
| | | |
| | | uchar SLPOKSign; |
| | | uchar SLPErrSign; |
| | | |
| | | int nCount; |
| | | |
| | | }stSLPDef; |
| | | |
| | | void SLPInit(stSLPDef * pSLP, SLPSendPktDef pFunc1); |
| | | void SLPSetCallBack(stSLPDef * pSLP, SLPSendPktDef pFunc1); |
| | | |
| | | void SLPparsePacket(stSLPDef * pSLP, char * pBuf, uchar len1); |
| | | void SLPMasterSendPacket(stSLPDef * pSLP); |
| | | void SLPProcess(stSLPDef * pSLP); |
| | | |
| | | |
| | | #endif /* __SLP_H_V10__ */ |
| | |
| | | |
| | | int nCount=0; |
| | | |
| | | stSLPDef SLP1; |
| | | |
| | | unsigned char bSLPMaster; |
| | | unsigned char nSLPStation; |
| | | |
| | | |
| | | void PutOutput(uchar a); |
| | |
| | | }Coils; |
| | | |
| | | Coils inputdata; |
| | | |
| | | /* |
| | | void Delay1ms() //@22.1184MHz |
| | | { |
| | | uchar data i, j; |
| | |
| | | } while (--i); |
| | | } |
| | | |
| | | |
| | | void Delay_ms(uint n) |
| | | { |
| | | while(n--) |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | */ |
| | | void Delay_us(uint n) |
| | | { |
| | | uchar data j; |
| | |
| | | uart3busy=1; |
| | | } |
| | | } |
| | | /* |
| | | void SLPSendPacket(char * str, uchar len) |
| | | { |
| | | Uart3SendPacket(str,len); |
| | | } |
| | | |
| | | */ |
| | | void Uart3RecvPacket() |
| | | { |
| | | if (uart3recvtimeout <2){ |
| | |
| | | }else |
| | | { /// recieved packet; |
| | | RUN=~RUN; //éªç¯ |
| | | SLPparsePacket(uart3recvbuf,uart3recvlen); |
| | | SLPparsePacket(&SLP1,uart3recvbuf,uart3recvlen); |
| | | uart3recvlen =0; |
| | | } |
| | | } |
| | |
| | | |
| | | inputdata.Byte = GetJumper(); |
| | | bSLPMaster = inputdata.bits.b5 ; //master? |
| | | nStation = inputdata.Byte & 0x0f; |
| | | nSLPStation = inputdata.Byte & 0x0f; |
| | | SLPInit(&SLP1,Uart3SendPacket); |
| | | SLP1.bSLPMaster = bSLPMaster; |
| | | SLP1.nStation = nSLPStation; |
| | | |
| | | // bSLPMaster=1; |
| | | |
| | | while(1) |
| | |
| | | |
| | | // Get Input Port; |
| | | inputdata.Byte = GetInput(); |
| | | SLPinputB = inputdata.Byte; |
| | | SLP1.SLPinputB = inputdata.Byte; |
| | | RUN =~ RUN; |
| | | // Delay_ms(1); |
| | | // receive packet |
| | | Uart3RecvPacket(); |
| | | // Process Packet |
| | | SLPProcess(); |
| | | SLPProcess(&SLP1); |
| | | |
| | | if (SLPErrSign) { |
| | | if (SLP1.SLPErrSign) { |
| | | ERR = 0; |
| | | }else { |
| | | ERR =1; |
| | |
| | | } |
| | | |
| | | // Set Ouput Port |
| | | PutOutput(SLPoutputB); |
| | | PutOutput(SLP1.SLPoutputB); |
| | | |
| | | |
| | | // receive packet |
File was renamed from MDK-ARM/F030CCT6_KMini.uvprojx |
| | |
| | | <FileType>5</FileType> |
| | | <FilePath>..\KMini_CCT6\Inc\lidar.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>LindarPos.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\KMini_CCT6\Inc\LindarPos.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>OrdLidar.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\KMini_CCT6\Inc\OrdLidar.h</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | | <Group> |
| | |
| | | <FileName>lidar.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\KMini_CCT6\Src\lidar.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>LidarPos.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\KMini_CCT6\Src\LidarPos.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>OrdLidar.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\KMini_CCT6\Src\OrdLidar.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_tim.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_flash.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_flash.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | | <Group> |
File was renamed from MDK-ARM/F030C8T6_KPLC.uvprojx |
| | |
| | | </OCR_RVCT3> |
| | | <OCR_RVCT4> |
| | | <Type>1</Type> |
| | | <StartAddress>0x8000000</StartAddress> |
| | | <Size>0x10000</Size> |
| | | <StartAddress>0x8001000</StartAddress> |
| | | <Size>0xf000</Size> |
| | | </OCR_RVCT4> |
| | | <OCR_RVCT5> |
| | | <Type>1</Type> |
| | |
| | | </OCR_RVCT8> |
| | | <OCR_RVCT9> |
| | | <Type>0</Type> |
| | | <StartAddress>0x20000000</StartAddress> |
| | | <Size>0x2000</Size> |
| | | <StartAddress>0x200000c0</StartAddress> |
| | | <Size>0x1f40</Size> |
| | | </OCR_RVCT9> |
| | | <OCR_RVCT10> |
| | | <Type>0</Type> |
| | |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_tim.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_flash.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_flash.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | | <Group> |
| | |
| | | * Auto generated Run-Time-Environment Component Configuration File |
| | | * *** Do not modify ! *** |
| | | * |
| | | * Project: 'F030C8T6_KBus' |
| | | * Project: 'KBus_C8T6_8è·¯16路模å' |
| | | * Target: 'F030C8T6_KBus' |
| | | */ |
| | | |
| | |
| | | * Auto generated Run-Time-Environment Component Configuration File |
| | | * *** Do not modify ! *** |
| | | * |
| | | * Project: 'F030C8T6_KLink' |
| | | * Project: 'KLink_C8T6' |
| | | * Target: 'F030C8T6_KLink' |
| | | */ |
| | | |
| | |
| | | * Auto generated Run-Time-Environment Component Configuration File |
| | | * *** Do not modify ! *** |
| | | * |
| | | * Project: 'F030C8T6_KNet' |
| | | * Project: 'F030C8T6_KNet_ç½å£æ¨¡å' |
| | | * Target: 'F030C8T6_KNet' |
| | | */ |
| | | |
File was renamed from MDK-ARM/F030C8T6_Radio_LLCC68.uvprojx |
| | |
| | | <InvalidFlash>1</InvalidFlash> |
| | | </TargetStatus> |
| | | <OutputDirectory>.\F030C8T6_Radio\</OutputDirectory> |
| | | <OutputName>F030C8T6_Radio_LLCC68</OutputName> |
| | | <OutputName>Radio_LLCC68</OutputName> |
| | | <CreateExecutable>1</CreateExecutable> |
| | | <CreateLib>0</CreateLib> |
| | | <CreateHexFile>1</CreateHexFile> |
| | |
| | | </OCR_RVCT3> |
| | | <OCR_RVCT4> |
| | | <Type>1</Type> |
| | | <StartAddress>0x8000000</StartAddress> |
| | | <Size>0x10000</Size> |
| | | <StartAddress>0x8001000</StartAddress> |
| | | <Size>0xf000</Size> |
| | | </OCR_RVCT4> |
| | | <OCR_RVCT5> |
| | | <Type>1</Type> |
| | |
| | | </OCR_RVCT8> |
| | | <OCR_RVCT9> |
| | | <Type>0</Type> |
| | | <StartAddress>0x20000000</StartAddress> |
| | | <Size>0x2000</Size> |
| | | <StartAddress>0x200000c0</StartAddress> |
| | | <Size>0x1f40</Size> |
| | | </OCR_RVCT9> |
| | | <OCR_RVCT10> |
| | | <Type>0</Type> |
| | |
| | | </ArmAdsMisc> |
| | | <Cads> |
| | | <interw>1</interw> |
| | | <Optim>4</Optim> |
| | | <Optim>7</Optim> |
| | | <oTime>0</oTime> |
| | | <SplitLS>0</SplitLS> |
| | | <OneElfS>1</OneElfS> |
| | |
| | | <uSurpInc>0</uSurpInc> |
| | | <uC99>1</uC99> |
| | | <useXO>0</useXO> |
| | | <v6Lang>1</v6Lang> |
| | | <v6LangP>1</v6LangP> |
| | | <v6Lang>3</v6Lang> |
| | | <v6LangP>3</v6LangP> |
| | | <vShortEn>1</vShortEn> |
| | | <vShortWch>1</vShortWch> |
| | | <v6Lto>0</v6Lto> |
| | |
| | | <FileType>5</FileType> |
| | | <FilePath>..\Radio_LLCC68\Inc\stm32f0xx_hal_conf.h</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>ATModem.h</FileName> |
| | | <FileType>5</FileType> |
| | | <FilePath>..\Radio_LLCC68\Inc\ATModem.h</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | | <Group> |
| | |
| | | <FileName>BoardType.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Radio_LLCC68\Src\BoardType.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>ATModem.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Radio_LLCC68\Src\ATModem.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_tim.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>stm32f0xx_ll_flash.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>..\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_ll_flash.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | | </Groups> |
New file |
| | |
| | | #ifndef __ATMODEM_H_V10__ |
| | | #define __ATMODEM_H_V10__ |
| | | |
| | | typedef unsigned char uchar; |
| | | |
| | | enum ATCmds |
| | | { |
| | | ST_M = 0x49, |
| | | ST_S = 0x69, |
| | | EDsign = 0x0d, |
| | | }; |
| | | |
| | | typedef void (*ATSendPktDef)(char * pBuf, int Len1); |
| | | |
| | | |
| | | typedef struct tagATModemDef |
| | | { |
| | | ATSendPktDef ATSendPktFunc; |
| | | uchar inputBuf[5]; |
| | | uchar outputBuf[5]; |
| | | uchar SendBuf[8]; |
| | | |
| | | }stATModemDef; |
| | | |
| | | void ATInit(stATModemDef * pATModem, ATSendPktDef pFunc1); |
| | | void ATSetCallBack(stATModemDef * pATModem, ATSendPktDef pFunc1); |
| | | |
| | | int ATParsePacket(stATModemDef * pATModem, char * pBuf, uchar len1); |
| | | void ATProcess(stATModemDef * pATModem); |
| | | |
| | | |
| | | #endif /* __ATMODEM_H_V10__ */ |
| | |
| | | |
| | | }; |
| | | |
| | | #define BOARD_TYPE 15 |
| | | #define BOARD_TYPE 16 |
| | | #define BOARD_VER 1 |
| | | |
| | | #if (BOARD_TYPE == 11) |
| | |
| | | |
| | | #define GetBoardType() (BOARD_TYPE) |
| | | |
| | | #define PLCFUNC 1 |
| | | |
| | | #if ( BOARD_TYPE == 1) |
| | | #define DINPUT 4 |
| | | #define DOUTPUT 4 |
| | | #elif (BOARD_TYPE == 2 || BOARD_TYPE == 4 || BOARD_TYPE == 6 || BOARD_TYPE == 8 || BOARD_TYPE == 10 || BOARD_TYPE == 11 || BOARD_TYPE == 16) |
| | | #elif (BOARD_TYPE == 2 || BOARD_TYPE == 4 || BOARD_TYPE == 6 || BOARD_TYPE == 8 || BOARD_TYPE == 10 || BOARD_TYPE == 11 ) |
| | | #define DINPUT 8 |
| | | #define DOUTPUT 8 |
| | | #elif BOARD_TYPE == 3 || BOARD_TYPE == 5 || BOARD_TYPE == 7 || BOARD_TYPE == 9 || BOARD_TYPE == 13 || BOARD_TYPE == 15 |
| | | #elif BOARD_TYPE == 3 || BOARD_TYPE == 5 || BOARD_TYPE == 7 || BOARD_TYPE == 9 || BOARD_TYPE == 13 |
| | | #define DINPUT 16 |
| | | #define DOUTPUT 16 |
| | | #elif BOARD_TYPE == 14 |
| | | #define DINPUT 0 |
| | | #define DOUTPUT 6 |
| | | #elif (BOARD_TYPE == 15) |
| | | #define DINPUT 16 |
| | | #define DOUTPUT 16 |
| | | #elif (BOARD_TYPE == 16) |
| | | #define DINPUT 16 |
| | | #define DOUTPUT 16 |
| | | #define EXDINPUT 8 |
| | | #define EXDOUPUT 8 |
| | | #else |
| | | #define DINPUT 0 |
| | | #define DOUTPUT 0 |
| | | #endif |
| | | |
| | | typedef struct tagInfoBlockHdr { |
| | | unsigned short nBlkSign; // å¼å§æ å¿ |
| | | unsigned short nBlkTypeVer; // ç±»ååçæ¬ |
| | | unsigned short nBlkSize; // Block 大å°, å
æ¬å¼å§åç»ææ å¿ |
| | | unsigned short Pad1; |
| | | }stInfoBlockHdr; |
| | | |
| | | typedef struct tagInfoBlockTail { |
| | | |
| | | unsigned short CRC16; |
| | | unsigned short EndSign; |
| | | }stInfoBlockTail; |
| | | |
| | | typedef struct tagBtLdrInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nBtldrVer; |
| | | unsigned short nBtldrDevice; |
| | | unsigned short nBtldrSize; // è®¾è®¡å¤§å° |
| | | unsigned short nBtldrDataSize; //代ç å¤§å° |
| | | unsigned int nBtldr_AppAddr; |
| | | unsigned int nBtldr_NewAppInfoAddr; |
| | | unsigned int nBtldr_NewAppAddr; |
| | | stInfoBlockTail tail; |
| | | }stBtLdrInfoBlock, *pBtLdrInfoBlock; |
| | | |
| | | typedef struct tagAppInfoBlock { |
| | | stInfoBlockHdr Hdr; |
| | | unsigned short nAppVer; |
| | | unsigned short nAppDevice; |
| | | unsigned short nAppSize; // 代ç è®¾è®¡å¤§å° |
| | | unsigned short nAppDataSize; //å®é
代ç å¤§å° |
| | | unsigned int nAppStartAddr; |
| | | unsigned int nAppStartOffset; |
| | | unsigned int nApp; |
| | | stInfoBlockTail tail; |
| | | }stAppInfoBlock, * pAppInfoBlock; |
| | | |
| | | |
| | | |
| | | #endif /* __BOARDTYPE_H__ */ |
| | |
| | | /* #define USE_FULL_ASSERT 1U */ |
| | | |
| | | /* USER CODE BEGIN Private defines */ |
| | | #include "KBus.h" |
| | | |
| | | extern stKBusDef KBus1; |
| | | /* USER CODE END Private defines */ |
| | | |
| | | #ifdef __cplusplus |
| | |
| | | #define USE_MODEM_LORA |
| | | //#define USE_MODEM_FSK |
| | | |
| | | /* |
| | | #define REGION_CN779 |
| | | |
| | | #if defined( REGION_AS923 ) |
| | |
| | | #error "Please define a frequency band in the compiler options." |
| | | |
| | | #endif |
| | | */ |
| | | /* |
| | | #if defined( USE_MODEM_LORA ) |
| | | |
| | | #define LORA_BANDWIDTH 1 // [0: 125 kHz, |
| | | // 1: 250 kHz, |
| | | // 2: 500 kHz, |
| | | // 3: Reserved] |
| | | #define LORA_SPREADING_FACTOR 8 // [SF5..SF12] |
| | | #define LORA_CODINGRATE 4 // [1: 4/5, |
| | | // 2: 4/6, |
| | | // 3: 4/7, |
| | | // 4: 4/8] |
| | | #define LORA_PREAMBLE_LENGTH 4 // Same for Tx and Rx |
| | | |
| | | */ |
| | | #define LORA_SYMBOL_TIMEOUT 0 // Symbols |
| | | #define LORA_FIX_LENGTH_PAYLOAD_ON false |
| | | #define LORA_IQ_INVERSION_ON false |
| | | |
| | | /* |
| | | #elif defined( USE_MODEM_FSK ) |
| | | |
| | | #define FSK_FDEV 20e3 // Hz |
| | | #define FSK_DATARATE 19.2e3 // bps |
| | | #define FSK_BANDWIDTH 60e3 // Hz >> DSB in sx126x |
| | | #define FSK_AFC_BANDWIDTH 200e3 // Hz |
| | | #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx |
| | | #define FSK_FIX_LENGTH_PAYLOAD_ON false |
| | | |
| | | #else |
| | | #error "Please define a modem in the compiler options." |
| | | #endif |
| | | */ |
| | | /* |
| | | #define nChannelSpacing 530000 // Hz |
| | | #define TX_OUTPUT_POWER 16 // 22 dBm |
| | | */ |
| | | |
| | | |
| | | extern bool IrqFired; |
| | | |
| | |
| | | * Radio events function pointer |
| | | */ |
| | | |
| | | const stWLConfig defaultWLConfig = |
| | | { |
| | | .RF_T_Freq = 430620000, // uint32_t Hz |
| | | .RF_R_Freq = 430620000, //uint32_t //Hz |
| | | .nChnSpacing = 530, // uint16_t ChannelSpacing; //kHz |
| | | .workMode = 1, // uchar workMode; //0: FSK, 1: LoRa |
| | | .Tx_Power = 22, // uchar Tx_Power; |
| | | .LoraBandWidth = 0, // uchar LoraBandWidth; // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved ] |
| | | .LoRaFactor = 5, // uchar LoRaFactor; // [SF5 .. SF 12] |
| | | .LoRaCodingRate = 1, // uchar LoRaCodingRate; // [1 : 4/5, 2: 4/6, 3: 4/7, 4: 4/8 |
| | | .NetWorkAddr = 0x00, // uint8_t NetWorkAddr; |
| | | .DeviceAddr = 0x0102, // uint16_t DeviceAddr; |
| | | .bEnableAddr = 0, // uchar bEnableAddr; |
| | | .bEnableEncrypt = 0, // uchar bEnableEncrypt; |
| | | .bEnableRelay = 0, // uchar bEnableRelay; |
| | | .LoRaPreambleLen = 4, // uchar LoRaPreamble_Len; // 2 - 12 |
| | | .bAutoReSend = 1, // èªå¨éå |
| | | }; |
| | | |
| | | //stWLConfig * pWLCfg = (stWLConfig *)&defaultWLConfig; |
| | | static RadioEvents_t RadioEvents; |
| | | |
| | | stWLConfig WLCfg ; |
| | | stWLRunStat KwRunStat; |
| | | |
| | | #if defined( USE_MODEM_LORA ) |
| | | |
| | | #define LORA_BANDWIDTH 1 // [0: 125 kHz, |
| | | // 1: 250 kHz, |
| | | // 2: 500 kHz, |
| | | // 3: Reserved] |
| | | #define LORA_SPREADING_FACTOR 8 // [SF7..SF12] |
| | | #define LORA_CODINGRATE 4 // [1: 4/5, |
| | | // 2: 4/6, |
| | | // 3: 4/7, |
| | | // 4: 4/8] |
| | | #define LORA_PREAMBLE_LENGTH 4 // Same for Tx and Rx |
| | | #define LORA_SYMBOL_TIMEOUT 0 // Symbols |
| | | #define LORA_FIX_LENGTH_PAYLOAD_ON false |
| | | #define LORA_IQ_INVERSION_ON false |
| | | |
| | | #elif defined( USE_MODEM_FSK ) |
| | | |
| | | #define FSK_FDEV 20e3 // Hz |
| | | #define FSK_DATARATE 19.2e3 // bps |
| | | #define FSK_BANDWIDTH 60e3 // Hz >> DSB in sx126x |
| | | #define FSK_AFC_BANDWIDTH 200e3 // Hz |
| | | #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx |
| | | #define FSK_FIX_LENGTH_PAYLOAD_ON false |
| | | |
| | | #else |
| | | #error "Please define a modem in the compiler options." |
| | | #endif |
| | | |
| | | typedef enum |
| | | { |
| | |
| | | }States_t; |
| | | |
| | | #define MASTER_RX_TIMEOUT_VALUE 80 //mS |
| | | #define SLAVE_RX_TIMEOUT_VALUE 250 //mS |
| | | #define CYCLE_TIME 200 //mS |
| | | #define SLAVE_RX_TIMEOUT_VALUE 400 //mS |
| | | #define CYCLE_TIME 160 //mS |
| | | |
| | | #define BUFFER_SIZE 32 // Define the payload size here |
| | | #define WL_RX_BUFFER_SIZE 256 // Define the payload size here |
| | | #define WL_TX_BUFFER_SIZE 128 // Define the payload size here |
| | | |
| | | uint16_t nTimeOnAir; |
| | | /* |
| | | const uint8_t PingMsg[] = "PING"; |
| | | const uint8_t PongMsg[] = "PONG"; |
| | | */ |
| | | |
| | | //uint16_t BufferSize = BUFFER_SIZE; |
| | | uint8_t TX_Buffer[BUFFER_SIZE]; |
| | | uint8_t RX_Buffer[BUFFER_SIZE]; |
| | | uint8_t RX_Buffer[WL_RX_BUFFER_SIZE]; |
| | | uint8_t TX_Buffer[WL_TX_BUFFER_SIZE]; |
| | | |
| | | |
| | | |
| | | States_t State = LOWPOWER; |
| | |
| | | LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_13); |
| | | } |
| | | |
| | | int LoadKwConfig(void) |
| | | { |
| | | stStoredWLConfig * pstStoredWLCFG = (stStoredWLConfig *)(STORE_KWCONFIG_BASE); |
| | | |
| | | if (pstStoredWLCFG->BlockSign == 0x55AA && pstStoredWLCFG->BlockType == 0x05) { |
| | | WLCfg = pstStoredWLCFG->WLConfig; |
| | | } else { |
| | | WLCfg = defaultWLConfig; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | int SaveKwConfig(void) |
| | | { |
| | | // stStoredWLConfig * pstStoredWLCFG = (stStoredWLConfig *)(STORE_KWCONFIG_BASE); |
| | | |
| | | stStoredWLConfig theStoredWLCFG; |
| | | theStoredWLCFG.BlockSign = 0x55AA; |
| | | theStoredWLCFG.BlockType = 0x05; |
| | | theStoredWLCFG.nSeq = 1; |
| | | theStoredWLCFG.nSize = sizeof(stWLConfig); |
| | | theStoredWLCFG.WLConfig = WLCfg; |
| | | theStoredWLCFG.nCRC16 = 0x0000; |
| | | EraseAndWriteToFlashMem(&theStoredWLCFG, (void *)STORE_KWCONFIG_BASE, sizeof(stStoredWLConfig)); |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | int KWireLessInit(bool bRadioEnableMaster, uint32_t nChn) |
| | | { |
| | | |
| | | stWLConfig * pWLCfg = & WLCfg; |
| | | RadioEnableMaster = bRadioEnableMaster; |
| | | // Radio initialization |
| | | RadioEvents.TxDone = OnTxDone; |
| | |
| | | |
| | | Radio.Init( &RadioEvents ); |
| | | nRadioChannel = nChn; |
| | | Radio.SetChannel( RF_FREQUENCY + nRadioChannel * nChannelSpacing ); |
| | | KwRunStat.RF_Freq = pWLCfg->RF_T_Freq + nRadioChannel * pWLCfg->nChnSpacing*1000; |
| | | |
| | | Radio.SetChannel( pWLCfg->RF_T_Freq + nRadioChannel * pWLCfg->nChnSpacing*1000 ); |
| | | |
| | | // Radio.WriteBuffer(0x06C0,data,2); |
| | | // Radio.ReadBuffer(0x06C0,test,2); |
| | |
| | | LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, |
| | | LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, |
| | | 0, true, 0, 0, LORA_IQ_INVERSION_ON, false ); |
| | | //*/ |
| | | // */ |
| | | |
| | | Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, |
| | | LORA_SPREADING_FACTOR, LORA_CODINGRATE, |
| | | LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, |
| | | Radio.SetTxConfig( MODEM_LORA, pWLCfg->Tx_Power, 0, pWLCfg->LoraBandWidth, |
| | | pWLCfg->LoRaFactor, pWLCfg->LoRaCodingRate, |
| | | pWLCfg->LoRaPreambleLen, LORA_FIX_LENGTH_PAYLOAD_ON, |
| | | true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); |
| | | |
| | | Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, |
| | | LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, |
| | | Radio.SetRxConfig( MODEM_LORA, pWLCfg->LoraBandWidth, pWLCfg->LoRaFactor, |
| | | pWLCfg->LoRaCodingRate, 0, pWLCfg->LoRaPreambleLen, |
| | | LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, |
| | | 0, true, 0, 0, LORA_IQ_INVERSION_ON, false ); |
| | | |
| | |
| | | 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, |
| | | 0, 0,false, false ); |
| | | #else |
| | | #error "Please define a frequency band in the compiler options." |
| | | #error "Please define a modem in the compiler options.." |
| | | #endif |
| | | SX126xSetRxTxFallbackMode(0x40); // 0x40-> FS 0x30 -> SD_XOSC 0x20 -> SD_RC |
| | | |
| | | SX126xSetCadParams(2,0,1,0,1); |
| | | SX126xSetCadParams(LORA_CAD_04_SYMBOL,0,1,LORA_CAD_ONLY,1); |
| | | |
| | | |
| | | nTimeOnAir = Radio.TimeOnAir(MODEM_LORA,14); |
| | | KwRunStat.nTimeOnAir = nTimeOnAir; |
| | | KMem.WDT[38]=nTimeOnAir; |
| | | KwRunStat.runStep=RS_IDEL; |
| | | return 0; |
| | | } |
| | |
| | | |
| | | void OnTxDone( void ) |
| | | { |
| | | KwRunStat.bMasterSent = 1; |
| | | KwRunStat.bMasterRecved = 0; |
| | | KwRunStat.runStep=RS_IDEL; |
| | | KMem.WDT[42]++; |
| | | KwRunStat.lastSenttime = GetTick(); |
| | |
| | | void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) |
| | | { |
| | | KMem.WDT[44] = size; |
| | | |
| | | memcpy( RX_Buffer, payload, size ); |
| | | memcpy(&KMem.WDT[64],payload,size); |
| | | Radio.Standby(); |
| | | |
| | | if (bThisRxError) { |
| | | bThisRxError=0; |
| | | // return; |
| | | return; |
| | | } |
| | | |
| | | KwRunStat.curStat = 0; |
| | |
| | | else //slave |
| | | { |
| | | KWLSlaveParsePkt(nRadioChannel,size); |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | KwRunStat.LostPackets++; |
| | | KwRunStat.CtnLstPkts++; |
| | | if (KwRunStat.CtnLstPkts > KwRunStat.MaxCtnLstPkts) {KwRunStat.MaxCtnLstPkts = KwRunStat.CtnLstPkts;} |
| | | // KMem.ErrStat=500; |
| | | if (KwRunStat.CtnLstPkts > 1) { KMem.ErrStat=500;} |
| | | if (KwRunStat.CtnLstPkts == 2) {KwRunStat.Err1Count++;} |
| | | if (KwRunStat.CtnLstPkts > 3) { KMem.ErrStat=5000;} |
| | | if (KwRunStat.CtnLstPkts == 4) {KwRunStat.Err2Count++;} |
| | | if (KwRunStat.CtnLstPkts > 6) { KMem.ErrStat=5000; KMem.WFX[1]=0; } |
| | | if (KwRunStat.CtnLstPkts == 7) {KwRunStat.Err3Count++;} |
| | | |
| | | // KwRunStat.ErrStat=500; |
| | | if (KwRunStat.CtnLstPkts > 2) { KwRunStat.ErrStat=500;} |
| | | if (KwRunStat.CtnLstPkts ==3 ) {KwRunStat.Err1Count++;} |
| | | if (KwRunStat.CtnLstPkts > 5) { KwRunStat.ErrStat=5000;} |
| | | if (KwRunStat.CtnLstPkts == 6) {KwRunStat.Err2Count++;} |
| | | if (KwRunStat.CtnLstPkts > 9) { KwRunStat.ErrStat=5000; KMem.WFX[1]=0; } |
| | | if (KwRunStat.CtnLstPkts == 10) {KwRunStat.Err3Count++;} |
| | | if ((KwRunStat.CtnLstPkts &0x0f) == 0x0f) { |
| | | KMem.WDT[51]++; |
| | | LoadKwConfig(); |
| | | KWireLessInit(RadioEnableMaster,nRadioChannel); |
| | | Radio.Standby(); |
| | | // KWireLessStart(); |
| | | } |
| | | if(RadioEnableMaster) |
| | | { |
| | | //KWLMasterSendReqPkt(1); |
| | | } |
| | | else |
| | | { |
| | | Radio.Standby(); |
| | | Radio.Rx( SLAVE_RX_TIMEOUT_VALUE ); |
| | | KwRunStat.runStep=RS_RECVING; |
| | | KwRunStat.lastActTime = GetTick(); |
| | |
| | | |
| | | void OnRxError( void ) |
| | | { |
| | | |
| | | // Radio.Standby(); |
| | | Radio.Standby(); |
| | | Radio.Rx( SLAVE_RX_TIMEOUT_VALUE ); |
| | | KwRunStat.runStep=RS_RECVING; |
| | | KwRunStat.lastActTime = GetTick(); |
| | | KwRunStat.lastRecvtime = GetTick(); |
| | | |
| | | KwRunStat.RXErr++; |
| | | KMem.WDT[46]++; |
| | | bThisRxError=1; |
| | |
| | | KwRunStat.LostPackets++; |
| | | KwRunStat.CtnLstPkts++; |
| | | if (KwRunStat.CtnLstPkts > KwRunStat.MaxCtnLstPkts) {KwRunStat.MaxCtnLstPkts = KwRunStat.CtnLstPkts;} |
| | | // KMem.ErrStat=500; |
| | | if (KwRunStat.CtnLstPkts > 1) { KMem.ErrStat=500; } |
| | | // KwRunStat.ErrStat=500; |
| | | if (KwRunStat.CtnLstPkts > 1) { KwRunStat.ErrStat=500; } |
| | | if (KwRunStat.CtnLstPkts == 2) {KwRunStat.Err1Count++;} |
| | | if (KwRunStat.CtnLstPkts > 3) { KMem.ErrStat=5000;} |
| | | if (KwRunStat.CtnLstPkts > 3) { KwRunStat.ErrStat=5000;} |
| | | if (KwRunStat.CtnLstPkts == 4) {KwRunStat.Err2Count++;} |
| | | if (KwRunStat.CtnLstPkts > 6) { KMem.ErrStat=5000; KMem.WFX[1]=0; } |
| | | if (KwRunStat.CtnLstPkts > 6) { KwRunStat.ErrStat=5000; KMem.WFX[1]=0; } |
| | | if (KwRunStat.CtnLstPkts == 7) {KwRunStat.Err3Count++;} |
| | | |
| | | } |
| | | // Radio.Standby(); |
| | | } |
| | | |
| | | void OnCadDone( bool channelActivityDetected) |
| | |
| | | if (RX_Buffer[size-2] != (crc_value&0xff) && RX_Buffer[size-1] != (crc_value >> 8)) |
| | | { |
| | | KwRunStat.CRCErr++; |
| | | KMem.ErrStat=500; |
| | | KwRunStat.ErrStat=500; |
| | | CRC_OK = 0; |
| | | }else { |
| | | CRC_OK = 1; |
| | |
| | | { |
| | | if (p1->DstAddr == MixAddr(nRadioChannel,nRadioAddr)) |
| | | { |
| | | KwRunStat.bMasterRecved = 1; |
| | | LedToggle();//LEDéªç |
| | | KwRunStat.lastRecvdtime=GetTick(); |
| | | KwRunStat.lastAckTime = GetTick(); |
| | |
| | | if (RX_Buffer[size-2] != (crc_value&0xff) && RX_Buffer[size-1] != (crc_value >> 8)) |
| | | { |
| | | KwRunStat.CRCErr++; |
| | | KMem.ErrStat=500; |
| | | KwRunStat.ErrStat=500; |
| | | CRC_OK = 0; |
| | | }else { |
| | | CRC_OK = 1; |
| | | if (p1->STSign != enReqSign) { |
| | | KwRunStat.PktErr++; |
| | | }else { |
| | | if (p1->DstAddr != MixAddr(nRadioChannel,nRadioAddr)) { |
| | | KwRunStat.ChnErr++; |
| | | } |
| | | } |
| | | } |
| | | //*/ |
| | | |
| | | if(CRC_OK && p1->STSign == enReqSign && p1->DstAddr == MixAddr(nRadioChannel,nRadioAddr))// memcmp(RX_Buffer,PingMsg,4)==0 && ) |
| | | { |
| | | |
| | |
| | | |
| | | int KWLSlaveProc(int nChn) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | int KWL_Process(int nChn) |
| | | { |
| | | RadioState_t stat = Radio.GetStatus(); |
| | | KMem.WDT[32]=stat; |
| | | // KMem.WDT[38]=Radio.Rssi(MODEM_FSK); |
| | | if (RadioEnableMaster){ |
| | | if (GetTick() - KwRunStat.lastSendtime > CYCLE_TIME *10 && KwRunStat.curStat == 0 ) //&& stat == RF_IDLE ) //200mS |
| | | { |
| | | KWireLessStart(); |
| | | } |
| | | }else //slave |
| | | { |
| | | RadioState_t stat = Radio.GetStatus(); |
| | | if (stat == RF_IDLE){ |
| | | KMem.WDT[48]++; |
| | | Radio.Standby(); |
| | |
| | | KWireLessStart(); |
| | | } |
| | | if (GetTick() - KwRunStat.lastRecvdtime > 4000){ // 200mS |
| | | // KMem.ErrStat=500; |
| | | KMem.ErrStat=500; |
| | | // KwRunStat.ErrStat=500; |
| | | KwRunStat.ErrStat=500; |
| | | // Radio.Standby(); |
| | | // KWireLessStart(); |
| | | } |
| | | if (GetTick() - KwRunStat.lastRecvdtime > 12000){ // 1200mS |
| | | KMem.ErrStat=5000; KMem.WFX[1]=0; |
| | | } |
| | | KwRunStat.ErrStat=5000; KMem.WFX[1]=0; |
| | | } |
| | | if (GetTick() - KwRunStat.lastRecvtime > 16000){ |
| | | KMem.WDT[52]++; |
| | | LoadKwConfig(); |
| | | KWireLessInit(RadioEnableMaster,nRadioChannel); |
| | | Radio.Standby(); |
| | | KWireLessStart(); |
| | | KwRunStat.lastRecvtime = GetTick(); |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | int KWL_Process(int nChn) |
| | | { |
| | | RadioState_t stat = Radio.GetStatus(); |
| | | KMem.WDT[32]=stat; |
| | | // KMem.WDT[38]=Radio.Rssi(MODEM_FSK); |
| | | if (RadioEnableMaster){ |
| | | if (GetTick() - KwRunStat.lastSendtime > CYCLE_TIME *10 && Radio.IsChannelFree(MODEM_LORA,KwRunStat.RF_Freq,-60,1)){ |
| | | if (!KwRunStat.bMasterRecved) { |
| | | KwRunStat.ErrStat=5000; |
| | | KwRunStat.LostPackets++; |
| | | KwRunStat.CtnLstPkts++; |
| | | if (KwRunStat.CtnLstPkts > KwRunStat.MaxCtnLstPkts) {KwRunStat.MaxCtnLstPkts = KwRunStat.CtnLstPkts;} |
| | | // KwRunStat.ErrStat=500; |
| | | if (KwRunStat.CtnLstPkts > 1) { KwRunStat.ErrStat=2000;} |
| | | if (KwRunStat.CtnLstPkts == 2) {KwRunStat.Err1Count++;} |
| | | if (KwRunStat.CtnLstPkts > 3) { KwRunStat.ErrStat=5000;} |
| | | if (KwRunStat.CtnLstPkts == 4) {KwRunStat.Err2Count++;} |
| | | if (KwRunStat.CtnLstPkts > 6) { KwRunStat.ErrStat=5000; KMem.WFX[1]=0; } |
| | | if (KwRunStat.CtnLstPkts == 7) {KwRunStat.Err3Count++;} |
| | | if ((KwRunStat.CtnLstPkts &0x0f) == 0x0f) { |
| | | KMem.WDT[51]++; |
| | | LoadKwConfig(); |
| | | KWireLessInit(RadioEnableMaster,nRadioChannel); |
| | | Radio.Standby(); |
| | | // KWireLessStart(); |
| | | } |
| | | } |
| | | if (KwRunStat.curStat == 0 ){ //&& stat == RF_IDLE ) //200mS |
| | | // Radio.Standby(); |
| | | KWireLessStart(); |
| | | }else { |
| | | Radio.Standby(); |
| | | KWireLessStart(); |
| | | } |
| | | } |
| | | }else //slave |
| | | { |
| | | KWLSlaveProc(nChn); |
| | | } |
| | | if (KwRunStat.RunStat) KwRunStat.RunStat--; |
| | | if (KwRunStat.ErrStat) KwRunStat.ErrStat--; |
| | | |
| | | KwRunStat.Tx_Power = WLCfg.Tx_Power; |
| | | KwRunStat.LoraBandWidth = WLCfg.LoraBandWidth; |
| | | KwRunStat.LoRaFactor = WLCfg.LoRaFactor; |
| | | KwRunStat.LoRaCodingRate = WLCfg.LoRaCodingRate; |
| | | KwRunStat.LoRaPreambleLen = WLCfg.LoRaPreambleLen; |
| | | |
| | | |
| | | return 0; |
| | | } |
| | | |
| | |
| | | KW_ERROR3, |
| | | }KWStates; |
| | | |
| | | #define STORE_KWCONFIG_BASE (FLASH_BASE + 0x0000F000) //50k K //and |
| | | //#define STORE_RUNSTAT_PAGESIZE (0x00000400) //Page Size = 1K |
| | | #define STORE_KWCONFIG_PAGES 1 //use 1 pages |
| | | |
| | | enum enWLWorkMode |
| | | { |
| | | WLWorkModeNone, // |
| | | WLWorkModeUni, // ä¸å¯¹ä¸ |
| | | WLWorkModeMul, // ä¸å¯¹å¤ |
| | | WLWorkModeThr, // éä¼ |
| | | |
| | | }; |
| | | |
| | | typedef struct tagWLConfig |
| | | { |
| | | uint32_t RF_T_Freq; //Hz |
| | | uint32_t RF_R_Freq; //Hz |
| | | uint16_t nChnSpacing; //kHz |
| | | uchar workMode; //0: FSK, 1: LoRa |
| | | uchar Tx_Power; // dBm 5 - 22 dBm |
| | | uchar LoraBandWidth; // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved ] |
| | | uchar LoRaFactor; // [SF5 .. SF 12] |
| | | uchar LoRaCodingRate; // [1 : 4/5, 2: 4/6, 3: 4/7, 4: 4/8 ] |
| | | uint8_t NetWorkAddr; |
| | | uint16_t DeviceAddr; |
| | | uchar bEnableAddr; |
| | | uchar bEnableEncrypt; |
| | | uchar bEnableRelay; |
| | | uchar LoRaPreambleLen; // 2 - 12 |
| | | uchar bAutoReSend; //èªå¨éå |
| | | |
| | | |
| | | // uchar ; // |
| | | // uchar |
| | | |
| | | }stWLConfig, *pstWLConfig; |
| | | |
| | | typedef struct tagStoredWLConfig |
| | | { |
| | | unsigned short BlockSign; |
| | | unsigned char BlockType; |
| | | unsigned char nSeq; |
| | | unsigned short nSize; |
| | | unsigned short nCRC16; |
| | | stWLConfig WLConfig; |
| | | }stStoredWLConfig, *pstStoredWLConfig; |
| | | |
| | | |
| | | typedef enum tag_runstep{ |
| | | RS_IDEL, |
| | | RS_SENDING, |
| | | RS_RECVING, |
| | | }enRunStep; |
| | | |
| | | #pragma anon_unions |
| | | typedef struct tagWLStat |
| | | { |
| | | uint32_t Stat; //ç¶æ |
| | | uint32_t curStat; //å½åç¶æ |
| | | uint32_t runStep; //å·¥ä½æ¥éª¤ |
| | | union { |
| | | uint32_t Status; //ç¶æ |
| | | struct { |
| | | uint32_t bMasterSent:1; |
| | | uint32_t bMasterRecved:1; |
| | | }; |
| | | }; |
| | | uint16_t curStat; //å½åç¶æ |
| | | uint16_t runStep; //å·¥ä½æ¥éª¤ |
| | | |
| | | uint16_t RunStat; //è¿è¡ç¶æ |
| | | uint16_t ErrStat; //é误ç¶æ |
| | | |
| | | uint32_t RF_Freq; //è¿è¡é¢ç |
| | | uint16_t nTimeOnAir; |
| | | uint16_t DeviceAddr; |
| | | |
| | | uint8_t NetWorkAddr; |
| | | |
| | | uchar Tx_Power; // dBm 5 - 22 dBm |
| | | uchar LoraBandWidth; // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved ] |
| | | uchar LoRaFactor; // [SF5 .. SF 12] |
| | | uchar LoRaCodingRate; // [1 : 4/5, 2: 4/6, 3: 4/7, 4: 4/8 ] |
| | | |
| | | uchar LoRaPreambleLen; // 2 - 12 |
| | | |
| | | uchar bEnableAddr; |
| | | uchar bEnableEncrypt; |
| | | uchar bEnableRelay; |
| | | uchar bAutoReSend; //èªå¨éå |
| | | |
| | | uint32_t sentCount; //åéè®¡æ° |
| | | uint32_t recvCount; //æ¥æ¶è®¡æ° |
| | | uint32_t lastSendtime; //ä¸æ¬¡åéæ¶é´ |
| | |
| | | uint32_t lastErrTime; //ä¸æ¬¡é误æ¶é´ |
| | | uint32_t latancy; //å»¶è¿ |
| | | uint32_t cycleTime; //循ç¯æ¶é´ |
| | | uint32_t LostPackets; //丢å
è®¡æ° |
| | | uint32_t CtnLstPkts; //è¿ç»ä¸¢å
è®¡æ° |
| | | uint32_t MaxCtnLstPkts; //æ大è¿ç»ä¸¢å
è®¡æ° |
| | | uint32_t TXErr; //åééè¯¯è®¡æ° |
| | | uint32_t RXErr; //æ¥æ¶éè¯¯è®¡æ° |
| | | uint32_t CRCErr; //CRCéè¯¯è®¡æ° |
| | | uint32_t CADDoneCount; //CAD å®ææ¬¡æ° |
| | | uint32_t StepErr1; //æ¥éª¤é误1 |
| | | uint32_t StepErr2; //æ¥éª¤é误2 |
| | | uint32_t Err1Count; //å¾®éªæ¥è¦æ¬¡æ° |
| | | uint32_t Err2Count; //大éªæ¥è¦æ¬¡æ° |
| | | uint32_t Err3Count; //严é丢失信å·æ¬¡æ° |
| | | uint16_t LostPackets; //丢å
è®¡æ° |
| | | uint16_t CtnLstPkts; //è¿ç»ä¸¢å
è®¡æ° |
| | | uint16_t MaxCtnLstPkts; //æ大è¿ç»ä¸¢å
è®¡æ° |
| | | uint16_t TXErr; //åééè¯¯è®¡æ° |
| | | uint16_t RXErr; //æ¥æ¶éè¯¯è®¡æ° |
| | | uint16_t CRCErr; //CRCéè¯¯è®¡æ° |
| | | uint16_t ChnErr; //é¢éé误 |
| | | uint16_t PktErr; //å
é误 |
| | | uint16_t CADDoneCount; //CAD å®ææ¬¡æ° |
| | | uint16_t StepErr1; //æ¥éª¤é误1 |
| | | uint16_t StepErr2; //æ¥éª¤é误2 |
| | | uint16_t Err1Count; //å¾®éªæ¥è¦æ¬¡æ° |
| | | uint16_t Err2Count; //大éªæ¥è¦æ¬¡æ° |
| | | uint16_t Err3Count; //严é丢失信å·æ¬¡æ° |
| | | |
| | | int8_t RSSI; //ä¿¡å·å¼ºåº¦ |
| | | int8_t SNR; //ä¿¡åªæ¯ |
| | |
| | | |
| | | }; |
| | | |
| | | typedef struct tagWLConfig |
| | | { |
| | | uint32_t RF_Freq; |
| | | uint32_t ChannelSpacing; |
| | | uchar Tx_Power; |
| | | |
| | | uchar workMode; //0: FSK, 1: LoRa |
| | | uchar LoraBandWidth; // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved ] |
| | | uchar LoRaFactor; // [SF5 .. SF 12] |
| | | uchar LoRaCodingRate; // [1 : 4/5, 2: 4/6, 3: 4/7 |
| | | uchar LoRaPreamble_Len; // 2 - 12 |
| | | // uchar ; // |
| | | // uchar |
| | | |
| | | }stWLConfig; |
| | | |
| | | |
| | | typedef struct tagKLPacket |
| | | { |
| | | uchar STSign; |
| | |
| | | |
| | | }stKLPacket, *pstKLPacket; |
| | | |
| | | int LoadKwConfig(void); |
| | | int SaveKwConfig(void); |
| | | |
| | | int KWireLessInit(bool bRadioEnableMaster, uint32_t nChn); |
| | | int KWireLessStart(void); |
| | |
| | | extern uchar nRadioChannel; |
| | | extern uchar nRadioAddr; |
| | | |
| | | extern stWLConfig WLCfg ; |
| | | extern stWLRunStat KwRunStat; |
| | | |
| | | |
| | |
| | | |
| | | |
| | | PacketStatus_t RadioPktStatus; |
| | | uint8_t RadioRxPayload[255]; |
| | | uint8_t RadioRxPayload[32]; |
| | | |
| | | bool IrqFired = false; |
| | | |
| | |
| | | return RF_TX_RUNNING; |
| | | case MODE_RX: |
| | | return RF_RX_RUNNING; |
| | | case RF_CAD: |
| | | case MODE_CAD: |
| | | return RF_CAD; |
| | | default: |
| | | return RF_IDLE; |
New file |
| | |
| | | /** |
| | | ****************************************************************************** |
| | | * @file : ATModem.c |
| | | * @brief : AT Modem Protocol program body |
| | | ****************************************************************************** |
| | | */ |
| | | #include "ATModem.h" |
| | | |
| | | |
| | | void ATInit(stATModemDef * pATModem, ATSendPktDef pFunc1) |
| | | { |
| | | pATModem->ATSendPktFunc = pFunc1; |
| | | |
| | | return; |
| | | } |
| | | void ATSetCallBack(stATModemDef * pATModem, ATSendPktDef pFunc1) |
| | | { |
| | | pATModem->ATSendPktFunc = pFunc1; |
| | | return; |
| | | } |
| | | |
| | | int ATParsePacket(stATModemDef * pATModem, char * pBuf, uchar len1) |
| | | { |
| | | return 0; |
| | | } |
| | | void ATProcess(stATModemDef * pATModem) |
| | | { |
| | | |
| | | } |
| | |
| | | #include "BoardType.h" |
| | | #include "KMachine.h" |
| | | #include "KBus.h" |
| | | |
| | | |
| | | #define APP_ADDR 0x08001000 //åºç¨ç¨åºé¦å°åå®ä¹ |
| | | #define APPINFOBLOCK_ADDR (APP_ADDR + 0x100) //ç¨åºä¿¡æ¯å å°å |
| | | #define INFOBLOCK_ADDR (APP_ADDR + 0x1000) //ä¿¡æ¯å å°å |
| | | |
| | | #define APP_START_ADDR IROM1_START_ADDRESS |
| | | |
| | | extern int Region$$Table$$Limit; |
| | | |
| | | #define MAKE_VER(x,y) ((x<<8)|y) |
| | | #define APP_VER MAKE_VER(1,14) |
| | | |
| | | const stAppInfoBlock AppInfoBlock __attribute__((at(APPINFOBLOCK_ADDR))) = |
| | | { |
| | | 0xAA55, // StartSign |
| | | 0x0301, // BlockType |
| | | sizeof(stAppInfoBlock), //BlockSize |
| | | 0, // Pad, |
| | | APP_VER, //AppVer |
| | | (BOARD_TYPE<<8) + BOARD_VER, //AppDevice; |
| | | 0x1000, //AppSize; |
| | | 0x0C00, //AppDataSize; |
| | | APP_ADDR, //nAppStartAddr |
| | | (int)&Region$$Table$$Limit, //nBtldr_NewAppInfoAddr |
| | | 0x08009000, //nBtldr_NewAppAddr |
| | | 0xCCCC, //crc16; |
| | | 0xAA55 //EndSign; |
| | | |
| | | }; |
| | | |
| | | const stKMInfoBlock KMInfoBlock __attribute__((at(INFOBLOCK_ADDR))) = |
| | | { |
| | | // sizeof(stKMInfoBlock), |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceType BOARD_VER, //nDevieVer |
| | | APP_VER, //ProgVer |
| | | 0x0102, //KLinkVer |
| | | KBUS_VER, //KBusVer |
| | | // 0x0100, //KNetVer |
| | | // 0x0100, //KWLVer |
| | | |
| | | 4, //nCapacity1 ?K |
| | | 1, //nCapacity2 ?k |
| | | |
| | | DINPUT, //nDInput; |
| | | DOUTPUT, //nDOutput |
| | | |
| | | 0, //nAInput |
| | | 0, //nAOutput |
| | | 0, //nHInput |
| | | 0, //nHOutput |
| | | 0, //nExt1; |
| | | 0, //nExt2; |
| | | 0, //nLogSize; |
| | | 3, //nPorts; |
| | | 0, //nManSize; |
| | | 0, //nAbility; |
| | | 6, //nSwitchBits; |
| | | }; |
| | | |
| | | |
| | | const stDeviceInfo MyDeviceInfo={ |
| | | |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | APP_VER, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | EXDOUPUT, // unsigned char ExInBitCount; // æ©å±çè¾å
¥å¼å
³éæ°é |
| | | EXDOUPUT, // unsigned char ExOutBitCount; // æ©å±çè¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | }; |
| | | |
| | | const stExDeviceInfo MyExDeviceInfo ={ |
| | | (BOARD_TYPE<<8) + BOARD_VER, //nDeviceTypeVer // unsigned short ClientType; // åæºç±»å |
| | | APP_VER, //ProgVer // unsigned short ClientVer; // åæºçæ¬ |
| | | |
| | | DINPUT, // unsigned char InBitCount; // è¾å
¥å¼å
³éæ°é |
| | | DOUTPUT, // unsigned char OutBitCount; // è¾åºå¼å
³éæ°é |
| | | EXDOUPUT, // unsigned char ExInBitCount; // æ©å±çè¾å
¥å¼å
³éæ°é |
| | | EXDOUPUT, // unsigned char ExOutBitCount; // æ©å±çè¾åºå¼å
³éæ°é |
| | | 0, // unsigned char InDWCount; // è¾å
¥æ°æ®åæ° |
| | | 0, // unsigned char OutDWCount; // è¾åºæ°æ®åæ° |
| | | 0, // unsigned char AIWCount; // è¾å
¥æ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | 0, // unsigned char AQWCount; // è¾åºæ¨¡æééé(å)æ° // 16ä½ä¸ºä¸ä¸ªå(éé) |
| | | // 0, // unsigned char AIBits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | // 0, // unsigned char AQbits; // æ¯ééä½æ° // 16ä½ä»¥ä¸ |
| | | |
| | | }; |
| | | |
| | |
| | | unsigned char FastFlicker=0; |
| | | |
| | | unsigned int Uart1IdelTimer = 0; |
| | | #if (ENABLE_PLC) |
| | | stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; |
| | | |
| | | #endif |
| | | uint32_t us1,us2,us3,us4,us5,us6; |
| | | |
| | | stKBusDef KBus1; // |
| | | |
| | | extern stDeviceInfo MyDeviceInfo; |
| | | |
| | | /* USER CODE END PV */ |
| | | |
| | |
| | | static int Count=0; |
| | | CurTickuS += 100; |
| | | nCurTick++; |
| | | nSlaveTick++; |
| | | KBus1.nSlaveTick++; |
| | | Count++; |
| | | if (Count>=10000) |
| | | { |
| | |
| | | |
| | | return; |
| | | } |
| | | |
| | | |
| | | void PendSvCallBack() |
| | | { |
| | | #if (BOARD_TYPE == 14) |
| | | ///* |
| | | if (bSPI1RecvDone) |
| | | { |
| | | bSPI1RecvDone=0; |
| | | FPxParsePkt(SPI1RecvBuf,nSPI1RecvLenInBuf); |
| | | } |
| | | //*/ |
| | | #endif |
| | | if (Uart2Stat.bPacketRecved) |
| | | { |
| | | KBusParsePacket(&KBus1, (pKBPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); |
| | | Uart2RecvBuf1DataLen=0; |
| | | Uart2Stat.bPacketRecved=0; |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | KMem.WDT[2]++; |
| | | } |
| | | } |
| | | |
| | | /* |
| | | KBusé讯åè°å½æ°ï¼å½é讯ç¶ææ¹åææ°æ®æ´æ°æ¶è¢«è°ç¨ã |
| | | æè
ç³»ç»è¯·æ±æ¶ã |
| | | */ |
| | | void * KBusEvCallBackFunc(void* pParam, int nEvent, void *pBuf, int nLen1) |
| | | { |
| | | switch (nEvent){ |
| | | |
| | | case KBusEvNone: |
| | | break; |
| | | case KBusEvCreate: |
| | | break; |
| | | case KBusEvConnected: |
| | | break; |
| | | case KBusEvDisConnected: |
| | | break; |
| | | case KBusEvClosed: |
| | | break; |
| | | case KBusEvStateChange: |
| | | break; |
| | | case KBusEvTimeSync: |
| | | break; |
| | | case KBusEvDataUpdate: |
| | | KMem.WLX[0] = KBusMem.WLX[0]; |
| | | KMem.WLY[0] = KBusMem.WLY[0]; |
| | | |
| | | if (KBus1.bMaster) { |
| | | KMem.WY[0]=KBusMem.WLX[0]; //KPLC with KBus Master |
| | | KBusMem.WLY[0]=KMem.WX[0]; |
| | | } else if (KBus1.bSlave) { |
| | | KMem.WYB[0]=KBusMem.WLYB[0]; //WireLess with KBus Slave |
| | | KBusMem.WLXB[0]=KMem.WXB[0]; |
| | | |
| | | } |
| | | break; |
| | | case KBusEvCmdResponse: |
| | | break; |
| | | |
| | | default: |
| | | break; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | /* USER CODE END 0 */ |
| | | |
| | |
| | | |
| | | /* USER CODE BEGIN Init */ |
| | | |
| | | for (int i=0;i<9;i++) |
| | | { |
| | | // memset(KBusChnStats[i],0,0); |
| | | KBusChnStats[i].SendPackets=0; |
| | | KBusChnStats[i].RecvPackets=0; |
| | | KBusChnStats[i].LostPackets=0; |
| | | KBusChnStats[i].CtnLstPkts=0; |
| | | KBusChnStats[i].MaxCtnLstPkts=0; |
| | | KBusChnStats[i].NotPkgErr=0; |
| | | KBusChnStats[i].PkgLenErr=0; |
| | | KBusChnStats[i].TimeOutErr=0; |
| | | KBusChnStats[i].BCCErr=0; |
| | | KBusChnStats[i].Delay=0; |
| | | KBusChnStats[i].MaxDelay=0; |
| | | } |
| | | |
| | | KMem.LastScanTime=0; |
| | | KMem.ScanTimeuS=0; |
| | | KMem.MinScanTimeuS=99999; |
| | | KMem.MaxScanTimeuS=0; |
| | | |
| | | // KMem.SDD[14]=(unsigned int)&KMStoreSysCfg; |
| | | // KMem.SDD[15]=(unsigned int)&KMStoreSysCfg1; |
| | | KMem.SDD[12]=((uint32_t *)UID_BASE)[0]; |
| | | // KMem.SDD[13]=((uint32_t *)UID_BASE)[1]; |
| | | // KMem.SDD[14]=((uint32_t *)UID_BASE)[2]; |
| | | KMem.SDD[13]=PendSvCount; |
| | | KMem.SDD[14]=RCC->CSR; |
| | | // KMem.SDD[15]=*(uint32_t *)FLASHSIZE_BASE; |
| | | // KMem.SDD[16]=(unsigned int)&KMSysCfg; |
| | | |
| | | /* USER CODE END Init */ |
| | | |
| | |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | KLinkInit(1); //注åKLinkç«¯å£ |
| | | |
| | | // stPortDef PortReg1 = {.nPortHardType = 3,.nPortUseType = 2}; |
| | | // KMRegisterPort(0,&PortReg1); |
| | | |
| | | |
| | | unsigned char bKBusMaster, bKBusSlave, bKBusRepeater; |
| | | int nKBusStationID; |
| | | int nKBusChilds; |
| | | |
| | | KMem.CurJumperSW=ReadJumperSW(); |
| | | KMem.EffJumperSW=KMem.CurJumperSW; |
| | | |
| | |
| | | FP0_Init(); |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | nStationID=1 ;//KMem.EffJumperSW&0x0f; |
| | | nKBusStationID=KMem.EffJumperSW&0x0f; |
| | | // if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | // else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | // else |
| | |
| | | else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | #endif |
| | | nChilds=nStationID; |
| | | nCurPollId=1; |
| | | nKBusChilds=nKBusStationID; |
| | | |
| | | if (bKBusMaster) { |
| | | KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds); |
| | | } else if (bKBusSlave) { |
| | | KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationID,&MyDeviceInfo); |
| | | } |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc); |
| | | |
| | | UNUSED(bKBusRepeater); |
| | | // 注åKBusç«¯å£ |
| | | /* |
| | | stPortDef PortReg2 = {.nPortHardType = 4,.nPortUseType = 3}; |
| | | KMRegisterPort(1,&PortReg2); |
| | | */ |
| | | //if (KMem.EffJumperSW == 0x00) |
| | | Uart1Baud = DefaultUart1Baud; |
| | | Uart1Baud = DefaultUart1Baud; |
| | | MX_USART1_UART_Init(); |
| | | MX_USART2_UART_Init(); |
| | | |
| | |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | LL_USART_EnableIT_IDLE(USART2); |
| | | LL_USART_EnableIT_TC(USART2); |
| | | |
| | | #if (BOARD_TYPE == 13) |
| | | int res; |
| | | res = w5500_init(); |
| | |
| | | KMRunStat.WorkMode2=0; |
| | | |
| | | KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode; |
| | | |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode == 1){ |
| | | InitPLC(); |
| | | KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ; |
| | | if (KMRunStat.WorkMode2) { |
| | | StartPLC(); } |
| | | } |
| | | KMem.WX[7]=0x5a; |
| | | #endif |
| | | |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | LoadKwConfig(); |
| | | // KWireLessInit(&KWInitStruct); |
| | | |
| | | KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
| | | KWireLessStart(); |
| | | #endif |
| | | |
| | | |
| | | stPortDef PortReg3 = {.nPortHardType = 7,.nPortUseType = 6}; |
| | | KMRegisterPort(2,&PortReg3); |
| | | |
| | | while (1) |
| | | { |
| | |
| | | |
| | | int thisJumperSW=ReadJumperSW(); |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode&1){ |
| | | if (thisJumperSW&0x20 && !(KMem.CurJumperSW&0x20)) // Run å¼å
³ æ£ è·³åã |
| | | {StartPLC();} |
| | | if (!(thisJumperSW&0x20) && (KMem.CurJumperSW&0x20)) // Run å¼å
³ è´ è·³åã |
| | | {StopPLC();} |
| | | } |
| | | |
| | | #endif |
| | | KMem.CurJumperSW=thisJumperSW; |
| | | KMem.haltick=haltick; |
| | | // KMem.TotalRunTime=TotalRunTime; |
| | |
| | | // *((unsigned int *)&(PLCMem.SDT[2]))=nChilds; |
| | | // KMem.SDD[13]=PendSvCount; |
| | | // KMem.SDD[14]=RCC->CSR; |
| | | |
| | | |
| | | int a; |
| | | a = LL_GPIO_ReadInputPort(GPIOA); |
| | |
| | | #endif |
| | | |
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
| | | { |
| | | if (KMRunStat.nBinProgBank == 0){ |
| | |
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1); |
| | | } |
| | | |
| | | #endif // ENABLE_PLC |
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime; |
| | | KMem.LastScanTime = us2; |
| | | if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;} |
| | |
| | | // BufferOut[1]=KMem.WX[0]&0xff; |
| | | // BufferOut[2]=(KMem.WX[0]>>8)&0xff; |
| | | #endif |
| | | if (nChilds>0) { KBusMasterFunc(2); } |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | // KMem.WX[0]=BufferIn[1]+(BufferIn[2]<<8); |
| | | #else |
| | | // KMem.WY[0]=BufferIn[1]+(BufferIn[2]<<8); |
| | | #endif |
| | | |
| | | } |
| | | KBusLoopProcess(&KBus1); |
| | | |
| | | if (haltick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | | if (haltick&0x00000800) FastFlicker=1; |
| | |
| | | // if (! KMem.RunStat) {BufferIn[0]=0;} |
| | | // KMem.WY[0]=BufferIn[0]; |
| | | #else |
| | | KBusSlaveFunc(2); |
| | | KBusSlaveFunc(&KBus1); |
| | | if (! KMem.RunStat) {BufferIn[0]=0;} |
| | | KMem.WY[0]=BufferIn[0]; |
| | | #endif |
| | | if (nSlaveTick&0x00002000) SlowFlicker=1; |
| | | if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | | if (nSlaveTick&0x00000800) FastFlicker=1; |
| | | if (KBus1.nSlaveTick&0x00000800) FastFlicker=1; |
| | | else FastFlicker=0; |
| | | |
| | | } |
| | | |
| | | // KMem.WY[0]=nCount2>>5; |
| | | if (KMem.RunStat) {KMem.RunStat--;} |
| | | if (KMem.ErrStat) {KMem.ErrStat--;} |
| | | |
| | | |
| | | if (KMRunStat.bLEDFlick) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | KMem.ErrStat = KwRunStat.ErrStat; |
| | | if ((KMem.EffJumperSW&0x10)==0x10) KMem.ErrStat += KBus1.ErrStat; |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode==1 ) { |
| | | if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
| | | else {SetRunLed(0);} |
| | | } |
| | | else { |
| | | else |
| | | #endif // ENABLE_PLC |
| | | { |
| | | if (!KMem.RunStat) SetRunLed(SlowFlicker); |
| | | else SetRunLed(FastFlicker); |
| | | } |
| | | |
| | | if (!KMem.ErrStat) |
| | | { |
| | | SetErrLed(0); |
| | |
| | | us4=GetuS(); |
| | | // EffJumperSW = GetInput(20)&0xff; |
| | | |
| | | |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | |
| | | if ((KMem.EffJumperSW&0x10)==0x10) { |
| | | KMem.WFY[1]=KMem.WLY[0]; |
| | | KMem.WLX[0]=KMem.WFX[1]; |
| | | KMem.WFY[1]=KBusMem.WLYB[1]; |
| | | KBusMem.WLXB[1]=KMem.WFX[1]; |
| | | }else |
| | | { |
| | | KMem.WFY[1]=KMem.WX[0]; |
| | |
| | | Uart1Stat.bPacketRecved=0; |
| | | Uart1IdelTimer = 0; |
| | | }else { |
| | | if (Uart1IdelTimer>600000) { // è¶
è¿60ç§æ²¡ææ°æ®ä¼ è¾ï¼éæ°è¿å
¥èªéåºæ³¢ç¹çç¶æ |
| | | |
| | | if (Uart1IdelTimer>300000) { // è¶
è¿60ç§æ²¡ææ°æ®ä¼ è¾ï¼éæ°è¿å
¥èªéåºæ³¢ç¹çç¶æ |
| | | LL_USART_EnableAutoBaudRate(USART1); |
| | | LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
| | | }else { |
| | | Uart1IdelTimer++; |
| | | } |
| | | } |
| | | if (bKBusSlave) HAL_Delay(0); |
| | | // if (bKBusSlave) HAL_Delay(0); |
| | | /* |
| | | if (!IsEmpty(&Uart1Stat.QRx)) |
| | | { |