From d3ce2906171e753bed1ea5a6cd442b657cd5ae66 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 6 Dec 2023 15:42:36 -0600 Subject: [PATCH] [coco] Make tape a task. --- lib/bus/drivewire/drivewire.cpp | 7 +++- lib/device/drivewire/cassette.cpp | 53 +++++++++++++++++++++++-------- lib/device/drivewire/cassette.h | 6 ++-- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/lib/bus/drivewire/drivewire.cpp b/lib/bus/drivewire/drivewire.cpp index ae083256e..75836be9d 100755 --- a/lib/bus/drivewire/drivewire.cpp +++ b/lib/bus/drivewire/drivewire.cpp @@ -43,11 +43,12 @@ static void drivewire_intr_task(void* arg) { if ( gpio_num == PIN_CASS_MOTOR && gpio_get_level( (gpio_num_t)gpio_num) ) { - Debug_printv( "Cassette motor enalbed! Send boot loader!" ); + Debug_printv( "Cassette motor enabled. Send boot loader!" ); bus->motorActive = true; } else { + Debug_printv("Cassette motor off"); bus->motorActive = false; } } @@ -82,8 +83,12 @@ void systemBus::service() { // Handle cassette play if MOTOR pin active. if (_cassetteDev) + { if (motorActive) _cassetteDev->play(); + else + _cassetteDev->stop(); + } } // Setup DRIVEWIRE bus diff --git a/lib/device/drivewire/cassette.cpp b/lib/device/drivewire/cassette.cpp index b369a1c64..587495622 100755 --- a/lib/device/drivewire/cassette.cpp +++ b/lib/device/drivewire/cassette.cpp @@ -16,21 +16,10 @@ #define SAMPLE_DELAY_US 89 -/** - * @brief since cassette isn't a DW device, we don't handle it here. - */ -void drivewireCassette::drivewire_process(uint32_t commanddata, uint8_t checksum) -{ - // Not really used... -} - -/** - * @brief Handle when motor active, and send tape via DAC - * @note This routine stays active until tape is done streaming. - */ -void drivewireCassette::play() +static void _play(void* arg) { - casf = fsFlash.file_open("/hdbcc2.raw","r"); + drivewireCassette *cass = (drivewireCassette *)arg; + FILE *casf = fsFlash.file_open("/hdbcc2.raw","r"); if (!casf) { @@ -70,6 +59,42 @@ void drivewireCassette::play() fclose(casf); Debug_printv("Tape done."); + + // We're done, just wait to be killed. + while(1) + vTaskDelay(10/portTICK_PERIOD_MS); +} + +/** + * @brief since cassette isn't a DW device, we don't handle it here. + */ +void drivewireCassette::drivewire_process(uint32_t commanddata, uint8_t checksum) +{ + // Not really used... +} + +/** + * @brief Handle when motor active, and send tape via DAC + * @note This routine stays active until tape is done streaming. + */ +void drivewireCassette::play() +{ + stop(); + Debug_printv("Play tape"); + xTaskCreate(_play,"playTask",4096,this,10,&playTask); +} + +/** + * @brief Handle when motor inactive, stop task if needed + */ +void drivewireCassette::stop() +{ + if (playTask) + { + Debug_printv("Stop tape"); + vTaskDelete(playTask); + playTask=NULL; + } } void drivewireCassette::setup() diff --git a/lib/device/drivewire/cassette.h b/lib/device/drivewire/cassette.h index 5623662f5..454756a25 100755 --- a/lib/device/drivewire/cassette.h +++ b/lib/device/drivewire/cassette.h @@ -16,13 +16,11 @@ virtual void setup(); virtual void drivewire_process(uint32_t commanddata, uint8_t checksum); virtual void shutdown(); void play(); +void stop(); private: -/** - * @brief The file pointer used by the cassette - */ -FILE *casf = NULL; +TaskHandle_t playTask = NULL; };