1 |
577 |
jeremybenn |
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
|
2 |
|
|
* File Name : 75x_smi.c
|
3 |
|
|
* Author : MCD Application Team
|
4 |
|
|
* Date First Issued : 03/10/2006
|
5 |
|
|
* Description : This file provides all the SMI software functions.
|
6 |
|
|
********************************************************************************
|
7 |
|
|
* History:
|
8 |
|
|
* 07/17/2006 : V1.0
|
9 |
|
|
* 03/10/2006 : V0.1
|
10 |
|
|
********************************************************************************
|
11 |
|
|
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
12 |
|
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
13 |
|
|
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
14 |
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
15 |
|
|
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
16 |
|
|
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
17 |
|
|
*******************************************************************************/
|
18 |
|
|
|
19 |
|
|
/* Includes ------------------------------------------------------------------*/
|
20 |
|
|
#include "75x_smi.h"
|
21 |
|
|
|
22 |
|
|
/* Private typedef -----------------------------------------------------------*/
|
23 |
|
|
/* Private define ------------------------------------------------------------*/
|
24 |
|
|
/* SMI_CR1 mask bits */
|
25 |
|
|
#define SMI_HOLDPRESCTCS_RESET_Mask 0xFF00800F
|
26 |
|
|
#define SMI_Prescaler_MaxValue 0x7F
|
27 |
|
|
#define SMI_DeselectTime_MaxValue 0x0F
|
28 |
|
|
#define SMI_ClockHold_Mask 0x00
|
29 |
|
|
#define SMI_Prescaler_Mask 0x02
|
30 |
|
|
#define SMI_DeselectTime_Mask 0x5
|
31 |
|
|
|
32 |
|
|
/* SMI_CR2 mask bits */
|
33 |
|
|
#define SMI_BS_RESET_Mask 0xFFFFCFFF
|
34 |
|
|
#define SMI_BS_Bank1_Mask 0x00001000
|
35 |
|
|
#define SMI_BS_Bank2_Mask 0x00002000
|
36 |
|
|
#define SMI_BS_Bank3_Mask 0x00003000
|
37 |
|
|
#define SMI_WEN_Mask 0x00000800
|
38 |
|
|
#define SMI_RSR_Mask 0x00000400
|
39 |
|
|
#define SMI_SEND_Mask 0x00000080
|
40 |
|
|
#define SMI_TRARECLENGTH_RESET_Mask 0xFFFFFF88
|
41 |
|
|
|
42 |
|
|
/* SMI_SR mask bits */
|
43 |
|
|
#define SMI_STATUSREGISTER_Mask 0xFF
|
44 |
|
|
|
45 |
|
|
/* Private macro -------------------------------------------------------------*/
|
46 |
|
|
/* Private variables ---------------------------------------------------------*/
|
47 |
|
|
/* Private function prototypes -----------------------------------------------*/
|
48 |
|
|
/* Private functions ---------------------------------------------------------*/
|
49 |
|
|
|
50 |
|
|
/*******************************************************************************
|
51 |
|
|
* Function Name : SMI_DeInit
|
52 |
|
|
* Description : Deinitializes the SMI peripheral registers to their default
|
53 |
|
|
* reset values. This function must not be used when booting
|
54 |
|
|
* from the SMI external memory.
|
55 |
|
|
* Input : None
|
56 |
|
|
* Output : None
|
57 |
|
|
* Return : None
|
58 |
|
|
*******************************************************************************/
|
59 |
|
|
void SMI_DeInit(void)
|
60 |
|
|
{
|
61 |
|
|
SMI->CR1 = 0x00000250;
|
62 |
|
|
SMI->CR2 = 0x00;
|
63 |
|
|
SMI->SR &= 0xFFFFF0FF;
|
64 |
|
|
SMI->TR = 0x00;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
/*******************************************************************************
|
68 |
|
|
* Function Name : SMI_Init
|
69 |
|
|
* Description : Initializes the SMI peripheral according to the specified
|
70 |
|
|
* parameters in the SMI_InitStruct.
|
71 |
|
|
* Input : - SMI_InitStruct: pointer to a SMI_InitTypeDef structure that
|
72 |
|
|
* contains the configuration information for the specified
|
73 |
|
|
* SMI peripheral.
|
74 |
|
|
* Output : None
|
75 |
|
|
* Return : None
|
76 |
|
|
*******************************************************************************/
|
77 |
|
|
void SMI_Init(SMI_InitTypeDef* SMI_InitStruct)
|
78 |
|
|
{
|
79 |
|
|
u32 Temp = 0;
|
80 |
|
|
|
81 |
|
|
/* Clear HOLD[7:0], PRESC[6:0] and TCS[3:0] bits */
|
82 |
|
|
Temp = SMI->CR1 & SMI_HOLDPRESCTCS_RESET_Mask;
|
83 |
|
|
|
84 |
|
|
/* Set HOLD[7:0] bits according to SMI_ClockHold value */
|
85 |
|
|
Temp |= SMI_InitStruct->SMI_ClockHold << 16;
|
86 |
|
|
|
87 |
|
|
if(SMI_InitStruct->SMI_Prescaler <= SMI_Prescaler_MaxValue)
|
88 |
|
|
{
|
89 |
|
|
/* Set PRESC[6:0] bits according to SMI_Prescaler value */
|
90 |
|
|
Temp |= SMI_InitStruct->SMI_Prescaler << 8;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
if(SMI_InitStruct->SMI_DeselectTime <= SMI_DeselectTime_MaxValue)
|
94 |
|
|
{
|
95 |
|
|
/* Set TCS[3:0] bits according to SMI_DeselectTime value */
|
96 |
|
|
Temp |= SMI_InitStruct->SMI_DeselectTime << 4;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
/* Store the new value */
|
100 |
|
|
SMI->CR1 = Temp;
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
/*******************************************************************************
|
104 |
|
|
* Function Name : SMI_StructInit
|
105 |
|
|
* Description : Fills each SMI_InitStruct member with its reset value.
|
106 |
|
|
* Input : - SMI_InitStruct: pointer to a SMI_InitTypeDef structure which
|
107 |
|
|
* will be initialized.
|
108 |
|
|
* Output : None
|
109 |
|
|
* Return : None
|
110 |
|
|
*******************************************************************************/
|
111 |
|
|
void SMI_StructInit(SMI_InitTypeDef* SMI_InitStruct)
|
112 |
|
|
{
|
113 |
|
|
/* SMI_CK is sent continuously */
|
114 |
|
|
SMI_InitStruct->SMI_ClockHold = SMI_ClockHold_Mask;
|
115 |
|
|
|
116 |
|
|
/* SMI_CK = HCLK/2 */
|
117 |
|
|
SMI_InitStruct->SMI_Prescaler = SMI_Prescaler_Mask;
|
118 |
|
|
|
119 |
|
|
/* Deselect Time set to 6*SMI_CK periods */
|
120 |
|
|
SMI_InitStruct->SMI_DeselectTime = SMI_DeselectTime_Mask;
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
/*******************************************************************************
|
124 |
|
|
* Function Name : SMI_ModeConfig
|
125 |
|
|
* Description : Selects the SMI mode: hardware or software.
|
126 |
|
|
* Input : - SMI_Mode: specifies the SMI mode.
|
127 |
|
|
* This parameter can be one of the following values:
|
128 |
|
|
* - SMI_Mode_HW: SMI in hardware mode
|
129 |
|
|
* - SMI_Mode_SW: SMI in software mode
|
130 |
|
|
* Output : None
|
131 |
|
|
* Return : None
|
132 |
|
|
*******************************************************************************/
|
133 |
|
|
void SMI_ModeConfig(u32 SMI_Mode)
|
134 |
|
|
{
|
135 |
|
|
if(SMI_Mode == SMI_Mode_SW)
|
136 |
|
|
{
|
137 |
|
|
SMI->CR1 |= SMI_Mode_SW;
|
138 |
|
|
}
|
139 |
|
|
else
|
140 |
|
|
{
|
141 |
|
|
SMI->CR1 &= SMI_Mode_HW;
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
/*******************************************************************************
|
146 |
|
|
* Function Name : SMI_TxRxLengthConfig
|
147 |
|
|
* Description : Configures the number of bytes to be transmitted and received
|
148 |
|
|
* to/from external memory. This function is used in Software
|
149 |
|
|
* mode only.
|
150 |
|
|
* Input : - SMI_TxLength: specifies the number of bytes to be transmitted
|
151 |
|
|
* to external memory.
|
152 |
|
|
* This parameter can be one of the following values:
|
153 |
|
|
* - SMI_TxLength_0Bytes: No bytes transmitted
|
154 |
|
|
* - SMI_TxLength_1Byte: 1 byte transmitted
|
155 |
|
|
* - SMI_TxLength_2Bytes: 2 bytes transmitted
|
156 |
|
|
* - SMI_TxLength_3Bytes: 3 bytes transmitted
|
157 |
|
|
* - SMI_TxLength_4Bytes: 4 bytes transmitted
|
158 |
|
|
* - SMI_RxLength: specifies the number of bytes to be received
|
159 |
|
|
* from external memory.
|
160 |
|
|
* This parameter can be one of the following values:
|
161 |
|
|
* - SMI_RxLength_0Bytes: No bytes received
|
162 |
|
|
* - SMI_RxLength_1Byte: 1 byte received
|
163 |
|
|
* - SMI_RxLength_2Bytes: 2 bytes received
|
164 |
|
|
* - SMI_RxLength_3Bytes: 3 bytes received
|
165 |
|
|
* - SMI_RxLength_4Bytes: 4 bytes received
|
166 |
|
|
* Output : None
|
167 |
|
|
* Return : None
|
168 |
|
|
*******************************************************************************/
|
169 |
|
|
void SMI_TxRxLengthConfig(u32 SMI_TxLength, u32 SMI_RxLength)
|
170 |
|
|
{
|
171 |
|
|
u32 Temp = 0;
|
172 |
|
|
|
173 |
|
|
/* Clear TRA_LENGTH[2:0] and REC_LENGTH[2:0] bits */
|
174 |
|
|
Temp = SMI->CR2 & SMI_TRARECLENGTH_RESET_Mask;
|
175 |
|
|
|
176 |
|
|
/* Set TRA_LENGTH[2:0] and REC_LENGTH[2:0] bits according to function parameters */
|
177 |
|
|
Temp |= SMI_TxLength | SMI_RxLength;
|
178 |
|
|
|
179 |
|
|
/* Store the new value */
|
180 |
|
|
SMI->CR2 = Temp;
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
/*******************************************************************************
|
184 |
|
|
* Function Name : SMI_BankCmd
|
185 |
|
|
* Description : Enables or disables the specified memory Bank.
|
186 |
|
|
* Input : - SMI_Bank: specifies the memory Bank to be enabled or disabled.
|
187 |
|
|
* This parameter can be any combination of the following values:
|
188 |
|
|
* - SMI_Bank_0
|
189 |
|
|
* - SMI_Bank_1
|
190 |
|
|
* - SMI_Bank_2
|
191 |
|
|
* - SMI_Bank_3
|
192 |
|
|
* - NewState: new state of the specified memory Bank.
|
193 |
|
|
* This parameter can be: ENABLE or DISABLE.
|
194 |
|
|
* Output : None
|
195 |
|
|
* Return : None
|
196 |
|
|
*******************************************************************************/
|
197 |
|
|
void SMI_BankCmd(u32 SMI_Bank, FunctionalState NewState)
|
198 |
|
|
{
|
199 |
|
|
if(NewState == ENABLE)
|
200 |
|
|
{
|
201 |
|
|
SMI->CR1 |= SMI_Bank;
|
202 |
|
|
}
|
203 |
|
|
else
|
204 |
|
|
{
|
205 |
|
|
SMI->CR1 &= ~SMI_Bank;
|
206 |
|
|
}
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
/*******************************************************************************
|
210 |
|
|
* Function Name : SMI_ITConfig
|
211 |
|
|
* Description : Enables or disables the specified SMI interrupts.
|
212 |
|
|
* Input : - SMI_IT: specifies the SMI interrupts sources to be
|
213 |
|
|
* enabled or disabled. This parameter can be any combination
|
214 |
|
|
* of the following values:
|
215 |
|
|
* - SMI_IT_WC : Write Complete Interrupt
|
216 |
|
|
* - SMI_IT_TF : Transfer Finished Interrupt
|
217 |
|
|
* - NewState: new state of the specified SMI interrupts.
|
218 |
|
|
* This parameter can be: ENABLE or DISABLE.
|
219 |
|
|
* Output : None
|
220 |
|
|
* Return : None
|
221 |
|
|
*******************************************************************************/
|
222 |
|
|
void SMI_ITConfig(u32 SMI_IT, FunctionalState NewState)
|
223 |
|
|
{
|
224 |
|
|
if(NewState == ENABLE)
|
225 |
|
|
{
|
226 |
|
|
SMI->CR2 |= SMI_IT;
|
227 |
|
|
}
|
228 |
|
|
else
|
229 |
|
|
{
|
230 |
|
|
SMI->CR2 &= ~SMI_IT;
|
231 |
|
|
}
|
232 |
|
|
}
|
233 |
|
|
|
234 |
|
|
/*******************************************************************************
|
235 |
|
|
* Function Name : SMI_SelectBank
|
236 |
|
|
* Description : Selects the memory Bank to be accessed. Only one Bank can be
|
237 |
|
|
* selected at a time.
|
238 |
|
|
* Input : - SMI_Bank: specifies the memory Bank to be selected.
|
239 |
|
|
* This parameter can be one of the following values:
|
240 |
|
|
* - SMI_Bank_0
|
241 |
|
|
* - SMI_Bank_1
|
242 |
|
|
* - SMI_Bank_2
|
243 |
|
|
* - SMI_Bank_3
|
244 |
|
|
* Output : None
|
245 |
|
|
* Return : None
|
246 |
|
|
*******************************************************************************/
|
247 |
|
|
void SMI_SelectBank(u32 SMI_Bank)
|
248 |
|
|
{
|
249 |
|
|
/* Clear BS[1:0] bits (Bank0 is selected)*/
|
250 |
|
|
SMI->CR2 &= SMI_BS_RESET_Mask;
|
251 |
|
|
|
252 |
|
|
switch(SMI_Bank)
|
253 |
|
|
{
|
254 |
|
|
case SMI_Bank_1:
|
255 |
|
|
/* Select Bank1 */
|
256 |
|
|
SMI->CR2 |= SMI_BS_Bank1_Mask;
|
257 |
|
|
break;
|
258 |
|
|
|
259 |
|
|
case SMI_Bank_2:
|
260 |
|
|
/* Select Bank2 */
|
261 |
|
|
SMI->CR2 |= SMI_BS_Bank2_Mask;
|
262 |
|
|
break;
|
263 |
|
|
|
264 |
|
|
case SMI_Bank_3:
|
265 |
|
|
/* Select Bank3 */
|
266 |
|
|
SMI->CR2 |= SMI_BS_Bank3_Mask;
|
267 |
|
|
break;
|
268 |
|
|
|
269 |
|
|
default:
|
270 |
|
|
break;
|
271 |
|
|
}
|
272 |
|
|
}
|
273 |
|
|
|
274 |
|
|
/*******************************************************************************
|
275 |
|
|
* Function Name : SMI_SendWENCmd
|
276 |
|
|
* Description : Sends a Write Enable command to the selected memory Bank.
|
277 |
|
|
* This function is used in Hardware mode only.
|
278 |
|
|
* Input : None
|
279 |
|
|
* Output : None
|
280 |
|
|
* Return : None
|
281 |
|
|
*******************************************************************************/
|
282 |
|
|
void SMI_SendWENCmd(void)
|
283 |
|
|
{
|
284 |
|
|
SMI->CR2 |= SMI_WEN_Mask;
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
/*******************************************************************************
|
288 |
|
|
* Function Name : SMI_SendRSRCmd
|
289 |
|
|
* Description : Sends a Read Status Register Command to the selected memory
|
290 |
|
|
* Bank.
|
291 |
|
|
* Input : None
|
292 |
|
|
* Output : None
|
293 |
|
|
* Return : None
|
294 |
|
|
*******************************************************************************/
|
295 |
|
|
void SMI_SendRSRCmd(void)
|
296 |
|
|
{
|
297 |
|
|
SMI->CR2 |= SMI_RSR_Mask;
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
/*******************************************************************************
|
301 |
|
|
* Function Name : SMI_SendCmd
|
302 |
|
|
* Description : Sends command to the selected memory Bank. This function is
|
303 |
|
|
* used in Software mode only.
|
304 |
|
|
* Input : - Command: specifies the command to send to the external memory.
|
305 |
|
|
* Output : None
|
306 |
|
|
* Return : None
|
307 |
|
|
*******************************************************************************/
|
308 |
|
|
void SMI_SendCmd(u32 Command)
|
309 |
|
|
{
|
310 |
|
|
/* Load the command in the Transmit Register */
|
311 |
|
|
SMI->TR = Command;
|
312 |
|
|
|
313 |
|
|
/* Start transfer */
|
314 |
|
|
SMI->CR2 |= SMI_SEND_Mask;
|
315 |
|
|
}
|
316 |
|
|
|
317 |
|
|
/*******************************************************************************
|
318 |
|
|
* Function Name : SMI_FastReadConfig
|
319 |
|
|
* Description : Enables or disables the Fast Read Mode.
|
320 |
|
|
* Input : - SMI_FastRead: specifies whether the Fast Read Mode is
|
321 |
|
|
* enabled or disabled.
|
322 |
|
|
* This parameter can be one of the following values:
|
323 |
|
|
* - SMI_FastRead_Disable : Fast Read Mode disabled
|
324 |
|
|
* - SMI_FastRead_Enable : Fast Read Mode enabled
|
325 |
|
|
* Output : None
|
326 |
|
|
* Return : None
|
327 |
|
|
*******************************************************************************/
|
328 |
|
|
void SMI_FastReadConfig(u32 SMI_FastRead)
|
329 |
|
|
{
|
330 |
|
|
if(SMI_FastRead == SMI_FastRead_Enable)
|
331 |
|
|
{
|
332 |
|
|
SMI->CR1 |= SMI_FastRead_Enable;
|
333 |
|
|
}
|
334 |
|
|
else
|
335 |
|
|
{
|
336 |
|
|
SMI->CR1 &= SMI_FastRead_Disable;
|
337 |
|
|
}
|
338 |
|
|
}
|
339 |
|
|
|
340 |
|
|
/*******************************************************************************
|
341 |
|
|
* Function Name : SMI_WriteBurstConfig
|
342 |
|
|
* Description : Enables or disables the Write Burst Mode.
|
343 |
|
|
* Input : - SMI_WriteBurst: specifies whether the Write Burst Mode is
|
344 |
|
|
* enabled or disabled.
|
345 |
|
|
* This parameter can be one of the following values:
|
346 |
|
|
* - SMI_WriteBurst_Disable : Write Burst Mode disabled
|
347 |
|
|
* - SMI_WriteBurst_Enable : Write Burst Mode enabled
|
348 |
|
|
* Output : None
|
349 |
|
|
* Return : None
|
350 |
|
|
*******************************************************************************/
|
351 |
|
|
void SMI_WriteBurstConfig(u32 SMI_WriteBurst)
|
352 |
|
|
{
|
353 |
|
|
if(SMI_WriteBurst == SMI_WriteBurst_Enable)
|
354 |
|
|
{
|
355 |
|
|
SMI->CR1 |= SMI_WriteBurst_Enable;
|
356 |
|
|
}
|
357 |
|
|
else
|
358 |
|
|
{
|
359 |
|
|
SMI->CR1 &= SMI_WriteBurst_Disable;
|
360 |
|
|
}
|
361 |
|
|
}
|
362 |
|
|
|
363 |
|
|
/*******************************************************************************
|
364 |
|
|
* Function Name : SMI_WriteByte
|
365 |
|
|
* Description : Writes a Byte to the selected memory Bank. This function is
|
366 |
|
|
* used in Hardware mode only.
|
367 |
|
|
* Before calling this function, send a Write Enable command to
|
368 |
|
|
* the selected memory Bank using SMI_SendWENCmd() function.
|
369 |
|
|
* Input : - WriteAddr: external memory address from which the data will
|
370 |
|
|
* be written.
|
371 |
|
|
* - Data: data to be written to the external memory.
|
372 |
|
|
* Output : None
|
373 |
|
|
* Return : None
|
374 |
|
|
*******************************************************************************/
|
375 |
|
|
void SMI_WriteByte(u32 WriteAddr, u8 Data)
|
376 |
|
|
{
|
377 |
|
|
/* Transfer data to the memory */
|
378 |
|
|
*(u8 *) WriteAddr = Data;
|
379 |
|
|
}
|
380 |
|
|
|
381 |
|
|
/*******************************************************************************
|
382 |
|
|
* Function Name : SMI_WriteHalfWord
|
383 |
|
|
* Description : Writes a Half Word to the selected memory Bank. This function
|
384 |
|
|
* is used in Hardware mode only.
|
385 |
|
|
* Before calling this function, send a Write Enable command to
|
386 |
|
|
* the selected memory Bank using SMI_SendWENCmd() function.
|
387 |
|
|
* Input : - WriteAddr: external memory address from which the data will
|
388 |
|
|
* be written.
|
389 |
|
|
* - Data: data to be written to the external memory.
|
390 |
|
|
* Output : None
|
391 |
|
|
* Return : None
|
392 |
|
|
*******************************************************************************/
|
393 |
|
|
void SMI_WriteHalfWord(u32 WriteAddr, u16 Data)
|
394 |
|
|
{
|
395 |
|
|
/* Transfer data to the memory */
|
396 |
|
|
*(u16 *) WriteAddr = Data;
|
397 |
|
|
}
|
398 |
|
|
|
399 |
|
|
/*******************************************************************************
|
400 |
|
|
* Function Name : SMI_WriteWord
|
401 |
|
|
* Description : Writes a Word to the selected memory Bank. This function is
|
402 |
|
|
* used in Hardware mode only.
|
403 |
|
|
* Before calling this function, send a Write Enable command to
|
404 |
|
|
* the selected memory Bank using SMI_SendWENCmd() function.
|
405 |
|
|
* Input : - WriteAddr: external memory address from which the data will
|
406 |
|
|
* be written.
|
407 |
|
|
* - Data: data to be written to the external memory.
|
408 |
|
|
* Output : None
|
409 |
|
|
* Return : None
|
410 |
|
|
*******************************************************************************/
|
411 |
|
|
void SMI_WriteWord(u32 WriteAddr, u32 Data)
|
412 |
|
|
{
|
413 |
|
|
/* Transfer data to the memory */
|
414 |
|
|
*(u32 *) WriteAddr = Data;
|
415 |
|
|
}
|
416 |
|
|
|
417 |
|
|
/*******************************************************************************
|
418 |
|
|
* Function Name : SMI_ReadByte
|
419 |
|
|
* Description : Reads a Byte from the selected memory Bank. This function is
|
420 |
|
|
* used in Hardware mode only.
|
421 |
|
|
* Input : - ReadAddr: external memory address to read from.
|
422 |
|
|
* Output : None
|
423 |
|
|
* Return : Data read from the external memory.
|
424 |
|
|
*******************************************************************************/
|
425 |
|
|
u8 SMI_ReadByte(u32 ReadAddr)
|
426 |
|
|
{
|
427 |
|
|
return(*(u8 *) ReadAddr);
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
/*******************************************************************************
|
431 |
|
|
* Function Name : SMI_ReadHalfWord
|
432 |
|
|
* Description : Reads a Half Word from the selected memory Bank. This function
|
433 |
|
|
* is used in Hardware mode only.
|
434 |
|
|
* Input : - ReadAddr: external memory address to read from.
|
435 |
|
|
* Output : None
|
436 |
|
|
* Return : Data read from the external memory.
|
437 |
|
|
*******************************************************************************/
|
438 |
|
|
u16 SMI_ReadHalfWord(u32 ReadAddr)
|
439 |
|
|
{
|
440 |
|
|
return(*(u16 *) ReadAddr);
|
441 |
|
|
}
|
442 |
|
|
|
443 |
|
|
/*******************************************************************************
|
444 |
|
|
* Function Name : SMI_ReadWord
|
445 |
|
|
* Description : Reads a Word from the selected memory Bank. This function is
|
446 |
|
|
* used in Hardware mode only.
|
447 |
|
|
* Input : - ReadAddr: external memory address to read from.
|
448 |
|
|
* Output : None
|
449 |
|
|
* Return : Data read from the external memory.
|
450 |
|
|
*******************************************************************************/
|
451 |
|
|
u32 SMI_ReadWord(u32 ReadAddr)
|
452 |
|
|
{
|
453 |
|
|
return(*(u32 *) ReadAddr);
|
454 |
|
|
}
|
455 |
|
|
|
456 |
|
|
/*******************************************************************************
|
457 |
|
|
* Function Name : SMI_ReadMemoryStatusRegister
|
458 |
|
|
* Description : Reads the status register of the memory connected to the
|
459 |
|
|
* selected Bank.
|
460 |
|
|
* Input : None
|
461 |
|
|
* Output : None
|
462 |
|
|
* Return : External memory status register value.
|
463 |
|
|
*******************************************************************************/
|
464 |
|
|
u8 SMI_ReadMemoryStatusRegister(void)
|
465 |
|
|
{
|
466 |
|
|
return((u8) (SMI->SR & SMI_STATUSREGISTER_Mask));
|
467 |
|
|
}
|
468 |
|
|
|
469 |
|
|
/*******************************************************************************
|
470 |
|
|
* Function Name : SMI_GetFlagStatus
|
471 |
|
|
* Description : Checks whether the specified SMI flag is set or not.
|
472 |
|
|
* Input : - SMI_FLAG: specifies the flag to check.
|
473 |
|
|
* This parameter can be one of the following values:
|
474 |
|
|
* - SMI_FLAG_Bank3_WM : Memory Bank3 Write Mode flag
|
475 |
|
|
* - SMI_FLAG_Bank2_WM : Memory Bank2 Write Mode flag
|
476 |
|
|
* - SMI_FLAG_Bank1_WM : Memory Bank1 Write Mode flag
|
477 |
|
|
* - SMI_FLAG_Bank0_WM : Memory Bank0 Write Mode flag
|
478 |
|
|
* - SMI_FLAG_ERF2 : Error Flag 2: Forbidden Write Request
|
479 |
|
|
* - SMI_FLAG_ERF1 : Error Flag 1: Forbidden Access
|
480 |
|
|
* - SMI_FLAG_WC : Write Complete flag
|
481 |
|
|
* - SMI_FLAG_TF : Transfer Finished flag
|
482 |
|
|
* Output : None
|
483 |
|
|
* Return : The new state of SMI_FLAG (SET or RESET).
|
484 |
|
|
*******************************************************************************/
|
485 |
|
|
FlagStatus SMI_GetFlagStatus(u32 SMI_FLAG)
|
486 |
|
|
{
|
487 |
|
|
if((SMI->SR & SMI_FLAG) != RESET)
|
488 |
|
|
{
|
489 |
|
|
return SET;
|
490 |
|
|
}
|
491 |
|
|
else
|
492 |
|
|
{
|
493 |
|
|
return RESET;
|
494 |
|
|
}
|
495 |
|
|
}
|
496 |
|
|
|
497 |
|
|
/*******************************************************************************
|
498 |
|
|
* Function Name : SMI_ClearFlag
|
499 |
|
|
* Description : Clears the SMI’s pending flags.
|
500 |
|
|
* Input : - SMI_FLAG: specifies the flag to clear.
|
501 |
|
|
* This parameter can be any combination of the following values:
|
502 |
|
|
* - SMI_FLAG_ERF2 : Error Flag 2: Forbidden Write Request
|
503 |
|
|
* - SMI_FLAG_ERF1 : Error Flag 1: Forbidden Access
|
504 |
|
|
* - SMI_FLAG_WC : Write Complete flag
|
505 |
|
|
* - SMI_FLAG_TF : Transfer Finished flag
|
506 |
|
|
* Output : None
|
507 |
|
|
* Return : None
|
508 |
|
|
*******************************************************************************/
|
509 |
|
|
void SMI_ClearFlag(u32 SMI_FLAG)
|
510 |
|
|
{
|
511 |
|
|
SMI->SR &= ~SMI_FLAG;
|
512 |
|
|
}
|
513 |
|
|
|
514 |
|
|
/*******************************************************************************
|
515 |
|
|
* Function Name : SMI_GetITStatus
|
516 |
|
|
* Description : Checks whether the specified SMI interrupt has occurred or not.
|
517 |
|
|
* Input : - SMI_FLAG: specifies the interrupt source to check.
|
518 |
|
|
* This parameter can be one of the following values:
|
519 |
|
|
* - SMI_IT_WC : Write Complete Interrupt
|
520 |
|
|
* - SMI_IT_TF : Transfer Finished Interrupt
|
521 |
|
|
* Output : None
|
522 |
|
|
* Return : The new state of SMI_IT (SET or RESET).
|
523 |
|
|
*******************************************************************************/
|
524 |
|
|
ITStatus SMI_GetITStatus(u32 SMI_IT)
|
525 |
|
|
{
|
526 |
|
|
if(((SMI->CR2 & SMI_IT) != RESET) && ((SMI->SR & SMI_IT) != RESET))
|
527 |
|
|
{
|
528 |
|
|
return SET;
|
529 |
|
|
}
|
530 |
|
|
else
|
531 |
|
|
{
|
532 |
|
|
return RESET;
|
533 |
|
|
}
|
534 |
|
|
}
|
535 |
|
|
|
536 |
|
|
/*******************************************************************************
|
537 |
|
|
* Function Name : SMI_ClearITPendingBit
|
538 |
|
|
* Description : Clears the SMI’s interrupt pending bits.
|
539 |
|
|
* Input : - SMI_FLAG: specifies the interrupts sources to clear.
|
540 |
|
|
* This parameter can be any combination of the following values:
|
541 |
|
|
* - SMI_IT_WC : Write Complete Interrupt
|
542 |
|
|
* - SMI_IT_TF : Transfer Finished Interrupt
|
543 |
|
|
* Output : None
|
544 |
|
|
* Return : None
|
545 |
|
|
*******************************************************************************/
|
546 |
|
|
void SMI_ClearITPendingBit(u32 SMI_IT)
|
547 |
|
|
{
|
548 |
|
|
SMI->SR &= ~SMI_IT;
|
549 |
|
|
}
|
550 |
|
|
|
551 |
|
|
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
|