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

📄 templatesio.c

📁 z85c30 DRIVER RUN ON PC104 PC AND VXWORKS SYSTERM.
💻 C
📖 第 1 页 / 共 3 页
字号:
	status = ERROR;	}    /*     * TODO -  Typically, acknowledge the interrupt as soon as possible.     * Usually before passing data or error conditions upstream.     */    TEMPLATE_SIO_WRITE8(pChan,		TEMPLATE_CSR_ID, TEMPLATE_RESET_INT); /* ack interrupt*/    if (status == ERROR)	{	/* send error notification upstream */	(*pChan->errorRtn) (pChan->errorArg, SIO_ERROR_UNKNWN, NULL, 0);	}    else	{	/* send data character upstream */	(*pChan->putRcvChar) (pChan->putRcvArg, inChar);	}    }/******************************************************************************** templateSioIntTx - handle a channels transmitter-ready interrupt** RETURNS: N/A*/ LOCAL void templateSioIntTx    (    TEMPLATE_CHAN *	pChan		/* channel generating the interrupt */    )    {    char	outChar;    char	crData = 0;    BOOL	txReady = TRUE;    int		errorCode = SIO_ERROR_NONE;    /*     * TODO - Check the Tx status     *     * For PCI devices, do an immediate return if device is not asserting     * an interrupt.     */    TEMPLATE_PIPE_FLUSH(pChan);    TEMPLATE_SIO_READ8(pChan, TEMPLATE_CSR_ID, &crData);    /* TODO - Check for error conditions */    if (crData & TEMPLATE_CR_TX_ERROR)	{	/*	 * TODO - Typically you should determine the precise error condition	 * and perform all recovery operations here.	 */	TEMPLATE_SIO_WRITE8 (pChan, TEMPLATE_CSR_ID, TEMPLATE_RESET_TX);	errorCode = SIO_ERROR_UNKNWN;	txReady = TRUE; /* set to false if xmitter is not ready now */	}    /*     * If transmitter is okay and ready to send, lets see if there is a     * data character ready to be sent.     *     * If there's a character to transmit then write it out, else reset (idle)     * the transmitter. For chips with output FIFO's it is more efficient     * to fill the entire FIFO here.     */    if (txReady)	{	if ((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR)	    {	    /* TODO - Output data to device.  */	    TEMPLATE_SIO_WRITE8(pChan, TEMPLATE_DATA_ID, outChar);	    /*	     * TODO - If a device error occurs at this point, then	     * isolate the precise error type and try to recover.	     */	    }	else	    {	    /*	     * TODO - There is no more data to send.	     *	     * Put XMTR in an idle state. Higher layer	     * will call TxStartup entry to resume xmit operations.	     */	    TEMPLATE_SIO_WRITE8(pChan, TEMPLATE_CSR_ID, TEMPLATE_RESET_TX);	    }	}    /*     * TODO - If needed, you should acknowledge or reset the interrupt source     * as soon as possible, usually before passing any error conditions     * upstream.     */    TEMPLATE_SIO_WRITE8(pChan, TEMPLATE_CSR_ID, TEMPLATE_RESET_INT);    /* Pass any errorCodes upstream.  */    if (errorCode != SIO_ERROR_NONE)	{	(*pChan->errorRtn) (pChan->errorArg, errorCode, NULL, 0);	}    }/******************************************************************************** templateSioIntErr - handle a channels error interrupt** RETURNS: N/A*/ LOCAL void templateSioIntErr    (    TEMPLATE_CHAN *	pChan		/* channel generating the interrupt */    )    {    int errorCode = SIO_ERROR_NONE;    char controlReg;    TEMPLATE_PIPE_FLUSH(pChan);    TEMPLATE_SIO_READ8 (pChan, TEMPLATE_CSR_ID, &controlReg);    /*     * TODO - Determine the precise error condition and perform recovery     * operations.     *     * For PCI devices, do an immediate return if device is not asserting     * an interrupt.     */    /*     * TODO - If needed, you should acknowledge or reset the interrupt source     * as soon as possible, usually before passing any error conditions     * upstream.     */    TEMPLATE_SIO_WRITE8(pChan, TEMPLATE_CSR_ID, TEMPLATE_RESET_INT);    if (errorCode != SIO_ERROR_NONE)	(*pChan->errorRtn) (pChan->errorArg, errorCode, NULL, 0);    }/******************************************************************************** templateTxStartup - start the interrupt transmitter** This routine exits to inform the device to start transmitting data again.* The actual data will be obtained by calling the TxCharGet callback routine.** This routine is usually just the same as the tx interrupt routine.  This* routine runs at task level context and does not have to be interrupt safe.** RETURNS: OK on success, ENOSYS if the device is polled-only, or* EIO on hardware error.*/LOCAL int templateTxStartup    (    SIO_CHAN * pSioChan                 /* channel to start */    )    {    TEMPLATE_CHAN * pChan = (TEMPLATE_CHAN *)pSioChan;    /* This routine should only be called while in interrupt mode */    if (pChan->mode == SIO_MODE_INT)        {        if (pChan->options & CLOCAL)            {            /* TODO - No modem control - start immediately */            }        else            {	    /*	     * TODO - Modem controls are active. 	     *	     * If CTS is high, we can start immediately so just enable	     * the TX interrupt.	     *	     * If CTS is low, then we cannot send now.  The driver	     * should be set up to generate a TX interrupt when the CTS	     * line returns to the active state.	     */            }        /*	 * TODO - Enable the correct interrupts. A TX interrupt should either	 * occur immediately, or later when CTS becomes active.  That will start	 * the flow of data.	 *	 * There are two usual methods here.  The first is to just enable	 * TX interrupts, which should cause an immediate TX interrupt, which	 * will begin fetching and sending characters.	 *	 * The second method is to call the getTxChara callback here, put	 * the data to the transmitter directly, and then to enable TX	 * interrupts to fetch and send additional characters.	 */	TEMPLATE_SIO_WRITE8(pChan, TEMPLATE_CSR_ID, TEMPLATE_TX_ENABLE);        }    else	return ENOSYS;  	/* Not valid for polled mode operation */    return (OK);    }/******************************************************************************** templateCallbackInstall - install ISR callbacks to get/put chars** This driver allows interrupt callbacks for transmitting characters* and receiving characters. In general, drivers may support other* types of callbacks too.** RETURNS: OK on success, or ENOSYS for an unsupported callback type.*/ LOCAL int templateCallbackInstall    (    SIO_CHAN *	pSioChan,               /* channel */    int		callbackType,           /* type of callback */    STATUS	(*callback)(void *,...),  /* callback */    void *      callbackArg             /* parameter to callback */    )    {    TEMPLATE_CHAN * pChan = (TEMPLATE_CHAN *)pSioChan;    switch (callbackType)	{	case SIO_CALLBACK_GET_TX_CHAR:	    pChan->getTxChar	= (STATUS (*)(void *, char *))callback;	    pChan->getTxArg	= callbackArg;	    return (OK);	case SIO_CALLBACK_PUT_RCV_CHAR:	    pChan->putRcvChar	= (void (*)(void *, char))callback;	    pChan->putRcvArg	= callbackArg;	    return (OK);	case SIO_CALLBACK_ERROR:	    pChan->errorRtn	= (void (*)(void *, int, void *, int))callback;	    pChan->errorArg	= callbackArg;	    return (OK);	default:	    return (ENOSYS);	}    }/********************************************************************************* templatePollOutput - output a character in polled mode** Polled mode operation takes place without any kernel or other OS* services available.  Use extreme care to insure that this code does not* call any kernel services.  Polled mode is only for WDB system mode use.* Kernel services, semaphores, tasks, etc, are not available during WDB* system mode.** RETURNS: OK if a character arrived, EIO on device error, EAGAIN* if the output buffer if full. ENOSYS if the device is* interrupt-only.*/LOCAL int templatePollOutput    (    SIO_CHAN *	pSioChan,    char	outChar    )    {    TEMPLATE_CHAN * pChan = (TEMPLATE_CHAN *)pSioChan;    UINT8	status;    /* is the transmitter ready to accept a character? */    TEMPLATE_PIPE_FLUSH(pChan);    TEMPLATE_SIO_READ8(pChan, TEMPLATE_CSR_ID, &status);    /* TODO - determine if transmitter is ready */    if ((status & TEMPLATE_CR_TX_READY) == 0x00)	{	/* device is busy, try again later */	return (EAGAIN);	}    /* TODO - Check for TX errors */    if (status & TEMPLATE_CR_TX_ERROR)	{	/* TODO - decode specific error condition and handle it */	/* Do not make error callback, just return EIO */	return EIO;	}    else	{	/* TODO - transmit the character */	TEMPLATE_SIO_WRITE8(pChan, TEMPLATE_DATA_ID, outChar);	}    return (OK);    }/******************************************************************************** templatePollInput - poll the device for input** Polled mode operation takes place without any kernel or other OS* services available.  Use extreme care to insure that this code does not* call any kernel services.  Polled mode is only for WDB system mode use.* Kernel services, semaphores, tasks, etc, are not available during WDB* system mode.** RETURNS: OK if a character arrived, EIO on device error, EAGAIN* if the input buffer if empty, ENOSYS if the device is* interrupt-only.*/LOCAL int templatePollInput    (    SIO_CHAN *	pSioChan,    char *	thisChar    )    {    TEMPLATE_CHAN * pChan = (TEMPLATE_CHAN *)pSioChan;    UINT8	status;    /* Read RX device status */    TEMPLATE_PIPE_FLUSH(pChan);    TEMPLATE_SIO_READ8(pChan, TEMPLATE_CSR_ID, &status);    /* TODO - Check if receive data is available */    if ((status & TEMPLATE_CR_RX_AVAIL) == 0x00)	{	return EAGAIN;	/* no input available at this time */	}    /* TODO - Check for receive error conditions */    if (status & TEMPLATE_CR_RX_ERROR)	{	/* TODO - Decode and handle the specific error condition */	/* Do NOT call the error callback routine, just return EIO */	return EIO;	}    /* TODO - read character, store it, and return OK  */    TEMPLATE_SIO_READ8(pChan, TEMPLATE_DATA_ID, thisChar);    return (OK);    }/******************************************************************************** templateModeSet - toggle between interrupt and polled mode** RETURNS: OK on success, EIO on unsupported mode.*/LOCAL int templateModeSet    (    TEMPLATE_CHAN * pChan,		/* channel */    uint_t	    newMode          	/* new mode */    )    {    UINT8 temp;    if ((newMode != SIO_MODE_POLL) && (newMode != SIO_MODE_INT))	return (EIO);    TEMPLATE_PIPE_FLUSH(pChan);    if (pChan->mode == SIO_MODE_INT)	{	/* TODO - switch device to interrupt mode */	if (pChan->intConnect == FALSE)	    {	    TEMPLATE_SIO_INT_CONNECT(pChan,TEMPLATE_RXINT_ID,			    templateSioIntRcv, (void *)pChan);	    TEMPLATE_SIO_INT_CONNECT(pChan, TEMPLATE_TXINT_ID,			    templateSioIntTx, (void *)pChan);	    TEMPLATE_SIO_INT_CONNECT(pChan, TEMPLATE_ERRINT_ID,			    templateSioIntErr, (void *)pChan);	    pChan->intConnect = TRUE;	    }	TEMPLATE_SIO_READ8(pChan, TEMPLATE_CSR_ID, &temp);	temp |= TEMPLATE_INT_ENABLE;	TEMPLATE_SIO_WRITE8(pChan, TEMPLATE_CSR_ID, temp);	}    else	{	/* TODO - switch device to polled mode */	TEMPLATE_SIO_READ8(pChan, TEMPLATE_CSR_ID, &temp);	temp &= ~TEMPLATE_INT_ENABLE;	TEMPLATE_SIO_WRITE8(pChan, TEMPLATE_CSR_ID, temp);	}    /* activate  the new mode */    pChan->mode = newMode;    return (OK);    }/********************************************************************************* templateHup - hang up the modem control lines ** Resets the RTS and DTR signals.** RETURNS: OK always.*/LOCAL STATUS templateHup    (    TEMPLATE_CHAN * pChan 	/* pointer to channel */    )    {    /*     * TODO - Use global intLock if lockout time will be very short. If not,     * use a device specific lockout that will not damage overall system     * latency.     */    templateMstatSetClr (pChan,(SIO_MODEM_RTS|SIO_MODEM_DTR), FALSE);    return (OK);    }    /********************************************************************************* templateOpen - Set the modem control lines ** Set the modem control lines(RTS, DTR) TRUE if not already set.  ** RETURNS: OK*/LOCAL STATUS templateOpen    (    TEMPLATE_CHAN * pChan 	/* pointer to channel */    )    {    /*     * TODO - Use global intLock if lockout time will be very short. If not,     * use a device specific lockout that will not damage overall system     * latency.     */    templateMstatSetClr (pChan, (SIO_MODEM_RTS|SIO_MODEM_DTR), TRUE);    return (OK);    }/******************************************************************************** templateOptSet - set hardware options** This routine sets up the hardware according to the specified option* argument.  If the hardware cannot support a particular option value, then* it should ignore that portion of the request.** RETURNS: OK upon success, or EIO for invalid arguments.*/LOCAL int templateOptSet    (    TEMPLATE_CHAN * pChan,		/* channel */    uint_t	    newOpts          	/* new options */    )    {    int dataBits = 8;    int stopBits = 1;    BOOL hdweFlowCtrl=TRUE;    BOOL rcvrEnable = TRUE;    int  lvl;    if (pChan == NULL || newOpts & 0xffffff00)	return EIO;    /* do nothing if options already set */    if (pChan->options == newOpts)	return OK;    /* ignore requests for unsupported options */    /* decode individual request elements */    switch (newOpts & CSIZE)	{	case CS5:	    dataBits = 5; break;	case CS6:	    dataBits = 6; break;	case CS7:	    dataBits = 7; break;	default:	case CS8:	    dataBits = 8; break;	}    if (newOpts & STOPB)

⌨️ 快捷键说明

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