Main Page

- Main Page
- Related Pages
- Files

- File List
- Globals

sram.c
1 /*
2 * $Id: sram.c,v 1.10 2004/01/30 07:09:56 troth Exp $
3 *
4 ****************************************************************************
5 *
6 * simulavr - A simulator for the Atmel AVR family of microcontrollers.
7 * Copyright (C) 2001, 2002, 2003, 2004 Theodore A. Roth
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 ****************************************************************************
24 */
25
26 #include <config.h>
27
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 #include "avrerror.h"
32 #include "avrmalloc.h"
33 #include "avrclass.h"
34 #include "utils.h"
35 #include "callback.h"
36 #include "op_names.h"
37
38 #include "storage.h"
39 #include "flash.h"
40
41 #include "vdevs.h"
42 #include "memory.h"
43 #include "stack.h"
44 #include "register.h"
45 #include "sram.h"
46 #include "eeprom.h"
47 #include "timers.h"
48 #include "ports.h"
49
50 #include "avrcore.h"
51
52 #include "display.h"
53
54 static uint8_t sram_read (VDevice *dev, int addr);
55 static void sram_write (VDevice *dev, int addr, uint8_t val);
56 static void sram_reset (VDevice *dev);
57
58 SRAM *
59 sram_new (int base, int size)
60 {
61 SRAM *sram;
62
63 sram = avr_new (SRAM, 1);
64 sram_construct (sram, base, size);
65 class_overload_destroy ((AvrClass *)sram, sram_destroy);
66
67 return sram;
68 }
69
70 void
71 sram_construct (SRAM *sram, int base, int size)
72 {
73 if (sram == NULL)
74 avr_error ("passed null ptr");
75
76 sram->stor = storage_new (base, size);
77 vdev_construct ((VDevice *)sram, sram_read, sram_write, sram_reset,
78 vdev_def_AddAddr);
79 }
80
81 void
82 sram_destroy (void *sram)
83 {
84 SRAM *_sram = (SRAM *)sram;
85
86 if (sram == NULL)
87 return;
88
89 class_unref ((AvrClass *)_sram->stor);
90
91 vdev_destroy (sram);
92 }
93
94 int
95 sram_get_size (SRAM *sram)
96 {
97 return storage_get_size (sram->stor);
98 }
99
100 int
101 sram_get_base (SRAM *sram)
102 {
103 return storage_get_base (sram->stor);
104 }
105
106 static uint8_t
107 sram_read (VDevice *dev, int addr)
108 {
109 SRAM *sram = (SRAM *)dev;
110
111 return storage_readb (sram->stor, addr);
112 }
113
114 static void
115 sram_write (VDevice *dev, int addr, uint8_t val)
116 {
117 SRAM *sram = (SRAM *)dev;
118
119 display_sram (addr, 1, &val);
120
121 storage_writeb (sram->stor, addr, val);
122 }
123
124 static void
125 sram_reset (VDevice *dev)
126 {
127 return; /* FIXME: should the array be cleared? */
128 }

Automatically generated by Doxygen 1.8.2 on Mon Aug 18 2014.