source: rtems/bsps/arm/lpc32xx/start/emc.c @ 43250167

5
Last change on this file since 43250167 was 43250167, checked in by Sebastian Huber <sebastian.huber@…>, on 04/25/18 at 08:36:52

bsp/lpc32xx: Move source files to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup lpc32xx_emc
5 *
6 * @brief EMC support implementation.
7 */
8
9/*
10 * Copyright (c) 2010
11 * embedded brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * <rtems@embedded-brains.de>
16 *
17 * The license and distribution terms for this file may be
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.org/license/LICENSE.
20 */
21
22#include <bsp/emc.h>
23
24#include <bsp.h>
25#include <bsp/mmu.h>
26
27static volatile lpc_emc *const emc = &lpc32xx.emc;
28
29static volatile lpc32xx_emc_ahb *const emc_ahb = &lpc32xx.emc_ahb [0];
30
31static void dynamic_init(const lpc32xx_emc_dynamic_config *cfg)
32{
33  uint32_t chip_begin = LPC32XX_BASE_EMC_DYCS_0;
34  uint32_t dynamiccontrol = (cfg->control | EMC_DYN_CTRL_CE | EMC_DYN_CTRL_CS)
35    & ~EMC_DYN_CTRL_I_MASK;
36  size_t i = 0;
37
38  LPC32XX_SDRAMCLK_CTRL = cfg->sdramclk_ctrl;
39
40  emc->dynamicreadconfig = cfg->readconfig;
41
42  /* Timings */
43  emc->dynamictrp = cfg->trp;
44  emc->dynamictras = cfg->tras;
45  emc->dynamictsrex = cfg->tsrex;
46  emc->dynamictwr = cfg->twr;
47  emc->dynamictrc = cfg->trc;
48  emc->dynamictrfc = cfg->trfc;
49  emc->dynamictxsr = cfg->txsr;
50  emc->dynamictrrd = cfg->trrd;
51  emc->dynamictmrd = cfg->tmrd;
52  emc->dynamictcdlr = cfg->tcdlr;
53  for (i = 0; i < EMC_DYN_CHIP_COUNT; ++i) {
54    if (cfg->chip [i].size != 0) {
55      emc->dynamic [i].config = cfg->chip [i].config;
56      emc->dynamic [i].rascas = cfg->chip [i].rascas;
57    }
58  }
59
60  /* NOP period */
61  emc->dynamiccontrol = dynamiccontrol | EMC_DYN_CTRL_I_NOP;
62  lpc32xx_micro_seconds_delay(cfg->nop_time_in_us);
63
64  /* Precharge */
65  emc->dynamiccontrol = dynamiccontrol | EMC_DYN_CTRL_I_PALL;
66  emc->dynamicrefresh = 1;
67  /* FIXME: Why a delay, why this value? */
68  lpc32xx_micro_seconds_delay(10);
69
70  /* Refresh timing */
71  emc->dynamicrefresh = cfg->refresh;
72  /* FIXME: Why a delay, why this value? */
73  lpc32xx_micro_seconds_delay(16);
74
75  /* Set modes */
76  for (i = 0; i < EMC_DYN_CHIP_COUNT; ++i) {
77    if (cfg->chip [i].size != 0) {
78      lpc32xx_set_translation_table_entries(
79        (void *) chip_begin,
80        (void *) (chip_begin + cfg->chip [i].size),
81        LPC32XX_MMU_READ_WRITE
82      );
83      emc->dynamiccontrol = dynamiccontrol | EMC_DYN_CTRL_I_MODE;
84      *(volatile uint32_t *)(chip_begin + cfg->chip [i].mode);
85      emc->dynamiccontrol = dynamiccontrol | EMC_DYN_CTRL_I_MODE;
86      *(volatile uint32_t *)(chip_begin + cfg->chip [i].extmode);
87    }
88    chip_begin += 0x20000000;
89  }
90
91  emc->dynamiccontrol = cfg->control;
92}
93
94void lpc32xx_emc_init(const lpc32xx_emc_dynamic_config *dyn_cfg)
95{
96  /* Enable buffers in AHB ports */
97  emc_ahb [0].control = EMC_AHB_PORT_BUFF_EN;
98  emc_ahb [3].control = EMC_AHB_PORT_BUFF_EN;
99  emc_ahb [4].control = EMC_AHB_PORT_BUFF_EN;
100
101  /* Set AHB port timeouts */
102  emc_ahb [0].timeout = EMC_AHB_TIMEOUT(32);
103  emc_ahb [3].timeout = EMC_AHB_TIMEOUT(32);
104  emc_ahb [4].timeout = EMC_AHB_TIMEOUT(32);
105
106  /* Enable EMC */
107  emc->control = EMC_CTRL_E,
108  emc->config = 0;
109
110  dynamic_init(dyn_cfg);
111}
Note: See TracBrowser for help on using the repository browser.