spifi_001.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * @brief SPIFI registers and control functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __SPIFI_001_H_
  32. #define __SPIFI_001_H_
  33. #include "sys_config.h"
  34. #include "cmsis.h"
  35. #include "spifi_rom_api.h"
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. // FIXME this file needs work and better explanations
  40. /** @defgroup IP_SPIFI_001 IP: SPIFI register block and driver
  41. * @ingroup IP_Drivers
  42. * @{
  43. */
  44. extern void cancel_mem_mode(SPIFIobj *obj);
  45. extern void (*set_mem_mode) (SPIFIobj *obj);
  46. /* mid level functions */
  47. extern int32_t checkAd(SPIFIobj *obj, SPIFIopers *opers);
  48. extern int32_t setProt(SPIFIobj *obj, SPIFIopers *opers, char *change,
  49. char *saveProt);
  50. extern int32_t check_block(SPIFIobj *obj, char *source, SPIFIopers *opers,
  51. uint32_t check_program);
  52. extern int32_t send_erase_cmd(SPIFIobj *obj, uint8_t op, uint32_t addr);
  53. extern uint32_t ck_erase(SPIFIobj *obj, uint32_t *addr, uint32_t length);
  54. extern int32_t prog_block(SPIFIobj *obj, char *source, SPIFIopers *opers,
  55. uint32_t *left_in_page);
  56. extern uint32_t ck_prog(SPIFIobj *obj, char *source, char *dest, uint32_t length);
  57. /* low level functions */
  58. extern void setSize(SPIFIobj *obj, int32_t value);
  59. extern int32_t setDev(SPIFIobj *obj, uint32_t opts, uint32_t mem_cmd,
  60. uint32_t prog_cmd);
  61. extern uint32_t cmd(uc op, uc addrLen, uc intLen, uint16_t len);
  62. extern uint32_t readAd(SPIFIobj *obj, uint32_t cmd, uint32_t addr);
  63. extern void send04(SPIFIobj *obj, uc op, uc len, uint32_t value);
  64. extern void wren_sendAd(SPIFIobj *obj, uint32_t cmd, uint32_t addr, uint32_t value);
  65. extern int32_t write_stat(SPIFIobj *obj, uc len, uint16_t value);
  66. extern int32_t wait_busy(SPIFIobj *obj, uc prog_or_erase);
  67. /**
  68. * @brief This call sends the standardized Read JEDEC ID command to the
  69. * attached serial Flash device. If it responds, it is set up for reading
  70. * in ARM memory space.
  71. * @param obj : Pointer to uninitialized SPIFIobj structure
  72. * @param csHigh : Value that is one less than the minimum number of clock
  73. * cycles with the CS pin high, that the SPIFI should maintain between
  74. * commands. Compute this from the SPIFI clock period and the minimum high
  75. * time of CS from the serial flash data sheet:
  76. * csHigh = ceiling( min CS high / SPIFI clock period) - 1
  77. * @param options : contains bits controlling the SPIFI behavior. See @ref IP_SPIFI_OPTIONS
  78. * @param mhz : should be the serial clock divided by 1000000.
  79. * @return A return value of zero indicates success. Non-zero error codes indicate various error states.
  80. */
  81. STATIC INLINE int32_t IP_SPIFI_Init(SPIFIobj *obj, uint32_t csHigh, uint32_t options, uint32_t mhz)
  82. {
  83. return spifi_init(obj, csHigh, options, mhz);
  84. }
  85. /**
  86. * @brief This call programs opers.length bytes in the serial flash. An
  87. * IP_SPIFI_Program call with source equal to opers.dest and opers.options
  88. * not including S_FORCE_ERASE can be used to protect or unprotect sectors
  89. * depending on the value of opers.protect.
  90. * @param obj : Pointer to initialized SPIFIobj structure (from IP_SPIFI_Init)
  91. * @param source : is the address of the data to be programmed
  92. * @param opers : specifies programming and erasing options
  93. * @return A return value of zero indicates success. Non-zero error codes
  94. * indicate various error states.
  95. */
  96. STATIC INLINE int32_t IP_SPIFI_Program(SPIFIobj *obj, char *source, SPIFIopers *opers)
  97. {
  98. return spifi_program(obj, source, opers);
  99. }
  100. /**
  101. * @brief This call erases opers.length bytes in the serial flash.
  102. * @param obj : Pointer to initialized SPIFIobj structure (from IP_SPIFI_Init)
  103. * @param opers : specifies erasing options
  104. * @return A return value of zero indicates success. Non-zero error codes
  105. * indicate various error states.
  106. */
  107. STATIC INLINE int32_t IP_SPIFI_Erase(SPIFIobj *obj, SPIFIopers *opers)
  108. {
  109. return spifi_erase(obj, opers);
  110. }
  111. /**
  112. * @brief : This function disables the memory mapping of the external QSPI flash.
  113. * @param obj : Pointer to initialized SPIFIobj structure (from IP_SPIFI_Init)
  114. * @return No return value
  115. */
  116. STATIC INLINE void IP_SPIFI_CancelMemMode(SPIFIobj *obj)
  117. {
  118. cancel_mem_mode(obj);
  119. }
  120. STATIC INLINE void IP_SPIFI_SetMemMode(SPIFIobj *obj)
  121. {
  122. set_mem_mode(obj);
  123. }
  124. /* mid level functions */
  125. STATIC INLINE int32_t IP_SPIFI_checkAd(SPIFIobj *obj, SPIFIopers *opers)
  126. {
  127. return checkAd(obj, opers);
  128. }
  129. STATIC INLINE int32_t IP_SPIFI_setProt(SPIFIobj *obj, SPIFIopers *opers, char *change, char *saveProt)
  130. {
  131. return setProt(obj, opers, change, saveProt);
  132. }
  133. STATIC INLINE int32_t IP_SPIFI_CheckBlock(SPIFIobj *obj, char *source, SPIFIopers *opers,
  134. uint32_t check_program)
  135. {
  136. return check_block(obj, source, opers, check_program);
  137. }
  138. STATIC INLINE int32_t IP_SPIFI_SendEraseCmd(SPIFIobj *obj, uint8_t op, uint32_t addr)
  139. {
  140. return send_erase_cmd(obj, op, addr);
  141. }
  142. STATIC INLINE uint32_t IP_SPIFI_CkErase(SPIFIobj *obj, uint32_t *addr, uint32_t length)
  143. {
  144. return ck_erase(obj, addr, length);
  145. }
  146. STATIC INLINE int32_t IP_SPIFI_ProgBlock(SPIFIobj *obj, char *source, SPIFIopers *opers,
  147. uint32_t *left_in_page)
  148. {
  149. return prog_block(obj, source, opers, left_in_page);
  150. }
  151. STATIC INLINE uint32_t IP_SPIFI_CkProg(SPIFIobj *obj, char *source, char *dest, uint32_t length)
  152. {
  153. return ck_prog(obj, source, dest, length);
  154. }
  155. /* low level functions */
  156. STATIC INLINE void IP_SPIFI_SetSize(SPIFIobj *obj, int32_t value)
  157. {
  158. setSize(obj, value);
  159. }
  160. STATIC INLINE int32_t IP_SPIFI_SetDev(SPIFIobj *obj, uint32_t opts, uint32_t mem_cmd,
  161. uint32_t prog_cmd)
  162. {
  163. return setDev(obj, opts, mem_cmd, prog_cmd);
  164. }
  165. STATIC INLINE uint32_t IP_SPIFI_Cmd(uc op, uc addrLen, uc intLen, uint16_t len)
  166. {
  167. return cmd(op, addrLen, intLen, len);
  168. }
  169. STATIC INLINE uint32_t IP_SPIFI_ReadAd(SPIFIobj *obj, uint32_t cmd, uint32_t addr)
  170. {
  171. return readAd(obj, cmd, addr);
  172. }
  173. STATIC INLINE void IP_SPIFI_Send04(SPIFIobj *obj, uc op, uc len, uint32_t value)
  174. {
  175. send04(obj, op, len, value);
  176. }
  177. STATIC INLINE void IP_SPIFI_WrEnSendAd(SPIFIobj *obj, uint32_t cmd, uint32_t addr, uint32_t value)
  178. {
  179. wren_sendAd(obj, cmd, addr, value);
  180. }
  181. STATIC INLINE int32_t IP_SPIFI_WriteStat(SPIFIobj *obj, uc len, uint16_t value)
  182. {
  183. return write_stat(obj, len, value);
  184. }
  185. STATIC INLINE int32_t IP_SPIFI_WaitBusy(SPIFIobj *obj, uc prog_or_erase)
  186. {
  187. return wait_busy(obj, prog_or_erase);
  188. }
  189. /**
  190. * @}
  191. */
  192. #ifdef __cplusplus
  193. }
  194. #endif
  195. #endif /* __SPIFI_001_H_ */