Skip to content
Merged
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
14 changes: 7 additions & 7 deletions .github/workflows/build_firmware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ jobs:
# Copy merged dir
cp -R -f $(pwd)/workflow-board-temp/boards/* $(pwd)/zephyr-workspace/zephyr/boards

- name: Cache ~/.cache/ccache
uses: actions/cache@v3
with:
path: ~/.cache/ccache
key: ccache-v1-${{ runner.os }}-${{ hashFiles('zephyr-workspace/nrfconnect-ci-app/west.yml') }}
restore-keys: |
ccache-v1-${{ runner.os }}-
#- name: Cache ~/.cache/ccache
# uses: actions/cache@v3
# with:
# path: ~/.cache/ccache
# key: ccache-v1-${{ runner.os }}-${{ hashFiles('zephyr-workspace/nrfconnect-ci-app/west.yml') }}
# restore-keys: |
# ccache-v1-${{ runner.os }}-

- name: Build Project
run: |
Expand Down
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ zephyr_library_include_directories(
src/utils
src/utils/macros
src/ParseInfo
src/SDLogger
src/SD_Card/SDLogger
src/SD_Card/Benchmark
src/SD_Card/SD_Card_Manager
src/SD_Card/CSV_Logger
)

zephyr_library_include_directories(app PRIVATE
Expand All @@ -65,7 +68,10 @@ add_subdirectory(src/modules)
add_subdirectory(src/utils)
add_subdirectory(src/ParseInfo)
add_subdirectory(src/SensorManager)
add_subdirectory(src/SDLogger)
add_subdirectory(src/SD_Card/SDLogger)
add_subdirectory(src/SD_Card/Benchmark)
add_subdirectory(src/SD_Card/SD_Card_Manager)
add_subdirectory(src/SD_Card/CSV_Logger)

## Cirrus Logic
if (CONFIG_HW_CODEC_CIRRUS_LOGIC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
status = "okay";
uart {
//gpios = <&gpio1 1 0>, <&gpio1 0 0>, <&gpio0 11 0>, <&gpio0 10 0>;
gpios = <&gpio1 6 0>, <&gpio0 7 0>, <&gpio0 11 0>, <&gpio0 10 0>;
//gpios = <&gpio1 6 0>, <&gpio0 7 0>, <&gpio0 11 0>, <&gpio0 10 0>;
gpios = <&gpio1 6 0>, <&gpio0 7 0>, <&gpio0 2 0>, <&gpio0 3 0>;
};
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
&pinctrl {
uart0_default: uart0_default {
group1 {
psels = <NRF_PSEL(UART_TX, 1, 1)>,
<NRF_PSEL(UART_RX, 1, 0)>,
<NRF_PSEL(UART_RTS, 0, 11)>,
<NRF_PSEL(UART_CTS, 0, 10)>;
psels = <NRF_PSEL(UART_TX, 1, 6)>,
<NRF_PSEL(UART_RX, 0, 7)>,
<NRF_PSEL(UART_RTS, 0, 2)>,
<NRF_PSEL(UART_CTS, 0, 3)>;
};
};

uart0_sleep: uart0_sleep {
group1 {
psels = <NRF_PSEL(UART_TX, 1, 1)>,
<NRF_PSEL(UART_RX, 1, 0)>,
<NRF_PSEL(UART_RTS, 0, 11)>,
<NRF_PSEL(UART_CTS, 0, 10)>;
psels = <NRF_PSEL(UART_TX, 1, 6)>,
<NRF_PSEL(UART_RX, 0, 7)>,
<NRF_PSEL(UART_RTS, 0, 2)>,
<NRF_PSEL(UART_CTS, 0, 3)>;
low-power-enable;
};
};
Expand Down
23 changes: 20 additions & 3 deletions prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
CONFIG_BT_AUDIO_PRESENTATION_DELAY_US=40000
CONFIG_BT_AUDIO_MAX_TRANSPORT_LATENCY_MS=20

CONFIG_BT_AUDIO_RETRANSMITS=5
CONFIG_BT_AUDIO_RETRANSMITS=2

CONFIG_BLE_ACL_CONN_INTERVAL=8

CONFIG_BT_PERIPHERAL=y
CONFIG_BT_OBSERVER=y

CONFIG_SFLOAT=y

Expand Down Expand Up @@ -174,6 +175,22 @@ CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_DISK_DRIVERS=y
CONFIG_DISK_DRIVER_SDMMC=y

CONFIG_BT_OBSERVER=y
CONFIG_FDSP=n

CONFIG_FS_FATFS_MOUNT_MKFS=n # Disable automatic formatting
CONFIG_FS_FATFS_EXFAT=y # Enable exFAT support

CONFIG_SDHC=y
CONFIG_LOG=y
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y # Enables FatFs (ff.h)
CONFIG_FS_FATFS_MOUNT_MKFS=n # Disable automatic formatting
CONFIG_FS_FATFS_EXFAT=y # Enable exFAT support
CONFIG_DISK_ACCESS=y # Required for SD card or storage access
CONFIG_FLASH=y # If using internal flash storage

CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096

CONFIG_FDSP=n
#CONFIG_USB_MASS_STORAGE=y
#CONFIG_MASS_STORAGE_STACK_SIZE=1024
3 changes: 0 additions & 3 deletions src/SDLogger/CMakeLists.txt

This file was deleted.

21 changes: 0 additions & 21 deletions src/SDLogger/SDLogger.h

This file was deleted.

21 changes: 21 additions & 0 deletions src/SD_Card/Benchmark/Benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "Benchmark.h"

Benchmark::Benchmark(void (*function)()) {
this->function = function;
}

void Benchmark::start() {
this->start_time = k_uptime_get_32();
this->start_cycles = k_cycle_get_32();
this->function();
this->end_time = k_uptime_get_32();
this->end_cycles = k_cycle_get_32();
}

uint32_t Benchmark::get_time() {
return this->end_time - this->start_time;
}

uint32_t Benchmark::get_cycles() {
return this->end_cycles - this->start_cycles;
}
29 changes: 29 additions & 0 deletions src/SD_Card/Benchmark/Benchmark.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef _BENCHMARK_H_
#define _BENCHMARK_H_

#include <zephyr/kernel.h>

class Benchmark {
public:
/**
* @brief Construct a new Benchmark object
* @param function The function that should be benchmarked
*/
Benchmark(void (*function)());

void start();

uint32_t get_time();
uint32_t get_cycles();

private:
uint32_t start_time;
uint32_t start_cycles;
uint32_t end_time;
uint32_t end_cycles;

// the pointer to the function that should be benchmarked
void (*function)();
};

#endif
8 changes: 8 additions & 0 deletions src/SD_Card/Benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
enable_language(CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Benchmark.cpp
)
8 changes: 8 additions & 0 deletions src/SD_Card/CSV_Logger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
enable_language(CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CSVLogger.cpp
)
106 changes: 106 additions & 0 deletions src/SD_Card/CSV_Logger/CSVLogger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include "CSVLogger.h"
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(CSVLogger, LOG_LEVEL_DBG);

template<typename T>
std::string joinLine(const T *data, size_t header_count, char separator) {
std::string line = "";
for (size_t i = 0; i < header_count; i++) {
line += std::to_string(data[i]);
if (i < header_count - 1) {
line += separator;
}
}
return line;
}

std::string joinLine(const char **data, size_t header_count, char separator) {
std::string line = "";
for (size_t i = 0; i < header_count; i++) {
line += data[i];
if (i < header_count - 1) {
line += separator;
}
}
return line;
}


CSVLogger::CSVLogger(std::string path, SDCardManager *sd_card , const char **headers, size_t header_count, char separator) {
this->file_path = path;
this->headers = headers;
this->header_count = header_count;
this->separator = separator;
this->sd_card = sd_card;
}

CSVLogger::~CSVLogger() {
this->end();
}

int CSVLogger::begin() {
// TODO: check if file already exists
int ret = sd_card->open_file(this->file_path, true, true, true);
if (ret != 0) {
LOG_ERR("Failed to open file: %d", ret);
} else {
LOG_DBG("Opened file %s", this->file_path.c_str());

std::string header_str = joinLine(this->headers, this->header_count, this->separator);
header_str += "\n";
LOG_DBG("Header: %s", header_str.c_str());
size_t header_size = header_str.size();
this->sd_card->write((char *)header_str.c_str(), &header_size);
}
return ret;
}

int CSVLogger::end() {
int ret = sd_card->close_file();
if (ret != 0) {
LOG_ERR("Failed to close file: %d", ret);
} else {
LOG_DBG("Closed file %s", this->file_path.c_str());
}
return ret;
}

int CSVLogger::sync() {
int ret = this->sd_card->sync();
if (ret < 0) {
LOG_ERR("Failed to sync file: %d", ret);
}
return ret;
}

int CSVLogger::writeLine(const char **data, bool sync) {
std::string line = joinLine(data, this->header_count, this->separator);
return this->write(line, sync);
}

int CSVLogger::writeLine(const double *data, bool sync) {
std::string line = joinLine<double>(data, this->header_count, this->separator);
return this->write(line, sync);
}

int CSVLogger::writeLine(const int *data, bool sync) {
std::string line = joinLine<int>(data, this->header_count, this->separator);
return this->write(line, sync);
}

int CSVLogger::write(std::string line, bool sync) {
line += "\n";
size_t line_size = line.size();
int ret = this->sd_card->write((char *)line.c_str(), &line_size);
if (ret < 0) {
LOG_ERR("Failed to write to file: %d", ret);
}
if (sync) {
ret = this->sd_card->sync();
if (ret < 0) {
LOG_ERR("Failed to sync file: %d", ret);
}
}
return ret;
}
41 changes: 41 additions & 0 deletions src/SD_Card/CSV_Logger/CSVLogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef _CSV_LOGGER_H_
#define _CSV_LOGGER_H_

#include <string>

#include "SD_Card_Manager.h"

class CSVLogger {
public:
/**
* @brief Construct a new CSVLogger object
*
* @param path the path where the file should be saved
* @param headers the array of headers of the csv file
* @param header_count the number of columns
* @param separator the separator between the columns
*/
CSVLogger(std::string path, SDCardManager *sd_card, const char **headers, size_t header_count, char separator = ',');
~CSVLogger();

int begin();
int end();

int sync();

int writeLine(const char **data, bool sync = false);
int writeLine(const double *data, bool sync = false);
int writeLine(const int *data, bool sync = false);

private:
std::string file_path;
const char **headers;
size_t header_count;
char separator;

SDCardManager *sd_card;

int write(std::string line, bool sync = false);
};

#endif
3 changes: 3 additions & 0 deletions src/SD_Card/SDLogger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/SDLogger.cpp
)
Loading