1 /******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
\r
2 * File Name : 75x_smi.c
\r
3 * Author : MCD Application Team
\r
4 * Date First Issued : 03/10/2006
\r
5 * Description : This file provides all the SMI software functions.
\r
6 ********************************************************************************
\r
10 ********************************************************************************
\r
11 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
\r
13 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
\r
14 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
\r
15 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
\r
16 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
17 *******************************************************************************/
\r
19 /* Includes ------------------------------------------------------------------*/
\r
20 #include "75x_smi.h"
\r
22 /* Private typedef -----------------------------------------------------------*/
\r
23 /* Private define ------------------------------------------------------------*/
\r
24 /* SMI_CR1 mask bits */
\r
25 #define SMI_HOLDPRESCTCS_RESET_Mask 0xFF00800F
\r
26 #define SMI_Prescaler_MaxValue 0x7F
\r
27 #define SMI_DeselectTime_MaxValue 0x0F
\r
28 #define SMI_ClockHold_Mask 0x00
\r
29 #define SMI_Prescaler_Mask 0x02
\r
30 #define SMI_DeselectTime_Mask 0x5
\r
32 /* SMI_CR2 mask bits */
\r
33 #define SMI_BS_RESET_Mask 0xFFFFCFFF
\r
34 #define SMI_BS_Bank1_Mask 0x00001000
\r
35 #define SMI_BS_Bank2_Mask 0x00002000
\r
36 #define SMI_BS_Bank3_Mask 0x00003000
\r
37 #define SMI_WEN_Mask 0x00000800
\r
38 #define SMI_RSR_Mask 0x00000400
\r
39 #define SMI_SEND_Mask 0x00000080
\r
40 #define SMI_TRARECLENGTH_RESET_Mask 0xFFFFFF88
\r
42 /* SMI_SR mask bits */
\r
43 #define SMI_STATUSREGISTER_Mask 0xFF
\r
45 /* Private macro -------------------------------------------------------------*/
\r
46 /* Private variables ---------------------------------------------------------*/
\r
47 /* Private function prototypes -----------------------------------------------*/
\r
48 /* Private functions ---------------------------------------------------------*/
\r
50 /*******************************************************************************
\r
51 * Function Name : SMI_DeInit
\r
52 * Description : Deinitializes the SMI peripheral registers to their default
\r
53 * reset values. This function must not be used when booting
\r
54 * from the SMI external memory.
\r
58 *******************************************************************************/
\r
59 void SMI_DeInit(void)
\r
61 SMI->CR1 = 0x00000250;
\r
63 SMI->SR &= 0xFFFFF0FF;
\r
67 /*******************************************************************************
\r
68 * Function Name : SMI_Init
\r
69 * Description : Initializes the SMI peripheral according to the specified
\r
70 * parameters in the SMI_InitStruct.
\r
71 * Input : - SMI_InitStruct: pointer to a SMI_InitTypeDef structure that
\r
72 * contains the configuration information for the specified
\r
76 *******************************************************************************/
\r
77 void SMI_Init(SMI_InitTypeDef* SMI_InitStruct)
\r
81 /* Clear HOLD[7:0], PRESC[6:0] and TCS[3:0] bits */
\r
82 Temp = SMI->CR1 & SMI_HOLDPRESCTCS_RESET_Mask;
\r
84 /* Set HOLD[7:0] bits according to SMI_ClockHold value */
\r
85 Temp |= SMI_InitStruct->SMI_ClockHold << 16;
\r
87 if(SMI_InitStruct->SMI_Prescaler <= SMI_Prescaler_MaxValue)
\r
89 /* Set PRESC[6:0] bits according to SMI_Prescaler value */
\r
90 Temp |= SMI_InitStruct->SMI_Prescaler << 8;
\r
93 if(SMI_InitStruct->SMI_DeselectTime <= SMI_DeselectTime_MaxValue)
\r
95 /* Set TCS[3:0] bits according to SMI_DeselectTime value */
\r
96 Temp |= SMI_InitStruct->SMI_DeselectTime << 4;
\r
99 /* Store the new value */
\r
103 /*******************************************************************************
\r
104 * Function Name : SMI_StructInit
\r
105 * Description : Fills each SMI_InitStruct member with its reset value.
\r
106 * Input : - SMI_InitStruct: pointer to a SMI_InitTypeDef structure which
\r
107 * will be initialized.
\r
110 *******************************************************************************/
\r
111 void SMI_StructInit(SMI_InitTypeDef* SMI_InitStruct)
\r
113 /* SMI_CK is sent continuously */
\r
114 SMI_InitStruct->SMI_ClockHold = SMI_ClockHold_Mask;
\r
116 /* SMI_CK = HCLK/2 */
\r
117 SMI_InitStruct->SMI_Prescaler = SMI_Prescaler_Mask;
\r
119 /* Deselect Time set to 6*SMI_CK periods */
\r
120 SMI_InitStruct->SMI_DeselectTime = SMI_DeselectTime_Mask;
\r
123 /*******************************************************************************
\r
124 * Function Name : SMI_ModeConfig
\r
125 * Description : Selects the SMI mode: hardware or software.
\r
126 * Input : - SMI_Mode: specifies the SMI mode.
\r
127 * This parameter can be one of the following values:
\r
128 * - SMI_Mode_HW: SMI in hardware mode
\r
129 * - SMI_Mode_SW: SMI in software mode
\r
132 *******************************************************************************/
\r
133 void SMI_ModeConfig(u32 SMI_Mode)
\r
135 if(SMI_Mode == SMI_Mode_SW)
\r
137 SMI->CR1 |= SMI_Mode_SW;
\r
141 SMI->CR1 &= SMI_Mode_HW;
\r
145 /*******************************************************************************
\r
146 * Function Name : SMI_TxRxLengthConfig
\r
147 * Description : Configures the number of bytes to be transmitted and received
\r
148 * to/from external memory. This function is used in Software
\r
150 * Input : - SMI_TxLength: specifies the number of bytes to be transmitted
\r
151 * to external memory.
\r
152 * This parameter can be one of the following values:
\r
153 * - SMI_TxLength_0Bytes: No bytes transmitted
\r
154 * - SMI_TxLength_1Byte: 1 byte transmitted
\r
155 * - SMI_TxLength_2Bytes: 2 bytes transmitted
\r
156 * - SMI_TxLength_3Bytes: 3 bytes transmitted
\r
157 * - SMI_TxLength_4Bytes: 4 bytes transmitted
\r
158 * - SMI_RxLength: specifies the number of bytes to be received
\r
159 * from external memory.
\r
160 * This parameter can be one of the following values:
\r
161 * - SMI_RxLength_0Bytes: No bytes received
\r
162 * - SMI_RxLength_1Byte: 1 byte received
\r
163 * - SMI_RxLength_2Bytes: 2 bytes received
\r
164 * - SMI_RxLength_3Bytes: 3 bytes received
\r
165 * - SMI_RxLength_4Bytes: 4 bytes received
\r
168 *******************************************************************************/
\r
169 void SMI_TxRxLengthConfig(u32 SMI_TxLength, u32 SMI_RxLength)
\r
173 /* Clear TRA_LENGTH[2:0] and REC_LENGTH[2:0] bits */
\r
174 Temp = SMI->CR2 & SMI_TRARECLENGTH_RESET_Mask;
\r
176 /* Set TRA_LENGTH[2:0] and REC_LENGTH[2:0] bits according to function parameters */
\r
177 Temp |= SMI_TxLength | SMI_RxLength;
\r
179 /* Store the new value */
\r
183 /*******************************************************************************
\r
184 * Function Name : SMI_BankCmd
\r
185 * Description : Enables or disables the specified memory Bank.
\r
186 * Input : - SMI_Bank: specifies the memory Bank to be enabled or disabled.
\r
187 * This parameter can be any combination of the following values:
\r
192 * - NewState: new state of the specified memory Bank.
\r
193 * This parameter can be: ENABLE or DISABLE.
\r
196 *******************************************************************************/
\r
197 void SMI_BankCmd(u32 SMI_Bank, FunctionalState NewState)
\r
199 if(NewState == ENABLE)
\r
201 SMI->CR1 |= SMI_Bank;
\r
205 SMI->CR1 &= ~SMI_Bank;
\r
209 /*******************************************************************************
\r
210 * Function Name : SMI_ITConfig
\r
211 * Description : Enables or disables the specified SMI interrupts.
\r
212 * Input : - SMI_IT: specifies the SMI interrupts sources to be
\r
213 * enabled or disabled. This parameter can be any combination
\r
214 * of the following values:
\r
215 * - SMI_IT_WC : Write Complete Interrupt
\r
216 * - SMI_IT_TF : Transfer Finished Interrupt
\r
217 * - NewState: new state of the specified SMI interrupts.
\r
218 * This parameter can be: ENABLE or DISABLE.
\r
221 *******************************************************************************/
\r
222 void SMI_ITConfig(u32 SMI_IT, FunctionalState NewState)
\r
224 if(NewState == ENABLE)
\r
226 SMI->CR2 |= SMI_IT;
\r
230 SMI->CR2 &= ~SMI_IT;
\r
234 /*******************************************************************************
\r
235 * Function Name : SMI_SelectBank
\r
236 * Description : Selects the memory Bank to be accessed. Only one Bank can be
\r
237 * selected at a time.
\r
238 * Input : - SMI_Bank: specifies the memory Bank to be selected.
\r
239 * This parameter can be one of the following values:
\r
246 *******************************************************************************/
\r
247 void SMI_SelectBank(u32 SMI_Bank)
\r
249 /* Clear BS[1:0] bits (Bank0 is selected)*/
\r
250 SMI->CR2 &= SMI_BS_RESET_Mask;
\r
256 SMI->CR2 |= SMI_BS_Bank1_Mask;
\r
261 SMI->CR2 |= SMI_BS_Bank2_Mask;
\r
266 SMI->CR2 |= SMI_BS_Bank3_Mask;
\r
274 /*******************************************************************************
\r
275 * Function Name : SMI_SendWENCmd
\r
276 * Description : Sends a Write Enable command to the selected memory Bank.
\r
277 * This function is used in Hardware mode only.
\r
281 *******************************************************************************/
\r
282 void SMI_SendWENCmd(void)
\r
284 SMI->CR2 |= SMI_WEN_Mask;
\r
287 /*******************************************************************************
\r
288 * Function Name : SMI_SendRSRCmd
\r
289 * Description : Sends a Read Status Register Command to the selected memory
\r
294 *******************************************************************************/
\r
295 void SMI_SendRSRCmd(void)
\r
297 SMI->CR2 |= SMI_RSR_Mask;
\r
300 /*******************************************************************************
\r
301 * Function Name : SMI_SendCmd
\r
302 * Description : Sends command to the selected memory Bank. This function is
\r
303 * used in Software mode only.
\r
304 * Input : - Command: specifies the command to send to the external memory.
\r
307 *******************************************************************************/
\r
308 void SMI_SendCmd(u32 Command)
\r
310 /* Load the command in the Transmit Register */
\r
313 /* Start transfer */
\r
314 SMI->CR2 |= SMI_SEND_Mask;
\r
317 /*******************************************************************************
\r
318 * Function Name : SMI_FastReadConfig
\r
319 * Description : Enables or disables the Fast Read Mode.
\r
320 * Input : - SMI_FastRead: specifies whether the Fast Read Mode is
\r
321 * enabled or disabled.
\r
322 * This parameter can be one of the following values:
\r
323 * - SMI_FastRead_Disable : Fast Read Mode disabled
\r
324 * - SMI_FastRead_Enable : Fast Read Mode enabled
\r
327 *******************************************************************************/
\r
328 void SMI_FastReadConfig(u32 SMI_FastRead)
\r
330 if(SMI_FastRead == SMI_FastRead_Enable)
\r
332 SMI->CR1 |= SMI_FastRead_Enable;
\r
336 SMI->CR1 &= SMI_FastRead_Disable;
\r
340 /*******************************************************************************
\r
341 * Function Name : SMI_WriteBurstConfig
\r
342 * Description : Enables or disables the Write Burst Mode.
\r
343 * Input : - SMI_WriteBurst: specifies whether the Write Burst Mode is
\r
344 * enabled or disabled.
\r
345 * This parameter can be one of the following values:
\r
346 * - SMI_WriteBurst_Disable : Write Burst Mode disabled
\r
347 * - SMI_WriteBurst_Enable : Write Burst Mode enabled
\r
350 *******************************************************************************/
\r
351 void SMI_WriteBurstConfig(u32 SMI_WriteBurst)
\r
353 if(SMI_WriteBurst == SMI_WriteBurst_Enable)
\r
355 SMI->CR1 |= SMI_WriteBurst_Enable;
\r
359 SMI->CR1 &= SMI_WriteBurst_Disable;
\r
363 /*******************************************************************************
\r
364 * Function Name : SMI_WriteByte
\r
365 * Description : Writes a Byte to the selected memory Bank. This function is
\r
366 * used in Hardware mode only.
\r
367 * Before calling this function, send a Write Enable command to
\r
368 * the selected memory Bank using SMI_SendWENCmd() function.
\r
369 * Input : - WriteAddr: external memory address from which the data will
\r
371 * - Data: data to be written to the external memory.
\r
374 *******************************************************************************/
\r
375 void SMI_WriteByte(u32 WriteAddr, u8 Data)
\r
377 /* Transfer data to the memory */
\r
378 *(u8 *) WriteAddr = Data;
\r
381 /*******************************************************************************
\r
382 * Function Name : SMI_WriteHalfWord
\r
383 * Description : Writes a Half Word to the selected memory Bank. This function
\r
384 * is used in Hardware mode only.
\r
385 * Before calling this function, send a Write Enable command to
\r
386 * the selected memory Bank using SMI_SendWENCmd() function.
\r
387 * Input : - WriteAddr: external memory address from which the data will
\r
389 * - Data: data to be written to the external memory.
\r
392 *******************************************************************************/
\r
393 void SMI_WriteHalfWord(u32 WriteAddr, u16 Data)
\r
395 /* Transfer data to the memory */
\r
396 *(u16 *) WriteAddr = Data;
\r
399 /*******************************************************************************
\r
400 * Function Name : SMI_WriteWord
\r
401 * Description : Writes a Word to the selected memory Bank. This function is
\r
402 * used in Hardware mode only.
\r
403 * Before calling this function, send a Write Enable command to
\r
404 * the selected memory Bank using SMI_SendWENCmd() function.
\r
405 * Input : - WriteAddr: external memory address from which the data will
\r
407 * - Data: data to be written to the external memory.
\r
410 *******************************************************************************/
\r
411 void SMI_WriteWord(u32 WriteAddr, u32 Data)
\r
413 /* Transfer data to the memory */
\r
414 *(u32 *) WriteAddr = Data;
\r
417 /*******************************************************************************
\r
418 * Function Name : SMI_ReadByte
\r
419 * Description : Reads a Byte from the selected memory Bank. This function is
\r
420 * used in Hardware mode only.
\r
421 * Input : - ReadAddr: external memory address to read from.
\r
423 * Return : Data read from the external memory.
\r
424 *******************************************************************************/
\r
425 u8 SMI_ReadByte(u32 ReadAddr)
\r
427 return(*(u8 *) ReadAddr);
\r
430 /*******************************************************************************
\r
431 * Function Name : SMI_ReadHalfWord
\r
432 * Description : Reads a Half Word from the selected memory Bank. This function
\r
433 * is used in Hardware mode only.
\r
434 * Input : - ReadAddr: external memory address to read from.
\r
436 * Return : Data read from the external memory.
\r
437 *******************************************************************************/
\r
438 u16 SMI_ReadHalfWord(u32 ReadAddr)
\r
440 return(*(u16 *) ReadAddr);
\r
443 /*******************************************************************************
\r
444 * Function Name : SMI_ReadWord
\r
445 * Description : Reads a Word from the selected memory Bank. This function is
\r
446 * used in Hardware mode only.
\r
447 * Input : - ReadAddr: external memory address to read from.
\r
449 * Return : Data read from the external memory.
\r
450 *******************************************************************************/
\r
451 u32 SMI_ReadWord(u32 ReadAddr)
\r
453 return(*(u32 *) ReadAddr);
\r
456 /*******************************************************************************
\r
457 * Function Name : SMI_ReadMemoryStatusRegister
\r
458 * Description : Reads the status register of the memory connected to the
\r
462 * Return : External memory status register value.
\r
463 *******************************************************************************/
\r
464 u8 SMI_ReadMemoryStatusRegister(void)
\r
466 return((u8) (SMI->SR & SMI_STATUSREGISTER_Mask));
\r
469 /*******************************************************************************
\r
470 * Function Name : SMI_GetFlagStatus
\r
471 * Description : Checks whether the specified SMI flag is set or not.
\r
472 * Input : - SMI_FLAG: specifies the flag to check.
\r
473 * This parameter can be one of the following values:
\r
474 * - SMI_FLAG_Bank3_WM : Memory Bank3 Write Mode flag
\r
475 * - SMI_FLAG_Bank2_WM : Memory Bank2 Write Mode flag
\r
476 * - SMI_FLAG_Bank1_WM : Memory Bank1 Write Mode flag
\r
477 * - SMI_FLAG_Bank0_WM : Memory Bank0 Write Mode flag
\r
478 * - SMI_FLAG_ERF2 : Error Flag 2: Forbidden Write Request
\r
479 * - SMI_FLAG_ERF1 : Error Flag 1: Forbidden Access
\r
480 * - SMI_FLAG_WC : Write Complete flag
\r
481 * - SMI_FLAG_TF : Transfer Finished flag
\r
483 * Return : The new state of SMI_FLAG (SET or RESET).
\r
484 *******************************************************************************/
\r
485 FlagStatus SMI_GetFlagStatus(u32 SMI_FLAG)
\r
487 if((SMI->SR & SMI_FLAG) != RESET)
\r
497 /*******************************************************************************
\r
498 * Function Name : SMI_ClearFlag
\r
499 * Description : Clears the SMI
\92s pending flags.
\r
500 * Input : - SMI_FLAG: specifies the flag to clear.
\r
501 * This parameter can be any combination of the following values:
\r
502 * - SMI_FLAG_ERF2 : Error Flag 2: Forbidden Write Request
\r
503 * - SMI_FLAG_ERF1 : Error Flag 1: Forbidden Access
\r
504 * - SMI_FLAG_WC : Write Complete flag
\r
505 * - SMI_FLAG_TF : Transfer Finished flag
\r
508 *******************************************************************************/
\r
509 void SMI_ClearFlag(u32 SMI_FLAG)
\r
511 SMI->SR &= ~SMI_FLAG;
\r
514 /*******************************************************************************
\r
515 * Function Name : SMI_GetITStatus
\r
516 * Description : Checks whether the specified SMI interrupt has occurred or not.
\r
517 * Input : - SMI_FLAG: specifies the interrupt source to check.
\r
518 * This parameter can be one of the following values:
\r
519 * - SMI_IT_WC : Write Complete Interrupt
\r
520 * - SMI_IT_TF : Transfer Finished Interrupt
\r
522 * Return : The new state of SMI_IT (SET or RESET).
\r
523 *******************************************************************************/
\r
524 ITStatus SMI_GetITStatus(u32 SMI_IT)
\r
526 if(((SMI->CR2 & SMI_IT) != RESET) && ((SMI->SR & SMI_IT) != RESET))
\r
536 /*******************************************************************************
\r
537 * Function Name : SMI_ClearITPendingBit
\r
538 * Description : Clears the SMI
\92s interrupt pending bits.
\r
539 * Input : - SMI_FLAG: specifies the interrupts sources to clear.
\r
540 * This parameter can be any combination of the following values:
\r
541 * - SMI_IT_WC : Write Complete Interrupt
\r
542 * - SMI_IT_TF : Transfer Finished Interrupt
\r
545 *******************************************************************************/
\r
546 void SMI_ClearITPendingBit(u32 SMI_IT)
\r
548 SMI->SR &= ~SMI_IT;
\r
551 /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
\r