mpc8xxx_serial.c

来自「eCos操作系统源码」· C语言 代码 · 共 1,017 行 · 第 1/3 页

C
1,017
字号
//==========================================================================////      io/serial/powerpc/mpc8xxx_serial.c////      PowerPC MPC8XXX (QUICC-II) (SMC/SCC) Serial I/O Interface Module////==========================================================================//####ECOSGPLCOPYRIGHTBEGIN####// -------------------------------------------// This file is part of eCos, the Embedded Configurable Operating System.// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.// Copyright (C) 2003 Gary Thomas//// eCos is free software; you can redistribute it and/or modify it under// the terms of the GNU General Public License as published by the Free// Software Foundation; either version 2 or (at your option) any later version.//// eCos is distributed in the hope that it will be useful, but WITHOUT ANY// WARRANTY; without even the implied warranty of MERCHANTABILITY or// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License// for more details.//// You should have received a copy of the GNU General Public License along// with eCos; if not, write to the Free Software Foundation, Inc.,// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.//// As a special exception, if other files instantiate templates or use macros// or inline functions from this file, or you compile this file and link it// with other works to produce a work based on this file, this file does not// by itself cause the resulting work to be covered by the GNU General Public// License. However the source code for this file must still be made available// in accordance with section (3) of the GNU General Public License.//// This exception does not invalidate any other reasons why a work based on// this file might be covered by the GNU General Public License.//// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.// at http://sources.redhat.com/ecos/ecos-license/// -------------------------------------------//####ECOSGPLCOPYRIGHTEND####//==========================================================================//#####DESCRIPTIONBEGIN####//// Author(s):    gthomas// Contributors: gthomas// Date:         1999-06-20// Purpose:      MPC8XXX Serial I/O module// Description: ////####DESCRIPTIONEND####////==========================================================================#include <pkgconf/system.h>#include <pkgconf/io_serial.h>#include <pkgconf/io.h>#include <cyg/io/io.h>#include <cyg/hal/hal_intr.h>#include <cyg/io/devtab.h>#include <cyg/io/serial.h>#include <cyg/infra/diag.h>#include <cyg/hal/hal_cache.h>#include <cyg/hal/mpc8xxx.h>#include CYGBLD_HAL_PLATFORM_H#include "mpc8xxx_serial.h"typedef struct mpc8xxx_sxx_serial_info {    CYG_ADDRWORD          channel;                   // Which channel SMCx/SCCx    short                 int_num;                   // Interrupt number    short                 type;                      // Channel type - SCC or SMC    unsigned long         *brg;                      // Which baud rate generator    void                  *pram;                     // Parameter RAM pointer    void                  *ctl;                      // SMC/SCC control registers    volatile struct cp_bufdesc     *txbd, *rxbd;     // Next Tx,Rx descriptor to use    struct cp_bufdesc     *tbase, *rbase;            // First Tx,Rx descriptor    int                   txsize, rxsize;            // Length of individual buffers    cyg_interrupt         serial_interrupt;    cyg_handle_t          serial_interrupt_handle;} mpc8xxx_sxx_serial_info;static bool mpc8xxx_sxx_serial_init(struct cyg_devtab_entry *tab);static bool mpc8xxx_sxx_serial_putc(serial_channel *chan, unsigned char c);static Cyg_ErrNo mpc8xxx_sxx_serial_lookup(struct cyg_devtab_entry **tab,                                    struct cyg_devtab_entry *sub_tab,                                   const char *name);static unsigned char mpc8xxx_sxx_serial_getc(serial_channel *chan);static Cyg_ErrNo mpc8xxx_sxx_serial_set_config(serial_channel *chan,                                             cyg_uint32 key, const void *xbuf,                                             cyg_uint32 *len);static void mpc8xxx_sxx_serial_start_xmit(serial_channel *chan);static void mpc8xxx_sxx_serial_stop_xmit(serial_channel *chan);static cyg_uint32 mpc8xxx_sxx_serial_ISR(cyg_vector_t vector, cyg_addrword_t data);static void       mpc8xxx_sxx_serial_DSR(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data);static SERIAL_FUNS(mpc8xxx_sxx_serial_funs,                    mpc8xxx_sxx_serial_putc,                    mpc8xxx_sxx_serial_getc,                   mpc8xxx_sxx_serial_set_config,                   mpc8xxx_sxx_serial_start_xmit,                   mpc8xxx_sxx_serial_stop_xmit    );#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC8XXX_SMC1static mpc8xxx_sxx_serial_info mpc8xxx_sxx_serial_info_smc1 = {    SMC1_PAGE_SUBBLOCK,                 // Channel indicator    CYGNUM_HAL_INTERRUPT_SMC1,    // interrupt    _SMC_CHAN};#if CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC1_BUFSIZE > 0static unsigned char mpc8xxx_smc_serial_out_buf_smc1[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC1_BUFSIZE];static unsigned char mpc8xxx_smc_serial_in_buf_smc1[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC1_BUFSIZE];static SERIAL_CHANNEL_USING_INTERRUPTS(mpc8xxx_sxx_serial_channel_smc1,                                       mpc8xxx_sxx_serial_funs,                                        mpc8xxx_sxx_serial_info_smc1,                                       CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC1_BAUD),                                       CYG_SERIAL_STOP_DEFAULT,                                       CYG_SERIAL_PARITY_DEFAULT,                                       CYG_SERIAL_WORD_LENGTH_DEFAULT,                                       CYG_SERIAL_FLAGS_DEFAULT,                                       &mpc8xxx_smc_serial_out_buf_smc1[0], sizeof(mpc8xxx_smc_serial_out_buf_smc1),                                       &mpc8xxx_smc_serial_in_buf_smc1[0], sizeof(mpc8xxx_smc_serial_in_buf_smc1)    );#elsestatic SERIAL_CHANNEL(mpc8xxx_sxx_serial_channel_smc1,                      mpc8xxx_sxx_serial_funs,                       mpc8xxx_sxx_serial_info_smc1,                      CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC1_BAUD),                      CYG_SERIAL_STOP_DEFAULT,                      CYG_SERIAL_PARITY_DEFAULT,                      CYG_SERIAL_WORD_LENGTH_DEFAULT,                      CYG_SERIAL_FLAGS_DEFAULT    );#endifstatic unsigned char mpc8xxx_smc1_txbuf[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC1_TxNUM*CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC1_TxSIZE] __attribute__((aligned(HAL_DCACHE_LINE_SIZE)));static unsigned char mpc8xxx_smc1_rxbuf[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC1_RxNUM*CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC1_RxSIZE] __attribute__((aligned(HAL_DCACHE_LINE_SIZE)));DEVTAB_ENTRY(mpc8xxx_smc_serial_io_smc1,              CYGDAT_IO_SERIAL_POWERPC_MPC8XXX_SMC1_NAME,             0,                     // Does not depend on a lower level interface             &cyg_io_serial_devio,              mpc8xxx_sxx_serial_init,              mpc8xxx_sxx_serial_lookup,     // Serial driver may need initializing             &mpc8xxx_sxx_serial_channel_smc1    );#endif //  CYGPKG_IO_SERIAL_POWERPC_MPC8XXX_SMC1#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC8XXX_SMC2static mpc8xxx_sxx_serial_info mpc8xxx_sxx_serial_info_smc2 = {    SMC2_PAGE_SUBBLOCK,         // Channel indicator    CYGNUM_HAL_INTERRUPT_SMC2,  // interrupt    _SMC_CHAN};#if CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC2_BUFSIZE > 0static unsigned char mpc8xxx_smc_serial_out_buf_smc2[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC2_BUFSIZE];static unsigned char mpc8xxx_smc_serial_in_buf_smc2[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC2_BUFSIZE];static SERIAL_CHANNEL_USING_INTERRUPTS(mpc8xxx_sxx_serial_channel_smc2,                                       mpc8xxx_sxx_serial_funs,                                        mpc8xxx_sxx_serial_info_smc2,                                       CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC2_BAUD),                                       CYG_SERIAL_STOP_DEFAULT,                                       CYG_SERIAL_PARITY_DEFAULT,                                       CYG_SERIAL_WORD_LENGTH_DEFAULT,                                       CYG_SERIAL_FLAGS_DEFAULT,                                       &mpc8xxx_smc_serial_out_buf_smc2[0], sizeof(mpc8xxx_smc_serial_out_buf_smc2),                                       &mpc8xxx_smc_serial_in_buf_smc2[0], sizeof(mpc8xxx_smc_serial_in_buf_smc2)    );#elsestatic SERIAL_CHANNEL(mpc8xxx_sxx_serial_channel_smc2,                      mpc8xxx_sxx_serial_funs,                       mpc8xxx_sxx_serial_info_smc2,                      CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC2_BAUD),                      CYG_SERIAL_STOP_DEFAULT,                      CYG_SERIAL_PARITY_DEFAULT,                      CYG_SERIAL_WORD_LENGTH_DEFAULT,                      CYG_SERIAL_FLAGS_DEFAULT    );#endifstatic unsigned char mpc8xxx_smc2_txbuf[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC2_TxNUM*CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC2_TxSIZE] __attribute__((aligned(HAL_DCACHE_LINE_SIZE)));static unsigned char mpc8xxx_smc2_rxbuf[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC2_RxNUM*CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SMC2_RxSIZE] __attribute__((aligned(HAL_DCACHE_LINE_SIZE)));DEVTAB_ENTRY(mpc8xxx_smc_serial_io_smc2,              CYGDAT_IO_SERIAL_POWERPC_MPC8XXX_SMC2_NAME,             0,                     // Does not depend on a lower level interface             &cyg_io_serial_devio,              mpc8xxx_sxx_serial_init,              mpc8xxx_sxx_serial_lookup,     // Serial driver may need initializing             &mpc8xxx_sxx_serial_channel_smc2    );#endif //  CYGPKG_IO_SERIAL_POWERPC_MPC8XXX_SMC2#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC8XXX_SCC1static mpc8xxx_sxx_serial_info mpc8xxx_sxx_serial_info_scc1 = {    SCC1_PAGE_SUBBLOCK,             // Channel indicator    CYGNUM_HAL_INTERRUPT_SCC1,      // interrupt    _SCC_CHAN};#if CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC1_BUFSIZE > 0static unsigned char mpc8xxx_smc_serial_out_buf_scc1[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC1_BUFSIZE];static unsigned char mpc8xxx_smc_serial_in_buf_scc1[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC1_BUFSIZE];static SERIAL_CHANNEL_USING_INTERRUPTS(mpc8xxx_sxx_serial_channel_scc1,                                       mpc8xxx_sxx_serial_funs,                                        mpc8xxx_sxx_serial_info_scc1,                                       CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC1_BAUD),                                       CYG_SERIAL_STOP_DEFAULT,                                       CYG_SERIAL_PARITY_DEFAULT,                                       CYG_SERIAL_WORD_LENGTH_DEFAULT,                                       CYG_SERIAL_FLAGS_DEFAULT,                                       &mpc8xxx_smc_serial_out_buf_scc1[0], sizeof(mpc8xxx_smc_serial_out_buf_scc1),                                       &mpc8xxx_smc_serial_in_buf_scc1[0], sizeof(mpc8xxx_smc_serial_in_buf_scc1)    );#elsestatic SERIAL_CHANNEL(mpc8xxx_sxx_serial_channel_scc1,                      mpc8xxx_sxx_serial_funs,                       mpc8xxx_sxx_serial_info_scc1,                      CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC1_BAUD),                      CYG_SERIAL_STOP_DEFAULT,                      CYG_SERIAL_PARITY_DEFAULT,                      CYG_SERIAL_WORD_LENGTH_DEFAULT,                      CYG_SERIAL_FLAGS_DEFAULT    );#endifstatic unsigned char mpc8xxx_scc1_txbuf[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC1_TxNUM*CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC1_TxSIZE] __attribute__((aligned(HAL_DCACHE_LINE_SIZE)));static unsigned char mpc8xxx_scc1_rxbuf[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC1_RxNUM*CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC1_RxSIZE] __attribute__((aligned(HAL_DCACHE_LINE_SIZE)));DEVTAB_ENTRY(mpc8xxx_smc_serial_io_scc1,              CYGDAT_IO_SERIAL_POWERPC_MPC8XXX_SCC1_NAME,             0,                     // Does not depend on a lower level interface             &cyg_io_serial_devio,              mpc8xxx_sxx_serial_init,              mpc8xxx_sxx_serial_lookup,     // Serial driver may need initializing             &mpc8xxx_sxx_serial_channel_scc1    );#endif //  CYGPKG_IO_SERIAL_POWERPC_MPC8XXX_SCC1#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC8XXX_SCC2static mpc8xxx_sxx_serial_info mpc8xxx_sxx_serial_info_scc2 = {    SCC2_PAGE_SUBBLOCK,             // Channel indicator    CYGNUM_HAL_INTERRUPT_SCC2,      // interrupt    _SCC_CHAN};#if CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC2_BUFSIZE > 0static unsigned char mpc8xxx_smc_serial_out_buf_scc2[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC2_BUFSIZE];static unsigned char mpc8xxx_smc_serial_in_buf_scc2[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC2_BUFSIZE];static SERIAL_CHANNEL_USING_INTERRUPTS(mpc8xxx_sxx_serial_channel_scc2,                                       mpc8xxx_sxx_serial_funs,                                        mpc8xxx_sxx_serial_info_scc2,                                       CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC2_BAUD),                                       CYG_SERIAL_STOP_DEFAULT,                                       CYG_SERIAL_PARITY_DEFAULT,                                       CYG_SERIAL_WORD_LENGTH_DEFAULT,                                       CYG_SERIAL_FLAGS_DEFAULT,                                       &mpc8xxx_smc_serial_out_buf_scc2[0], sizeof(mpc8xxx_smc_serial_out_buf_scc2),                                       &mpc8xxx_smc_serial_in_buf_scc2[0], sizeof(mpc8xxx_smc_serial_in_buf_scc2)    );#elsestatic SERIAL_CHANNEL(mpc8xxx_sxx_serial_channel_scc2,                      mpc8xxx_sxx_serial_funs,                       mpc8xxx_sxx_serial_info_scc2,                      CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC2_BAUD),                      CYG_SERIAL_STOP_DEFAULT,                      CYG_SERIAL_PARITY_DEFAULT,                      CYG_SERIAL_WORD_LENGTH_DEFAULT,                      CYG_SERIAL_FLAGS_DEFAULT    );#endifstatic unsigned char mpc8xxx_scc2_txbuf[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC2_TxNUM*CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC2_TxSIZE] __attribute__((aligned(HAL_DCACHE_LINE_SIZE)));static unsigned char mpc8xxx_scc2_rxbuf[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC2_RxNUM*CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC2_RxSIZE] __attribute__((aligned(HAL_DCACHE_LINE_SIZE)));DEVTAB_ENTRY(mpc8xxx_smc_serial_io_scc2,              CYGDAT_IO_SERIAL_POWERPC_MPC8XXX_SCC2_NAME,             0,                     // Does not depend on a lower level interface             &cyg_io_serial_devio,              mpc8xxx_sxx_serial_init,              mpc8xxx_sxx_serial_lookup,     // Serial driver may need initializing             &mpc8xxx_sxx_serial_channel_scc2    );#endif //  CYGPKG_IO_SERIAL_POWERPC_MPC8XXX_SCC2#ifdef CYGPKG_IO_SERIAL_POWERPC_MPC8XXX_SCC3static mpc8xxx_sxx_serial_info mpc8xxx_sxx_serial_info_scc3 = {    SCC3_PAGE_SUBBLOCK,             // Channel indicator    CYGNUM_HAL_INTERRUPT_SCC3,      // interrupt    _SCC_CHAN};#if CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC3_BUFSIZE > 0static unsigned char mpc8xxx_smc_serial_out_buf_scc3[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC3_BUFSIZE];static unsigned char mpc8xxx_smc_serial_in_buf_scc3[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC3_BUFSIZE];static SERIAL_CHANNEL_USING_INTERRUPTS(mpc8xxx_sxx_serial_channel_scc3,                                       mpc8xxx_sxx_serial_funs,                                        mpc8xxx_sxx_serial_info_scc3,                                       CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC3_BAUD),                                       CYG_SERIAL_STOP_DEFAULT,                                       CYG_SERIAL_PARITY_DEFAULT,                                       CYG_SERIAL_WORD_LENGTH_DEFAULT,                                       CYG_SERIAL_FLAGS_DEFAULT,                                       &mpc8xxx_smc_serial_out_buf_scc3[0], sizeof(mpc8xxx_smc_serial_out_buf_scc3),                                       &mpc8xxx_smc_serial_in_buf_scc3[0], sizeof(mpc8xxx_smc_serial_in_buf_scc3)    );#elsestatic SERIAL_CHANNEL(mpc8xxx_sxx_serial_channel_scc3,                      mpc8xxx_sxx_serial_funs,                       mpc8xxx_sxx_serial_info_scc3,                      CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC3_BAUD),                      CYG_SERIAL_STOP_DEFAULT,                      CYG_SERIAL_PARITY_DEFAULT,                      CYG_SERIAL_WORD_LENGTH_DEFAULT,                      CYG_SERIAL_FLAGS_DEFAULT    );#endifstatic unsigned char mpc8xxx_scc3_txbuf[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC3_TxNUM*CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC3_TxSIZE] __attribute__((aligned(HAL_DCACHE_LINE_SIZE)));static unsigned char mpc8xxx_scc3_rxbuf[CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC3_RxNUM*CYGNUM_IO_SERIAL_POWERPC_MPC8XXX_SCC3_RxSIZE] __attribute__((aligned(HAL_DCACHE_LINE_SIZE)));DEVTAB_ENTRY(mpc8xxx_smc_serial_io_scc3,              CYGDAT_IO_SERIAL_POWERPC_MPC8XXX_SCC3_NAME,             0,                     // Does not depend on a lower level interface             &cyg_io_serial_devio,              mpc8xxx_sxx_serial_init,              mpc8xxx_sxx_serial_lookup,     // Serial driver may need initializing             &mpc8xxx_sxx_serial_channel_scc3    );#endif //  CYGPKG_IO_SERIAL_POWERPC_MPC8XXX_SCC3// Internal function to actually configure the hardware to desired baud rate, etc.static boolmpc8xxx_smc_serial_config_port(serial_channel *chan, cyg_serial_info_t *new_config, bool init){    mpc8xxx_sxx_serial_info *smc_chan = (mpc8xxx_sxx_serial_info *)chan->dev_priv;    unsigned int baud_divisor = select_baud[new_config->baud];    cyg_uint32 _lcr;    volatile struct smc_regs_8260 *ctl = (volatile struct smc_regs_8260*)smc_chan->ctl;

⌨️ 快捷键说明

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