 |
 |
| View previous topic :: View next topic |
| Author |
Message |
dmitrboristuk
Joined: 26 Sep 2020 Posts: 75
|
| Software interrupts in Q84 series |
Posted: Fri Jan 30, 2026 12:55 pm |
|
|
| Have a nice day everyone! How to use software interrupts SWIF in the Q84 series. What is their main purpose? Where can they be useful? |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20031
|
|
Posted: Sun Feb 01, 2026 3:24 am |
|
|
First thing to understand is that you can use software interrupts even on
chips that don't offer these. For example, if you want this ability on a chip
without them, you can look through what peripherals you are not using, and
if (for example), you do not use the timer2 interrupt you can setup an
interrupt handler for this, leave the hardware disabled, and when you want
the software interrupt, just set the interrupt flag for this. Since the hardware
is disabled, this flag will not be set otherwise. Result a software interrupt.
Now the key point of software interrupts is where you want a piece of
handler code to be called, but there is no hardware event to trigger it.
So (for example), you want to call some tidy up code whenever the main
code completes all it's jobs, or you want to send data, when you are
not busy handling some other devices. Since there is no hardware
event to signal this, you can't use a normal interrupt to be the trigger.
Now on a lot of chips there are hardware triggered software interrupts,
so for example division by zero can be used to trigger a maths error
interrupt handler on the DSPIC's, and this is called a software interrupt,
but is in this case being triggered by the maths hardware. A truly software
triggered version would be where (for example), you have buffers for
several hardware devices, and just want occasionally to call code to
check that these are not getting close to overflowing. So you setup a
software interrupt to do this check and trigger this at the end of key parts
of the code. Now, where software interrupt become 'distinct' from just a
normal handler routine, is on chips which have hardware interrupt priorities.
Here you can (for example) have a software interrupt with it's priority set
above that of your normal serial handler, and at intervals in the code trigger
this, to have a handler called that can override this hardware event.
Historically software interrupts were used for things like BIOS operations
on the Intel PC. So when you wanted to do disk I/O or screen I/O, your
code called such an interrupt. This had priority above the normal code,
but below important hardware events. Result nice controlled priorities
on how things were done.
The Q84 family have an interrupt controller that supports vectored
interrupts, so is one of the most basic PIC's that could make sensible
use of this ability. However given that there are only two interrupt priority
levels, the ability is rather restricted.
The software interrupt becomes particularly important, if you run something
like an RTOS on your chip. Here, since you are effectively 'multi tasking',
having handler code that can have a priority above the main code becomes
really useful. |
|
 |
dmitrboristuk
Joined: 26 Sep 2020 Posts: 75
|
|
Posted: Mon Feb 02, 2026 1:52 pm |
|
|
| Ttelmah, Thank you for your detailed answer, this is indeed a useful feature. |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|