1 | // Sollte vorne zu den anderen includes
|
2 | #include <ebi.h>
|
3 | #include <ebi_port.h>
|
4 | #include <hugemem.h>
|
5 | // constants for refresh and init
|
6 | //! SDRAM initialization delay in number of CLKper2 cycles (100 us)
|
7 | #define BOARD_EBI_SDRAM_INITDLY \
|
8 | (100 * 2 * sysclk_get_per2_hz() / 1000000)
|
9 |
|
10 | //! SDRAM refresh interval in number of CLKper2 cycles (16 us)
|
11 | #define BOARD_EBI_SDRAM_REFRESH \
|
12 | (16 * 2 * sysclk_get_per2_hz() / 1000000)
|
13 |
|
14 | /**
|
15 | * \brief EBI chip select configuration
|
16 | *
|
17 | * This struct holds the configuration for the chip select used to set up the
|
18 | * SDRAM. The example code will use the EBI helper function to setup the
|
19 | * contents before writing the configuration using ebi_cs_write_config().
|
20 | */
|
21 | static struct ebi_cs_config cs_config;
|
22 |
|
23 | /**
|
24 | * \brief EBI SDRAM configuration
|
25 | *
|
26 | * This struct holds the configuration for the SDRAM. The example code will
|
27 | * use the EBI helper function to setup the contents before writing the
|
28 | * configuration using ebi_sdram_write_config().
|
29 | */
|
30 | static struct ebi_sdram_config sdram_config;
|
31 | // Init the EBI and the RAM. Note that the RAM will not be cleared here.
|
32 | static void InitSDRAM(void) {
|
33 | /*
|
34 | * Configure the EBI port with 12 address lines, no address latches or
|
35 | * low pin count, and set it in SDRAM mode with 3-port EBI port.
|
36 | */
|
37 | ebi_setup_port(12, 0, 0, EBI_PORT_3PORT | EBI_PORT_SDRAM);
|
38 |
|
39 | /*
|
40 | * Configure the EBI chip select for an 8 MB SDRAM located at
|
41 | * \ref BOARD_EBI_SDRAM_BASE.
|
42 | */
|
43 | ebi_cs_set_mode(&cs_config, EBI_CS_MODE_SDRAM_gc);
|
44 | ebi_cs_set_address_size(&cs_config, EBI_CS_ASIZE_8MB_gc);
|
45 | ebi_cs_set_base_address(&cs_config, BOARD_EBI_SDRAM_BASE);
|
46 |
|
47 | /* Configure the EBI chip select to be in SDRAM mode. */
|
48 | ebi_sdram_set_mode(&cs_config, EBI_CS_SDMODE_NORMAL_gc);
|
49 |
|
50 | /* Setup the number of SDRAM rows and columns. */
|
51 | ebi_sdram_set_row_bits(&sdram_config, 12);
|
52 | ebi_sdram_set_col_bits(&sdram_config, 10);
|
53 |
|
54 | /* Further, setup the SDRAM timing. */
|
55 | ebi_sdram_set_cas_latency(&sdram_config, 3);
|
56 | ebi_sdram_set_mode_delay(&sdram_config, EBI_MRDLY_2CLK_gc);
|
57 | ebi_sdram_set_row_cycle_delay(&sdram_config, EBI_ROWCYCDLY_7CLK_gc);
|
58 | ebi_sdram_set_row_to_precharge_delay(&sdram_config, EBI_RPDLY_7CLK_gc);
|
59 | ebi_sdram_set_write_recovery_delay(&sdram_config, EBI_WRDLY_1CLK_gc);
|
60 | ebi_sdram_set_self_refresh_to_active_delay(&sdram_config,
|
61 | EBI_ESRDLY_7CLK_gc);
|
62 | ebi_sdram_set_row_to_col_delay(&sdram_config, EBI_ROWCOLDLY_7CLK_gc);
|
63 | ebi_sdram_set_refresh_period(&sdram_config, BOARD_EBI_SDRAM_REFRESH);
|
64 | ebi_sdram_set_initialization_delay(&sdram_config,
|
65 | BOARD_EBI_SDRAM_INITDLY);
|
66 |
|
67 | /* Write SDRAM configuration into the EBI registers. */
|
68 | ebi_sdram_write_config(&sdram_config);
|
69 | /* Write the chip select configuration into the EBI registers. */
|
70 | ebi_cs_write_config(EBI_SDRAM_CS, &cs_config);
|
71 |
|
72 | ebi_enable_cs(EBI_SDRAM_CS, &cs_config);
|
73 | do {
|
74 | // Wait for SDRAM to initialize.
|
75 | } while (!ebi_sdram_is_ready());
|
76 |
|
77 | /* Debug: Enable LED1: SDRAM is ready. */
|
78 | LED_PORT.OUTCLR = OLED1;
|
79 | _delay_ms(100);
|
80 | LED_PORT.OUTSET = OLED1;
|
81 | }
|
82 | // Clear and Write SDRam
|
83 | static void ClearSDRAM(void) {
|
84 | hugemem_ptr_t n;
|
85 | for (n = BOARD_EBI_SDRAM_BASE; n < (BOARD_EBI_SDRAM_SIZE + BOARD_EBI_SDRAM_BASE);n+=4) {
|
86 | hugemem_write32(n,0);
|
87 | }
|
88 | }
|
89 | // My application specific write routine, writeptr is a global , as is the time variables 'days, hours, minutes, seconds'
|
90 | static void WriteSet(uint16_t x, uint16_t y , uint16_t z){
|
91 | uint32_t time = ((days * 16777216) + (hours * 65536) + (minutes * 256) + seconds);
|
92 | // Wrap around pointer if its beyond the RAM Range
|
93 | if (writeptr > (BOARD_EBI_SDRAM_SIZE + BOARD_EBI_SDRAM_BASE)) writeptr = BOARD_EBI_SDRAM_BASE;
|
94 | hugemem_write32(writeptr ,time);
|
95 | writeptr +=4;
|
96 | hugemem_write16(writeptr ,x);
|
97 | writeptr +=2;
|
98 | hugemem_write16(writeptr ,y);
|
99 | writeptr +=2;
|
100 | hugemem_write16(writeptr ,z);
|
101 | writeptr +=2;
|
102 | }
|