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

A write of any width, one frame in flight at a time. More...

#include <stdbool.h>
#include <stdint.h>
#include "link_host.h"
#include "link_msg.h"

Go to the source code of this file.

Data Structures

 How a request reaches the far end and its answer comes back. More...

Functions

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

A write of any width, one frame in flight at a time.

link_host_write() builds one request, and the CAN (Controller Area Network) mapping renders a request wider than LINK_CAN_REGS_PER_FRAME (4) registers as several frames sent back to back. The IOmcu's controller buffers 2 received frames and is read from a polled loop, so the 8 frames of a 32-register page arrive faster than a loop that is busy for one pass can take them, and the frame that finds both buffers full is gone.

link_write_acked() sends the same registers as one request per frame and waits for each acknowledgement before it builds the next. At most one request frame is on its way at any time, so a slow pass at the far end delays a frame and cannot lose one to a full buffer.

The transport and the clock are the caller's, handed in as a link_port_t, so the sequence runs on the host against a modelled bus.

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.