1 // at29.h - A specialisation of the generic flash memory class to
2 // model the ATMEL 29xxx series of flash memory. -*- C++ -*-
4 // Copyright (C) 1999, 2000 Red Hat.
5 // This file is part of SID and is licensed under the GPL.
6 // See the file COPYING.SID for conditions for redistribution.
8 // The ATMEL flash has a data security mechanism that prevents
9 // unexpected data modification due to transient address/data lines in
10 // the physical realm. To write to a given sector, a special sequence
11 // of address writes must first take place.
13 // More details on this component can be found on ATMEL's web site
14 // (http://www.atmel.com/) in various data sheets.
23 #include <sidattrutil.h>
34 using sid::host_int_1;
35 using sid::host_int_4;
36 using sid::little_int_1;
37 using sid::little_int_2;
38 using sid::little_int_4;
39 using sid::little_int_8;
45 using sidutil::make_attribute;
46 using sidutil::parse_attribute;
50 struct at29_flash_memory_type
53 host_int_4 memory_size;
54 host_int_4 sector_size;
60 class at29_flash_memory;
62 class at29_bus: public bus
65 at29_bus(at29_flash_memory* target): target(target) {}
67 bus::status write(host_int_4 address, big_int_1 data) throw ();
68 bus::status write(host_int_4 address, little_int_1 data) throw ();
69 bus::status read(host_int_4 address, big_int_1& data) throw ();
70 bus::status read(host_int_4 address, little_int_1& data) throw ();
72 #define NOPERM_WRITE(type) \
73 bus::status write(host_int_4 address, type data) throw () \
74 { return bus::unpermitted; }
76 #define NOPERM_READ(type) \
77 bus::status read(host_int_4 address, type& data) throw () \
78 { return bus::unpermitted; }
80 NOPERM_WRITE(big_int_2);
81 NOPERM_WRITE(little_int_2);
82 NOPERM_WRITE(big_int_4);
83 NOPERM_WRITE(little_int_4);
84 NOPERM_WRITE(big_int_8);
85 NOPERM_WRITE(little_int_8);
87 NOPERM_READ(big_int_2);
88 NOPERM_READ(little_int_2);
89 NOPERM_READ(big_int_4);
90 NOPERM_READ(little_int_4);
91 NOPERM_READ(big_int_8);
92 NOPERM_READ(little_int_8);
98 at29_flash_memory* target;
103 class at29_flash_memory: public flash_uniform_sector_memory
107 at29_flash_memory(size_t memory_size, size_t sector_size,
108 host_int_1 device_id) throw (bad_alloc);
109 static const at29_flash_memory_type types[];
112 void stream_state (ostream&) const;
113 void destream_state (istream&);
116 friend class at29_bus;
119 bool write_ok(host_int_4 address);
129 const host_int_4 noSectorNum;
130 host_int_4 sectorNum;
131 host_int_1 manufacturerCode;
132 host_int_1 deviceIdCode;