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

PCM - How to tell if putc() will block

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



Joined: 23 Apr 2005
Posts: 21
Location: Phoenix,AZ

View user's profile Send private message Visit poster's website AIM Address

PCM - How to tell if putc() will block
PostPosted: Fri May 06, 2005 3:24 pm     Reply with quote

I want a little snippet of code that will tell me if putc() will block before I call it (my application cannot afford to be hung up in a read or write).

I wrote one for the 18F452 in assembly:

Code:

while(1) {
    #asm
    btfss 0xF9E.4           //UART Ready? (PIE2)
    bra   notrdy
    #endasm
    charssent++;
    putc(c);
    return;
    notrdy:
    defer();
}


However, the analogous code does not work on the 18F877A. It is

Code:

#define PIE1 0x8c
    while(1) {
        #asm

        btfss PIE1.4
        goto  notrdy
        #endasm
        charssent++;
        putc(c);
        return;
        notrdy:
        defer();


This code never writes anything.

Any ideas?
_________________
The best weather is bad weather
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Fri May 06, 2005 3:44 pm     Reply with quote

OK, some questions.

Why are you reading the enable bit for the transmit interrupt?

Wouldn't you be better off trying to read the status of TXIF in PIR1 or TRMT in TXSTA?
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
gustnado



Joined: 23 Apr 2005
Posts: 21
Location: Phoenix,AZ

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Fri May 06, 2005 3:59 pm     Reply with quote

Because of a dumb mistake. I had tried TXSTA before without success but I suspect it was a syntactical screwup.

The following appears to work:
Code:

void sendChar(int c)
{
    while(1) {
        #asm
   btfss 0x98,1
   goto  notrdy
   #endasm
   charssent++;
   putc(c);
   return;
   notrdy:
   defer();
    }
}


Which leads to the next question: does setjmp/longjmp work on this processor (16F877A)?
_________________
The best weather is bad weather
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Sat May 07, 2005 11:43 am     Reply with quote

There is a running discussion about the setjump/longjump commands and how they work.

I haven't really kept up but as I understand it, they work but not very well and not under all conditions. Also some dependence on your compiler revision and the chip type.

Didn't help much did it...

My advice would be to think long and hard about a way to NOT use setjump and longjump in your code.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
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