efm32_msc.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /***************************************************************************//**
  2. * @file
  3. * @brief On-board Flash controller module peripheral API for EFM32
  4. * devices.
  5. * @author Energy Micro AS
  6. * @version 1.3.0
  7. *******************************************************************************
  8. * @section License
  9. * <b>(C) Copyright 2010 Energy Micro AS, http://www.energymicro.com</b>
  10. *******************************************************************************
  11. *
  12. * This source code is the property of Energy Micro AS. The source and compiled
  13. * code may only be used on Energy Micro "EFM32" microcontrollers.
  14. *
  15. * This copyright notice may not be removed from the source code nor changed.
  16. *
  17. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  18. * obligation to support this Software. Energy Micro AS is providing the
  19. * Software "AS IS", with no express or implied warranties of any kind,
  20. * including, but not limited to, any implied warranties of merchantability
  21. * or fitness for any particular purpose or warranties against infringement
  22. * of any proprietary rights of a third party.
  23. *
  24. * Energy Micro AS will not be liable for any consequential, incidental, or
  25. * special damages, or any other relief, or for any claim by any third party,
  26. * arising from your use of this Software.
  27. *
  28. ******************************************************************************/
  29. #ifndef __EFM32_MSC_H
  30. #define __EFM32_MSC_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #include "efm32.h"
  35. #include "core_cm3.h"
  36. #include <stdint.h>
  37. /***************************************************************************//**
  38. * @addtogroup EFM32_Library
  39. * @{
  40. ******************************************************************************/
  41. /***************************************************************************//**
  42. * @addtogroup MSC
  43. * @brief EFM32 Flash controller utilities.
  44. * @{
  45. ******************************************************************************/
  46. /*******************************************************************************
  47. ************************* DEFINES *****************************************
  48. ******************************************************************************/
  49. /**
  50. * @brief
  51. * The timeout used while waiting for the flash to become ready after
  52. * a write. This number indicates the number of iterations to perform before
  53. * issuing a timeout.
  54. * @note
  55. * This timeout is set very large (in the order of 100x longer than
  56. * necessary). This is to avoid any corner cases.
  57. *
  58. */
  59. #define MSC_PROGRAM_TIMEOUT 10000000ul
  60. /*******************************************************************************
  61. ************************* TYPEDEFS ****************************************
  62. ******************************************************************************/
  63. /** Return codes for writing/erasing the flash */
  64. typedef enum
  65. {
  66. mscReturnOk = 0, /**< Flash write/erase successful. */
  67. mscReturnInvalidAddr = -1, /**< Invalid address. Write to an address that is not flash. */
  68. mscReturnLocked = -2, /**< Flash address is locked. */
  69. mscReturnTimeOut = -3, /**< Timeout while writing to flash. */
  70. mscReturnUnaligned = -4 /**< Unaligned access to flash. */
  71. } msc_Return_TypeDef;
  72. /*******************************************************************************
  73. ************************* PROTOTYPES **************************************
  74. ******************************************************************************/
  75. void MSC_Deinit(void);
  76. void MSC_Init(void);
  77. /***************************************************************************//**
  78. * @brief
  79. * Clear one or more pending MSC interrupts.
  80. *
  81. * @param[in] flags
  82. * Pending MSC intterupt source to clear. Use a logical OR combination of
  83. * valid interrupt flags for the MSC module (MSC_IF_nnn).
  84. ******************************************************************************/
  85. static __INLINE void MSC_IntClear(uint32_t flags)
  86. {
  87. MSC->IFC = flags;
  88. }
  89. /***************************************************************************//**
  90. * @brief
  91. * Disable one or more MSC interrupts.
  92. *
  93. * @param[in] flags
  94. * MSC interrupt sources to disable. Use a logical OR combination of
  95. * valid interrupt flags for the MSC module (MSC_IF_nnn).
  96. ******************************************************************************/
  97. static __INLINE void MSC_IntDisable(uint32_t flags)
  98. {
  99. MSC->IEN &= ~(flags);
  100. }
  101. /***************************************************************************//**
  102. * @brief
  103. * Enable one or more MSC interrupts.
  104. *
  105. * @note
  106. * Depending on the use, a pending interrupt may already be set prior to
  107. * enabling the interrupt. Consider using MSC_IntClear() prior to enabling
  108. * if such a pending interrupt should be ignored.
  109. *
  110. * @param[in] flags
  111. * MSC interrupt sources to enable. Use a logical OR combination of
  112. * valid interrupt flags for the MSC module (MSC_IF_nnn).
  113. ******************************************************************************/
  114. static __INLINE void MSC_IntEnable(uint32_t flags)
  115. {
  116. MSC->IEN |= flags;
  117. }
  118. /***************************************************************************//**
  119. * @brief
  120. * Get pending MSV interrupt flags.
  121. *
  122. * @note
  123. * The event bits are not cleared by the use of this function.
  124. *
  125. * @return
  126. * MSC interrupt sources pending. A logical OR combination of valid
  127. * interrupt flags for the MSC module (MSC_IF_nnn).
  128. ******************************************************************************/
  129. static __INLINE uint32_t MSC_IntGet(void)
  130. {
  131. return(MSC->IF);
  132. }
  133. /***************************************************************************//**
  134. * @brief
  135. * Set one or more pending MSC interrupts from SW.
  136. *
  137. * @param[in] flags
  138. * MSC interrupt sources to set to pending. Use a logical OR combination of
  139. * valid interrupt flags for the MSC module (MSC_IF_nnn).
  140. ******************************************************************************/
  141. static __INLINE void MSC_IntSet(uint32_t flags)
  142. {
  143. MSC->IFS = flags;
  144. }
  145. #ifdef __CC_ARM /* MDK-ARM compiler */
  146. msc_Return_TypeDef MSC_WriteWord(uint32_t *address, void *data, int numBytes);
  147. msc_Return_TypeDef MSC_ErasePage(uint32_t *startAddress);
  148. #endif /* __CC_ARM */
  149. #ifdef __ICCARM__ /* IAR compiler */
  150. __ramfunc msc_Return_TypeDef MSC_WriteWord(uint32_t *address, void *data, int numBytes);
  151. __ramfunc msc_Return_TypeDef MSC_ErasePage(uint32_t *startAddress);
  152. #endif /* __ICCARM__ */
  153. #ifdef __GNUC__ /* GCC based compilers */
  154. #ifdef __CROSSWORKS_ARM /* Rowley Crossworks */
  155. msc_Return_TypeDef MSC_WriteWord(uint32_t *address, void *data, int numBytes) __attribute__ ((section(".fast")));
  156. msc_Return_TypeDef MSC_ErasePage(uint32_t *startAddress) __attribute__ ((section(".fast")));
  157. #else /* Sourcery G++ */
  158. msc_Return_TypeDef MSC_WriteWord(uint32_t *address, void *data, int numBytes) __attribute__ ((section(".ram")));
  159. msc_Return_TypeDef MSC_ErasePage(uint32_t *startAddress) __attribute__ ((section(".ram")));
  160. #endif /* __GNUC__ */
  161. #endif /* __CROSSWORKS_ARM */
  162. /** @} (end addtogroup MSC) */
  163. /** @} (end addtogroup EFM32_Library) */
  164. #ifdef __cplusplus
  165. }
  166. #endif
  167. #endif /* __EFM32_MSC_H */