Handling for Common Flash Interfafce compliant chips.
More...
#include <flash.h>
|
| CFIFlash (const SPIDevice &dev) |
|
| ~CFIFlash () |
|
void | readID (ID *id) |
| execute command 0x9f JEDEC-ID read More...
|
|
bool | writable () |
|
epicsUInt32 | alignement () |
|
epicsUInt32 | blockSize () |
|
epicsUInt32 | pageSize () |
|
epicsUInt32 | sectorSize () |
|
void | read (epicsUInt32 start, epicsUInt32 count, epicsUInt8 *in) |
|
void | read (epicsUInt32 start, std::vector< epicsUInt8 > &in) |
|
void | write (epicsUInt32 start, epicsUInt32 count, const epicsUInt8 *out, bool strict=true) |
|
void | write (epicsUInt32 start, const std::vector< epicsUInt8 > &out, bool strict=true) |
|
void | erase (epicsUInt32 start, epicsUInt32 count, bool strict=true) |
|
Handling for Common Flash Interfafce compliant chips.
Definition at line 23 of file flash.h.
◆ CFIFlash()
mrf::CFIFlash::CFIFlash |
( |
const SPIDevice & |
dev | ) |
|
|
explicit |
◆ ~CFIFlash()
mrf::CFIFlash::~CFIFlash |
( |
| ) |
|
◆ alignement()
epicsUInt32 mrf::CFIFlash::alignement |
( |
| ) |
|
|
inline |
Definition at line 50 of file flash.h.
epicsUInt32 pageSize
PAGE PROGRAM (0x02) size in bytes. Always a power of 2.
epicsUInt32 sectorSize
SECTOR ERASE (0xd8) size in bytes. Always a power of 2.
◆ blockSize()
epicsUInt32 mrf::CFIFlash::blockSize |
( |
| ) |
|
|
inline |
◆ erase()
void mrf::CFIFlash::erase |
( |
epicsUInt32 |
start, |
|
|
epicsUInt32 |
count, |
|
|
bool |
strict = true |
|
) |
| |
Definition at line 274 of file flash.cpp.
276 if((start&0xff000000) || (count&0xff000000) || ((start+count)&0xff000000))
277 std::runtime_error(
"start/count exceeds 24-bit addressing");
282 throw std::runtime_error(
"Won't attempt to write when capacity isn't known");
285 throw std::runtime_error(
"Can't write beyond capacity");
288 throw std::runtime_error(
"Won't attempt to write to unsupported flash chip");
293 throw std::runtime_error(
"start address not aligned to page & sector sizes");
295 if(strict && ((start+count)&mask))
296 throw std::runtime_error(
"end address not aligned to page & sector sizes");
299 const epicsUInt32 end = start+count;
303 WriteEnabler WE(*
this);
315 cmd[1] = (
addr>>16)&0xff;
316 cmd[2] = (
addr>> 8)&0xff;
317 cmd[3] = (
addr>> 0)&0xff;
318 SPIInterface::Operation op = {4, cmd, NULL};
321 SPIDevice::Selector S(dev);
epicsUInt32 pageSize
PAGE PROGRAM (0x02) size in bytes. Always a power of 2.
double timeout() const
timeout in seconds for an individual cycle()
virtual void cycles(size_t nops, const Operation *ops)
epicsUInt32 capacity
total capacity in bytes
epicsUInt32 sectorSize
SECTOR ERASE (0xd8) size in bytes. Always a power of 2.
SPIInterface * interface() const
◆ pageSize()
epicsUInt32 mrf::CFIFlash::pageSize |
( |
| ) |
|
|
inline |
Definition at line 53 of file flash.h.
epicsUInt32 pageSize
PAGE PROGRAM (0x02) size in bytes. Always a power of 2.
◆ read() [1/2]
void mrf::CFIFlash::read |
( |
epicsUInt32 |
start, |
|
|
epicsUInt32 |
count, |
|
|
epicsUInt8 * |
in |
|
) |
| |
Definition at line 124 of file flash.cpp.
126 if((start&0xff000000) || (count&0xff000000) || ((start+count)&0xff000000))
127 std::runtime_error(
"start/count exceeds 24-bit addressing");
136 cmd[1] = (start>>16)&0xff;
137 cmd[2] = (start>> 8)&0xff;
138 cmd[3] = (start>> 0)&0xff;
141 SPIInterface::Operation ops[2];
147 ops[1].ncycles = count;
152 SPIDevice::Selector S(dev);
virtual void cycles(size_t nops, const Operation *ops)
SPIInterface * interface() const
◆ read() [2/2]
void mrf::CFIFlash::read |
( |
epicsUInt32 |
start, |
|
|
std::vector< epicsUInt8 > & |
in |
|
) |
| |
|
inline |
Definition at line 57 of file flash.h.
58 {
read(start, in.size(), &in[0]); }
void read(epicsUInt32 start, epicsUInt32 count, epicsUInt8 *in)
◆ readID()
void mrf::CFIFlash::readID |
( |
ID * |
id | ) |
|
execute command 0x9f JEDEC-ID read
Definition at line 33 of file flash.cpp.
35 epicsUInt8 cmd[7] = {0x9f, 0u, 0u, 0u},
37 SPIInterface::Operation ops[2] = {{4, cmd, response}};
40 ops[0].out = response;
43 SPIDevice::Selector S(dev);
53 SPIDevice::Selector S(dev);
57 id->vendor = response[1];
58 id->dev_type = response[2];
59 id->dev_id = response[3];
61 id->vendorName =
"<Unknown>";
62 id->capacity =
id->sectorSize =
id->pageSize = 0u;
64 if(id->vendor==0x20) {
69 id->vendorName =
"Micron";
71 switch(id->dev_type) {
73 id->capacity = 1u<<(
id->dev_id);
74 id->sectorSize = 256*1024u;
79 id->capacity = 1u<<(
id->dev_id);
80 id->sectorSize = 64*1024u;
92 SPIDevice::Selector S(dev);
99 id->SN.resize(response[4]-2);
100 ops[1].ncycles =
id->SN.size();
102 ops[1].out = &
id->SN[0];
104 SPIDevice::Selector S(dev);
111 if((response[5]&0x3)!=0) {
120 if(id->capacity>0x1000000)
121 id->capacity = 0x1000000;
virtual void cycles(size_t nops, const Operation *ops)
SPIInterface * interface() const
◆ sectorSize()
epicsUInt32 mrf::CFIFlash::sectorSize |
( |
| ) |
|
|
inline |
Definition at line 54 of file flash.h.
epicsUInt32 sectorSize
SECTOR ERASE (0xd8) size in bytes. Always a power of 2.
◆ writable()
bool mrf::CFIFlash::writable |
( |
| ) |
|
|
inline |
Definition at line 48 of file flash.h.
epicsUInt32 pageSize
PAGE PROGRAM (0x02) size in bytes. Always a power of 2.
epicsUInt32 sectorSize
SECTOR ERASE (0xd8) size in bytes. Always a power of 2.
◆ write() [1/2]
void mrf::CFIFlash::write |
( |
epicsUInt32 |
start, |
|
|
epicsUInt32 |
count, |
|
|
const epicsUInt8 * |
out, |
|
|
bool |
strict = true |
|
) |
| |
Definition at line 157 of file flash.cpp.
162 if((start&0xff000000) || (count&0xff000000) || ((start+count)&0xff000000))
163 std::runtime_error(
"start/count exceeds 24-bit addressing");
168 throw std::runtime_error(
"Won't attempt to write when capacity isn't known");
171 throw std::runtime_error(
"Can't write beyond capacity");
174 throw std::runtime_error(
"Won't attempt to write to unsupported flash chip");
179 throw std::runtime_error(
"start address not aligned to page & sector sizes");
181 if(strict && ((start+count)&mask))
182 throw std::runtime_error(
"end address not aligned to page & sector sizes");
185 const epicsUInt32 end = start+count;
190 WriteEnabler WE(*
this);
202 cmd[1] = (
addr>>16)&0xff;
203 cmd[2] = (
addr>> 8)&0xff;
204 cmd[3] = (
addr>> 0)&0xff;
205 SPIInterface::Operation op = {4, cmd, NULL};
208 SPIDevice::Selector S(dev);
215 const epicsUInt8 *cur = data;
226 cmd[1] = (
addr>>16)&0xff;
227 cmd[2] = (
addr>> 8)&0xff;
228 cmd[3] = (
addr>> 0)&0xff;
230 SPIInterface::Operation ops[2];
240 SPIDevice::Selector S(dev);
252 std::vector<epicsUInt8> scratch;
254 const epicsUInt8 *cur = data;
264 if(memcmp(cur, &scratch[0], N)!=0) {
265 printf(
"FLASH readback mis-match in sector 0x%06x\n", (
unsigned)
addr);
271 throw std::runtime_error(
"FLASH readback error");
epicsUInt32 pageSize
PAGE PROGRAM (0x02) size in bytes. Always a power of 2.
double timeout() const
timeout in seconds for an individual cycle()
virtual void cycles(size_t nops, const Operation *ops)
epicsUInt32 capacity
total capacity in bytes
epicsUInt32 sectorSize
SECTOR ERASE (0xd8) size in bytes. Always a power of 2.
SPIInterface * interface() const
void read(epicsUInt32 start, epicsUInt32 count, epicsUInt8 *in)
◆ write() [2/2]
void mrf::CFIFlash::write |
( |
epicsUInt32 |
start, |
|
|
const std::vector< epicsUInt8 > & |
out, |
|
|
bool |
strict = true |
|
) |
| |
|
inline |
Definition at line 61 of file flash.h.
62 {
write(start, out.size(), &out[0], strict); }
void write(epicsUInt32 start, epicsUInt32 count, const epicsUInt8 *out, bool strict=true)
The documentation for this class was generated from the following files: