mirror of
https://github.com/sanni/cartreader.git
synced 2024-11-15 01:15:06 +01:00
remove duplicate code to write Flash Command
This commit is contained in:
parent
aaaa6ea3cd
commit
4d000418a8
@ -1081,6 +1081,27 @@ bool openVerifyFlashFile() {
|
|||||||
return openFileOnSD();
|
return openFileOnSD();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************
|
||||||
|
Command functions
|
||||||
|
*****************************************/
|
||||||
|
void writeByteCommand_Flash(byte command) {
|
||||||
|
writeByte_Flash(0x555, 0xaa);
|
||||||
|
writeByte_Flash(0x2aa, 0x55);
|
||||||
|
writeByte_Flash(0x555, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeByteCommandShift_Flash(byte command) {
|
||||||
|
writeByte_Flash(0x5555 << 1, 0xaa);
|
||||||
|
writeByte_Flash(0x2aaa << 1, 0x55);
|
||||||
|
writeByte_Flash(0x5555 << 1, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeWordCommand_Flash(byte command) {
|
||||||
|
writeWord_Flash(0x5555, 0xaa);
|
||||||
|
writeWord_Flash(0x2aaa, 0x55);
|
||||||
|
writeWord_Flash(0x5555, command);
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
29F032 flashrom functions
|
29F032 flashrom functions
|
||||||
*****************************************/
|
*****************************************/
|
||||||
@ -1102,9 +1123,7 @@ void idFlash29F032() {
|
|||||||
dataOut();
|
dataOut();
|
||||||
|
|
||||||
// ID command sequence
|
// ID command sequence
|
||||||
writeByte_Flash(0x555, 0xaa);
|
writeByteCommand_Flash(0x90);
|
||||||
writeByte_Flash(0x2aa, 0x55);
|
|
||||||
writeByte_Flash(0x555, 0x90);
|
|
||||||
|
|
||||||
// Set data pins to input again
|
// Set data pins to input again
|
||||||
dataIn8();
|
dataIn8();
|
||||||
@ -1120,12 +1139,8 @@ void eraseFlash29F032() {
|
|||||||
dataOut();
|
dataOut();
|
||||||
|
|
||||||
// Erase command sequence
|
// Erase command sequence
|
||||||
writeByte_Flash(0x555, 0xaa);
|
writeByteCommand_Flash(0x80);
|
||||||
writeByte_Flash(0x2aa, 0x55);
|
writeByteCommand_Flash(0x10);
|
||||||
writeByte_Flash(0x555, 0x80);
|
|
||||||
writeByte_Flash(0x555, 0xaa);
|
|
||||||
writeByte_Flash(0x2aa, 0x55);
|
|
||||||
writeByte_Flash(0x555, 0x10);
|
|
||||||
|
|
||||||
// Set data pins to input again
|
// Set data pins to input again
|
||||||
dataIn8();
|
dataIn8();
|
||||||
@ -1177,9 +1192,7 @@ void writeFlash29F032() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Write command sequence
|
// Write command sequence
|
||||||
writeByte_Flash(0x555, 0xaa);
|
writeByteCommand_Flash(0xa0);
|
||||||
writeByte_Flash(0x2aa, 0x55);
|
|
||||||
writeByte_Flash(0x555, 0xa0);
|
|
||||||
// Write current byte
|
// Write current byte
|
||||||
writeByte_Flash(currByte + c, datum);
|
writeByte_Flash(currByte + c, datum);
|
||||||
if (busyCheck29F032(currByte + c, datum)) {
|
if (busyCheck29F032(currByte + c, datum)) {
|
||||||
@ -1258,9 +1271,7 @@ void resetFlash29F1610() {
|
|||||||
dataOut();
|
dataOut();
|
||||||
|
|
||||||
// Reset command sequence
|
// Reset command sequence
|
||||||
writeByte_Flash(0x5555 << 1, 0xaa);
|
writeByteCommandShift_Flash(0xf0);
|
||||||
writeByte_Flash(0x2aaa << 1, 0x55);
|
|
||||||
writeByte_Flash(0x5555 << 1, 0xf0);
|
|
||||||
|
|
||||||
// Set data pins to input again
|
// Set data pins to input again
|
||||||
dataIn8();
|
dataIn8();
|
||||||
@ -1286,9 +1297,7 @@ void writeFlash29F1610() {
|
|||||||
busyCheck29F1610();
|
busyCheck29F1610();
|
||||||
|
|
||||||
// Write command sequence
|
// Write command sequence
|
||||||
writeByte_Flash(0x5555 << 1, 0xaa);
|
writeByteCommandShift_Flash(0xa0);
|
||||||
writeByte_Flash(0x2aaa << 1, 0x55);
|
|
||||||
writeByte_Flash(0x5555 << 1, 0xa0);
|
|
||||||
|
|
||||||
// Write one full page at a time
|
// Write one full page at a time
|
||||||
for (byte c = 0; c < 128; c++) {
|
for (byte c = 0; c < 128; c++) {
|
||||||
@ -1326,9 +1335,7 @@ void writeFlash29F1601() {
|
|||||||
busyCheck29F1610();
|
busyCheck29F1610();
|
||||||
|
|
||||||
// Write command sequence
|
// Write command sequence
|
||||||
writeByte_Flash(0x5555 << 1, 0xaa);
|
writeByteCommandShift_Flash(0xa0);
|
||||||
writeByte_Flash(0x2aaa << 1, 0x55);
|
|
||||||
writeByte_Flash(0x5555 << 1, 0xa0);
|
|
||||||
|
|
||||||
// Write one full page at a time
|
// Write one full page at a time
|
||||||
for (byte c = 0; c < 128; c++) {
|
for (byte c = 0; c < 128; c++) {
|
||||||
@ -1357,9 +1364,7 @@ void idFlash29F1610() {
|
|||||||
dataOut();
|
dataOut();
|
||||||
|
|
||||||
// ID command sequence
|
// ID command sequence
|
||||||
writeByte_Flash(0x5555 << 1, 0xaa);
|
writeByteCommandShift_Flash(0x90);
|
||||||
writeByte_Flash(0x2aaa << 1, 0x55);
|
|
||||||
writeByte_Flash(0x5555 << 1, 0x90);
|
|
||||||
|
|
||||||
// Set data pins to input again
|
// Set data pins to input again
|
||||||
dataIn8();
|
dataIn8();
|
||||||
@ -1375,9 +1380,7 @@ byte readStatusReg() {
|
|||||||
dataOut();
|
dataOut();
|
||||||
|
|
||||||
// Status reg command sequence
|
// Status reg command sequence
|
||||||
writeByte_Flash(0x5555 << 1, 0xaa);
|
writeByteCommandShift_Flash(0x70);
|
||||||
writeByte_Flash(0x2aaa << 1, 0x55);
|
|
||||||
writeByte_Flash(0x5555 << 1, 0x70);
|
|
||||||
|
|
||||||
// Set data pins to input again
|
// Set data pins to input again
|
||||||
dataIn8();
|
dataIn8();
|
||||||
@ -1392,12 +1395,8 @@ void eraseFlash29F1610() {
|
|||||||
dataOut();
|
dataOut();
|
||||||
|
|
||||||
// Erase command sequence
|
// Erase command sequence
|
||||||
writeByte_Flash(0x5555 << 1, 0xaa);
|
writeByteCommandShift_Flash(0x80);
|
||||||
writeByte_Flash(0x2aaa << 1, 0x55);
|
writeByteCommandShift_Flash(0x10);
|
||||||
writeByte_Flash(0x5555 << 1, 0x80);
|
|
||||||
writeByte_Flash(0x5555 << 1, 0xaa);
|
|
||||||
writeByte_Flash(0x2aaa << 1, 0x55);
|
|
||||||
writeByte_Flash(0x5555 << 1, 0x10);
|
|
||||||
|
|
||||||
// Set data pins to input again
|
// Set data pins to input again
|
||||||
dataIn8();
|
dataIn8();
|
||||||
@ -1536,9 +1535,7 @@ void writeFlash29F800() {
|
|||||||
|
|
||||||
for (int c = 0; c < 512; c++) {
|
for (int c = 0; c < 512; c++) {
|
||||||
// Write command sequence
|
// Write command sequence
|
||||||
writeByte_Flash(0x5555 << 1, 0xaa);
|
writeByteCommandShift_Flash(0xa0);
|
||||||
writeByte_Flash(0x2aaa << 1, 0x55);
|
|
||||||
writeByte_Flash(0x5555 << 1, 0xa0);
|
|
||||||
// Write current byte
|
// Write current byte
|
||||||
writeByte_Flash(currByte + c, sdBuffer[c]);
|
writeByte_Flash(currByte + c, sdBuffer[c]);
|
||||||
busyCheck29F032(currByte + c, sdBuffer[c]);
|
busyCheck29F032(currByte + c, sdBuffer[c]);
|
||||||
@ -1811,9 +1808,7 @@ void resetFlash16() {
|
|||||||
dataOut16();
|
dataOut16();
|
||||||
|
|
||||||
// Reset command sequence
|
// Reset command sequence
|
||||||
writeWord_Flash(0x5555, 0xaa);
|
writeWordCommand_Flash(0xf0);
|
||||||
writeWord_Flash(0x2aaa, 0x55);
|
|
||||||
writeWord_Flash(0x5555, 0xf0);
|
|
||||||
|
|
||||||
// Set data pins to input again
|
// Set data pins to input again
|
||||||
dataIn16();
|
dataIn16();
|
||||||
@ -1841,9 +1836,7 @@ void writeFlash16() {
|
|||||||
busyCheck16();
|
busyCheck16();
|
||||||
|
|
||||||
// Write command sequence
|
// Write command sequence
|
||||||
writeWord_Flash(0x5555, 0xaa);
|
writeWordCommand_Flash(0xa0);
|
||||||
writeWord_Flash(0x2aaa, 0x55);
|
|
||||||
writeWord_Flash(0x5555, 0xa0);
|
|
||||||
|
|
||||||
// Write one full page at a time
|
// Write one full page at a time
|
||||||
for (byte c = 0; c < 64; c++) {
|
for (byte c = 0; c < 64; c++) {
|
||||||
@ -1884,9 +1877,7 @@ void writeFlash16_29F1601() {
|
|||||||
busyCheck16();
|
busyCheck16();
|
||||||
|
|
||||||
// Write command sequence
|
// Write command sequence
|
||||||
writeWord_Flash(0x5555, 0xaa);
|
writeWordCommand_Flash(0xa0);
|
||||||
writeWord_Flash(0x2aaa, 0x55);
|
|
||||||
writeWord_Flash(0x5555, 0xa0);
|
|
||||||
|
|
||||||
// Write one full page at a time
|
// Write one full page at a time
|
||||||
for (byte c = 0; c < 64; c++) {
|
for (byte c = 0; c < 64; c++) {
|
||||||
@ -1918,9 +1909,7 @@ void idFlash16() {
|
|||||||
dataOut16();
|
dataOut16();
|
||||||
|
|
||||||
// ID command sequence
|
// ID command sequence
|
||||||
writeWord_Flash(0x5555, 0xaa);
|
writeWordCommand_Flash(0x90);
|
||||||
writeWord_Flash(0x2aaa, 0x55);
|
|
||||||
writeWord_Flash(0x5555, 0x90);
|
|
||||||
|
|
||||||
// Set data pins to input again
|
// Set data pins to input again
|
||||||
dataIn16();
|
dataIn16();
|
||||||
@ -1936,9 +1925,7 @@ byte readStatusReg16() {
|
|||||||
dataOut16();
|
dataOut16();
|
||||||
|
|
||||||
// Status reg command sequence
|
// Status reg command sequence
|
||||||
writeWord_Flash(0x5555, 0xaa);
|
writeWordCommand_Flash(0x70);
|
||||||
writeWord_Flash(0x2aaa, 0x55);
|
|
||||||
writeWord_Flash(0x5555, 0x70);
|
|
||||||
|
|
||||||
// Set data pins to input again
|
// Set data pins to input again
|
||||||
dataIn16();
|
dataIn16();
|
||||||
@ -1953,12 +1940,8 @@ void eraseFlash16() {
|
|||||||
dataOut16();
|
dataOut16();
|
||||||
|
|
||||||
// Erase command sequence
|
// Erase command sequence
|
||||||
writeWord_Flash(0x5555, 0xaa);
|
writeWordCommand_Flash(0x80);
|
||||||
writeWord_Flash(0x2aaa, 0x55);
|
writeWordCommand_Flash(0x10);
|
||||||
writeWord_Flash(0x5555, 0x80);
|
|
||||||
writeWord_Flash(0x5555, 0xaa);
|
|
||||||
writeWord_Flash(0x2aaa, 0x55);
|
|
||||||
writeWord_Flash(0x5555, 0x10);
|
|
||||||
|
|
||||||
// Set data pins to input again
|
// Set data pins to input again
|
||||||
dataIn16();
|
dataIn16();
|
||||||
@ -2153,9 +2136,7 @@ void writeFlash16_29LV640() {
|
|||||||
|
|
||||||
for (int c = 0; c < 256; c++) {
|
for (int c = 0; c < 256; c++) {
|
||||||
// Write command sequence
|
// Write command sequence
|
||||||
writeWord_Flash(0x5555, 0xaa);
|
writeWordCommand_Flash(0xa0);
|
||||||
writeWord_Flash(0x2aaa, 0x55);
|
|
||||||
writeWord_Flash(0x5555, 0xa0);
|
|
||||||
|
|
||||||
// Write current word
|
// Write current word
|
||||||
word myWord = ((sdBuffer[d + 1] & 0xFF) << 8) | (sdBuffer[d] & 0xFF);
|
word myWord = ((sdBuffer[d + 1] & 0xFF) << 8) | (sdBuffer[d] & 0xFF);
|
||||||
|
Loading…
Reference in New Issue
Block a user