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

Program won't compile with call to rcv_buffer_bytes()

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



Joined: 06 Dec 2010
Posts: 25

View user's profile Send private message

Program won't compile with call to rcv_buffer_bytes()
PostPosted: Sun Jul 03, 2016 8:24 am     Reply with quote

I am using CCS C version 5.015 IDE.

I have found that serial port has function rcv_buffer_bytes() to determine how many bytes are in the receive buffer. I am using PIC18F87K22. In the header file of this device it says:

// #use rs232() Prototypes:
...
_bif unsigned int16 rcv_buffer_bytes(void);
_bif unsigned int16 rcv_buffer_bytes(unsigned int8 stream);
...

so these functions are defined. But when I call them in the main routine of the program the program does not compile!

It says "function used but not defined".
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Sun Jul 03, 2016 11:48 am     Reply with quote

The function only exists if you setup a receive buffer in the #USE RS232.

So:

#use rs232(baud=9600, UART1, RECEIVE_BUFFER=32)

Then the compiler will generate a software receive buffer (and use INT_RDA for this). With this done 'rcv_buffer_bytes()', becomes available to tell you how much data is in the buffer.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: Program won't compile with call to rcv_buffer_bytes()
PostPosted: Mon Jul 04, 2016 1:58 am     Reply with quote

matrixofdynamism wrote:

// #use rs232() Prototypes:
...
_bif unsigned int16 rcv_buffer_bytes(void);
_bif unsigned int16 rcv_buffer_bytes(unsigned int8 stream);
...

so these functions are defined.


No, they are declared, but if no body is later given, or provided by the compiler then they are not defined. As Ttelmah says, they only get defined under certain circumstances.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Mon Jul 04, 2016 7:55 am     Reply with quote

This is one of the classic C 'bewares'.

Have a look at:

<http://www.cprogramming.com/declare_vs_define.html>

Often (if you define a function/variable before using it for example), the 'declaration' never happens (it is implied by the definition).
A declare without a define will not give an error, till you actually use the function, when the compiler will then tell you that the function is 'not defined'.

In this case the function only exists (and is therefore defined), when the extra commands are added to #USE RS232.
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Mon Jul 04, 2016 9:22 am     Reply with quote

Another gotcha to watch out for using the CCS buffers. Unless things have changed in the last year, they have a curious side effect. If you fill up the buffer before using it, all of the data in the buffer is lost (it's technically still there in memory, but the CCS pointers to it lose track of the data). So you need to make sure you don't fill up the buffers:

See:
https://www.ccsinfo.com/forum/viewtopic.php?t=54339&highlight=receivebuffer

Applies to both TX and RX buffers.

Their code example versions (ex_sisr.c for example) are usually a better type of route to go (with a couple mods).
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