View previous topic :: View next topic |
Author |
Message |
Les
Joined: 23 Dec 2022 Posts: 2
|
Warnings during compile |
Posted: Fri Dec 23, 2022 8:19 am |
|
|
Hi,
I have a trial version of the latest compiler. But when I compile a program that was written (compiled and worked fine) with an old CCS compiler. The trial version throws up the following warning :
Warning - Interrupts disabled during call to prevent re-entrancy: (@PRINTF_LD_19200_31766_31767)
Is there a way to stop the interrupts being disabled automatically? I suspect that it is this that's causing the problems I'm experiencing.
Many thanks,
Les |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Fri Dec 23, 2022 8:28 am |
|
|
The warning is telling you that you have a function which is being called both inside and outside of an interrupt service routine. The compiler is telling you that when it encounters printf outside of an ISR, it's automatically wrapping it in a disable_interrupts(GLOBAL) ... enable_interrupts(GLOBAL) pair. If the compiler did not do this, then your program is sure to fail in practice. You can:
a) Refactor your code to remove the printf inside of an ISR. It's really bad practice to do anything slow inside of an ISR, particularly a print to some external stream of whatever sort. Or,
b) Take the lazy way out and wrap the printf you have outside of an interrupt inside your own function, my_printf(). This will cause the compiler to create a 2nd instance of the function and that will make the warning go away.
Finally, just because you didn't see this issue with an older version of the compiler doesn't mean it wasn't there. It just, for whatever reason, wasn't telling you about it. |
|
|
Les
Joined: 23 Dec 2022 Posts: 2
|
|
Posted: Mon Dec 26, 2022 2:36 pm |
|
|
Thanks for the info.
The program was written using a CCS 2007 compiler, and built to work without conflicts. But the way in which it was done wasn't very elegant.
From your comments I've rewritten sections of the code. It now compiles without errors, works fine, and I feel more confident in it's operation.
Many thanks - sometimes a simple explanation goes a long way. :-) |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Dec 27, 2022 7:19 am |
|
|
The older compilers still did this, but did not give you a warning.
They have to, because if not, it results in the code having to be re-entrant
(calling inside itself), and the PIC because it lacks a variable stack cannot
do this.
The warning was added to tell you that this was happening, so you could
potentially redesign the code to avoid it (it in many cases will be better
if you can avoid this).
The old compiler was doing this 'silently', the newer compilers tell you.
2007, would be a very early compiler. Late V3 possibly. |
|
|
|