|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
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. | |
|
static |
Build the registers and CRC of one block of the image as sent.
| u | The update state. |
| block | Block number, 0 to blocks - 1. |
| regs | Receives LINK_UPD_DATA_COUNT registers. |
| crc | Receives the CRC-16 of the block's bytes. |
|
static |
Send a command to the UPDATE_CTL page and classify the answer.
| h | The panel's link state. |
| port | The transport and clock. |
| cmd | The command, an LINK_UPD_CMD_* value. |
| a0 | First argument. |
| a1 | Second argument. |
| reply | Receives the answer. |
|
static |
End the update with a result.
| u | The update state. |
| result | The result, a link_uph_result_t. |
|
static |
An exchange was answered.
| u | The update state. |
| 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.
| u | The update state. |
| img | The image to compare with the IOmcu's running slot. |
| len | Length of img in bytes. |
| now_ms | The current time, in ms. |
| void link_uph_confirm | ( | link_uph_t * | u, |
| uint32_t | now_ms ) |
Buy an image found on trial.
Ends UPDATED, NO_ANSWER or REFUSED.
| u | The update state. |
| now_ms | The current time, in ms. |
| bool link_uph_mismatch_answers | ( | const link_uph_mismatch_t * | m | ) |
Whether the last probe was answered by a mismatched IOmcu.
| m | The mismatch state; NULL gives false. |
| 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().
| m | The mismatch state. |
| mismatch | true when the answer came from an IOmcu of another major. |
| void link_uph_mismatch_rearm | ( | link_uph_mismatch_t * | m | ) |
An update ended: the next mismatched answer owes the check again.
| m | The mismatch state; NULL is ignored. |
| uint16_t link_uph_permille | ( | const link_uph_t * | u | ) |
Blocks committed, in thousandths of the image: 0 to 1000.
| u | The update state; NULL or no blocks gives 0. |
| 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.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
| 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.
| u | The update state. |
| img | The image to send. |
| len | Length of img in bytes. |
| now_ms | The current time, in ms. |
|
static |
An exchange went unanswered; true when the link has been silent for LINK_UPH_LOST_MS and the update ends.
| u | The update state. |
| port | The transport and clock. |
|
static |
The refusal's reason, read back; the result REFUSED.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
| nack | The refusal. |
|
static |
Enter the RESYNC phase, remembering the phase it was entered from.
| u | The update state. |
| from | The phase the resync is entered from. |
|
static |
Set up an update run: clear the state and record the image.
| u | The update state. |
| img | The image, or NULL. |
| len | Length of img in bytes. |
| phase | The phase to start in. |
| now_ms | The current time, in ms; starts the phase's wait. |
|
static |
The IOmcu lost the session: from block 0 again, or give up.
| u | The update state. |
| now_ms | The current time, in ms. |
|
static |
ACTIVATE step: send the ACTIVATE command and wait for the restart.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
| now_ms | The current time, in ms. |
|
static |
BEGIN step: send the BEGIN command with the image length.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
| now_ms | The current time, in ms. |
|
static |
BUY step: send the BUY command and read back the slot.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
|
static |
CHECK_ASK step: read the IOmcu's slot and ask it to hash.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
| now_ms | The current time, in ms. |
|
static |
CHECK_WAIT step: read the IOmcu's digest of its running slot.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
| now_ms | The current time, in ms. |
|
static |
FINISH step: send the expected digest, then the FINISH command.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
| now_ms | The current time, in ms. |
|
static |
RESTARTING step: read identity and slot until the new image shows.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
| now_ms | The current time, in 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.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
| now_ms | The current time, in ms. |
|
static |
SEND step: write one block to UPDATE_DATA, then COMMIT it.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
| now_ms | The current time, in ms. |
|
static |
VERIFY step: read the IOmcu's verdict on the image it received.
| u | The update state. |
| h | The panel's link state. |
| port | The transport and clock. |
| now_ms | The current time, in 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.
| u | The update state. |
| now_ms | The current time, in ms. |