Main Page | File List | Globals | Related Pages

sram.c

00001 /* 00002 * $Id: sram.c,v 1.9 2003/12/01 09:10:16 troth Exp $ 00003 * 00004 **************************************************************************** 00005 * 00006 * simulavr - A simulator for the Atmel AVR family of microcontrollers. 00007 * Copyright (C) 2001, 2002 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 static char *sram_name (VDevice *dev, int addr); 00058 00059 SRAM * 00060 sram_new (int base, int size) 00061 { 00062 SRAM *sram; 00063 00064 sram = avr_new (SRAM, 1); 00065 sram_construct (sram, base, size); 00066 class_overload_destroy ((AvrClass *)sram, sram_destroy); 00067 00068 return sram; 00069 } 00070 00071 void 00072 sram_construct (SRAM *sram, int base, int size) 00073 { 00074 char *name = "SRAM"; 00075 00076 if (sram == NULL) 00077 avr_error ("passed null ptr"); 00078 00079 sram->stor = storage_new (base, size); 00080 vdev_construct ((VDevice *)sram, name, base, size, sram_read, sram_write, 00081 sram_reset, sram_name); 00082 } 00083 00084 void 00085 sram_destroy (void *sram) 00086 { 00087 SRAM *_sram = (SRAM *)sram; 00088 00089 if (sram == NULL) 00090 return; 00091 00092 class_unref ((AvrClass *)_sram->stor); 00093 00094 vdev_destroy (sram); 00095 } 00096 00097 int 00098 sram_get_size (SRAM *sram) 00099 { 00100 return storage_get_size (sram->stor); 00101 } 00102 00103 int 00104 sram_get_base (SRAM *sram) 00105 { 00106 return storage_get_base (sram->stor); 00107 } 00108 00109 static uint8_t 00110 sram_read (VDevice *dev, int addr) 00111 { 00112 SRAM *sram = (SRAM *)dev; 00113 00114 return storage_readb (sram->stor, addr); 00115 } 00116 00117 static void 00118 sram_write (VDevice *dev, int addr, uint8_t val) 00119 { 00120 SRAM *sram = (SRAM *)dev; 00121 00122 display_sram (addr, 1, &val); 00123 00124 storage_writeb (sram->stor, addr, val); 00125 } 00126 00127 static void 00128 sram_reset (VDevice *dev) 00129 { 00130 return; /* FIXME: should the array be cleared? */ 00131 } 00132 00133 static char * 00134 sram_name (VDevice *dev, int addr) 00135 { 00136 return NULL; 00137 }

Automatically generated by Doxygen 1.3.8 on 11 Aug 2004.