Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

243 Zeilen
8.7 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief This module contains common APIs declarations.
  6. *
  7. * Copyright (c) 2017-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. /**@defgroup COMMON COMMON
  35. */
  36. #ifndef _NM_COMMON_H_
  37. #define _NM_COMMON_H_
  38. #include "bsp/include/nm_bsp.h"
  39. #include "common/include/nm_debug.h"
  40. /**@defgroup COMMONDEF Defines
  41. * @ingroup COMMON
  42. */
  43. /**@{*/
  44. #define M2M_TIME_OUT_DELAY 10000
  45. /*states*/
  46. #define M2M_SUCCESS ((sint8)0)
  47. #define M2M_ERR_SEND ((sint8)-1)
  48. #define M2M_ERR_RCV ((sint8)-2)
  49. #define M2M_ERR_MEM_ALLOC ((sint8)-3)
  50. #define M2M_ERR_TIME_OUT ((sint8)-4)
  51. #define M2M_ERR_INIT ((sint8)-5)
  52. #define M2M_ERR_BUS_FAIL ((sint8)-6)
  53. #define M2M_NOT_YET ((sint8)-7)
  54. #define M2M_ERR_FIRMWARE ((sint8)-8)
  55. #define M2M_SPI_FAIL ((sint8)-9)
  56. #define M2M_ERR_FIRMWARE_bURN ((sint8)-10)
  57. #define M2M_ACK ((sint8)-11)
  58. #define M2M_ERR_FAIL ((sint8)-12)
  59. #define M2M_ERR_FW_VER_MISMATCH ((sint8)-13)
  60. #define M2M_ERR_SCAN_IN_PROGRESS ((sint8)-14)
  61. /*
  62. Invalid argument
  63. */
  64. #define M2M_ERR_INVALID_ARG ((sint8)-15)
  65. /*i2c MAASTER ERR*/
  66. #define I2C_ERR_LARGE_ADDRESS 0xE1UL /*!< the address exceed the max addressing mode in i2c flash*/
  67. #define I2C_ERR_TX_ABRT 0xE2UL /*!< NO ACK from slave*/
  68. #define I2C_ERR_OVER_SIZE 0xE3UL /**/
  69. #define ERR_PREFIX_NMIS 0xE4UL /*!< wrong first four byte in flash NMIS*/
  70. #define ERR_FIRMEWARE_EXCEED_SIZE 0xE5UL /*!< Total size of firmware exceed the max size 256k*/
  71. /**/
  72. #define PROGRAM_START 0x26961735UL
  73. #define BOOT_SUCCESS 0x10add09eUL
  74. #define BOOT_START 0x12345678UL
  75. #define NBIT31 (0x80000000)
  76. #define NBIT30 (0x40000000)
  77. #define NBIT29 (0x20000000)
  78. #define NBIT28 (0x10000000)
  79. #define NBIT27 (0x08000000)
  80. #define NBIT26 (0x04000000)
  81. #define NBIT25 (0x02000000)
  82. #define NBIT24 (0x01000000)
  83. #define NBIT23 (0x00800000)
  84. #define NBIT22 (0x00400000)
  85. #define NBIT21 (0x00200000)
  86. #define NBIT20 (0x00100000)
  87. #define NBIT19 (0x00080000)
  88. #define NBIT18 (0x00040000)
  89. #define NBIT17 (0x00020000)
  90. #define NBIT16 (0x00010000)
  91. #define NBIT15 (0x00008000)
  92. #define NBIT14 (0x00004000)
  93. #define NBIT13 (0x00002000)
  94. #define NBIT12 (0x00001000)
  95. #define NBIT11 (0x00000800)
  96. #define NBIT10 (0x00000400)
  97. #define NBIT9 (0x00000200)
  98. #define NBIT8 (0x00000100)
  99. #define NBIT7 (0x00000080)
  100. #define NBIT6 (0x00000040)
  101. #define NBIT5 (0x00000020)
  102. #define NBIT4 (0x00000010)
  103. #define NBIT3 (0x00000008)
  104. #define NBIT2 (0x00000004)
  105. #define NBIT1 (0x00000002)
  106. #define NBIT0 (0x00000001)
  107. /*! Maximum of two values */
  108. #define M2M_MAX(A,B) ((A) > (B) ? (A) : (B))
  109. /*! Choose one of three values */
  110. #define M2M_SEL(x,m1,m2,m3) ((x>1)?((x>2)?(m3):(m2)):(m1))
  111. /*! Align to next multiple of 4 */
  112. #define WORD_ALIGN(val) (((val) & 0x03) ? ((val) + 4 - ((val) & 0x03)) : (val))
  113. #define DATA_PKT_OFFSET 4
  114. #ifndef BIG_ENDIAN
  115. /*! Most significant byte of 32bit word (LE) */
  116. #define BYTE_0(word) ((uint8)(((word) >> 0 ) & 0x000000FFUL))
  117. /*! Second most significant byte of 32bit word (LE) */
  118. #define BYTE_1(word) ((uint8)(((word) >> 8 ) & 0x000000FFUL))
  119. /*! Third most significant byte of 32bit word (LE) */
  120. #define BYTE_2(word) ((uint8)(((word) >> 16) & 0x000000FFUL))
  121. /*! Least significant byte of 32bit word (LE) */
  122. #define BYTE_3(word) ((uint8)(((word) >> 24) & 0x000000FFUL))
  123. #else
  124. /*! Most significant byte of 32bit word (BE) */
  125. #define BYTE_0(word) ((uint8)(((word) >> 24) & 0x000000FFUL))
  126. /*! Second most significant byte of 32bit word (BE) */
  127. #define BYTE_1(word) ((uint8)(((word) >> 16) & 0x000000FFUL))
  128. /*! Third most significant byte of 32bit word (BE) */
  129. #define BYTE_2(word) ((uint8)(((word) >> 8 ) & 0x000000FFUL))
  130. /*! Least significant byte of 32bit word (BE) */
  131. #define BYTE_3(word) ((uint8)(((word) >> 0 ) & 0x000000FFUL))
  132. #endif
  133. /**@}*/
  134. #ifdef __cplusplus
  135. extern "C" {
  136. #endif
  137. /**@defgroup COMMONAPI Functions
  138. * @ingroup COMMON
  139. */
  140. /**@{*/
  141. /*!
  142. * @fn void m2m_memcpy(uint8* pDst,uint8* pSrc,uint32 sz);
  143. * @brief Copy specified number of bytes from source buffer to destination buffer
  144. * @param [in] sz
  145. * number of data bytes to copy
  146. * @param [in] pSrc
  147. * source buffer
  148. * @param [out] pDst
  149. * destination buffer
  150. * @return None
  151. */
  152. NMI_API void m2m_memcpy(uint8* pDst,uint8* pSrc,uint32 sz);
  153. /*!
  154. * @fn void m2m_memset(uint8* pBuf,uint8 val,uint32 sz);
  155. * @brief Set specified number of data bytes in specified data buffer to specified value
  156. * @param [in] sz
  157. * number of data bytes (in specified data buffer whose values are to be set to the specified value)
  158. * @param [in] val
  159. * the specified value (to which data bytes in data buffer will be set)
  160. * @param [out] pBuf
  161. * the specified data buffer (whose data bytes will be set to the specified value)
  162. * @return None
  163. */
  164. NMI_API void m2m_memset(uint8* pBuf,uint8 val,uint32 sz);
  165. /*!
  166. * @fn uint16 m2m_strlen(uint8 * pcStr);
  167. * @brief Returns the string length of a null terminated string buffer
  168. * @param [in] pcStr
  169. * null terminated string buffer
  170. * @return length of the string in the specified string buffer
  171. */
  172. NMI_API uint16 m2m_strlen(uint8 * pcStr);
  173. /*!
  174. * @fn sint8 m2m_memcmp(uint8 *pu8Buff1,uint8 *pu8Buff2 ,uint32 u32Size);
  175. * @brief Compare specified number of data bytes in pu8Buff1 and pu8Buff2 and decide if they all match.
  176. * @param [in] u32Size
  177. * number of data bytes to compare
  178. * @param [in] pu8Buff1
  179. * one of two data buffers for the comparison
  180. * @param [in] pu8Buff2
  181. * one of two data buffers for the comparison
  182. * @return zero if matched, one if not matched
  183. */
  184. NMI_API sint8 m2m_memcmp(uint8 *pu8Buff1,uint8 *pu8Buff2 ,uint32 u32Size);
  185. /*!
  186. * @fn uint8 m2m_strncmp(uint8 *pcS1, uint8 *pcS2, uint16 u16Len);
  187. * @brief Compare specified number of data bytes in string buffers pcS1 and pcS2
  188. * @param [in] u16Len
  189. * Number of data bytes to compare
  190. * @param [in] pcS1
  191. * first of two string buffers for the comparison
  192. * @param [in] pcS2
  193. * second of two string buffers for the comparison
  194. * @return 0 if matched, -1 if the first non-matching byte in pcS1 is smaller than that in pcS2, +1 if it is bigger
  195. */
  196. NMI_API uint8 m2m_strncmp(uint8 *pcS1, uint8 *pcS2, uint16 u16Len);
  197. /*!
  198. * @fn uint8 * m2m_strstr(uint8 *pcIn, uint8 *pcStr);
  199. * @brief Find the occurrence of pcStr string in pcIn string
  200. * @param [in] pcStr
  201. * one of two string buffers
  202. * @param [in] pcIn
  203. * one of two string buffers
  204. * @return If pcStr string is part of pcIn string return a valid pointer to the start of pcStr within pcIn. If not a NULL Pointer is returned
  205. */
  206. NMI_API uint8 * m2m_strstr(uint8 *pcIn, uint8 *pcStr);
  207. /*!
  208. * @fn uint8 m2m_checksum(uint8* buf, int sz);
  209. * @brief calculates checksum for the specified number of data bytes in specified data buffer
  210. * @param [in] sz
  211. * number of data bytes used in the checksum calculation
  212. * @param [in] buf
  213. * the specified data buffer (whose data bytes will be used to calculate the checksum)
  214. * @return the calculated checksum
  215. */
  216. NMI_API uint8 m2m_checksum(uint8* buf, int sz);
  217. /*!
  218. * @fn void (*at_sb_printf)(const char *_format, ...);
  219. * @brief chooses which function to use in order to output debug
  220. */
  221. NMI_API void (*at_sb_printf)(const char *_format, ...);
  222. /**@}*/
  223. #ifdef __cplusplus
  224. }
  225. #endif
  226. #endif /*_NM_COMMON_H_*/