Skip to content

[Help] Multiple software tasks of the same type #1110

@vafu

Description

@vafu

Hi, I'm very new to rtic and rust in general, so might be missing something.

I'm developing a midi processor. One of the tasks to solve is sending a timed stream of data spawned from multiple sources. simplified example.

    #[task(shared = [midi_bus], priority = 2)]
    async fn midi_dispatch(
        mut cx: midi_dispatch::Context,
        mut r: Receiver<'static, MidiMsg, MIDI_CHANNEL_CAPACITY>,
    ) -> ! {
        loop {
            let msg = r.recv().await.unwrap();
            cx.shared.midi_bus.lock(|midi| {
                midi.send(&msg);
            });
            slide(&mut cx.shared.midi_bus, msg).await;
        }
    }


   async fn slide(midi_bus: &mut midi_bus_that_needs_to_be_locked<'static>, msg: MidiMsg) {
       loop {
              // .. calculate pitch bend
              midi_bus.lock(|bus| bus.send(&bend_msg));
              Systick::delay(10.millis()).await;
              // return at some point
       }
   }

sw task midi_dispatch sends midi data via uart (abstracted away in midi_bus), and spawns a special processor function slide.
slide produces a stream of messages at a fixed rate (10 millis) and sends them via midi_bus.

midi_dispatch uses a channel to receive midi data.
problem arises when sender provides messages quicker than slide returns -- midi_dispatch rate is clamped by slide's latency.

if I'll extract slide in a separate SW task -- app panics, since in rtic v2 it's not possible to spawn multiple of the same sw tasks while previous one did not complete.

I can imagine in rticv1 I could define a capacity to task pool, but what's the correct way to achieve this with rtic v2?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions