#include <sys/timer.h>
#include <arch/cm3.h>
#include <arch/cm3/nxp/lpc177x_8x.h>
#include <arch/cm3/nxp/lpc177x_8x_emc.h>
#include <arch/cm3/nxp/lpc177x_8x_clk.h>
#include <arch/cm3/nxp/lpc177x_8x_gpio.h>
Defines | |
#define | DEFAULT_CLKOUTDLY 0 |
#define | DEFAULT_FBCLKDLY 20 |
#define | DEFAULT_CMDDLY 16 |
#define | DELAY_RANGE 0x1F |
#define | SDRAMTEST_BLOCKSIZE 0x100 |
#define | SDRAMTEST_JUMPSIZE 0x10000 |
Functions | |
void | Lpc177x_8x_EmcInit (void) |
Initialize EMC. | |
void | Lpc177x_8x_EmcSDRAMAdjustTiming (void) |
Ajust SDRAM SDRAM timing. | |
int | Lpc177x_8x_EmcSDRAMCheck (SDRAM sdram, uint32_t offset) |
Simple SDRAM test. | |
void | Lpc177x_8x_EmcSDRAMInit (SDRAM sdram, uint32_t dynamic_config) |
EMC SDRAM initialisation. | |
void | Lpc177x_8x_EmcConfigEndianMode (uint32_t endian_mode) |
Configure Little Endian/Big Endian mode for EMC. | |
void | Lpc177x_8x_EmcDynCtrlClockEnable (uint32_t clock_enable) |
Set the value for dynamic clock enable bit. | |
void | Lpc177x_8x_EmcDynCtrlClockControl (uint32_t clock_control) |
Set the value for dynamic memory clock control: stops or runs continuously. | |
void | Lpc177x_8x_EmcDynCtrlSelfRefresh (uint32_t self_refresh_mode) |
Switch the Self-refresh mode between normal and self-refresh mode. | |
void | Lpc177x_8x_EmcDynCtrlMMC (uint32_t mmc_val) |
Enable/disable CLKOUT. | |
void | Lpc177x_8x_EmcDynCtrlSDRAMCmd (uint32_t sdram_command) |
Issue SDRAM command. | |
void | Lpc177x_8x_EmcDynCtrlPowerDownMode (uint32_t power_command) |
Switch between Normal operation and deep sleep power mode. | |
void | Lpc177x_8x_EmcSetDynMemoryParameter (EMC_DYN_MEM_PAR par, uint32_t val) |
Set the value of EMC dynamic memory registers. | |
void | Lpc177x_8x_EmcStaticExtendedWait (uint32_t timeout) |
Set extended wait time out for accessing static memory. | |
void | Lpc177x_8x_EmcDynMemConfigMD (uint32_t cs, uint32_t mem_dev) |
Configure the memory device. | |
void | Lpc177x_8x_EmcDynMemConfigAM (uint32_t cs, uint32_t addr_mapped) |
Map the address for the memory device. | |
void | Lpc177x_8x_EmcDynMemConfigB (uint32_t cs, uint32_t buff_control) |
Enable/disable the buffer. | |
void | Lpc177x_8x_EmcDynMemConfigP (uint32_t cs, uint32_t permission) |
Configure write permission: protect or not. | |
void | Lpc177x_8x_EmcDynMemRAS (uint32_t cs, uint32_t ras_val) |
Set value for RAS latency. | |
void | Lpc177x_8x_EmcDynMemCAS (uint32_t cs, uint32_t cas_val) |
Set value for CAS latency. | |
void | Lpc177x_8x_EmcStaticMemConfigMW (uint32_t cs, uint32_t mem_width) |
Configure the memory bus width. | |
void | Lpc177x_8x_EmcStaticMemConfigPM (uint32_t cs, uint32_t page_mode) |
Configure the page mode. | |
void | Lpc177x_8x_EmcStaticMemConfigPC (uint32_t cs, uint32_t polarity) |
Configure the chip select polarity. | |
void | Lpc177x_8x_EmcStaticMemConfigPB (uint32_t cs, uint32_t pb_val) |
Configure the byte lane state. | |
void | Lpc177x_8x_EmcStaticMemConfigEW (uint32_t cs, uint32_t ex_wait) |
Configure the extended wait value. | |
void | Lpc177x_8x_EmcStaticMemConfigB (uint32_t cs, uint32_t buf_val) |
Configure the buffer enable value. | |
void | Lpc177x_8x_EmcStaticMemConfigpP (uint32_t cs, uint32_t permission) |
Configure the write permission. | |
void | Lpc177x_8x_EmcSetStaticMemoryParameter (uint32_t cs, EMC_STA_MEM_PAR par, uint32_t val) |
Set the value of LPC_EMC static memory registers. | |
Variables | |
volatile uint32_t | original_cmdclkdelay = 0 |
volatile uint32_t | original_fbclkdelay = 0 |
volatile uint32_t | initial_calibration_value |
#define DEFAULT_CLKOUTDLY 0 |
Referenced by Lpc177x_8x_EmcSDRAMAdjustTiming().
#define DEFAULT_FBCLKDLY 20 |
Referenced by Lpc177x_8x_EmcSDRAMInit().
#define DEFAULT_CMDDLY 16 |
Referenced by Lpc177x_8x_EmcSDRAMInit().
#define DELAY_RANGE 0x1F |
#define SDRAMTEST_BLOCKSIZE 0x100 |
Referenced by Lpc177x_8x_EmcSDRAMCheck().
#define SDRAMTEST_JUMPSIZE 0x10000 |
Referenced by Lpc177x_8x_EmcSDRAMCheck().
void Lpc177x_8x_EmcInit | ( | void | ) |
Initialize EMC.
Initialize the external memory controller. GPIO pins should be correctly configured when calling this function.
none |
References CLKPWR_PCONP_PCEMC, LPC_EMC, LPC_SC, and SysCtlPeripheralClkEnable.
Referenced by NutBoardInit().
void Lpc177x_8x_EmcSDRAMAdjustTiming | ( | void | ) |
Ajust SDRAM SDRAM timing.
This function should be called regularly to re-calibrate the delay lines which might change their correct delays due to thermal influences
none |
References DEFAULT_CLKOUTDLY, initial_calibration_value, LPC_SC, original_cmdclkdelay, and original_fbclkdelay.
Simple SDRAM test.
This is used at startup time (before the first usage) to find the optimum delay time values.
ATT: This test overwrites the previous SDRAM contents! Please note that IT IS NOT POSSIBLE to preserve these contents because it might be possible that garbage address commands are output and we will not know which locations are addressed during this test. DO NOT USE this test if executing code from SDRAM.
ATT: This test is far from complete. We neither check differen write sizes nor do we use selected pattern to check single bit failures etc.
sdram | configuration struct of the used sdram |
offset | constant used to modify the test pattern |
References _sdram_params::base_addr, SDRAMTEST_BLOCKSIZE, SDRAMTEST_JUMPSIZE, and _sdram_params::size.
Referenced by NutIdleInit().
EMC SDRAM initialisation.
This function configures the emc to a sdram connected to CS0 SDRAM timing parameters must be given as parameter
sdram | configuration struct of the used sdram |
dynamic_config | configuration values for dynamic_config register |
References _BV, _sdram_params::base_addr, _sdram_params::bus_width, _sdram_params::cas_latency, _sdram_params::cols, DEFAULT_CMDDLY, DEFAULT_FBCLKDLY, initial_calibration_value, LPC_EMC, LPC_SC, NS_2_CLKS, NUT_HWCLK_CPU, NutArchClockGet(), original_cmdclkdelay, original_fbclkdelay, _sdram_params::ras_latency, _sdram_params::refresh, _sdram_params::tAPR, _sdram_params::tDAL, _sdram_params::tMRD, _sdram_params::tRAS, _sdram_params::tRC, _sdram_params::tRFC, _sdram_params::tRP, _sdram_params::tRRD, _sdram_params::tSREX, _sdram_params::tWR, and _sdram_params::tXSR.
Referenced by NutBoardInit().
void Lpc177x_8x_EmcConfigEndianMode | ( | uint32_t | endian_mode | ) |
Configure Little Endian/Big Endian mode for EMC.
endian_mode | Endian mode, should be:
|
References EMC_Config_MASK, and LPC_EMC.
void Lpc177x_8x_EmcDynCtrlClockEnable | ( | uint32_t | clock_enable | ) |
Set the value for dynamic clock enable bit.
clock_enable | clock enable mode, should be:
|
References EMC_DynamicControl_CE, and LPC_EMC.
void Lpc177x_8x_EmcDynCtrlClockControl | ( | uint32_t | clock_control | ) |
Set the value for dynamic memory clock control: stops or runs continuously.
clock_control | clock control mode, should be:
|
References EMC_DynamicControl_CS, and LPC_EMC.
void Lpc177x_8x_EmcDynCtrlSelfRefresh | ( | uint32_t | self_refresh_mode | ) |
Switch the Self-refresh mode between normal and self-refresh mode.
self_refresh_mode | self refresh mode, should be:
|
References EMC_DynamicControl_SR, and LPC_EMC.
void Lpc177x_8x_EmcDynCtrlMMC | ( | uint32_t | mmc_val | ) |
Enable/disable CLKOUT.
MMC_val | Memory clock control mode, should be:
|
References EMC_DynamicControl_MMC, and LPC_EMC.
void Lpc177x_8x_EmcDynCtrlSDRAMCmd | ( | uint32_t | sdram_command | ) |
Issue SDRAM command.
sdram_command | Command mode, should be:
|
References EMC_DynamicControl_I, and LPC_EMC.
void Lpc177x_8x_EmcDynCtrlPowerDownMode | ( | uint32_t | power_command | ) |
Switch between Normal operation and deep sleep power mode.
power_command | Low-power SDRAM deep-sleep mode, should be:
|
References EMC_DynamicControl_DP, and LPC_EMC.
void Lpc177x_8x_EmcSetDynMemoryParameter | ( | EMC_DYN_MEM_PAR | par, |
uint32_t | val | ||
) |
Set the value of EMC dynamic memory registers.
par | EMC register that will set value, should be:
|
References EMC_DYN_MEM_READ_CONFIG, EMC_DYN_MEM_REFRESH_TIMER, EMC_DYN_MEM_TAPR, EMC_DYN_MEM_TDAL, EMC_DYN_MEM_TMRD, EMC_DYN_MEM_TRAS, EMC_DYN_MEM_TRC, EMC_DYN_MEM_TRFC, EMC_DYN_MEM_TRP, EMC_DYN_MEM_TRRD, EMC_DYN_MEM_TSREX, EMC_DYN_MEM_TWR, EMC_DYN_MEM_TXSR, and LPC_EMC.
void Lpc177x_8x_EmcStaticExtendedWait | ( | uint32_t | timeout | ) |
Set extended wait time out for accessing static memory.
timeout | timeout value that will be set |
References LPC_EMC.
Configure the memory device.
cs | number of chip select, should be from 0 to 3 |
mem_dev | memory device type, should be:
|
References LPC_EMC.
Enable/disable the buffer.
cs | number of chip select, should be from 0 to 3 |
buff_control | buffer control mode, should be: 0 - buffer disabled EMC_StaticConfig_B: buffer enabled for the selected chip select |
References EMC_DynamicConfig_B, and LPC_EMC.
Configure write permission: protect or not.
cs | number of chip select, should be from 0 to 3 |
permission | permission mode, should be: 0 - not protected EMC_StaticConfig_P: write protection enabled |
References EMC_DynamicConfig_P, and LPC_EMC.
Set value for RAS latency.
cs | number of chip select, should be from 0 to 3 |
ras_val | RAS value should be in range: 0..3 |
References LPC_EMC.
Set value for CAS latency.
cs | number of chip select, should be from 0 to 3 |
cas_val | CAS value should be in range: 0..3 |
References LPC_EMC.
Configure the memory bus width.
cs | number of chip select, should be from 0 to 3 |
mem_width | memory width, should be:
|
References LPC_EMC.
Configure the page mode.
cs | number of chip select, should be from 0 to 3 |
page_mode | page mode, should be
|
References EMC_StaticConfig_PM, and LPC_EMC.
Configure the chip select polarity.
cs | number of chip select, should be from 0 to 3 |
polarity | chip select polarity, should be:
|
References EMC_StaticConfig_PC, and LPC_EMC.
Configure the byte lane state.
cs | number of chip select, should be from 0 to 3 |
pb_val | Byte lane state, should be:
|
References EMC_StaticConfig_PB, and LPC_EMC.
Configure the extended wait value.
cs | number of chip select, should be from 0 to 3 |
ex_wait | Extended wait mode, should be:
|
References EMC_StaticConfig_EW, and LPC_EMC.
Configure the buffer enable value.
cs | number of chip select, should be from 0 to 3 |
buf_val | Buffer mode, should be:
|
References EMC_StaticConfig_B, and LPC_EMC.
void Lpc177x_8x_EmcSetStaticMemoryParameter | ( | uint32_t | cs, |
EMC_STA_MEM_PAR | par, | ||
uint32_t | val | ||
) |
Set the value of LPC_EMC static memory registers.
cs | number of chip select, should be from 0 to 3 |
par | Static register, should be:
|
val | register value to set |
References EMC_STA_MEM_WAITOEN, EMC_STA_MEM_WAITPAGE, EMC_STA_MEM_WAITRD, EMC_STA_MEM_WAITTURN, EMC_STA_MEM_WAITWEN, EMC_STA_MEM_WAITWR, and LPC_EMC.
volatile uint32_t original_cmdclkdelay = 0 |
Referenced by Lpc177x_8x_EmcSDRAMAdjustTiming(), and Lpc177x_8x_EmcSDRAMInit().
volatile uint32_t original_fbclkdelay = 0 |
Referenced by Lpc177x_8x_EmcSDRAMAdjustTiming(), and Lpc177x_8x_EmcSDRAMInit().
volatile uint32_t initial_calibration_value |
Referenced by Lpc177x_8x_EmcSDRAMAdjustTiming(), and Lpc177x_8x_EmcSDRAMInit().