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

Receiving an image. See fw_upload.h. More...

#include "fw_upload.h"
#include <string.h>

Functions

void fw_upload_init (fw_upload_t *u, uint8_t *buf, uint32_t cap, uint32_t slot)
 An upload into buf of cap bytes, for a slot of slot bytes: IDLE.
fw_err_t fw_upload_begin (fw_upload_t *u, uint32_t bytes)
 A source announces bytes.
static fw_err_t refuse (fw_upload_t *u, fw_err_t e)
 FAILED with e.
fw_err_t fw_upload_add (fw_upload_t *u, const uint8_t *data, uint32_t len)
 len more bytes.
fw_err_t fw_upload_seal (fw_upload_t *u, bool whole)
 The first half of fw_upload_end(), for a check run without the caller's lock: the bytes are whole and wait for fw_image_check() over buf and bytes.
fw_err_t fw_upload_checked (fw_upload_t *u, fw_err_t e, const fw_image_info_t *info)
 The second half: the answer of the check over a sealed upload.
fw_err_t fw_upload_end (fw_upload_t *u, bool whole)
 The source is done; the image is checked at once.
bool fw_upload_busy (const fw_upload_t *u)
 Whether the buffer is in use: bytes arriving, or a check under way. A caller frees the buffer of an upload that is neither this nor STAGED.
void fw_upload_discard (fw_upload_t *u)
 Drop what is received or staged: IDLE. During a check, IDLE once fw_upload_checked() has its answer.
unsigned fw_upload_percent (const fw_upload_t *u)
 Received of announced.

Detailed Description

Receiving an image. See fw_upload.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ fw_upload_add()

fw_err_t fw_upload_add ( fw_upload_t * u,
const uint8_t * data,
uint32_t len )

len more bytes.

Parameters
uthe upload
datathe bytes
lenhow many
Returns
FW_OK; FW_ERR_LENGTH, and FAILED, when they run past the announced size; FW_ERR_BUSY when not RECEIVING or sealed

◆ fw_upload_begin()

fw_err_t fw_upload_begin ( fw_upload_t * u,
uint32_t bytes )

A source announces bytes.

Parameters
uthe upload
bytesthe image's bytes
Returns
FW_OK and RECEIVING, or why not, with the state unchanged: FW_ERR_BUSY while RECEIVING, sealed or STAGED, FW_ERR_EMPTY for 0, FW_ERR_TOO_BIG over the slot, FW_ERR_MEMORY for a buffer too small

◆ fw_upload_busy()

bool fw_upload_busy ( const fw_upload_t * u)

Whether the buffer is in use: bytes arriving, or a check under way. A caller frees the buffer of an upload that is neither this nor STAGED.

Parameters
uthe upload
Returns
true while RECEIVING or sealed

◆ fw_upload_checked()

fw_err_t fw_upload_checked ( fw_upload_t * u,
fw_err_t e,
const fw_image_info_t * info )

The second half: the answer of the check over a sealed upload.

Parameters
uthe upload
ewhat fw_image_check() returned
infowhat it filled in
Returns
FW_OK and STAGED, or FAILED with e; FW_ERR_BUSY and IDLE when the upload was discarded during the check, or was not sealed

◆ fw_upload_discard()

void fw_upload_discard ( fw_upload_t * u)

Drop what is received or staged: IDLE. During a check, IDLE once fw_upload_checked() has its answer.

Parameters
uthe upload

◆ fw_upload_end()

fw_err_t fw_upload_end ( fw_upload_t * u,
bool whole )

The source is done; the image is checked at once.

Parameters
uthe upload
wholefalse when the source broke off
Returns
FW_OK and STAGED, or FAILED with the reason: FW_ERR_READ for a source that broke off or sent less than announced, anything fw_image_check() refuses

◆ fw_upload_init()

void fw_upload_init ( fw_upload_t * u,
uint8_t * buf,
uint32_t cap,
uint32_t slot )

An upload into buf of cap bytes, for a slot of slot bytes: IDLE.

Parameters
uthe upload
bufthe buffer, or NULL
capits bytes
slotthe slot's bytes

◆ fw_upload_percent()

unsigned fw_upload_percent ( const fw_upload_t * u)

Received of announced.

Parameters
uthe upload
Returns
percent, 0 to 100

◆ fw_upload_seal()

fw_err_t fw_upload_seal ( fw_upload_t * u,
bool whole )

The first half of fw_upload_end(), for a check run without the caller's lock: the bytes are whole and wait for fw_image_check() over buf and bytes.

Between this and fw_upload_checked() the state stays RECEIVING and fw_upload_busy() is true, a fw_upload_discard() included: the buffer is the check's, and no caller frees it.

Parameters
uthe upload
wholefalse when the source broke off
Returns
FW_OK and checking set; otherwise what fw_upload_end() returns for the same call, with the same state

◆ refuse()

fw_err_t refuse ( fw_upload_t * u,
fw_err_t e )
static

FAILED with e.

Parameters
uthe upload
ethe reason
Returns
e