This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How do do parallel, concurrent operations?

I am reading data over the duration of 3 seconds on SPI, but while I'm doing that, I need to send that data over RF using microESB library.

I need to make sure the read is not blocking RF send and vice versa. The reading is the most imporant. So I imagine some kind of a big buffer that holds all the data I read, where a task independently reads what's filled in the buffer at it's own pace. As you know transfers can fail, and take substantially longer than a quick SPI read. Right now I read from SPI with 10 ms nrf_delay_ms() in a loop over 3 seconds. I also have the possibility to have the SPI interrupting when it's internal ring buffer is full, doing a large read in short bursts.

Thanks!

Parents
  • As there is only one core, you can not do more than one thing at the same time. However there are other ways to do multiple things in order to have seemingly concurrent threads.

    • You can use interrupt routines (or event handlers) and use different priorities so that a high priority interrupt will be run even tough a low priority interrupt or main context code is being run.
    • You can use flags to signal data between functions running in the interrupt context and main context (or use the scheduler or another synchronization mechanism).
    • For some applications it may be sensible to use a RTOS (e.g. FreeRTOS) which provide you with a simple way to create tasks ("threads") at different priorities and communicate between tasks using message queues etc.

    For the scenario you have described you could do several other things. One possible way of doing this is something like this:

    1. let a SPI event handler write data to a ring buffer.
    2. set a flag indicating that the buffer has been updated
    3. from your main loop you can check that flag, and run another function (call it "thread" if you like) responsible for sending data
    4. from the send-data function, read data from the ring-buffer and write it to the micro_esb library.
  • The SPI device actually has it's own internal ring buffer, but smaller than I am going to send, so I think I will just use it's interrupt to read the whole buffer in one go, reducing time.

    But what is an SPI event handler? Does it run in parallel? And running another function from my main loop will halt the main loop and possibly hang the "SPI Event Handler" also? Are there some truly parallel event handler / calls I can do here? I would love some function names! :)

    Thanks!

Reply
  • The SPI device actually has it's own internal ring buffer, but smaller than I am going to send, so I think I will just use it's interrupt to read the whole buffer in one go, reducing time.

    But what is an SPI event handler? Does it run in parallel? And running another function from my main loop will halt the main loop and possibly hang the "SPI Event Handler" also? Are there some truly parallel event handler / calls I can do here? I would love some function names! :)

    Thanks!

Children
No Data
Related