⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 am85c30serial.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* am85c30Serial.c - Am85C30 ESCC (Enhanced Serial Communications Controller)                     tty driver*//* Copyright 1984-1993 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01c,27apr95,tpr  inverted RX and TX text in tyCoInt().01b,11mar94,pme  changed dedines to defines.01a,02dec93,pad  written, by modifying 01n of the z8530 version.*//*DESCRIPTIONThis is the driver for the Am85C30 ESCC (Enhanced Serial CommunicationsController).It uses the ESCCs in asynchronous mode only.USER-CALLABLE ROUTINESMost of the routines in this driver are accessible only through the I/Osystem.  Two routines, however, must be called directly: tyCoDrv() toinitialize the driver, and tyCoDevCreate() to create devices.Before the driver can be used, it must be initialized by calling tyCoDrv().This routine should be called exactly once, before any reads, writes, orcalls to tyCoDevCreate().  Normally, it is called by usrRoot() in usrConfig.c.Before a terminal can be used, it must be created using tyCoDevCreate().Each port to be used should have exactly one device associated with it bycalling this routine.IOCTL FUNCTIONSThis driver responds to the same ioctl() codes as a normal tty driver; formore information, see the manual entry for tyLib.  Available baud ratesrange from 50 to 38400.SEE ALSOtyLib*//* includes */#include "vxWorks.h"#include "iv.h"#include "ioLib.h"#include "iosLib.h"#include "tyLib.h"#include "intLib.h"#include "errnoLib.h"#include "drv/serial/am85c30.h"/* defines */#define DEFAULT_BAUD	9600/* externals */IMPORT TY_CO_DEV tyCoDv [];	/* device descriptors */IMPORT int delayCount;		/* used in SCC_DELAY *//* locals */LOCAL int tyCoDrvNum;		/* driver number assigned to this driver *//* forward declarations */LOCAL void   tyCoStartup (TY_CO_DEV * pTyCoDv);LOCAL int    tyCoOpen (TY_CO_DEV * pTyCoDv, char * name, int mode);LOCAL STATUS tyCoIoctl (TY_CO_DEV * pTyCoDv, int request, int arg);LOCAL void   tyCoHrdInit (void);LOCAL void   tyCoInitChannel (int channel);LOCAL void   tyCoResetChannel (int channel);/********************************************************************************* tyCoDrv - initialize the tty driver** This routine initializes the serial driver, sets up interrupt vectors, and* performs hardware initialization of the serial ports.** This routine should be called exactly once, before any reads, writes, or* calls to tyCoDevCreate().  Normally, it is called by usrRoot() in* usrConfig.c.** RETURNS: OK, or ERROR if the driver cannot be installed.** SEE ALSO: tyCoDevCreate()*/STATUS tyCoDrv (void)    {    /* check if driver already installed */    if (tyCoDrvNum > 0)	return (OK);    tyCoHrdInit ();    tyCoDrvNum = iosDrvInstall (tyCoOpen, (FUNCPTR) NULL, tyCoOpen,				(FUNCPTR) NULL, tyRead, tyWrite, tyCoIoctl);    (void) intConnect (INUM_TO_IVEC (INT_NUM_SCC), tyCoInt, 0);    return (tyCoDrvNum == ERROR ? ERROR : OK);    }/********************************************************************************* tyCoDevCreate - create a device for an on-board serial port** This routine creates a device on a specified serial port.  Each port* to be used should have exactly one device associated with it by calling* this routine.** For instance, to create the device "/tyCo/0", with buffer sizes of 512 bytes,* the proper call would be:* .CS*     tyCoDevCreate ("/tyCo/0", 0, 512, 512);* .CE** RETURNS: OK, or ERROR if the driver is not installed, the channel is* invalid, or the device already exists.** SEE ALSO: tyCoDrv()*/STATUS tyCoDevCreate    (    char * name,           /* name to use for this device      */    int    channel,        /* physical channel for this device */    int    rdBufSize,      /* read buffer size, in bytes       */    int    wrtBufSize      /* write buffer size, in bytes      */    )    {    TY_CO_DEV * pTyCoDv;    if (tyCoDrvNum <= 0)	{	errnoSet (S_ioLib_NO_DRIVER);	return (ERROR);	}    /* if this doesn't represent a valid channel, don't do it */    if (channel < 0 || channel >= tyCoDv [0].numChannels)	return (ERROR);    pTyCoDv = &tyCoDv [channel];    /* if there is a device already on this channel, don't do it */    if (pTyCoDv->created)	return (ERROR);    /* initialize the ty descriptor */    if (tyDevInit (&pTyCoDv->tyDev, rdBufSize, wrtBufSize,		   (FUNCPTR) tyCoStartup) != OK)	{	return (ERROR);	}    /* initialize the channel hardware */    tyCoInitChannel (channel);    /* mark the device as created, and add the device to the I/O system */    pTyCoDv->created = TRUE;    return (iosDevAdd (&pTyCoDv->tyDev.devHdr, name, tyCoDrvNum));    }/********************************************************************************* tyCoHrdInit - initialize the USART*/LOCAL void tyCoHrdInit (void)    {    int oldlevel;	/* current interrupt level mask */    int ix;    oldlevel = intLock ();	/* disable interrupts during init */    for (ix=0; ix < tyCoDv [0].numChannels; ix++)	tyCoResetChannel (ix);	/* reset channel */    intUnlock (oldlevel);    }/********************************************************************************* tyCoResetChannel - reset a single channel*/LOCAL void tyCoResetChannel    (    int channel    )    {    volatile char *	cr = tyCoDv [channel].cr; /* SCC control reg adr */    int			zero = 0;    *cr = zero;		/* SCC_WR0_NULL_CODE sync the state machine */    SCC_DELAY;    *cr = zero;		/* SCC_WR0_NULL_CODE sync the state machine */    SCC_DELAY;    *cr = SCC_WR0_ERR_RST;    SCC_DELAY;    *cr = SCC_WR0_RST_INT;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR9;      /* write register 9 - master int ctrl */    SCC_DELAY;    *cr = ((channel % 2) == 0) ?        SCC_WR9_CH_A_RST :      /* reset channel A */        SCC_WR9_CH_B_RST;       /* reset channel B */    SCC_DELAY; SCC_DELAY; SCC_DELAY; SCC_DELAY; SCC_DELAY; SCC_DELAY;     SCC_DELAY; SCC_DELAY; SCC_DELAY; SCC_DELAY; SCC_DELAY; SCC_DELAY;    }/********************************************************************************* tyCoInitChannel - initialize a single channel*/LOCAL void tyCoInitChannel    (    int channel    )    {    TY_CO_DEV *		pTyCoDv = &tyCoDv [channel];    volatile char *	cr = pTyCoDv->cr;	/* SCC control reg adr */    int			baudConstant;    int			oldlevel;	/* current interrupt level mask */    int			zero = 0;    oldlevel = intLock ();		/* disable interrupts during init */    /* initialize registers */    *cr = SCC_WR0_RST_TX_UND;		/* reset transmit underrun */    SCC_DELAY;    *cr = SCC_WR0_SEL_WR4;              /* write reg 4 - misc parms and modes */    SCC_DELAY;    *cr = SCC_WR4_1_STOP | SCC_WR4_16_CLOCK;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR1;    SCC_DELAY;    *cr = 0;				/* no DMA */    SCC_DELAY;    *cr = SCC_WR0_SEL_WR2;    SCC_DELAY;    *cr = 0;				/* no vector */    SCC_DELAY;    *cr = SCC_WR0_SEL_WR3;		/* write reg 3 - receive params */    SCC_DELAY;    *cr = SCC_WR3_RX_8_BITS;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR5;		/* tx params */    SCC_DELAY;    *cr = SCC_WR5_TX_8_BITS;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR6;		/* no sync mode */    SCC_DELAY;    *cr = zero;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR7;		/* no sync mode */    SCC_DELAY;    *cr = zero;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR9;		/* no interrupt acknowledge */    SCC_DELAY;    *cr = SCC_WR9_NV;    SCC_DELAY;    *cr = SCC_WR0_SEL_WR10;		/* misc tx/rx control */    SCC_DELAY;    *cr = zero;				/* clear sync, loop, poll */    SCC_DELAY;    *cr = SCC_WR0_SEL_WR11;		/* clock mode */    SCC_DELAY;    *cr = pTyCoDv->clockModeWR11;    SCC_DELAY;    /* Calculate the baud rate constant for the default baud rate     * from the input clock frequency.  This assumes that the     * divide-by-16 bit is set (done in WR4 above).     */    baudConstant = ((pTyCoDv->baudFreq / 32) / DEFAULT_BAUD) - 2;    *cr = SCC_WR0_SEL_WR12;		/* LSB of baud constant */    SCC_DELAY;    *cr = (char) baudConstant;		/* write LSB */    SCC_DELAY;    *cr = SCC_WR0_SEL_WR13;		/* MSB of baud constant */    SCC_DELAY;    *cr = (char) (baudConstant >> 8);	/* write MSB */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -