Skip to content

Commit

Permalink
[coco] Make tape a task.
Browse files Browse the repository at this point in the history
  • Loading branch information
tschak909 committed Dec 6, 2023
1 parent 8fef9db commit d3ce290
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
7 changes: 6 additions & 1 deletion lib/bus/drivewire/drivewire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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
Expand Down
53 changes: 39 additions & 14 deletions lib/device/drivewire/cassette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 2 additions & 4 deletions lib/device/drivewire/cassette.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

};

Expand Down

0 comments on commit d3ce290

Please sign in to comment.