?? diti.c
字號:
/* Check to see if there is still data in a message block that was */
/* gotten previously. If not get one. */
/*-----------------------------------------------------------------*/
if (!chancfg->rdmblk)
{
/*-------------------------------------------------------------*/
/* Check to see if the q_receive call should wait if there is */
/* nothing in the queue. */
/* q_receive should not wait if the channel is in non */
/* canonical mode and MinChar and MaxTime are both zero. */
/*-------------------------------------------------------------*/
if((!(chancfg->termio.c_lflag & ICANON) &&
(!chancfg->termio.c_cc[VMIN] &&
!chancfg->termio.c_cc[VTIME])))
wait = Q_NOWAIT;
else
wait = Q_WAIT;
/*-------------------------------------------------------------*/
/* Set the q_receive time out value if the channel is in non */
/* canonical mode and MinChar = 0 and MaxTime has value. */
/* If the above is not true we will wait forever. */
/*-------------------------------------------------------------*/
if (!(chancfg->termio.c_lflag & ICANON) &&
(!chancfg->termio.c_cc[VMIN] &&
chancfg->termio.c_cc[VTIME]))
{
wait = Q_WAIT;
timeout_ticks = (anchor->psosct->kc_ticks2sec/10)
* (ULONG)chancfg->termio.c_cc[VTIME];
}
else if (!(chancfg->termio.c_lflag & ICANON) &&
(chancfg->termio.c_cc[VMIN] &&
chancfg->termio.c_cc[VTIME]))
{
/*---------------------------------------------------------*/
/* Get starting ticks for timed input. */
/*---------------------------------------------------------*/
if(tm_get(&date, &time, &ticks))
/*-----------------------------------------------------*/
/* If call fails set start_ticks to 0 to indicate no */
/* timer. */
/*-----------------------------------------------------*/
start_ticks = 0;
else
{
start_ticks = ticks;
/*-----------------------------------------------------*/
/* Compute vtime in ticks. */
/*-----------------------------------------------------*/
vtime = (anchor->psosct->kc_ticks2sec/10)
* (ULONG)chancfg->termio.c_cc[VTIME];
}
if(characters_received)
{
/*-----------------------------------------------------*/
/* At lease one character has been received. The */
/* should not wait more then VTIME without receiving */
/* a character. */
/*-----------------------------------------------------*/
wait = Q_WAIT;
timeout_ticks = (anchor->psosct->kc_ticks2sec/10)
* (ULONG)chancfg->termio.c_cc[VTIME];
}
}
else
timeout_ticks = 0;
/*-------------------------------------------------------------*/
/* Get the next message block off the queue. */
/*-------------------------------------------------------------*/
error = q_receive(chancfg->rxq_id, wait, timeout_ticks, msg);
if (error != 0)
{
if(error != ERR_TIMEOUT)
parms->err = TERM_QUE;
else
parms->err = error;
/*---------------------------------------------------------*/
/* Free the semaphore which controls access to the device. */
/*---------------------------------------------------------*/
parms->out_retval = conio->length - length;
sm_v(chancfg->rda_id);
return;
}
/*-------------------------------------------------------------*/
/* Check status. (index 1 of message) */
/*-------------------------------------------------------------*/
imask = splx(MAX_ILEV);
chancfg->rqhead = chancfg->rqhead->b_next;
splx(imask);
if(msg[1])
{
if(msg[1] & SIOCLGFRAME)
parms->err = TERM_OUTSYNC;
else if(msg[1] & SIOCFRAMING)
parms->err = TERM_FRAMING;
else if(msg[1] & SIOCPARITY)
parms->err = TERM_PARITY;
else if(msg[1] & SIOCOVERRUN)
parms->err = TERM_OVERRUN;
if(msg[1] & (SIOCLGFRAME | SIOCFRAMING
| SIOCPARITY | SIOCOVERRUN))
{
parms->out_retval = conio->length - length;
gs_freemsg((mblk_t *)msg[0]);
SerialIoctl((Lid)chancfg->lid, SIOCREPLENISH, (void *)0);
/*-----------------------------------------------------*/
/* Free the semaphore which controls the device. */
/*-----------------------------------------------------*/
sm_v(chancfg->rda_id);
return;
}
}
/*-------------------------------------------------------------*/
/* Save the pointers to the message block (index 0 of message) */
/* and save status. */
/*-------------------------------------------------------------*/
chancfg->rdmblk = (mblk_t *)msg[0];
chancfg->rdbflg = msg[1];
}
mblk = (mblk_t *)chancfg->rdmblk;
b_flags = chancfg->rdbflg;
/*-----------------------------------------------------------------*/
/* Now copy the characters to the callers buffer */
/*-----------------------------------------------------------------*/
while((mblk->b_rptr < mblk->b_wptr) && (length > 0))
{
character = *mblk->b_rptr++;
if(chancfg->termio.c_iflag & IXON)
if(character == chancfg->termio.c_cc[VSTART] ||
character == chancfg->termio.c_cc[VSTOP] )
continue;
/*-------------------------------------------------------------*/
/* Check for in-put processing */
/*-------------------------------------------------------------*/
if((c_iflag = chancfg->termio.c_iflag) & IPOST)
{
/*---------------------------------------------------------*/
/* INLCR NL to CR conversion? */
/*---------------------------------------------------------*/
if(c_iflag & INLCR && character == NL)
character = CR;
/*---------------------------------------------------------*/
/* IGNCR (Ignore CR)? */
/*---------------------------------------------------------*/
if(c_iflag & IGNCR && character == CR)
continue;
/*---------------------------------------------------------*/
/* ICRNL CR to NL conversion? */
/*---------------------------------------------------------*/
else if(c_iflag & ICRNL && character == CR)
character = NL;
/*---------------------------------------------------------*/
/* IUCLC Upper to Lower case conversion? */
/*---------------------------------------------------------*/
else if(c_iflag & IUCLC)
character = tolower(character);
}
/*-------------------------------------------------------------*/
/* If the channel is in canonical mode and character is an */
/* erase character back over last character. */
/*-------------------------------------------------------------*/
if((chancfg->termio.c_lflag & ICANON) &&
(character == chancfg->termio.c_cc[VERASE]))
{
if (characters_received <= 0)
continue;
buffp--;
characters_received--;
/*---------------------------------------------------------*/
/* If ECHO is set then rub out last character on screen. */
/*---------------------------------------------------------*/
if(chancfg->termio.c_lflag & ECHO)
{
echo_mblk = chancfg->echo_mblk;
/*-----------------------------------------------------*/
/* Back up and rubout last character. */
/*-----------------------------------------------------*/
*echo_mblk->b_wptr++ = BS;
*echo_mblk->b_wptr++ = SPACE;
*echo_mblk->b_wptr++ = BS;
/*-----------------------------------------------------*/
/* Send rubout and wait for it to happen. */
/* NOTE semaphore released by data conformation */
/* function, term_datacnf. */
/*-----------------------------------------------------*/
/* Request to write to device, and wait until */
/* availability. */
/*-----------------------------------------------------*/
if (sm_p(chancfg->wra_id, SM_WAIT, FOREVER))
{
parms->err = TERM_SEM;
return;
}
chancfg->dflags |= WAITING;
SerialSend((Lid)chancfg->lid, echo_mblk);
if(parms->out_retval =
sm_p(chancfg->txc_id, SM_WAIT, FOREVER))
{
chancfg->dflags &= ~WAITING;
parms->err = TERM_SEM;
parms->out_retval = conio->length - length;
/*-------------------------------------------------*/
/* Restore echo mblock pointer so it can be reused */
/*-------------------------------------------------*/
echo_mblk->b_wptr = chancfg->echo_rwprt;
echo_mblk->b_rptr = chancfg->echo_rwprt;
/*-------------------------------------------------*/
/* Free the message block if it is empty. */
/*-------------------------------------------------*/
if(mblk->b_rptr >= mblk->b_wptr)
{
gs_freemsg(mblk);
chancfg->rdmblk = 0;
SerialIoctl((Lid)chancfg->lid, SIOCREPLENISH, (void *)0);
}
/*-------------------------------------------------*/
/* Free the semaphores which control the device. */
/*-------------------------------------------------*/
sm_v(chancfg->rda_id);
sm_v(chancfg->wra_id);
return;
}
chancfg->dflags &= ~WAITING;
/*-----------------------------------------------------*/
/* Free write semphore so others can write. */
/*-----------------------------------------------------*/
sm_v(chancfg->wra_id);
/*-----------------------------------------------------*/
/* Restore echo mblock pointer so it can be reused. */
/*-----------------------------------------------------*/
echo_mblk->b_wptr = chancfg->echo_rwprt;
echo_mblk->b_rptr = chancfg->echo_rwprt;
}
continue;
}
/*-------------------------------------------------------------*/
/* If ECHO echo the character. */
/*-------------------------------------------------------------*/
if((chancfg->termio.c_lflag & ECHO) ||
((chancfg->termio.c_lflag & ECHONL) &&
(character == chancfg->termio.c_cc[VEOL])))
{
echo_mblk = chancfg->echo_mblk;
if((c_oflag = chancfg->termio.c_oflag) & OPOST)
/*-----------------------------------------------------*/
/* Out-put needs post processing. */
/*-----------------------------------------------------*/
opost(&character, echo_mblk, 1, c_oflag);
else
*echo_mblk->b_wptr++ = character;
/*---------------------------------------------------------*/
/* Send character out and wait for send to complete. */
/* NOTE semaphore released by data conformation function, */
/* term_datacnf. */
/*---------------------------------------------------------*/
/* Request to write to device, and wait until */
/* availability. */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -