CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
littlefs_helper.c File Reference
#include <stdint.h>
#include "littlefs/littlefs_helper.h"
#include "littlefs/lfs.h"
#include "littlefs/littlefs_driver.h"
#include "log/log.h"
Include dependency graph for littlefs_helper.c:

Macros

#define FLASH_CHIP_PAGE_SIZE_BYTES   2048
 
#define FLASH_CHIP_BLOCK_SIZE_BYTES   FLASH_CHIP_PAGE_SIZE_BYTES * FLASH_CHIP_PAGES_PER_BLOCK
 
#define FLASH_LOOKAHEAD_SIZE   16
 

Functions

int8_t LFS_format ()
 Formats Memory Module so it can successfully mount LittleFS.
 
int8_t LFS_mount ()
 Mounts LittleFS to the Memory Module.
 
int8_t LFS_unmount ()
 Unmounts LittleFS to the Memory Module.
 
int8_t LFS_ensure_mounted ()
 Mounts LFS filesystem if not already mounted. Does nothing if LFS is already mounted.
 
int8_t LFS_ensure_unmounted ()
 Mounts LFS filesystem if not already mounted. Does nothing if LFS is already mounted.
 
int8_t LFS_list_directory (const char root_directory[], uint16_t offset, int16_t count)
 Lists contents of LittleFS Directory, where each entry is sent as a log message.
 
int8_t LFS_make_directory (const char dir_name[])
 Creates directory.
 
int8_t LFS_delete_file (const char file_name[])
 Removes / deletes the file specified.
 
int8_t LFS_write_file (const char file_name[], uint8_t *write_buffer, uint32_t write_buffer_len)
 Creates/Opens LittleFS File to write to the Memory Module.
 
int8_t LFS_append_file (const char file_name[], uint8_t *write_buffer, uint32_t write_buffer_len)
 Creates/Opens LittleFS File to append contents.
 
int8_t LFS_write_file_with_offset (const char file_name[], lfs_soff_t offset, uint8_t *write_buffer, uint32_t write_buffer_len)
 Creates / Opens LittleFS File and writes data at a specific offset.
 
lfs_ssize_t LFS_read_file (const char file_name[], lfs_soff_t offset, uint8_t *read_buffer, uint32_t read_buffer_size)
 Opens LittleFS File to read from the Memory Module.
 
lfs_ssize_t LFS_file_size (const char file_name[])
 Returns the file size.
 

Variables

uint8_t LFS_is_lfs_mounted = 0
 
uint8_t LFS_read_buffer [FLASH_CHIP_PAGE_SIZE_BYTES]
 
uint8_t LFS_prog_buffer [FLASH_CHIP_PAGE_SIZE_BYTES]
 
uint8_t LFS_lookahead_buf [FLASH_LOOKAHEAD_SIZE]
 
uint8_t LFS_file_buffer [FLASH_CHIP_PAGE_SIZE_BYTES]
 
lfs_t LFS_filesystem
 
struct lfs_config LFS_cfg
 
struct lfs_file_config LFS_file_cfg
 

Macro Definition Documentation

◆ FLASH_CHIP_BLOCK_SIZE_BYTES

#define FLASH_CHIP_BLOCK_SIZE_BYTES   FLASH_CHIP_PAGE_SIZE_BYTES * FLASH_CHIP_PAGES_PER_BLOCK

◆ FLASH_CHIP_PAGE_SIZE_BYTES

#define FLASH_CHIP_PAGE_SIZE_BYTES   2048

◆ FLASH_LOOKAHEAD_SIZE

#define FLASH_LOOKAHEAD_SIZE   16

Function Documentation

◆ LFS_append_file()

int8_t LFS_append_file ( const char file_name[],
uint8_t * write_buffer,
uint32_t write_buffer_len )

Creates/Opens LittleFS File to append contents.

Parameters
file_name- Pointer to cstring holding the file name to create or open
write_buffer- Pointer to buffer holding the data to write
write_buffer_len- Size of the data to write
Returns
0 on success, 1 if LFS is unmounted, negative LFS error codes on failure
Here is the call graph for this function:

◆ LFS_delete_file()

int8_t LFS_delete_file ( const char file_name[])

Removes / deletes the file specified.

Parameters
file_namePointer to cstring holding the file name to remove
Returns
0 on success, 1 if LFS is unmounted, negative LFS error codes on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LFS_ensure_mounted()

int8_t LFS_ensure_mounted ( )

Mounts LFS filesystem if not already mounted. Does nothing if LFS is already mounted.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LFS_ensure_unmounted()

int8_t LFS_ensure_unmounted ( )

Mounts LFS filesystem if not already mounted. Does nothing if LFS is already mounted.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LFS_file_size()

lfs_ssize_t LFS_file_size ( const char file_name[])

Returns the file size.

Parameters
file_name- Pointer to buffer holding the file name to open
Returns
Returns negative values if read or file open failed, else the number of bytes in the file
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LFS_format()

int8_t LFS_format ( )

Formats Memory Module so it can successfully mount LittleFS.

Parameters
None
Returns
0 on success, 1 if LFS is already mounted, negative LFS error codes on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LFS_list_directory()

int8_t LFS_list_directory ( const char root_directory[],
uint16_t offset,
int16_t count )

Lists contents of LittleFS Directory, where each entry is sent as a log message.

Parameters
root_directorycstring holding the root directory to open and read
offsetNumber of entries to skip before listing directory
countNumber of entries to list in total (if 0, prints all entries)
Returns
0 on success, 1 if LFS is unmounted, negative LFS error codes on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LFS_make_directory()

int8_t LFS_make_directory ( const char dir_name[])

Creates directory.

Parameters
dir_namePointer to cstring holding the name of the directory
Returns
0 on success, 1 if LFS is unmounted, negative LFS error codes on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LFS_mount()

int8_t LFS_mount ( )

Mounts LittleFS to the Memory Module.

Parameters
None
Returns
0 on success, 1 if LFS is already mounted, negative LFS error codes on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LFS_read_file()

lfs_ssize_t LFS_read_file ( const char file_name[],
lfs_soff_t offset,
uint8_t * read_buffer,
uint32_t read_buffer_size )

Opens LittleFS File to read from the Memory Module.

Parameters
file_name- Pointer to buffer holding the file name to open
offset- position within the file to read from
read_buffer- Pointer to buffer where the read data will be stored
read_buffer_size- Size of the data to read
Returns
Returns negative values if read or file open failed, else the number of bytes read.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LFS_unmount()

int8_t LFS_unmount ( )

Unmounts LittleFS to the Memory Module.

Parameters
None
Returns
0 on success, 1 if LFS is already unmounted, negative LFS error codes on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LFS_write_file()

int8_t LFS_write_file ( const char file_name[],
uint8_t * write_buffer,
uint32_t write_buffer_len )

Creates/Opens LittleFS File to write to the Memory Module.

Parameters
file_name- Pointer to cstring holding the file name to create or open
write_buffer- Pointer to buffer holding the data to write
write_buffer_len- Size of the data to write
Returns
0 on success, 1 if LFS is unmounted, negative LFS error codes on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LFS_write_file_with_offset()

int8_t LFS_write_file_with_offset ( const char file_name[],
lfs_soff_t offset,
uint8_t * write_buffer,
uint32_t write_buffer_len )

Creates / Opens LittleFS File and writes data at a specific offset.

Parameters
file_name- Pointer to cstring holding the file name to create or open
offset- Position within the file to write the data
write_buffer- Pointer to buffer holding the data to write
write_buffer_len- Size of the data to write
Return values
0on success, 1 if LFS is unmounted, negative LFS error codes on failure
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ LFS_cfg

struct lfs_config LFS_cfg
Initial value:
= {
.block_cycles = 100,
.lookahead_size = FLASH_LOOKAHEAD_SIZE,
.compact_thresh = -1,
.read_buffer = LFS_read_buffer,
.prog_buffer = LFS_prog_buffer,
.lookahead_buffer = LFS_lookahead_buf}
#define FLASH_CHIP_SIZE_BYTES
Definition flash_driver.h:16
int LFS_block_device_sync(const struct lfs_config *)
LittleFS sync function.
Definition littlefs_driver.c:61
int LFS_block_device_read(const struct lfs_config *, lfs_block_t, lfs_off_t, void *, lfs_size_t)
LittleFS read function.
Definition littlefs_driver.c:18
int LFS_block_device_prog(const struct lfs_config *, lfs_block_t, lfs_off_t, const void *, lfs_size_t)
LittleFS write function.
Definition littlefs_driver.c:33
int LFS_block_device_erase(const struct lfs_config *, lfs_block_t)
LittleFS erase function.
Definition littlefs_driver.c:48
#define FLASH_CHIP_PAGE_SIZE_BYTES
Definition littlefs_helper.c:15
uint8_t LFS_read_buffer[FLASH_CHIP_PAGE_SIZE_BYTES]
Definition littlefs_helper.c:20
#define FLASH_LOOKAHEAD_SIZE
Definition littlefs_helper.c:17
uint8_t LFS_prog_buffer[FLASH_CHIP_PAGE_SIZE_BYTES]
Definition littlefs_helper.c:21
#define FLASH_CHIP_BLOCK_SIZE_BYTES
Definition littlefs_helper.c:16
uint8_t LFS_lookahead_buf[FLASH_LOOKAHEAD_SIZE]
Definition littlefs_helper.c:22

◆ LFS_file_buffer

uint8_t LFS_file_buffer[FLASH_CHIP_PAGE_SIZE_BYTES]

◆ LFS_file_cfg

struct lfs_file_config LFS_file_cfg
Initial value:
= {
.buffer = LFS_file_buffer,
.attr_count = 0,
.attrs = NULL}
uint8_t LFS_file_buffer[FLASH_CHIP_PAGE_SIZE_BYTES]
Definition littlefs_helper.c:23

◆ LFS_filesystem

lfs_t LFS_filesystem

littlefs_helper.h

Created on: May 2, 2024 Author: Saksham Puri

◆ LFS_is_lfs_mounted

uint8_t LFS_is_lfs_mounted = 0

◆ LFS_lookahead_buf

uint8_t LFS_lookahead_buf[FLASH_LOOKAHEAD_SIZE]

◆ LFS_prog_buffer

uint8_t LFS_prog_buffer[FLASH_CHIP_PAGE_SIZE_BYTES]

◆ LFS_read_buffer

uint8_t LFS_read_buffer[FLASH_CHIP_PAGE_SIZE_BYTES]