⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lpc177x_8x_emc.c

📁 LPC1788的USBHOST的FATFS移植
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************
* $Id$		lpc177x_8x_emc.c			2011-06-02
*//**
* @file		lpc177x_8x_emc.c
* @brief	Contains all functions support for EMC firmware library
*			on LPC177x_8x
* @version	1.0
* @date		02. June. 2011
* @author	NXP MCU SW Application Team
* 
* Copyright(C) 2011, NXP Semiconductor
* All rights reserved.
*
***********************************************************************
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified
* use without further testing or modification.
**********************************************************************/

#include "lpc177x_8x_emc.h"
#include "lpc177x_8x_clkpwr.h"
#include "lpc177x_8x_pinsel.h"


/*********************************************************************//**
 * @brief 		EMC initialize
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void EMC_Init(void)
{
	uint8_t i;

	/* Enable clock for EMC */
//	CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCEMC, ENABLE);
//	LPC_EMC->Control 	= 0x00000001;
// 	LPC_EMC->Config  	= 0x00000000;

	  LPC_SC->PCONP   	|= 0x00000800;
	  LPC_SC->EMCDLYCTL   = 0x00001010;
	  LPC_EMC->Control 	= 0x00000001;
	  LPC_EMC->Config  	= 0x00000000;

  /* Pin configuration:
   * P2.14 - /EMC_CS2
   * P2.15 - /EMC_CS3
   *
   * P2.16 - /EMC_CAS
   * P2.17 - /EMC_RAS
   * P2.18 - EMC_CLK[0]
   * P2.19 - EMC_CLK[1]
   *
   * P2.20 - EMC_DYCS0
   * P2.21 - EMC_DYCS1
   * P2.22 - EMC_DYCS2
   * P2.23 - EMC_DYCS3
   *
   * P2.24 - EMC_CKE0
   * P2.25 - EMC_CKE1
   * P2.26 - EMC_CKE2
   * P2.27 - EMC_CKE3
   *
   * P2.28 - EMC_DQM0
   * P2.29 - EMC_DQM1
   * P2.30 - EMC_DQM2
   * P2.31 - EMC_DQM3
   *
   * P3.0-P3.31 - EMC_D[0-31]
   * P4.0-P4.23 - EMC_A[0-23]
   *
   * P4.24 - /EMC_OE
   * P4.25 - /EMC_WE
   *
   * P4.30 - /EMC_CS0
   * P4.31 - /EMC_CS1   */


    PINSEL_ConfigPin(0,15,2);
	PINSEL_ConfigPin(2,14,1);
	PINSEL_ConfigPin(2,15,1);
	PINSEL_ConfigPin(2,16,1);
	PINSEL_ConfigPin(2,17,1);
	PINSEL_ConfigPin(2,18,1);
	PINSEL_ConfigPin(2,19,1);
	PINSEL_ConfigPin(2,20,1);
	PINSEL_ConfigPin(2,21,1);
   	PINSEL_ConfigPin(2,22,1);
	PINSEL_ConfigPin(2,23,1);
	PINSEL_ConfigPin(2,24,1);
	PINSEL_ConfigPin(2,25,1);
	PINSEL_ConfigPin(2,26,1);
	PINSEL_ConfigPin(2,27,1);
	PINSEL_ConfigPin(2,28,1);
	PINSEL_ConfigPin(2,29,1);
	PINSEL_ConfigPin(2,30,1);
	PINSEL_ConfigPin(2,31,1);

	for(i = 0; i < 32; i++)
	{
		PINSEL_ConfigPin(3,i,1);
		PINSEL_ConfigPin(4,i,1);
	}
}
/*********************************************************************//**
 * @brief 		Configure Little Endian/Big Endian mode for EMC
 * @param[in]	endia_mode	Endian mode, should be:
 * 				- EMC_LITTLE_ENDIAN_MODE:	Little-endian mode
 * 				- EMC_BIG_ENDIAN_MODE	:	Big-endian mode
 * @return 		None
 **********************************************************************/
void EMC_ConfigEndianMode(uint32_t endian_mode)
{
   LPC_EMC->Config = ((LPC_EMC->Config & 0x01)|endian_mode) & EMC_Config_MASK;
}

/****************** Group of Dynamic control functions************************/
/*********************************************************************//**
 * @brief 		Set the value for dynamic clock enable bit
 * @param[in]	clock_enable	clock enable mode, should be:
 * 					- 0: Clock enable of idle devices are deasserted to
 * 						save power
 * 					- 1: All clock enables are driven HIGH continuously
 * @return 		None
 **********************************************************************/
void EMC_DynCtrlClockEnable(uint32_t clock_enable)
{
   LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl) |clock_enable);
}

/*********************************************************************//**
 * @brief 		Set the value for dynamic memory clock control:
 * 				stops or runs continuously
 * @param[in]	clock_control	clock control mode, should be:
 * 					- 0: CLKOUT stops when all SDRAMs are idle and
 * 						during self-refresh mode
 * 					- 1: CLKOUT runs continuously
 * @return 		None
 **********************************************************************/
void EMC_DynCtrlClockControl(int32_t clock_control)
{
   uint32_t mask = ~(uint32_t)(2);
   LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl & mask) |clock_control);
}

/*********************************************************************//**
 * @brief 		Switch the Self-refresh mode between normal and self-refresh mode
 * @param[in]	self_refresh_mode	self refresh mode, should be:
 * 					- 0: Normal mode
 * 					- 1: Enter self-refresh mode
 * @return 		None
 **********************************************************************/
void EMC_DynCtrlSelfRefresh(uint32_t self_refresh_mode)
{
   uint32_t mask = ~(uint32_t)(4);
   LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl & mask) |self_refresh_mode);
}

/*********************************************************************//**
 * @brief 		Enable/disable CLKOUT
 * @param[in]	MMC_val	Memory clock control mode, should be:
 * 					- 0: CLKOUT enabled
 * 					- 1: CLKOUT disabled
 * @return 		None
 **********************************************************************/
void EMC_DynCtrlMMC(uint32_t MMC_val)
{
   uint32_t mask = ~(uint32_t)(_BIT(5));
   LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl & mask) |MMC_val);
}

/*********************************************************************//**
 * @brief 		Issue SDRAM command
 * @param[in]	SDRAM_command	Command mode, should be:
 * 					- 0x00: Issue SDRAM NORMAL operation command
 * 					- 0x01: Issue SDRAM MODE command
 * 					- 0x02: Issue SDRAM PALL (precharge all) command
 * 					- 0x03: Issue SRAM NOP (no operation) command
 * @return 		None
 **********************************************************************/
void EMC_DynCtrlSDRAMInit(uint32_t SDRAM_command)
{
   uint32_t mask = ~(uint32_t)(_SBF(7,0x03));
   LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl & mask)|SDRAM_command);
}

/*********************************************************************//**
 * @brief 		Switch between Normal operation and deep sleep power mode
 * @param[in]	Power_command	Low-power SDRAM deep-sleep mode, should be:
 *					- 0: Normal operation
 *					- 1: Enter deep-sleep mode
 * @return 		None
 **********************************************************************/
void EMC_DynCtrlPowerDownMode(uint32_t Power_command)
{
   uint32_t mask = ~(uint32_t)(_BIT(13));
   LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl & mask)|Power_command);
}

/*********************************************************************//**
 * @brief 		Set the value of EMC dynamic memory registers
 * @param[in]	par	EMC register that will set value, should be:
 *					- EMC_DYN_MEM_REFRESH_TIMER: Dynamic Refresh register
 *					- EMC_DYN_MEM_READ_CONFIG: Dynamic Read Config register
 *					- EMC_DYN_MEM_TRP: Dynamic RP register
 *					- EMC_DYN_MEM_TRAS: Dynamic RAS register
 *					- EMC_DYN_MEM_TSREX: Dynamic SREX register
 *					- EMC_DYN_MEM_TAPR: Dynamic APR register
 *					- EMC_DYN_MEM_TDAL: Dynamic DAL register
 *					- EMC_DYN_MEM_TWR: Dynamic WR register
 *					- EMC_DYN_MEM_TRC: Dynamic RC register
 *					- EMC_DYN_MEM_TRFC: Dynamic RFC register
 *					- EMC_DYN_MEM_TXSR: Dynamic XSR register
 *					- EMC_DYN_MEM_TRRD: Dynamic RRD register
 *					- EMC_DYN_MEM_TMRD: Dynamic MRD register
 * @return 		None
 **********************************************************************/
void EMC_SetDynMemoryParameter(EMC_DYN_MEM_PAR par, uint32_t val)
{
   switch ( par)
   {
      case EMC_DYN_MEM_REFRESH_TIMER:
         LPC_EMC->DynamicRefresh = val;
         break;
      case EMC_DYN_MEM_READ_CONFIG:
         LPC_EMC->DynamicReadConfig = val;
         break;
      case EMC_DYN_MEM_TRP:
         LPC_EMC->DynamicRP = val;
         break;
      case EMC_DYN_MEM_TRAS:
         LPC_EMC->DynamicRAS = val;
         break;
      case EMC_DYN_MEM_TSREX:
         LPC_EMC->DynamicSREX = val;
         break;
      case EMC_DYN_MEM_TAPR:
         LPC_EMC->DynamicAPR = val;
         break;
      case EMC_DYN_MEM_TDAL:
         LPC_EMC->DynamicDAL = val;
         break;
      case EMC_DYN_MEM_TWR:
         LPC_EMC->DynamicWR = val;
         break;
      case EMC_DYN_MEM_TRC:
         LPC_EMC->DynamicRC = val;
         break;
      case EMC_DYN_MEM_TRFC:
         LPC_EMC->DynamicRFC = val;
         break;
      case EMC_DYN_MEM_TXSR:
         LPC_EMC->DynamicXSR = val;
         break;
      case EMC_DYN_MEM_TRRD:
         LPC_EMC->DynamicRRD = val;
         break;
      case EMC_DYN_MEM_TMRD:
         LPC_EMC->DynamicMRD = val;
         break;
   }
}

/*********************************************************************//**
 * @brief 		Set extended wait time out for accessing static memory
 * @param[in]	Extended_wait_time_out timeout value that will be set
 * @return 		None
 **********************************************************************/
void EMC_StaticExtendedWait(uint32_t Extended_wait_time_out)
{
   LPC_EMC->StaticExtendedWait = Extended_wait_time_out;
}

/*********************************************************************//**
 * @brief 		Configure the memory device
 * @param[in]	index index number, should be from 0 to 3
 * @param[in]	mem_dev Memory device, should be:
 *					- 0x00: SDRAM
 *					- 0x01: Low-power SDRAM
 *					- 0x02: Micron Syncflash
 * @return 		None
 **********************************************************************/
void EMC_DynMemConfigMD(uint32_t index , uint32_t mem_dev)
{
   uint32_t mask = ~(uint32_t)(_SBF(3, 0x03));
   switch ( index)
   {
      case 0:
         LPC_EMC->DynamicConfig0 = (LPC_EMC->DynamicConfig0 & mask) | mem_dev;
	   break;
      case 1:
         LPC_EMC->DynamicConfig1 = (LPC_EMC->DynamicConfig1 & mask) | mem_dev;
	   break;
      case 2:
         LPC_EMC->DynamicConfig2 =(LPC_EMC->DynamicConfig2 & mask) | mem_dev;
	   break;
      case 3:
         LPC_EMC->DynamicConfig3 = (LPC_EMC->DynamicConfig3 & mask) | mem_dev;
	   break;
   }
}

/*********************************************************************//**
 * @brief 		Map the address for the memory device
 * @param[in]	index index number, should be from 0 to 3
 * @param[in] 	add_mapped address where the memory will be mapped
 * @return 		None
 **********************************************************************/
void EMC_DynMemConfigAM(uint32_t index , uint32_t add_mapped)
{
   uint32_t mask = ~(uint32_t)(_SBF(7, 0x3f)) | ~(uint32_t)(_BIT(14))  ;

   switch ( index)
   {
      case 0:
         LPC_EMC->DynamicConfig0 = ( LPC_EMC->DynamicConfig0 & mask) | add_mapped;
	   break;
      case 1:
         LPC_EMC->DynamicConfig1 = (LPC_EMC->DynamicConfig1 & mask) | add_mapped;
	   break;
      case 2:
         LPC_EMC->DynamicConfig2 = (LPC_EMC->DynamicConfig2 & mask) | add_mapped;
	   break;
      case 3:
         LPC_EMC->DynamicConfig3 = (LPC_EMC->DynamicConfig3 & mask) | add_mapped;
	   break;
   }
}

/*********************************************************************//**
 * @brief 		Enable/disable the buffer
 * @param[in]	index index number, should be from 0 to 3
 * @param[in] 	buff_control buffer control mode, should be:
 * 					- ENABLE
 * 					- DISABLE
 * @return 		None
 **********************************************************************/
void EMC_DynMemConfigB(uint32_t index , uint32_t buff_control)
{
   uint32_t mask =  ~(uint32_t)(_BIT(19))  ;
   switch ( index)
   {
      case 0:
         LPC_EMC->DynamicConfig0 = (LPC_EMC->DynamicConfig0 & mask) | buff_control;
	   break;
      case 1:
         LPC_EMC->DynamicConfig1 = ( LPC_EMC->DynamicConfig1 & mask) | buff_control;
	   break;
      case 2:
         LPC_EMC->DynamicConfig2 = (LPC_EMC->DynamicConfig2 & mask)| buff_control;
	   break;
      case 3:
         LPC_EMC->DynamicConfig3 = (LPC_EMC->DynamicConfig3 & mask) | buff_control;
	   break;
   }
}


/*********************************************************************//**
 * @brief 		Configure write permission: protect or not
 * @param[in]	index index number, should be from 0 to 3
 * @param[in] 	permission  permission mode, should be:
 * 					- ENABLE: protect
 * 					- DISABLE: not protect
 * @return 		None
 **********************************************************************/
void EMC_DynMemConfigP(uint32_t index , uint32_t permission)
{
   uint32_t mask =  ~(uint32_t)(_BIT(20))  ;
   switch ( index)
   {
      case 0:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -