Page 1 of 1

BASIC interrupt priorities

Posted: Wed May 04, 2016 2:43 pm
by maray
>from the help line

>Within ARMBASIC how are the Interrupt priorities currently set, mainly in reference to Systemtick, Uarts EINT0 and timers.
>Can WAIT() and WAITMICRO() be used freely within an interrupt service routine?

For almost all chips I've worked with,
SysTick and other system interrupts are not part of the priority scheme.

I saw a case recently (which we don't use) where Systick, HardFault, etc had a priority register.
You would need to verify in the Interrupt Priority Register section of the individual User Manual.

I think Systick, HardFault, etc receive the highest priority.
I did a test to verify but that was many years ago.

By default all other priorities are FF, lowest.

Bellow is a basic example to set priorities to different levels.
Note: the lower 3 bits of each 8 bit value are not used so the actual priority is >> 3.

Code: Select all

'  Interrupt Priority Registers from LPC40xx.bas
#define NVIC_IP0    *&HE000E400
#define NVIC_IP1    *&HE000E404
#define NVIC_IP2    *&HE000E408
#define NVIC_IP3    *&HE000E40C
#define NVIC_IP4    *&HE000E410
#define NVIC_IP5    *&HE000E414
#define NVIC_IP6    *&HE000E418
#define NVIC_IP7    *&HE000E41C
#define NVIC_IP8    *&HE000E420
#define NVIC_IP9    *&HE000E424
#define NVIC_IP10    *&HE000E428

sub Config
    ' set interrupt priorities
    ' Timer1   priority = 0 highest
    ' Timer2   priority = 4 (&H20 >> 3)
    ' Timer3   priority = 6 (&H30 >> 3)
    ' set all other interrupt priorities to lowest
    NVIC_IP0 = &H2000FFFF
    NVIC_IP1 = &HFFFFFF30
    NVIC_IP2 = &HFFFFFFFF
    NVIC_IP3 = &HFFFFFFFF
    NVIC_IP4 = &HFFFFFFFF
    NVIC_IP5 = &HFFFFFFFF
    NVIC_IP6 = &HFFFFFFFF
    NVIC_IP7 = &HFFFFFFFF
    NVIC_IP8 = &HFFFFFFFF
    NVIC_IP9 = &HFFFFFFFF
    NVIC_IP10 = &HFFFFFFFF
' other stuff .....
end sub

Re: BASIC interrupt priorities

Posted: Wed May 04, 2016 2:51 pm
by basicchip
>Can WAIT() and WAITMICRO() be used freely within an interrupt service routine?

WAIT() requires the Systick interrupt to be serviced, by default this will preempt other interrupts, though you can change that, but I don't recommend that.

WAITMICRO() does not need the SysTick interrupt, so that would be a better choice.

BUT Interrupt code should be kept to a minimum and it is BAD practice to wait for anything inside an interrupt !!!

Re: BASIC interrupt priorities

Posted: Fri May 20, 2016 11:08 pm
by AMDlloydsp
I do a great deal of interrupt-serviced I/O on SuperPro boards, on real-time automated explosives manufacturing machinery.

I find it most beneficial to just set flags and "get the hell out", rather than doing 'productive work' (or especially DELAYS) inside an IRQ routine!

Depending upon your IRQ rate (which you establish, of course), the service routines alone (regardless of any 'real' processing within them) can usurp a substantial portion of your available processing time, et. al.

Lloyd