Skip to main content

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.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.
BundleContext
Context passed to bundle providers when building resources.
BundleIndex
Index identifying a resource bundle in the active mission.
Owned
Lightweight wrapper used when a task needs to take ownership of a resource.
ResourceBindingMap
Static mapping between user-defined binding ids and resource keys.
ResourceKey
Typed identifier for a resource entry.
ResourceManager
Manages the concrete resources available to tasks and bridges.
ThreadPoolBundle

Enums§

ThreadPoolId

Traits§

NamedResourceBundleDecl
Optional name metadata for resource bundles.
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.
ResourceBundleDecl
Trait implemented by bundle providers to declare their resource id enum.
ResourceId
Trait implemented by resource id enums generated by bundle_resources!.