Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions omi/firmware/omi/omi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=y

# Set preferred connection parameters
# 7.5ms
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=24
# 15ms
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=6
# 30ms
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=24
CONFIG_BT_PERIPHERAL_PREF_LATENCY=0
# 4 seconds
Expand Down
2 changes: 1 addition & 1 deletion omi/firmware/omi/src/lib/core/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ int codec_start()
NULL,
NULL,
NULL,
K_PRIO_PREEMPT(4),
K_PRIO_PREEMPT(7),
0,
K_NO_WAIT);

Expand Down
7 changes: 1 addition & 6 deletions omi/firmware/omi/src/lib/core/sd_card.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ typedef enum {
REQ_CLEAR_AUDIO_DIR,
REQ_WRITE_DATA,
REQ_READ_DATA,
REQ_SAVE_OFFSET,
REQ_READ_OFFSET
REQ_SAVE_OFFSET
} sd_req_type_t;

/* Read request response object */
Expand Down Expand Up @@ -43,10 +42,6 @@ typedef struct {
struct {
uint32_t offset_value;
} info;
struct {
struct read_resp *resp;
uint32_t *out_offset;
} offset;
struct {
struct read_resp *resp;
} clear_dir;
Expand Down
2 changes: 1 addition & 1 deletion omi/firmware/omi/src/lib/core/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void storage_write(void)
write_to_gatt(conn);

heartbeat_count = (heartbeat_count + 1) % (MAX_HEARTBEAT_FRAMES + 1);
k_msleep(100);

transport_started = 0;
if (remaining_length == 0) {
if (stop_started) {
Expand Down
81 changes: 16 additions & 65 deletions omi/firmware/omi/src/sd_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static struct fs_file_t fil_info;
static bool is_mounted = false;
static bool sd_enabled = false;
static uint32_t current_file_size = 0;
static uint32_t current_file_offset = 0;
static size_t bytes_since_sync = 0;

// Get the device pointer for the SDHC SPI slot from the device tree
Expand Down Expand Up @@ -277,32 +278,7 @@ int save_offset(uint32_t offset)

uint32_t get_offset(void)
{
struct read_resp resp;
k_sem_init(&resp.sem, 0, 1);

uint32_t offset;
sd_req_t req = {0};
req.type = REQ_READ_OFFSET;
req.u.offset.resp = &resp;
req.u.offset.out_offset = &offset;

int ret = k_msgq_put(&sd_msgq, &req, K_MSEC(100));
if (ret != 0) {
LOG_ERR("Failed to queue get_offset request: %d", ret);
return 0;
}

// wait for sd_worker_thread to finish processing
if (k_sem_take(&resp.sem, K_MSEC(5000)) != 0) {
LOG_ERR("Timeout waiting for get_offset response");
return 0;
}

if (resp.res) {
LOG_ERR("Failed to read offset from info file: %d", resp.res);
return 0;
}
return offset;
return current_file_offset;
}

int app_sd_off(void)
Expand Down Expand Up @@ -379,13 +355,24 @@ void sd_worker_thread(void)
need_init_offset = true;
}
if (need_init_offset) {
current_file_offset = 0;
uint32_t zero_offset = 0;
ssize_t bw = fs_write(&fil_info, &zero_offset, sizeof(zero_offset));
if (bw != sizeof(zero_offset)) {
LOG_ERR("[SD_WORK] init info.txt failed to write offset 0: %d\n", (int)bw);
} else {
fs_sync(&fil_info);
}
} else {
/* Read existing offset from info.txt */
fs_seek(&fil_info, 0, FS_SEEK_SET);
ssize_t rbytes = fs_read(&fil_info, &current_file_offset, sizeof(current_file_offset));
if (rbytes != sizeof(current_file_offset)) {
LOG_ERR("[SD_WORK] Failed to read offset at boot: %d\n", (int)rbytes);
current_file_offset = 0;
} else {
LOG_INF("[SD_WORK] Loaded offset from info.txt: %u\n", current_file_offset);
}
}

fs_seek(&fil_data, 0, FS_SEEK_END);
Expand Down Expand Up @@ -508,6 +495,8 @@ void sd_worker_thread(void)
res = fs_sync(&fil_info);
if (res < 0) {
LOG_ERR("[SD_WORK] fs_sync of info file failed: %d", res);
} else {
current_file_offset = req.u.info.offset_value;
}
}
}
Expand All @@ -530,52 +519,14 @@ void sd_worker_thread(void)
return;
}
current_file_size = 0;
current_file_offset = 0;
// Return result to resp if available
if (req.u.clear_dir.resp) {
req.u.clear_dir.resp->res = 0;
k_sem_give(&req.u.clear_dir.resp->sem);
}
break;

case REQ_READ_OFFSET:
LOG_DBG("[SD_WORK] Reading offset from info file\n");
/* read offset from file info.txt (first 4 bytes) */
if (&fil_info == NULL) {
LOG_ERR("[SD_WORK] info file not open (read offset)\n");
if (req.u.offset.resp) {
req.u.offset.resp->res = -1;
k_sem_give(&req.u.offset.resp->sem);
}
break;
}

int seek_res = fs_seek(&fil_info, 0, FS_SEEK_SET);
if (seek_res < 0) {
LOG_ERR("[SD_WORK] seek info failed: %d\n", seek_res);
if (req.u.offset.resp) {
req.u.offset.resp->res = seek_res;
k_sem_give(&req.u.offset.resp->sem);
}
break;
}
uint32_t offset_val = 0;
ssize_t rbytes = fs_read(&fil_info, &offset_val, sizeof(offset_val));
if (rbytes != sizeof(offset_val)) {
LOG_ERR("[SD_WORK] read offset failed: %d\n", (int)rbytes);
if (req.u.offset.resp) {
req.u.offset.resp->res = (int)rbytes;
k_sem_give(&req.u.offset.resp->sem);
}
break;
}
if (req.u.offset.out_offset) {
*req.u.offset.out_offset = offset_val;
}
if (req.u.offset.resp) {
req.u.offset.resp->res = 0;
k_sem_give(&req.u.offset.resp->sem);
}
break;
default:
LOG_ERR("[SD_WORK] unknown req type\n");
}
Expand Down