|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The bench console: command lines read and written as link page requests and replies. More...
#include "page_console.h"#include <stdarg.h>#include <stdio.h>#include <string.h>#include "hitec_wire.h"Data Structures | |
| struct | hitec_args_t |
| The options of send, listen and power, and the bytes of a send. More... | |
Macros | |
| #define | TOKENS_MAX 40u |
| #define | say page_console_say |
| The console's own lines. | |
| #define | NAME(table, v) |
The name of value v in table, or "?". | |
| #define | HST(c, reg) |
The staged HITEC register reg of console c. | |
| #define | RUN_AT(reg) |
Functions | |
| static void | push (page_console_t *c, const char *s, size_t n) |
Append n bytes of s to the output, or drop them and count the loss. | |
| void | page_console_vsay (page_console_t *c, const char *fmt, va_list ap) |
| page_console_say() with a va_list. | |
| void | page_console_say (page_console_t *c, const char *fmt,...) |
| One line of output from outside the console, formatted as printf() formats: the LF is added, and one the text ends with is not doubled. | |
| static size_t | take_out (page_console_t *c, char *buf, size_t n) |
Move n bytes from the head of the output to buf. | |
| size_t | page_console_take (page_console_t *c, char *buf, size_t room) |
Whole lines of output, at most room bytes; the bytes copied. | |
| size_t | page_console_take_part (page_console_t *c, char *buf, size_t room) |
The first room bytes of output, a line cut where the room ends: a line longer than room leaves in pieces, and the rest of it comes first in the next take. | |
| static const char * | name_of (const char *const *names, unsigned count, unsigned v) |
The name of value v from a table of names. | |
| static bool | apply (page_console_t *c, uint8_t op, uint8_t page, uint8_t off, uint8_t n, const uint16_t *in) |
| A read or a write through the link's handlers; the reply. | |
| static bool | read_regs (page_console_t *c, uint8_t page, uint8_t off, uint8_t n, uint16_t *out) |
| Read n registers of a page through the link. | |
| static bool | write_regs (page_console_t *c, uint8_t page, uint8_t off, uint8_t n, const uint16_t *in) |
| A write; false, with the refusal said, when it is not acknowledged. | |
| static bool | parse_u32 (const char *s, uint32_t *out) |
| Parse an unsigned number, decimal or 0x hexadecimal. | |
| static bool | parse_max (const char *s, uint32_t max, uint32_t *out) |
Parse an unsigned number no larger than max. | |
| static const char * | value_of (const char *tok, const char *key) |
"key=value": the value when tok starts with key and '='. | |
| static unsigned | split (char *line, char **tok) |
| Split a line into tokens at spaces and tabs. | |
| static void | say_regs (page_console_t *c, const char *what, uint8_t page, uint8_t off, uint8_t n, const uint16_t *regs) |
| The reply's registers: up to 32 of 7 characters each, so the line is made in two halves of 16 when it is long. | |
| static void | cmd_pages (page_console_t *c) |
| Answer the pages command: one line per page. | |
| static void | cmd_read (page_console_t *c, char **tok, unsigned n) |
| Answer the r command: read n registers and reply with them. | |
| static void | cmd_write (page_console_t *c, char **tok, unsigned n) |
| Answer the w command: write the values and reply with the acknowledgement. | |
| static void | hst32 (page_console_t *c, unsigned lo, uint32_t v) |
| Stage a 32-bit value in two HITEC registers, low word first. | |
| static uint32_t | u32_of (const uint16_t *r, unsigned lo) |
| Read a 32-bit value from two registers, low word first. | |
| static void | say_flags (char *buf, size_t size, uint16_t st) |
| Write the names of the STATE flags set in st, comma separated, or "-". | |
| static void | hitec_report (page_console_t *c, const char *what) |
| What the page says now: the state line, and the capture with its bytes when it holds one. | |
| static void | hitec_command (page_console_t *c, link_hitec_op_t op, uint32_t port, bool key) |
| Stage, name the CRC and the next SEQ, and send the command. | |
| static bool | parse_dec (const char *v, uint16_t *out) |
| dec=none | c:<cmd> | d:<addr> | l:<byte> | |
| static bool | parse_args (page_console_t *c, char **tok, unsigned n, hitec_args_t *a) |
| Parse the options and the bytes of send, listen, power and level. | |
| static void | stage_xfer (page_console_t *c, const hitec_xfer_t *x, uint16_t dec) |
| The staged registers of a transaction; LINE and the supply's are 0. | |
| static bool | parse_port (page_console_t *c, const char *tok, uint32_t *port) |
| Parse a programming port number, 0 to 15. | |
| static void | hitec_open (page_console_t *c, uint32_t port, char **tok, unsigned n) |
| Answer hitec open: OPEN the port with the family, drive and receive mode. | |
| static bool | open_family (page_console_t *c, uint8_t *family) |
| The family of the open line, from the page; false when none is open. | |
| static void | hitec_send (page_console_t *c, uint32_t port, char **tok, unsigned n) |
| Answer hitec send: transmit the bytes in one transaction. | |
| static void | hitec_listen (page_console_t *c, uint32_t port, char **tok, unsigned n, bool power) |
| Answer hitec listen or hitec power, the listen part of it. | |
| static void | hitec_level (page_console_t *c, uint32_t port, char **tok, unsigned n) |
| Answer hitec level: hold the line at a level for a time. | |
| static bool | family_is (page_console_t *c, uint8_t family) |
Whether the open line is of family; says why not. | |
| static void | hitec_classic (page_console_t *c, uint32_t port, char **tok, unsigned n) |
| Answer hitec c: one classic command and its reply. | |
| static void | hitec_d (page_console_t *c, uint32_t port, char **tok, unsigned n) |
| Answer hitec d: one D series read or write. | |
| static void | cmd_hitec (page_console_t *c, char **tok, unsigned n) |
| Answer the hitec command and route it by its subcommand. | |
| static void | cmd_help (page_console_t *c) |
| Answer the help command: the command list. | |
| static void | run_line (page_console_t *c) |
| Run the command line held in the console. | |
| void | page_console_init (page_console_t *c, const link_dev_t *dev) |
An empty console on the pages of dev. | |
| void | page_console_key (page_console_t *c, int ch) |
| One character in. | |
| void | page_console_poll (page_console_t *c) |
| Once a pass: the report of a HITEC operation that has ended. | |
Variables | |
| static const char *const | k_nack [] |
| static const char *const | k_state [] |
| static const char *const | k_op [] |
| static const char *const | k_result [] |
| static const char *const | k_refusal [] |
| static const char *const | k_dec [] = { "NONE", "C", "D", "LISTEN" } |
| static const char *const | k_rx [] |
The bench console: command lines read and written as link page requests and replies.
SPDX-License-Identifier: MIT
| #define HST | ( | c, | |
| reg ) |
The staged HITEC register reg of console c.
| #define NAME | ( | table, | |
| v ) |
| #define RUN_AT | ( | reg | ) |
|
static |
A read or a write through the link's handlers; the reply.
The reply is c->reply.
| c | The console. |
| op | The operation, LINK_OP_READ or LINK_OP_WRITE. |
| page | The page number. |
| off | First register of the window. |
| n | Number of registers. |
| in | The n values to write; NULL for a read. |
|
static |
Answer the help command: the command list.
| c | The console. |
|
static |
Answer the hitec command and route it by its subcommand.
| c | The console. |
| tok | The tokens of the line. |
| n | Number of tokens. |
|
static |
Answer the pages command: one line per page.
| c | The console. |
|
static |
Answer the r command: read n registers and reply with them.
| c | The console. |
| tok | The tokens of the line. |
| n | Number of tokens. |
|
static |
Answer the w command: write the values and reply with the acknowledgement.
| c | The console. |
| tok | The tokens of the line. |
| n | Number of tokens. |
|
static |
Whether the open line is of family; says why not.
A frame of one family on a line of the other goes out at the wrong rate and polarity.
| c | The console. |
| family | The family the command needs. |
|
static |
Answer hitec c: one classic command and its reply.
| c | The console. |
| port | Programming port index. |
| tok | The tokens after the port. |
| n | Number of tokens. |
|
static |
Stage, name the CRC and the next SEQ, and send the command.
| c | The console. |
| op | The operation. |
| port | Programming port index. |
| key | true to put LINK_HITEC_WRITE_KEY in the command. |
|
static |
Answer hitec d: one D series read or write.
| c | The console. |
| port | Programming port index. |
| tok | The tokens after the port. |
| n | Number of tokens. |
|
static |
Answer hitec level: hold the line at a level for a time.
| c | The console. |
| port | Programming port index. |
| tok | The tokens after the port. |
| n | Number of tokens. |
|
static |
Answer hitec listen or hitec power, the listen part of it.
| c | The console. |
| port | Programming port index. |
| tok | The tokens after the port. |
| n | Number of tokens. |
| power | true for hitec power. |
|
static |
Answer hitec open: OPEN the port with the family, drive and receive mode.
| c | The console. |
| port | Programming port index. |
| tok | The tokens after the port. |
| n | Number of tokens. |
|
static |
What the page says now: the state line, and the capture with its bytes when it holds one.
| c | The console. |
| what | The word that opens the report, such as done. |
|
static |
Answer hitec send: transmit the bytes in one transaction.
| c | The console. |
| port | Programming port index. |
| tok | The tokens after the port. |
| n | Number of tokens. |
|
static |
Stage a 32-bit value in two HITEC registers, low word first.
| c | The console. |
| lo | Register number of the low word. |
| v | The value. |
|
static |
The name of value v from a table of names.
| names | The table of names. |
| count | Entries in the table. |
| v | The value to name. |
|
static |
The family of the open line, from the page; false when none is open.
| c | The console. |
| family | Receives the family of the open line. |
| void page_console_init | ( | page_console_t * | c, |
| const link_dev_t * | dev ) |
An empty console on the pages of dev.
| c | The console; zeroed first. A NULL c is ignored. |
| dev | The link device whose pages the console reads and writes. |
| void page_console_key | ( | page_console_t * | c, |
| int | ch ) |
One character in.
CR or LF runs the line.
| c | The console. |
| ch | The character; a value below 0 is ignored, and so is a control character other than CR, LF, BS and DEL. |
| void page_console_poll | ( | page_console_t * | c | ) |
Once a pass: the report of a HITEC operation that has ended.
| c | The console. |
| void page_console_say | ( | page_console_t * | c, |
| const char * | fmt, | ||
| ... ) |
One line of output from outside the console, formatted as printf() formats: the LF is added, and one the text ends with is not doubled.
At most PAGE_CONSOLE_OUT_LINE bytes with the LF; a longer text is cut.
| c | The console. |
| fmt | The printf format. |
| ... | The arguments of fmt. |
| size_t page_console_take | ( | page_console_t * | c, |
| char * | buf, | ||
| size_t | room ) |
Whole lines of output, at most room bytes; the bytes copied.
A line longer than room does not leave: a caller whose room can be smaller than PAGE_CONSOLE_OUT_LINE takes with page_console_take_part().
| c | The console. |
| buf | Receives the bytes. |
| room | Size of buf in bytes. |
| size_t page_console_take_part | ( | page_console_t * | c, |
| char * | buf, | ||
| size_t | room ) |
The first room bytes of output, a line cut where the room ends: a line longer than room leaves in pieces, and the rest of it comes first in the next take.
Any room from 1 byte on moves the output. A caller that takes in parts keeps to this function: page_console_take() leaves a part-taken line where it is until the rest of it fits.
| c | The console. |
| buf | Receives the bytes. |
| room | Size of buf in bytes. |
| void page_console_vsay | ( | page_console_t * | c, |
| const char * | fmt, | ||
| va_list | ap ) |
page_console_say() with a va_list.
| c | The console. |
| fmt | The printf format. |
| ap | The argument list, started by the caller. |
|
static |
Parse the options and the bytes of send, listen, power and level.
| c | The console. |
| tok | The tokens of the line. |
| n | Number of tokens. |
| a | Receives the options and the bytes. |
|
static |
dec=none | c:<cmd> | d:<addr> | l:<byte>
| v | The text after dec=. |
| out | Receives the packed decoder word. |
|
static |
Parse an unsigned number no larger than max.
| s | The text, as parse_u32() reads it. |
| max | The largest value accepted. |
| out | Receives the value. |
|
static |
Parse a programming port number, 0 to 15.
| c | The console. |
| tok | The token. |
| port | Receives the port. |
|
static |
Parse an unsigned number, decimal or 0x hexadecimal.
| s | The text: decimal, or hexadecimal after 0x. |
| out | Receives the value. |
|
static |
Append n bytes of s to the output, or drop them and count the loss.
| c | The console. |
| s | The bytes. |
| n | Number of bytes. |
|
static |
Read n registers of a page through the link.
| c | The console. |
| page | The page number. |
| off | First register of the window. |
| n | Number of registers to read. |
| out | Receives the n register values. |
|
static |
Run the command line held in the console.
| c | The console. |
|
static |
Write the names of the STATE flags set in st, comma separated, or "-".
| buf | Receives the text, NUL-terminated. |
| size | Size of buf in bytes. |
| st | The STATE register value. |
|
static |
The reply's registers: up to 32 of 7 characters each, so the line is made in two halves of 16 when it is long.
| c | The console. |
| what | The word that opens the line, such as data or ack. |
| page | The page number. |
| off | First register of the window. |
| n | Number of registers. |
| regs | The register values. |
|
static |
Split a line into tokens at spaces and tabs.
| line | The line; each separator is replaced by a NUL. |
| tok | Receives a pointer to each token, TOKENS_MAX entries. |
|
static |
The staged registers of a transaction; LINE and the supply's are 0.
| c | The console. |
| x | The transaction to stage. |
| dec | The packed decoder word. |
|
static |
Move n bytes from the head of the output to buf.
| c | The console. |
| buf | Receives the bytes. |
| n | Number of bytes to take from the head of the output. |
|
static |
Read a 32-bit value from two registers, low word first.
| r | The register values. |
| lo | Index of the low word. |
|
static |
"key=value": the value when tok starts with key and '='.
| tok | A token of the line. |
| key | The key to match. |
|
static |
A write; false, with the refusal said, when it is not acknowledged.
| c | The console. |
| page | The page number. |
| off | First register of the window. |
| n | Number of registers to write. |
| in | The n register values. |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |