Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protothreading: Virtually parallel execution #9

Open
Jatoxo opened this issue May 16, 2021 · 0 comments
Open

Protothreading: Virtually parallel execution #9

Jatoxo opened this issue May 16, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@Jatoxo
Copy link
Collaborator

Jatoxo commented May 16, 2021

Introduction

Since we only have one core to work with on our Atmel 2560, we need to find a solution to run things in parallel. This is called protothreading (At least according to some guy's article I read).

We need this sort of concurrency for many things, for example for cycling the RGB Led through some colors while operating the UI, or for scrolling a list entry while, well, not worrying about having to do that in the list loop. We could also use it for polling for input in a background "thread" (this would require an input rewrite).

Description

The main keyword here is interrupts. The 2560 has a total of 6 timers, that's three more than the usual on more basic Arduino models. Because of that, these timers aren't used by most libraries and are free for us to use. Every timer is capable of outputting a overflow interrupt, which triggers an IRQ on the processor every time it overflows. We can use this to periodically call a method, no matter the current state of our program, to check up on our protothreads or "routines" and execute them if need be.

Every routine needs to have the following properties:

  • A frequency, a delay that specifies in what intervals this routines wants to be run
  • A condition, the condition that specifies whether this routine wants to be run, or not
  • A run method, the method that runs when the frequency delay has passed and the condition is true
  • (A break condition), the condition that specifies when this routine would like to be removed completely from the list of routines

The last one is in brackets because this could be handled by whoever added the routine, it doesn't need to be handled by the routine itself, though it is probably not bad to implement something like it.

@Jatoxo Jatoxo added the enhancement New feature or request label May 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant