39 #define MIN(x,y) ((x) < (y) ? (x) : (y))
57 #define PIOS_STREAMFS_TASK_PRIORITY PIOS_THREAD_PRIO_LOW
58 #define PIOS_STREAMFS_TASK_STACK_BYTES 1000
123 return (arena_id * streamfs->
cfg->
arena_size) + arena_offset;
165 for (uint32_t arena = 0; arena < num_arenas; arena++) {
183 if (!streamfs)
return (NULL);
221 for (
int i=0;
i <
sizeof(footer);
i++) {
222 if (((uint8_t*)&footer)[
i] != 0xFF) {
268 bool found_file =
false;
269 uint32_t min_segment = 0xFFFFFFFF;
270 uint32_t sector = 0xFFFFFFFF;
272 for (uint16_t arena = 0; arena < num_arenas; arena++) {
309 bool found_file =
false;
310 int32_t max_segment = -1;
313 for (uint16_t arena = 0; arena < num_arenas; arena++) {
356 return (last_sector + 1) % num_arenas;
368 uint32_t total_written = 0;
375 uint32_t bytes_to_write = len;
386 len -= bytes_to_write;
387 total_written += bytes_to_write;
388 data = &data[bytes_to_write];
398 return total_written;
410 uint32_t total_read_len = 0;
411 int32_t current_segment = 0;
417 PIOS_Assert(start_address < streamfs->partition_size);
424 return total_read_len;
429 return total_read_len;
434 return total_read_len;
441 int32_t bytes_to_read = len;
456 len -= bytes_to_read;
457 total_read_len += bytes_to_read;
458 data = &data[bytes_to_read];
469 return total_read_len;
485 bool found_file =
false;
487 for (uint16_t arena = 0; arena < num_arenas; arena++) {
521 int32_t bytes_to_write = 0;
531 if (bytes_to_write <= 0) {
555 while (bytes_to_write > 0) {
633 if (!streamfs->
mutex) {
640 if (!streamfs->
sem) {
658 *fs_id = (uintptr_t) streamfs;
struct pios_mutex * mutex
int32_t PIOS_STREAMFS_Init(uintptr_t *fs_id, const struct streamfs_cfg *cfg, enum pios_flash_partition_labels partition_label)
Initialize the flash object setting FS.
int32_t PIOS_FLASH_find_partition_id(enum pios_flash_partition_labels label, uintptr_t *partition_id)
int32_t active_file_arena
pios_flashfs_streamfs_dev_magic
static void PIOS_STREAMFS_TxStart(uintptr_t fs_id, uint16_t tx_bytes_avail)
#define PIOS_SEMAPHORE_TIMEOUT_MAX
const struct pios_com_driver pios_streamfs_com_driver
Main PiOS header to include all the compiled in PiOS options.
static int32_t streamfs_find_new_sector(struct streamfs_state *streamfs)
struct pios_semaphore * sem
static int32_t streamfs_close_sector(struct streamfs_state *streamfs)
const struct streamfs_cfg * cfg
COM layer functions header.
int32_t PIOS_FLASH_get_partition_size(uintptr_t partition_id, uint32_t *partition_size)
#define PIOS_STREAMFS_TASK_PRIORITY
void * PIOS_malloc(size_t size)
int32_t PIOS_STREAMFS_OpenRead(uintptr_t fs_id, uint32_t file_id)
static int32_t streamfs_erase_arena(const struct streamfs_state *streamfs, uint32_t arena_id)
Erases all sectors within the given arena and sets arena to erased state.
void * PIOS_malloc_no_dma(size_t size)
pios_com_callback tx_out_cb
bool PIOS_Mutex_Unlock(struct pios_mutex *mtx)
static int32_t streamfs_find_first_arena(struct streamfs_state *streamfs, int32_t file_id)
struct pios_mutex * PIOS_Mutex_Create(void)
int32_t PIOS_STREAMFS_Close(uintptr_t fs_id)
int32_t PIOS_STREAMFS_MinFileId(uintptr_t fs_id)
uint8_t data[XFER_BYTES_PER_PACKET]
static void PIOS_STREAMFS_RegisterTxCallback(uintptr_t fs_id, pios_com_callback tx_out_cb, uintptr_t context)
static uintptr_t streamfs_get_addr(const struct streamfs_state *streamfs, uint32_t arena_id, uint16_t arena_offset)
Return the offset in flash of a particular slot within an arena.
int32_t PIOS_FLASH_write_data(uintptr_t partition_id, uint32_t offset, const uint8_t *data, uint16_t len)
static struct flyingpicmd_cfg_fa cfg
uint32_t partition_arenas
int32_t PIOS_FLASH_end_transaction(uintptr_t partition_id)
int32_t PIOS_STREAMFS_Testing_Write(uintptr_t fs_id, uint8_t *data, uint32_t len)
struct pios_semaphore * PIOS_Semaphore_Create(void)
Creates a binary semaphore.
uintptr_t PIOS_COM_GetDriverCtx(uintptr_t com_id)
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
static int32_t streamfs_find_last_arena(struct streamfs_state *streamfs, int32_t file_id)
struct pios_thread * task
static int32_t streamfs_append_to_file(struct streamfs_state *streamfs, uint8_t *data, uint32_t len)
int32_t PIOS_STREAMFS_OpenWrite(uintptr_t fs_id)
#define PIOS_STREAMFS_TASK_STACK_BYTES
bool PIOS_Semaphore_Give(struct pios_semaphore *sema)
Gives binary semaphore.
static bool streamfs_validate(const struct streamfs_state *streamfs)
static int32_t streamfs_new_sector(struct streamfs_state *streamfs)
int32_t PIOS_FLASH_erase_range(uintptr_t partition_id, uint32_t start_offset, uint32_t size)
static int32_t streamfs_scan_filesystem(struct streamfs_state *streamfs)
enum pios_flashfs_streamfs_dev_magic magic
int32_t active_file_arena_offset
void PIOS_free(void *buf)
void PIOS_Thread_Sleep(uint32_t time_ms)
static int32_t streamfs_erase_all_arenas(const struct streamfs_state *streamfs)
Erases all arenas available to this filesystem instance.
int32_t PIOS_STREAMFS_Read(uintptr_t fs_id, uint8_t *data, uint32_t len)
bool PIOS_Semaphore_Take(struct pios_semaphore *sema, uint32_t timeout_ms)
Takes binary semaphore.
pios_flash_partition_labels
static void PIOS_STREAMFS_Task(void *parameters)
int32_t active_file_segment
int32_t PIOS_FLASH_read_data(uintptr_t partition_id, uint32_t offset, uint8_t *data, uint16_t len)
int32_t PIOS_FLASH_start_transaction(uintptr_t partition_id)
int32_t PIOS_STREAMFS_Format(uintptr_t fs_id)
Erases all filesystem arenas and activate the first arena.
static int32_t streamfs_read_from_file(struct streamfs_state *streamfs, uint8_t *data, uint32_t len)
int32_t PIOS_STREAMFS_MaxFileId(uintptr_t fs_id)
static struct streamfs_state * streamfs_alloc(void)
#define PIOS_Assert(test)
void(* tx_start)(uintptr_t id, uint16_t tx_bytes_avail)
uint16_t(* pios_com_callback)(uintptr_t context, uint8_t *buf, uint16_t buf_len, uint16_t *headroom, bool *task_woken)
pios_com_callback rx_in_cb
#define PIOS_MUTEX_TIMEOUT_MAX
bool PIOS_Mutex_Lock(struct pios_mutex *mtx, uint32_t timeout_ms)