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

The panel's half of the IOmcu update. More...

#include "link_update_host.h"
#include <stddef.h>
#include <string.h>
#include "link_crc.h"
#include "link_msg.h"

Enumerations

enum  x_t { X_NONE = 0 , X_OK , X_NACK }
 How an exchange ended.

Functions

static void start (link_uph_t *u, const uint8_t *img, uint32_t len, link_uph_phase_t phase, uint32_t now_ms)
 Set up an update run: clear the state and record the image.
static void done (link_uph_t *u, uint8_t result)
 End the update with a result.
void link_uph_check (link_uph_t *u, const uint8_t *img, uint32_t len, uint32_t now_ms)
 Find out whether the IOmcu runs the build in img: this end's build hash, then the IOmcu's over its running slot.
void link_uph_update (link_uph_t *u, const uint8_t *img, uint32_t len, uint32_t now_ms)
 Send img to the slot that is not running, check it, start it and buy it.
void link_uph_confirm (link_uph_t *u, uint32_t now_ms)
 Buy an image found on trial.
uint16_t link_uph_permille (const link_uph_t *u)
 Blocks committed, in thousandths of the image: 0 to 1000.
static x_t read_regs (link_host_t *h, const link_port_t *port, uint8_t page, uint8_t offset, uint8_t count, link_msg_t *reply)
static x_t command (link_host_t *h, const link_port_t *port, uint16_t cmd, uint16_t a0, uint16_t a1, link_msg_t *reply)
 Send a command to the UPDATE_CTL page and classify the answer.
static bool missed (link_uph_t *u, const link_port_t *port)
 An exchange went unanswered; true when the link has been silent for LINK_UPH_LOST_MS and the update ends.
static void heard (link_uph_t *u)
 An exchange was answered.
static void refused (link_uph_t *u, link_host_t *h, const link_port_t *port, const link_msg_t *nack)
 The refusal's reason, read back; the result REFUSED.
static bool wait_gate (link_uph_t *u, uint32_t now_ms)
 A command the store's gate refused: wait for it, up to LINK_UPH_BUSY_MS from the first refusal.
static void start_over (link_uph_t *u, uint32_t now_ms)
 The IOmcu lost the session: from block 0 again, or give up.
static void resync (link_uph_t *u, uint8_t from)
 Enter the RESYNC phase, remembering the phase it was entered from.
static void step_check_hash (link_uph_t *u)
static void step_check_ask (link_uph_t *u, link_host_t *h, const link_port_t *port, uint32_t now_ms)
 CHECK_ASK step: read the IOmcu's slot and ask it to hash.
static void step_check_wait (link_uph_t *u, link_host_t *h, const link_port_t *port, uint32_t now_ms)
 CHECK_WAIT step: read the IOmcu's digest of its running slot.
static void step_prepare (link_uph_t *u, link_host_t *h, const link_port_t *port, uint32_t now_ms)
static void step_begin (link_uph_t *u, link_host_t *h, const link_port_t *port, uint32_t now_ms)
 BEGIN step: send the BEGIN command with the image length.
static void block_regs (const link_uph_t *u, uint16_t block, uint16_t *regs, uint16_t *crc)
 Build the registers and CRC of one block of the image as sent.
static void step_send (link_uph_t *u, link_host_t *h, const link_port_t *port, uint32_t now_ms)
 SEND step: write one block to UPDATE_DATA, then COMMIT it.
static void step_resync (link_uph_t *u, link_host_t *h, const link_port_t *port, uint32_t now_ms)
 Where the IOmcu stands, after an exchange went unanswered or a command was refused: carry on from the block it expects, check what it has, or start over from block 0 when it lost the session.
static void step_finish (link_uph_t *u, link_host_t *h, const link_port_t *port, uint32_t now_ms)
 FINISH step: send the expected digest, then the FINISH command.
static void step_verify (link_uph_t *u, link_host_t *h, const link_port_t *port, uint32_t now_ms)
 VERIFY step: read the IOmcu's verdict on the image it received.
static void step_activate (link_uph_t *u, link_host_t *h, const link_port_t *port, uint32_t now_ms)
 ACTIVATE step: send the ACTIVATE command and wait for the restart.
static void step_restarting (link_uph_t *u, link_host_t *h, const link_port_t *port, uint32_t now_ms)
 RESTARTING step: read identity and slot until the new image shows.
static void step_buy (link_uph_t *u, link_host_t *h, const link_port_t *port)
 BUY step: send the BUY command and read back the slot.
link_uph_phase_t link_uph_step (link_uph_t *u, link_host_t *h, const link_port_t *port)
 One step; returns the phase it leaves the update in.
bool link_uph_mismatch_probe (link_uph_mismatch_t *m, bool mismatch)
 One identity probe: mismatch whether an IOmcu of another protocol major answered it.
bool link_uph_mismatch_answers (const link_uph_mismatch_t *m)
 Whether the last probe was answered by a mismatched IOmcu.
void link_uph_mismatch_rearm (link_uph_mismatch_t *m)
 An update ended: the next mismatched answer owes the check again.

Detailed Description

The panel's half of the IOmcu update.

See link_update_host.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ block_regs()

void block_regs ( const link_uph_t * u,
uint16_t block,
uint16_t * regs,
uint16_t * crc )
static

Build the registers and CRC of one block of the image as sent.

Parameters
uThe update state.
blockBlock number, 0 to blocks - 1.
regsReceives LINK_UPD_DATA_COUNT registers.
crcReceives the CRC-16 of the block's bytes.

◆ command()

x_t command ( link_host_t * h,
const link_port_t * port,
uint16_t cmd,
uint16_t a0,
uint16_t a1,
link_msg_t * reply )
static

Send a command to the UPDATE_CTL page and classify the answer.

Parameters
hThe panel's link state.
portThe transport and clock.
cmdThe command, an LINK_UPD_CMD_* value.
a0First argument.
a1Second argument.
replyReceives the answer.
Returns
X_NONE when unanswered, X_OK for ACK, X_NACK for a refusal.

◆ done()

void done ( link_uph_t * u,
uint8_t result )
static

End the update with a result.

Parameters
uThe update state.
resultThe result, a link_uph_result_t.

◆ heard()

void heard ( link_uph_t * u)
static

An exchange was answered.

Parameters
uThe update state.

◆ link_uph_check()

void link_uph_check ( link_uph_t * u,
const uint8_t * img,
uint32_t len,
uint32_t now_ms )

Find out whether the IOmcu runs the build in img: this end's build hash, then the IOmcu's over its running slot.

Ends SAME, DIFFERENT, TRIAL, NEEDS_USB, NO_ANSWER or REFUSED.

A session found in the IOmcu – this panel's own, from before it restarted or lost the link – is ended with ABORT first: nobody sends its blocks any more, and it would hold ARM. An ACTIVATE found is waited out for LINK_UPH_HASH_MS: the restart it leads to ends it.

Parameters
uThe update state.
imgThe image to compare with the IOmcu's running slot.
lenLength of img in bytes.
now_msThe current time, in ms.

◆ link_uph_confirm()

void link_uph_confirm ( link_uph_t * u,
uint32_t now_ms )

Buy an image found on trial.

Ends UPDATED, NO_ANSWER or REFUSED.

Parameters
uThe update state.
now_msThe current time, in ms.

◆ link_uph_mismatch_answers()

bool link_uph_mismatch_answers ( const link_uph_mismatch_t * m)

Whether the last probe was answered by a mismatched IOmcu.

Parameters
mThe mismatch state; NULL gives false.
Returns
true when the last probe was answered by a mismatched IOmcu.

◆ link_uph_mismatch_probe()

bool link_uph_mismatch_probe ( link_uph_mismatch_t * m,
bool mismatch )

One identity probe: mismatch whether an IOmcu of another protocol major answered it.

True when the build check is owed now: the first such answer since a probe nobody or a matching IOmcu answered, or the first after link_uph_mismatch_rearm().

Parameters
mThe mismatch state.
mismatchtrue when the answer came from an IOmcu of another major.
Returns
true when the build check is owed now.

◆ link_uph_mismatch_rearm()

void link_uph_mismatch_rearm ( link_uph_mismatch_t * m)

An update ended: the next mismatched answer owes the check again.

Parameters
mThe mismatch state; NULL is ignored.

◆ link_uph_permille()

uint16_t link_uph_permille ( const link_uph_t * u)

Blocks committed, in thousandths of the image: 0 to 1000.

Parameters
uThe update state; NULL or no blocks gives 0.
Returns
Committed blocks times 1000 over all blocks.

◆ link_uph_step()

link_uph_phase_t link_uph_step ( link_uph_t * u,
link_host_t * h,
const link_port_t * port )

One step; returns the phase it leaves the update in.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.
Returns
The phase after the step.

◆ link_uph_update()

void link_uph_update ( link_uph_t * u,
const uint8_t * img,
uint32_t len,
uint32_t now_ms )

Send img to the slot that is not running, check it, start it and buy it.

Ends UPDATED or with the reason it stopped.

Parameters
uThe update state.
imgThe image to send.
lenLength of img in bytes.
now_msThe current time, in ms.

◆ missed()

bool missed ( link_uph_t * u,
const link_port_t * port )
static

An exchange went unanswered; true when the link has been silent for LINK_UPH_LOST_MS and the update ends.

Parameters
uThe update state.
portThe transport and clock.
Returns
true when the update ended (NO_ANSWER), else false.

◆ refused()

void refused ( link_uph_t * u,
link_host_t * h,
const link_port_t * port,
const link_msg_t * nack )
static

The refusal's reason, read back; the result REFUSED.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.
nackThe refusal.

◆ resync()

void resync ( link_uph_t * u,
uint8_t from )
static

Enter the RESYNC phase, remembering the phase it was entered from.

Parameters
uThe update state.
fromThe phase the resync is entered from.

◆ start()

void start ( link_uph_t * u,
const uint8_t * img,
uint32_t len,
link_uph_phase_t phase,
uint32_t now_ms )
static

Set up an update run: clear the state and record the image.

Parameters
uThe update state.
imgThe image, or NULL.
lenLength of img in bytes.
phaseThe phase to start in.
now_msThe current time, in ms; starts the phase's wait.

◆ start_over()

void start_over ( link_uph_t * u,
uint32_t now_ms )
static

The IOmcu lost the session: from block 0 again, or give up.

Parameters
uThe update state.
now_msThe current time, in ms.

◆ step_activate()

void step_activate ( link_uph_t * u,
link_host_t * h,
const link_port_t * port,
uint32_t now_ms )
static

ACTIVATE step: send the ACTIVATE command and wait for the restart.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.
now_msThe current time, in ms.

◆ step_begin()

void step_begin ( link_uph_t * u,
link_host_t * h,
const link_port_t * port,
uint32_t now_ms )
static

BEGIN step: send the BEGIN command with the image length.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.
now_msThe current time, in ms.

◆ step_buy()

void step_buy ( link_uph_t * u,
link_host_t * h,
const link_port_t * port )
static

BUY step: send the BUY command and read back the slot.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.

◆ step_check_ask()

void step_check_ask ( link_uph_t * u,
link_host_t * h,
const link_port_t * port,
uint32_t now_ms )
static

CHECK_ASK step: read the IOmcu's slot and ask it to hash.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.
now_msThe current time, in ms.

◆ step_check_wait()

void step_check_wait ( link_uph_t * u,
link_host_t * h,
const link_port_t * port,
uint32_t now_ms )
static

CHECK_WAIT step: read the IOmcu's digest of its running slot.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.
now_msThe current time, in ms.

◆ step_finish()

void step_finish ( link_uph_t * u,
link_host_t * h,
const link_port_t * port,
uint32_t now_ms )
static

FINISH step: send the expected digest, then the FINISH command.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.
now_msThe current time, in ms.

◆ step_restarting()

void step_restarting ( link_uph_t * u,
link_host_t * h,
const link_port_t * port,
uint32_t now_ms )
static

RESTARTING step: read identity and slot until the new image shows.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.
now_msThe current time, in ms.

◆ step_resync()

void step_resync ( link_uph_t * u,
link_host_t * h,
const link_port_t * port,
uint32_t now_ms )
static

Where the IOmcu stands, after an exchange went unanswered or a command was refused: carry on from the block it expects, check what it has, or start over from block 0 when it lost the session.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.
now_msThe current time, in ms.

◆ step_send()

void step_send ( link_uph_t * u,
link_host_t * h,
const link_port_t * port,
uint32_t now_ms )
static

SEND step: write one block to UPDATE_DATA, then COMMIT it.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.
now_msThe current time, in ms.

◆ step_verify()

void step_verify ( link_uph_t * u,
link_host_t * h,
const link_port_t * port,
uint32_t now_ms )
static

VERIFY step: read the IOmcu's verdict on the image it received.

Parameters
uThe update state.
hThe panel's link state.
portThe transport and clock.
now_msThe current time, in ms.

◆ wait_gate()

bool wait_gate ( link_uph_t * u,
uint32_t now_ms )
static

A command the store's gate refused: wait for it, up to LINK_UPH_BUSY_MS from the first refusal.

True while still waiting.

Parameters
uThe update state.
now_msThe current time, in ms.
Returns
true while still waiting; false when the wait ended (BUSY).