~ubuntu-branches/ubuntu/dapper/simulavr/dapper

« back to all changes in this revision

Viewing changes to src/storage.h

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2004-04-10 13:54:17 UTC
  • Revision ID: james.westby@ubuntu.com-20040410135417-zywapjyz252y65se
Tags: upstream-0.1.2.1
ImportĀ upstreamĀ versionĀ 0.1.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: storage.h,v 1.6 2003/12/02 08:25:00 troth Exp $
 
3
 *
 
4
 ****************************************************************************
 
5
 *
 
6
 * simulavr - A simulator for the Atmel AVR family of microcontrollers.
 
7
 * Copyright (C) 2001, 2002, 2003  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
#ifndef SIM_STORAGE_H
 
27
#define SIM_STORAGE_H
 
28
 
 
29
/***************************************************************************\
 
30
 *
 
31
 * Storage(AvrClass) Object
 
32
 *
 
33
\***************************************************************************/
 
34
 
 
35
typedef struct _Storage Storage;
 
36
 
 
37
struct _Storage
 
38
{
 
39
    AvrClass parent;
 
40
    int base;                   /* address */
 
41
    int size;                   /* bytes */
 
42
    uint8_t *data;
 
43
};
 
44
 
 
45
extern Storage *storage_new (int base, int size);
 
46
extern void storage_construct (Storage *stor, int base, int size);
 
47
extern void storage_destroy (void *stor);
 
48
 
 
49
extern inline uint8_t
 
50
storage_readb (Storage *stor, int addr)
 
51
{
 
52
    int _addr = addr - stor->base;
 
53
 
 
54
    if (stor == NULL)
 
55
        avr_error ("passed null ptr");
 
56
 
 
57
    if ((_addr < 0) || (_addr >= stor->size))
 
58
        avr_error ("address out of bounds: 0x%x", addr);
 
59
 
 
60
    return stor->data[_addr];
 
61
}
 
62
 
 
63
extern inline uint16_t
 
64
storage_readw (Storage *stor, int addr)
 
65
{
 
66
    int _addr = addr - stor->base;
 
67
    uint8_t bl, bh;
 
68
 
 
69
    if (stor == NULL)
 
70
        avr_error ("passed null ptr");
 
71
 
 
72
    if ((_addr < 0) || (_addr >= stor->size))
 
73
        avr_error ("address out of bounds: 0x%x", addr);
 
74
 
 
75
    bh = stor->data[_addr];
 
76
    bl = stor->data[_addr + 1];
 
77
 
 
78
    return (uint16_t) ((bh << 8) | bl);
 
79
}
 
80
 
 
81
extern void storage_writeb (Storage *stor, int addr, uint8_t val);
 
82
extern void storage_writew (Storage *stor, int addr, uint16_t val);
 
83
 
 
84
extern int storage_get_size (Storage *stor);
 
85
extern int storage_get_base (Storage *stor);
 
86
 
 
87
#endif /* SIM_STORAGE_H */