View previous topic :: View next topic |
Author |
Message |
gustnado
Joined: 23 Apr 2005 Posts: 21 Location: Phoenix,AZ
|
PCM - How to tell if putc() will block |
Posted: Fri May 06, 2005 3:24 pm |
|
|
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
|
|
Posted: Fri May 06, 2005 3:44 pm |
|
|
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
|
|
Posted: Fri May 06, 2005 3:59 pm |
|
|
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
|
|
Posted: Sat May 07, 2005 11:43 am |
|
|
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! |
|
|
|