1
1
/*
2
- * The Clear BSD License
3
2
* Copyright (c) 2016, Freescale Semiconductor, Inc.
4
3
* Copyright 2016-2017 NXP
5
4
* All rights reserved.
6
5
*
7
- * Redistribution and use in source and binary forms, with or without modification,
8
- * are permitted (subject to the limitations in the disclaimer below) provided
9
- * that the following conditions are met:
10
- *
11
- * o Redistributions of source code must retain the above copyright notice, this list
12
- * of conditions and the following disclaimer.
13
- *
14
- * o Redistributions in binary form must reproduce the above copyright notice, this
15
- * list of conditions and the following disclaimer in the documentation and/or
16
- * other materials provided with the distribution.
17
- *
18
- * o Neither the name of the copyright holder nor the names of its
19
- * contributors may be used to endorse or promote products derived from this
20
- * software without specific prior written permission.
21
- *
22
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6
+ * SPDX-License-Identifier: BSD-3-Clause
33
7
*/
34
8
35
9
#include "fsl_spifi.h"
38
12
* Definitions
39
13
******************************************************************************/
40
14
15
+ /* Component ID definition, used by tools. */
16
+ #ifndef FSL_COMPONENT_ID
17
+ #define FSL_COMPONENT_ID "platform.drivers.spifi"
18
+ #endif
19
+
41
20
/*******************************************************************************
42
21
* Prototypes
43
22
******************************************************************************/
44
23
45
- /*!
46
- * @brief Get the SPIFI instance from peripheral base address.
47
- *
48
- * @param base SPIFI peripheral base address.
49
- * @return SPIFI instance.
50
- */
51
- uint32_t SPIFI_GetInstance (SPIFI_Type * base );
52
-
53
24
/*******************************************************************************
54
25
* Variables
55
26
******************************************************************************/
@@ -62,9 +33,19 @@ static SPIFI_Type *const s_spifiBases[] = SPIFI_BASE_PTRS;
62
33
static const clock_ip_name_t s_spifiClock [] = SPIFI_CLOCKS ;
63
34
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
64
35
36
+ #if !(defined(FSL_FEATURE_SPIFI_HAS_NO_RESET ) && FSL_FEATURE_SPIFI_HAS_NO_RESET )
37
+ static const reset_ip_name_t s_spifiResets [] = SPIFI_RSTS ;
38
+ #endif
39
+
65
40
/*******************************************************************************
66
41
* Code
67
42
******************************************************************************/
43
+ /*!
44
+ * brief Get the SPIFI instance from peripheral base address.
45
+ *
46
+ * param base SPIFI peripheral base address.
47
+ * return SPIFI instance.
48
+ */
68
49
uint32_t SPIFI_GetInstance (SPIFI_Type * base )
69
50
{
70
51
uint32_t instance ;
@@ -83,8 +64,16 @@ uint32_t SPIFI_GetInstance(SPIFI_Type *base)
83
64
return instance ;
84
65
}
85
66
67
+ /*!
68
+ * brief Get SPIFI default configure settings.
69
+ *
70
+ * param config SPIFI config structure pointer.
71
+ */
86
72
void SPIFI_GetDefaultConfig (spifi_config_t * config )
87
73
{
74
+ /* Initializes the configure structure to zero. */
75
+ memset (config , 0 , sizeof (* config ));
76
+
88
77
config -> timeout = 0xFFFFU ;
89
78
config -> csHighTime = 0xFU ;
90
79
config -> disablePrefetch = false;
@@ -95,6 +84,14 @@ void SPIFI_GetDefaultConfig(spifi_config_t *config)
95
84
config -> dualMode = kSPIFI_QuadMode ;
96
85
}
97
86
87
+ /*!
88
+ * brief Initializes the SPIFI with the user configuration structure.
89
+ *
90
+ * This function configures the SPIFI module with the user-defined configuration.
91
+ *
92
+ * param base SPIFI peripheral base address.
93
+ * param config The pointer to the configuration structure.
94
+ */
98
95
void SPIFI_Init (SPIFI_Type * base , const spifi_config_t * config )
99
96
{
100
97
assert (config );
@@ -104,6 +101,10 @@ void SPIFI_Init(SPIFI_Type *base, const spifi_config_t *config)
104
101
CLOCK_EnableClock (s_spifiClock [SPIFI_GetInstance (base )]);
105
102
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
106
103
104
+ #if !(defined(FSL_FEATURE_SPIFI_HAS_NO_RESET ) && FSL_FEATURE_SPIFI_HAS_NO_RESET )
105
+ RESET_PeripheralReset (s_spifiResets [SPIFI_GetInstance (base )]);
106
+ #endif
107
+
107
108
/* Reset the Command register */
108
109
SPIFI_ResetCommand (base );
109
110
@@ -114,6 +115,11 @@ void SPIFI_Init(SPIFI_Type *base, const spifi_config_t *config)
114
115
SPIFI_CTRL_RFCLK (config -> isReadFullClockCycle ) | SPIFI_CTRL_FBCLK (config -> isFeedbackClock );
115
116
}
116
117
118
+ /*!
119
+ * brief Deinitializes the SPIFI regions.
120
+ *
121
+ * param base SPIFI peripheral base address.
122
+ */
117
123
void SPIFI_Deinit (SPIFI_Type * base )
118
124
{
119
125
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL ) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL )
@@ -122,29 +128,84 @@ void SPIFI_Deinit(SPIFI_Type *base)
122
128
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
123
129
}
124
130
131
+ /*!
132
+ * brief Set SPIFI flash command.
133
+ *
134
+ * param base SPIFI peripheral base address.
135
+ * param cmd SPIFI command structure pointer.
136
+ */
125
137
void SPIFI_SetCommand (SPIFI_Type * base , spifi_command_t * cmd )
126
138
{
127
- /* Wait for the CMD and MCINT flag all be 0 */
128
- while (SPIFI_GetStatusFlag (base ) & ( SPIFI_STAT_MCINIT_MASK | SPIFI_STAT_CMD_MASK ) )
139
+ /* If SPIFI in memory mode, call reset function to abort memory mode */
140
+ if (SPIFI_GetStatusFlag (base ) & SPIFI_STAT_MCINIT_MASK )
129
141
{
142
+ SPIFI_ResetCommand (base );
130
143
}
131
- base -> CMD = SPIFI_CMD_DATALEN (cmd -> dataLen ) | SPIFI_CMD_POLL (cmd -> isPollMode ) | SPIFI_CMD_DOUT (cmd -> direction ) |
132
- SPIFI_CMD_INTLEN (cmd -> intermediateBytes ) | SPIFI_CMD_FIELDFORM (cmd -> format ) |
133
- SPIFI_CMD_FRAMEFORM (cmd -> type ) | SPIFI_CMD_OPCODE (cmd -> opcode );
134
144
135
- /* Wait for the command written */
136
- while ((base -> STAT & SPIFI_STAT_CMD_MASK ) == 0U )
145
+ /* Wait for other command finished */
146
+ while (SPIFI_GetStatusFlag (base ) & SPIFI_STAT_CMD_MASK )
137
147
{
138
148
}
149
+
150
+ base -> CMD = SPIFI_CMD_DATALEN (cmd -> dataLen ) | SPIFI_CMD_POLL (cmd -> isPollMode ) | SPIFI_CMD_DOUT (cmd -> direction ) |
151
+ SPIFI_CMD_INTLEN (cmd -> intermediateBytes ) | SPIFI_CMD_FIELDFORM (cmd -> format ) |
152
+ SPIFI_CMD_FRAMEFORM (cmd -> type ) | SPIFI_CMD_OPCODE (cmd -> opcode );
139
153
}
140
154
155
+ /*!
156
+ * brief Set SPIFI flash AHB read command.
157
+ *
158
+ * Call this function means SPIFI enters to memory mode, while users need to use command, a SPIFI_ResetCommand shall
159
+ * be called.
160
+ *
161
+ * param base SPIFI peripheral base address.
162
+ * param cmd SPIFI command structure pointer.
163
+ */
141
164
void SPIFI_SetMemoryCommand (SPIFI_Type * base , spifi_command_t * cmd )
142
165
{
143
- /* Wait for the CMD and MCINT flag all be 0 */
144
- while (SPIFI_GetStatusFlag (base ) & ( SPIFI_STAT_MCINIT_MASK | SPIFI_STAT_CMD_MASK ) )
166
+ /* Wait for the CMD flag be 0 */
167
+ while (SPIFI_GetStatusFlag (base ) & SPIFI_STAT_CMD_MASK )
145
168
{
146
169
}
147
170
148
171
base -> MCMD = SPIFI_MCMD_POLL (0U ) | SPIFI_MCMD_DOUT (0U ) | SPIFI_MCMD_INTLEN (cmd -> intermediateBytes ) |
149
172
SPIFI_MCMD_FIELDFORM (cmd -> format ) | SPIFI_MCMD_FRAMEFORM (cmd -> type ) | SPIFI_MCMD_OPCODE (cmd -> opcode );
173
+
174
+ /* Wait for the command written */
175
+ while ((base -> STAT & SPIFI_STAT_MCINIT_MASK ) == 0 )
176
+ {
177
+ }
178
+ }
179
+
180
+ /*!
181
+ * brief Write a halfword data in address of SPIFI.
182
+ *
183
+ * Users can write a halfword data into SPIFI address.
184
+ *
185
+ * param base SPIFI peripheral base address.
186
+ * param data Data need be write.
187
+ */
188
+ void SPIFI_WriteDataHalfword (SPIFI_Type * base , uint16_t data )
189
+ {
190
+ volatile uint8_t * dataReg = ((volatile uint8_t * )(& (base -> DATA )));
191
+
192
+ * dataReg = (data & 0xFFU );
193
+ dataReg ++ ;
194
+ * dataReg = ((data >> 8U ) & 0xFFU );
195
+ }
196
+
197
+ /*!
198
+ * brief Read a halfword data from serial flash.
199
+ *
200
+ * param base SPIFI peripheral base address.
201
+ * return Data input from flash.
202
+ */
203
+ uint16_t SPIFI_ReadDataHalfword (SPIFI_Type * base )
204
+ {
205
+ uint16_t val = 0 ;
206
+ volatile uint8_t * dataReg = ((volatile uint8_t * )(& (base -> DATA )));
207
+
208
+ val = ((* dataReg ) | (uint16_t )((uint16_t )(* (dataReg + 1U )) << 8U ));
209
+
210
+ return val ;
150
211
}
0 commit comments