[En-Nut-Discussion] Again hardware handshake
Harald Kipp
harald.kipp at egnite.de
Wed Sep 15 15:22:50 CEST 2004
From dev/usartavr.c, AvrUsartSetFlowControl() called
somehow by ioctl().
----------------------------------------------------
#ifdef UART_RTS_BIT
/*
* Set RTS control mode.
*/
if (flags & USART_MF_RTSCONTROL) {
sbi(UART_RTS_PORT, UART_RTS_BIT);
sbi(UART_RTS_DDR, UART_RTS_BIT);
rts_control = 1;
} else if (rts_control) {
rts_control = 0;
cbi(UART_RTS_DDR, UART_RTS_BIT);
}
#endif
----------------------------------------------------
This is where handshake control is activated. But
RTS is disabled (the PC cannot send).
From dev/usartavr.c, AvrUsartRxStart() called by
Nut/OS driver receive on empty buffers.
----------------------------------------------------
#ifdef UART_RTS_BIT
if (rts_control) {
/* Enable RTS. */
cbi(UART_RTS_PORT, UART_RTS_BIT);
}
#endif
----------------------------------------------------
Here is where the above routine is called,
routine UsartRead() in dev/usart.c
----------------------------------------------------
NutEnterCritical();
avail = rbf->rbf_cnt;
NutExitCritical();
if (avail) {
break;
}
/*
* This will enable RTS hardware handshake or re-enable the
* remote transmitter by sending a XON character.
*/
(*dcb->dcb_rx_start) ();
if (NutEventWait(&rbf->rbf_que, dcb->dcb_rtimeout)) {
return 0;
}
----------------------------------------------------
So...calling let's say fgets with no bytes in the
buffer _will_ enable the RTS handshake line.
Later on, the handshake may be disabled during receive
interrupt.
From dev/usartavr.c, AvrUsartRxComplete() interrupt
handler:
----------------------------------------------------
#ifdef UART_RTS_BIT
/*
* Check the high watermark for hardware handshake. If the number of
* buffered bytes is above this mark, then disable RTS.
*/
else if (rts_control && cnt >= rbf->rbf_hwm) {
sbi(UART_RTS_PORT, UART_RTS_BIT);
}
#endif
----------------------------------------------------
This is where handshake will be disabled, when
the number of bytes in the buffer reach the
high watermark.
The default buffer size is 256 and the default
high watermark is 240. No need to set them.
From all the above I can't locate any problem. You may try
to initiate a read buffer flush, which should immediately
activate the RTS line (fread with NULL pointer).
Here's the sequence I used for the tests:
----------------------------------------------------
u_long flow = UART_HS_RTSCTS;
//u_long flow = UART_HS_SOFT;
NutRegisterDevice(&devUsartAvr0, 0, 0);
...
cd.cd_rs232 = fopen("uart0", "r+b");
stdout = cd.cd_rs232;
printf("\r\nServer Start uart=%04X\r\n", (u_short) stdout);
_ioctl(_fileno(cd.cd_rs232), UART_SETSPEED, &baud);
_ioctl(_fileno(cd.cd_rs232), UART_SETFLOWCONTROL, &flow);
...
----------------------------------------------------
Another idea: You opened the device for writing _and_ reading,
don't you?
Harald
At 13:09 15.09.2004 +0200, you wrote:
> > The PC may also require DCD and DSR. Try to connect them
> > to DTR. It might be also possible to with minicom to enable
> > RTS/CTS only, not the full modem handshake.
>
>Yes, I've just connected DCD and DSR with DTR. So there should be no
>problem... The RTS signal has the inverted state of what the pc sends on
>it's RTS line... So I think ther'll be a problem with the NutOS side.
>
>Do I have to set the buffersize of the incomming buffer by my own?
>
>I'm on debugging this thing, but until now no success...
>
>Regards,
>
>Ole Reinhardt
>--
>kernel concepts Tel: +49-271-771091-14
>Dreisbachstr. 24 Fax: +49-271-771091-19
>D-57250 Netphen E+ : +49-177-7420433
>--
>
>
>_______________________________________________
>En-Nut-Discussion mailing list
>En-Nut-Discussion at egnite.de
>http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
More information about the En-Nut-Discussion
mailing list