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

📄 uart.c

📁 文件内包含了nuclues的内核代码和针对Power PC的编译器。需要用VirtNet生成一个虚拟网卡才可使用
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************/
/*                                                                          */
/*      Copyright (c) 1997 by Accelerated Technology, Inc.                  */
/*                                                                          */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the subject */
/* matter of this material.  All manufacturing, reproduction, use and sales */
/* rights pertaining to this subject matter are governed by the license     */
/* agreement.  The recipient of this software implicity accepts the terms   */
/* of the license.                                                          */
/*                                                                          */
/****************************************************************************/
/****************************************************************************/
/*                                                                          */
/* FILENAME                                                 VERSION         */
/*                                                                          */
/*    UART.C                                             MPC860/D 1.3       */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This file contains the UART specific functions.  The functions in     */
/*    this file will have to be modified for each UART used.                */
/*                                                                          */
/* AUTHOR                                                                   */
/*                                                                          */
/*    Barry Sellew, Accelerated Technology, Inc.                            */
/*                                                                          */
/* DATA STRUCTURES                                                          */
/*                                                                          */
/*     UART_Communication_Mode                                              */
/*                                                                          */
/* FUNCTIONS                                                                */
/*                                                                          */
/*     UART_Init_Port                                                       */
/*     UART_LISR                                                            */
/*     UART_Get_Char                                                        */
/*     UART_Put_Char                                                        */
/*     UART_Put_String                                                      */
/*     UART_Set_Baud_Rate                                                   */
/*     UART_Change_Communication_Mode                                       */
/*                                                                          */
/* DEPENDENCIES                                                             */
/*                                                                          */
/*     nucleus.h                                                            */
/*     target.h                                                             */
/*     externs.h                                                            */
/*     protocol.h                                                           */
/*     ppp_defs.h                                                           */
/*     ppp_extr.h                                                           */
/*     mdm_extr.h                                                           */
/*     urt_defs.h                                                           */
/*     urt_extr.h                                                           */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*       NAME               DATE              REMARKS                       */
/*                                                                          */
/*     B. Sellew          01/09/97      Created initial version.            */
/*                                                                          */
/****************************************************************************/
#include "nucleus.h"
#include "mpc860.h"
#include "uart.h"
#ifdef NU_PPP
#include "target.h"
#include "ppp_defs.h"
#endif

INT      UART_Communication_Mode;

UNSIGNED UART_Parity_Error;
UNSIGNED UART_Frame_Error;
UNSIGNED UART_Overrun_Error;
UNSIGNED UART_Busy_Error;
extern UART_INIT  uart[2];

#define  RX_BUFFERS    16
#define  TX_BUFFERS     1

#pragma section SMC_BUF ".smcbuf" ".smcbuf"    
#pragma use_section SMC_BUF rxbuf, txbuf
char rxbuf[2][RX_BUFFERS * 2];       /* Rx buffer area for SMC1 and SMC2 */
char txbuf[2][TX_BUFFERS * 2];       /* Tx buffer area for SMC1 and SMC2 */

UNSIGNED_CHAR  rbd_idx[2];   /* Current Rx BD for SMC1 and SMC2 */
UNSIGNED_CHAR  tbd_idx[2];   /* Current Tx BD for SMC1 and SMC2 */

/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    UART_Init_Port                                                        */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This function intializes the SMC port that will be used for serial    */
/*    communications.                                                       */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    NU_Etopen                                                             */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    NU_Local_Control_Interrupts                                           */
/*    UART_Set_Baud_Rate                                                    */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    UART_INIT * :   UART initalization structure.                         */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    STATUS      :   Returns UART_SUCCESS if successful initialization,    */
/*                    else a negative value is returned.                    */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*        NAME          DATE              REMARKS                           */
/*                                                                          */
/*    B. Sellew       12/22/97      Created Initial version.                */
/*                                                                          */
/****************************************************************************/
STATUS UART_Init_Port(UART_INIT *uart_ptr)
{
    UNSIGNED       old_state;
    UNSIGNED       status = UART_SUCCESS;
    UNSIGNED       *bcsr1;
    UNSIGNED_CHAR  pram_index, smc;
    PDA            *immr = (PDA *)(Get_IMMR() & 0xffff0000);
    BD             *rbd, *tbd; 
    UNSIGNED_CHAR  i;

    /* check the validity of the requested port */
    if (uart_ptr->smc_port == SMC1)
    {
        pram_index = SMC1_PRAM;
        rbd = (BD *) immr->udata_bd;          
        tbd = rbd + RX_BUFFERS;          
    }
    else if (uart_ptr->smc_port == SMC2)
    {
        pram_index = SMC2_PRAM;
        rbd = ((BD *) immr->udata_bd) + (RX_BUFFERS + TX_BUFFERS);
        tbd = rbd + RX_BUFFERS;          
    }
    else
        status = UART_BAD_SMC_PORT;

    if (status == UART_SUCCESS)
    {

        /* disable interrupts */
        old_state = NU_Local_Control_Interrupts(NU_DISABLE_INTERRUPTS);

        /* initialize current BD pointers */
        rbd_idx[0] = rbd_idx[1] = 0;
        tbd_idx[0] = tbd_idx[1] = 0;

        if (uart_ptr->smc_port == SMC1)
        {

            /* setup PortB pins for SMC1 */
            immr->pip_pbpar |= (0x00c0);
            immr->pip_pbdir &= ~(0x00c0);

            /* set SMC1 to NMSI mode and use BRG1 clock */
            immr->si_simode &= ~(0x0000f000);            

        }
        else
        {

            /* setup PortB pins for SMC2 */
            immr->pip_pbpar |= (0x0c00);
            immr->pip_pbdir &= ~(0x0c00);

            /* set SMC2 to NMSI mode and use BRG2 clock */
            immr->si_simode &= ~(0xf0000000);            
            immr->si_simode |= 0x10000000;            

        }

        /* set the baud rate */
        UART_Set_Baud_Rate(uart_ptr->smc_port, uart_ptr->baud_rate);

        /* setup RBD and TBD pointers in SMC PRAM */
        immr->pram[pram_index].scc.pothers.smc_modem.psmc.u.rbase = 
            (unsigned short) &(rbd->status);
        immr->pram[pram_index].scc.pothers.smc_modem.psmc.u.tbase =
            (unsigned short) &(tbd->status);

        /* initialize Rx and Tx parameters for SMC, wait until the CPCR flag
           is clear */
        if (uart_ptr->smc_port == SMC1)
            for(immr->cp_cr = 0x0091; immr->cp_cr & 0x0001;) ;
        else
            for(immr->cp_cr = 0x00d1; immr->cp_cr & 0x0001;) ;

        /* set Rx and Tx function codes */
        immr->pram[pram_index].scc.pothers.smc_modem.psmc.u.rfcr = 0x18;
        immr->pram[pram_index].scc.pothers.smc_modem.psmc.u.tfcr = 0x18;

        /* initialize the SDMA configuration register */
        immr->dma_sdcr = 0x0001;

        /* set UART specific parameters:
              maximum buffer length = 1
              disable sending idle characters 
              last received break length = 0
              receive break condition counter = 0
              send 1 break character on STOP Tx command  */ 
        immr->pram[pram_index].scc.pothers.smc_modem.psmc.u.mrblr = 1;
        immr->pram[pram_index].scc.pothers.smc_modem.psmc.u.max_idl = 0;
        immr->pram[pram_index].scc.pothers.smc_modem.psmc.u.brkln = 0;
        immr->pram[pram_index].scc.pothers.smc_modem.psmc.u.brkec = 0;
        immr->pram[pram_index].scc.pothers.smc_modem.psmc.u.brkcr = 1;

        smc = uart_ptr->smc_port;

        /* setup Rx buffer descriptors */
        for (i = 0; i < RX_BUFFERS; i++, rbd++)

⌨️ 快捷键说明

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