Jump to content
Sign in to follow this  
andydavy

Incorrect Defines In Include Files

Recommended Posts

The following will not compile:-

21  #pragma DATA 0x2007, _INTRC_OSC_NOCLK

 

and will produce the following error:-

Compiling...

"C:\Program Files\SourceBoost\boostc.pic16.exe" -t PIC16F676  s2kdashir.c

BoostC Optimizing C Compiler Version 1.6 Alpha (for PIC16 architecture)
http://www.picant.com/c2c/c.html
Copyright(C) 2004 Pavel Baranov
Copyright(C) 2004 David Hobday


s2kdashir.c(21): warning: unknown or invalid pragma (ignored)
success
Done

 

Ok...so far great problem detected. Now try the following:-

#pragma DATA 0x2007, _CP_OFF & _INTRC_OSC_NOCLK

The error you get this time is lsightly different:-

BoostC Optimizing C Compiler Version 1.6 Alpha (for PIC16 architecture)
http://www.picant.com/c2c/c.html
Copyright(C) 2004 Pavel Baranov
Copyright(C) 2004 David Hobday


s2kdashir.c(21): error:  failure
failure
Exit code was 1.
Removing target: s2kdashir.obj
Failed to locate output file 's2kdashir.obj'
Done

Failed

 

Not such a great message :) . Ignoring the difference in the compiler error message, the real problem is due to the supplied include files.

 

The incorrect include file looked like this:-

#define   _EC_OSC 0x3FFB                                                                               
        
#define _INTRC_OSC_NOCLK0x3FFC                                                                                       
#define         _INTRC_OSC_CLKOU0x3FFD                                                                              
         
#define         _EXTRC_OSC_NOCLK0x3FFE                                                                              
          
#define         _EXTRC_OSC_CLKOU0x3FFF    

 

The problem is there is a missing space between the define name and the hex value, which only seems to occur to define names that are long. To solve the problem put a space between the name and the value.

 

For Example

#define _INTRC_OSC_NOCLK 0x3FFC

 

Hope this helps someone.

 

Also, you will notice that in the first example it doesn't fail to compile and the pragma is ignored. If you run a build the warning disappears of the top of the report box and therefore you dont see it, unless you are in the habit of scrolling back and checking every message. I think that this warning should be an error as well and stop the build.

Share this post


Link to post
Share on other sites
For Example

#define _INTRC_OSC_NOCLK0x3FFC

 

I've written a perl script to "correct" all those header files. (This assumes that the actual variable names weren't actually truncated in the original headers):

 

#!/usr/bin/perl -w

use strict;

my $currentFile;
my $currentDir = "c:\\program files\\SourceBoost\\include\\";
opendir(DIR, $currentDir) or die "can't opendir $currentDir: $!";
while (defined($currentFile = readdir(DIR))) 
{
if ($currentFile =~ m/(boostc.h|rand.h|system.h)/i)
{
 next;
}
if ($currentFile =~ m/\.h$/)
{
 open(DEFINE_IN, "<" . $currentDir . $currentFile) or die "Couldn't read $currentFile: $!";
 my @fileBuffer;
 while (<DEFINE_IN>)
 {
	 chomp;
	 # delete any extra spaces at the end of each line
	 s/\s+$//;
	 if (m/^[^\/].*[^;]$/)
	 {
   s/\s{2,}/\t/g;
	 }
	 else
	 {
   s/\s{2,}//g;
	 }
	 
	 if (m/#define\s*([^\s]+)\s*(0x[a-fA-F0-9]{4})$/)
	 {
   push (@fileBuffer, "#define\t$1\t$2\n");
	 }
	 else
	 {
   push (@fileBuffer, ($_ . "\n"));
	 }
 }
 close(DEFINE_IN);
 open(DEFINE_OUT, ">" . $currentDir . $currentFile) or die "Couldn't write to $currentFile: $!";
 foreach(@fileBuffer)
 {
	 print DEFINE_OUT;
 }
 close(DEFINE_OUT);
}
}
closedir(DIR);

 

you can get the perl interpreter for windows here:

 

http://downloads.activestate.com/ActivePer...MSWin32-x86.msi

Share this post


Link to post
Share on other sites

The script still left some errors:

...
#define         _OSC_ECIOSWPLL_10xFD
...

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
The script still left some errors:

...
#define         _OSC_ECIOSWPLL_10xFD
...

 

Regards,

Pavel

 

I think changing this line:

if (m/#define\s*([^\s]+)\s*(0x[a-fA-F0-9]{4})$/)

to

if (m/#define\s*([^\s]+)\s*(0x[a-fA-F0-9]{1,4})$/)

 

should fix that.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...