1 /*
2  * @brief FLASH Memory Controller (FMC) registers and control functions
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 
32 #ifndef __FMC_15XX_H_
33 #define __FMC_15XX_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /** @defgroup FMC_15XX CHIP: LPC15xx FLASH Memory Controller driver
40  * @ingroup CHIP_15XX_Drivers
41  * @{
42  */
43 
44 /**
45  * @brief FLASH Memory Controller Unit register block structure
46  */
47 typedef struct {		/*!< FMC Structure */
48 	__I  uint32_t  RESERVED1[7];
49 	__IO uint32_t  FMSSTART;
50 	__IO uint32_t  FMSSTOP;
51 	__I  uint32_t  RESERVED2;
52 	__I  uint32_t  FMSW[1];
53 } LPC_FMC_T;
54 
55 /* Flash signature start and busy status bit */
56 #define FMC_FLASHSIG_BUSY   (1UL << 17)
57 
58 /**
59  * @brief	Start computation of a signature for a FLASH memory range
60  * @param	start	: Starting FLASH address for computation, must be aligned on 16 byte boundary
61  * @param	stop	: Ending FLASH address for computation, must be aligned on 16 byte boundary
62  * @return	Nothing
63  * @note	Only bits 20..4 are used for the FLASH signature computation.
64  *			Use the Chip_FMC_IsSignatureBusy() function to determine when the
65  *			signature computation operation is complete and use the
66  *			Chip_FMC_GetSignature() function to get the computed signature.
67  */
Chip_FMC_ComputeSignature(uint32_t start,uint32_t stop)68 STATIC INLINE void Chip_FMC_ComputeSignature(uint32_t start, uint32_t stop)
69 {
70 	LPC_FMC->FMSSTART = (start >> 4);
71 	LPC_FMC->FMSSTOP = (stop >> 4) | FMC_FLASHSIG_BUSY;
72 }
73 
74 /**
75  * @brief	Start computation of a signature for a FLASH memory address and block count
76  * @param	start	: Starting FLASH address for computation, must be aligned on 16 byte boundary
77  * @param	blocks	: Number of 16 byte blocks used for computation
78  * @return	Nothing
79  * @note	Only bits 20..4 are used for the FLASH signature computation.
80  *			Use the Chip_FMC_IsSignatureBusy() function to determine when the
81  *			signature computation operation is complete and the
82  *			Chip_FMC_GetSignature() function to get the computed signature.
83  */
Chip_FMC_ComputeSignatureBlocks(uint32_t start,uint32_t blocks)84 STATIC INLINE void Chip_FMC_ComputeSignatureBlocks(uint32_t start, uint32_t blocks)
85 {
86 	Chip_FMC_ComputeSignature(start, (start + (blocks * 16)));
87 }
88 
89 /**
90  * @brief	Check for signature geenration completion
91  * @return	true if the signature computation is running, false if finished
92  */
Chip_FMC_IsSignatureBusy(void)93 STATIC INLINE bool Chip_FMC_IsSignatureBusy(void)
94 {
95 	return (bool) ((LPC_FMC->FMSSTOP & FMC_FLASHSIG_BUSY) != 0);
96 }
97 
98 /**
99  * @brief	Returns the generated FLASH signature value
100  * @param	index	: Not used, must be 0
101  * @return	the generated FLASH signature value
102  */
Chip_FMC_GetSignature(int index)103 STATIC INLINE uint32_t Chip_FMC_GetSignature(int index)
104 {
105 	return LPC_FMC->FMSW[index];
106 }
107 
108 /**
109  * @}
110  */
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif /* __FMC_15XX_H_ */
117