Module resource

Module resource 

Source
Expand description

Resource descriptors and utilities to hand resources to tasks and bridges. User view: in copperconfig.ron, map the binding names your tasks/bridges expect to the resources exported by your board bundle. Exclusive things (like a serial port) should be bound once; shared things (like a telemetry bus Arc) can be bound to multiple consumers.

(
    resources: [ ( id: "board", provider: "board_crate::BoardBundle" ) ],
    bridges: [
        ( id: "crsf", type: "cu_crsf::CrsfBridge<SerialPort, SerialError>",
          resources: { serial: "board.serial0" } // pick whichever serial port you want
        ),
    ],
    tasks: [
        ( id: "telemetry", type: "app::TelemetryTask",
          resources: { bus: "board.telemetry_bus" } // shared: borrowed
        ),
    ],
)

Writing your own task/bridge? Add a small Resources struct and implement ResourceBindings to pull the names you declared:

pub struct TelemetryResources<'r> { pub bus: Borrowed<'r, TelemetryBus> }
impl<'r> ResourceBindings<'r> for TelemetryResources<'r> {
    fn from_bindings(mgr: &'r mut ResourceManager, map: Option<&ResourceMapping>) -> CuResult<Self> {
        let key = map.expect("bus binding").get("bus").expect("bus").typed();
        Ok(Self { bus: mgr.borrow(key)? })
    }
}
pub fn new_with(_cfg: Option<&ComponentConfig>, res: TelemetryResources<'_>) -> CuResult<Self> {
    Ok(Self { bus: res.bus })
}

Otherwise, use config to point to the right board resource and you’re done.

Structs§

Borrowed
Wrapper used when a task needs to borrow a resource that remains managed by the ResourceManager.
Owned
Lightweight wrapper used when a task needs to take ownership of a resource.
ResourceDecl
Static declaration of a single resource path bound to a key.
ResourceKey
Typed identifier for a resource entry.
ResourceManager
Manages the concrete resources available to tasks and bridges.
ResourceMapping
Static mapping between user-defined binding names (e.g. “bus”, “irq”) and resource keys. Backed by a slice to avoid runtime allocation.
ResourceProvider
Static metadata describing how to create a bundle of resources.
ThreadPoolBundle

Traits§

ResourceBindings
Trait implemented by resource binding structs passed to task/bridge constructors. Implementors pull the concrete resources they need from the ResourceManager, using the symbolic mapping provided in the Copper config (resources: { name: "bundle.resource" }).
ResourceBundle
Bundle providers implement this trait to populate the ResourceManager with concrete resources for a given bundle id.