Skip to content
Draft
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
8 changes: 8 additions & 0 deletions include/openearable_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ struct sensor_config {
uint8_t storageOptions;
} __attribute__((packed));

struct seal_check_data {
uint8_t version;
uint8_t quality;
uint8_t mean_magnitude;
uint8_t num_peaks;
uint16_t frequencies[9]; // 12.4 fixed point
uint16_t magnitudes[9];
} __attribute__((packed));

struct battery_settings {
float u_nominal;
Expand Down
9 changes: 9 additions & 0 deletions prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ CONFIG_SFLOAT=y

CONFIG_FPU=y

CONFIG_CMSIS_DSP=y
CONFIG_CMSIS_DSP_TRANSFORM=y
CONFIG_CMSIS_DSP_COMPLEXMATH=y

CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_NEWLIB_LIBC_FLOAT_SCANF=y
Expand Down Expand Up @@ -182,6 +186,11 @@ CONFIG_FS_FATFS_EXFAT=y # Enable exFAT support

CONFIG_FDSP=y

# CMSIS-DSP Configuration
CONFIG_CMSIS_DSP=y
CONFIG_CMSIS_DSP_TRANSFORM=y
CONFIG_CMSIS_DSP_COMPLEXMATH=y

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096

#CONFIG_USB_MASS_STORAGE=y
Expand Down
4 changes: 4 additions & 0 deletions prj_fota.conf
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,7 @@ CONFIG_MCUMGR_GRP_OS_RESET_HOOK=y
#CONFIG_MCUMGR_GRP_SETTINGS_ACCESS_HOOK=y

CONFIG_SETUP_FUEL_GAUGE=y

CONFIG_CMSIS_DSP=y
CONFIG_CMSIS_DSP_TRANSFORM=y
CONFIG_CMSIS_DSP_COMPLEXMATH=y
8 changes: 0 additions & 8 deletions src/Battery/BQ25120a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,8 @@ uint8_t BQ25120a::write_LDO_voltage_control(float volt) {

readReg(registers::LS_LDO_CTRL, &status, sizeof(status));

//status |= (((uint16_t)((volt - 0.8) * 10)) & 0x1F) << 2;
status &= 1 << 7;
status |= ((uint8_t)((volt - 0.8f) * 10 + EPS)) << 2;
//status |= 1 << 7;

writeReg(registers::LS_LDO_CTRL, &status, sizeof(status));

Expand Down Expand Up @@ -292,8 +290,6 @@ chrg_state BQ25120a::read_termination_control() {

struct chrg_state chrg;

// if (!ret) printk("failed to read\n");

chrg.enabled = status & 0x2;
//chrg.high_impedance = status & 0x1;

Expand Down Expand Up @@ -343,8 +339,6 @@ ilim_uvlo BQ25120a::read_uvlo_ilim() {

bool ret = readReg(registers::ILIM_UVLO, (uint8_t *) &status, sizeof(status));

// if (!ret) printk("failed to read\n");

param.uvlo_v = CLAMP(3.0f- 0.2f * ((status & 0x7) - 2), 2.2, 3.0);
param.lim_mA = 50.f + 50.f * ((status >> 3) & 0x7);

Expand Down Expand Up @@ -410,8 +404,6 @@ button_state BQ25120a::read_button_state() {
uint8_t status = 0;
bool ret = readReg(registers::BTN_CTRL, (uint8_t *) &status, sizeof(status));

// if (!ret) printk("failed to read\n");

btn.wake_1 = status & 0x2;
btn.wake_2 = status & 0x1;

Expand Down
24 changes: 2 additions & 22 deletions src/Battery/PowerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ int PowerManager::power_down(bool fault) {
ret = pm_device_action_run(ls_sd, PM_DEVICE_ACTION_SUSPEND);
ret = pm_device_action_run(ls_3_3, PM_DEVICE_ACTION_SUSPEND);
ret = pm_device_action_run(ls_1_8, PM_DEVICE_ACTION_SUSPEND);
ret = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
ret = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);

/*const struct device *const i2c = DEVICE_DT_GET(DT_NODELABEL(i2c1));
ret = pm_device_action_run(i2c, PM_DEVICE_ACTION_SUSPEND);
Expand Down Expand Up @@ -666,27 +666,7 @@ void PowerManager::charge_task() {
battery_controller.enable_charge();
}

//if (last_charging_state != charging_state || ) {
k_work_submit(&fuel_gauge_work);
//state_inidicator.set_state()
/*switch (charging_state) {
case 0:
LOG_INF("charging state: ready");
break;
case 1:
LOG_INF("charging state: charging");
break;
case 2:
LOG_INF("charging state: done");
break;
case 3:
LOG_WRN("charging state: fault");

//battery_controller.setup(_battery_settings);

break;
}*/
//}
k_work_submit(&fuel_gauge_work);

last_charging_state = charging_state;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ParseInfo/DefaultSensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ SensorScheme defaultSensors[SENSOR_COUNT] = {
.availableOptions = DATA_STORAGE | FREQUENCIES_DEFINED, // no streaming
.frequencyOptions = {
.frequencyCount = sizeof(Microphone::sample_rates.reg_vals),
.defaultFrequencyIndex = 1,
.maxBleFrequencyIndex = 1,
.defaultFrequencyIndex = 0,
.maxBleFrequencyIndex = 0,
.frequencies = Microphone::sample_rates.sample_rates,
},
},
Expand All @@ -159,7 +159,7 @@ SensorScheme defaultSensors[SENSOR_COUNT] = {
.availableOptions = DATA_STREAMING | DATA_STORAGE | FREQUENCIES_DEFINED,
.frequencyOptions = {
.frequencyCount = sizeof(PPG::sample_rates.reg_vals),
.defaultFrequencyIndex = 2,
.defaultFrequencyIndex = 1,
.maxBleFrequencyIndex = 12,
.frequencies = PPG::sample_rates.sample_rates,
},
Expand Down
2 changes: 1 addition & 1 deletion src/ParseInfo/ParseType.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum ParseType {
PARSE_TYPE_DOUBLE,
};

const int parseTypeSizes[] = {
static const int parseTypeSizes[] = {
1, // PARSE_TYPE_INT8
1, // PARSE_TYPE_UINT8

Expand Down
14 changes: 9 additions & 5 deletions src/SD_Card/SDLogger/SDLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ void sd_listener_callback(const struct zbus_channel *chan)
}
}

inline void reset_logger_signal() {
k_poll_signal_reset(&logger_sig);
logger_evt.state = K_POLL_STATE_NOT_READY;
}

void SDLogger::sensor_sd_task() {
int ret;
Expand All @@ -112,7 +116,7 @@ void SDLogger::sensor_sd_task() {

// If a close/flush is in progress, do not write concurrently.
if (atomic_get(&g_stop_writing)) {
k_poll_signal_reset(&logger_sig);
reset_logger_signal();
continue;
}

Expand All @@ -122,7 +126,7 @@ void SDLogger::sensor_sd_task() {
ring_buf_reset(&ring_buffer);
k_mutex_unlock(&ring_mutex);
sdlogger.is_open = false;
k_poll_signal_reset(&logger_sig);
reset_logger_signal();
continue;
}

Expand All @@ -148,7 +152,7 @@ void SDLogger::sensor_sd_task() {

if (claimed == 0 || data == nullptr) {
// Nothing to write right now.
k_poll_signal_reset(&logger_sig);
reset_logger_signal();
continue;
}

Expand All @@ -165,7 +169,7 @@ void SDLogger::sensor_sd_task() {

// Do not advance the ring buffer on error.
// Wakeups will continue; user can call end().
k_poll_signal_reset(&logger_sig);
reset_logger_signal();
continue;
}

Expand All @@ -177,7 +181,7 @@ void SDLogger::sensor_sd_task() {
k_yield();
}

k_poll_signal_reset(&logger_sig);
reset_logger_signal();

STACK_USAGE_PRINT("sensor_msg_thread", &sdlogger.thread_data);
}
Expand Down
20 changes: 12 additions & 8 deletions src/SD_Card/SDLogger/SDLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ static_assert(BUFFER_SIZE % SD_BLOCK_SIZE == 0, "BUFFER_SIZE must be a multiple

// Singleton pattern
class SDLogger {
protected:
// Add static instance pointer for work handler
//static SDLogger* instance_ptr;
//friend void sd_work_handler(struct k_work* work);

private:

SDCardManager* sd_card = nullptr;
Expand Down Expand Up @@ -80,14 +75,23 @@ class SDLogger {
*/
int write_sensor_data(const void* const* data_blocks, const size_t* lengths, size_t block_count);

/**
* @brief Write a single sensor_data message to the log file
* @param msg The sensor_data message to write
* @return 0 on success, negative error code on failure
*/
int write_sensor_data(const sensor_data& msg);

/**
* @brief End logging and close the current file
* @return 0 on success, negative error code on failure
*/
* @brief End logging and close the current file
* @return 0 on success, negative error code on failure
*/
int end();

/**
* @brief Check if the logger is currently recording
* @return true if active, false otherwise
*/
bool is_active();

SDLogger(SDLogger const&) = delete;
Expand Down
19 changes: 12 additions & 7 deletions src/SensorManager/Microphone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@ extern void empty_fifo();
#endif

#include <zephyr/logging/log.h>
//LOG_MODULE_DECLARE(BMX160);
LOG_MODULE_REGISTER(microphone, CONFIG_LOG_DEFAULT_LEVEL);

extern struct data_fifo fifo_rx;

Microphone Microphone::sensor;

const SampleRateSetting<1> Microphone::sample_rates = {
{ 0 },
const SampleRateSetting<9> Microphone::sample_rates = {
{ 1, 2, 3, 4, 6, 8, 12, 16, 24 },

{ 48000 },
{ 48000, 24000, 16000, 12000, 8000, 6000, 4000, 3000, 2000 },

{ 48000.0 }
{ 48000.0, 24000.0, 16000.0, 12000.0, 8000.0, 6000.0, 4000.0, 3000.0, 2000.0 }
};

bool Microphone::init(struct k_msgq * queue) {
Expand All @@ -55,16 +54,20 @@ bool Microphone::init(struct k_msgq * queue) {
}

void Microphone::start(int sample_rate_idx) {
ARG_UNUSED(sample_rate_idx);
//ARG_UNUSED(sample_rate_idx);

int ret;

if (!_active) return;

record_to_sd(true);
LOG_INF("Starting Microphone at %f Hz", sample_rates.sample_rates[sample_rate_idx]);

audio_datapath_aquire(&fifo_rx);

audio_datapath_decimator_init(sample_rates.reg_vals[sample_rate_idx]);

record_to_sd(true);

_running = true;
}

Expand All @@ -78,5 +81,7 @@ void Microphone::stop() {

audio_datapath_release();

//audio_datapath_decimator_cleanup();

_running = false;
}
2 changes: 1 addition & 1 deletion src/SensorManager/Microphone.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Microphone : public EdgeMlSensor {
void start(int sample_rate_idx) override;
void stop() override;

const static SampleRateSetting<1> sample_rates;
const static SampleRateSetting<9> sample_rates;
private:
bool _active = false;
};
Expand Down
7 changes: 7 additions & 0 deletions src/SensorManager/SensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <string>
#include <set>

#include "audio_datapath.h"

#include <sensor_service.h>

#include <zephyr/logging/log.h>
Expand Down Expand Up @@ -128,6 +130,10 @@ void stop_sensor_manager() {

LOG_DBG("Stopping sensor manager");

// Stop audio recording/processing first to prevent race condition
//extern "C" void audio_datapath_stop_recording(void);
audio_datapath_stop_recording();

Baro::sensor.stop();
IMU::sensor.stop();
PPG::sensor.stop();
Expand Down Expand Up @@ -225,6 +231,7 @@ static void config_work_handler(struct k_work *work) {
std::string filename = recording_name_prefix + std::to_string(micros());
int ret = sdlogger.begin(filename);
if (ret == 0) state_indicator.set_sd_state(SD_RECORDING);
else LOG_ERR("Failed to start SDLogger, ret: %d", ret);
}
} else if (sd_sensors.find(config.sensorId) != sd_sensors.end()) {
sd_sensors.erase(config.sensorId);
Expand Down
2 changes: 2 additions & 0 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/audio_datapath.c
${CMAKE_CURRENT_SOURCE_DIR}/sw_codec_select.c
${CMAKE_CURRENT_SOURCE_DIR}/le_audio_rx.c
${CMAKE_CURRENT_SOURCE_DIR}/decimation_filter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/audio_datapath_decimator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sdlogger_wrapper.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/rx_publish.c
# ${CMAKE_CURRENT_SOURCE_DIR}/pdm_mic.c
Expand Down
Loading
Loading