| | |
| | | //#define UID_BASE ((uint32_t)0x1FFFF7ACU) /*!< Unique device ID register base address */
|
| | |
|
| | |
|
| | | stKMSysCfg KMSysCfg ;
|
| | | stStoredKMSysCfg storedKMSysCfg ;
|
| | | stKMem KMem;
|
| | | stRunStat KMRunStat;
|
| | |
|
| | |
| | | //uint32_t * pUID = (uint32_t *)(UID_BASE);
|
| | | const stKMInfoBlock KMInfoBlock =
|
| | | {
|
| | | 0x0008,
|
| | | 0x0100,
|
| | | 0x0100,
|
| | | 0x0100,
|
| | | 16,
|
| | | 16,
|
| | | 0,
|
| | | 0,
|
| | | 0,
|
| | | 0,
|
| | | 0,
|
| | | 0,
|
| | | BOARD_TYPE, //nDeviceType
|
| | | 0x0100, //ProgVer
|
| | | 0x0100, //KLinkVer
|
| | | 0x0100, //nCapacity
|
| | | 16, //nDInput;
|
| | | 16, //nDOutput
|
| | | 0, //nAInput
|
| | | 0, //nAOutput
|
| | | 0, //nHInput
|
| | | 0, //nHOutput
|
| | | 0, //nExt1;
|
| | | 0, //nExt2;
|
| | | };
|
| | | const char VersionStr[] __attribute__((at(FLASH_BASE + 0X1000))) //__attribute__((at(0X8001000)))
|
| | | = "3.00";
|
| | |
|
| | | const stKMSysCfg KMStoreSysCfg /*__attribute__((at(STORECFGBASE)))*/ =
|
| | | const stStoredKMSysCfg KMDefaultSysCfg /*__attribute__((at(STORECFGBASE)))*/ =
|
| | | {
|
| | | 0x55aa,
|
| | | START_SIGN,
|
| | | 0x0000,
|
| | | 0x00000000,
|
| | | |
| | | CFG_VER,
|
| | | 0x0000,
|
| | | 0x0000,
|
| | | {0,0,0,0,0,0},
|
| | | {
|
| | | {
|
| | | 1,
|
| | | 0,
|
| | | 2304, //Buadrate * 100;
|
| | | PortType_KLink, //PorttType
|
| | | 1, //ByteSize
|
| | | 0, //Parity
|
| | | 0, //StopBits
|
| | | 0, //EofChar
|
| | | 0, //SofChar
|
| | | 2304, //Buadrate * 100;
|
| | | },
|
| | | {
|
| | | 1,
|
| | | 0,
|
| | | 2304, //Buadrate * 100;
|
| | | PortType_KBus, //PorttType
|
| | | 1, //ByteSize
|
| | | 0, //Parity
|
| | | 0, //StopBits
|
| | | 0, //EofChar
|
| | | 0, //SofChar
|
| | | 2304, //Buadrate * 100;
|
| | | }
|
| | | },
|
| | | {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}},
|
| | |
| | | 0x0010,
|
| | | {0},
|
| | | 0x0011,
|
| | | 0x5aa5,
|
| | | END_SIGN,
|
| | | };
|
| | |
|
| | | const stKMSysCfg KMStoreSysCfg2[7] /*__attribute__((at(STORECFGBASE+sizeof(stKMSysCfg))))*/;
|
| | | const stKMSysCfg KMDefaultSysCfg2[7] /*__attribute__((at(STORECFGBASE+sizeof(stKMSysCfg))))*/;
|
| | |
|
| | | int ReadFlashMem(void * pBuf, void * pAddrFlash, int nByteSize)
|
| | | {
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | int LoadDefaultSysCfg(pKMSysCfg theKMSysCfg)
|
| | | int LoadDefaultSysCfg(pStoredKMSysCfg theStoredKMSysCfg)
|
| | | {
|
| | | memcpy(theKMSysCfg,&KMStoreSysCfg,sizeof(stKMSysCfg));
|
| | | memcpy(theStoredKMSysCfg,&KMDefaultSysCfg,sizeof(stKMSysCfg));
|
| | | return 0;
|
| | | }
|
| | | int ReadSysCfgFromFlash(pKMSysCfg theKMSysCfg)
|
| | | int ReadSysCfgFromFlash(pStoredKMSysCfg theStoredKMSysCfg)
|
| | | {
|
| | | pKMSysCfg pStoreKMSysCfg = (pKMSysCfg)(STORE_SYSREG_BASE);
|
| | | pStoredKMSysCfg pStoreKMSysCfg = (pStoredKMSysCfg)(STORE_SYSREG_BASE);
|
| | | // find latest Store Cfg
|
| | | int nIndex=-1;
|
| | | int nMaxSeq=-1;
|
| | | for (int i=0;i<8;i++)
|
| | | {
|
| | | if (pStoreKMSysCfg->Sign1 == 0x55aa && pStoreKMSysCfg->EndSign1 == 0x5aa5)
|
| | | if (pStoreKMSysCfg->Sign1 == START_SIGN && pStoreKMSysCfg->EndSign1 == END_SIGN)
|
| | | {
|
| | | if (pStoreKMSysCfg->Seq1 > nMaxSeq)
|
| | | {
|
| | |
| | | }
|
| | | if (nIndex>=0 && nIndex <8)
|
| | | {
|
| | | ReadFlashMem(theKMSysCfg,(void *)(pStoreKMSysCfg+nIndex),sizeof(stKMSysCfg));
|
| | | ReadFlashMem(theStoredKMSysCfg,(void *)(&pStoreKMSysCfg[nIndex]),sizeof(stStoredKMSysCfg));
|
| | | }else {
|
| | | LoadDefaultSysCfg(theKMSysCfg);
|
| | | LoadDefaultSysCfg(theStoredKMSysCfg);
|
| | | }
|
| | | //memcpy(theKMSysCfg,(void* )STORECFGBASE,sizeof(KMSysCfg));
|
| | | return 0;
|
| | | }
|
| | |
|
| | | int WriteSysCfgToFlash(pKMSysCfg theKMSysCfg)
|
| | | int WriteSysCfgToFlash(pStoredKMSysCfg theStoredKMSysCfg)
|
| | | {
|
| | | theKMSysCfg->Seq1++;
|
| | | theKMSysCfg->cfgvar16++;
|
| | | theStoredKMSysCfg->Seq1++;
|
| | | // theKMSysCfg->cfgvar16++;
|
| | | // find the next empty space to write
|
| | | int nIndex=-1;
|
| | | int s2=128;
|
| | |
| | | break;
|
| | | }
|
| | | if (nIndex >=0 && nIndex <8) {
|
| | | WriteToFlashMemNoErase(theKMSysCfg,(void *)(STORE_SYSREG_BASE + nIndex*s2),sizeof(KMSysCfg));
|
| | | WriteToFlashMemNoErase(theStoredKMSysCfg,(void *)(STORE_SYSREG_BASE + nIndex*s2),sizeof(theStoredKMSysCfg));
|
| | | }
|
| | | else {
|
| | | EraseAndWriteToFlashMem(theKMSysCfg,(void *)STORE_SYSREG_BASE,sizeof(KMSysCfg));
|
| | | EraseAndWriteToFlashMem(theStoredKMSysCfg,(void *)STORE_SYSREG_BASE,sizeof(theStoredKMSysCfg));
|
| | | }
|
| | | return 0;
|
| | | }
|
| | |
| | | volatile int PowerDownEvent=0;
|
| | | volatile int OldPowerDownEvent=0;
|
| | | volatile int OldPowerDownEventTime=0;
|
| | |
|
| | |
|
| | | int CheckEventLog()
|
| | | {
|