rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
panel_files.c File Reference

FILES' card task: the file manager's card (fm_io.h) over the storage component, the task cardjob that runs the screen's requests (fm_req.h), and the screen's way to it (files_io_t). More...

#include <errno.h>
#include <fcntl.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "files_screen.h"
#include "fm_io.h"
#include "fm_ops.h"
#include "fm_req.h"
#include "log_take.h"
#include "panel.h"
#include "storage.h"
#include "ui_screen.h"

Data Structures

struct  walk_ctx_t
 A walk's visit and its context, for walk_take(). More...

Macros

#define FILES_STACK   6656
 cardjob's stack, bytes: the logger's figure for the deepest card chain, a walk with the card mounted again under it (main.c).
#define FILES_PRIO   1
 cardjob's priority: the render loop's.
#define FILES_CORE   0
 cardjob's core: the render loop's.
#define FILES_PATH   (sizeof(STORAGE_MOUNT_POINT) + FM_PATH_SIZE)
 Room for "/sdcard/" and a path of the file manager.

Functions

static bool full_path (const char *path, char *out, size_t n)
 The full path of path, a path from the card's root.
static fm_err_t err_of (int e)
 The core's answer for a failed call's errno. A failure with no other reason looks at the slot: a card taken out answers so.
static fm_err_t gone_or_io (void)
 The answer of a call that found nothing it can name.
static bool io_mounted (void *ctx)
 fm_io_t mounted().
static unsigned io_mounts (void *ctx)
 fm_io_t mounts().
static bool io_hold (void *ctx, unsigned mount)
 fm_io_t hold().
static void io_release (void *ctx)
 fm_io_t release().
static void walk_take (const storage_entry_t *entry, void *ctx)
 One entry of storage_walk_counted() handed to the core.
static fm_err_t io_walk (void *ctx, const char *dir, fm_visit_fn visit, void *vctx, unsigned *unlisted)
 fm_io_t walk(): storage_walk_counted() with no suffix filter, so every entry is visited or counted: a name starting with "." and a name of 64 characters or more are counted as unlisted.
static fm_err_t io_stat (void *ctx, const char *path, fm_stat_t *out)
 fm_io_t stat(), FatFs's own f_stat() through storage_stat() for a 64-bit size.
static fm_err_t path_call (const char *path, int call)
 A path call on the full path: mkdir(), unlink() or rmdir().
static fm_err_t io_mkdir (void *ctx, const char *path)
 fm_io_t mkdir().
static fm_err_t io_unlink (void *ctx, const char *path)
 fm_io_t unlink().
static fm_err_t io_rmdir (void *ctx, const char *path)
 fm_io_t rmdir(). FatFs refuses a folder with entries with FR_DENIED, which is EACCES and FM_ERR_DENIED.
static fm_err_t io_rename (void *ctx, const char *from, const char *to)
 fm_io_t rename(): FatFs's f_rename(), which renames over no name (FR_EXIST, EEXIST) but the same entry's in another case.
static int fd_of (void *file)
 The descriptor of a handle: fd + 1, so no handle is NULL.
static fm_err_t io_open (void *ctx, const char *path, fm_mode_t mode, void **file)
 fm_io_t open(): a descriptor, the volume held until close(). A new file is O_EXCL: a taken name is FM_ERR_EXISTS.
static fm_err_t io_read (void *ctx, void *file, uint8_t *buf, size_t cap, size_t *got)
 fm_io_t read().
static fm_err_t io_write (void *ctx, void *file, const uint8_t *buf, size_t len)
 fm_io_t write(): all of it, or FM_ERR_FULL for a short write.
static fm_err_t io_sync (void *ctx, void *file)
 fm_io_t sync(): fsync(), the file on the card.
static fm_err_t io_close (void *ctx, void *file)
 fm_io_t close(), and the open's hold given back.
static void job_bench (fm_bench_t *out, void *ctx)
 The runner's bench(): the control task's snapshot and the logger's open files, now.
static bool job_cancelled (void *ctx)
 The runner's cancelled().
static void job_progress (uint64_t done, uint64_t total, void *ctx)
 The runner's progress().
static void job_look (void *ctx)
 The runner's look(): a card put in, taken out or swapped is found.
static void log_copy (const fm_req_t *req, int64_t us)
 A copy's bytes, time and rate, and the stack cardjob left: the card's figures on this board.
static void files_task (void *arg)
 cardjob: each request handed over, run to its end.
static bool start_task (void)
 cardjob and its chunk, at the first request.
static bool fio_submit (fm_req_t *req, void *ctx)
 files_io_t submit().
static bool fio_idle (void *ctx)
 files_io_t idle().
static void fio_progress (uint64_t *done, uint64_t *total, void *ctx)
 files_io_t progress().
static void fio_cancel (void *ctx)
 files_io_t cancel().
static void fio_bench (fm_bench_t *out, void *ctx)
 files_io_t bench(): the band's ARMED and link, and the logger's open files, for the footer's gate and the rows' marks.
static const char * fio_volume (void *ctx)
 files_io_t volume().
static card_state_t fio_card (void *ctx)
 files_io_t card().

Variables

static const char * TAG = "rcbench"
 The log tag of the panel's lines.
static const fm_io_t k_io
 The card as the core sees it.
static fm_req_t * s_req
 The request handed over, cardjob's from the count up to its answer.
static atomic_uint s_sent
 Requests handed over: equal to s_done while none is under way.
static atomic_uint s_done
 Requests answered.
static atomic_bool s_cancel
 CANCEL, set by the render task, read by cardjob before each step.
static portMUX_TYPE s_prog_mux = portMUX_INITIALIZER_UNLOCKED
 Guards s_prog_done and s_prog_total, 64-bit each.
static uint64_t s_prog_done
 The job's bytes done, under s_prog_mux.
static uint64_t s_prog_total
 The job's bytes to do, under s_prog_mux.
static TaskHandle_t s_task
 cardjob, NULL until the first request starts it.
static uint8_t * s_chunk
 cardjob's copy buffer, FM_CHUNK bytes of internal DMA RAM.
static log_marks_t s_job_marks
 The logger's open files as cardjob last read them.
static char s_job_run_dir [CARD_DIR_MAX]
 The folder of s_job_marks' run.
static char s_job_test_dir [CARD_DIR_MAX]
 The folder of s_job_marks' test.
static log_marks_t s_ui_marks
 The logger's open files as the screen last read them: the task that renders' own.
static char s_ui_run_dir [CARD_DIR_MAX]
 The folder of s_ui_marks' run.
static char s_ui_test_dir [CARD_DIR_MAX]
 The folder of s_ui_marks' test.
const files_io_t k_files_io
 FILES' way to the card: its requests run on cardjob.

Detailed Description

FILES' card task: the file manager's card (fm_io.h) over the storage component, the task cardjob that runs the screen's requests (fm_req.h), and the screen's way to it (files_io_t).

The FILES screen makes no card call: it hands a request over through k_files_io, and cardjob makes every call of it, listings and INFO included, one request at a time. A long copy then holds up neither a frame nor STOP. cardjob runs at priority 1 on core 0, the render loop's, and is created at the first request, not at start-up: its stack (FILES_STACK) and the copy's chunk (FM_CHUNK, internal and DMA-capable, since the card's driver reads a PSRAM target one sector at a time) cost internal RAM only once FILES is used. Both are kept from then on.

Every call runs under the hold of the mount the names were listed from (storage_hold_mount()), which fm_tree.c and fm_ops.c take: a card swapped since is never written under a stale name. A file stays held from open() to close() as well (storage_hold()). A call that fails with no other reason looks at the slot once (storage_check()); a card found gone answers FM_ERR_CARD_GONE.

The bench the write gate reads is the control task's snapshot: ARMED and an arm waiting count as ARMED, the IOmcu link as it stands, and the logger's open files (log_open_marks()). A job reads it before each chunk, so an ARM stops a copy at its next 16KiB.

Each copy logs its bytes, its time and its rate, and the stack cardjob left unused: the card's rate on this board is not measured.

SPDX-License-Identifier: MIT

Function Documentation

◆ err_of()

fm_err_t err_of ( int e)
static

The core's answer for a failed call's errno. A failure with no other reason looks at the slot: a card taken out answers so.

Parameters
ethe errno
Returns
the answer

◆ fd_of()

int fd_of ( void * file)
static

The descriptor of a handle: fd + 1, so no handle is NULL.

Parameters
filethe handle
Returns
the descriptor

◆ files_task()

void files_task ( void * arg)
static

cardjob: each request handed over, run to its end.

Parameters
argunused

◆ fio_bench()

void fio_bench ( fm_bench_t * out,
void * ctx )
static

files_io_t bench(): the band's ARMED and link, and the logger's open files, for the footer's gate and the rows' marks.

Parameters
outtakes the bench
ctxunused

◆ fio_cancel()

void fio_cancel ( void * ctx)
static

files_io_t cancel().

Parameters
ctxunused

◆ fio_card()

card_state_t fio_card ( void * ctx)
static

files_io_t card().

Parameters
ctxunused
Returns
storage_card_state()

◆ fio_idle()

bool fio_idle ( void * ctx)
static

files_io_t idle().

Parameters
ctxunused
Returns
true with no request under way

◆ fio_progress()

void fio_progress ( uint64_t * done,
uint64_t * total,
void * ctx )
static

files_io_t progress().

Parameters
donetakes the bytes done
totaltakes the bytes to do
ctxunused

◆ fio_submit()

bool fio_submit ( fm_req_t * req,
void * ctx )
static

files_io_t submit().

Parameters
reqthe request
ctxunused
Returns
false with one under way, or with no task

◆ fio_volume()

const char * fio_volume ( void * ctx)
static

files_io_t volume().

Parameters
ctxunused
Returns
the card's name, the render task's copy

◆ full_path()

bool full_path ( const char * path,
char * out,
size_t n )
static

The full path of path, a path from the card's root.

Parameters
paththe path; "" for the root
outtakes "/sdcard/<path>", or "/sdcard" for the root
nbytes at out
Returns
false for a path that does not fit

◆ gone_or_io()

fm_err_t gone_or_io ( void )
static

The answer of a call that found nothing it can name.

Returns
FM_ERR_IO with a volume mounted, FM_ERR_CARD_GONE without

◆ io_close()

fm_err_t io_close ( void * ctx,
void * file )
static

fm_io_t close(), and the open's hold given back.

Parameters
ctxunused
filethe handle
Returns
FM_OK or err_of()

◆ io_hold()

bool io_hold ( void * ctx,
unsigned mount )
static

fm_io_t hold().

Parameters
ctxunused
mountthe mount the names were read from
Returns
storage_hold_mount()

◆ io_mkdir()

fm_err_t io_mkdir ( void * ctx,
const char * path )
static

fm_io_t mkdir().

Parameters
ctxunused
paththe new folder
Returns
path_call()

◆ io_mounted()

bool io_mounted ( void * ctx)
static

fm_io_t mounted().

Parameters
ctxunused
Returns
storage_mounted()

◆ io_mounts()

unsigned io_mounts ( void * ctx)
static

fm_io_t mounts().

Parameters
ctxunused
Returns
storage_mount_count()

◆ io_open()

fm_err_t io_open ( void * ctx,
const char * path,
fm_mode_t mode,
void ** file )
static

fm_io_t open(): a descriptor, the volume held until close(). A new file is O_EXCL: a taken name is FM_ERR_EXISTS.

Parameters
ctxunused
paththe file
moderead, or a new file
filetakes the handle
Returns
FM_OK or why not

◆ io_read()

fm_err_t io_read ( void * ctx,
void * file,
uint8_t * buf,
size_t cap,
size_t * got )
static

fm_io_t read().

Parameters
ctxunused
filethe handle
buftakes the bytes
caproom in buf
gottakes the count, 0 at the end
Returns
FM_OK or err_of()

◆ io_release()

void io_release ( void * ctx)
static

fm_io_t release().

Parameters
ctxunused

◆ io_rename()

fm_err_t io_rename ( void * ctx,
const char * from,
const char * to )
static

fm_io_t rename(): FatFs's f_rename(), which renames over no name (FR_EXIST, EEXIST) but the same entry's in another case.

Parameters
ctxunused
fromthe entry's path
toits new path
Returns
FM_OK or err_of()

◆ io_rmdir()

fm_err_t io_rmdir ( void * ctx,
const char * path )
static

fm_io_t rmdir(). FatFs refuses a folder with entries with FR_DENIED, which is EACCES and FM_ERR_DENIED.

Parameters
ctxunused
paththe folder
Returns
path_call()

◆ io_stat()

fm_err_t io_stat ( void * ctx,
const char * path,
fm_stat_t * out )
static

fm_io_t stat(), FatFs's own f_stat() through storage_stat() for a 64-bit size.

Parameters
ctxunused
paththe name's path
outtakes the answer
Returns
FM_OK, FM_ERR_NOT_FOUND, FM_ERR_CARD_GONE or FM_ERR_IO

◆ io_sync()

fm_err_t io_sync ( void * ctx,
void * file )
static

fm_io_t sync(): fsync(), the file on the card.

Parameters
ctxunused
filethe handle
Returns
FM_OK or err_of()

◆ io_unlink()

fm_err_t io_unlink ( void * ctx,
const char * path )
static

fm_io_t unlink().

Parameters
ctxunused
paththe file
Returns
path_call()

◆ io_walk()

fm_err_t io_walk ( void * ctx,
const char * dir,
fm_visit_fn visit,
void * vctx,
unsigned * unlisted )
static

fm_io_t walk(): storage_walk_counted() with no suffix filter, so every entry is visited or counted: a name starting with "." and a name of 64 characters or more are counted as unlisted.

Parameters
ctxunused
dirthe folder
visitcalled per entry
vctxpassed to visit
unlistedtakes the count left out; may be NULL
Returns
FM_OK, FM_ERR_NOT_FOUND, FM_ERR_CARD_GONE or FM_ERR_IO

◆ io_write()

fm_err_t io_write ( void * ctx,
void * file,
const uint8_t * buf,
size_t len )
static

fm_io_t write(): all of it, or FM_ERR_FULL for a short write.

Parameters
ctxunused
filethe handle
bufthe bytes
lenhow many
Returns
FM_OK, FM_ERR_FULL or err_of()

◆ job_bench()

void job_bench ( fm_bench_t * out,
void * ctx )
static

The runner's bench(): the control task's snapshot and the logger's open files, now.

Parameters
outtakes the bench
ctxunused

◆ job_cancelled()

bool job_cancelled ( void * ctx)
static

The runner's cancelled().

Parameters
ctxunused
Returns
CANCEL was pressed

◆ job_look()

void job_look ( void * ctx)
static

The runner's look(): a card put in, taken out or swapped is found.

Parameters
ctxunused

◆ job_progress()

void job_progress ( uint64_t done,
uint64_t total,
void * ctx )
static

The runner's progress().

Parameters
donebytes done
totalbytes to do
ctxunused

◆ log_copy()

void log_copy ( const fm_req_t * req,
int64_t us )
static

A copy's bytes, time and rate, and the stack cardjob left: the card's figures on this board.

Parameters
reqthe answered request
usits time, microseconds

◆ path_call()

fm_err_t path_call ( const char * path,
int call )
static

A path call on the full path: mkdir(), unlink() or rmdir().

Parameters
paththe path from the root
call0 mkdir, 1 unlink, 2 rmdir
Returns
FM_OK or err_of()

◆ start_task()

bool start_task ( void )
static

cardjob and its chunk, at the first request.

Returns
true when the task runs

◆ walk_take()

void walk_take ( const storage_entry_t * entry,
void * ctx )
static

One entry of storage_walk_counted() handed to the core.

Parameters
entrythe entry, borrowed for the call
ctxthe walk_ctx_t

Variable Documentation

◆ k_files_io

const files_io_t k_files_io
Initial value:
= {
.submit = fio_submit, .idle = fio_idle, .progress = fio_progress,
.cancel = fio_cancel, .bench = fio_bench, .volume = fio_volume,
.card = fio_card, .ctx = NULL,
}
static void fio_cancel(void *ctx)
files_io_t cancel().
Definition panel_files.c:680
static void fio_progress(uint64_t *done, uint64_t *total, void *ctx)
files_io_t progress().
Definition panel_files.c:667
static const char * fio_volume(void *ctx)
files_io_t volume().
Definition panel_files.c:716
static void fio_bench(fm_bench_t *out, void *ctx)
files_io_t bench(): the band's ARMED and link, and the logger's open files, for the footer's gate and...
Definition panel_files.c:700
static bool fio_submit(fm_req_t *req, void *ctx)
files_io_t submit().
Definition panel_files.c:636
static card_state_t fio_card(void *ctx)
files_io_t card().
Definition panel_files.c:729
static bool fio_idle(void *ctx)
files_io_t idle().
Definition panel_files.c:655

FILES' way to the card: its requests run on cardjob.

FILES' way to the card: its requests run on the task cardjob.

FILES' way to the card: its requests run on cardjob.

◆ k_io

const fm_io_t k_io
static
Initial value:
= {
.mounted = io_mounted, .mounts = io_mounts, .hold = io_hold,
.release = io_release, .walk = io_walk, .stat = io_stat,
.mkdir = io_mkdir, .unlink = io_unlink, .rmdir = io_rmdir,
.rename = io_rename, .open = io_open, .read = io_read,
.write = io_write, .sync = io_sync, .close = io_close, .ctx = NULL,
}
static fm_err_t io_rename(void *ctx, const char *from, const char *to)
fm_io_t rename(): FatFs's f_rename(), which renames over no name (FR_EXIST, EEXIST) but the same entr...
Definition panel_files.c:321
static unsigned io_mounts(void *ctx)
fm_io_t mounts().
Definition panel_files.c:147
static fm_err_t io_open(void *ctx, const char *path, fm_mode_t mode, void **file)
fm_io_t open(): a descriptor, the volume held until close(). A new file is O_EXCL: a taken name is FM...
Definition panel_files.c:356
static fm_err_t io_read(void *ctx, void *file, uint8_t *buf, size_t cap, size_t *got)
fm_io_t read().
Definition panel_files.c:388
static fm_err_t io_mkdir(void *ctx, const char *path)
fm_io_t mkdir().
Definition panel_files.c:278
static fm_err_t io_walk(void *ctx, const char *dir, fm_visit_fn visit, void *vctx, unsigned *unlisted)
fm_io_t walk(): storage_walk_counted() with no suffix filter, so every entry is visited or counted: a...
Definition panel_files.c:206
static fm_err_t io_rmdir(void *ctx, const char *path)
fm_io_t rmdir(). FatFs refuses a folder with entries with FR_DENIED, which is EACCES and FM_ERR_DENIE...
Definition panel_files.c:307
static bool io_mounted(void *ctx)
fm_io_t mounted().
Definition panel_files.c:136
static fm_err_t io_unlink(void *ctx, const char *path)
fm_io_t unlink().
Definition panel_files.c:290
static void io_release(void *ctx)
fm_io_t release().
Definition panel_files.c:169
static fm_err_t io_stat(void *ctx, const char *path, fm_stat_t *out)
fm_io_t stat(), FatFs's own f_stat() through storage_stat() for a 64-bit size.
Definition panel_files.c:233
static fm_err_t io_close(void *ctx, void *file)
fm_io_t close(), and the open's hold given back.
Definition panel_files.c:445
static fm_err_t io_write(void *ctx, void *file, const uint8_t *buf, size_t len)
fm_io_t write(): all of it, or FM_ERR_FULL for a short write.
Definition panel_files.c:409
static fm_err_t io_sync(void *ctx, void *file)
fm_io_t sync(): fsync(), the file on the card.
Definition panel_files.c:433
static bool io_hold(void *ctx, unsigned mount)
fm_io_t hold().
Definition panel_files.c:159

The card as the core sees it.