📄 sysserial.c
字号:
/* sysSerial.c - MPC860 SMC UART BSP serial device initialization *//* Copyright 1984-1998 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01h,19mar99,cn only SMC1 is initialized on MPC823/850 (SPR# 25839).01g,19feb99,cn fixed mangen error.01f,28jan99,cn Added support for the second SMC channel (SPR# 10005).01e,08may98,gls Added clearing of serial interrupts to sysSerialHwInit01d,06nov96,tpr replaced SYS_CPU_FREQ by BRGCLK_FREQ.01c,20jun96,tpr added sysSerialReset().01b,28may96,dzb tweaked setting of portB registers.01a,19apr86,cah created*//*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 two SMC channels in UART mode only.*/ #include "vxWorks.h"#include "iv.h"#include "intLib.h"#include "config.h"#include "sysLib.h"#include "drv/sio/ppc860Sio.h"#include "drv/multi/ppc860Cpm.h"#include "sgrwm7040.h"/* defines *//* * the macros below define parameters describing the configuration of * the SMCs channels in the PPC860's DPRAM, for instance the offset * of the transmit buffer descriptors (TBD), receive buffer descriptors * (RBD), and so on. The user may redefine them to best suit its needs. * He should be aware of the location of other peripherals's parameters * within the DPRAM (SCC1, etc.). *//* offset from DPRAM of SMC1's TBDs */#define SMC1_TBD_OFF 0x200/* offset from DPRAM of SMC1's RBDs */#define SMC1_RBD_OFF (SMC1_TBD_OFF + 0x10)/* offset from DPRAM of SMC1's Tx buffers */#define SMC1_TX_BUF_OFF 0x300/* offset from DPRAM of SMC1's Rx buffers */#define SMC1_RX_BUF_OFF (SMC1_TX_BUF_OFF + 0x80)/* number of SMC1's TBDs */#define SMC1_TBD_NUM 0x01/* number of SMC1's RBDs */#define SMC1_RBD_NUM 0x10/* offset from DPRAM of SMC2's TBDs */#define SMC2_TBD_OFF 0x400/* offset from DPRAM of SMC2's RBDs */#define SMC2_RBD_OFF (SMC2_TBD_OFF + 0x10)/* offset from DPRAM of SMC2's Tx buffers */#define SMC2_TX_BUF_OFF 0x500/* offset from DPRAM of SMC2's Rx buffers */#define SMC2_RX_BUF_OFF (SMC2_TX_BUF_OFF + 0x80)/* number of SMC2's TBDs */#define SMC2_TBD_NUM 0x01/* number of SMC2's RBDs */#define SMC2_RBD_NUM 0x10/* size of the SMC1 transmit buffer */#define SMC1_TX_BUF_SZ 0x01/* size of the SMC2 transmit buffer */#define SMC2_TX_BUF_SZ 0x01/* device initialization structure */ typedef struct { UINT32 smcTbdOff; /* offset of the TBDs for this smc */ UINT32 smcRbdOff; /* offset of the RBDs for this smc */ UINT32 smcTbdNum; /* number of TBDs for this smc */ UINT32 smcRbdNum; /* number of RBDs for this smc */ UINT32 smcTxBufOff; /* offset of the Tx buf for this smc */ UINT32 smcRxBufOff; /* offset of the Rx buf for this smc */ UINT32 smcTxBufSz; /* size of the Tx buf for this smc */ } PPC860SMC_PARMS; /* forward declaration */ /* Local data structures */ static UINT8 chanNum = NUM_TTY; /* number of channels actually used */static PPC860SMC_PARMS ppc860SmcParms [] = { {SMC1_TBD_OFF, SMC1_RBD_OFF, SMC1_TBD_NUM, SMC1_RBD_NUM, SMC1_TX_BUF_OFF, SMC1_RX_BUF_OFF, SMC1_TX_BUF_SZ}, {SMC2_TBD_OFF, SMC2_RBD_OFF, SMC2_TBD_NUM, SMC2_RBD_NUM, SMC2_TX_BUF_OFF, SMC2_RX_BUF_OFF, SMC2_TX_BUF_SZ}, }; static PPC860SMC_CHAN ppc860Chan [NUM_TTY];/******************************************************************************** sysSerialHwInit - initialize the BSP serial devices to a quiesent state** This routine initializes the BSP serial device descriptors and puts the* devices in a quiesent state. It is called from sysHwInit() with* interrupts locked.** Both the SMC serial channels are initialized if the variable chanNum * equals two. In this case, SMC1 uses BRG1 and SMC2 uses BRG2. However, * if using an MPC823/850 processor, only SMC1 is initialized.** Data Parameter Ram layout:** -----------------------------* | | DPRAM base * | |* | |* | |* |---------------------------|* | 8 bytes per descriptor | SMC1 Tx Buffer Descriptor (0x2200)* |---------------------------|* | |* |---------------------------|* | 16 descriptors @ | SMC1 Rx Buffer Descriptors (0x2210)* | 8 bytes per descriptor | * | |* |---------------------------|* | | end SMC1 Rx BDs (0x2290)* | |* | |* |---------------------------|* | 80 bytes allowed | SMC1 Tx Buffer (0x2300 + DPRAM base )* |---------------------------|* | one receive char/buffer | SMC1 Rx Buffer (0x2380 + DPRAM base )* |---------------------------|* | |* | |* |---------------------------|* | 8 bytes per descriptor | SMC2 Tx Buffer Descriptor (0x2400)* |---------------------------|* | |* |---------------------------|* | 16 descriptors @ | SMC2 Rx Buffer Descriptors (0x2410)* | 8 bytes per descriptor | * | |* |---------------------------|* | | end SMC2 Rx BDs (0x2490)* | |* | |* |---------------------------|* | 80 bytes allowed | SMC2 Tx Buffer (0x2500 + DPRAM base )* |---------------------------|* | one receive char/buffer | SMC2 Rx Buffer (0x2580 + DPRAM base )* |---------------------------|* | |* | |* | |* | |* |---------------------------|* | 34 bytes of parameter info| SMC1 Parameter Area (0x3e80)* | including Rx and Tx BD | * | pointers, func codes |* | etc... |* |---------------------------|* | |* |---------------------------|* | 34 bytes of parameter info| SMC2 Parameter Area (0x3f80)* | including Rx and Tx BD | * | pointers, func codes |* | etc... |* |---------------------------|* | |* | |**** RETURNS: N/A*/ void sysSerialHwInit (void) { int i; /* an index */ /* intialize the chips device descriptors */ for (i = 0; i < chanNum; i++) { UINT32 regBase; /* BRGCLK freq (Hz) */ ppc860Chan [i].clockRate = BRGCLK_FREQ; /* IMMR reg has base adr */ ppc860Chan [i].regBase = vxImmrGet(); regBase = ppc860Chan [i].regBase; /* use BRG1 for channel 1 and BRG2 for channel 2 */ ppc860Chan [i].bgrNum = (i + 1); /* SMC wired for rs232 */ ppc860Chan [i].uart.smcNum = (i + 1); /* init the number of TBDs */ ppc860Chan [i].uart.txBdNum = ppc860SmcParms[i].smcTbdNum; /* init the number of RBDs */ ppc860Chan [i].uart.rxBdNum = ppc860SmcParms[i].smcRbdNum; /* transmit BD base adrs */ ppc860Chan [i].uart.txBdBase = (SMC_BUF *) (MPC860_REGB_OFFSET + ppc860SmcParms[i].smcTbdOff); /* receive BD base adrs */ ppc860Chan [i].uart.rxBdBase = (SMC_BUF *) (MPC860_REGB_OFFSET + ppc860SmcParms[i].smcRbdOff); /* tx buf base */ ppc860Chan [i].uart.txBufBase = (u_char *) (MPC860_DPRAM_BASE (regBase) + ppc860SmcParms[i].smcTxBufOff); /* rx buf base */ ppc860Chan [i].uart.rxBufBase = (u_char *) (MPC860_DPRAM_BASE (regBase) + ppc860SmcParms[i].smcRxBufOff); /* transmit buffer size */ ppc860Chan [i].uart.txBufSize = ppc860SmcParms[i].smcTxBufSz; /* DPRAM addr of SMC1 params */ ppc860Chan [i].uart.pSmc = (SMC *) ((UINT32) PPC860_DPR_SMC1 (MPC860_DPRAM_BASE (regBase)) + (i * 0x100)); /* SMCMR1 for SMC1 */ ppc860Chan [i].uart.pSmcReg = (SMC_REG *) ((UINT32) MPC860_SMCMR1 (regBase) + (i * 0x10)); /* Mask interrupts */ ppc860Chan [i].uart.pSmcReg->smcm = 0; ppc860Chan [i].pBaud = (UINT32 *) ((UINT32) MPC860_BRGC1 (regBase) + (i * 4)); ppc860Chan [i].channelMode = 0; /* select RS232 pins */ *MPC860_PBPAR(regBase) |= 0xC0 << (i * 4); /* set it to normal operations */ *MPC860_SDCR(regBase) = SDCR_RAID_BR5; /* reset the chip */ ppc860DevInit(&(ppc860Chan [i])); } }/******************************************************************************** sysSerialHwInit2 - connect BSP serial device interrupts** This routine connects the BSP serial device interrupts. It is called from* sysHwInit2(). Serial device interrupts could not be connected in* sysSerialHwInit() because the kernel memory allocator was not initialized* at that point, and intConnect() calls malloc().** RETURNS: N/A*/ void sysSerialHwInit2 (void) { int i; /* an index */ /* connect serial interrupts */ for (i = 0; i < chanNum; i++) { switch (i) { case 0: (void) intConnect (IV_SMC1, (VOIDFUNCPTR) ppc860Int, (int) &ppc860Chan [i]); break; case 1: (void) intConnect (IV_SMC2_PIP, (VOIDFUNCPTR) ppc860Int, (int) &ppc860Chan [i]); break; default: return; } *CIMR(vxImmrGet()) |= (CIMR_SMC1 >> i); } }/******************************************************************************** sysSerialChanGet - get the SIO_CHAN device associated with a serial channel** This routine gets the SIO_CHAN device associated with a specified 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 >= chanNum) return ((SIO_CHAN *) ERROR); return ((SIO_CHAN *) &ppc860Chan [channel]); }/********************************************************************************* sysSerialReset - reset the serail device ** This function calls sysSerialHwInit() to reset the serail device** RETURNS: N/A**/void sysSerialReset (void) { sysSerialHwInit (); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -