📄 sdc.c
字号:
/****************************************************************************/
/* */
/* Copyright (c) 1999 by Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the subject */
/* matter of this material. All manufacturing, reproduction, use and sales */
/* rights pertaining to this subject matter are governed by the license */
/* agreement. The recipient of this software implicity accepts the terms */
/* of the license. */
/* */
/****************************************************************************/
/****************************************************************************/
/* */
/* FILENAME */
/* */
/* SDC.C M68EZ328/ D 1.0 */
/* */
/* DESCRIPTION */
/* */
/* This file contains the Serial Driver specific functions. */
/* */
/* DATA STRUCTURES */
/* */
/* SD_PORT * : An array of pointers to serial port structures. */
/* */
/* FUNCTIONS */
/* */
/* SDC_Init_Port */
/* SDC_Date_Ready */
/* SDC_Put_String */
/* SDC_LISR */
/* SDC_Get_Char */
/* SDC_Put_Char */
/* SDC_Set_Baud_Rate */
/* SD_Send_Break */
/* SD_Flush_Rx_FIFO */
/* */
/* DEPENDENCIES */
/* */
/* nucleus.h */
/* urt_defs.h */
/* urt_extr.h */
/* */
/****************************************************************************/
#include "plus\nucleus.h"
#include "sd_defs.h"
#include "sd_extr.h"
/* Define a small array to hold pointers to the two UART data
structures. This is used by the LISR to find the correct
data structure for the interrupt being handled. */
SD_PORT *SDC_Port_List[SD_MAX_UARTS];
/* Define prototypes for functions local to this module. */
static VOID SDC_LISR(INT vector);
static VOID SDC_Set_Baud_Rate(UNSIGNED, SD_PORT *);
STATUS SD_Send_Break(SD_PORT *uart);
STATUS SD_Flush_Rx_FIFO(SD_PORT *uart);
#define BCLR(var,bit) (var &= ~(bit))
/****************************************************************************/
/* FUNCTION */
/* */
/* SDC_Init_Port */
/* */
/* DESCRIPTION */
/* */
/* This function intializes the COM port that will be used for PPP */
/* communications. */
/* */
/* CALLED BY */
/* */
/* Application */
/* */
/* CALLS */
/* */
/* NU_Local_Control_Interrupts */
/* SDC_Set_Baud_Rate */
/* */
/* INPUTS */
/* */
/* SD_PORT * : device initialization structure. */
/* */
/* OUTPUTS */
/* */
/* STATUS : Returns NU_SUCCESS if successful initialization, */
/* else a negative value is returned. */
/* */
/****************************************************************************/
STATUS SDC_Init_Port(SD_PORT *uart)
{
STATUS status;
VOID (*old_lisr)(INT); /* old LISR */
INT int_level; /* old interrupt level */
static INT num_ports = 0;
INT i;
unsigned short data_bits;
unsigned short stop_bits;
unsigned short parity;
unsigned short parity_enabled;
/* Check the supplied parity */
if ((uart->parity != SD_PARITY_NONE) &&
(uart->parity != SD_PARITY_EVEN) &&
(uart->parity != SD_PARITY_ODD))
{
/* The supplied parity is not valid */
status = NU_SD_INVALID_PARITY;
}
/* Check the supplied number of data bits */
else if ((uart->data_bits != SD_DATA_BITS_7) &&
(uart->data_bits != SD_DATA_BITS_8))
{
/* The supplied data bits value is not valid */
status = NU_SD_INVALID_DATA_BITS;
}
/* Check the supplied number of stop bits */
else if ((uart->stop_bits != SD_STOP_BITS_1) &&
(uart->stop_bits != SD_STOP_BITS_2))
{
/* The supplied stop bits value is not valid */
status = NU_SD_INVALID_STOP_BITS;
}
else if ((uart->baud_rate < 300) || (uart->baud_rate > 390625))
{
/* The baud rate is out of range */
status = NU_SD_INVALID_BAUD;
}
/* Validate the com port. Only One Useable Com port with 68EZ328*/
else if (uart->com_port == SD_UART1)
{
/* Register the LISR for this interrupt. */
status = NU_Register_LISR(SD_UART_VECTOR+4, SDC_LISR, &old_lisr);
/* Set the base address for this UART. */
uart->base_address = (0xfffff000);
/* Save off the vector. */
uart->vector = SD_UART_VECTOR+4;
}
else
{
/* Not a supported port. */
status = NU_SD_INVALID_COM_PORT;
}
/* Make sure all the above was completed and
store off this UART stucture. */
if ((status == NU_SUCCESS) && (num_ports < SD_MAX_UARTS))
{
SDC_Port_List[num_ports++] = uart;
/* Initialize the UART */
/* Setup the SD buffer */
uart-> buffer.read = uart-> buffer.write =
uart-> buffer.head = uart-> buffer.data;
uart->buffer.tail = uart->buffer.head + SD_BUFFER_SIZE - 1;
uart->buffer.status = NU_SD_BUFFER_EMPTY;
/* Disable interrupts */
int_level = NU_Local_Control_Interrupts(NU_DISABLE_INTERRUPTS);
/* Initialize the Control/Status Register */
SD_OUTWORD((uart->base_address+USCREG),0);
/* Delay for a Bit */
for(i=0; i<100000; i++);
/* Set the Baud Rate */
SDC_Set_Baud_Rate(uart->baud_rate, uart);
/* Set TX Mode to Ignore CTS */
SD_OUTBYTE ((uart->base_address + UTX_REGS),SD_TX_NO_CTS);
/* INIT Misc Register to 0 */
SD_OUTWORD((uart->base_address+UMISC),0);
/* Set the UART Driver to the passed in Parameters */
/* Determine Partity */
switch(uart->parity)
{
case SD_PARITY_NONE:
parity=0;
parity_enabled=0;
break;
case SD_PARITY_EVEN:
parity= 0;
parity_enabled=SD_PARITY_ENABLE;
break;
case SD_PARITY_ODD_SET:
parity=SD_PARITY_ODD;
parity_enabled=SD_PARITY_ENABLE;
break;
}
/* Set the Data Bits */
switch(uart->data_bits)
{
case SD_DATA_BITS_7:
data_bits=0;
break;
case SD_DATA_BITS_8:
data_bits=SD_DATA_BITS_8;
break;
}
/* Set the Stop Bits */
switch(uart->stop_bits)
{
case SD_STOP_BITS_1:
stop_bits=0;
break;
case SD_STOP_BITS_2:
stop_bits=SD_STOP_BITS_2;
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -