Xmega Application Note


ebi_sram_example.c

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00051 #include "avr_compiler.h"
00052 #include "ebi_driver.h"
00053 
00054 /* \brief Define the testbyte to be written to the RAM. */
00055 #define TESTBYTE   0xA5
00056 
00058 #define SRAM_SIZE 0x20000UL
00059 
00065 #define MEMORY_BLOCK 1
00066 
00068 #define SRAM_ADDR (SRAM_SIZE * MEMORY_BLOCK)
00069 
00070 
00093 int main( void )
00094 {
00095         /* Counter indicating correct data transfer to and from SDRAM */
00096         uint32_t SRAM_ERR = 0;
00097 
00098         /* Configure bus pins as outputs(except for data lines). */
00099         PORTH.DIR = 0xFF;
00100         PORTK.DIR = 0xFF;
00101         PORTJ.DIR = 0x00;
00102 
00103         /* Initialize EBI. */
00104         EBI_Enable( EBI_SDDATAW_8BIT_gc,
00105                     EBI_LPCMODE_ALE1_gc,
00106                     EBI_SRMODE_ALE12_gc,
00107                     EBI_IFMODE_3PORT_gc );
00108 
00109         /* Initialize SRAM */
00110         EBI_EnableSRAM( &EBI.CS0,               /* Chip Select 0. */
00111                         EBI_CS_ASPACE_128KB_gc, /* 128 KB Address space. */
00112                         SRAM_ADDR,              /* Base address. */
00113                         0 );                    /* 0 wait states. */
00114 
00115         /* Fill SRAM with data. */
00116         for (uint32_t i = 0; i < SRAM_SIZE; i++) {
00117                 __far_mem_write(i+SRAM_ADDR, TESTBYTE);
00118         }
00119 
00120         /* Read back from SRAM and verify. */
00121         for (uint32_t i = 0; i < SRAM_SIZE; i++) {
00122                 if (__far_mem_read(i+SRAM_ADDR) != TESTBYTE){
00123                         SRAM_ERR++;
00124                 }
00125         }
00126 
00127         /* Report success or failure. */
00128         if (SRAM_ERR == 0) {
00129                 while(true) {
00130                 /* Breakpoint for success. */
00131                         nop();
00132                 }
00133         }
00134         else {
00135                 while(true) {
00136                 /* Breakpoint for failure. */
00137                         nop();
00138                 }
00139         }
00140 }
@DOC_TITLE@
Generated on Mon Jun 21 09:15:36 2010 for AVR1312 Using the XMEGA External Bus Interface by doxygen 1.5.5