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

📄 uart.c

📁 文件内包含了nuclues的内核代码和针对Power PC的编译器。需要用VirtNet生成一个虚拟网卡才可使用
💻 C
📖 第 1 页 / 共 3 页
字号:
        {
            rbd->status = 0x9000;      
            rbd->length = 0;          
            rbd->addr = &(rxbuf[smc][i << 1]);
        }

        /* set the wrap bit in the last Rx buffer descriptor */
        --rbd;
        rbd->status |= 0x2000;

        /* setup Tx buffer descriptors */
        for (i = 0; i < TX_BUFFERS; i++, tbd++)
        {
            tbd->status = 0x0000;
            tbd->length = 1;
            tbd->addr = &(txbuf[smc][i << 1]);
        }

        /* set the wrap bit in the last Tx buffer descriptor */
        --tbd;
        tbd->status |= 0x2000;

        /* setup and enable SMC interrupts */
        immr->smc_regs[smc].smc_smce = 0xff;  /* clear pending events */
        immr->smc_regs[smc].smc_smcm = 0x05;  /* enable all interrupts */

        /* setup and enable CPM SMC interrupt */
        immr->cpmi_cipr = 0xffffffff;   /* clear all pending CPM interrupts */
        if (uart_ptr->smc_port == SMC1)
            immr->cpmi_cimr |= 0x000000010;      /* enable SMC1 interrupts */
        else
            immr->cpmi_cimr |= 0x000000008;      /* enable SMC2 interrupts */
        immr->cpmi_cicr = 0x939f80;     /* enable CPM interrups */

        /* enable CPM interrupt in SIU interrupt controller */
        immr->siu_simask |= 0x00400000;

        /* setup 8-N-1 configuration in the SMCMR register */
        immr->smc_regs[smc].smc_smcmr = 0x4820;

        /* enable Rx and Tx in the SMCMR register */
        immr->smc_regs[smc].smc_smcmr |= 0x0003; 

#ifdef ADS
        /* Get the base address of the BCSR1 register and assert the 
           RS232EN bit */ 
        bcsr1 = (unsigned long *)((immr->memc_br1 & 0xfffffffe) + 4);
        if (uart_ptr->smc_port == SMC1)
            *bcsr1 &=  0xfeffffff;
        else
            *bcsr1 &=  0xfffbffff;
#endif

#ifdef NU_PPP
        /* the PPP driver will begin in terminal mode. */
        UART_Communication_Mode = PPP_TERMINAL_COMMUNICATION;
#endif

        /* initialize the error counters. */
        UART_Parity_Error = UART_Frame_Error = UART_Overrun_Error = 
           UART_Busy_Error = 0;

        /* restore previous interrupt lockout status */
        NU_Local_Control_Interrupts(old_state);
    }

    return (status);

}


/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    UART_LISR                                                             */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This is the entry function for the ISR that services the UART.        */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    none                                                                  */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    NU_Local_Control_Interrupts                                           */
/*    PPP_Receive                                                           */
/*    MDM_Receive                                                           */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    INT         :   Interrupt vector                                      */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    none                                                                  */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*        NAME             DATE              REMARKS                        */
/*                                                                          */
/*    B. Sellew          12/22/97      Created Initial version.             */
/*                                                                          */
/****************************************************************************/
VOID UART_LISR (INT vector)
{
    PDA            *immr = (PDA *) (Get_IMMR() & 0xffff0000);  
    BD             *rbd = (BD *) immr->udata_bd;      
    UNSIGNED_CHAR  event, smc;
    UNSIGNED_CHAR  i;

    if (vector == SMC1_VECTOR)
    {
        smc = SMC1;
        rbd += rbd_idx[smc];
    }
    else 
    {
        smc = SMC2;
        rbd += (RX_BUFFERS + TX_BUFFERS + rbd_idx[smc]);
    }

    /* only consider enabled interrupts */
    event = immr->smc_regs[smc].smc_smce;
    event &= immr->smc_regs[smc].smc_smcm;

    /* check for busy condition */
    if (event & 0x04)
        UART_Busy_Error++;

    /* check for receive interrupt */
    if (event & 0x01)
        while ((rbd->status & 0x8000) == 0)
        {
            if (rbd->status & 0x0010)
                UART_Frame_Error++;
            if (rbd->status & 0x0008)
                UART_Parity_Error++;
            if (rbd->status & 0x0002)
                UART_Overrun_Error++;

            /* if no receive error, get the character */
            if (((rbd->status & 0x001a) == 0) &&
                    uart[smc].buf_status != BUF_FULL)
            {
                i = uart[smc].write;
                uart[smc].buffer[i] = *(rbd->addr);
                uart[smc].write = ++(uart[smc].write) % BUF_LEN;
                if (uart[smc].write == uart[smc].read)
                    uart[smc].buf_status = BUF_FULL;
            }

            /* reset the buffer status to empty */
            rbd->status |= 0x8000;

            /* if UART is set for PPP, call PPP processing functions */
            if (uart[smc].mode == SMC_PPP_MODE)
            {
#ifdef NU_PPP
                switch(UART_Communication_Mode)
                {
                    case PPP_NETWORK_COMMUNICATION:
                        PPP_Receive(smc);
                        break;
    
                    case PPP_TERMINAL_COMMUNICATION:
                    default:
                        MDM_Receive(smc);
                        break;
                }
#endif
            }

            rbd_idx[smc] = ++(rbd_idx[smc]) % RX_BUFFERS;
            if (rbd_idx[smc] == 0)
                rbd -= (RX_BUFFERS - 1);
            else
                rbd++;
        }

    /* clear the interrupt */
    immr->smc_regs[smc].smc_smce = event;
        
} /* UART_LISR */

/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    UART_Get_Char                                                         */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This function reads the next character from the UART's buffer.        */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    PPP_Receive                                                           */
/*    MDM_Receive                                                           */
/*    Application                                                           */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    None                                                                  */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    UNSIGNED         :   SMC port                                         */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    CHAR  :  Character read                                               */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*        NAME             DATE                  REMARKS                    */
/*                                                                          */
/*      B. Sellew        12/24/97         Created Initial version.          */
/*                                                                          */
/****************************************************************************/

⌨️ 快捷键说明

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