📄 syslib.c
字号:
*PDDIR(INTERNAL_MEM_MAP_ADDR) |= PDDIRMASK; *PDDAT(INTERNAL_MEM_MAP_ADDR) = 0x0000; }void BSP_LedPortInit(void){ *PCPAR(INTERNAL_MEM_MAP_ADDR) &= ~(PC15 | PC13); *PCSO(INTERNAL_MEM_MAP_ADDR) &= ~(PC15 | PC13); *PCDIR(INTERNAL_MEM_MAP_ADDR) |= (PC15 | PC13);}/******************************************************************************** sysMsDelay - delay for the specified amount of time (MS)** This routine will delay for the specified amount of time by counting* decrementer ticks.** This routine is not dependent on a particular rollover value for* the decrementer, it should work no matter what the rollover* value is.** A small amount of count may be lost at the rollover point resulting in* the sysMsDelay() causing a slightly longer delay than requested.** This routine will produce incorrect results if the delay time requested* requires a count larger than 0xffffffff to hold the decrementer* elapsed tick count. For a System Bus Speed of 67 MHZ this amounts to* about 258 seconds.** RETURNS: N/A*/void sysMsDelay ( _U32 delay /* length of time in MS to delay */ ) { register UINT oldval; /* decrementer value */ register UINT newval; /* decrementer value */ register UINT totalDelta; /* Dec. delta for entire delay period */ register UINT decElapsed; /* cumulative decrementer ticks */ /* * Calculate delta of decrementer ticks for desired elapsed time. */ totalDelta = ((DEC_CLOCK_FREQ / 4) / 1000) * delay; /* * Now keep grabbing decrementer value and incrementing "decElapsed" until * we hit the desired delay value. Compensate for the fact that we may * read the decrementer at 0xffffffff before the interrupt service * routine has a chance to set in the rollover value. */ decElapsed = 0; oldval = vxDecGet (); while (decElapsed < totalDelta) { newval = vxDecGet (); if ( DELTA(oldval,newval) < 1000 ) decElapsed += (UINT)DELTA(oldval,newval); /* no rollover */ else if (newval > oldval) decElapsed += (UINT)abs((int)oldval); /* rollover */ oldval = newval; }}_U32 BSP_GetBiosVer(){ return *(_U32 *)(ROM_VERSION_ADRS);}_S8 *BSP_GetBspVer(){ memset((void *)gBSPVerStr,0,BSP_VER_STR_SIZE); sprintf(gBSPVerStr,"%s %s|Creation date: %s",BSP_VERSION,BSP_REV,__DATE__); return gBSPVerStr;}void BSP_GetCallersPC( _U32 *pulAddrArray, _U32 ulArrayNum ){ _U32 i; _U32 *pulSP; if ((NULL == pulAddrArray)||(( 6 <= ulArrayNum ))) { /* 此处不设错误码 */ return; } pulSP = (_U32 *)BSP_GetSP(); /* 忽略本函数和上层调用函数 */ pulSP = (_U32 *)*pulSP; /* 本函数的栈顶, *( pulSP + 1 )为本函数地址 */ pulSP = (_U32 *)*pulSP; /* 上层函数的栈顶, *( pulSP + 1 )上层本函数地址 */ for ( i = 0; i < ulArrayNum; i++ ) { if ( 0 != *pulSP ) { /* Drv_Print( "pulSP = %x, func%d addr = %x \r\n", (_U32)pulSP, i, *( pulSP + 1 ) ); */ pulAddrArray[i] = *( pulSP + 1 ); pulSP = (_U32 *)*pulSP; } else { pulAddrArray[i] = NULL; } }}void BSP_GetTimeDetail(_U32 *ulTick, _U32 *ulUsec){}void BSP_PrintMemSimple(char *pData,_U32 Count){ _U32 loop; for (loop = 0;loop<Count;loop++) { if (loop%0x10 == 0) { Drv_Print("\r\n 0x%x: ",&(pData[loop])); } Drv_Print("%02x ",(_U8)(pData[loop])); }}void sysMacToStr(char *pData,char *pStr){ sprintf(pStr,"%02x-%02x-%02x-%02x-%02x-%02x", pData[0], pData[1], pData[2], pData[3], pData[4], pData[5]);}_U32 sysStrToMac(char *strmac, char *pmac){ int i = 0; int limit = 17; int byUPTI = 0; pmac[i] = 0; while((i < 6)&&(limit > 0)) { byUPTI ++; if((*strmac >= '0')&&(*strmac <= '9')){ pmac[i] = (pmac[i]<<4)|(*strmac -'0'); } else if((*strmac >= 'a')&&(*strmac <= 'f')){ pmac[i] = (pmac[i]<<4)|(*strmac -'a'+0X0A); } else if((*strmac >= 'A')&&(*strmac <= 'F')){ pmac[i] = (pmac[i]<<4)|(*strmac -'A'+0X0A); } else if(*strmac == '-'){ byUPTI = 0; i++; pmac[i] = 0; } else{ return -1; } if(byUPTI >2){ return -1; } strmac++; limit --; } if(limit == 0){ return 0; } else{ return -1; }}_U32 sysVerifyMASKAddress(_S8 *szMaskAdd){ _S8 *pData; _U8 ucMask = 0xff; _U8 ucTmpMask; _U8 ucByte; _U32 ulCount = 0, ulIpByte = 0; _S8 pTmp[4]; _U32 i, ulAllOne = 1; pData = szMaskAdd; pTmp[0] = pTmp[1] = pTmp[2] = pTmp[3] = '\0'; if(pData == G_NULL) { return G_FAILURE; } for(;;) { if(isdigit(*pData)) { if(ulIpByte > 2) return G_FAILURE; pTmp[ulIpByte] = *pData; } else if((*pData == '.') || (*pData == '\0')) { ulCount ++; ulIpByte = (_U32)-1; ucByte = (_U8)atoi(pTmp); if((ulCount > 4) || (pTmp[0] == '\0') || (ucByte > 255)) return G_FAILURE; ucTmpMask = ucMask; for(i = 0; i < 8; i++) { if(ucByte == ucTmpMask) break; ucTmpMask = (_S8)(ucTmpMask << 1); } if((i == 8) && (ucByte != 0)) return G_FAILURE; if((ucTmpMask != 0xff) && (ulAllOne == 1)) ulAllOne = 0; else if((ucTmpMask != 0x00) && (ulAllOne == 0)) return G_FAILURE; pTmp[0] = pTmp[1] = pTmp[2] = pTmp[3] = '\0'; if(*pData == '\0') { if(ulCount < 4) return G_FAILURE; return G_SUCCESS; } } else return G_FAILURE; pData ++; ulIpByte ++; }}_U32 sysVerifyMACAddress(_S8 *szMACAdd){ _S8 *pData; _U32 ulCount = 0, ulIpByte = 0; _S8 pTmp[3]; pData = szMACAdd; pTmp[0] = pTmp[1] = pTmp[2] = '\0'; if(pData == G_NULL) { return G_FAILURE; } for(;;) { if (((*pData >= '0') && (*pData <= '9')) ||((*pData >= 'a') && (*pData <= 'f')) ||((*pData >= 'A') && (*pData <= 'F'))) { if(ulIpByte > 1) return G_FAILURE; pTmp[ulIpByte] = *pData; } else if((*pData == '-') || (*pData == '\0')) { ulCount ++; if(ulIpByte != 2) return G_FAILURE; ulIpByte = (_U32)-1; if((ulCount > 6) || (pTmp[0] == '\0')) return G_FAILURE; pTmp[0] = pTmp[1] = pTmp[2] = '\0'; if(*pData == '\0') { if(ulCount < 6) return G_FAILURE; return G_SUCCESS; } } else return G_FAILURE; pData ++; ulIpByte ++; }}_U32 sysVerifyHostIPAddress(_S8 *szIPAdd){ _S8 *pData; _U32 ulCount = 0, ulIpByte = 0; _S8 pTmp[4]; pData = szIPAdd; pTmp[0] = pTmp[1] = pTmp[2] = pTmp[3] = '\0'; if(pData == NULL) { return FAILURE; } for(;;) { if(isdigit(*pData)) { if(ulIpByte > 2) return G_FAILURE; pTmp[ulIpByte] = *pData; } else if((*pData == '.') || (*pData == '\0')) { ulCount ++; ulIpByte = (_U32)-1; if(ulCount > 4) return G_FAILURE; if((atoi(pTmp) > 255) || (pTmp[0] == '\0')) return G_FAILURE; if((pTmp[0] == '0') && (pTmp[1] == '\0') && (ulCount == 1)) return G_FAILURE; pTmp[0] = pTmp[1] = pTmp[2] = pTmp[3] = '\0'; if(*pData == '\0') { if(ulCount < 4) return G_FAILURE; return G_SUCCESS; } } else return G_FAILURE; pData ++; ulIpByte ++; }}/*只支持点分十进制转换,如10.10.10.1,前后中间不能有空格*/_U32 sysStrToIp(_S8 *ipstr){ _U32 ip; _U8 *curpos; _U8 tempbyte; _S16 dotnum,lenbetweendot,lenlimit; ip = 0; dotnum = 0; lenbetweendot = 0; lenlimit = sizeof("255.255.255.255"); curpos = ipstr; if(ipstr == 0) return 0; tempbyte = 0; while(lenlimit > 0) { if((*curpos >= '0') && (*curpos <= '9')){ if(lenbetweendot >=3){ ip = 0; break; } tempbyte = tempbyte*10 + *curpos - '0'; lenbetweendot++; } else if(*curpos == '.'){ if(lenbetweendot == 0){ ip = 0; break; } ip = (ip<<8) + tempbyte; tempbyte = 0; dotnum ++; lenbetweendot = 0; } else if(lenbetweendot > 3){ ip = 0; break; } else if(*curpos == 0) { ip = (ip<<8) + tempbyte; tempbyte = 0; break; } curpos ++; lenlimit --; } if(dotnum != 3) ip = 0; ip = htonl(ip); return ip;}/*地址到字符串,地址为网络序*/void sysIpToStr(_U32 ip,_S8 *strip){ _U8 addr[4]; *((_U32 *)addr) = ip; sprintf(strip,"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]);}_U32 sysMacIsBrdCast(_S8 *pDestMAC){ _U8 BroadCase[MAC_ADDR_SIZE] = {0xff,0xff,0xff,0xff,0xff,0xff}; if (0 == memcmp(pDestMAC,BroadCase,MAC_ADDR_SIZE)) { return SUCCESS; } return FAILURE;}void Drv_FeedHardWatchDog(){ }_U32 CalcSum(_U32 num, ...){ va_list Ap; _U32 sum = 0; va_start(Ap, num); for (;num > 0;num--) { sum += va_arg(Ap, _U32); } va_end(Ap); return sum;}_U32 BSP_GetPCBVer(_VOID){ _U16 usPcbVer0 = 0; _U32 ulPcbVer1 = 0; _U32 ulRet; *PADIR(INTERNAL_MEM_MAP_ADDR) &= ~PCB_VER0; *PBDIR(INTERNAL_MEM_MAP_ADDR) &= ~PCB_VER1; usPcbVer0 = (*PADAT(INTERNAL_MEM_MAP_ADDR)) & PCB_VER0; ulPcbVer1 = (*PBDAT(INTERNAL_MEM_MAP_ADDR)) & PCB_VER1; ulRet = (_U32)(usPcbVer0 >> PCB_VER0_SHIFT) + (ulPcbVer1 >> PCB_VER1_SHIFT); return ulRet;}VOID PressAnyKeyToContinue( _U8 *pucFile, _U32 ulLine ){ unsigned long ulRet; unsigned char szString; Drv_Print( "\r\nI'm here! File:%s Line:%d", pucFile, ulLine ); Drv_Print( "\r\nPress Any Key To Continue" ); ulRet = FAILURE; while( ulRet == FAILURE ) { InChar( &szString, &ulRet ); taskDelay( 1 ); } Drv_Print( "\r\n%c\r\nContinue...", szString ); return;}void Reboot(void){ sysToMonitor( BOOT_COLD ); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -