stm32f10x_fsmc.c
上传用户:yj_qqy
上传日期:2017-01-28
资源大小:2911k
文件大小:41k
源码类别:

uCOS

开发平台:

C/C++

  1. /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
  2. * File Name          : stm32f10x_fsmc.c
  3. * Author             : MCD Application Team
  4. * Version            : V2.0.2
  5. * Date               : 07/11/2008
  6. * Description        : This file provides all the FSMC firmware functions.
  7. ********************************************************************************
  8. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  9. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  10. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  11. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  12. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  13. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  14. *******************************************************************************/
  15. /* Includes ------------------------------------------------------------------*/
  16. #include "stm32f10x_fsmc.h"
  17. #include "stm32f10x_rcc.h"
  18. /* Private typedef -----------------------------------------------------------*/
  19. /* Private define ------------------------------------------------------------*/
  20. /* --------------------- FSMC registers bit mask ---------------------------- */
  21. /* FSMC BCRx Mask */
  22. #define BCR_MBKEN_Set                       ((u32)0x00000001)
  23. #define BCR_MBKEN_Reset                     ((u32)0x000FFFFE)
  24. #define BCR_FACCEN_Set                      ((u32)0x00000040)
  25. /* FSMC PCRx Mask */
  26. #define PCR_PBKEN_Set                       ((u32)0x00000004)
  27. #define PCR_PBKEN_Reset                     ((u32)0x000FFFFB)
  28. #define PCR_ECCEN_Set                       ((u32)0x00000040)
  29. #define PCR_ECCEN_Reset                     ((u32)0x000FFFBF)
  30. #define PCR_MemoryType_NAND                 ((u32)0x00000008)
  31. /* Private macro -------------------------------------------------------------*/
  32. /* Private variables ---------------------------------------------------------*/
  33. /* Private function prototypes -----------------------------------------------*/
  34. /* Private functions ---------------------------------------------------------*/
  35. /*******************************************************************************
  36. * Function Name  : FSMC_NORSRAMDeInit
  37. * Description    : Deinitializes the FSMC NOR/SRAM Banks registers to their default 
  38. *                  reset values.
  39. * Input          : - FSMC_Bank: specifies the FSMC Bank to be used
  40. *                    This parameter can be one of the following values:
  41. *                       - FSMC_Bank1_NORSRAM1: FSMC Bank1 NOR/SRAM1  
  42. *                       - FSMC_Bank1_NORSRAM2: FSMC Bank1 NOR/SRAM2 
  43. *                       - FSMC_Bank1_NORSRAM3: FSMC Bank1 NOR/SRAM3 
  44. *                       - FSMC_Bank1_NORSRAM4: FSMC Bank1 NOR/SRAM4                       
  45. * Output         : None
  46. * Return         : None
  47. *******************************************************************************/
  48. void FSMC_NORSRAMDeInit(u32 FSMC_Bank)
  49. {
  50.   /* Check the parameter */
  51.   assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank));
  52.   
  53.   /* FSMC_Bank1_NORSRAM1 */
  54.   if(FSMC_Bank == FSMC_Bank1_NORSRAM1)
  55.   {
  56.     FSMC_Bank1->BTCR[FSMC_Bank] = 0x000030DB;    
  57.   }
  58.   /* FSMC_Bank1_NORSRAM2,  FSMC_Bank1_NORSRAM3 or FSMC_Bank1_NORSRAM4 */
  59.   else
  60.   {   
  61.     FSMC_Bank1->BTCR[FSMC_Bank] = 0x000030D2; 
  62.   }
  63.   FSMC_Bank1->BTCR[FSMC_Bank + 1] = 0x0FFFFFFF;
  64.   FSMC_Bank1E->BWTR[FSMC_Bank] = 0x0FFFFFFF;  
  65. }
  66. /*******************************************************************************
  67. * Function Name  : FSMC_NANDDeInit
  68. * Description    : Deinitializes the FSMC NAND Banks registers to their default 
  69. *                  reset values.
  70. * Input          : - FSMC_Bank: specifies the FSMC Bank to be used
  71. *                    This parameter can be one of the following values:
  72. *                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
  73. *                       - FSMC_Bank3_NAND: FSMC Bank3 NAND                       
  74. * Output         : None
  75. * Return         : None
  76. *******************************************************************************/
  77. void FSMC_NANDDeInit(u32 FSMC_Bank)
  78. {
  79.   /* Check the parameter */
  80.   assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  81.   
  82.   if(FSMC_Bank == FSMC_Bank2_NAND)
  83.   {
  84.     /* Set the FSMC_Bank2 registers to their reset values */
  85.     FSMC_Bank2->PCR2 = 0x00000018;
  86.     FSMC_Bank2->SR2 = 0x00000040;
  87.     FSMC_Bank2->PMEM2 = 0xFCFCFCFC;
  88.     FSMC_Bank2->PATT2 = 0xFCFCFCFC;  
  89.   }
  90.   /* FSMC_Bank3_NAND */  
  91.   else
  92.   {
  93.     /* Set the FSMC_Bank3 registers to their reset values */
  94.     FSMC_Bank3->PCR3 = 0x00000018;
  95.     FSMC_Bank3->SR3 = 0x00000040;
  96.     FSMC_Bank3->PMEM3 = 0xFCFCFCFC;
  97.     FSMC_Bank3->PATT3 = 0xFCFCFCFC; 
  98.   }  
  99. }
  100. /*******************************************************************************
  101. * Function Name  : FSMC_PCCARDDeInit
  102. * Description    : Deinitializes the FSMC PCCARD Bank registers to their default 
  103. *                  reset values.
  104. * Input          : None                       
  105. * Output         : None
  106. * Return         : None
  107. *******************************************************************************/
  108. void FSMC_PCCARDDeInit(void)
  109. {
  110.   /* Set the FSMC_Bank4 registers to their reset values */
  111.   FSMC_Bank4->PCR4 = 0x00000018; 
  112.   FSMC_Bank4->SR4 = 0x00000000;
  113.   FSMC_Bank4->PMEM4 = 0xFCFCFCFC;
  114.   FSMC_Bank4->PATT4 = 0xFCFCFCFC;
  115.   FSMC_Bank4->PIO4 = 0xFCFCFCFC;
  116. }
  117. /*******************************************************************************
  118. * Function Name  : FSMC_NORSRAMInit
  119. * Description    : Initializes the FSMC NOR/SRAM Banks according to the 
  120. *                  specified parameters in the FSMC_NORSRAMInitStruct.
  121. * Input          : - FSMC_NORSRAMInitStruct : pointer to a FSMC_NORSRAMInitTypeDef
  122. *                  structure that contains the configuration information for 
  123. *                  the FSMC NOR/SRAM specified Banks.                       
  124. * Output         : None
  125. * Return         : None
  126. *******************************************************************************/
  127. void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)
  128.   /* Check the parameters */
  129.   assert_param(IS_FSMC_NORSRAM_BANK(FSMC_NORSRAMInitStruct->FSMC_Bank));
  130.   assert_param(IS_FSMC_MUX(FSMC_NORSRAMInitStruct->FSMC_DataAddressMux));
  131.   assert_param(IS_FSMC_MEMORY(FSMC_NORSRAMInitStruct->FSMC_MemoryType));
  132.   assert_param(IS_FSMC_MEMORY_WIDTH(FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth));
  133.   assert_param(IS_FSMC_BURSTMODE(FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode));
  134.   assert_param(IS_FSMC_WAIT_POLARITY(FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity));
  135.   assert_param(IS_FSMC_WRAP_MODE(FSMC_NORSRAMInitStruct->FSMC_WrapMode));
  136.   assert_param(IS_FSMC_WAIT_SIGNAL_ACTIVE(FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive));
  137.   assert_param(IS_FSMC_WRITE_OPERATION(FSMC_NORSRAMInitStruct->FSMC_WriteOperation));
  138.   assert_param(IS_FSMC_WAITE_SIGNAL(FSMC_NORSRAMInitStruct->FSMC_WaitSignal));
  139.   assert_param(IS_FSMC_EXTENDED_MODE(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode));
  140.   assert_param(IS_FSMC_ASYNC_WAIT(FSMC_NORSRAMInitStruct->FSMC_AsyncWait));
  141.   assert_param(IS_FSMC_WRITE_BURST(FSMC_NORSRAMInitStruct->FSMC_WriteBurst));  
  142.   assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime));
  143.   assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime));
  144.   assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime));
  145.   assert_param(IS_FSMC_TURNAROUND_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration));
  146.   assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision));
  147.   assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency));
  148.   assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode)); 
  149.   
  150.   /* Bank1 NOR/SRAM control register configuration */ 
  151.   FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] = 
  152.             (u32)FSMC_NORSRAMInitStruct->FSMC_DataAddressMux |
  153.             FSMC_NORSRAMInitStruct->FSMC_MemoryType |
  154.             FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth |
  155.             FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode |
  156.             FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity |
  157.             FSMC_NORSRAMInitStruct->FSMC_WrapMode |
  158.             FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive |
  159.             FSMC_NORSRAMInitStruct->FSMC_WriteOperation |
  160.             FSMC_NORSRAMInitStruct->FSMC_WaitSignal |
  161.             FSMC_NORSRAMInitStruct->FSMC_ExtendedMode |
  162.             FSMC_NORSRAMInitStruct->FSMC_AsyncWait |
  163.             FSMC_NORSRAMInitStruct->FSMC_WriteBurst;
  164.   if(FSMC_NORSRAMInitStruct->FSMC_MemoryType == FSMC_MemoryType_NOR)
  165.   {
  166.     FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] |= (u32)BCR_FACCEN_Set;
  167.   }
  168.   /* Bank1 NOR/SRAM timing register configuration */
  169.   FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank+1] = 
  170.             (u32)FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime |
  171.             (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime << 4) |
  172.             (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime << 8) |
  173.             (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration << 16) |
  174.             (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision << 20) |
  175.             (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency << 24) |
  176.              FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode;
  177.             
  178.     
  179.   /* Bank1 NOR/SRAM timing register for write configuration, if extended mode is used */
  180.   if(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode == FSMC_ExtendedMode_Enable)
  181.   {
  182.     assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime));
  183.     assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime));
  184.     assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime));
  185.     assert_param(IS_FSMC_TURNAROUND_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_BusTurnAroundDuration));
  186.     assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision));
  187.     assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency));
  188.     assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode));
  189.     FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] = 
  190.               (u32)FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime |
  191.               (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime << 4 )|
  192.               (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime << 8) |
  193.               (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_BusTurnAroundDuration << 16) |
  194.               (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision << 20) |
  195.               (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency << 24) |
  196.                FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode;
  197.   }
  198.   else
  199.   {
  200.     FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] = 0x0FFFFFFF;
  201.   }
  202. }
  203. /*******************************************************************************
  204. * Function Name  : FSMC_NANDInit
  205. * Description    : Initializes the FSMC NAND Banks according to the specified 
  206. *                  parameters in the FSMC_NANDInitStruct.
  207. * Input          : - FSMC_NANDInitStruct : pointer to a FSMC_NANDInitTypeDef 
  208. *                    structure that contains the configuration information for 
  209. *                    the FSMC NAND specified Banks.                       
  210. * Output         : None
  211. * Return         : None
  212. *******************************************************************************/
  213. void FSMC_NANDInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
  214. {
  215.   u32 tmppcr = 0x00000000, tmppmem = 0x00000000, tmppatt = 0x00000000; 
  216.     
  217.   /* Check the parameters */
  218.   assert_param( IS_FSMC_NAND_BANK(FSMC_NANDInitStruct->FSMC_Bank));
  219.   assert_param( IS_FSMC_WAIT_FEATURE(FSMC_NANDInitStruct->FSMC_Waitfeature));
  220.   assert_param( IS_FSMC_DATA_WIDTH(FSMC_NANDInitStruct->FSMC_MemoryDataWidth));
  221.   assert_param( IS_FSMC_ECC_STATE(FSMC_NANDInitStruct->FSMC_ECC));
  222.   assert_param( IS_FSMC_ECCPAGE_SIZE(FSMC_NANDInitStruct->FSMC_ECCPageSize));
  223.   assert_param( IS_FSMC_ADDRESS_LOW_MAPPING(FSMC_NANDInitStruct->FSMC_AddressLowMapping));
  224.   assert_param( IS_FSMC_TCLR_TIME(FSMC_NANDInitStruct->FSMC_TCLRSetupTime));
  225.   assert_param( IS_FSMC_TAR_TIME(FSMC_NANDInitStruct->FSMC_TARSetupTime));
  226.   assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
  227.   assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
  228.   assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
  229.   assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
  230.   assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
  231.   assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
  232.   assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
  233.   assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
  234.   
  235.   /* Set the tmppcr value according to FSMC_NANDInitStruct parameters */
  236.   tmppcr = (u32)FSMC_NANDInitStruct->FSMC_Waitfeature |
  237.             PCR_MemoryType_NAND |
  238.             FSMC_NANDInitStruct->FSMC_MemoryDataWidth |
  239.             FSMC_NANDInitStruct->FSMC_ECC |
  240.             FSMC_NANDInitStruct->FSMC_ECCPageSize |
  241.             FSMC_NANDInitStruct->FSMC_AddressLowMapping |
  242.             (FSMC_NANDInitStruct->FSMC_TCLRSetupTime << 9 )|
  243.             (FSMC_NANDInitStruct->FSMC_TARSetupTime << 13);
  244.             
  245.   /* Set tmppmem value according to FSMC_CommonSpaceTimingStructure parameters */
  246.   tmppmem = (u32)FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
  247.             (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  248.             (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  249.             (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24); 
  250.             
  251.   /* Set tmppatt value according to FSMC_AttributeSpaceTimingStructure parameters */
  252.   tmppatt = (u32)FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
  253.             (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  254.             (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  255.             (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  256.   
  257.   if(FSMC_NANDInitStruct->FSMC_Bank == FSMC_Bank2_NAND)
  258.   {
  259.     /* FSMC_Bank2_NAND registers configuration */
  260.     FSMC_Bank2->PCR2 = tmppcr;
  261.     FSMC_Bank2->PMEM2 = tmppmem;
  262.     FSMC_Bank2->PATT2 = tmppatt;
  263.   }
  264.   else
  265.   {
  266.     /* FSMC_Bank3_NAND registers configuration */
  267.     FSMC_Bank3->PCR3 = tmppcr;
  268.     FSMC_Bank3->PMEM3 = tmppmem;
  269.     FSMC_Bank3->PATT3 = tmppatt;
  270.   }
  271. }
  272. /*******************************************************************************
  273. * Function Name  : FSMC_PCCARDInit
  274. * Description    : Initializes the FSMC PCCARD Bank according to the specified 
  275. *                  parameters in the FSMC_PCCARDInitStruct.
  276. * Input          : - FSMC_PCCARDInitStruct : pointer to a FSMC_PCCARDInitTypeDef
  277. *                    structure that contains the configuration information for 
  278. *                    the FSMC PCCARD Bank.                       
  279. * Output         : None
  280. * Return         : None
  281. *******************************************************************************/
  282. void FSMC_PCCARDInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
  283. {
  284.   /* Check the parameters */
  285.   assert_param(IS_FSMC_WAIT_FEATURE(FSMC_PCCARDInitStruct->FSMC_Waitfeature));
  286.   assert_param(IS_FSMC_ADDRESS_LOW_MAPPING(FSMC_PCCARDInitStruct->FSMC_AddressLowMapping));
  287.   assert_param(IS_FSMC_TCLR_TIME(FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime));
  288.   assert_param(IS_FSMC_TAR_TIME(FSMC_PCCARDInitStruct->FSMC_TARSetupTime));
  289.  
  290.   assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
  291.   assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
  292.   assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
  293.   assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
  294.   
  295.   assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
  296.   assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
  297.   assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
  298.   assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
  299.   assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime));
  300.   assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime));
  301.   assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime));
  302.   assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime));
  303.   
  304.   /* Set the PCR4 register value according to FSMC_PCCARDInitStruct parameters */
  305.   FSMC_Bank4->PCR4 = (u32)FSMC_PCCARDInitStruct->FSMC_Waitfeature |
  306.                      FSMC_PCCARDInitStruct->FSMC_AddressLowMapping |
  307.                      (FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime << 9) |
  308.                      (FSMC_PCCARDInitStruct->FSMC_TARSetupTime << 13);
  309.             
  310.   /* Set PMEM4 register value according to FSMC_CommonSpaceTimingStructure parameters */
  311.   FSMC_Bank4->PMEM4 = (u32)FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
  312.                       (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  313.                       (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  314.                       (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24); 
  315.             
  316.   /* Set PATT4 register value according to FSMC_AttributeSpaceTimingStructure parameters */
  317.   FSMC_Bank4->PATT4 = (u32)FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
  318.                       (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  319.                       (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  320.                       (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  321.             
  322.   /* Set PIO4 register value according to FSMC_IOSpaceTimingStructure parameters */
  323.   FSMC_Bank4->PIO4 = (u32)FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime |
  324.                      (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  325.                      (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  326.                      (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime << 24);             
  327. }
  328. /*******************************************************************************
  329. * Function Name  : FSMC_NORSRAMStructInit
  330. * Description    : Fills each FSMC_NORSRAMInitStruct member with its default value.
  331. * Input          : - FSMC_NORSRAMInitStruct: pointer to a FSMC_NORSRAMInitTypeDef 
  332. *                    structure which will be initialized.
  333. * Output         : None
  334. * Return         : None
  335. *******************************************************************************/
  336. void FSMC_NORSRAMStructInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)
  337. {  
  338.   /* Reset NOR/SRAM Init structure parameters values */
  339.   FSMC_NORSRAMInitStruct->FSMC_Bank = FSMC_Bank1_NORSRAM1;
  340.   FSMC_NORSRAMInitStruct->FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;
  341.   FSMC_NORSRAMInitStruct->FSMC_MemoryType = FSMC_MemoryType_SRAM;
  342.   FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
  343.   FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  344.   FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  345.   FSMC_NORSRAMInitStruct->FSMC_WrapMode = FSMC_WrapMode_Disable;
  346.   FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  347.   FSMC_NORSRAMInitStruct->FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  348.   FSMC_NORSRAMInitStruct->FSMC_WaitSignal = FSMC_WaitSignal_Enable;
  349.   FSMC_NORSRAMInitStruct->FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  350.   FSMC_NORSRAMInitStruct->FSMC_AsyncWait = FSMC_AsyncWait_Disable;
  351.   FSMC_NORSRAMInitStruct->FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  352.   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime = 0xF;
  353.   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime = 0xF;
  354.   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime = 0xFF;
  355.   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration = 0xF;
  356.   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision = 0xF;
  357.   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency = 0xF;
  358.   FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode = FSMC_AccessMode_A; 
  359.   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime = 0xF;
  360.   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime = 0xF;
  361.   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime = 0xFF;
  362.   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_BusTurnAroundDuration = 0xF;
  363.   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision = 0xF;
  364.   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency = 0xF;
  365.   FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode = FSMC_AccessMode_A;
  366. }
  367. /*******************************************************************************
  368. * Function Name  : FSMC_NANDStructInit
  369. * Description    : Fills each FSMC_NANDInitStruct member with its default value.
  370. * Input          : - FSMC_NORSRAMInitStruct: pointer to a FSMC_NANDInitTypeDef 
  371. *                    structure which will be initialized.
  372. * Output         : None
  373. * Return         : None
  374. *******************************************************************************/
  375. void FSMC_NANDStructInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
  376.   /* Reset NAND Init structure parameters values */
  377.   FSMC_NANDInitStruct->FSMC_Bank = FSMC_Bank2_NAND;
  378.   FSMC_NANDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
  379.   FSMC_NANDInitStruct->FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
  380.   FSMC_NANDInitStruct->FSMC_ECC = FSMC_ECC_Disable;
  381.   FSMC_NANDInitStruct->FSMC_ECCPageSize = FSMC_ECCPageSize_256Bytes;
  382.   FSMC_NANDInitStruct->FSMC_AddressLowMapping = FSMC_AddressLowMapping_Direct;
  383.   FSMC_NANDInitStruct->FSMC_TCLRSetupTime = 0x0;
  384.   FSMC_NANDInitStruct->FSMC_TARSetupTime = 0x0;
  385.   FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  386.   FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  387.   FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  388.   FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  389.   FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  390.   FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  391.   FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  392.   FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;   
  393. }
  394. /*******************************************************************************
  395. * Function Name  : FSMC_PCCARDStructInit
  396. * Description    : Fills each FSMC_PCCARDInitStruct member with its default value.
  397. * Input          : - FSMC_PCCARDInitStruct: pointer to a FSMC_PCCARDInitTypeDef 
  398. *                    structure which will be initialized.
  399. * Output         : None
  400. * Return         : None
  401. *******************************************************************************/
  402. void FSMC_PCCARDStructInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
  403. {
  404.   /* Reset PCCARD Init structure parameters values */
  405.   FSMC_PCCARDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
  406.   FSMC_PCCARDInitStruct->FSMC_AddressLowMapping = FSMC_AddressLowMapping_Direct;
  407.   FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime = 0x0;
  408.   FSMC_PCCARDInitStruct->FSMC_TARSetupTime = 0x0;
  409.   FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  410.   FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  411.   FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  412.   FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  413.   FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  414.   FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  415.   FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  416.   FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  417.   FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  418.   FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  419.   FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  420.   FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  421. }
  422. /*******************************************************************************
  423. * Function Name  : FSMC_NORSRAMCmd
  424. * Description    : Enables or disables the specified NOR/SRAM Memory Bank.
  425. * Input          : - FSMC_Bank: specifies the FSMC Bank to be used
  426. *                    This parameter can be one of the following values:
  427. *                       - FSMC_Bank1_NORSRAM1: FSMC Bank1 NOR/SRAM1  
  428. *                       - FSMC_Bank1_NORSRAM2: FSMC Bank1 NOR/SRAM2 
  429. *                       - FSMC_Bank1_NORSRAM3: FSMC Bank1 NOR/SRAM3 
  430. *                       - FSMC_Bank1_NORSRAM4: FSMC Bank1 NOR/SRAM4 
  431. *                : - NewState: new state of the FSMC_Bank.
  432. *                    This parameter can be: ENABLE or DISABLE.
  433. * Output         : None
  434. * Return         : None
  435. *******************************************************************************/
  436. void FSMC_NORSRAMCmd(u32 FSMC_Bank, FunctionalState NewState)
  437. {
  438.   assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank));
  439.   assert_param(IS_FUNCTIONAL_STATE(NewState));
  440.   
  441.   if (NewState != DISABLE)
  442.   {
  443.     /* Enable the selected NOR/SRAM Bank by setting the PBKEN bit in the BCRx register */
  444.     FSMC_Bank1->BTCR[FSMC_Bank] |= BCR_MBKEN_Set;
  445.   }
  446.   else
  447.   {
  448.     /* Disable the selected NOR/SRAM Bank by clearing the PBKEN bit in the BCRx register */
  449.     FSMC_Bank1->BTCR[FSMC_Bank] &= BCR_MBKEN_Reset;
  450.   }
  451. }
  452. /*******************************************************************************
  453. * Function Name  : FSMC_NANDCmd
  454. * Description    : Enables or disables the specified NAND Memory Bank.
  455. * Input          : - FSMC_Bank: specifies the FSMC Bank to be used
  456. *                    This parameter can be one of the following values:
  457. *                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
  458. *                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
  459. *                : - NewState: new state of the FSMC_Bank.
  460. *                    This parameter can be: ENABLE or DISABLE.
  461. * Output         : None
  462. * Return         : None
  463. *******************************************************************************/
  464. void FSMC_NANDCmd(u32 FSMC_Bank, FunctionalState NewState)
  465. {
  466.   assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  467.   assert_param(IS_FUNCTIONAL_STATE(NewState));
  468.   
  469.   if (NewState != DISABLE)
  470.   {
  471.     /* Enable the selected NAND Bank by setting the PBKEN bit in the PCRx register */
  472.     if(FSMC_Bank == FSMC_Bank2_NAND)
  473.     {
  474.       FSMC_Bank2->PCR2 |= PCR_PBKEN_Set;
  475.     }
  476.     else
  477.     {
  478.       FSMC_Bank3->PCR3 |= PCR_PBKEN_Set;
  479.     }
  480.   }
  481.   else
  482.   {
  483.     /* Disable the selected NAND Bank by clearing the PBKEN bit in the PCRx register */
  484.     if(FSMC_Bank == FSMC_Bank2_NAND)
  485.     {
  486.       FSMC_Bank2->PCR2 &= PCR_PBKEN_Reset;
  487.     }
  488.     else
  489.     {
  490.       FSMC_Bank3->PCR3 &= PCR_PBKEN_Reset;
  491.     }
  492.   }
  493. }
  494. /*******************************************************************************
  495. * Function Name  : FSMC_PCCARDCmd
  496. * Description    : Enables or disables the PCCARD Memory Bank.
  497. * Input          : - NewState: new state of the PCCARD Memory Bank.  
  498. *                    This parameter can be: ENABLE or DISABLE.
  499. * Output         : None
  500. * Return         : None
  501. *******************************************************************************/
  502. void FSMC_PCCARDCmd(FunctionalState NewState)
  503. {
  504.   assert_param(IS_FUNCTIONAL_STATE(NewState));
  505.   
  506.   if (NewState != DISABLE)
  507.   {
  508.     /* Enable the PCCARD Bank by setting the PBKEN bit in the PCR4 register */
  509.     FSMC_Bank4->PCR4 |= PCR_PBKEN_Set;
  510.   }
  511.   else
  512.   {
  513.     /* Disable the PCCARD Bank by clearing the PBKEN bit in the PCR4 register */
  514.     FSMC_Bank4->PCR4 &= PCR_PBKEN_Reset;
  515.   }
  516. }
  517. /*******************************************************************************
  518. * Function Name  : FSMC_NANDECCCmd
  519. * Description    : Enables or disables the FSMC NAND ECC feature.
  520. * Input          : - FSMC_Bank: specifies the FSMC Bank to be used
  521. *                    This parameter can be one of the following values:
  522. *                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
  523. *                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
  524. *                : - NewState: new state of the FSMC NAND ECC feature.  
  525. *                    This parameter can be: ENABLE or DISABLE.
  526. * Output         : None
  527. * Return         : None
  528. *******************************************************************************/
  529. void FSMC_NANDECCCmd(u32 FSMC_Bank, FunctionalState NewState)
  530. {
  531.   assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  532.   assert_param(IS_FUNCTIONAL_STATE(NewState));
  533.   
  534.   if (NewState != DISABLE)
  535.   {
  536.     /* Enable the selected NAND Bank ECC function by setting the ECCEN bit in the PCRx register */
  537.     if(FSMC_Bank == FSMC_Bank2_NAND)
  538.     {
  539.       FSMC_Bank2->PCR2 |= PCR_ECCEN_Set;
  540.     }
  541.     else
  542.     {
  543.       FSMC_Bank3->PCR3 |= PCR_ECCEN_Set;
  544.     }
  545.   }
  546.   else
  547.   {
  548.     /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */
  549.     if(FSMC_Bank == FSMC_Bank2_NAND)
  550.     {
  551.       FSMC_Bank2->PCR2 &= PCR_ECCEN_Reset;
  552.     }
  553.     else
  554.     {
  555.       FSMC_Bank3->PCR3 &= PCR_ECCEN_Reset;
  556.     }
  557.   }
  558. }
  559. /*******************************************************************************
  560. * Function Name  : FSMC_GetECC
  561. * Description    : Returns the error correction code register value.
  562. * Input          : - FSMC_Bank: specifies the FSMC Bank to be used
  563. *                    This parameter can be one of the following values:
  564. *                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
  565. *                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
  566. * Output         : None
  567. * Return         : The Error Correction Code (ECC) value.
  568. *******************************************************************************/
  569. u32 FSMC_GetECC(u32 FSMC_Bank)
  570. {
  571.   u32 eccval = 0x00000000;
  572.   
  573.   if(FSMC_Bank == FSMC_Bank2_NAND)
  574.   {
  575.     /* Get the ECCR2 register value */
  576.     eccval = FSMC_Bank2->ECCR2;
  577.   }
  578.   else
  579.   {
  580.     /* Get the ECCR3 register value */
  581.     eccval = FSMC_Bank3->ECCR3;
  582.   }
  583.   /* Return the error correction code value */
  584.   return(eccval);
  585. }
  586. /*******************************************************************************
  587. * Function Name  : FSMC_ITConfig
  588. * Description    : Enables or disables the specified FSMC interrupts.
  589. * Input          : - FSMC_Bank: specifies the FSMC Bank to be used
  590. *                    This parameter can be one of the following values:
  591. *                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
  592. *                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
  593. *                       - FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  594. *                  - FSMC_IT: specifies the FSMC interrupt sources to be
  595. *                    enabled or disabled.
  596. *                    This parameter can be any combination of the following values:
  597. *                       - FSMC_IT_RisingEdge: Rising edge detection interrupt. 
  598. *                       - FSMC_IT_Level: Level edge detection interrupt.                                  
  599. *                       - FSMC_IT_FallingEdge: Falling edge detection interrupt.
  600. *                  - NewState: new state of the specified FSMC interrupts.
  601. *                    This parameter can be: ENABLE or DISABLE.
  602. * Output         : None
  603. * Return         : None
  604. *******************************************************************************/
  605. void FSMC_ITConfig(u32 FSMC_Bank, u32 FSMC_IT, FunctionalState NewState)
  606. {
  607.   assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  608.   assert_param(IS_FSMC_IT(FSMC_IT));
  609.   assert_param(IS_FUNCTIONAL_STATE(NewState));
  610.   
  611.   if (NewState != DISABLE)
  612.   {
  613.     /* Enable the selected FSMC_Bank2 interrupts */
  614.     if(FSMC_Bank == FSMC_Bank2_NAND)
  615.     {
  616.       FSMC_Bank2->SR2 |= FSMC_IT;
  617.     }
  618.     /* Enable the selected FSMC_Bank3 interrupts */
  619.     else if (FSMC_Bank == FSMC_Bank3_NAND)
  620.     {
  621.       FSMC_Bank3->SR3 |= FSMC_IT;
  622.     }
  623.     /* Enable the selected FSMC_Bank4 interrupts */
  624.     else
  625.     {
  626.       FSMC_Bank4->SR4 |= FSMC_IT;    
  627.     }
  628.   }
  629.   else
  630.   {
  631.     /* Disable the selected FSMC_Bank2 interrupts */
  632.     if(FSMC_Bank == FSMC_Bank2_NAND)
  633.     {
  634.       
  635.       FSMC_Bank2->SR2 &= (u32)~FSMC_IT;
  636.     }
  637.     /* Disable the selected FSMC_Bank3 interrupts */
  638.     else if (FSMC_Bank == FSMC_Bank3_NAND)
  639.     {
  640.       FSMC_Bank3->SR3 &= (u32)~FSMC_IT;
  641.     }
  642.     /* Disable the selected FSMC_Bank4 interrupts */
  643.     else
  644.     {
  645.       FSMC_Bank4->SR4 &= (u32)~FSMC_IT;    
  646.     }
  647.   }
  648. }
  649.                   
  650. /*******************************************************************************
  651. * Function Name  : FSMC_GetFlagStatus
  652. * Description    : Checks whether the specified FSMC flag is set or not.
  653. * Input          : - FSMC_Bank: specifies the FSMC Bank to be used
  654. *                    This parameter can be one of the following values:
  655. *                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
  656. *                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
  657. *                       - FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  658. *                  - FSMC_FLAG: specifies the flag to check.
  659. *                    This parameter can be one of the following values:
  660. *                       - FSMC_FLAG_RisingEdge: Rising egde detection Flag.
  661. *                       - FSMC_FLAG_Level: Level detection Flag.
  662. *                       - FSMC_FLAG_FallingEdge: Falling egde detection Flag.
  663. *                       - FSMC_FLAG_FEMPT: Fifo empty Flag. 
  664. * Output         : None
  665. * Return         : The new state of FSMC_FLAG (SET or RESET).
  666. *******************************************************************************/                   
  667. FlagStatus FSMC_GetFlagStatus(u32 FSMC_Bank, u32 FSMC_FLAG)
  668. {
  669.   FlagStatus bitstatus = RESET;
  670.   u32 tmpsr = 0x00000000;
  671.   
  672.   /* Check the parameters */
  673.   assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
  674.   assert_param(IS_FSMC_GET_FLAG(FSMC_FLAG));
  675.   
  676.   if(FSMC_Bank == FSMC_Bank2_NAND)
  677.   {
  678.     tmpsr = FSMC_Bank2->SR2;
  679.   }  
  680.   else if(FSMC_Bank == FSMC_Bank3_NAND)
  681.   {
  682.     tmpsr = FSMC_Bank3->SR3;
  683.   }
  684.   /* FSMC_Bank4_PCCARD*/
  685.   else
  686.   {
  687.     tmpsr = FSMC_Bank4->SR4;
  688.   } 
  689.   
  690.   /* Get the flag status */
  691.   if ((tmpsr & FSMC_FLAG) != (u16)RESET )
  692.   {
  693.     bitstatus = SET;
  694.   }
  695.   else
  696.   {
  697.     bitstatus = RESET;
  698.   }
  699.   /* Return the flag status */
  700.   return bitstatus;
  701. }
  702. /*******************************************************************************
  703. * Function Name  : FSMC_ClearFlag
  704. * Description    : Clears the FSMC抯 pending flags.
  705. * Input          : - FSMC_Bank: specifies the FSMC Bank to be used
  706. *                    This parameter can be one of the following values:
  707. *                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
  708. *                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
  709. *                       - FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  710. *                  - FSMC_FLAG: specifies the flag to clear.
  711. *                    This parameter can be any combination of the following values:
  712. *                       - FSMC_FLAG_RisingEdge: Rising egde detection Flag.
  713. *                       - FSMC_FLAG_Level: Level detection Flag.
  714. *                       - FSMC_FLAG_FallingEdge: Falling egde detection Flag.
  715. * Output         : None
  716. * Return         : None
  717. *******************************************************************************/                   
  718. void FSMC_ClearFlag(u32 FSMC_Bank, u32 FSMC_FLAG)
  719. {
  720.  /* Check the parameters */
  721.   assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
  722.   assert_param(IS_FSMC_CLEAR_FLAG(FSMC_FLAG)) ;
  723.     
  724.   if(FSMC_Bank == FSMC_Bank2_NAND)
  725.   {
  726.     FSMC_Bank2->SR2 &= ~FSMC_FLAG; 
  727.   }  
  728.   else if(FSMC_Bank == FSMC_Bank3_NAND)
  729.   {
  730.     FSMC_Bank3->SR3 &= ~FSMC_FLAG;
  731.   }
  732.   /* FSMC_Bank4_PCCARD*/
  733.   else
  734.   {
  735.     FSMC_Bank4->SR4 &= ~FSMC_FLAG;
  736.   }
  737. }
  738. /*******************************************************************************
  739. * Function Name  : FSMC_GetITStatus
  740. * Description    : Checks whether the specified FSMC interrupt has occurred or not.
  741. * Input          : - FSMC_Bank: specifies the FSMC Bank to be used
  742. *                    This parameter can be one of the following values:
  743. *                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
  744. *                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
  745. *                       - FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  746. *                  - FSMC_IT: specifies the FSMC interrupt source to check.
  747. *                    This parameter can be one of the following values:
  748. *                       - FSMC_IT_RisingEdge: Rising edge detection interrupt. 
  749. *                       - FSMC_IT_Level: Level edge detection interrupt.                                  
  750. *                       - FSMC_IT_FallingEdge: Falling edge detection interrupt. 
  751. * Output         : None
  752. * Return         : The new state of FSMC_IT (SET or RESET).
  753. *******************************************************************************/ 
  754. ITStatus FSMC_GetITStatus(u32 FSMC_Bank, u32 FSMC_IT)
  755. {
  756.   ITStatus bitstatus = RESET;
  757.   u32 tmpsr = 0x0, itstatus = 0x0, itenable = 0x0; 
  758.   
  759.   /* Check the parameters */
  760.   assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  761.   assert_param(IS_FSMC_GET_IT(FSMC_IT));
  762.   
  763.   if(FSMC_Bank == FSMC_Bank2_NAND)
  764.   {
  765.     tmpsr = FSMC_Bank2->SR2;
  766.   }  
  767.   else if(FSMC_Bank == FSMC_Bank3_NAND)
  768.   {
  769.     tmpsr = FSMC_Bank3->SR3;
  770.   }
  771.   /* FSMC_Bank4_PCCARD*/
  772.   else
  773.   {
  774.     tmpsr = FSMC_Bank4->SR4;
  775.   } 
  776.   
  777.   itstatus = tmpsr & FSMC_IT;
  778.   
  779.   itenable = tmpsr & (FSMC_IT >> 3);
  780.   if ((itstatus != (u32)RESET)  && (itenable != (u32)RESET))
  781.   {
  782.     bitstatus = SET;
  783.   }
  784.   else
  785.   {
  786.     bitstatus = RESET;
  787.   }
  788.   return bitstatus; 
  789. }
  790. /*******************************************************************************
  791. * Function Name  : FSMC_ClearITPendingBit
  792. * Description    : Clears the FSMC抯 interrupt pending bits.
  793. * Input          : - FSMC_Bank: specifies the FSMC Bank to be used
  794. *                    This parameter can be one of the following values:
  795. *                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
  796. *                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
  797. *                       - FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  798. *                  - FSMC_IT: specifies the interrupt pending bit to clear.
  799. *                    This parameter can be any combination of the following values:
  800. *                       - FSMC_IT_RisingEdge: Rising edge detection interrupt. 
  801. *                       - FSMC_IT_Level: Level edge detection interrupt.                                  
  802. *                       - FSMC_IT_FallingEdge: Falling edge detection interrupt.
  803. * Output         : None
  804. * Return         : None
  805. *******************************************************************************/
  806. void FSMC_ClearITPendingBit(u32 FSMC_Bank, u32 FSMC_IT)
  807. {
  808.   /* Check the parameters */
  809.   assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  810.   assert_param(IS_FSMC_IT(FSMC_IT));
  811.     
  812.   if(FSMC_Bank == FSMC_Bank2_NAND)
  813.   {
  814.     FSMC_Bank2->SR2 &= ~(FSMC_IT >> 3); 
  815.   }  
  816.   else if(FSMC_Bank == FSMC_Bank3_NAND)
  817.   {
  818.     FSMC_Bank3->SR3 &= ~(FSMC_IT >> 3);
  819.   }
  820.   /* FSMC_Bank4_PCCARD*/
  821.   else
  822.   {
  823.     FSMC_Bank4->SR4 &= ~(FSMC_IT >> 3);
  824.   }
  825. }
  826. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/