Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# sramsw.c

Go to the documentation of this file.

    00001 /*! \file sramsw.c \brief Software-driven SRAM memory bus access functions. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'sramsw.c'
    00005 // Title        : Software-driven SRAM memory bus access functions
    00006 // Author       : Pascal Stang - Copyright (C) 2002
    00007 // Created      : 11/11/2002
    00008 // Revised      : 11/13/2002
    00009 // Version      : 1.0
    00010 // Target MCU   : Atmel AVR series
    00011 // Editor Tabs  : 4
    00012 //
    00013 // This code is distributed under the GNU Public License
    00014 //      which can be found at http://www.gnu.org/licenses/gpl.txt
    00015 //
    00016 //*****************************************************************************
    00017
    00018 #include <avr/io.h>
    00019 #include <avr/interrupt.h>
    00020
    00021 #include "global.h"
    00022 #include "sramsw.h"
    00023
    00024 // global variables
    00025
    00026 // functions
    00027 void sramswInit(void)
    00028 {
    00029     // initialize port state
    00030     outb(SRAM_ADL, 0xFF);       // addr/data port set to 0xFF (pull-ups enabled)
    00031     outb(SRAM_AH, 0x00);        // high addr port set to 0x00
    00032     // initialize port directions
    00033     outb(SRAM_ADL_DDR, 0x00);   // addr/data port set to input
    00034     outb(SRAM_AH_DDR, 0xFF);    // high addr port set to output
    00035     // initialize control line states
    00036     sbi(SRAM_CTRL, SRAM_WR);    // de-assert write (active low)
    00037     sbi(SRAM_CTRL, SRAM_RD);    // de-assert read (active low)
    00038     cbi(SRAM_CTRL, SRAM_ALE);   // de-assert ALE (active high)
    00039     // set control line direction
    00040     sbi(SRAM_CTRL_DDR, SRAM_WR);
    00041     sbi(SRAM_CTRL_DDR, SRAM_RD);
    00042     sbi(SRAM_CTRL_DDR, SRAM_ALE);
    00043     // set page lines direction
    00044     outb(SRAM_PAGE_DDR, inb(SRAM_PAGE_DDR) | SRAM_PAGE_MASK );
    00045     // initialize page
    00046     sramswSetPage(0);
    00047 }
    00048
    00049 void sramswOff(void)
    00050 {
    00051 }
    00052
    00053 void sramswWrite(u32 addr, u08 data)
    00054 {
    00055     // set page
    00056     sramswSetPage( (addr & 0x00FF0000)>>16 );
    00057     // set high-order address
    00058     outb(SRAM_AH, (addr & 0x0000FF00)>>8 );
    00059     // set low-order address
    00060     outb(SRAM_ADL, addr & 0x000000FF);
    00061     // apply low-order address to latch
    00062     outb(SRAM_ADL_DDR, 0xFF);
    00063     // clock latch to save low-order address
    00064     sbi(SRAM_CTRL, SRAM_ALE);   // assert ALE (active high)
    00065     asm volatile ("nop");
    00066     cbi(SRAM_CTRL, SRAM_ALE);   // de-assert ALE (active high)
    00067
    00068     // apply data to memory
    00069     outb(SRAM_ADL, data);
    00070     // clock write line to store data
    00071     cbi(SRAM_CTRL, SRAM_WR);    // assert write (active low)
    00072     asm volatile ("nop");
    00073     sbi(SRAM_CTRL, SRAM_WR);    // de-assert write (active low)
    00074 }
    00075
    00076 u08 sramswRead(u32 addr)
    00077 {
    00078     u08 data;
    00079
    00080     // set page
    00081     sramswSetPage( (addr & 0x00FF0000)>>16 );
    00082     // set high-order address
    00083     outb(SRAM_AH, (addr & 0x0000FF00)>>8 );
    00084     // set low-order address
    00085     outb(SRAM_ADL, addr & 0x000000FF);
    00086     // apply low-order address to latch
    00087     outb(SRAM_ADL_DDR, 0xFF);
    00088     // clock latch to save low-order address
    00089     sbi(SRAM_CTRL, SRAM_ALE);   // assert ALE (active high)
    00090     asm volatile ("nop");
    00091     cbi(SRAM_CTRL, SRAM_ALE);   // de-assert ALE (active high)
    00092
    00093     // switch data bus to input
    00094     outb(SRAM_ADL_DDR, 0x00);
    00095     // clear pullups
    00096     outb(SRAM_ADL, 0x00);
    00097     // request data from memory
    00098     cbi(SRAM_CTRL, SRAM_RD);    // assert read (active low)
    00099     // retrieve data
    00100     asm volatile ("nop");
    00101     data = inb(SRAM_ADL_IN);
    00102     // release read line
    00103     sbi(SRAM_CTRL, SRAM_RD);    // de-assert read (active low)
    00104     // switch data bus to output
    00105     outb(SRAM_ADL_DDR, 0xFF);
    00106
    00107     return data;
    00108 }
    00109
    00110 void sramswSetPage(u08 page)
    00111 {
    00112     outb(SRAM_PAGE, (page & SRAM_PAGE_MASK));
    00113 }