📄 sdc.c
字号:
/**************************************************************************
*
* Copyright Mentor Graphics Corporation 2002
* All Rights Reserved.
*
* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS
* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS
* SUBJECT TO LICENSE TERMS.
*
***************************************************************************
***************************************************************************
*
* FILE NAME VERSION
*
* sdc.c Nucleus PLUS\ARM925\Code Composer 1.14.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
*
* B. Ronquillo 08-28-2002 Released version 1.14.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];
/************** Begin Port Specific Section ****************/
UINT8 SDC_TX_Int_Flag=0;
/*************** End Port Specific Section ****************/
/* Define prototypes for functions local to this module. */
/**************** Begin Port Specific Section **************/
#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)
{
STATUS status = NU_SUCCESS;
INT32 int_level, /* old interrupt level */
tInt;
UINT8 temp_byte;
UINT32 temp_word, int_val;
CHAR sem_name[8];
static INT num_ports = 0;
VOID (*old_lisr)(INT); /* old LISR */
#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_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;
/* 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 UARTA */
if (uart->com_port == SD_UART1)
{
/* Set the vector inside this structure */
uart->vector = SD_UART1_VECTOR;
/* Set the base address for this UART. */
uart->base_address = SD_UART1_BASE;
}
else /* Otherwise handle UARTB. */
{
/* Set the vector inside this structure */
uart->vector = SD_UART2_VECTOR;
/* Set the base address for this UART. */
uart->base_address = SD_UART2_BASE;
}
}
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
{
status = NU_Allocate_Memory (&System_Memory,(VOID**) &uart->tx_buffer,
(2 * uart->sd_buffer_size), NU_NO_SUSPEND);
/* Set the RX buffer to just past the TX buffer. */
uart->rx_buffer = (CHAR *)(uart->tx_buffer + uart->sd_buffer_size);
}
else
{
status = NU_Allocate_Memory (&System_Memory,(VOID**) &uart->tx_buffer,
uart->sd_buffer_size, NU_NO_SUSPEND);
}
if (status == NU_SUCCESS)
{
/* Setup the RX SD buffer */
uart->rx_buffer_read = uart->rx_buffer_write = 0;
uart->rx_buffer_status = NU_BUFFER_EMPTY;
/* Setup the TX SD buffer */
uart->tx_buffer_read = uart->tx_buffer_write = 0;
uart->tx_buffer_status = NU_BUFFER_EMPTY;
}
}
if (status == NU_SUCCESS)
{
/* Disable interrupts */
int_level = NU_Local_Control_Interrupts(NU_DISABLE_INTERRUPTS);
/* Initialize the UART */
/************** Begin Port Specific Section *************/
/* Determine the clock source of UART1 and UART2 */
SD_OUTDWORD(FUNC_MUX_CTRL_0 + MOD_CONF_CTRL_0, UART_CLOCK_SET);
if(uart->com_port==SD_UART1)
{
/* Turn off BT Module */
temp_byte = SD_INBYTE(EPLD_PWR_CNTRL);
SD_OUTBYTE (EPLD_PWR_CNTRL, (temp_byte | EPLD_PWR_BT_MOD));
/* Turn-on power to UART 1 through the EPLD (FPGA memory-mapped registers) */
temp_byte = SD_INBYTE(EPLD_PWR_CNTRL);
SD_OUTBYTE (EPLD_PWR_CNTRL, (temp_byte | EPLD_PWR_UART1));
}
else /* Set up UART2 */
{
/* Turn-on power to UART 2 through the EPLD (FPGA memory-mapped registers) */
temp_byte = SD_INBYTE(EPLD_PWR_CNTRL);
SD_OUTBYTE (EPLD_PWR_CNTRL, (temp_byte | EPLD_PWR_UART2));
}
/* Enable UART clock, make sure to release peripheral reset */
temp_word = SD_INDWORD(MPU_CLOCK_BASE + MPU_RSTCT2_OFFSET);
SD_OUTDWORD(MPU_CLOCK_BASE + MPU_RSTCT2_OFFSET, (temp_word | MPU_RSTCT2_PER_EN));
temp_word = SD_INDWORD(MPU_CLOCK_BASE + MPU_IDLECT2_OFFSET);
SD_OUTDWORD(MPU_CLOCK_BASE + MPU_IDLECT2_OFFSET, (temp_word | MPU_EN_XORPCK | MPU_EN_PERCK));
/* Configure the Mode Definition Register */
SD_OUTBYTE(uart->base_address + MDR_OFFSET, MDR_RESET_MODE);
/* MUX the UART Signals */
temp_word = SD_INDWORD(FUNC_MUX_CTRL_0);
if(uart->com_port==SD_UART1)
SD_OUTDWORD(FUNC_MUX_CTRL_0,temp_word | (1UL << 25));
else
SD_OUTDWORD(FUNC_MUX_CTRL_0,temp_word | (1UL << 24));
/* Reset the TX/RX FIFOs */
SD_OUTBYTE(uart->base_address + FCR_OFFSET, FCR_FIFO_RESET);
/* Setup baud rate */
SDC_Set_Baud_Rate(uart->baud_rate, uart);
/* Set the modem control register. Set DTR, RTS to output to LOW,
and set INT output pin to normal operating mode */
SD_OUTBYTE (uart->base_address + MCR_OFFSET, (MCR_DTR_LOW | MCR_RTS_LOW));
/* Setup parity, data bits, and stop bits */
SD_OUTBYTE (uart->base_address + LCR_OFFSET,
(LCR_NO_BREAK|uart->parity|uart->data_bits|uart->stop_bits ));
/* Setup Fifo trigger level and enable FIFO */
SD_OUTBYTE (uart->base_address + FCR_OFFSET, 0);
/* Register the interrupt handler for the UART receiver */
if (uart->com_port == SD_UART1)
status = NU_Register_LISR(SD_UART1_VECTOR, SDC_LISR, &old_lisr);
else
status = NU_Register_LISR(SD_UART2_VECTOR, SDC_LISR, &old_lisr);
if (status == NU_SUCCESS)
{
/* Enable the RX interrupts */
SD_OUTBYTE (uart->base_address + IER_OFFSET, IER_RX_HOLDING_REG);
/* Get the Level 1 Interrupt bit to be masked */
int_val = SD_INDWORD (ICBASE + INT_MASK_OFFSET);
int_val &= ~(LEVEL_2_INT);
SD_OUTDWORD(ICBASE + INT_MASK_OFFSET, int_val);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -