📄 sysserial.c
字号:
/* sysSerial.c - IBM CPC700 serial device initialization *//******************************************************************************* This source and oject code has been made available to you by IBM on an AS-IS basis. IT IS PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OR OF NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL IBM OR ITS LICENSORS BE LIABLE FOR INCIDENTAL, CONSEQUENTIAL OR PUNITIVE DAMAGES. IBM'S OR ITS LICENSOR'S DAMAGES FOR ANY CAUSE OF ACTION, WHETHER IN CONTRACT OR IN TORT, AT LAW OR AT EQUITY, SHALL BE LIMITED TO A MAXIMUM OF $1,000 PER LICENSE. Anyone receiving this source or object code is licensed under IBM copyrights to use it in any way he or she deems fit, including copying it, modifying it, compiling it, and redistributing it either with or without modifications. No license under IBM patents or patent applications is to be implied by the copyright license. Any user of this software should understand that neither IBM nor its licensors will be responsible for any consequences resulting from the use of this software. Any person who transfers this object code or any derivative work must include the IBM copyright notice in the transferred software. COPYRIGHT I B M CORPORATION 1999 LICENSED MATERIAL - PROGRAM PROPERTY OF I B M"*******************************************************************************//* Copyright 1984-1997 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01a,27mar01,kab Removed IBM support info per request 13mar00,ajm changed underlying driver from evbNs16550Sio to ns16550Sio01a,05mar99,mcg created from IBM evb403 sysSerial.c ver 01f*//*DESCRIPTIONThis library contains board-specific routines for serial devices.There are two serial ports integrated into the IBM CPC700 chipset. Thesedevices are 16550-like, but only the transmit and receive signals are broughtout to pins on the chip for each device. The Ns16550Sio driver is usedfor both devices.*/#include "vxWorks.h"#include "config.h"#include "iv.h"#include "intLib.h"#include "sysLib.h"#include "drv/sio/ns16552Sio.h"/* device initialization structure */typedef struct { USHORT vector; ULONG baseAdrs; USHORT regSpace; USHORT intLevel; } NS16550_CHAN_PARAS;/* initialize the structure for each serial device */static NS16550_CHAN_PARAS dev0Paras = {0,UART0ADR,UART_REG_ADDR_INTERVAL,INT_LVL_UART0};static NS16550_CHAN_PARAS dev1Paras = {0,UART1ADR,UART_REG_ADDR_INTERVAL,INT_LVL_UART1};#define UART0_REG(reg) (dev0Paras.baseAdrs + reg*dev0Paras.regSpace)#define UART1_REG(reg) (dev1Paras.baseAdrs + reg*dev1Paras.regSpace)static NS16550_CHAN ns16550Chan0;static NS16550_CHAN ns16550Chan1;/******************************************************************************** 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.** RETURNS: N/A** SEE ALSO: sysHwInit()*/void sysSerialHwInit ( void ) { UINT32 cpu_bus_freq; UINT32 uart_clk_freq; /* * Disable and clear serial interrupts in the CPC700 UIC for both UARTs */ intDisable(INT_LVL_UART0); intDisable(INT_LVL_UART1); /* * intialize serial device 0 descriptors (S1) */ ns16550Chan0.level = dev0Paras.intLevel; ns16550Chan0.channelMode = 0; ns16550Chan0.lcr = UART0_REG(LCR); ns16550Chan0.ier = UART0_REG(IER); ns16550Chan0.mcr = UART0_REG(MCR); ns16550Chan0.options = 0; ns16550Chan0.baudRate = 9600; ns16550Chan0.regs = (UINT8 *)dev0Paras.baseAdrs; ns16550Chan0.regDelta = 1 ; /* * intialize serial device 1 descriptors (S2) */ ns16550Chan1.level = dev1Paras.intLevel; ns16550Chan1.channelMode = 0; ns16550Chan1.lcr = UART1_REG(LCR); ns16550Chan1.ier = UART1_REG(IER); ns16550Chan1.mcr = UART1_REG(MCR); ns16550Chan1.options = 0; ns16550Chan1.baudRate = 9600; ns16550Chan1.regs = (UINT8 *)dev1Paras.baseAdrs; ns16550Chan1.regDelta = 1; /* * Get the CPU bus speed from which the UART baud rate generator * frequency can be derived. * clock supplied to CPU = x * CPC700 clock = x/2 (found in FPGA_REG_A) * UART clock = x/8 (CPC700 clock / 4) */ cpu_bus_freq = sysGetBusSpd(); if (cpu_bus_freq == 83333333) uart_clk_freq = 0x9f6000; /* CPU bus freq = 83.33Mhz */ else { if (cpu_bus_freq == 66666666) uart_clk_freq = 0x7e9000; /* CPU bus freq = 66.66Mhz */ else uart_clk_freq = 0x72d800; /* CPU bus freq = 60.00Mhz */ } ns16550Chan0.xtal = uart_clk_freq; ns16550Chan1.xtal = uart_clk_freq; /* * reset both devices */ ns16550DevInit(&ns16550Chan0); ns16550DevInit(&ns16550Chan1); }/******************************************************************************** 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 intLevel = intLock (); /* * Connect serial interrupt handlers for S1 (UART 0) * and enable serial interrupts for S1 */ (void) intConnect (INUM_TO_IVEC(INT_VEC_UART0), ns16550Int, (int) sysSerialChanGet(0)); intEnable (INT_LVL_UART0); /* * connect serial interrupt handlers for S2 (UART 1) * and enable serial interrupts for S2 */ (void) intConnect (INUM_TO_IVEC(INT_VEC_UART1), ns16550Int, (int) sysSerialChanGet(1)); intEnable (INT_LVL_UART1); intUnlock (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 */ ) { switch (channel) { case 0: /* S1 */ return ((SIO_CHAN *)&ns16550Chan0); case 1: /* S2 */ return ((SIO_CHAN *)&ns16550Chan1); default: return ((SIO_CHAN *)ERROR); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -