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

The programmer for servos by Hitec: the session driven through the link's task, the state the overlay draws and the messages it says. See hitec_prog.h. More...

#include "hitec_prog.h"
#include <string.h>
#include "hitec_prog_int.h"
#include "hitec_rx_link.h"

Enumerations

enum  { W_NONE = 0 , W_ANSWER , W_OUTCOME }
 What a command waits for. More...

Functions

void hitec_prog_gate_init (hitec_prog_gate_t *g)
 Sets up a gate: no pass offered.
void hitec_prog_gate_offer (hitec_prog_gate_t *g, uint32_t id)
 The pass of command id is there to be taken.
static bool gate_take (hitec_prog_gate_t *g, uint32_t id)
 The pass of id, taken by whoever asks first.
bool hitec_prog_gate_claim (hitec_prog_gate_t *g, uint32_t id)
 The link's task, with command id out of its queue.
bool hitec_prog_gate_revoke (hitec_prog_gate_t *g, uint32_t id)
 The model gives command id up.
hitec_prog_level_t hitec_prog_level (unsigned id)
 The level of message id.
hitec_prog_msg_id_t hpg_say2 (hitec_prog_t *p, hitec_prog_msg_id_t id, unsigned arg, unsigned reg)
 Say message id.
static hitec_prog_msg_id_t say (hitec_prog_t *p, hitec_prog_msg_id_t id, unsigned arg)
 Say message id with one argument.
static bool stop_seen (const hitec_prog_t *p)
 Whether a stop at either end cut what ran.
static void refusal_say (hitec_prog_t *p, unsigned ref)
 The message of a refusal of the page.
static void outcome_say (hitec_prog_t *p, const hitec_link_outcome_t *o)
 The message of a request's outcome that did not end as asked.
void hitec_prog_init (hitec_prog_t *p)
 Sets up the programmer: nothing fed, D series, the default supply.
void hitec_prog_gate_set (hitec_prog_t *p, hitec_prog_gate_t *g)
 The gate the link's task claims each command at; NULL for none.
static void session_gone (hitec_prog_t *p)
 The session ends: nothing of it is in mode any more.
static void send (hitec_prog_t *p, hitec_prog_cmd_t *cmd)
 Put a command on its way to the link's task. Every caller has moved off ST_IDLE first, and every end of a command's wait goes back to it: a model in ST_IDLE has no command out.
static void send_bare (hitec_prog_t *p, uint8_t kind, uint8_t port)
 A command of kind on the port the model works on.
bool hitec_prog_take (hitec_prog_t *p, hitec_prog_cmd_t *out)
 The next command for the link's task.
static void enter (hitec_prog_t *p)
 Start the entry into programming mode on the open port.
static void read_all (hitec_prog_t *p)
 Start a read of the full set.
static void read_done (hitec_prog_t *p)
 A full read ended well: the servo, its model and the message.
void hpg_ses_say (hitec_prog_t *p, hitec_ses_t r)
 The message of a session operation that did not end well.
static void ses_done (hitec_prog_t *p, hitec_ses_t r)
 A session operation ended with r.
static void give_up (hitec_prog_t *p)
 A command that ended without an outcome: nothing of it ran, or what ran is not known. A step out ends as one that did not run.
static void not_started (hitec_prog_t *p, unsigned answer)
 The link's task answered the command awaited with answer, not OK: it did not start.
static void on_outcome (hitec_prog_t *p, const hitec_link_outcome_t *o)
 An outcome of the request awaited.
static void take_answers (hitec_prog_t *p)
 The answer to the command awaited, and the outcome of its request.
static void take_timeouts (hitec_prog_t *p)
 A command nobody answered, and a request with no outcome.
static void follow (hitec_prog_t *p)
 The session follows the page: a port that is no longer this model's ends it.
void hpg_pump (hitec_prog_t *p)
 The session's next step goes out, or its operation's end is taken.
void hitec_prog_feed (hitec_prog_t *p, const hitec_prog_feed_t *f)
 The feed of this frame: answers and outcomes are taken, the session's next step goes out, and the state follows the page.
hitec_prog_state_t hitec_prog_state (const hitec_prog_t *p)
 Where the programmer is.
void hitec_prog_bench_armed (hitec_prog_t *p, bool armed)
 The bench is armed or asked to arm.
bool hitec_prog_series_set (hitec_prog_t *p, uint8_t series)
 The series of the next CONNECT; taken in PWM only. A change of series drops what the last read found: hitec_prog_servo() and hitec_prog_model() return NULL until the next read.
uint8_t hitec_prog_series (const hitec_prog_t *p)
 The series: the session's while the port is held, else the one the next CONNECT uses.
void hitec_prog_supply_set (hitec_prog_t *p, uint16_t mv, uint16_t ma)
 The programming voltage and current limit the next CONNECT asks.
void hitec_prog_supply_caps (hitec_prog_t *p, uint16_t max_mv, uint16_t max_ma)
 The SUPPLY screen's limits, 0 for none.
uint16_t hitec_prog_mv (const hitec_prog_t *p)
 The voltage a POWER of the next CONNECT asks: the setting, at most HITEC_PROG_MV_MAX and at least HITEC_PROG_MV_MIN.
uint16_t hitec_prog_ma (const hitec_prog_t *p)
 The current limit a POWER of the next CONNECT asks, HITEC_PROG_MA_MIN to HITEC_PROG_MA_MAX.
bool hitec_prog_mv_capped (const hitec_prog_t *p)
 Whether the setting is above HITEC_PROG_MV_MAX and is taken as it.
static bool bench_armed (const hitec_prog_t *p)
 Whether the bench is armed or asked to arm.
hitec_prog_msg_id_t hpg_held_idle (const hitec_prog_t *p, bool safe)
 Whether an operation of the held port may start now.
static hitec_prog_msg_id_t from_pwm (const hitec_prog_t *p)
 What keeps the tester's port from a CONNECT.
hitec_prog_msg_id_t hitec_prog_connect (hitec_prog_t *p)
 CONNECT on the SERVO screen's programming port.
hitec_prog_msg_id_t hitec_prog_read (hitec_prog_t *p)
 READ ALL.
hitec_prog_msg_id_t hitec_prog_leave (hitec_prog_t *p)
 LEAVE: programming mode ends and the port goes back to PWM.
hitec_prog_msg_id_t hitec_prog_clear (hitec_prog_t *p)
 CLEAR the page's STOPPED flag, then the entry or the read.
void hitec_prog_abort (hitec_prog_t *p)
 ABORT the running operation; the port stays held.
hitec_prog_msg_id_t hitec_prog_release (hitec_prog_t *p)
 RELEASE PORT: CLOSE the port another session holds.
const hitec_prog_msg_t * hitec_prog_message (const hitec_prog_t *p)
 The last message.
uint8_t hitec_prog_port (const hitec_prog_t *p)
 The programming port the overlay names: the session's while one holds it, the held port of another session, else the tester's; 0 while the tester drives the standard outputs.
uint8_t hitec_prog_pin (const hitec_prog_t *p)
 The GPIO that port drives: the HITEC page's while it holds the line, else the PROG page's.
bool hitec_prog_precharge (const hitec_prog_t *p)
 Whether the line receives by PRECHARGE: the open line's mode while the page holds one, else the mode its next OPEN takes.
bool hitec_prog_on_port (const hitec_prog_t *p)
 Whether the SERVO screen's tester drives a programming port.
bool hitec_prog_port_taken (const hitec_link_readout_t *rd)
 The link task's view: the page holds a port, or a request runs.
bool hitec_prog_holds_port (const hitec_prog_t *p)
 Whether the session or another one holds a port, or a request of this model is on its way: no other programmer opens and the bench takes no arm.
bool hitec_prog_in_mode (const hitec_prog_t *p)
 Whether the servo is in programming mode.
bool hitec_prog_stopped (const hitec_prog_t *p)
 Whether the page's STOPPED flag is set on this panel's port.
bool hitec_prog_rail (const hitec_prog_t *p)
 Whether a PD mini answers the page (LINK_HT_F_RAIL).
const hitec_image_t * hitec_prog_servo (const hitec_prog_t *p)
 The servo as the last full read found it; NULL with none.
const hitec_model_t * hitec_prog_model (const hitec_prog_t *p)
 The model of that servo; NULL with none.
uint8_t hitec_prog_layout (const hitec_prog_t *p)
 The layout the values are decoded with: the model's, or the series' measured one before a read.
bool hitec_prog_progress (const hitec_prog_t *p, unsigned *done, unsigned *total)
 The progress of the running read.
unsigned hitec_prog_retry_code (const hitec_prog_t *p)
 The decoder's code of the last failed try of the running transaction, while it goes again.

Detailed Description

The programmer for servos by Hitec: the session driven through the link's task, the state the overlay draws and the messages it says. See hitec_prog.h.

Hitec is a name or trademark of its owner; it is used here only to say which servos this module works with.

SPDX-License-Identifier: MIT

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

What a command waits for.

Enumerator
W_NONE 

no command is out

W_ANSWER 

the link's task has not answered it

W_OUTCOME 

the module took it; its outcome is owed

Function Documentation

◆ bench_armed()

bool bench_armed ( const hitec_prog_t * p)
static

Whether the bench is armed or asked to arm.

Parameters
pThe programmer.
Returns
true when it is.

◆ enter()

void enter ( hitec_prog_t * p)
static

Start the entry into programming mode on the open port.

Classic: the supply is cycled HITEC_SES_OFF_MS. D series: the supply is switched on, off 0ms, where a PD mini answers the page; without one the servo runs on the supply as it is.

Parameters
pThe programmer.

◆ follow()

void follow ( hitec_prog_t * p)
static

The session follows the page: a port that is no longer this model's ends it.

Parameters
pThe programmer.

◆ from_pwm()

hitec_prog_msg_id_t from_pwm ( const hitec_prog_t * p)
static

What keeps the tester's port from a CONNECT.

Parameters
pThe programmer.
Returns
HITEC_PROG_MSG_NONE, or why not.

◆ gate_take()

bool gate_take ( hitec_prog_gate_t * g,
uint32_t id )
static

The pass of id, taken by whoever asks first.

Parameters
gThe gate.
idThe command's id.
Returns
true when the pass was taken.

◆ give_up()

void give_up ( hitec_prog_t * p)
static

A command that ended without an outcome: nothing of it ran, or what ran is not known. A step out ends as one that did not run.

Parameters
pThe programmer.

◆ hitec_prog_abort()

void hitec_prog_abort ( hitec_prog_t * p)

ABORT the running operation; the port stays held.

Parameters
pThe programmer.

◆ hitec_prog_bench_armed()

void hitec_prog_bench_armed ( hitec_prog_t * p,
bool armed )

The bench is armed or asked to arm.

Parameters
pThe programmer.
armedtrue while it is.

◆ hitec_prog_clear()

hitec_prog_msg_id_t hitec_prog_clear ( hitec_prog_t * p)

CLEAR the page's STOPPED flag, then the entry or the read.

Parameters
pThe programmer.
Returns
HITEC_PROG_MSG_NONE when it starts, else the message said.

◆ hitec_prog_connect()

hitec_prog_msg_id_t hitec_prog_connect ( hitec_prog_t * p)

CONNECT on the SERVO screen's programming port.

Parameters
pThe programmer.
Returns
HITEC_PROG_MSG_NONE when it starts, else the message said.

◆ hitec_prog_feed()

void hitec_prog_feed ( hitec_prog_t * p,
const hitec_prog_feed_t * f )

The feed of this frame: answers and outcomes are taken, the session's next step goes out, and the state follows the page.

Parameters
pThe programmer.
fThe feed.

◆ hitec_prog_gate_claim()

bool hitec_prog_gate_claim ( hitec_prog_gate_t * g,
uint32_t id )

The link's task, with command id out of its queue.

Parameters
gThe gate.
idThe command's id.
Returns
true when the command is to be carried out; false: it is dropped, with no answer.

◆ hitec_prog_gate_init()

void hitec_prog_gate_init ( hitec_prog_gate_t * g)

Sets up a gate: no pass offered.

Parameters
gThe gate.

◆ hitec_prog_gate_offer()

void hitec_prog_gate_offer ( hitec_prog_gate_t * g,
uint32_t id )

The pass of command id is there to be taken.

Parameters
gThe gate.
idThe command's id.

◆ hitec_prog_gate_revoke()

bool hitec_prog_gate_revoke ( hitec_prog_gate_t * g,
uint32_t id )

The model gives command id up.

Parameters
gThe gate.
idThe command's id.
Returns
true when the command is not carried out and never is.

◆ hitec_prog_gate_set()

void hitec_prog_gate_set ( hitec_prog_t * p,
hitec_prog_gate_t * g )

The gate the link's task claims each command at; NULL for none.

With none, a command nobody answers within HITEC_PROG_START_MS counts as one that may have run: an ABORT follows it.

Parameters
pThe programmer.
gThe gate.

◆ hitec_prog_holds_port()

bool hitec_prog_holds_port ( const hitec_prog_t * p)

Whether the session or another one holds a port, or a request of this model is on its way: no other programmer opens and the bench takes no arm.

Parameters
pThe programmer.
Returns
true while held.

◆ hitec_prog_in_mode()

bool hitec_prog_in_mode ( const hitec_prog_t * p)

Whether the servo is in programming mode.

Parameters
pThe programmer.
Returns
true after an entry, until a leave.

◆ hitec_prog_init()

void hitec_prog_init ( hitec_prog_t * p)

Sets up the programmer: nothing fed, D series, the default supply.

Parameters
pThe programmer.

◆ hitec_prog_layout()

uint8_t hitec_prog_layout ( const hitec_prog_t * p)

The layout the values are decoded with: the model's, or the series' measured one before a read.

Parameters
pThe programmer.
Returns
hitec_layout_t.

◆ hitec_prog_leave()

hitec_prog_msg_id_t hitec_prog_leave ( hitec_prog_t * p)

LEAVE: programming mode ends and the port goes back to PWM.

Taken while the port is this panel's and nothing runs, STOPPED or not.

Parameters
pThe programmer.
Returns
HITEC_PROG_MSG_NONE when it starts, else the message said.

◆ hitec_prog_level()

hitec_prog_level_t hitec_prog_level ( unsigned id)

The level of message id.

Parameters
idhitec_prog_msg_id_t.
Returns
hitec_prog_level_t.

◆ hitec_prog_ma()

uint16_t hitec_prog_ma ( const hitec_prog_t * p)

The current limit a POWER of the next CONNECT asks, HITEC_PROG_MA_MIN to HITEC_PROG_MA_MAX.

Parameters
pThe programmer.
Returns
mA.

◆ hitec_prog_message()

const hitec_prog_msg_t * hitec_prog_message ( const hitec_prog_t * p)

The last message.

Parameters
pThe programmer.
Returns
The message.

◆ hitec_prog_model()

const hitec_model_t * hitec_prog_model ( const hitec_prog_t * p)

The model of that servo; NULL with none.

Parameters
pThe programmer.
Returns
The model.

◆ hitec_prog_mv()

uint16_t hitec_prog_mv ( const hitec_prog_t * p)

The voltage a POWER of the next CONNECT asks: the setting, at most HITEC_PROG_MV_MAX and at least HITEC_PROG_MV_MIN.

Parameters
pThe programmer.
Returns
mV.

◆ hitec_prog_mv_capped()

bool hitec_prog_mv_capped ( const hitec_prog_t * p)

Whether the setting is above HITEC_PROG_MV_MAX and is taken as it.

Parameters
pThe programmer.
Returns
true when capped.

◆ hitec_prog_on_port()

bool hitec_prog_on_port ( const hitec_prog_t * p)

Whether the SERVO screen's tester drives a programming port.

Parameters
pThe programmer.
Returns
true when it does.

◆ hitec_prog_pin()

uint8_t hitec_prog_pin ( const hitec_prog_t * p)

The GPIO that port drives: the HITEC page's while it holds the line, else the PROG page's.

Parameters
pThe programmer.
Returns
The pin, HITEC_PROG_NO_PIN when not known.

◆ hitec_prog_port()

uint8_t hitec_prog_port ( const hitec_prog_t * p)

The programming port the overlay names: the session's while one holds it, the held port of another session, else the tester's; 0 while the tester drives the standard outputs.

Parameters
pThe programmer.
Returns
The port, from 0.

◆ hitec_prog_port_taken()

bool hitec_prog_port_taken ( const hitec_link_readout_t * rd)

The link task's view: the page holds a port, or a request runs.

Parameters
rdThe module's readout.
Returns
true while the bench takes no arm and no supply change.

◆ hitec_prog_precharge()

bool hitec_prog_precharge ( const hitec_prog_t * p)

Whether the line receives by PRECHARGE: the open line's mode while the page holds one, else the mode its next OPEN takes.

Parameters
pThe programmer.
Returns
true for PRECHARGE.

◆ hitec_prog_progress()

bool hitec_prog_progress ( const hitec_prog_t * p,
unsigned * done,
unsigned * total )

The progress of the running read.

Parameters
pThe programmer.
doneReceives the addresses read.
totalReceives the addresses it reads.
Returns
true while a read runs.

◆ hitec_prog_rail()

bool hitec_prog_rail ( const hitec_prog_t * p)

Whether a PD mini answers the page (LINK_HT_F_RAIL).

Parameters
pThe programmer.
Returns
true when one does.

◆ hitec_prog_read()

hitec_prog_msg_id_t hitec_prog_read ( hitec_prog_t * p)

READ ALL.

Parameters
pThe programmer.
Returns
HITEC_PROG_MSG_NONE when it starts, else the message said.

◆ hitec_prog_release()

hitec_prog_msg_id_t hitec_prog_release ( hitec_prog_t * p)

RELEASE PORT: CLOSE the port another session holds.

Parameters
pThe programmer.
Returns
HITEC_PROG_MSG_NONE when it starts, else the message said.

◆ hitec_prog_retry_code()

unsigned hitec_prog_retry_code ( const hitec_prog_t * p)

The decoder's code of the last failed try of the running transaction, while it goes again.

Parameters
pThe programmer.
Returns
hitec_rx_t, 0 while no try failed.

◆ hitec_prog_series()

uint8_t hitec_prog_series ( const hitec_prog_t * p)

The series: the session's while the port is held, else the one the next CONNECT uses.

Parameters
pThe programmer.
Returns
hitec_family_t.

◆ hitec_prog_series_set()

bool hitec_prog_series_set ( hitec_prog_t * p,
uint8_t series )

The series of the next CONNECT; taken in PWM only. A change of series drops what the last read found: hitec_prog_servo() and hitec_prog_model() return NULL until the next read.

Parameters
pThe programmer.
serieshitec_family_t.
Returns
true when taken.

◆ hitec_prog_servo()

const hitec_image_t * hitec_prog_servo ( const hitec_prog_t * p)

The servo as the last full read found it; NULL with none.

Parameters
pThe programmer.
Returns
The image.

◆ hitec_prog_state()

hitec_prog_state_t hitec_prog_state ( const hitec_prog_t * p)

Where the programmer is.

Parameters
pThe programmer.
Returns
The state.

◆ hitec_prog_stopped()

bool hitec_prog_stopped ( const hitec_prog_t * p)

Whether the page's STOPPED flag is set on this panel's port.

Parameters
pThe programmer.
Returns
true while stopped.

◆ hitec_prog_supply_caps()

void hitec_prog_supply_caps ( hitec_prog_t * p,
uint16_t max_mv,
uint16_t max_ma )

The SUPPLY screen's limits, 0 for none.

Parameters
pThe programmer.
max_mvThe voltage limit, mV.
max_maThe current limit, mA.

◆ hitec_prog_supply_set()

void hitec_prog_supply_set ( hitec_prog_t * p,
uint16_t mv,
uint16_t ma )

The programming voltage and current limit the next CONNECT asks.

Parameters
pThe programmer.
mvThe voltage, mV.
maThe current limit, mA.

◆ hitec_prog_take()

bool hitec_prog_take ( hitec_prog_t * p,
hitec_prog_cmd_t * out )

The next command for the link's task.

Parameters
pThe programmer.
outReceives it.
Returns
true when one was taken.

◆ hpg_held_idle()

hitec_prog_msg_id_t hpg_held_idle ( const hitec_prog_t * p,
bool safe )

Whether an operation of the held port may start now.

Parameters
pThe programmer.
safetrue for one that sends frames: not with STOP latched, not armed, not on a STOPPED port.
Returns
HITEC_PROG_MSG_NONE when it may, else why not.

◆ hpg_pump()

void hpg_pump ( hitec_prog_t * p)

The session's next step goes out, or its operation's end is taken.

Parameters
pThe programmer.

◆ hpg_say2()

hitec_prog_msg_id_t hpg_say2 ( hitec_prog_t * p,
hitec_prog_msg_id_t id,
unsigned arg,
unsigned reg )

Say message id.

Parameters
pThe programmer.
idhitec_prog_msg_id_t.
argIts argument.
regIts second argument.
Returns
id.

◆ hpg_ses_say()

void hpg_ses_say ( hitec_prog_t * p,
hitec_ses_t r )

The message of a session operation that did not end well.

Parameters
pThe programmer.
rIts result.

◆ not_started()

void not_started ( hitec_prog_t * p,
unsigned answer )
static

The link's task answered the command awaited with answer, not OK: it did not start.

Parameters
pThe programmer.
answerhitec_link_start_t.

◆ on_outcome()

void on_outcome ( hitec_prog_t * p,
const hitec_link_outcome_t * o )
static

An outcome of the request awaited.

Parameters
pThe programmer.
oThe outcome.

◆ outcome_say()

void outcome_say ( hitec_prog_t * p,
const hitec_link_outcome_t * o )
static

The message of a request's outcome that did not end as asked.

Parameters
pThe programmer.
oThe outcome.

◆ read_all()

void read_all ( hitec_prog_t * p)
static

Start a read of the full set.

Parameters
pThe programmer.

◆ read_done()

void read_done ( hitec_prog_t * p)
static

A full read ended well: the servo, its model and the message.

Parameters
pThe programmer.

◆ refusal_say()

void refusal_say ( hitec_prog_t * p,
unsigned ref )
static

The message of a refusal of the page.

Parameters
pThe programmer.
reflink_hitec_refusal_t.

◆ say()

hitec_prog_msg_id_t say ( hitec_prog_t * p,
hitec_prog_msg_id_t id,
unsigned arg )
static

Say message id with one argument.

Parameters
pThe programmer.
idhitec_prog_msg_id_t.
argIts argument.
Returns
id.

◆ send()

void send ( hitec_prog_t * p,
hitec_prog_cmd_t * cmd )
static

Put a command on its way to the link's task. Every caller has moved off ST_IDLE first, and every end of a command's wait goes back to it: a model in ST_IDLE has no command out.

Parameters
pThe programmer.
cmdThe command; its id is given here.

◆ send_bare()

void send_bare ( hitec_prog_t * p,
uint8_t kind,
uint8_t port )
static

A command of kind on the port the model works on.

Parameters
pThe programmer.
kindhitec_prog_cmd_kind_t.
portThe programming port.

◆ ses_done()

void ses_done ( hitec_prog_t * p,
hitec_ses_t r )
static

A session operation ended with r.

Parameters
pThe programmer.
rIts result.

◆ session_gone()

void session_gone ( hitec_prog_t * p)
static

The session ends: nothing of it is in mode any more.

Parameters
pThe programmer.

◆ stop_seen()

bool stop_seen ( const hitec_prog_t * p)
static

Whether a stop at either end cut what ran.

Parameters
pThe programmer.
Returns
true when the page or the panel is stopped.

◆ take_answers()

void take_answers ( hitec_prog_t * p)
static

The answer to the command awaited, and the outcome of its request.

Parameters
pThe programmer.

◆ take_timeouts()

void take_timeouts ( hitec_prog_t * p)
static

A command nobody answered, and a request with no outcome.

Parameters
pThe programmer.