sdram.c

Go to the documentation of this file.
00001 /* ************************************************************************
00002 
00003 Copyright (c) 2006, Atmel Corporation All rights reserved. 
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007 
00008 1. Redistributions of source code must retain the above copyright notice,
00009 this list of conditions and the 
00010 following disclaimer. 
00011 
00012 2. Redistributions in binary form must reproduce the above copyright notice,
00013 this list of conditions and the following disclaimer in the documentation
00014 and/or other materials provided with the distribution.
00015 
00016 3. The name of ATMEL may not be used to endorse or promote products 
00017 derived from this software without specific prior written permission.  
00018 
00019 THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS 
00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00021 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
00022 PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY 
00023 DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00024 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00025 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00026 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00027 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00028 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
00029 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 
00030 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00031 
00032 POSSIBILITY OF SUCH DAMAGE. 
00033 
00034 ************************************************************************ */
00035 
00036 #include "sdram.h"
00037 
00038 #define MODE_NORMAL     0
00039 #define MODE_NOP        1
00040 #define MODE_PRECHARGE      2
00041 #define MODE_LOAD_MR        3
00042 #define MODE_AUTOREFRESH    4
00043 #define MODE_EXT_LOAD_MR    5
00044 #define MODE_POWER_DOWN     6
00045 
00046 static void sdram_delay(int us)
00047 {
00048   int i, loop_limit;
00049 
00050   loop_limit = us * 20;
00051 
00052   for (i=0; i<loop_limit;i++);
00053 
00054 }
00055 
00056 void sdramc_init(const sdram_info *info)
00057 {
00058 
00059   volatile avr32_sdramc_t *hsdramc = &AVR32_SDRAMC;
00060   volatile avr32_hmatrix_t *hmatrix = &AVR32_HMATRIX;
00061   volatile avr32_pio_t *pio = &AVR32_PIOE;
00062 
00063   // Enable SDRAM mode for CS1 in the BAMBI mux 
00064   hmatrix->sfr[4] |= 0x0002;
00065   hmatrix->sfr[4] |= 0x0100;
00066 
00067   // Initialize data bus bits 31-16 (muxed with the LCDC).
00068   pio->asr |= 0x0000FFFF;
00069   pio->pdr |= 0x0000FFFF;
00070   
00071   // Setup SDRAM info
00072   hsdramc->cr = ( (info->cols-8) << AVR32_SDRAMC_CR_NC ) |
00073     ( (info->rows-11) << AVR32_SDRAMC_CR_NR ) |
00074     ( (info->banks-1) << AVR32_SDRAMC_CR_NB ) |
00075     ( info->cas << AVR32_SDRAMC_CR_CAS ) |
00076     ( info->twr << AVR32_SDRAMC_CR_TWR ) |
00077     ( info->trc << AVR32_SDRAMC_CR_TRC ) |
00078     ( info->trp << AVR32_SDRAMC_CR_TRP ) |
00079     ( info->trcd << AVR32_SDRAMC_CR_TRCD ) |
00080     ( info->tras << AVR32_SDRAMC_CR_TRAS ) |
00081     ( info->txsr << AVR32_SDRAMC_CR_TXSR );
00082 
00083   sdram_delay(200);
00084 
00085 }

Generated on Thu May 10 13:52:44 2007 for AVR32102 - Using the AVR32 SDRAM controller by  doxygen 1.5.1