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 
00061 #define SRAM_ADDR 0x4000
00062 
00063 
00065 #define SRAM(addr) ((uint8_t *) SRAM_ADDR)[addr]
00066 
00068 #define VECTOR_SIZE 1000
00069 
00070 
00090 int main( void )
00091 {
00092         /* Flag indicating correct data transfer to and from SRAM */
00093         bool equal = true;
00094 
00095         /* Set signals which are active-low to high value */
00096         PORTH.OUT = 0xFF;
00097 
00098         /* Configure bus pins as outputs(except for data lines). */
00099         PORTH.DIR = 0xFF;
00100         PORTK.DIR = 0xFF;
00101 
00102         /* Initialize EBI. */
00103         EBI_Enable( EBI_SDDATAW_8BIT_gc,
00104                     EBI_LPCMODE_ALE1_gc,
00105                     EBI_SRMODE_ALE12_gc,
00106                     EBI_IFMODE_3PORT_gc );
00107 
00108         /* Initialize SRAM */
00109         EBI_EnableSRAM( &EBI.CS0,               /* Chip Select 0. */
00110                         EBI_CS_ASPACE_128KB_gc, /* 128 KB Address space. */
00111                         (void *) SRAM_ADDR,     /* Base address. */
00112                         0 );                    /* 0 wait states. */
00113 
00114         /* Fill SRAM with data. */
00115         for (uint16_t i = 0; i < VECTOR_SIZE; i++) {
00116                 SRAM(i) =  (uint8_t) i & 0xFF;
00117         }
00118 
00119         /* Read back from SRAM and verify */
00120         for (uint16_t i = 0; i < VECTOR_SIZE; i++) {
00121                 if (SRAM(i) != ((uint8_t) i & 0xFF)){
00122                         equal = false;
00123                         break;
00124                 }
00125         }
00126 
00127         /* Report success or failure. */
00128 
00129         if (equal) {
00130                 while(true) {
00131                 /* Breakpoint for success. */
00132                         nop();
00133                 }
00134         }
00135         else {
00136                 while(true) {
00137                 /* Breakpoint for failure. */
00138                         nop();
00139                 }
00140         }
00141 }
@DOC_TITLE@
Generated on Wed Apr 23 08:16:46 2008 for AVR1312 Using the XMEGA External Bus Interface by doxygen 1.5.5