📄 sysserial.c
字号:
/* sysSerial.c - Serial device initialization *//* Copyright 1984-2001 Wind River Systems, Inc. *//* Copyright 1996-2001 Motorola, Inc. All Rights Reserved */#include "copyright_wrs.h"/*modification history--------------------01b,08feb01,cak Added support for COMs 2 and 301a,02nov00,djs created base on 01c,18feb99,srr mv2100*//*The sysSerial.c file is normally included as part of the sysLib.c file.This code segment configures the serial ports for the BSP.This BSP can support up to three 16550-compatible UARTs. */#include "vxWorks.h"#include "iv.h"#include "intLib.h"#include "config.h"#include "sysLib.h"#include "drv/sio/i8250Sio.h"/* externals */IMPORT UCHAR sysInByte(ULONG);IMPORT void sysOutByte(ULONG, UCHAR);IMPORT int intEnable (int intLevel);/* device initialization structures */typedef struct { USHORT vector; /* Interrupt vector */ ULONG baseAdrs; /* Register base address */ USHORT regSpace; /* Address Interval */ USHORT intLevel; /* Interrupt level */ } I8250_CHAN_PARAS;/* Local data structures */static I8250_CHAN i8250Chan[N_UART_CHANNELS];static I8250_CHAN_PARAS devParas[] = { {COM1_INT_VEC, COM1_BASE_ADR, UART_REG_ADDR_INTERVAL, COM1_INT_LVL}, {COM2_INT_VEC, COM2_BASE_ADR, UART_REG_ADDR_INTERVAL, COM2_INT_LVL}, {COM3_INT_VEC, COM3_BASE_ADR, UART_REG_ADDR_INTERVAL, COM3_INT_LVL} };#define UART_REG(reg,chan) \ (devParas[chan].baseAdrs + reg * devParas[chan].regSpace)/* globals *//* * sysSioChans - Array of pointers to all serial channels configured in system. * * Channel pointer position in this table determines the device name * under vxWorks. The first pointer points to the device for /tyCo/0, * the second to /tyCo/1, etc. See sysSerialChanGet(). */SIO_CHAN * sysSioChans [N_SIO_CHANNELS] = { (SIO_CHAN *)&i8250Chan[0].pDrvFuncs, /* /tyCo/0 */ (SIO_CHAN *)&i8250Chan[1].pDrvFuncs, /* /tyCo/1 */ (SIO_CHAN *)&i8250Chan[2].pDrvFuncs, /* /tyCo/2 */ };/******************************************************************************** sysSerialHwInit - initialize the BSP serial devices to a quiescent state** This routine initializes the BSP serial device descriptors and puts the* devices in a quiescent state. It is called from sysHwInit() with* interrupts locked. Polled mode serial operations are possible, but not* interrupt mode operations which are enabled by sysSerialHwInit2().** RETURNS: N/A** SEE ALSO: sysHwInit(), sysSerialHwInit2()*/void sysSerialHwInit (void) { int i; for (i = 0; i < N_UART_CHANNELS; i++) { i8250Chan[i].int_vec = devParas[i].vector; i8250Chan[i].channelMode = 0; i8250Chan[i].lcr = UART_REG(UART_LCR, i); i8250Chan[i].data = UART_REG(UART_RDR, i); i8250Chan[i].brdl = UART_REG(UART_BRDL, i); i8250Chan[i].brdh = UART_REG(UART_BRDH, i); i8250Chan[i].ier = UART_REG(UART_IER, i); i8250Chan[i].iid = UART_REG(UART_IID, i); i8250Chan[i].mdc = UART_REG(UART_MDC, i); i8250Chan[i].lst = UART_REG(UART_LST, i); i8250Chan[i].msr = UART_REG(UART_MSR, i); i8250Chan[i].outByte = (void (*) (int, char)) sysOutByte; i8250Chan[i].inByte = (UINT8 (*) ()) sysInByte; i8250HrdInit (&i8250Chan[i]); } }/******************************************************************************** sysSerialHwInit2 - connect BSP serial device interrupts** This routine connects the BSP serial device interrupts. It is called from* sysHwInit2(). * * Serial device interrupts cannot be connected in sysSerialHwInit() because* the kernel memory allocator is not initialized at that point, and* intConnect() calls malloc().** RETURNS: N/A** SEE ALSO: sysHwInit2()*/void sysSerialHwInit2 (void) { int i; /* connect serial interrupts */ for (i = 0; i < N_UART_CHANNELS; i++) if (i8250Chan[i].int_vec) { (void) intConnect (INUM_TO_IVEC ((int)i8250Chan[i].int_vec), i8250Int, (int)&i8250Chan[i] ); intEnable (devParas[i].intLevel); } }/******************************************************************************** sysSerialChanGet - get the SIO_CHAN device associated with a serial channel** This routine returns a pointer to the SIO_CHAN device associated* with a specified serial channel. It is called by usrRoot() to obtain * pointers when creating the system serial devices, `/tyCo/x'. It* is also used by the WDB agent to locate its serial channel.** RETURNS: A pointer to the SIO_CHAN structure for the channel, or ERROR* if the channel is invalid.*/SIO_CHAN * sysSerialChanGet ( int channel /* serial channel */ ) { if (channel < 0 || channel >= NELEMENTS(sysSioChans)) return (SIO_CHAN *)ERROR; return sysSioChans[channel]; }/******************************************************************************** sysSerialReset - reset all serial devices to a quiescent state** This routine resets all serial devices to a quiescent state. It is called * by sysToMonitor().** RETURNS: N/A** SEE ALSO: sysToMonitor()*/void sysSerialReset (void) { int i; for (i = 0; i < N_UART_CHANNELS; i++) i8250HrdInit (&i8250Chan[i]); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -