io: Create irq names for io addresses
[simavr] / simavr / sim / avr_eeprom.h
1 /*
2         avr_eeprom.h
3
4         Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
5
6         This file is part of simavr.
7
8         simavr is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 3 of the License, or
11         (at your option) any later version.
12
13         simavr is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #ifndef __AVR_EEPROM_H__
23 #define __AVR_EEPROM_H__
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include "sim_avr.h"
30
31 typedef struct avr_eeprom_t {
32         avr_io_t        io;
33
34         uint8_t *       eeprom; // actual bytes
35         uint16_t        size;   // size for this MCU
36         
37         uint8_t r_eearh;
38         uint8_t r_eearl;
39         uint8_t r_eedr;
40
41         // eepm -- eeprom write mode
42         uint8_t r_eecr; // shortcut, assumes these bits fit in that register
43         avr_regbit_t    eepm[4];
44         avr_regbit_t    eempe;  // eeprom master program enable
45         avr_regbit_t    eepe;   // eeprom program enable
46         avr_regbit_t    eere;   // eeprom read enable
47         
48         avr_int_vector_t ready; // EERIE vector
49 } avr_eeprom_t;
50
51 void avr_eeprom_init(avr_t * avr, avr_eeprom_t * port);
52
53 typedef struct avr_eeprom_desc_t {
54         uint8_t *       ee;
55         uint16_t        offset;
56         uint32_t        size;
57 } avr_eeprom_desc_t;
58
59 #define AVR_IOCTL_EEPROM_GET    AVR_IOCTL_DEF('e','e','g','p')
60 #define AVR_IOCTL_EEPROM_SET    AVR_IOCTL_DEF('e','e','s','p')
61
62
63 /*
64  * the eeprom block seems to be very similar across AVRs, 
65  * so here is a macro to declare a "typical" one in a core.
66  */
67
68 #define AVR_EEPROM_DECLARE(_vector) \
69         .eeprom = {\
70                 .size = E2END+1,\
71                 .r_eearh = EEARH,\
72                 .r_eearl = EEARL,\
73                 .r_eedr = EEDR,\
74                 .r_eecr = EECR,\
75                 .eepm = { AVR_IO_REGBIT(EECR, EEPM0), AVR_IO_REGBIT(EECR, EEPM1) },\
76                 .eempe = AVR_IO_REGBIT(EECR, EEMPE),\
77                 .eepe = AVR_IO_REGBIT(EECR, EEPE),\
78                 .eere = AVR_IO_REGBIT(EECR, EERE),\
79                 .ready = {\
80                         .enable = AVR_IO_REGBIT(EECR, EERIE),\
81                         .vector = _vector,\
82                 },\
83         }
84
85 /*
86  * no EEPM registers in atmega128
87  */
88 #define AVR_EEPROM_DECLARE_NOEEPM(_vector)              \
89         .eeprom = {\
90                 .size = E2END+1,\
91                 .r_eearh = EEARH,\
92                 .r_eearl = EEARL,\
93                 .r_eedr = EEDR,\
94                 .r_eecr = EECR,\
95                 .eepm = { },            \
96                 .eempe = AVR_IO_REGBIT(EECR, EEMWE),\
97                 .eepe = AVR_IO_REGBIT(EECR, EEWE),\
98                 .eere = AVR_IO_REGBIT(EECR, EERE),\
99                 .ready = {\
100                         .enable = AVR_IO_REGBIT(EECR, EERIE),\
101                         .vector = _vector,\
102                 },\
103         }
104
105
106 /*
107  * macro definition without a high address bit register,
108  * which is not implemented in some tiny AVRs.
109  */
110
111 #define AVR_EEPROM_DECLARE_8BIT(_vector) \
112         .eeprom = {\
113                 .size = E2END+1,\
114                 .r_eearl = EEARL,\
115                 .r_eedr = EEDR,\
116                 .r_eecr = EECR,\
117                 .eepm = { AVR_IO_REGBIT(EECR, EEPM0), AVR_IO_REGBIT(EECR, EEPM1) },\
118                 .eempe = AVR_IO_REGBIT(EECR, EEMPE),\
119                 .eepe = AVR_IO_REGBIT(EECR, EEPE),\
120                 .eere = AVR_IO_REGBIT(EECR, EERE),\
121                 .ready = {\
122                         .enable = AVR_IO_REGBIT(EECR, EERIE),\
123                         .vector = _vector,\
124                 },\
125         }
126
127 #ifdef __cplusplus
128 };
129 #endif
130
131 #endif /* __AVR_EEPROM_H__ */