📄 sdc.c
字号:
/**************************************************************************
*
* Copyright (c) 2001 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.
*
***************************************************************************
***************************************************************************
*
* FILE NAME VERSION
*
* sdc.c Nucleus PLUS\MPC8245\Diab C/C++ 1.13.1
*
* 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
*
* DEPENDENCIES
*
* nucleus.h
* sd_defs.h
* sd_extr.h
* target.h
* protocol.h
* externs.h
* ppp.h
*
* HISTORY
*
* NAME DATE REMARKS
*
* T. Weller 12\19\2001 Created inital version 1.13.1
****************************************************************************/
#include "nucleus.h"
#include "sd_defs.h"
#include "sd_extr.h"
#ifdef NU_ENABLE_PPP
#include "net\target.h"
#include "net\inc\externs.h"
#include "net\inc\tcp_errs.h"
#include "ppp\inc\ppp.h"
#endif /* NU_ENABLE_PPP */
extern NU_MEMORY_POOL System_Memory;
/* 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. */
/**************** Begin Port Specific Section **************/
static VOID SDC_LISR(INT vector);
#ifdef GRAFIX_MOUSE
extern NU_HISR Mouse_HISR;
#endif
/**************** End Port Specific Section **************/
static VOID SDC_Set_Baud_Rate(UINT32, SD_PORT *);
/***************************************************************************
* FUNCTION
*
* SDC_Init_Port
*
* DESCRIPTION
*
* This function intializes the COM port that will be used for PPP
* communications.
*
*
* 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)
{
UINT32 imr_val; /* IMR register value */
STATUS status = NU_SUCCESS;
VOID (*old_lisr)(INT); /* old LISR */
INT int_level; /* old interrupt level */
CHAR sem_name[8];
static INT num_ports = 0;
/**************** Begin Port Specific Section **************/
CHAR tByte; /* used to surpress compiler warnings */
INT tInt;
UINT32 eumbbar, temp;
/***************** End Port Specific Section ***************/
#ifdef GRAFIX_MOUSE
if ((uart->communication_mode == SERIAL_MODE) ||
(uart->communication_mode == SERIAL_MOUSE))
#else
if (uart->communication_mode == SERIAL_MOUSE)
{
status = NU_INVALID_MOUSE_MODE;
}
else if (uart->communication_mode == SERIAL_MODE)
#endif
{
/* Check for max allowed UARTS. */
if (num_ports >= SD_MAX_UARTS)
/* We have already initialized the max allowed UARTS. */
status = NU_UART_LIST_FULL;
}
if (status != NU_SUCCESS)
return (status);
/* Check the supplied parity */
else if ((uart->parity != SD_PARITY_NONE) &&
(uart->parity != SD_PARITY_EVEN) &&
(uart->parity != SD_PARITY_ODD))
/* The supplied parity is not valid */
status = NU_INVALID_PARITY;
/* Check the supplied number of data bits */
else if ((uart->data_bits != SD_DATA_BITS_6) &&
(uart->data_bits != SD_DATA_BITS_7) &&
(uart->data_bits != SD_DATA_BITS_8))
/* The supplied data bits value is not valid */
status = NU_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_INVALID_STOP_BITS;
/**************** Begin Port Specific Section **************
Note: this section is port specific because not all UARTS
have a mode setting.
*/
/* Check the supplied mode */
else if ((uart->data_mode != SD_MODE_NORMAL))
/* The supplied mode is not valid */
status = NU_INVALID_DATA_MODE;
/**************** End Port Specific Section ****************/
/* Verify the baud rate is within acceptable range */
else if ((uart->baud_rate < 300) || (uart->baud_rate > 115200))
/* The baud rate is out of range */
status = NU_INVALID_BAUD;
/************** Begin Port Specific Section ****************/
/* Validate the com port. */
else if ((uart->com_port == SD_UART1) ||
(uart->com_port == SD_UART2))
{
/* Handle UART1 */
if (uart->com_port == SD_UART1)
{
/* Register the LISR for this interrupt. */
status = NU_Register_LISR(SD_UART1_VECTOR,
SDC_LISR, &old_lisr);
/* Set the base address for this UART. */
uart->base_address = (SD_BASE + SD_UART1_BASE_OFFSET);
/* Save off the vector. */
uart->vector = SD_UART1_VECTOR;
}
else /* Otherwise handle UART2. */
{
/* Register the LISR for this interrupt. */
status = NU_Register_LISR(SD_UART2_VECTOR,
SDC_LISR, &old_lisr);
/* Set the base address for this UART. */
uart->base_address = (SD_BASE + SD_UART2_BASE_OFFSET);
/* Save off the vector. */
uart->vector = SD_UART2_VECTOR;
}
}
else
/************** End Port Specific Section **************/
/* Not a supported port. */
status = NU_INVALID_COM_PORT;
#ifdef GRAFIX_MOUSE
if ((uart->communication_mode == SERIAL_MODE) ||
(uart->communication_mode == SERIAL_MOUSE))
#else
if (uart->communication_mode == SERIAL_MODE)
#endif
{
/* Make sure the port was valid and the LISR was
registered. Then create the semaphore used to make
the SD_Put_String service thread safe. */
if (status == NU_SUCCESS)
{
/* Allocate memory for the semaphore control block. */
status = NU_Allocate_Memory (&System_Memory,(VOID **) &uart->sd_semaphore, sizeof(NU_SEMAPHORE),
NU_NO_SUSPEND);
for(tInt=0; tInt < sizeof(NU_SEMAPHORE); tInt++)
/* Fixed SPR 211. Changed type from (UINT32) to (CHAR *) */
SD_OUTBYTE((CHAR *) uart->sd_semaphore + tInt, 0x00);
if (status == NU_SUCCESS)
{
/* Build the name. */
sem_name[0] = 's';
sem_name[1] = 'e';
sem_name[2] = 'r';
sem_name[3] = 'i';
sem_name[4] = 'a';
sem_name[5] = 'l';
sem_name[6] = '_';
sem_name[7] = (CHAR)(0x30 + num_ports);
status = NU_Create_Semaphore (uart->sd_semaphore, sem_name,
1, NU_FIFO);
}
}
/* Make sure all the above was completed. Then store off this
UART stucture and initialize the chip. */
if (status == NU_SUCCESS)
{
SDC_Port_List[num_ports++] = uart;
}
}
if (status == NU_SUCCESS)
{
/* Allocate memory for the data buffers. PPP only requires a TX
buffer so the allocation will be a little different for PPP mode. */
#ifdef GRAFIX_MOUSE
if ((uart->communication_mode == SERIAL_MODE) ||
(uart->communication_mode == SERIAL_MOUSE))
#else
if (uart->communication_mode == SERIAL_MODE)
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -