Can we make Swift 6 easier?

Microcontrollers are concurrent systems, too. That's the point I was making.

Pre-emptive multitasking is all about code being interrupted so other code can run. Even if you don't have an operating system, you'll still have hardware interrupts (e.g. a button was pressed, a hardware timer triggered, or some buffer is empty and needs to be filled).

An interrupt is a signal (generally called an "interrupt request") to the CPU to immediately begin executing different code, code that is written to respond to the cause of the interrupt. "Immediately" can be as soon as the end of the current instruction, in the best case. The time between the generation of the interrupt request and the entry into the ISR is called the "interrupt latency," and faster (lower latency) is always better. The CPU will remember the location of the next instruction it was going to execute by storing that instruction address in a register or memory location, and will then jump directly to the code designated by the programmer for that particular interrupt. [...]

A microcontroller CPU will be designed to respond to a number of different interrupt sources (perhaps 10 to 100 sources, typically), and each source can have specific user-written code which executes when that interrupt triggers. The code that executes for an interrupt is called the "interrupt service routine" or ISR. The "now you see it, now you don't" heading [of this article] refers to what you would see if you were watching the code execute in slow motion. The program counter would be moving from one instruction to the next, and then when the interrupt triggered the PC would suddenly end up in some totally different area of the program (the entry point of the ISR). Then, when the ISR was complete, the PC would just as suddenly be pointing back to the next instruction, as if nothing had happened.

Embedded Related: Introduction to Microcontrollers - Interrupts

Nothing about this requires multiprocessors.

For instance, consider the PIC10F320 - a 6/8 pin MCU which you can buy for 59 Euro cents even without a bulk discount:

  • Only 35 Instructions to Learn:
    • All single-cycle instructions, except branches
  • Operating Speed:
    • DC – 16 MHz clock input
    • DC – 250ns instruction cycle
  • Eight-Level Deep Hardware Stack
  • Interrupt Capability :point_left:
  • Processor Self-Write/Read access to Program
  • Up to 512 Words of Flash Program Memory [Note: that's on the 322. The 320 only has 256]
  • 64 Bytes Data Memory
  • High-Endurance Flash Data Memory (HEF)
    • 128B of nonvolatile data storage
    • 100K erase/write cycles

Even this is a concurrent system (it will also probably never run Swift, either - it's designed for hand-written assembly; hence the "only 35 instructions to learn").

7 Likes