CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Modulus function within ISR

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bcfd36



Joined: 14 Apr 2015
Posts: 28
Location: Boulder Creek, CA

View user's profile Send private message

Modulus function within ISR
PostPosted: Wed Apr 22, 2015 11:33 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 11:36 am     Reply with quote

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: 9220
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 12:10 pm     Reply with quote

'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: 1344

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 12:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 12:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 1:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 1:59 pm     Reply with quote

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: 1344

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 2:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 3:05 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Wed Apr 22, 2015 4:20 pm     Reply with quote

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: 19492

View user's profile Send private message

PostPosted: Thu Apr 23, 2015 12:22 am     Reply with quote

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..)'.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group