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

Acknowledged write and read sequences over a link port; see link_port.h. More...

#include "link_port.h"
#include <string.h>
#include "link_can.h"

Functions

static bool usable (const link_host_t *h, const link_port_t *port, const link_msg_t *reply)
 Check that a link exchange has everything it needs.
bool link_write_acked (link_host_t *h, const link_port_t *port, uint8_t page, uint8_t offset, uint8_t count, const uint16_t *regs, link_msg_t *reply)
 Write count registers of page from offset, one frame of up to LINK_CAN_REGS_PER_FRAME registers per exchange, each acknowledged before the next is sent.
bool link_read_window (link_host_t *h, const link_port_t *port, uint8_t page, uint8_t offset, uint8_t count, link_msg_t *reply)
 Read count registers of page from offset in one exchange.

Detailed Description

Acknowledged write and read sequences over a link port; see link_port.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ link_read_window()

bool link_read_window ( link_host_t * h,
const link_port_t * port,
uint8_t page,
uint8_t offset,
uint8_t count,
link_msg_t * reply )

Read count registers of page from offset in one exchange.

True when it was answered; reply is the data or the refusal.

Parameters
hThe host state.
portThe transport and clock.
pagePage number to read.
offsetFirst register within the page.
countNumber of registers to read.
replyReceives the data or the refusal.
Returns
true when it was answered, else false.

◆ link_write_acked()

bool link_write_acked ( link_host_t * h,
const link_port_t * port,
uint8_t page,
uint8_t offset,
uint8_t count,
const uint16_t * regs,
link_msg_t * reply )

Write count registers of page from offset, one frame of up to LINK_CAN_REGS_PER_FRAME registers per exchange, each acknowledged before the next is sent.

True when the far end answered every frame sent. reply is then one of two things: an ACK (acknowledge) for the whole window, carrying what the far end stored for each register, or the NACK (negative acknowledge) of the first frame it refused, with that frame's offset. Nothing is sent after a refusal.

False when a frame ended unanswered, when a request is already outstanding on h, or when the window does not fit a page; reply is then not meaningful.

The frames before a refused or unanswered one stay applied at the far end: the transport has no rollback. A page that must change whole is written through pages that prepare it; see LINK_PAGE_BIND.

Parameters
hThe host state.
portThe transport and clock.
pagePage number to write.
offsetFirst register within the page.
countNumber of registers, 1 to LINK_MAX_REGS.
regsThe count values to write.
replyReceives the ACK or the NACK.
Returns
true when every frame sent was answered, else false.

◆ usable()

bool usable ( const link_host_t * h,
const link_port_t * port,
const link_msg_t * reply )
static

Check that a link exchange has everything it needs.

Parameters
hThe host state.
portThe transport and clock.
replyWhere the answer goes.
Returns
true when h, port, port->exchange, port->now_ms and reply are all non-NULL.