View previous topic :: View next topic |
Author |
Message |
bcfd36
Joined: 14 Apr 2015 Posts: 28 Location: Boulder Creek, CA
|
Modulus function within ISR |
Posted: Wed Apr 22, 2015 11:33 am |
|
|
1. I am new to CCS and PIC processors. Be gentle.
2. The code I am working with, I inherited.
One of the tasks I have been given is to eliminate all compiler warnings in generated by the source code. In one project, there were modulus operations being done in 2 ISRs. These generated compiler warnings. I determined that what was being done didn't need a modulus operation and changed the code.
In a different project, almost identical code was found in a similar ISR. However, on compile, no warning was generated. I have not found any #IGNORE_WARNING compiler flags.
The compile without the warning is on a 18LF45K22.
The compile with the warnings is on a 18F66J50. I'm guessing that this won't make any difference.
Any ideas what might be going on here?
D. Scruggs _________________ D. Scruggs |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 22, 2015 11:36 am |
|
|
If these are two separate MPLAB projects, are you sure that warnings
weren't turned off in one of the projects ? Look in Project / Build
Options for the "Show Warnings" tickbox.
If that's not the problem, post the code for the two isrs, and post the
CCS compiler version(s). |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Apr 22, 2015 12:10 pm |
|
|
'warnings' don't really hurt the program, just friendly reminders you're doing 'something' that might not be 'politically correct'.
'errors' though...those you don't want !!
I don't bother turning off warnings. Sometimes I need the reminder as there may be a better,faster,shorter, smarter way to do a particular operation or function.
Jay |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1355
|
|
Posted: Wed Apr 22, 2015 12:11 pm |
|
|
I don't have the compiler in front of me to check this, but maybe someone else can comment:
Would the compiler generate the warnings if power of 2 was used versus not? When you take the modulus of a number using a power of 2, you don't need to do division:
9 mod 8
is the same as
9 bitwise-AND (8-1)
so I wouldn't expect the warnings for that scenario but would when the modulus operation incurs a division.
Just thinking if one program used a non power of 2 and another did, then maybe that might be related. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 22, 2015 12:19 pm |
|
|
Yes, modulus that required actual division (as opposed to a shift) would
generate this warning (if division was also done outside the isr):
Quote: | Interrupts disabled during call to prevent re-entrancy: (@DIV88) |
I assumed that he was doing a modulus that required division in both
projects. Maybe you are right, and only one of them is doing it. |
|
|
bcfd36
Joined: 14 Apr 2015 Posts: 28 Location: Boulder Creek, CA
|
|
Posted: Wed Apr 22, 2015 1:47 pm |
|
|
This is not MPLAB, if I understand correctly. This is CCS Version 5.018. There is a project file for Prod_1 and Prod_2 but I don't believe these are MPLAB projects. Just CCS C Compiler projects.
I am not finding a Show Warnings tickbox. Nor a Project/Build Options selection of any type. I find, under the Options Tab, IDE, Project, Printer, and Updates.
Under Project I find Files, Include Files, Global Defines, and Output Files.
Under Output Files I find a "Show All Warnings" check box that is checked.
So I thought I should be seeing warnings. _________________ D. Scruggs |
|
|
bcfd36
Joined: 14 Apr 2015 Posts: 28 Location: Boulder Creek, CA
|
|
Posted: Wed Apr 22, 2015 1:59 pm |
|
|
I am guessing my question wasn't entirely clear. What I am trying to find out is why I got a warning in one place and not the other. There might be other warnings I am interested in and not seeing.
I have probably missed an option somewhere and don't know about it.
But thanks for the help. You've given me other things to consider.
This forum kind of reminds me of the old days of Usenet, without the flame wars. _________________ D. Scruggs |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1355
|
|
Posted: Wed Apr 22, 2015 2:18 pm |
|
|
Did you see my (and PCM Programmer's) comment about division operations and how they affect compiler warnings?
You say "almost" identical but we don't really have much to go on. Did you check to see if one project had divisions in both the ISR and outside and the other only in the ISR, or not at all (should be easy to tell from the SYM file + LST file)? |
|
|
bcfd36
Joined: 14 Apr 2015 Posts: 28 Location: Boulder Creek, CA
|
|
Posted: Wed Apr 22, 2015 3:05 pm |
|
|
Jeremiah,
Yes, I saw youse guys answers. Much appreciated. The fix, is to replace the modulus since it wasn't appropriate anyway. I have taken care of that. The question had to do with why the warning was in one place and not the other. I didn't look at DIVISIONS inside and outside. I assumed that CCS didn't like ANY divisions inside an ISR. I'm thinking I assumed wrong.
Thanks much.
Just in case you are interested, I will post the offending code:
Code: |
g_pGUI_IncompleteCmd->buff[g_pGUI_IncompleteCmd->len] = c; // Store new character in the buffer
++g_pGUI_IncompleteCmd->len; // Increment the buffer length
g_pGUI_IncompleteCmd->len %= COMM_BUFFER_LEN; // Limit bounds
|
The modulus really didn't make sense. I see what he was doing, but it is completely inappropriate. I changed it to a check of the length against the maximum length and if true, reset to 0 and then a few other things. _________________ D. Scruggs |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Apr 22, 2015 4:20 pm |
|
|
if its not huge - i'd be curious what the warnings actually are.
too big to post some or all?
also 5.018 is still early in the the 5.x family. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Thu Apr 23, 2015 12:22 am |
|
|
On the difference between (which is what the poster was puzzled about), one possibility is the number involved.
If the modulus in one (say) was %16, and the other %14, the second would generate a warning, and the first wouldn't. The reason is that the compiler's optimiser is quite smart, and realises that the first can be done using &, rather than a division.
This is a long term 'gripe' of mine, with regard to the 'example' files. ex_sisr for example, uses a modulus in the ISR. However it is careful to use a binary buffer size, so the compiler then substitutes the 'and' operation. Problem is that there is no warning in the notes to say 'only do it this way with binary buffer sizes (4,8,16 bytes etc..)'. |
|
|
|