Skip to main content

airfrog_rpc/client/
mod.rs

1//! Client for RPC communication between Host and Target using two channels:
2//! - Command channel: Host writes commands, Target reads
3//! - Response channel: Target writes responses, Host reads
4//!
5//! See [`AsyncRpcClient`] for async client usage, for example on a Host.
6
7// Copyright (C) 2025 Piers Finlayson <piers@piers.rocks>
8//
9// MIT License
10
11#[cfg(feature = "async")]
12pub mod futures;
13
14#[cfg(feature = "async")]
15pub use futures::{AsyncDelay, AsyncRpcClient};
16
17/// Configuration for creating an RPC Client.
18/// - `Direct`: Create channels with explicit sizes
19/// - `FromTarget`: Create channels by reading sizes from target memory,
20///   normally used by Hosts.
21#[derive(Debug)]
22pub enum RpcClientConfig {
23    Direct {
24        /// Pointer to command channel in target memory
25        cmd_ch_ptr: u32,
26        /// Size of command channel in bytes
27        cmd_ch_size: usize,
28        /// Pointer to response channel in target memory
29        rsp_ch_ptr: u32,
30        /// Size of response channel in bytes
31        rsp_ch_size: usize,
32    },
33    FromTarget {
34        /// Pointer to command channel in target memory
35        cmd_ch_ptr: u32,
36        /// Pointer to response channel in target memory
37        rsp_ch_ptr: u32,
38    },
39}
40
41#[cfg(feature = "async")]
42/// Configuration for how to create a channel
43#[derive(Debug, Clone)]
44enum ChannelConfig {
45    /// Create channel with explicit size
46    Direct { ptr: u32, size: usize },
47    /// Create channel by reading size from target
48    FromTarget { ptr: u32 },
49}