Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

173 linhas
7.0 KiB

  1. /*******************************************************************************
  2. File Name:
  3. nm_common.h
  4. Summary:
  5. This module contains common APIs declarations.
  6. Description:
  7. This module contains common APIs declarations.
  8. *******************************************************************************/
  9. //DOM-IGNORE-BEGIN
  10. /*******************************************************************************
  11. * Copyright (C) 2021 Microchip Technology Inc. and its subsidiaries.
  12. *
  13. * Subject to your compliance with these terms, you may use Microchip software
  14. * and any derivatives exclusively with Microchip products. It is your
  15. * responsibility to comply with third party license terms applicable to your
  16. * use of third party software (including open source software) that may
  17. * accompany Microchip software.
  18. *
  19. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
  20. * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
  21. * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
  22. * PARTICULAR PURPOSE.
  23. *
  24. * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
  25. * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
  26. * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
  27. * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
  28. * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
  29. * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  30. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  31. *******************************************************************************/
  32. //DOM-IGNORE-END
  33. /** @defgroup COMMON Common
  34. @{
  35. @defgroup COMMONDEF Defines
  36. @defgroup COMMONAPI Functions
  37. @}
  38. */
  39. #ifndef _NM_COMMON_H_
  40. #define _NM_COMMON_H_
  41. #include <stdint.h>
  42. #include "define.h"
  43. #include "nm_bsp.h"
  44. #include "nm_debug.h"
  45. /**@addtogroup COMMONDEF
  46. * @{
  47. */
  48. /*states*/
  49. #define M2M_SUCCESS ((int8_t)0)
  50. #define M2M_ERR_SEND ((int8_t)-1)
  51. #define M2M_ERR_RCV ((int8_t)-2)
  52. #define M2M_ERR_MEM_ALLOC ((int8_t)-3)
  53. #define M2M_ERR_TIME_OUT ((int8_t)-4)
  54. #define M2M_ERR_INIT ((int8_t)-5)
  55. #define M2M_ERR_BUS_FAIL ((int8_t)-6)
  56. #define M2M_NOT_YET ((int8_t)-7)
  57. #define M2M_ERR_FIRMWARE ((int8_t)-8)
  58. #define M2M_SPI_FAIL ((int8_t)-9)
  59. #define M2M_ERR_FIRMWARE_bURN ((int8_t)-10)
  60. #define M2M_ACK ((int8_t)-11)
  61. #define M2M_ERR_FAIL ((int8_t)-12)
  62. #define M2M_ERR_FW_VER_MISMATCH ((int8_t)-13)
  63. #define M2M_ERR_SCAN_IN_PROGRESS ((int8_t)-14)
  64. #define M2M_ERR_INVALID_ARG ((int8_t)-15)
  65. #define NBIT31 (0x80000000)
  66. #define NBIT30 (0x40000000)
  67. #define NBIT29 (0x20000000)
  68. #define NBIT28 (0x10000000)
  69. #define NBIT27 (0x08000000)
  70. #define NBIT26 (0x04000000)
  71. #define NBIT25 (0x02000000)
  72. #define NBIT24 (0x01000000)
  73. #define NBIT23 (0x00800000)
  74. #define NBIT22 (0x00400000)
  75. #define NBIT21 (0x00200000)
  76. #define NBIT20 (0x00100000)
  77. #define NBIT19 (0x00080000)
  78. #define NBIT18 (0x00040000)
  79. #define NBIT17 (0x00020000)
  80. #define NBIT16 (0x00010000)
  81. #define NBIT15 (0x00008000)
  82. #define NBIT14 (0x00004000)
  83. #define NBIT13 (0x00002000)
  84. #define NBIT12 (0x00001000)
  85. #define NBIT11 (0x00000800)
  86. #define NBIT10 (0x00000400)
  87. #define NBIT9 (0x00000200)
  88. #define NBIT8 (0x00000100)
  89. #define NBIT7 (0x00000080)
  90. #define NBIT6 (0x00000040)
  91. #define NBIT5 (0x00000020)
  92. #define NBIT4 (0x00000010)
  93. #define NBIT3 (0x00000008)
  94. #define NBIT2 (0x00000004)
  95. #define NBIT1 (0x00000002)
  96. #define NBIT0 (0x00000001)
  97. #ifndef BIG_ENDIAN
  98. /*! Most significant byte of 32bit word (LE) */
  99. #define BYTE_0(word) ((uint8_t)(((word) >> 0) & 0x000000FFUL))
  100. /*! Second most significant byte of 32bit word (LE) */
  101. #define BYTE_1(word) ((uint8_t)(((word) >> 8) & 0x000000FFUL))
  102. /*! Third most significant byte of 32bit word (LE) */
  103. #define BYTE_2(word) ((uint8_t)(((word) >> 16) & 0x000000FFUL))
  104. /*! Least significant byte of 32bit word (LE) */
  105. #define BYTE_3(word) ((uint8_t)(((word) >> 24) & 0x000000FFUL))
  106. #else
  107. /*! Most significant byte of 32bit word (BE) */
  108. #define BYTE_0(word) ((uint8_t)(((word) >> 24) & 0x000000FFUL))
  109. /*! Second most significant byte of 32bit word (BE) */
  110. #define BYTE_1(word) ((uint8_t)(((word) >> 16) & 0x000000FFUL))
  111. /*! Third most significant byte of 32bit word (BE) */
  112. #define BYTE_2(word) ((uint8_t)(((word) >> 8) & 0x000000FFUL))
  113. /*! Least significant byte of 32bit word (BE) */
  114. #define BYTE_3(word) ((uint8_t)(((word) >> 0) & 0x000000FFUL))
  115. #endif
  116. /**@}*/
  117. #ifdef __cplusplus
  118. extern "C" {
  119. #endif
  120. /*!
  121. * @ingroup COMMONAPI
  122. * @fn int8_t hexstr_2_bytes(uint8_t *pu8Out, uint8_t *pu8In, uint8_t u8SizeOut);
  123. * @brief Converts a string of hex characters to bytes.
  124. * @param[out] pu8Out
  125. * Output buffer (eg {0x11, 0x12, 0x13,...})
  126. * @param[in] pu8In
  127. * Input buffer (eg {0x31, 0x31, 0x31, 0x32, 0x31, 0x33, ...})
  128. * @param[in] u8SizeOut
  129. * Length of output buffer (should be half of the length of the input buffer).
  130. * @return @ref M2M_SUCCESS if successful, M2M_ERR_INVALID_ARG otherwise (eg unrecognised hexchar in input).
  131. */
  132. int8_t hexstr_2_bytes(uint8_t *pu8Out, uint8_t *pu8In, uint8_t u8SizeOut);
  133. /*!
  134. * @fn void nm_sleep(uint32_t u32TimeMsec);
  135. * @brief Used to put the host to sleep for the specified duration (in milliseconds).
  136. * Forcing the host to sleep for extended period may lead to host not being able to respond
  137. * to WINC board events. It is important to be considerate while choosing the sleep period.
  138. * @param [in] u32TimeMsec
  139. * Time unit in milliseconds.
  140. * @pre Initialize @ref nm_bsp_init first.
  141. * @note Implementation of this function is host dependent.
  142. * @warning Maximum value must nor exceed 4294967295 milliseconds which is equal to 4294967.295 seconds.
  143. * @see nm_bsp_init
  144. * @return None
  145. */
  146. void nm_sleep(uint32_t u32TimeMsec);
  147. /*!
  148. * @ingroup COMMONAPI
  149. * @fn nm_reset
  150. * @brief Reset NMC3400 SoC by setting CHIP_EN and RESET_N signals low,
  151. * CHIP_EN high then RESET_N high
  152. */
  153. void nm_reset(void);
  154. /**@}*/
  155. #ifdef __cplusplus
  156. }
  157. #endif
  158. #endif /*_NM_COMMON_H_*/