mirror of
https://github.com/sanni/cartreader.git
synced 2024-11-13 08:25:05 +01:00
V30E: Moved disabling interrupts out of the loop when reading/writing N64 eeproms
Hopefully this was the reason it sometimes froze at that point.
This commit is contained in:
parent
fa63471333
commit
76ae5c5408
@ -2,8 +2,8 @@
|
|||||||
Cartridge Reader for Arduino Mega2560
|
Cartridge Reader for Arduino Mega2560
|
||||||
|
|
||||||
Author: sanni
|
Author: sanni
|
||||||
Date: 2017-11-21
|
Date: 2017-11-22
|
||||||
Version: V30D
|
Version: V30E
|
||||||
|
|
||||||
SD lib: https://github.com/greiman/SdFat
|
SD lib: https://github.com/greiman/SdFat
|
||||||
LCD lib: https://github.com/adafruit/Adafruit_SSD1306
|
LCD lib: https://github.com/adafruit/Adafruit_SSD1306
|
||||||
@ -35,7 +35,7 @@
|
|||||||
infinest - help with GB Memory cart
|
infinest - help with GB Memory cart
|
||||||
|
|
||||||
**********************************************************************************/
|
**********************************************************************************/
|
||||||
char ver[5] = "V30D";
|
char ver[5] = "V30E";
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
Define Starting Point
|
Define Starting Point
|
||||||
@ -457,6 +457,8 @@ void setup() {
|
|||||||
Serial.println(F("Cartridge Reader"));
|
Serial.println(F("Cartridge Reader"));
|
||||||
Serial.println(F("2017 sanni"));
|
Serial.println(F("2017 sanni"));
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
|
// LED
|
||||||
|
rgb.setColor(0, 0, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init SD card
|
// Init SD card
|
||||||
@ -616,6 +618,8 @@ void println_Msg(long unsigned int message) {
|
|||||||
void display_Update() {
|
void display_Update() {
|
||||||
if (enable_OLED)
|
if (enable_OLED)
|
||||||
display.display();
|
display.display();
|
||||||
|
if (enable_Serial)
|
||||||
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_Clear() {
|
void display_Clear() {
|
||||||
@ -641,43 +645,44 @@ void wait_serial() {
|
|||||||
while (Serial.available() == 0) {
|
while (Serial.available() == 0) {
|
||||||
}
|
}
|
||||||
incomingByte = Serial.read() - 48;
|
incomingByte = Serial.read() - 48;
|
||||||
|
/* if ((incomingByte == 53) && (fileName[0] != '\0')) {
|
||||||
if (incomingByte == 53) {
|
|
||||||
// Open file on sd card
|
// Open file on sd card
|
||||||
sd.chdir(folder);
|
sd.chdir(folder);
|
||||||
if (myFile.open(fileName, O_READ)) {
|
if (myFile.open(fileName, O_READ)) {
|
||||||
// Get rom size from file
|
// Get rom size from file
|
||||||
fileSize = myFile.fileSize();
|
fileSize = myFile.fileSize();
|
||||||
|
|
||||||
|
// Send filesize
|
||||||
|
char tempStr[16];
|
||||||
|
sprintf(tempStr, "%d", fileSize);
|
||||||
|
Serial.write(tempStr);
|
||||||
|
|
||||||
|
// Wait for ok
|
||||||
|
while (Serial.available() == 0) {
|
||||||
|
}
|
||||||
|
|
||||||
// Send file
|
// Send file
|
||||||
for (unsigned long currByte = 0; currByte < fileSize; currByte += 512) {
|
for (unsigned long currByte = 0; currByte < fileSize; currByte++) {
|
||||||
myFile.read(sdBuffer, 512);
|
|
||||||
// Blink led
|
// Blink led
|
||||||
if (currByte % 2048 == 0)
|
if (currByte % 1024 == 0)
|
||||||
PORTB ^= (1 << 4);
|
PORTB ^= (1 << 4);
|
||||||
|
Serial.write(myFile.read());
|
||||||
for (int c = 0; c < 512; c++) {
|
|
||||||
Serial.write(sdBuffer[c]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Close the file:
|
// Close the file:
|
||||||
myFile.close();
|
myFile.close();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print_Error(F("Can't open file"), true);
|
print_Error(F("Can't open file"), true);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
Serial.println("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte questionBox_Serial(const char* question, char answers[7][20], int num_answers, int default_choice) {
|
byte questionBox_Serial(const char* question, char answers[7][20], int num_answers, int default_choice) {
|
||||||
// Print menu to serial monitor
|
// Print menu to serial monitor
|
||||||
if (enable_Serial && filebrowse) {
|
if (filebrowse) {
|
||||||
Serial.print("Filebrowser: ");
|
Serial.print("Filebrowser: ");
|
||||||
}
|
}
|
||||||
Serial.print(question);
|
Serial.println(question);
|
||||||
Serial.println(F(" Menu"));
|
|
||||||
for (byte i = 0; i < num_answers; i++) {
|
for (byte i = 0; i < num_answers; i++) {
|
||||||
Serial.print(i);
|
Serial.print(i);
|
||||||
Serial.print(F(")"));
|
Serial.print(F(")"));
|
||||||
@ -686,14 +691,14 @@ byte questionBox_Serial(const char* question, char answers[7][20], int num_answe
|
|||||||
// Wait for user input
|
// Wait for user input
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
Serial.println(F("Please browse pages with 'u'(up) and 'd'(down)"));
|
Serial.println(F("Please browse pages with 'u'(up) and 'd'(down)"));
|
||||||
Serial.print(F("and enter a selection by typing a number(0-6): _ "));
|
Serial.println(F("and enter a selection by typing a number(0-6): _ "));
|
||||||
while (Serial.available() == 0) {
|
while (Serial.available() == 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the incoming byte:
|
// Read the incoming byte:
|
||||||
incomingByte = Serial.read() - 48;
|
incomingByte = Serial.read() - 48;
|
||||||
|
|
||||||
// Import file (i)
|
/* Import file (i)
|
||||||
if (incomingByte == 57) {
|
if (incomingByte == 57) {
|
||||||
if (filebrowse == 1) {
|
if (filebrowse == 1) {
|
||||||
// Make sure we have an import directory
|
// Make sure we have an import directory
|
||||||
@ -728,7 +733,7 @@ byte questionBox_Serial(const char* question, char answers[7][20], int num_answe
|
|||||||
println_Msg(fileName);
|
println_Msg(fileName);
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Page up (u)
|
// Page up (u)
|
||||||
if (incomingByte == 69) {
|
if (incomingByte == 69) {
|
||||||
|
@ -303,7 +303,7 @@ void setup_N64_Cart() {
|
|||||||
DDRH |= (1 << 0) | (1 << 5) | (1 << 6);
|
DDRH |= (1 << 0) | (1 << 5) | (1 << 6);
|
||||||
DDRC |= (1 << 0) | (1 << 1);
|
DDRC |= (1 << 0) | (1 << 1);
|
||||||
// Pull RESET(PH0) low until we are ready
|
// Pull RESET(PH0) low until we are ready
|
||||||
//PORTH &= ~(1 << 0);
|
PORTH &= ~(1 << 0);
|
||||||
// Output a high signal on WR(PH5) RD(PH6), pins are active low therefore everything is disabled now
|
// Output a high signal on WR(PH5) RD(PH6), pins are active low therefore everything is disabled now
|
||||||
PORTH |= (1 << 5) | (1 << 6);
|
PORTH |= (1 << 5) | (1 << 6);
|
||||||
// Pull aleL(PC0) low and aleH(PC1) high
|
// Pull aleL(PC0) low and aleH(PC1) high
|
||||||
@ -326,9 +326,8 @@ void setup_N64_Cart() {
|
|||||||
// Wait until all is stable
|
// Wait until all is stable
|
||||||
delay(300);
|
delay(300);
|
||||||
|
|
||||||
// Pull RESET(PH0) high
|
// Pull RESET(PH0) high to start eeprom
|
||||||
//PORTH |= (1 << 0);
|
PORTH |= (1 << 0);
|
||||||
//delay(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
@ -1338,11 +1337,10 @@ void writeEeprom() {
|
|||||||
|
|
||||||
for (byte i = 0; i < (eepPages / 64); i++) {
|
for (byte i = 0; i < (eepPages / 64); i++) {
|
||||||
myFile.read(sdBuffer, 512);
|
myFile.read(sdBuffer, 512);
|
||||||
|
|
||||||
for (byte pageNumber = 0; pageNumber < 64; pageNumber++) {
|
|
||||||
// Disable interrupts for more uniform clock pulses
|
// Disable interrupts for more uniform clock pulses
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
|
|
||||||
|
for (byte pageNumber = 0; pageNumber < 64; pageNumber++) {
|
||||||
// Wait ~50ms between page writes or eeprom will have write errors
|
// Wait ~50ms between page writes or eeprom will have write errors
|
||||||
pulseClock_N64(26000);
|
pulseClock_N64(26000);
|
||||||
|
|
||||||
@ -1355,10 +1353,10 @@ void writeEeprom() {
|
|||||||
sendData(sdBuffer[(pageNumber * 8) + j]);
|
sendData(sdBuffer[(pageNumber * 8) + j]);
|
||||||
}
|
}
|
||||||
sendStop();
|
sendStop();
|
||||||
|
}
|
||||||
interrupts();
|
interrupts();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Close the file:
|
// Close the file:
|
||||||
myFile.close();
|
myFile.close();
|
||||||
println_Msg(F("Done"));
|
println_Msg(F("Done"));
|
||||||
@ -1400,10 +1398,10 @@ void readEeprom() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (byte i = 0; i < (eepPages / 64); i++) {
|
for (byte i = 0; i < (eepPages / 64); i++) {
|
||||||
for (byte pageNumber = 0; pageNumber < 64; pageNumber++) {
|
|
||||||
// Disable interrupts for more uniform clock pulses
|
// Disable interrupts for more uniform clock pulses
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
|
|
||||||
|
for (byte pageNumber = 0; pageNumber < 64; pageNumber++) {
|
||||||
// Send read command
|
// Send read command
|
||||||
sendData(0x04);
|
sendData(0x04);
|
||||||
// Send Page number
|
// Send Page number
|
||||||
@ -1415,8 +1413,6 @@ void readEeprom() {
|
|||||||
readData();
|
readData();
|
||||||
sendStop();
|
sendStop();
|
||||||
|
|
||||||
interrupts();
|
|
||||||
|
|
||||||
// OR 8 bits into one byte for a total of 8 bytes
|
// OR 8 bits into one byte for a total of 8 bytes
|
||||||
for (byte j = 0; j < 64; j += 8) {
|
for (byte j = 0; j < 64; j += 8) {
|
||||||
sdBuffer[(pageNumber * 8) + (j / 8)] = tempBits[0 + j] << 7 | tempBits[1 + j] << 6 | tempBits[2 + j] << 5 | tempBits[3 + j] << 4 | tempBits[4 + j] << 3 | tempBits[5 + j] << 2 | tempBits[6 + j] << 1 | tempBits[7 + j];
|
sdBuffer[(pageNumber * 8) + (j / 8)] = tempBits[0 + j] << 7 | tempBits[1 + j] << 6 | tempBits[2 + j] << 5 | tempBits[3 + j] << 4 | tempBits[4 + j] << 3 | tempBits[5 + j] << 2 | tempBits[6 + j] << 1 | tempBits[7 + j];
|
||||||
@ -1424,6 +1420,7 @@ void readEeprom() {
|
|||||||
// Wait ~0.6ms between pages or eeprom will lock up
|
// Wait ~0.6ms between pages or eeprom will lock up
|
||||||
pulseClock_N64(300);
|
pulseClock_N64(300);
|
||||||
}
|
}
|
||||||
|
interrupts();
|
||||||
|
|
||||||
// Write 64 pages at once to the SD card
|
// Write 64 pages at once to the SD card
|
||||||
myFile.write(sdBuffer, 512);
|
myFile.write(sdBuffer, 512);
|
||||||
@ -1458,10 +1455,10 @@ unsigned long verifyEeprom() {
|
|||||||
if (myFile.open(filePath, O_READ)) {
|
if (myFile.open(filePath, O_READ)) {
|
||||||
|
|
||||||
for (byte i = 0; i < (eepPages / 64); i++) {
|
for (byte i = 0; i < (eepPages / 64); i++) {
|
||||||
for (byte pageNumber = 0; pageNumber < 64; pageNumber++) {
|
|
||||||
// Disable interrupts for more uniform clock pulses
|
// Disable interrupts for more uniform clock pulses
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
|
|
||||||
|
for (byte pageNumber = 0; pageNumber < 64; pageNumber++) {
|
||||||
// Send read command
|
// Send read command
|
||||||
sendData(0x04);
|
sendData(0x04);
|
||||||
// Send Page number
|
// Send Page number
|
||||||
@ -1473,7 +1470,7 @@ unsigned long verifyEeprom() {
|
|||||||
readData();
|
readData();
|
||||||
sendStop();
|
sendStop();
|
||||||
|
|
||||||
interrupts();
|
|
||||||
|
|
||||||
// OR 8 bits into one byte for a total of 8 bytes
|
// OR 8 bits into one byte for a total of 8 bytes
|
||||||
for (byte j = 0; j < 64; j += 8) {
|
for (byte j = 0; j < 64; j += 8) {
|
||||||
@ -1482,6 +1479,7 @@ unsigned long verifyEeprom() {
|
|||||||
// Wait ~0.6ms between pages or eeprom will lock up
|
// Wait ~0.6ms between pages or eeprom will lock up
|
||||||
pulseClock_N64(300);
|
pulseClock_N64(300);
|
||||||
}
|
}
|
||||||
|
interrupts();
|
||||||
|
|
||||||
// Check sdBuffer content against file on sd card
|
// Check sdBuffer content against file on sd card
|
||||||
for (int c = 0; c < 512; c++) {
|
for (int c = 0; c < 512; c++) {
|
||||||
@ -1987,7 +1985,7 @@ void readRom_N64() {
|
|||||||
foldern = foldern + 1;
|
foldern = foldern + 1;
|
||||||
EEPROM_writeAnything(10, foldern);
|
EEPROM_writeAnything(10, foldern);
|
||||||
|
|
||||||
readn64rom:
|
//readn64rom:
|
||||||
// Open file on sd card
|
// Open file on sd card
|
||||||
if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
|
if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
|
||||||
print_Error(F("SD Error"), true);
|
print_Error(F("SD Error"), true);
|
||||||
@ -2016,7 +2014,7 @@ readn64rom:
|
|||||||
// Close the file:
|
// Close the file:
|
||||||
myFile.close();
|
myFile.close();
|
||||||
|
|
||||||
calcn64crc:
|
/*calcn64crc:
|
||||||
// Calculate Checksum and convert to string
|
// Calculate Checksum and convert to string
|
||||||
println_Msg(F("Calculating CRC.."));
|
println_Msg(F("Calculating CRC.."));
|
||||||
display_Update();
|
display_Update();
|
||||||
@ -2089,7 +2087,12 @@ calcn64crc:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
display_Update();*/
|
||||||
|
println_Msg(F("Done."));
|
||||||
|
println_Msg(F(""));
|
||||||
|
println_Msg(F("Press Button..."));
|
||||||
display_Update();
|
display_Update();
|
||||||
|
wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user