sram.c

00001 /*
00002  * $Id: sram.c,v 1.10 2004/01/30 07:09:56 troth Exp $
00003  *
00004  ****************************************************************************
00005  *
00006  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
00007  * Copyright (C) 2001, 2002, 2003, 2004  Theodore A. Roth
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  *
00023  ****************************************************************************
00024  */
00025 
00026 #include <config.h>
00027 
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 
00031 #include "avrerror.h"
00032 #include "avrmalloc.h"
00033 #include "avrclass.h"
00034 #include "utils.h"
00035 #include "callback.h"
00036 #include "op_names.h"
00037 
00038 #include "storage.h"
00039 #include "flash.h"
00040 
00041 #include "vdevs.h"
00042 #include "memory.h"
00043 #include "stack.h"
00044 #include "register.h"
00045 #include "sram.h"
00046 #include "eeprom.h"
00047 #include "timers.h"
00048 #include "ports.h"
00049 
00050 #include "avrcore.h"
00051 
00052 #include "display.h"
00053 
00054 static uint8_t sram_read (VDevice *dev, int addr);
00055 static void sram_write (VDevice *dev, int addr, uint8_t val);
00056 static void sram_reset (VDevice *dev);
00057 
00058 SRAM *
00059 sram_new (int base, int size)
00060 {
00061     SRAM *sram;
00062 
00063     sram = avr_new (SRAM, 1);
00064     sram_construct (sram, base, size);
00065     class_overload_destroy ((AvrClass *)sram, sram_destroy);
00066 
00067     return sram;
00068 }
00069 
00070 void
00071 sram_construct (SRAM *sram, int base, int size)
00072 {
00073     if (sram == NULL)
00074         avr_error ("passed null ptr");
00075 
00076     sram->stor = storage_new (base, size);
00077     vdev_construct ((VDevice *)sram, sram_read, sram_write, sram_reset,
00078                     vdev_def_AddAddr);
00079 }
00080 
00081 void
00082 sram_destroy (void *sram)
00083 {
00084     SRAM *_sram = (SRAM *)sram;
00085 
00086     if (sram == NULL)
00087         return;
00088 
00089     class_unref ((AvrClass *)_sram->stor);
00090 
00091     vdev_destroy (sram);
00092 }
00093 
00094 int
00095 sram_get_size (SRAM *sram)
00096 {
00097     return storage_get_size (sram->stor);
00098 }
00099 
00100 int
00101 sram_get_base (SRAM *sram)
00102 {
00103     return storage_get_base (sram->stor);
00104 }
00105 
00106 static uint8_t
00107 sram_read (VDevice *dev, int addr)
00108 {
00109     SRAM *sram = (SRAM *)dev;
00110 
00111     return storage_readb (sram->stor, addr);
00112 }
00113 
00114 static void
00115 sram_write (VDevice *dev, int addr, uint8_t val)
00116 {
00117     SRAM *sram = (SRAM *)dev;
00118 
00119     display_sram (addr, 1, &val);
00120 
00121     storage_writeb (sram->stor, addr, val);
00122 }
00123 
00124 static void
00125 sram_reset (VDevice *dev)
00126 {
00127     return;                     /* FIXME: should the array be cleared? */
00128 }

Automatically generated by Doxygen 1.5.2 on 3 Jan 2008.