⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swsstackcommon.c

📁 ucos在NEC平台下的移植
💻 C
字号:
#include"includes.h"
//-------------------------------------------------------------------------------------------------------
//  BYTE stackGetRandomByte(void)
//
//  DESCRIPTION:
//      Get a single return pseudo-random byte, initialized from msupInitRandom()
//
//  RETURN VALUE:
//      BYTE
//          The low part of the random word
//-------------------------------------------------------------------------------------------------------
extern UINT16 random;
BYTE stackGetRandomByte(void) {
    UINT8 n = 8;

    do {
        if ((random >> 8) & 0x80) {
            random = (random << 1) ^ RANDOM_POLY;
        } else {
            random = (random << 1);
        }
    } while (--n);

    return (BYTE) random;
} // msupGetRandomByte


//-----------------------------------------------------------------------------------------
//  ZBOOL ContentIsEqual(BYTE *a,BYTE *b, BYTE compareLength);
//
//  DESCRIPTION:
//            Compare the contents of two byte arrays,the length of the array is stored in compareLength.
//  PARAMETER:
//            BYTE *a,BYTE *b
//             Two byte pointers,point to the start address of two arrays;
//            BYTE compareLength,
//             The length of the array
//  RETURN-VALUE:
//            TRUE:the contents of the two byte arrays are equal.
//            FALSE:the contents of the two byte arrays are not equal.
//-----------------------------------------------------------------------------------------
ZBOOL ContentIsEqual(BYTE *a,BYTE *b, BYTE compareLength)
{
  BYTE length;
  for(length=0;length<compareLength;length++)
  	{
         if((*(a++))==(*(b++)))
		continue;
	  else
	  	break;
		 	
       }
  if(length==compareLength)
  	return TRUE;
  else 
  	return FALSE;
  
}

//-----------------------------------------------------------------
//  void ByteArrayContentCopy(BYTE *dest,BYTE *src, BYTE copyLength);
//
//  DESCRIPTION:
//           Copy the contents of the src to the dest.
//  PARAMETER:
//            BYTE *dest,
//            the start address of the dest byte array.
//            BYTE *src, 
//            the start address of the src byte array.
//            BYTE copyLength,
//            how many bytes should be copied,usually copyLength is the length of
//                   the src byte array,and the length of the two byte array should be equal.
//  RETURN-VALUE:
//             NO
//--------------------------------------------------------------------
void ByteArrayContentCopy(BYTE *dest,BYTE *src, BYTE copyLength)
{
 BYTE copiedLength;
 for(copiedLength=0;copiedLength<copyLength;copiedLength++)
 	{
          *dest++=*src++ ;
       }
   
}

//--------------------------------------------------------------------
//   ZBOOL NWKThisIsMyLongAddress( BYTE *address );
//
//   DESCRIPTION:
//            This function determines if the address stored in the  'BYTE *address' is my
//             long address.It will call the ContentIsEqual()function.
//   PARAMETER:
//            BYTE *address ,
//            The initial address of the byte array which is used to store the contents the deviceAddress
//            input from the nlmeLeaveRequest()function.
//   RETURN-VALUE:
//            TRUE - values at address match my long address
//            FALSE-else
//-----------------------------------------------------------------------
ZBOOL NWKThisIsMyLongAddress( BYTE *address )
{
  BYTE    macAddress[8];
  ZBOOL    result;
  GetMACAddress(macAddress);
  result=ContentIsEqual(macAddress, address, 8);
  return result;
}

//-----------------------------------------------------------------
//   BYTE *ContactTwoByteArray(BYTE *first,BYTE *second);
//
//   DESCRIPTION:
//          Contacts the contents of two byte array.
//   PARAMETER:
//           BYTE *first,
//                the initial address of the first byte array.
//           BYTE *second,
//                the initial address of the second byte array.
//   RETURN-VALUE:
//           NO,we return the initial address of the contacted array through 'first'.
//           This can save memory.
//-----------------------------------------------------------------
void ContactTwoByteArray(BYTE *first,BYTE *second)
{
  BYTE i;
  BYTE j;
  j=0;
  for(i=0;*first!=0x00;i++);
   do{ 
    *first++=*second++;
   	}while(*second!=0x00);
}


//----------------------------------------------------------------------------
//    BYTE CompareTime(INT16 startTimeStamp,INT16 endTimeStamp,INT16 duration);
//
//    DESCRIPTION:
//            Compare the two timaStamp to justify if timeout occurs
//    PARAMETER:
//            BYTE *startTimeStamp,
//              A pointer points to the startTimeStamp;
//            BYTE *endTimeStamp,
//              A pointer points to the endTimeStamp.
//            BYTE *duration
//              A pointer points to the duration.
//   RETURN-VALUES;
//            1:timeout occurs
//            -1:timeoutout doesn't occurs
//----------------------------------------------------------------------------
 INT8 CompareTime(TICK startTimeStamp,TICK endTimeStamp,TICK duration)
{
 TICK zero;
 zero=0;
  if((endTimeStamp-(startTimeStamp+duration))>zero)
  	return (INT8)1;
  else
  	return (INT8)-1;
  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -