Skip to content

Commit

Permalink
Merge pull request #48 from marchingband/recover
Browse files Browse the repository at this point in the history
Recover
  • Loading branch information
marchingband authored May 4, 2022
2 parents dd1be77 + 1d647ef commit 508bc67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/bundle.h

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions src/emmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "ws_log.h"

static SemaphoreHandle_t mutex;

static const char* TAG = "emmc";

esp_err_t ret;
Expand All @@ -28,21 +31,24 @@ size_t current_block = 0;
// utility functions for other files to import
esp_err_t emmc_write(const void *source, size_t block, size_t size)
{
// log_i("write block %d",block);
xSemaphoreTake(mutex, portMAX_DELAY);
ret = sdmmc_write_sectors(&card, (const void *)source, (size_t)block, (size_t)size);
// ret = sdmmc_write_sectors(&card, (char *)source, (size_t)block, (size_t)size);
xSemaphoreGive(mutex);
return(ret);
}

esp_err_t emmc_read(void *dst, size_t start_sector, size_t sector_count)
{
xSemaphoreTake(mutex, portMAX_DELAY);
ret = sdmmc_read_sectors(&card, (void *)dst, (size_t)start_sector, (size_t)sector_count);
xSemaphoreGive(mutex);
return(ret);
}


void emmc_init(void)
{
mutex = xSemaphoreCreateMutex();
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
host.flags = SDMMC_HOST_FLAG_4BIT;
Expand Down Expand Up @@ -94,7 +100,7 @@ esp_err_t write_wav_to_emmc(char* source, size_t block, size_t size)
{
// the buffer is full, print it to the emmc and reset
// log_i("%u",current_block);
ret = sdmmc_write_sectors(&card, file_buf, current_block, 1);
ret = emmc_write(file_buf, current_block, 1);
if (ret != ESP_OK) {
log_e( "Failed to write sector %d :: (%s)", current_block, esp_err_to_name(ret));
return ESP_FAIL;
Expand All @@ -120,7 +126,7 @@ esp_err_t close_wav_to_emmc(void)
{
// write the last little bit
// log_i("%u",current_block);
ret = sdmmc_write_sectors(&card, file_buf, current_block, 1);
ret = emmc_write(file_buf, current_block, 1);
if (ret != ESP_OK) {
log_e( "Failed to write sector %d :: (%s)", current_block, esp_err_to_name(ret));
return ESP_FAIL;
Expand Down

0 comments on commit 508bc67

Please sign in to comment.