📄 sdc.c
字号:
/*************************************************************************** * Copyright Mentor Graphics Corporation 2003 * 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\Integrator\ADS 1.14.9 * * 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 ** ***************************************************************************/#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);extern void ERC_System_Error(int); /**************** 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;VOID (*old_lisr)(INT); /* old LISR */INT int_level; /* old interrupt level */CHAR sem_name[8];static INT num_ports = 0;UINT32 tInt;UINT32 irq_base_offset = 0;NU_SUPERV_USER_VARIABLES /* Switch to supervisor mode */ NU_SUPERVISOR_MODE();#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 to user mode */ NU_USER_MODE(); 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; /* Verify the baud rate is within acceptable range */ else if ((uart->baud_rate < 1200) || (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_UART0) || (uart->com_port == SD_UART1)) { /* Handle UART0 */ if (uart->com_port == SD_UART0) { /* Register the LISR for this interrupt. */ status = NU_Register_LISR(SD_UIVR_UART0_VECTOR, SDC_LISR, &old_lisr); /* Set the vector inside this structure */ uart->vector = SD_UIVR_UART0_VECTOR; /* Set the base address for this UART. */ uart->base_address = SD_UART0_BASE; } else /* Otherwise handle UART1. */ { /* Register the LISR for this interrupt. */ status = NU_Register_LISR(SD_UIVR_UART1_VECTOR, SDC_LISR, &old_lisr); /* Set the vector inside this structure */ uart->vector = SD_UIVR_UART1_VECTOR; /* Set the base address for this UART. */ uart->base_address = SD_UART1_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++) 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -