📄 uart.c
字号:
CHAR UART_Get_Char(UNSIGNED smc)
{
CHAR ch;
CHAR i;
if ((uart[smc].read != uart[smc].write) ||
uart[smc].buf_status == BUF_FULL)
{
i = uart[smc].read;
ch = uart[smc].buffer[i];
uart[smc].read = ++(uart[smc].read) % BUF_LEN;
uart[smc].buf_status = BUF_NOT_FULL;
}
else
ch = BUF_EMPTY;
return ch;
}
/****************************************************************************/
/* FUNCTION */
/* */
/* UART_Put_Char */
/* */
/* DESCRIPTION */
/* */
/* This writes a character out to the serial port. */
/* */
/* CALLED BY */
/* */
/* NU_Xmit_Packet */
/* MDM_Control_String */
/* */
/* CALLS */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* UNSIGNED : The SMC port to be written to */
/* CHAR : Character to to be written to the serial port. */
/* */
/* OUTPUTS */
/* */
/* none */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* B. Sellew 12/24/97 Created Initial version. */
/* */
/****************************************************************************/
VOID UART_Put_Char(UNSIGNED smc, CHAR ch)
{
PDA *immr = (PDA *) (Get_IMMR() & 0xffff0000);
BD *tbd = (BD *) immr->udata_bd;
if (smc == SMC1)
tbd += (RX_BUFFERS + tbd_idx[smc]);
else
tbd += ((RX_BUFFERS * 2) + TX_BUFFERS + tbd_idx[smc]);
/* write the character */
*(tbd->addr) = ch;
tbd->length = 1;
tbd->status |= 0x8000;
/* wait until the character has been sent */
while (tbd->status & 0x8000);
/* increment current Tx BD pointer */
tbd_idx[smc] = ++(tbd_idx[smc]) % TX_BUFFERS;
}
/****************************************************************************/
/* FUNCTION */
/* */
/* UART_Put_String */
/* */
/* DESCRIPTION */
/* */
/* This writes a null-terminated string out to the serial port. */
/* */
/* CALLED BY */
/* */
/* Application */
/* */
/* CALLS */
/* */
/* UART_Put_Char */
/* */
/* INPUTS */
/* */
/* UNSIGNED : The SMC port to be written to */
/* CHAR : Character to be written to the serial port. */
/* */
/* OUTPUTS */
/* */
/* none */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* B. Sellew 12/24/97 Created Initial version. */
/* */
/****************************************************************************/
VOID UART_Put_String(UNSIGNED smc, CHAR *str)
{
for (; *str != 0; str++)
UART_Put_Char(smc, *str);
}
/****************************************************************************/
/* FUNCTION */
/* */
/* UART_Set_Baud_Rate */
/* */
/* DESCRIPTION */
/* */
/* This function sets the baud rate control register to the input baud */
/* rate. */
/* */
/* CALLED BY */
/* */
/* MDM_Hangup */
/* */
/* CALLS */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* UNSINGED : The SMC port to configure */
/* UNSINGED : Baud rate */
/* */
/* OUTPUTS */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* B. Sellew 01/02/98 Created Initial version. */
/* */
/****************************************************************************/
VOID UART_Set_Baud_Rate(UNSIGNED smc, UNSIGNED baud_rate)
{
PDA *immr = (PDA *)(Get_IMMR() & 0xffff0000);
UNSIGNED br_div;
/* calculate the baud rate divisor */
br_div = (SYSCLK / (16 * baud_rate)) - 1;
/* if the divisor is too large, prescale by 16 */
if (br_div >= 4096)
{
br_div = br_div / 16;
br_div = br_div << 1;
br_div |= 1;
}
else
br_div = br_div << 1;
/* set the baud control register */
if (smc == SMC1)
immr->brgc1 = br_div | 0x10000;
else
immr->brgc2 = br_div | 0x10000;
} /* UART_Set_Baud_Rate */
/****************************************************************************/
/* FUNCTION */
/* */
/* UART_Change_Communication_Mode */
/* */
/* DESCRIPTION */
/* */
/* This function switches the serial port between terminal mode and */
/* PPP mode. The Mode affects where incoming characters are directed. */
/* */
/* CALLED BY */
/* */
/* MDM_Change_Communication_Mode */
/* */
/* CALLS */
/* */
/* none */
/* */
/* INPUTS */
/* */
/* INT : The mode of operation desired. */
/* */
/* OUTPUTS */
/* */
/* none */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* B. Sellew 01/02/98 Created Initial version. */
/* */
/****************************************************************************/
VOID UART_Change_Communication_Mode(INT mode)
{
UART_Communication_Mode = mode;
} /* UART_Change_Communication_Mode */
Get_IMMR ()
{
asm(" mfspr r3, 638");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -