Odd interrupt execution.

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by rogerwilson on Fri May 24 02:56:33 MST 2013
[FONT=Arial]I have a piece of code which is basically:[/FONT]

[FONT=Courier New]#include rit.h[/FONT]

[FONT=Courier New]extern volatile rit_counter1;[/FONT]
[FONT=Courier New]extern volatile rit_counter2;[/FONT]

[FONT=Courier New]while (1) {[/FONT]

[FONT=Courier New]if (rit_counter1 >= 1) {[/FONT]
[FONT=Courier New]   some stuff ...[/FONT]
[FONT=Courier New]   rit_counter1 = 0;[/FONT]
[FONT=Courier New]}[/FONT]

[FONT=Courier New]if (rit_counter2 >= interval) {[/FONT]
[FONT=Courier New]      some other stuff ...[/FONT]
[FONT=Courier New]      rit_counter2 = 0;[/FONT]
[FONT=Courier New]}[/FONT]

[FONT=Arial]'interval' is setup elsewhere to be 4.[/FONT]
[FONT=Arial]The rit_counter variables are incremented in the RIT ISR i.e.[/FONT]

[FONT=Courier New]volatile uint32_t rit_counter1 = 0;[/FONT]
[FONT=Courier New]volatile uint32_t rit_counter2 = 0;[/FONT]

[FONT=Courier New]void RIT_IRQHandler (void)[/FONT]
[FONT=Courier New]{   [/FONT]
[FONT=Courier New]  rit_counter1++;[/FONT]
[FONT=Courier New]  rit_counter2 ++;[/FONT]
[FONT=Courier New]  LPC_RIT->RICTRL |= (0x1<<0);[/FONT]
[FONT=Courier New]return;[/FONT]
[FONT=Courier New]}[/FONT]

[FONT=Arial]Whilst developing the code (optimisation off) there were times when only the second "if" section would run. I never got to the bottom of why but with a bit of fiddling about and apparently needless modifications it went away and I have some perfectly good working code. If however the optimisation level is anything but -O0, the code behaves very oddly. The first "if"statement never runs and the second "if" statement seems to run at twice the frequency it should.[/FONT]

[FONT=Arial]Does anyone have any view on why this might be please? Is there anything inherent in the way I'm using the RIT interrupt and 2 similar but separate variales to control the execution that's in some way dodgy?[/FONT]