arch_avr_nvm.h Source File

yasimavr: arch_avr_nvm.h Source File
yasimavr
Loading...
Searching...
No Matches
arch_avr_nvm.h
Go to the documentation of this file.
1/*
2 * arch_avr_nvm.h
3 *
4 * Copyright 2024-2026 Clement Savergne <csavergne@yahoo.com>
5
6 This file is part of yasim-avr.
7
8 yasim-avr 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 yasim-avr 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 yasim-avr. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22//=======================================================================================
23
24#ifndef __YASIMAVR_AVR_NVM_H__
25#define __YASIMAVR_AVR_NVM_H__
26
27#include "core/sim_types.h"
28#include "core/sim_peripheral.h"
29#include "core/sim_interrupt.h"
30#include "core/sim_memory.h"
31#include "arch_avr_globals.h"
32
34
35
36//=======================================================================================
37
75
76
88
89public:
90
91 explicit ArchAVR_NVM(const ArchAVR_NVMConfig& config);
92 virtual ~ArchAVR_NVM();
93
94 virtual bool init(Device& device) override;
95 virtual void reset(int flags) override;
96 virtual bool ctlreq(ctlreq_id_t req, ctlreq_data_t* data) override;
97 virtual void ioreg_write_handler(reg_addr_t addr, const ioreg_write_t& data) override;
98 virtual bool interrupt_ack_handler(int_vect_t vector) override;
99
100private:
101
102 class SPM_Timer;
103 friend class SPM_Timer;
104
105 class EE_Timer;
106 friend class EE_Timer;
107
108 enum State {
109 State_Idle = 0,
110 State_Pending,
111 State_Read,
112 State_Write,
113 };
114
115 enum SPM_Command {
116 SPM_BufferLoad = 0x00,
117 SPM_PageErase = 0x01,
118 SPM_PageWrite = 0x02,
119 SPM_LockBits = 0x04,
120 SPM_RWWEnable = 0x08,
121 SPM_SigRead = 0x10,
122 };
123
124 enum EEPROM_Mode {
125 EE_ModeEraseWrite = 0,
126 EE_ModeErase,
127 EE_ModeWrite,
128 EE_ModeRead
129 };
130
131 const ArchAVR_NVMConfig& m_config;
132
133 uint8_t* m_spm_buffer;
134 uint8_t* m_spm_bufset;
135 flash_addr_t m_spm_page_size;
136 State m_spm_state;
137 int m_spm_command;
138 SPM_Timer* m_spm_timer;
139 bool m_halt;
140
141 State m_ee_state;
142 uint8_t m_ee_prog_mode;
143 EE_Timer* m_ee_timer;
144
145 MemorySectionManager* m_section_manager;
146
147 NonVolatileMemory* get_nvm(int nvm_index);
148 void clear_spm_buffer();
149 int process_NVM_read(NVM_request_t& req);
150 int process_NVM_write(NVM_request_t& req);
151 void spm_timer_next();
152 void start_eeprom_command(uint8_t command);
153 void ee_timer_next();
154
155};
156
157
158//=======================================================================================
159
171#define AVR_CTLREQ_FUSE_VALUE (AVR_CTLREQ_BASE + 1)
172
174
175
200
208
209public:
210
211 enum Fuses {
213 };
214
215 explicit ArchAVR_Fuses(const ArchAVR_FusesConfig& config);
216
217 virtual bool init(Device& device) override;
218 virtual bool ctlreq(ctlreq_id_t req, ctlreq_data_t* data) override;
219 virtual void reset(int flags) override;
220
221private:
222
223 const ArchAVR_FusesConfig& m_config;
224
225 NonVolatileMemory* m_fuses;
226 NonVolatileMemory* m_lockbit;
227 MemorySectionManager* m_sections;
228
229 void configure_sections();
230 uint8_t read_fuse(const regmask_t& rm) const;
231
232};
233
234
236
237#endif //__YASIMAVR_XT_NVM_H__
#define AVR_ARCHAVR_PUBLIC_API
Definition arch_avr_globals.h:46
Implementation of a fuse NVM peripheral for AVR series.
Definition arch_avr_nvm.h:207
Fuses
Definition arch_avr_nvm.h:211
@ Fuse_BootRst
Definition arch_avr_nvm.h:212
Definition arch_avr_nvm.cpp:52
Definition arch_avr_nvm.cpp:33
Implementation of a NVM controller for AVR series.
Definition arch_avr_nvm.h:87
Basic AVR device model.
Definition sim_device.h:61
Abstract interface to a interrupt controller.
Definition sim_interrupt.h:221
virtual bool interrupt_ack_handler(int_vect_t vector)=0
Memory section management.
Definition sim_memory.h:124
Non-volatile memory model.
Definition sim_memory.h:42
Abstract class defining a framework for MCU peripherals.
Definition sim_peripheral.h:286
virtual bool init(Device &device)
Definition sim_peripheral.cpp:60
virtual bool ctlreq(ctlreq_id_t req, ctlreq_data_t *data)
Definition sim_peripheral.cpp:79
virtual void ioreg_write_handler(reg_addr_t addr, const ioreg_write_t &data) override
Definition sim_peripheral.cpp:117
virtual void reset(int flags)
Definition sim_peripheral.cpp:72
bit spec structure. Represent a field in a I/O register. It works the same as bitmask_t except used b...
Definition sim_types.h:287
Representation of a I/O register address, with validity state.
Definition sim_types.h:60
Definition sim_types.h:431
Represents a field in a I/O register with address.
Definition sim_types.h:348
int ctlreq_id_t
Definition sim_peripheral.h:111
#define YASIMAVR_BEGIN_NAMESPACE
Definition sim_globals.h:58
#define YASIMAVR_END_NAMESPACE
Definition sim_globals.h:59
unsigned long flash_addr_t
Definition sim_types.h:42
short int_vect_t
Definition sim_types.h:43
Definition arch_avr_nvm.h:181
unsigned long boot_size
Definition arch_avr_nvm.h:182
Configuration structure for ArchAVR_Fuses.
Definition arch_avr_nvm.h:179
bitspec_t bs_applockbit
Regbit for the application part of the lockbits.
Definition arch_avr_nvm.h:192
regbit_t rb_bootsz
Regbit for the boot size fuse bits.
Definition arch_avr_nvm.h:186
bitspec_t bs_bootlockbit
Regbit for the boot part of the lockbits.
Definition arch_avr_nvm.h:190
regbit_t rb_bootrst
Regbit for the boot reset fuse bit.
Definition arch_avr_nvm.h:188
std::vector< bootsize_config_t > boot_sizes
Boot_sizes mapping, in number of section pages.
Definition arch_avr_nvm.h:197
flash_addr_t nrww_start
Start of NRWW (No Read-While-Write) section, in number of section pages.
Definition arch_avr_nvm.h:195
Configuration structure for ArchAVR_NVM.
Definition arch_avr_nvm.h:41
regbit_t rb_ee_read
Definition arch_avr_nvm.h:51
regbit_compound_t rbc_ee_addr
Definition arch_avr_nvm.h:49
regbit_t rb_ee_write
Definition arch_avr_nvm.h:52
bitspec_t bs_spm_rww_busy
Definition arch_avr_nvm.h:47
unsigned int ee_write_delay
EEPROM Write delay in usecs.
Definition arch_avr_nvm.h:62
regbit_t rb_ee_wren
Definition arch_avr_nvm.h:53
unsigned int ee_erase_write_delay
EEPROM Erase/Write delay in usecs.
Definition arch_avr_nvm.h:66
int_vect_t iv_spm_ready
Interrupt vector for SPM.
Definition arch_avr_nvm.h:68
uint32_t dev_id
Device ID.
Definition arch_avr_nvm.h:72
unsigned int spm_erase_delay
Flash/EEPROM page erase operation delay in usecs.
Definition arch_avr_nvm.h:60
bitspec_t bs_spm_inten
Definition arch_avr_nvm.h:46
reg_addr_t reg_spm_ctrl
Definition arch_avr_nvm.h:43
bitspec_t bs_spm_cmd
Definition arch_avr_nvm.h:44
regbit_t rb_ee_inten
Definition arch_avr_nvm.h:54
unsigned int ee_erase_delay
EEPROM Erase delay in usecs.
Definition arch_avr_nvm.h:64
int_vect_t iv_ee_ready
Interrupt vector index for EEREADY.
Definition arch_avr_nvm.h:70
bitspec_t bs_spm_enable
Definition arch_avr_nvm.h:45
reg_addr_t reg_ee_data
Definition arch_avr_nvm.h:50
regbit_t rb_ee_mode
Definition arch_avr_nvm.h:55
unsigned int spm_write_delay
Flash/EEPROM page write operation delay in usecs.
Definition arch_avr_nvm.h:58
Structure used for AVR_CTLREQ_NVM_REQUEST requests.
Definition sim_peripheral.h:220
Definition sim_peripheral.h:252
Definition sim_peripheral.h:237
Definition sim_ioreg.h:39
Address + bit mask structure.
Definition sim_types.h:156