XINU
device
tty
ttyhandle_out.c
Go to the documentation of this file.
1
/* ttyhandle_out.c - ttyhandle_out */
2
3
#include <
xinu.h
>
4
5
/*------------------------------------------------------------------------
6
* ttyhandle_out - Handle an output on a tty device by sending more
7
* characters to the device FIFO (interrupts disabled)
8
*------------------------------------------------------------------------
9
*/
10
void
ttyhandle_out
(
11
struct
ttycblk
*typtr,
/* Ptr to ttytab entry */
12
struct
uart_csreg
*csrptr
/* Address of UART's CSRs */
13
)
14
{
15
16
int32
ochars;
/* Number of output chars sent */
17
/* to the UART */
18
int32
avail;
/* Available chars in output buf*/
19
int32
uspace;
/* Space left in onboard UART */
20
/* output FIFO */
21
uint32
ier = 0;
22
23
/* If output is currently held, simply ignore the call */
24
25
if
(typtr->
tyoheld
) {
26
return
;
27
}
28
29
/* If echo and output queues empty, turn off interrupts */
30
31
if
( (typtr->
tyehead
== typtr->
tyetail
) &&
32
(
semcount
(typtr->
tyosem
) >=
TY_OBUFLEN
) ) {
33
ier = csrptr->
ier
;
34
csrptr->
ier
= ier & ~
UART_IER_ETBEI
;
35
return
;
36
}
37
38
/* Initialize uspace to the available space in the Tx FIFO */
39
40
uspace =
UART_FIFO_SIZE
- csrptr->
txfifo_lvl
;
41
42
/* While onboard FIFO is not full and the echo queue is */
43
/* nonempty, xmit chars from the echo queue */
44
45
while
( (uspace>0) && typtr->
tyehead
!= typtr->
tyetail
) {
46
csrptr->
buffer
= *typtr->
tyehead
++;
47
if
(typtr->
tyehead
>= &typtr->
tyebuff
[
TY_EBUFLEN
]) {
48
typtr->
tyehead
= typtr->
tyebuff
;
49
}
50
uspace--;
51
}
52
53
/* While onboard FIFO is not full and the output queue is */
54
/* nonempty, transmit chars from the output queue */
55
56
ochars = 0;
57
avail =
TY_OBUFLEN
-
semcount
(typtr->
tyosem
);
58
while
( (uspace>0) && (avail > 0) ) {
59
csrptr->
buffer
= *typtr->
tyohead
++;
60
if
(typtr->
tyohead
>= &typtr->
tyobuff
[
TY_OBUFLEN
]) {
61
typtr->
tyohead
= typtr->
tyobuff
;
62
}
63
avail--;
64
uspace--;
65
ochars++;
66
}
67
if
(ochars > 0) {
68
signaln
(typtr->
tyosem
, ochars);
69
}
70
71
if
( (typtr->
tyehead
== typtr->
tyetail
) &&
72
(semcount(typtr->
tyosem
) >=
TY_OBUFLEN
) ) {
73
ier = csrptr->
ier
;
74
csrptr->
ier
= (ier & ~
UART_IER_ETBEI
);
75
}
76
return
;
77
}
semcount
syscall semcount(sid32)
セマフォのカウント値を返す。
Definition:
semcount.c:18
TY_EBUFLEN
#define TY_EBUFLEN
Definition:
tty.h:5
UART_IER_ETBEI
#define UART_IER_ETBEI
Definition:
uart.h:66
uart_csreg::buffer
volatile uint32 buffer
Definition:
uart.h:15
uart_csreg::txfifo_lvl
volatile uint32 txfifo_lvl
Definition:
uart.h:32
signaln
syscall signaln(sid32, int32)
セマフォにシグナルをN回送り、N個の待機プロセスがある場合はそれらをREADY状態にする。 ...
Definition:
signaln.c:16
xinu.h
全てのシステムヘッダファイルをインクルードする。
ttyhandle_out
void ttyhandle_out(struct ttycblk *typtr, struct uart_csreg *csrptr)
Definition:
ttyhandle_out.c:10
uart_csreg::ier
volatile uint32 ier
Definition:
uart.h:17
ttycblk::tyoheld
bool8 tyoheld
Definition:
tty.h:53
ttycblk
Definition:
tty.h:26
ttycblk::tyehead
char * tyehead
Definition:
tty.h:35
ttycblk::tyobuff
char tyobuff[TY_OBUFLEN]
Definition:
tty.h:33
ttycblk::tyetail
char * tyetail
Definition:
tty.h:36
ttycblk::tyohead
char * tyohead
Definition:
tty.h:31
int32
int int32
符号あり32ビット整数(int)
Definition:
kernel.h:11
TY_OBUFLEN
#define TY_OBUFLEN
Definition:
tty.h:16
UART_FIFO_SIZE
#define UART_FIFO_SIZE
Definition:
uart.h:5
uart_csreg
Definition:
uart.h:13
uint32
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition:
kernel.h:15
ttycblk::tyebuff
char tyebuff[TY_EBUFLEN]
Definition:
tty.h:37
ttycblk::tyosem
sid32 tyosem
Definition:
tty.h:34
Generated by
1.8.13