Skip to content

Commit

Permalink
CAN logging with logfs (#1268)
Browse files Browse the repository at this point in the history
### Changelist 
<!-- Give a list of the changes covered in this PR. This will help both
you and the reviewer keep this PR within scope. -->

Change the VC from using littlefs for CAN message logging to logfs.
Tested on the VC and was seeing 5-10% CPU load while logging the entire
CAN bus. Still needs more reliability testing but results looked
promising so far.

### Testing Done
<!-- Outline the testing that was done to demonstrate the changes are
solid. This could be unit tests, integration tests, testing on the car,
etc. Include relevant code snippets, screenshots, etc as needed. -->

Basic testing with the car on jacks. Nothing broke obviously, but still
needs more testing.
  • Loading branch information
gtaharaedmonds authored May 22, 2024
1 parent fd15be5 commit 1de2a16
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 186 deletions.
14 changes: 14 additions & 0 deletions firmware/logfs/python/logfs/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,17 @@ def list_dir(self, matches: str = "/"):
# Filter by provided prefix.
filtered_paths = [path for path in paths if path.startswith(matches)]
return filtered_paths

def cat(self, path: str) -> None:
"""
Linux command to print contents of a file.
"""
file = self.open(path=path, flags="r")
metadata = file.read_metadata()
data = file.read()

print("Metadata:")
print(metadata)
print("Data:")
print(data)
17 changes: 3 additions & 14 deletions firmware/quadruna/VC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ file(GLOB_RECURSE IO_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/io/*.c")
list(APPEND IO_SRCS
"${SHARED_IO_INCLUDE_DIR}/io_can.c"
"${SHARED_IO_INCLUDE_DIR}/io_canLogging.c"
"${SHARED_IO_INCLUDE_DIR}/io_fileSystem_lfs.c"
"${SHARED_IO_INCLUDE_DIR}/io_fileSystem_logfs.c"
"${SHARED_IO_INCLUDE_DIR}/io_jsoncan.c"
"${SHARED_IO_INCLUDE_DIR}/io_chimera.c"
"${SHARED_IO_INCLUDE_DIR}/io_led.c"
Expand Down Expand Up @@ -111,17 +111,6 @@ if ("${TARGET}" STREQUAL "deploy")
"${MD5_LOCATION}"
)

# LittleFS Library
# Add your replacement function source file to the littlefs_cm7 library
embedded_library(
"littlefs_cm7_vc"
"${LITTLEFS_SRCS}"
"${LITTLEFS_SOURCE_DIR}"
"cm7"
TRUE
)
target_compile_definitions("littlefs_cm7_vc" PRIVATE LFS_ASSERT=io_custom_lfs_assert)

# Telemetry Protocol Buffers
nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS proto/telem.proto)
set(P_SRCS ${PROTO_SRCS})
Expand All @@ -145,8 +134,8 @@ if ("${TARGET}" STREQUAL "deploy")
"${ARM_CORE}"
)

target_link_libraries("quadruna_VC_jsoncan" "quadruna_VC_stm32cube" "sbg_ecom_cm4")
target_link_libraries("quadruna_VC_app.elf" "quadruna_VC_stm32cube" "quadruna_VC_jsoncan" "quadruna_VC_commit_info" "littlefs_cm7_vc" "debug_modules" "m" "telem_proto")
target_link_libraries("quadruna_VC_jsoncan" "quadruna_VC_stm32cube" "sbg_ecom_cm7")
target_link_libraries("quadruna_VC_app.elf" "quadruna_VC_stm32cube" "quadruna_VC_jsoncan" "quadruna_VC_commit_info" "logfs_cm7" "debug_modules" "m" "telem_proto")
target_link_libraries("quadruna_VC_boot.elf" "quadruna_VC_commit_info")

embedded_image(
Expand Down
109 changes: 0 additions & 109 deletions firmware/quadruna/VC/src/io/io_lfsConfig.c

This file was deleted.

31 changes: 0 additions & 31 deletions firmware/quadruna/VC/src/io/io_lfsConfig.h

This file was deleted.

9 changes: 5 additions & 4 deletions firmware/shared/src/io/io_canLogging.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <assert.h>
#include "cmsis_os.h"
#include "queue.h"
#include "hw_gpio.h"
#include "io_canLogging.h"
#include "io_fileSystem.h"
#include "io_time.h"

// Private globals.
static const CanConfig *config;
#define QUEUE_SIZE 2048
Expand Down Expand Up @@ -37,18 +39,17 @@ static const osMessageQueueAttr_t queue_attr = {
// assume the filesystem is already inited
static int initLoggingFileSystem(void)
{
// early return
uint32_t bootcount = 0;
current_bootcount = io_fileSystem_getBootCount();
current_bootcount = io_fileSystem_getBootCount();

// create new folder for this boot
sprintf(current_path, "%lu", current_bootcount);
sprintf(current_path, "/%lu.txt", current_bootcount);
log_fd = io_fileSystem_open(current_path);
if (log_fd < 0)
{
logging_error_remaining = 0;
return 1;
}

return 0;
}

Expand Down
1 change: 0 additions & 1 deletion firmware/shared/src/io/io_canLogging.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "io_can.h"
#include "hw_sd.h"
#include "lfs.h"

typedef struct
{
Expand Down
24 changes: 13 additions & 11 deletions firmware/shared/src/io/io_fileSystem.h
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
#include <stdint.h>
#include <stddef.h>

typedef enum
{
FILE_OK = 0,
FILE_ERROR = -1, // general error
FILE_CORRUPTED = -2, // file system corrupted
FILE_NOT_FOUND = -3, // file not found
FILE_NO_SPACE = -4, // no space left
FILE_ERROR_IO = -5, // io error
FILE_OK = 0,
FILE_ERROR = -1, // general error
FILE_CORRUPTED = -2, // file system corrupted
FILE_NOT_FOUND = -3, // file not found
FILE_NO_SPACE = -4, // no space left
FILE_ERROR_IO = -5, // io error
FILE_ERROR_BAD_ARG = -6, // Invalid argument passed in
} FileSystemError;

// init the file system
// config the file system
// mount the file system
int io_fileSystem_init(void);
FileSystemError io_fileSystem_init(void);

// open a file and return the file descriptor
int io_fileSystem_open(const char *path);

// write return error code
int io_fileSystem_write(int fd, void *buf, size_t size);
FileSystemError io_fileSystem_write(int fd, void *buf, size_t size);

// given fd, buf, size, return error code
int io_fileSystem_read(int fd, void *buf, size_t size);
FileSystemError io_fileSystem_read(int fd, void *buf, size_t size);
// close file
int io_fileSystem_close(int fd);
FileSystemError io_fileSystem_close(int fd);

uint32_t io_fileSystem_getBootCount(void);

// do the concrete write operation to the hardware
int io_fileSystem_sync(int fd);
FileSystemError io_fileSystem_sync(int fd);
Loading

0 comments on commit 1de2a16

Please sign in to comment.