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.uart0" }
),
],
tasks: [
( id: "telemetry", type: "app::TelemetryTask",
resources: { bus: "board.telemetry_bus" }
),
],
)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> {
type Binding = Binding;
fn from_bindings(mgr: &'r mut ResourceManager, map: Option<&ResourceBindingMap<Self::Binding>>) -> CuResult<Self> {
let key = map.expect("bus binding").get(Binding::Bus).expect("bus").typed();
Ok(Self { bus: mgr.borrow(key)? })
}
}
pub fn new(_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. - Bundle
Context - Context passed to bundle providers when building resources.
- Bundle
Index - Index identifying a resource bundle in the active mission.
- Owned
- Lightweight wrapper used when a task needs to take ownership of a resource.
- Resource
Binding Map - Static mapping between user-defined binding ids and resource keys.
- Resource
Key - Typed identifier for a resource entry.
- Resource
Manager - Manages the concrete resources available to tasks and bridges.
- Thread
Pool Bundle
Enums§
Traits§
- Resource
Bindings - 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" }). - Resource
Bundle - Bundle providers implement this trait to populate the
ResourceManagerwith concrete resources for a given bundle id. - Resource
Bundle Decl - Trait implemented by bundle providers to declare their resource id enum.
- Resource
Id - Trait implemented by resource id enums generated by
bundle_resources!.