Main Page
Main Page
Related Pages
Files
storage.c00001 /*
00002 * $Id: storage.c,v 1.8 2003/12/02 08:25:00 troth Exp $
00003 *
00004 ****************************************************************************
00005 *
00006 * simulavr - A simulator for the Atmel AVR family of microcontrollers.
00007 * Copyright (C) 2001, 2002, 2003 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 "storage.h"
00035
00036 /***************************************************************************\
00037 *
00038 * Storage(AvrClass) Methods
00039 *
00040 \***************************************************************************/
00041
00042 Storage *
00043 storage_new (int base, int size)
00044 {
00045 Storage *stor;
00046
00047 stor = avr_new (Storage, 1);
00048 storage_construct (stor, base, size);
00049 class_overload_destroy ((AvrClass *)stor, storage_destroy);
00050
00051 return stor;
00052 }
00053
00054 void
00055 storage_construct (Storage *stor, int base, int size)
00056 {
00057 if (stor == NULL)
00058 avr_error ("passed null ptr");
00059
00060 class_construct ((AvrClass *)stor);
00061
00062 stor->base = base; /* address */
00063 stor->size = size; /* bytes */
00064
00065 stor->data = avr_new0 (uint8_t, size);
00066 }
00067
00068 /*
00069 * Not to be called directly, except by a derived class.
00070 * Called via class_unref.
00071 */
00072 void
00073 storage_destroy (void *stor)
00074 {
00075 if (stor == NULL)
00076 return;
00077
00078 avr_free (((Storage *)stor)->data);
00079 class_destroy (stor);
00080 }
00081
00082 extern inline uint8_t
00083 storage_readb (Storage *stor, int addr);
00084
00085 extern inline uint16_t
00086 storage_readw (Storage *stor, int addr);
00087
00088 void
00089 storage_writeb (Storage *stor, int addr, uint8_t val)
00090 {
00091 int _addr = addr - stor->base;
00092
00093 if (stor == NULL)
00094 avr_error ("passed null ptr");
00095
00096 if ((_addr < 0) || (_addr >= stor->size))
00097 avr_error ("address out of bounds: 0x%x", addr);
00098
00099 stor->data[_addr] = val;
00100 }
00101
00102 void
00103 storage_writew (Storage *stor, int addr, uint16_t val)
00104 {
00105 int _addr = addr - stor->base;
00106
00107 if (stor == NULL)
00108 avr_error ("passed null ptr");
00109
00110 if ((_addr < 0) || (_addr >= stor->size))
00111 avr_error ("address out of bounds: 0x%x", addr);
00112
00113 stor->data[_addr] = (uint8_t) (val >> 8 & 0xff);
00114 stor->data[_addr + 1] = (uint8_t) (val & 0xff);
00115 }
00116
00117 int
00118 storage_get_size (Storage *stor)
00119 {
00120 return stor->size;
00121 }
00122
00123 int
00124 storage_get_base (Storage *stor)
00125 {
00126 return stor->base;
00127 }
Automatically generated by Doxygen 1.5.5 on 7 Nov 2008.
Wyszukiwarka
Podobne podstrony:
source30Matrix3?pp sourceThread?pp sourcearm biquad ?scade ?1 ?st q31? sourcearm conv ?2? sourcearm mat mult q15? sourceNyx Password Storage 1 21 readmeResource 8inl sourcearm fir lattice init q31? sourcearm fir ?cimate ?st q15? sourcesource11arm correlate ?st q15? sourceconnector?s sourcesource8register? sourceCabinet storage towerwięcej podobnych podstron