fmc_8xx.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * @brief LPC8xx FLASH Memory Controller (FMC) driver
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2013
  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 __FMC_8XX_H_
  32. #define __FMC_8XX_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup FMC_8XX CHIP: LPC8xx FLASH Memory Controller driver
  37. * @ingroup CHIP_8XX_Drivers
  38. * @{
  39. */
  40. /**
  41. * @brief FLASH Memory Controller Unit register block structure
  42. */
  43. typedef struct {
  44. __I uint32_t RESERVED1[4];
  45. __IO uint32_t FLASHCFG; /*!< Flash Configuration register */
  46. __I uint32_t RESERVED2[3];
  47. __IO uint32_t FMSSTART; /*!< Signature start address register */
  48. __IO uint32_t FMSSTOP; /*!< Signature stop address register */
  49. __I uint32_t RESERVED3;
  50. __I uint32_t FMSW[1]; /*!< Signature word regsiter */
  51. } LPC_FMC_T;
  52. /* Reserved bits masks for registers */
  53. #define FMC_FLASHCFG_RESERVED (~3)
  54. #define FMC_FMSSTART_RESERVED 0xfffe0000
  55. #define FMC_FMSSTOP_RESERVED 0x7ffe0000
  56. /**
  57. * @brief FLASH Access time definitions
  58. */
  59. typedef enum {
  60. FLASHTIM_20MHZ_CPU = 0, /*!< Flash accesses use 1 CPU clocks. Use for up to 20 MHz CPU clock*/
  61. FLASHTIM_30MHZ_CPU = 1, /*!< Flash accesses use 2 CPU clocks. Use for up to 30 MHz CPU clock*/
  62. } FMC_FLASHTIM_T;
  63. /**
  64. * @brief Set FLASH memory access time in clocks
  65. * @param clks : Clock cycles for FLASH access
  66. * @return Nothing
  67. * @note For CPU speed up to 20MHz, use a value of 0. For up to 30MHz, use
  68. * a value of 1
  69. */
  70. STATIC INLINE void Chip_FMC_SetFLASHAccess(FMC_FLASHTIM_T clks)
  71. {
  72. uint32_t tmp = LPC_FMC->FLASHCFG & (~((0x3)|FMC_FLASHCFG_RESERVED));
  73. /* Don't alter upper bits */
  74. LPC_FMC->FLASHCFG = tmp | clks;
  75. }
  76. /* Flash signature start and busy status bit */
  77. #define FMC_FLASHSIG_BUSY (1UL << 31)
  78. /**
  79. * @brief Start computation of a signature for a FLASH memory range
  80. * @param start : Starting FLASH address for computation, must be aligned on 16 byte boundary
  81. * @param stop : Ending FLASH address for computation, must be aligned on 16 byte boundary
  82. * @return Nothing
  83. * @note Only bits 20..4 are used for the FLASH signature computation.
  84. * Use the Chip_FMC_IsSignatureBusy() function to determine when the
  85. * signature computation operation is complete and the
  86. * Chip_FMC_GetSignature() function to get the computed signature.
  87. */
  88. STATIC INLINE void Chip_FMC_ComputeSignature(uint32_t start, uint32_t stop)
  89. {
  90. LPC_FMC->FMSSTART = (start >> 4);
  91. LPC_FMC->FMSSTOP = (stop >> 4) | FMC_FLASHSIG_BUSY;
  92. }
  93. /**
  94. * @brief Start computation of a signature for a FLASH memory address and block count
  95. * @param start : Starting FLASH address for computation, must be aligned on 16 byte boundary
  96. * @param blocks : Number of 16 byte blocks used for computation
  97. * @return Nothing
  98. * @note Only bits 20..4 are used for the FLASH signature computation.
  99. * Use the Chip_FMC_IsSignatureBusy() function to determine when the
  100. * signature computation operation is complete and the
  101. * Chip_FMC_GetSignature() function to get the computed signature.
  102. */
  103. STATIC INLINE void Chip_FMC_ComputeSignatureBlocks(uint32_t start, uint32_t blocks)
  104. {
  105. Chip_FMC_ComputeSignature(start, (start + (blocks * 16)));
  106. }
  107. /**
  108. * @brief Check for signature geenration completion
  109. * @return true if the signature computation is running, false if finished
  110. */
  111. STATIC INLINE bool Chip_FMC_IsSignatureBusy(void)
  112. {
  113. return (bool) ((LPC_FMC->FMSSTOP & FMC_FLASHSIG_BUSY) != 0);
  114. }
  115. /**
  116. * @brief Returns the generated FLASH signature value
  117. * @param index : Signature index, must be 0
  118. * @return the generated FLASH signature value
  119. */
  120. STATIC INLINE uint32_t Chip_FMC_GetSignature(int index)
  121. {
  122. return LPC_FMC->FMSW[index];
  123. }
  124. /**
  125. * @}
  126. */
  127. #ifdef __cplusplus
  128. }
  129. #endif
  130. #endif /* __FMC_8XX_H_ */