1 | //! SDRAM initialization delay in number of CLKper2 cycles (100 us)
|
2 | #define BOARD_EBI_SDRAM_INITDLY \
|
3 | (100 * 2 * sysclk_get_per2_hz() / 1000000)
|
4 | //! SDRAM refresh interval in number of CLKper2 cycles (16 us)
|
5 | #define BOARD_EBI_SDRAM_REFRESH \
|
6 | (16 * 2 * sysclk_get_per2_hz() / 1000000)
|
7 | /* \brief EBI chip select configuration
|
8 | *
|
9 | * This struct holds the configuration for the chip select used to set up the
|
10 | * SDRAM. The example code will use the EBI helper function to setup the
|
11 | * contents before writing the configuration using ebi_cs_write_config().
|
12 | */
|
13 | static struct ebi_cs_config cs_config;
|
14 | /*
|
15 | * \brief EBI SDRAM configuration
|
16 | *
|
17 | * This struct holds the configuration for the SDRAM. The example code will
|
18 | * use the EBI helper function to setup the contents before writing the
|
19 | * configuration using ebi_sdram_write_config().
|
20 | */
|
21 | static void InitSDRAM(void) {
|
22 | /*
|
23 | * Configure the EBI port with 12 address lines, no address latches or
|
24 | * low pin count, and set it in SDRAM mode with 3-port EBI port.
|
25 | */
|
26 | ebi_setup_port(12, 0, 0, EBI_PORT_3PORT | EBI_PORT_SDRAM);
|
27 | /*
|
28 | * Configure the EBI chip select for an 8 MB SDRAM located at
|
29 | * \ref BOARD_EBI_SDRAM_BASE.
|
30 | */
|
31 | ebi_cs_set_mode(&cs_config, EBI_CS_MODE_SDRAM_gc);
|
32 | ebi_cs_set_address_size(&cs_config, EBI_CS_ASIZE_8MB_gc);
|
33 | ebi_cs_set_base_address(&cs_config, BOARD_EBI_SDRAM_BASE);
|
34 |
|
35 | /* Configure the EBI chip select to be in SDRAM mode. */
|
36 | ebi_sdram_set_mode(&cs_config, EBI_CS_SDMODE_NORMAL_gc);
|
37 |
|
38 | /* Setup the number of SDRAM rows and columns. */
|
39 | ebi_sdram_set_row_bits(&sdram_config, 12);
|
40 | ebi_sdram_set_col_bits(&sdram_config, 10);
|
41 | /* Further, setup the SDRAM timing. */
|
42 | ebi_sdram_set_cas_latency(&sdram_config, 3);
|
43 | ebi_sdram_set_mode_delay(&sdram_config, EBI_MRDLY_2CLK_gc);
|
44 | ebi_sdram_set_row_cycle_delay(&sdram_config, EBI_ROWCYCDLY_7CLK_gc);
|
45 | ebi_sdram_set_row_to_precharge_delay(&sdram_config, EBI_RPDLY_7CLK_gc);
|
46 | ebi_sdram_set_write_recovery_delay(&sdram_config, EBI_WRDLY_1CLK_gc);
|
47 | ebi_sdram_set_self_refresh_to_active_delay(&sdram_config,
|
48 | EBI_ESRDLY_7CLK_gc);
|
49 | ebi_sdram_set_row_to_col_delay(&sdram_config, EBI_ROWCOLDLY_7CLK_gc);
|
50 | ebi_sdram_set_refresh_period(&sdram_config, BOARD_EBI_SDRAM_REFRESH);
|
51 | ebi_sdram_set_initialization_delay(&sdram_config,
|
52 | BOARD_EBI_SDRAM_INITDLY);
|
53 |
|
54 | /* Write SDRAM configuration into the EBI registers. */
|
55 | ebi_sdram_write_config(&sdram_config);
|
56 | /* Write the chip select configuration into the EBI registers. */
|
57 | ebi_cs_write_config(EBI_SDRAM_CS, &cs_config);
|
58 |
|
59 | ebi_enable_cs(EBI_SDRAM_CS, &cs_config);
|
60 | do {
|
61 | // Wait for SDRAM to initialize.
|
62 | } while (!ebi_sdram_is_ready());
|
63 | }
|
64 | {/c]
|
65 | Lesen und schreiben tust du am besten mit den Hugemem routinen:
|
66 | [c]// write something
|
67 | hugemem_write32(writeptr ,time);
|
68 | writeptr +=4;
|
69 | hugemem_write16(writeptr ,x);
|
70 | writeptr +=2;
|
71 | //Read something
|
72 | hugemem_read32(readptr ,time);
|
73 | readptr +=4;
|
74 | hugemem_read16(readptr ,x);
|
75 | readptr +=2;
|