/**********************************************************************@fnosal_strlen*@brief计算字符长度*@paramchar*pString-目标字符*@returnint-字符的长度*/intosal_strlen(char*pString){return(int)(strlen(pString));}/**********************************************************************@fnosal_memcpy*@brief复制字符串*@paramdst-目的字符串地址*@paramsrc-源字符串地址*@paramlen-复制的字节数*@return目的字符串的最后一个字节的地址*/void*osal_memcpy(void*dst,constvoidGENERIC*src,unsignedintlen){uint8*pDst;constuint8GENERIC*pSrc;pSrc=src;pDst=dst;while(len--)*pDst++=*pSrc++;return(pDst);}/**********************************************************************@fnosal_revmemcpy*@brief逆向复制字符串*@paramdst-目的字符串地址*@paramsrc-源字符串地址*@paramlen-复制的字节数*@return目的字符串的最后一个字节的地址*/void*osal_revmemcpy(void*dst,constvoidGENERIC*src,unsignedintlen){uint8*pDst;constuint8GENERIC*pSrc;pSrc=src;pSrc+=(len-1);pDst=dst;while(len--)*pDst++=*pSrc--;return(pDst);}/**********************************************************************@fnosal_memdup**@brief用osal_mem_alloc()函数分配一段存储区并把源字符串复制到新分配的空间中*@paramsrc-源字符串地址*@paramlen-复制的字节数**@return新建字符串地址*/void*osal_memdup(constvoidGENERIC*src,unsignedintlen){uint8*pDst;pDst=osal_mem_alloc(len);if(pDst){VOIDosal_memcpy(pDst,src,len);}return((void*)pDst);}/**********************************************************************@fnosal_memcmp**@brief比较字符串**@paramsrc1-第一源字符串地址*@paramsrc2-第二源字符串地址*@paramlen-要比较的字符串长度**@returnTRUE-相同,FALSE-不同*/uint8osal_memcmp(constvoidGENERIC*src1,constvoidGENERIC*src2,unsignedintlen){constuint8GENERIC*pSrc1;constuint8GENERIC*pSrc2;pSrc1=src1;pSrc2=src2;while(len--){if(*pSrc1++!=*pSrc2++)returnFALSE;}returnTRUE;}/**********************************************************************@fnosal_memset*@brief为一字符串集体赋同一数值*@paramdest-目标字符串*@paramvalue-要赋的值*@paramsize-长度*@return目的存储区地址*/void*osal_memset(void*dest,uint8value,intlen){returnmemset(dest,value,len);}/**********************************************************************@fnosal_build_uint16*@brief建立一个uint16变量*@paramswapped-0和1*@returnuint16*/uint16osal_build_uint16(uint8*swapped){return(BUILD_UINT16(swapped[0],swapped[1]));}/**********************************************************************@fnosal_build_uint32*@brief建立一个UINT32变量*@paramswapped-连续字节地址*@paramlen-uint8数组的字节数*@returnuint32*/uint32osal_build_uint32(uint8*swapped,uint8len){if(len==2)return(BUILD_UINT32(swapped[0],swapped[1],0L,0L));elseif(len==3)return(BUILD_UINT32(swapped[0],swapped[1],swapped[2],0L));elseif(len==4)return(BUILD_UINT32(swapped[0],swapped[1],swapped[2],swapped[3]));elsereturn((uint32)swapped[0]);}#if!defined(ZBIT)&&!defined(ZBIT2)&&!defined(UBIT)/**********************************************************************@fn_ltoa*@brief把一个长整形变量转换成一个字符串*@paraml-要转换的长整形*@parambuf-转换后的数据的指针*@paramradix-十进制十六进制*@return转换后的数据的指针*/unsignedchar*_ltoa(unsignedlongl,unsignedchar*buf,unsignedcharradix){#ifdefined(__GNUC__)return((char*)ltoa(l,buf,radix));#elseunsignedchartmp1[10]=,tmp2[10]=,tmp3[10]=;unsignedshortnum1,num2,num3;unsignedchari;buf[0]='\0';if(radix==10){num1=l%10000;num2=(l/10000)%10000;num3=(unsignedshort)(l/100000000);if(num3)_itoa(num3,tmp3,10);if(num2)_itoa(num2,tmp2,10);if(num1)_itoa(num1,tmp1,10);if(num3){strcpy((char*)buf,(charconst*)tmp3);for(i=0;i4-strlen((charconst*)tmp2);i++)strcat((char*)buf,0);}strcat((char*)buf,(charconst*)tmp2);if(num3||num2){for(i=0;i4-strlen((charconst*)tmp1);i++)strcat((char*)buf,0);}strcat((char*)buf,(charconst*)tmp1);if(!num3&&!num2&&!num1)strcpy((char*)buf,0);}elseif(radix==16){num1=l&0x0000FFFF;num2=l16;if(num2)_itoa(num2,tmp2,16);if(num1)_itoa(num1,tmp1,16);if(num2){strcpy((char*)buf,(charconst*)tmp2);for(i=0;i4-strlen((charconst*)tmp1);i++)strcat((char*)buf,0);}strcat((char*)buf,(charconst*)tmp1);if(!num2&&!num1)strcpy((char*)buf,0);}elsereturnNULL;returnbuf;#endif}#endif//!defined(ZBIT)&&!defined(ZBIT2)/**********************************************************************@fnosal_rand*@brief产生一个随机数*@paramnone*@returnuint16-产生的随机数*/uint16osal_rand(void){return(Onboard_rand());}/**********************************************************************APIFUNCTIONS*********************************************************************//**********************************************************************@fnosal_msg_allocate**@brief此函数用于在一个任务中创建一个消息缓存区*@paramuint8len-想创建的缓存区长度*@return创建的缓存区目标地址*/uint8*osal_msg_allocate(uint16len){osal_msg_hdr_t*hdr;if(len==0)return(NULL);hdr=(osal_msg_hdr_t*)osal_mem_alloc((short)(len+sizeof(osal_msg_hdr_t)));if(hdr){hdr-next=NULL;hdr-len=len;hdr-dest_id=TASK_NO_TASK;return((uint8*)(hdr+1));}elsereturn(NULL);}/**********************************************************************@fnosal_msg_deallocate*@brief此函数用于释放消息缓冲区。*@paramuint8*msg_ptr-新的消息缓存区地址*@returnSUCCESS,INVALID_MSG_POINTER*/uint8osal_msg_deallocate(uint8*msg_ptr){uint8*x;if(msg_ptr==NULL)return(INVALID_MSG_POINTER);//don'tdeallocatequeuedbufferif(OSAL_MSG_ID(msg_ptr)!=TASK_NO_TASK)return(MSG_BUFFER_NOT_AVAIL);x=(uint8*)((uint8*)msg_ptr-sizeof(osal_msg_hdr_t));osal_me