forked from td0g/ArduinoHVP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_flash_read.ino
75 lines (70 loc) · 2.06 KB
/
_flash_read.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//Functions to read flash back to Serial
uint16_t flash_read(unsigned int addr) {
unsigned int _addr = addr;
//Read Flash Low and High Bytes
writeHV(addr, 0b00001100);
addr = addr >> 8;
//addr &= 0b00001111; //That blasted error again...
writeHV(addr, 0b00011100);
writeHV(0, 0b01101000);
byte low = writeHV(0, 0b01101100);
writeHV(0, 0b01111000);
unsigned int high = writeHV(0, 0b01111100);
//Return value
high = high << 8;
high |= low;
return high;
}
char flash_read_page(int length) {
writeHV(0b00000010, 0b01001100); //Load "Read Flash" Command
pmode = 3;
for (int x = 0; x < length; x += 2) {
uint16_t input = flash_read(here);
byte inputByte = input;
SERIAL.print((char) inputByte);
input = input >> 8;
SERIAL.print((char) input);
here++;
}
return STK_OK;
}
void read_page() {
char result = (char)STK_FAILED;
int length = 256 * getSerialChar();
length += getSerialChar();
char memtype = getSerialChar();
if (CRC_EOP != getSerialChar()) {
error++;
SERIAL.print((char) STK_NOSYNC);
return;
}
SERIAL.print((char) STK_INSYNC);
if (memtype == 'F') result = flash_read_page(length);
if (memtype == 'E') result = eeprom_read_page(length);
SERIAL.print(result);
}
void read_signature() {
if (!pmode) start_pmode();
if (CRC_EOP != getSerialChar()) {
error++;
SERIAL.print((char) STK_NOSYNC);
return;
}
SERIAL.print((char) STK_INSYNC);
writeHV(0b00001000,0b01001100);
writeHV(0b00000000,0b00001100);
writeHV(0b00000000,0b01101000);
uint8_t high = writeHV(0b00000000,0b01101100);
SERIAL.print((char) high);
writeHV(0b00001000,0b01001100);
writeHV(0b00000001,0b00001100);
writeHV(0b00000000,0b01101000);
uint8_t middle = writeHV(0b00000000,0b01101100);
SERIAL.print((char) middle);
writeHV(0b00001000,0b01001100);
writeHV(0b00000010,0b00001100);
writeHV(0b00000000,0b01101000);
uint8_t low = writeHV(0b00000000,0b01101100);
SERIAL.print((char) low);
SERIAL.print((char) STK_OK);
}