SimAVR
AVR Simulator
avr_flash.h
Go to the documentation of this file.
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 it under the terms of the GNU
9  * General Public License as published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * simavr is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
13  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with simavr. If not, see
17  * <http://www.gnu.org/licenses/>.
18 */
19 
25 #ifndef __AVR_FLASH_H___
26 #define __AVR_FLASH_H___
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 #include "sim_avr.h"
34 
38  typedef struct avr_flash_t
39  {
41 
42  uint16_t flags;
43  uint16_t *tmppage;
44  uint8_t *tmppage_used;
45  uint16_t spm_pagesize;
46  uint8_t r_spm;
53 
55  } avr_flash_t;
56 
58 #define AVR_SELFPROG_HAVE_RWW (1 << 0)
59 
60  void avr_flash_init (avr_t * avr, avr_flash_t * p);
61 
62 #define AVR_IOCTL_FLASH_SPM AVR_IOCTL_DEF('f','s','p','m')
63 
64 #define AVR_SELFPROG_DECLARE_INTERNAL(_spmr, _spen, _vector) \
65  .r_spm = _spmr, \
66  .spm_pagesize = SPM_PAGESIZE, \
67  .selfprgen = AVR_IO_REGBIT(_spmr, _spen), \
68  .pgers = AVR_IO_REGBIT(_spmr, PGERS), \
69  .pgwrt = AVR_IO_REGBIT(_spmr, PGWRT), \
70  .blbset = AVR_IO_REGBIT(_spmr, BLBSET), \
71  .flash = { \
72  .enable = AVR_IO_REGBIT(_spmr, SPMIE), \
73  .vector = _vector, \
74  } \
75 
76 #define AVR_SELFPROG_DECLARE_NORWW(_spmr, _spen, _vector) \
77  .selfprog = { \
78  .flags = 0, \
79  AVR_SELFPROG_DECLARE_INTERNAL(_spmr, _spen, _vector), \
80  }
81 
82 #define AVR_SELFPROG_DECLARE(_spmr, _spen, _vector) \
83  .selfprog = { \
84  .flags = AVR_SELFPROG_HAVE_RWW, \
85  AVR_SELFPROG_DECLARE_INTERNAL(_spmr, _spen, _vector), \
86  .rwwsre = AVR_IO_REGBIT(_spmr, RWWSRE), \
87  .rwwsb = AVR_IO_REGBIT(_spmr, RWWSB), \
88  }
89 
90 #ifdef __cplusplus
91 };
92 #endif
93 
94 #endif /* __AVR_FLASH_H___ */
95 
uint8_t * tmppage_used
Definition: avr_flash.h:44
avr_io_t io
Definition: avr_flash.h:40
Handles self-programming subsystem if the core supports it.
Definition: avr_flash.h:38
uint16_t flags
Definition: avr_flash.h:42
avr_t * avr
Definition: run_avr.c:54
avr_regbit_t blbset
lock bit set
Definition: avr_flash.h:50
uint8_t r_spm
Definition: avr_flash.h:46
void avr_flash_init(avr_t *avr, avr_flash_t *p)
Definition: avr_flash.c:147
interrupt vector for the IO modules
Definition: sim_interrupts.h:37
This 'structure' is a packed representation of an IO register 'bit' (or consecutive bits)...
Definition: sim_avr_types.h:47
struct avr_flash_t avr_flash_t
Handles self-programming subsystem if the core supports it.
avr_regbit_t pgers
page erase
Definition: avr_flash.h:48
avr_int_vector_t flash
Interrupt vector.
Definition: avr_flash.h:54
avr_regbit_t selfprgen
Definition: avr_flash.h:47
uint16_t spm_pagesize
Definition: avr_flash.h:45
avr_regbit_t pgwrt
page write
Definition: avr_flash.h:49
avr_regbit_t rwwsb
read while write section busy
Definition: avr_flash.h:52
uint16_t * tmppage
Definition: avr_flash.h:43
Main AVR instance.
Definition: sim_avr.h:142
IO module base struct Modules uses that as their first member in their own struct.
Definition: sim_io.h:42
avr_regbit_t rwwsre
read while write section read enable
Definition: avr_flash.h:51