3 ms·
There are microcontrollers that cost a penny. Admittedly, even some of those have DMA. But it is wholly legitimate for a main program to be a two instruction lo
by moloch-hai 4y ago
There are microcontrollers that cost a penny. Admittedly, even some of those have DMA. But it is wholly legitimate for a main program to be a two instruction loop "a: sleep; jump a", and all the work is done in interrupt context. That is not to claim it is better; rather, in a microcontroller, whatever works, works.
- sgtnoodle 4y agoIndeed. It doesn't really matter as long as the firmware reliably does what it needs to do. A lot of MCUs only have one CPU, and so interrupts are one of the features to allow multi-tasking in a predictable way. If you only have one thing to do, then go ahead and stick it in a main loop. If you only have two things to do, then spending a bunch of CPU cycles in an interrupt handler might not be a problem at all. If you're working on a sufficiently complex embedded system with a bunch of competing real-time goals, you learn to be very careful with what your CPU is doing at any given time. Quite often, "inefficient" interrupt based or bit-banged peripheral drivers are the right answer, even if the hardware supports DMA. It all depends on the complexity of the application and how much time and money you have.