dffaeaf796139c9bace24b24b7f71298dd94e0e9
[simavr] / simavr / sim / avr_flash.h
1 /*
2         avr_flash.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
23 #ifndef __AVR_FLASH_H___
24 #define __AVR_FLASH_H___
25
26 #include "sim_avr.h"
27
28 /*
29  * Handles self-programming subsystem if the core
30  * supports it.
31  */
32 typedef struct avr_flash_t {
33         avr_io_t        io;
34
35         uint16_t        spm_pagesize;
36         uint8_t r_spm;
37         avr_regbit_t selfprgen;
38         avr_regbit_t pgers;             // page erase
39         avr_regbit_t pgwrt;             // page write
40         avr_regbit_t blbset;    // lock bit set
41
42         avr_int_vector_t flash; // Interrupt vector
43 } avr_flash_t;
44
45 void avr_flash_init(avr_t * avr, avr_flash_t * p);
46
47
48 #define AVR_IOCTL_FLASH_SPM             AVR_IOCTL_DEF('f','s','p','m')
49
50 #define AVR_SELFPROG_DECLARE(_spmr, _spen, _vector) \
51         .selfprog = {\
52                 .r_spm = _spmr,\
53                 .spm_pagesize = SPM_PAGESIZE,\
54                 .selfprgen = AVR_IO_REGBIT(_spmr, _spen),\
55                 .pgers = AVR_IO_REGBIT(_spmr, PGERS),\
56                 .pgwrt = AVR_IO_REGBIT(_spmr, PGWRT),\
57                 .blbset = AVR_IO_REGBIT(_spmr, BLBSET),\
58                 .flash = {\
59                         .enable = AVR_IO_REGBIT(_spmr, SPMIE),\
60                         .vector = _vector,\
61                 },\
62         }
63
64 #endif /* __AVR_FLASH_H___ */