hyperkineticOP•

Found in this thread where u/jringstad and u/playaspec duke it out. u/jringstad insists the AVR can't do preemptive multitasking, but the library u/playaspec links to seems to fit the bill. Anyway, I thought I'd share. I'm always amazed by the things people make these processors do!

5
EkriirkEAVR Noduino•

So long as the CPU/hardware can have a periodic interrupt (watchdog timer) it's doable.

5
verdantmiles•

Welcome to reddit where lots of people say lots of dumb things.

3
uzimonkey•

There's no reason an AVR can't do this, but there's two things that come to mind:

  • And AVR has little memory and no memory management unit. It can't do "real" multitasking with separate address spaces and virtual memory and all that jazz. In other words, it can't run what would be considered a modern OS. It can switch tasks pretty easily by setting a timer interrupt, saving the state of one program and restoring the state of another program. In other words, the very definition of preemptive multitasking. The only thing required to this is the ability to have an interrupt on a timer and to save and restore the state of a program (in this case, likely just the program counter and they share registers by convention?).

  • Most people would not want to do this. This is antithetical to most tasks microcontrollers are typically doing. You cannot ensure timing, response to external events, etc in a preemptive multitasking environment so depending on what you're doing this is simply not appropriate. Maybe the right word is not you "can't" do this, but rather you "shouldn't" do this or "wouldn't want to" do this.

  • I'm not going to read that whole thread, but it seems like one of them is confusing multitasking with symmetric multiprocessing (SMP). Then a nerdfight ensues and now no one is happy.

1†
TheCreat•

I have no idea why you're being downvoted. That is good (and correct) information...

-1
[deleted]•

[deleted]

1
EternityForestuno•

There's actually quite a few multitasking kernels for the AVR, including chibios and freertos, but this one seems a little more efficient and easier to use than the rest. at the expense of being avr specific. Nice find!

3
DStoo•

ChibiOS is kind of awesome.

1
nixfu•

There are a few libraries out there that use the main loop and interrupts to simulate multitasking.

1