View previous topic :: View next topic |
Author |
Message |
guy
Joined: 21 Oct 2005 Posts: 297
|
DISABLE_INTS quirks |
Posted: Fri Oct 21, 2005 6:09 pm |
|
|
When I add DISABLE_INTS option to the #USE RS232, the code size increases by 300 instructions and I get a warning:
Variable never used: rs232_errors
Is this a bug or a feature?
How can I tell if the compiler uses hardware or software RS232? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
...bug or feature? |
Posted: Fri Oct 21, 2005 7:46 pm |
|
|
Thank you for the answers but my main question is - could it be that the code size increases by 300 instructions just because interrupts are disabled? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 21, 2005 8:10 pm |
|
|
Post a small program that shows the problem. Also post your compiler
version. I'll compile it and look at the .LST file. Make sure the
program is complete , with all #include, #fuses, and #use statements,
so I can drop it into MPLAB and compile it.
The compiler version will be a number such as 3.191 or 3.236, etc.,
and can be found at the top of the .LST file, which is in your project
directory. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
Re: ...bug or feature? |
Posted: Fri Oct 21, 2005 8:14 pm |
|
|
guy wrote: | Thank you for the answers but my main question is - could it be that the code size increases by 300 instructions just because interrupts are disabled? | You can find this out by yourself by comparing the list file (*.lst) of the two versions. Adding the DISABLE_INTS options will increase your code because every call to the serial port has to be embedded in a disable/enable pair of instructions. The exact growth of your program will depend on the number of RS232 calls. You can limit the program increase by writing a wrapper for the serial functions so that the actual serial port access (and interrupt blocking) is always performed from those wrapper functions.
Code: |
//-----------------------------------------------------------------------------
// A wrapper function for the serial port write function.
//-----------------------------------------------------------------------------
void ToLog(char Msg)
{
putc(Msg);
}
void main()
{
// Note that we call the ToLog function with a string as parameter
// while ToLog is defined to take a single character. This is a special
// feature of the CCS compiler where the compiler breaks the string
// into seperate characters.
printf(ToLog, "Test\n");
} |
|
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Sat Oct 22, 2005 6:13 am |
|
|
I guess every printf() adds more disabling/enabling code, and I have plenty of those.
Unfortunately I don't know how to 'wrap' a printf() because it has a different number of parameters and parameter types.
More ideas?
By the way, compiler version is 3.236
(thanks for the help!!!) |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Oct 22, 2005 11:51 am |
|
|
Quote: | Unfortunately I don't know how to 'wrap' a printf() because it has a different number of parameters and parameter types. | That's exactly what I tried to explain in my example. In CCS code the printf function has a non-standard feature that allows you to send the data to a user defined function for outputting (default is putc if no function is specified).
What I tried to explain in my previous post is that you write your own output function which is just a wrapper for putc. This way putc is only called in one location of your program and the enable/disable interrupt code is only inserted in this single location. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Oct 22, 2005 1:34 pm |
|
|
What ckielstra means is you must add a routine such as his ToLog()
function, and then edit every one of your printf() statements as shown
below:
Original code:
Code: | printf("ABC");
printf("Hello World\n\r");
printf("my value = %U\n\r", my_value); |
Edited code which re-directs printf output to the ToLog() function,
as shown in bold below:
Quote: | printf(ToLog, "ABC");
printf(ToLog, "Hello World\n\r");
printf(ToLog, "my value = %U\n\r", my_value); |
|
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Sat Oct 22, 2005 1:40 pm |
|
|
Thanks. I will try it.
Being new to the CCS compiler, I'm still amazed how much codespace is wasted and how much 'optimization' the user needs to do himself... |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Oct 22, 2005 4:04 pm |
|
|
guy wrote: | Thanks. I will try it.
Being new to the CCS compiler, I'm still amazed how much codespace is wasted and how much 'optimization' the user needs to do himself... | I've used the compiler for two years and am everytime surprised by how efficient and flexible it is. If the compiler turns out to be inefficient there is often a workaround but more than once it turned out to be me who made a clumsy algorithm and blamed the compiler for not being optimal.
As you say you are new to the CCS compiler I'm wondering why you want to disable the interrupts? This feature is available to solve some very specific issues and since you are new to this environment my guess is you are solving your problem in the wrong way. |
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Sat Oct 22, 2005 4:48 pm |
|
|
I'm new to the CCS compiler but I've been programming in PIC assembler for 10 years. I believe this is part of my problem. I can easily estimate that the code produced by the compiler is about twice the amount it would take in assembler. This is for several reasons, and among them is my lack of understanding of the compiler. I'm sure it will improve over time, but this will not be because the compiler will get better but rather because I will look into the code and waste hours trying to improve my algorithms and 'reverse-engineer' the compiler to understand it better.
The example of the DISABLE_INTS is just the thing I would expect from a professional, optimized compiler. Why should I replace the printf() routine and then go through my code and change each printf() statement??? Shouldn't the compiler to it by itself?
I don't mean to be offensive - not to you ckielstra and not to the compiler or the guys who made it. I'm sure that in time I will adjust to 'your' way of thinking, blaming myself for not optimizing the code for the compiler, rather than the other way around. I guess it's because I'm still comparing it to assembly...
By the way, I agree that if the RS232 is hardware-based, interrupts shouldn't be a problem anyway.
Thanks a lot for the support. everyone! |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Oct 23, 2005 6:26 am |
|
|
Quote: | The example of the DISABLE_INTS is just the thing I would expect from a professional, optimized compiler. Why should I replace the printf() routine and then go through my code and change each printf() statement??? Shouldn't the compiler to it by itself? | You have a point here. It wouldn't hurt to send your suggestion to support@ccsinfo.com, I've had very good response in the past. |
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Sun Oct 23, 2005 6:40 am |
|
|
* send an e-mail to CCS support - done.
I doubt it if I'll get a free download when the new version appears, though. |
|
|
|