From 7852ff37c24f87ffcbdd2e31e379929413fa7b8a Mon Sep 17 00:00:00 2001 From: nino-porcino Date: Mon, 28 Mar 2022 19:26:30 +0200 Subject: [PATCH] sd card command MOUNT, SD OS v1.1 --- demos/sdcard/apple1_sdcard/apple1_sdcard.ino | 38 +++++++++++--------- demos/sdcard/cmd_mount.h | 8 +++++ demos/sdcard/console.h | 10 ++++-- 3 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 demos/sdcard/cmd_mount.h diff --git a/demos/sdcard/apple1_sdcard/apple1_sdcard.ino b/demos/sdcard/apple1_sdcard/apple1_sdcard.ino index bed1740..eff5433 100644 --- a/demos/sdcard/apple1_sdcard/apple1_sdcard.ino +++ b/demos/sdcard/apple1_sdcard/apple1_sdcard.ino @@ -36,6 +36,7 @@ in Verilog syntax: data = { PORTB[1:0], PORTD[7:2] }; */ +// FASTWRITE not working (yet) // #define FASTWRITE 1 #ifdef FASTWRITE @@ -46,9 +47,6 @@ in Verilog syntax: data = { PORTB[1:0], PORTD[7:2] }; #define set_mcu_strobe(c) digitalWrite(MCU_STROBE,(c)) #endif - -// #include - #include #include "SdFat.h" @@ -218,6 +216,7 @@ const byte CMD_MKDIR = 14; const byte CMD_PWD = 19; const byte CMD_RMDIR = 15; const byte CMD_TEST = 20; +const byte CMD_MOUNT = 21; const byte ERR_RESPONSE = 255; const byte WAIT_RESPONSE = 1; @@ -244,6 +243,8 @@ const char *CANT_MAKE_DIR = "?CAN'T MAKE DIR"; const char *DIR_CREATED = " (DIR) CREATED"; const char *CANT_CD_DIR = "?CAN'T CHANGE DIR"; const char *NOT_A_DIRECTORY = "?NOT A DIRECTORY"; +const char *MOUNT_OK = "MOUNTING SDCARD...\rOK"; +const char *MOUNT_FAILED = "?SD CARD ERROR"; // file structures used to operate with the SD card File myFile; @@ -254,9 +255,7 @@ void setup() { Serial.begin(9600); Serial.println(F("SDCARD library: SDFat.h")); - // initialize SD card - if (!SD.begin(SD_CS_PIN)) Serial.println(F("SD card initialization failed")); - else Serial.println(F("SD card initialized")); + mount_sdcard(); // control pins setup pinMode(CPU_STROBE, INPUT); @@ -267,21 +266,21 @@ void setup() { last_dir = -1; // no previous data direction set_data_port_direction(DIR_INPUT); - /* - // regex disabled for now - MatchState ms; - char buf [100] = { "The quick " }; - ms.Target (buf); - char result = ms.Match ("f.x"); - if(result >0) { - Serial.println("match!"); - } - */ - // set working directory to root strcpy(cd_path, "/"); } +bool mount_sdcard() { + // initialize SD card + if(!SD.begin(SD_CS_PIN)) { + Serial.println(F("SD card initialization failed")); + return false; + } + else { + Serial.println(F("SD card initialized")); + return true; + } +} // ************************************************************************************** // ************************************************************************************** @@ -1067,6 +1066,11 @@ void loop() { send_byte_to_cpu(data ^ 0xFF); } } + else if(data == CMD_MOUNT) { + bool mount = mount_sdcard(); + if(mount) send_string_to_cpu(MOUNT_OK); + else send_string_to_cpu(MOUNT_FAILED); + } else { Serial.print(F("unknown command ")); Serial.print(data); diff --git a/demos/sdcard/cmd_mount.h b/demos/sdcard/cmd_mount.h new file mode 100644 index 0000000..44ac9bf --- /dev/null +++ b/demos/sdcard/cmd_mount.h @@ -0,0 +1,8 @@ +void comando_mount() { + // send command byte + send_byte_to_MCU(CMD_MOUNT); + if(TIMEOUT) return; + + print_string_response(); + return; +} diff --git a/demos/sdcard/console.h b/demos/sdcard/console.h index e19975c..def8959 100644 --- a/demos/sdcard/console.h +++ b/demos/sdcard/console.h @@ -43,7 +43,8 @@ const byte CMD_PWD = 19; const byte CMD_TEST = 20; const byte CMD_HELP = 21; const byte CMD_QMARK = 22; -const byte CMD_EXIT = 23; +const byte CMD_MOUNT = 23; +const byte CMD_EXIT = 24; // the list of recognized commands byte *DOS_COMMANDS[] = { @@ -70,6 +71,7 @@ byte *DOS_COMMANDS[] = { "TEST", "HELP", "?", + "MOUNT", "EXIT" }; @@ -177,12 +179,13 @@ void append_hex_tmpword(char *dest) { #include "cmd_pwd.h" #include "cmd_test.h" #include "cmd_help.h" +#include "cmd_mount.h" void console() { VIA_init(); - woz_puts("\r\r*** SD CARD OS 1.0\r\r"); + woz_puts("\r\r*** SD CARD OS 1.1\r\r"); cmd = 0; @@ -406,6 +409,9 @@ void console() { get_token(filename, 32); // parse filename comando_help(); } + else if(cmd == CMD_MOUNT) { + comando_mount(); + } else if(cmd == CMD_EXIT) { woz_puts("BYE\r"); woz_mon();