5 years, 2 months ago.

Timer interrupt priority over TCPSocket Callbacks

I have a Timer Interrupt Routine which runs periodically (1000/sec). I plan on using TCPSocket to receive incoming messages. For obvious reasons, this should be non-blocking.

It is essential that Timer Interrupt Routine takes priority over the TCPSocket Callback. How can I ensure this?

1 Answer

5 years, 2 months ago.

The command you need is: NVIC_SetPriority(<interrupt name>,priority)

Unfortunately this is all platform specific and you don't say which you're using.

Interrupt names depend on the processor used. Priority is an integer, the lower it is the higher the priority. How many bits the priority value has depends on the CPU core being used.

You will need to look in the appropriate file of the mbed library to find out exactly what values you need to use.

e.g. for mbed 2 on the LPC1768 the appropriate data is in the file https://os.mbed.com/users/mbed_official/code/mbed-dev/file/0387e8f68319/targets/TARGET_NXP/TARGET_LPC176X/device/LPC17xx.h/

There it lists all of the interrupts and also defines __NVIC_PRIO_BITS to indicate that the priority values are 5 bits long.

So to set the ehternet on that part to the lowest priority would be NVIC_SetPriority(ENET_IRQn,0x1f);

If you want to change the priority of the Ticker then you need to know which hardware timer it's using, the file https://os.mbed.com/users/mbed_official/code/mbed-dev/file/0387e8f68319/targets/TARGET_NXP/TARGET_LPC176X/us_ticker.c/ sets Tickers/Timers to use Timer3