nm_common.c
Go to the documentation of this file.
1 
35 
36 void m2m_memcpy(uint8* pDst,uint8* pSrc,uint32 sz)
37 {
38  if(sz == 0) return;
39  do
40  {
41  *pDst = *pSrc;
42  pDst++;
43  pSrc++;
44  }while(--sz);
45 }
46 uint8 m2m_checksum(uint8* buf, int sz)
47 {
48  uint8 cs = 0;
49  while(--sz)
50  {
51  cs ^= *buf;
52  buf++;
53  }
54 
55  return cs;
56 }
57 
58 void m2m_memset(uint8* pBuf,uint8 val,uint32 sz)
59 {
60  if(sz == 0) return;
61  do
62  {
63  *pBuf = val;
64  pBuf++;
65  }while(--sz);
66 }
67 
69 {
70  uint16 u16StrLen = 0;
71  while(*pcStr)
72  {
73  u16StrLen ++;
74  pcStr++;
75  }
76  return u16StrLen;
77 }
78 
79 uint8 m2m_strncmp(uint8 *pcS1, uint8 *pcS2, uint16 u16Len)
80 {
81  for ( ; u16Len > 0; pcS1++, pcS2++, --u16Len)
82  if (*pcS1 != *pcS2)
83  return ((*(uint8 *)pcS1 < *(uint8 *)pcS2) ? -1 : +1);
84  else if (*pcS1 == '\0')
85  return 0;
86  return 0;
87 }
88 
89 /* Finds the occurance of pcStr in pcIn.
90 If pcStr is part of pcIn it returns a valid pointer to the start of pcStr within pcIn.
91 Otherwise a NULL Pointer is returned.
92 */
93 uint8 * m2m_strstr(uint8 *pcIn, uint8 *pcStr)
94 {
95  uint8 u8c;
96  uint16 u16StrLen;
97 
98  u8c = *pcStr++;
99  if (!u8c)
100  return (uint8 *) pcIn; // Trivial empty string case
101 
102  u16StrLen = m2m_strlen(pcStr);
103  do {
104  uint8 u8Sc;
105 
106  do {
107  u8Sc = *pcIn++;
108  if (!u8Sc)
109  return (uint8 *) 0;
110  } while (u8Sc != u8c);
111  } while (m2m_strncmp(pcIn, pcStr, u16StrLen) != 0);
112 
113  return (uint8 *) (pcIn - 1);
114 }
115 
116 sint8 m2m_memcmp(uint8 *pu8Buff1,uint8 *pu8Buff2 ,uint32 u32Size)
117 {
118  uint32 i;
119  sint8 s8Result = 0;
120  for(i = 0 ; i < u32Size ; i++)
121  {
122  if(pu8Buff1[i] != pu8Buff2[i])
123  {
124  s8Result = 1;
125  break;
126  }
127  }
128  return s8Result;
129 }
void m2m_memcpy(uint8 *pDst, uint8 *pSrc, uint32 sz)
Copy specified number of bytes from source buffer to destination buffer.
Definition: nm_common.c:36
This module contains common APIs declarations.
signed char sint8
Range of values between -128 to 127.
Definition: nm_bsp.h:111
sint8 m2m_memcmp(uint8 *pu8Buff1, uint8 *pu8Buff2, uint32 u32Size)
Compare specified number of data bytes in pu8Buff1 and pu8Buff2 and decide if they all match...
Definition: nm_common.c:116
uint8 * m2m_strstr(uint8 *pcIn, uint8 *pcStr)
Find the occurrence of pcStr string in pcIn string.
Definition: nm_common.c:93
unsigned short uint16
Range of values between 0 to 65535.
Definition: nm_bsp.h:96
void m2m_memset(uint8 *pBuf, uint8 val, uint32 sz)
Set specified number of data bytes in specified data buffer to specified value.
Definition: nm_common.c:58
uint16 m2m_strlen(uint8 *pcStr)
Returns the string length of a null terminated string buffer.
Definition: nm_common.c:68
unsigned long uint32
Range of values between 0 to 4294967295.
Definition: nm_bsp.h:103
unsigned char uint8
Range of values between 0 to 255.
Definition: nm_bsp.h:89
uint8 m2m_checksum(uint8 *buf, int sz)
calculates checksum for the specified number of data bytes in specified data buffer ...
Definition: nm_common.c:46
uint8 m2m_strncmp(uint8 *pcS1, uint8 *pcS2, uint16 u16Len)
Compare specified number of data bytes in string buffers pcS1 and pcS2.
Definition: nm_common.c:79


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58