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

What does int filthit:3 mean?

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



Joined: 12 Aug 2009
Posts: 40

View user's profile Send private message

What does int filthit:3 mean?
PostPosted: Tue Mar 02, 2010 4:51 pm     Reply with quote

What does int filthit:3 mean?

I was doing some code testing and wanted to see what the CANbus was bringing in. So looking at examples, I decided to check what the rxstat had in it.

rxstat is define as using the struct rx_stat.

Code:

struct rx_stat {
   int1 err_ovfl;
   int filthit:3;
   int1 buffer;
   int1 rtr;
   int1 ext;
   int1 inv;
};


I asked the question like this:

Code:

printf("\r\nGOT: BUFF=%U ID=%LU LEN=%U OVF=%U ", rxstat.buffer, rx_id, rx_len, rxstat.err_ovfl);
            printf("FILT=%U RTR=%U EXT=%U INV=%U", rxstat.filthit, rxstat.rtr, rxstat.ext, rxstat.inv);


I got a "error 57 , Expecting structure/union"

The offending portion was:
rxstat.buffer

and

rxstat.buffer

The above example is from EX_CAN.c

So a two fold question:
What does int filthit:3 mean? and Why does rxstat.buffer throw an error?

Thanks L.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 02, 2010 6:21 pm     Reply with quote

It's a bit field. See this links:
http://en.wikipedia.org/wiki/Bit_field
http://www.cs.cf.ac.uk/Dave/C/node13.html#SECTION001320000000000000000
http://publications.gbdirect.co.uk/c_book/chapter6/bitfields.html
lecutus



Joined: 12 Aug 2009
Posts: 40

View user's profile Send private message

PostPosted: Wed Mar 03, 2010 10:29 am     Reply with quote

Thanks I have the first part of my question answered. Now for the second part.


I got a "error 57 , Expecting structure/union" twice, concerning rxstat.buffer and rxstat.filthit.

The code I used was from one of the examples sent with the compiler, EX_CAN.c, just a cut and paste.

Quote:

if(can_getd(rx_id, &buffer[0], rx_len, rxstat)) //...then get data from buffer
{
printf("\r\nGOT: BUFF=%U ID=%LU LEN=%U OVF=%U ", rxstat.buffer, rx_id, rx_len, rxstat.err_ovfl);
printf("FILT=%U RTR=%U EXT=%U INV=%U", rxstat.filthit, rxstat.rtr, rxstat.ext, rxstat.inv);
printf("\r\n DATA = ");
for (i=0;i<rx_len;i++)
{
printf("%X ",buffer[i]);
}
printf("\r\n");
}
else
{
printf("\r\nFAIL on GETD\r\n");


I did do the #include <can-18xxx8.c>. I checked the spelling of structure type and the variable that took the structure type.

So what am I missing.

Thanks
L.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 03, 2010 12:48 pm     Reply with quote

Post your PIC and your compiler version.
lecutus



Joined: 12 Aug 2009
Posts: 40

View user's profile Send private message

PostPosted: Thu Mar 04, 2010 8:12 am     Reply with quote

Sorry, I forgot the protocol.

I'm using PIC18F258 with PCWHD 4.079

For the record I have :
Code:

int buffer[8],rx_len,rxstat;

As an observation, does using can_getd implicitly make rxstat a structure if used like this:
Code:

int1 can_getd(int32 & id, int * data, int & len, struct rx_stat & stat)

Or should rx_stat be declared as a structure before use?

L.
Ttelmah
Guest







PostPosted: Thu Mar 04, 2010 9:28 am     Reply with quote

No.
The declaration shown, for can_getd, has no effect at all on 'rxstat'. It makes the _pointer_ passed to the function, into a pointer to a structure of type rx_stat. Inside the function you can then access the parts using:

stat->filthit

for example, but not using the '.' notation, unless you dereference the pointer (*).
It sounds like this is where your problem actually lies....

Best Wishes
lecutus



Joined: 12 Aug 2009
Posts: 40

View user's profile Send private message

PostPosted: Thu Mar 04, 2010 1:14 pm     Reply with quote

Thanks

I wish they would have mentioned that in the example.
Ttelmah
Guest







PostPosted: Thu Mar 04, 2010 3:11 pm     Reply with quote

That is standard C.....

Best Wishes
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