Execution of callback routines of interrupts (i.e. timer1)

 Question

What are the allowed operations and execution duration of callback functions?
How often an interrupt event can occur?

 Answer

Overview on interrupt callback

If planning an interrupt callback you have to consider this facts:

As all interrupts have the same priority (except the UART interrupt) it is possible, that our callback has to wait, till radio, scheduler (timer0),timer1, i/o callback or uart interrupt is executed. It is not possible to guaranty a minimum time from triggering any interrupt till execution of the interrupt service routine.

An interrupt callback will be executed within the interrupt handler. So you have to be carefull what the callback does generally these rules apply

– Do not stay in the callback function too long (not more than 100 us because that takes too much time away from the scheduler, see more info on the scheduler in the DolphinAPI Manual)

– Do not call other API functions than io_getDigital or io_getPort in callback function

– Do not switch the registerbank.

– Do not use overlaying and optimizing in callback function.

– You are allowed to allocate local variables

– You are allowed to read from flash using code[]

– You are allowed to change global variables of the code but before be sure to set them to volatile. For more info on volatile see KEILs Manual on Cx51.

Callback duration

As mentioned before: Do not stay in the callback function too long. It is important to:

  • measure how long the execution takes

  • be sure that the interrupt event will not occur in shorter period then the execution takes

For example this code:

uint8 tempDigitalOutputState; void callback(void) { io_getDigital(SCLKDIO_1, &tempDigitalOutputState); io_setDigital(SCLKDIO_1, 1-tempDigitalOutputState); return; }

Is a common callback. The execution of this can be measured by the KEILs uVision Simulator

First set the breakpoint of the simulator on the function start and start debug simulator.

\\

When the execution stops at our breakpoint point reset the stop watch (right mouse click on the stop watch)

step the code to the end of the function and see the stop watch result.

KEILs uVision has a complete description of Dolphin instruction set so the showed stop watch result is reliable. I this case our callback function executes 24,38 us. This also means that the interrupt event can occur tops every 25 us.
For more details and support visit KEILs uVision Support page.

There is a possibility to slightly increase the speed of the callback function. You can place the variable in the internal data i.e.

uint8 tempDigitalOutputState; //to uint8 data tempDigitalOutputState;

Variables placed in DATA are handled much faster as variable placed in XDATA (default memory space). The execution of our example callback function is then reduced to 22,13 us.

For more information make sure to read the KEILs Manual about memory configuration of the 8051.

REFERENCES:

 Related Products

  • DolphinAPI