Xmega Application Note


ebi_sram_example.c File Reference


Detailed Description

XMEGA EBI driver SRAM example source.

This file contains an example application that demonstrates the EBI driver. It shows how to configure the EBI for 3-port SRAM operation. The example fills a data pattern in the memory, copies back and compares the copied block.

Application note:
AVR1312: Using the XMEGA External Bus Interface
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Revision
595
Date
2007-03-22 14:43:03 +0100 (to, 22 mar 2007)

Copyright (c) 2008, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file ebi_sram_example.c.

#include "avr_compiler.h"
#include "ebi_driver.h"

Include dependency graph for ebi_sram_example.c:

Go to the source code of this file.

Defines

#define MEMORY_BLOCK   1
 Memory block to use in the memory map.
#define SRAM_ADDR   (SRAM_SIZE * MEMORY_BLOCK)
 Address where we want SDRAM to be accessed.
#define SRAM_SIZE   0x20000UL
 Size of SDRAM to be accessed.
#define TESTBYTE   0xA5

Functions

int main (void)
 Test function for EBI with SRAM.


Define Documentation

#define MEMORY_BLOCK   1

Memory block to use in the memory map.

This depends on the size of the RAM. It can be up to (16MB/RAM_SIZE - 1). In this example the RAM size is 128KB, so the block can maximum 127.

Definition at line 65 of file ebi_sram_example.c.

#define SRAM_ADDR   (SRAM_SIZE * MEMORY_BLOCK)

Address where we want SDRAM to be accessed.

Definition at line 68 of file ebi_sram_example.c.

Referenced by main().

#define SRAM_SIZE   0x20000UL

Size of SDRAM to be accessed.

Definition at line 58 of file ebi_sram_example.c.

Referenced by main().

#define TESTBYTE   0xA5

Definition at line 55 of file ebi_sram_example.c.


Function Documentation

int main ( void   ) 

Test function for EBI with SRAM.

Hardware setup for 3-port SRAM interface:

PORTK[7:0] - A[7:0]/A[15:8]/A[23:16] (BYTE 2 and 3 connected through ALE1 and ALE2)

PORTJ[7:0] - D[7:0]

PORTH[7:0] - {CS3,CS2,CS1,CS0,ALE2,ALE1,RE,WE} (CS0 used for SRAM)

In this example a 128KB SRAM is used, which does not require any wait states at 2 MHz. Pull-up resistors should be connected to the Chip Select line to prevent garbage from being written to the SRAM during start-up, while the control lines are still in an unknown state.

This example assume the use of two address latch enable (ALE) signals to multiplex the address bytes to the SRAM.

The setup is tested by writing a set of data to the SRAM. The data is then read back and verified. At the end, the program will be stuck in one of two infinite loops, dependent on whether the test passed or not.

Definition at line 93 of file ebi_sram_example.c.

References EBI_Enable(), EBI_EnableSRAM(), SRAM_ADDR, SRAM_SIZE, and TESTBYTE.

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 }

Here is the call graph for this function:

@DOC_TITLE@
Generated on Mon Jun 21 09:15:38 2010 for AVR1312 Using the XMEGA External Bus Interface by doxygen 1.5.5