Syntax error in Simplicity Studio when declaring interrupts?
11/334/2018 | 06:09 PM
Question:
Why do I receive syntax errors in Simplicity Studio when defining an interrupt? The code compiles and works correctly, but declaring an interrupt, such as this one, gives a syntax error in Studio:
This occurs since Simplicity Studio uses a generic C syntax parser when looking for syntax errors in code. It doesn't understand compiler-specific C code, like that used by Keil C51 to define an interrupt function - the 'interrupt' keyword and interrupt number after the function declaration aren't standard C, so it throws a syntax error. Keil, however, when the project is compiled, understands this syntax and compiles the code correctly.
We have a work-around for this visual error by the way of macros in si_toolchain.h. If you use the SI_INTERRUPT(name, vector) macro, it will generate different declarations based on which tool is viewing the code. If __SLS_IDE__ is defined (that is, if the Simplicity Studio parser is looking at the code, it omits the interrupt vector number from the actual declaration. If Keil C51 is viewing the code, it places the vector number in the correct location for Keil to compile it correctly.
For example, if we used the following:
SI_INTERRUPT(INT1_ISR, 2)
In the IDE, this would generate:
void INT1_ISR (void)
But, for C51, this would generate:
void INT1_ISR (void) interrupt 2
This would eliminate the syntax error, but still allow Keil to compile the interrupt correctly.
Syntax error in Simplicity Studio when declaring interrupts?
Question:
Why do I receive syntax errors in Simplicity Studio when defining an interrupt? The code compiles and works correctly, but declaring an interrupt, such as this one, gives a syntax error in Studio:
Answer:
This occurs since Simplicity Studio uses a generic C syntax parser when looking for syntax errors in code. It doesn't understand compiler-specific C code, like that used by Keil C51 to define an interrupt function - the 'interrupt' keyword and interrupt number after the function declaration aren't standard C, so it throws a syntax error. Keil, however, when the project is compiled, understands this syntax and compiles the code correctly.
We have a work-around for this visual error by the way of macros in si_toolchain.h. If you use the SI_INTERRUPT(name, vector) macro, it will generate different declarations based on which tool is viewing the code. If __SLS_IDE__ is defined (that is, if the Simplicity Studio parser is looking at the code, it omits the interrupt vector number from the actual declaration. If Keil C51 is viewing the code, it places the vector number in the correct location for Keil to compile it correctly.
For example, if we used the following:
In the IDE, this would generate:
But, for C51, this would generate:
This would eliminate the syntax error, but still allow Keil to compile the interrupt correctly.