Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

130 строки
2.9 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief This module contains common APIs declarations.
  6. *
  7. * Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Subject to your compliance with these terms, you may use Microchip
  14. * software and any derivatives exclusively with Microchip products.
  15. * It is your responsibility to comply with third party license terms applicable
  16. * to your use of third party software (including open source software) that
  17. * may accompany Microchip software.
  18. *
  19. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
  20. * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
  21. * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
  22. * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
  23. * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
  24. * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
  25. * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
  26. * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
  27. * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
  28. * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  29. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  30. *
  31. * \asf_license_stop
  32. *
  33. */
  34. #include "common/include/nm_common.h"
  35. void m2m_memcpy(uint8* pDst,uint8* pSrc,uint32 sz)
  36. {
  37. if(sz == 0) return;
  38. do
  39. {
  40. *pDst = *pSrc;
  41. pDst++;
  42. pSrc++;
  43. }while(--sz);
  44. }
  45. uint8 m2m_checksum(uint8* buf, int sz)
  46. {
  47. uint8 cs = 0;
  48. while(--sz)
  49. {
  50. cs ^= *buf;
  51. buf++;
  52. }
  53. return cs;
  54. }
  55. void m2m_memset(uint8* pBuf,uint8 val,uint32 sz)
  56. {
  57. if(sz == 0) return;
  58. do
  59. {
  60. *pBuf = val;
  61. pBuf++;
  62. }while(--sz);
  63. }
  64. uint16 m2m_strlen(uint8 * pcStr)
  65. {
  66. uint16 u16StrLen = 0;
  67. while(*pcStr)
  68. {
  69. u16StrLen ++;
  70. pcStr++;
  71. }
  72. return u16StrLen;
  73. }
  74. uint8 m2m_strncmp(uint8 *pcS1, uint8 *pcS2, uint16 u16Len)
  75. {
  76. for ( ; u16Len > 0; pcS1++, pcS2++, --u16Len)
  77. if (*pcS1 != *pcS2)
  78. return ((*(uint8 *)pcS1 < *(uint8 *)pcS2) ? -1 : +1);
  79. else if (*pcS1 == '\0')
  80. return 0;
  81. return 0;
  82. }
  83. /* Finds the occurance of pcStr in pcIn.
  84. If pcStr is part of pcIn it returns a valid pointer to the start of pcStr within pcIn.
  85. Otherwise a NULL Pointer is returned.
  86. */
  87. uint8 * m2m_strstr(uint8 *pcIn, uint8 *pcStr)
  88. {
  89. uint8 u8c;
  90. uint16 u16StrLen;
  91. u8c = *pcStr++;
  92. if (!u8c)
  93. return (uint8 *) pcIn; // Trivial empty string case
  94. u16StrLen = m2m_strlen(pcStr);
  95. do {
  96. uint8 u8Sc;
  97. do {
  98. u8Sc = *pcIn++;
  99. if (!u8Sc)
  100. return (uint8 *) 0;
  101. } while (u8Sc != u8c);
  102. } while (m2m_strncmp(pcIn, pcStr, u16StrLen) != 0);
  103. return (uint8 *) (pcIn - 1);
  104. }
  105. sint8 m2m_memcmp(uint8 *pu8Buff1,uint8 *pu8Buff2 ,uint32 u32Size)
  106. {
  107. uint32 i;
  108. sint8 s8Result = 0;
  109. for(i = 0 ; i < u32Size ; i++)
  110. {
  111. if(pu8Buff1[i] != pu8Buff2[i])
  112. {
  113. s8Result = 1;
  114. break;
  115. }
  116. }
  117. return s8Result;
  118. }