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

📄 mn10300_serial.c

📁 ecos为实时嵌入式操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
//==========================================================================////      mn10300_serial.c////      Serial device driver for mn10300 on-chip serial devices////==========================================================================//####COPYRIGHTBEGIN####//// -------------------------------------------// The contents of this file are subject to the Cygnus eCos Public License// Version 1.0 (the "License"); you may not use this file except in// compliance with the License.  You may obtain a copy of the License at// http://sourceware.cygnus.com/ecos// // Software distributed under the License is distributed on an "AS IS"// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the// License for the specific language governing rights and limitations under// the License.// // The Original Code is eCos - Embedded Cygnus Operating System, released// September 30, 1998.// // The Initial Developer of the Original Code is Cygnus.  Portions created// by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions.  All Rights Reserved.// -------------------------------------------////####COPYRIGHTEND####//==========================================================================//#####DESCRIPTIONBEGIN####//// Author(s):   nickg// Contributors: nickg// Date:        1999-02-25// Purpose:     MN10300 serial device driver// Description: MN10300 serial device driver////####DESCRIPTIONEND####////==========================================================================#include <pkgconf/hal.h>#include <pkgconf/io_serial.h>#include <cyg/hal/hal_io.h>#include <cyg/io/io.h>#include <cyg/io/devtab.h>#include <cyg/io/serial.h>#include <cyg/hal/hal_intr.h>#ifdef CYGPKG_IO_SERIAL_MN10300//-------------------------------------------------------------------------extern void diag_printf(const char *fmt, ...);//-------------------------------------------------------------------------// Forward definitionsstatic bool mn10300_serial_init(struct cyg_devtab_entry *tab);static bool mn10300_serial_putc(serial_channel *chan, unsigned char c);static Cyg_ErrNo mn10300_serial_lookup(struct cyg_devtab_entry **tab,                                    struct cyg_devtab_entry *sub_tab,                                   const char *name);static unsigned char mn10300_serial_getc(serial_channel *chan);static bool mn10300_serial_set_config(serial_channel *chan, cyg_serial_info_t *config);static void mn10300_serial_start_xmit(serial_channel *chan);static void mn10300_serial_stop_xmit(serial_channel *chan);#ifndef CYGPKG_IO_SERIAL_MN10300_POLLED_MODEstatic cyg_uint32 mn10300_serial_rx_ISR(cyg_vector_t vector, cyg_addrword_t data);static cyg_uint32 mn10300_serial_tx_ISR(cyg_vector_t vector, cyg_addrword_t data);static void       mn10300_serial_rx_DSR(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data);static void       mn10300_serial_tx_DSR(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data);#endif//-------------------------------------------------------------------------#define BUFSIZE 128//-------------------------------------------------------------------------// MN10300 serial line control register values:// Offsets to serial control registers from base#define SERIAL_CTR      0x0#define SERIAL_ICR      0x4#define SERIAL_TXB      0x8#define SERIAL_RXB      0x9#define SERIAL_STR      0xc#define SERIAL_TIM      0xd// Status register bits#define SR_RBF          0x10#define SR_TBF          0x20#define SR_RXF          0x40#define SR_TXF          0x80// Control register bits#define LCR_SB1         0x00#define LCR_SB1_5       0x00#define LCR_SB2         0x04#define LCR_PN          0x00    // Parity mode - none#define LCR_PS          0x40    // Forced "space" parity#define LCR_PM          0x50    // Forced "mark" parity#define LCR_PE          0x60    // Parity mode - even#define LCR_PO          0x70    // Parity mode - odd#define LCR_WL5         0x00    // not supported - use 7bit#define LCR_WL6         0x00    // not supported - use 7bit#define LCR_WL7         0x00    // 7 bit chars#define LCR_WL8         0x80    // 8 bit chars#define LCR_RXE         0x4000  // receive enable#define LCR_TXE         0x8000  // transmit enable//-------------------------------------------------------------------------// MN10300 timer registers:#undef TIMER_BR#undef TIMER_MD#define TIMER_MD        0x00#define TIMER_BR        0x10//-------------------------------------------------------------------------// IO Port:#define PORT3_MD        0x36008025//-------------------------------------------------------------------------// Tables to map input values to hardware settingsstatic unsigned char select_word_length[] = {    LCR_WL5,    // 5 bits / word (char)    LCR_WL6,    LCR_WL7,    LCR_WL8};static unsigned char select_stop_bits[] = {    0,    LCR_SB1,    // 1 stop bit    LCR_SB1_5,  // 1.5 stop bit    LCR_SB2     // 2 stop bits};static unsigned char select_parity[] = {    LCR_PN,     // No parity    LCR_PE,     // Even parity    LCR_PO,     // Odd parity    LCR_PM,     // Mark parity    LCR_PS,     // Space parity};static unsigned short select_baud_01[] = {    0,          // Unused    0,          // 50    0,          // 75    0,          // 110    0,          // 134.5    0,          // 150    0,          // 200    0,          // 300    0,          // 600    0,          // 1200    0,          // 1800    0,          // 2400    0,          // 3600    0,          // 4800    0,          // 7200    195,        // 9600    130,        // 14400    98,         // 19200    48,         // 38400    32,         // 57600    16,         // 115200    8,          // 230400};// Serial 2 has its own timer register in addition to using timer 2 to// supply the baud rate generator. Both of these must be proframmed to// get the right baud rate. The following values come from Matsushita// with some modifications from Cygmon.static struct{    cyg_uint8   serial2_val;    cyg_uint8   timer2_val;} select_baud_2[] = {    {   0,   0 },       // Unused    {   0,   0 },       // 50    {   0,   0 },       // 75    {   0,   0 },       // 110    {   0,   0 },       // 134.5    {   0,   0 },       // 150    {   0,   0 },       // 200    {   0,   0 },       // 300    { 126, 196 },       // 600    { 125,  98 },       // 1200    {   0,   0 },       // 1800    { 124,  49 },       // 2400    { 0,     0 },       // 3600    { 124,  24 },       // 4800    {   0,   0 },       // 7200    {  70,  21 },       // 9600    {   0,   0 },       // 14400    {  70,  10 },       // 19200    {  22,  16 },       // 38400    {  88,   2 },       // 57600    {  64,   1 },       // 115200    {  62,   0 },       // 230400};//-------------------------------------------------------------------------// Info for each serial device controlledtypedef struct mn10300_serial_info {    CYG_ADDRWORD   base;    CYG_ADDRWORD   timer_base;    CYG_WORD       rx_int;    CYG_WORD       tx_int;    cyg_bool       is_serial2;    cyg_interrupt  rx_interrupt;    cyg_interrupt  tx_interrupt;    cyg_handle_t   rx_interrupt_handle;    cyg_handle_t   tx_interrupt_handle;} mn10300_serial_info;//-------------------------------------------------------------------------// Callback functions exported by this driverstatic SERIAL_FUNS(mn10300_serial_funs,                    mn10300_serial_putc,                    mn10300_serial_getc,                   mn10300_serial_set_config,                   mn10300_serial_start_xmit,                   mn10300_serial_stop_xmit    );//-------------------------------------------------------------------------// Hardware info for each serial line#ifndef CYG_HAL_MN10300_STDEVAL1#ifdef CYGPKG_IO_SERIAL_MN10300_SERIAL0static mn10300_serial_info mn10300_serial_info0 = {    0x34000800,    0x34001000,    CYGNUM_HAL_INTERRUPT_SERIAL_0_RX,    CYGNUM_HAL_INTERRUPT_SERIAL_0_TX,    false};#if CYGNUM_IO_SERIAL_MN10300_SERIAL0_BUFSIZE > 0static unsigned char mn10300_serial_out_buf0[CYGNUM_IO_SERIAL_MN10300_SERIAL0_BUFSIZE];static unsigned char mn10300_serial_in_buf0[CYGNUM_IO_SERIAL_MN10300_SERIAL0_BUFSIZE];#endif#endif // CYGPKG_IO_SERIAL_MN10300_SERIAL0#endif#ifdef CYGPKG_IO_SERIAL_MN10300_SERIAL1static mn10300_serial_info mn10300_serial_info1 = {    0x34000810,    0x34001001,        CYGNUM_HAL_INTERRUPT_SERIAL_1_RX,    CYGNUM_HAL_INTERRUPT_SERIAL_1_TX,    false};#if CYGNUM_IO_SERIAL_MN10300_SERIAL1_BUFSIZE > 0static unsigned char mn10300_serial_out_buf1[CYGNUM_IO_SERIAL_MN10300_SERIAL1_BUFSIZE];static unsigned char mn10300_serial_in_buf1[CYGNUM_IO_SERIAL_MN10300_SERIAL1_BUFSIZE];#endif#endif // CYGPKG_IO_SERIAL_MN10300_SERIAL1#ifdef CYGPKG_IO_SERIAL_MN10300_SERIAL2static mn10300_serial_info mn10300_serial_info2 = {    0x34000820,    0x34001002,        CYGNUM_HAL_INTERRUPT_SERIAL_2_RX,    CYGNUM_HAL_INTERRUPT_SERIAL_2_TX,    true};#if CYGNUM_IO_SERIAL_MN10300_SERIAL2_BUFSIZE > 0static unsigned char mn10300_serial_out_buf2[CYGNUM_IO_SERIAL_MN10300_SERIAL2_BUFSIZE];static unsigned char mn10300_serial_in_buf2[CYGNUM_IO_SERIAL_MN10300_SERIAL2_BUFSIZE];#endif#endif // CYGPKG_IO_SERIAL_MN10300_SERIAL2//-------------------------------------------------------------------------// Channel descriptions:#ifdef CYGPKG_IO_SERIAL_MN10300_POLLED_MODE#define SIZEOF_BUF(_x_) 0#else#define SIZEOF_BUF(_x_) sizeof(_x_)#endif#ifndef CYG_HAL_MN10300_STDEVAL1#ifdef CYGPKG_IO_SERIAL_MN10300_SERIAL0#if CYGNUM_IO_SERIAL_MN10300_SERIAL0_BUFSIZE > 0static SERIAL_CHANNEL_USING_INTERRUPTS(mn10300_serial_channel0,                                       mn10300_serial_funs,                                        mn10300_serial_info0,                                       CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_MN10300_SERIAL0_BAUD),                                       CYG_SERIAL_STOP_DEFAULT,                                       CYG_SERIAL_PARITY_DEFAULT,                                       CYG_SERIAL_WORD_LENGTH_DEFAULT,                                       CYG_SERIAL_FLAGS_DEFAULT,                                       &mn10300_serial_out_buf0[0],                                       SIZEOF_BUF(mn10300_serial_out_buf0),                                       &mn10300_serial_in_buf0[0],                                       SIZEOF_BUF(mn10300_serial_in_buf0)    );#elsestatic SERIAL_CHANNEL(mn10300_serial_channel0,                      mn10300_serial_funs,                       mn10300_serial_info0,                      CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_MN10300_SERIAL0_BAUD),                      CYG_SERIAL_STOP_DEFAULT,                      CYG_SERIAL_PARITY_DEFAULT,                      CYG_SERIAL_WORD_LENGTH_DEFAULT,                      CYG_SERIAL_FLAGS_DEFAULT    );#endif#endif // CYGPKG_IO_SERIAL_MN10300_SERIAL0#endif    #ifdef CYGPKG_IO_SERIAL_MN10300_SERIAL1#if CYGNUM_IO_SERIAL_MN10300_SERIAL1_BUFSIZE > 0static SERIAL_CHANNEL_USING_INTERRUPTS(mn10300_serial_channel1,                                       mn10300_serial_funs,                                        mn10300_serial_info1,                                       CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_MN10300_SERIAL1_BAUD),                                       CYG_SERIAL_STOP_DEFAULT,                                       CYG_SERIAL_PARITY_DEFAULT,                                       CYG_SERIAL_WORD_LENGTH_DEFAULT,                                       CYG_SERIAL_FLAGS_DEFAULT,                                       &mn10300_serial_out_buf1[0],                                       SIZEOF_BUF(mn10300_serial_out_buf1),                                       &mn10300_serial_in_buf1[0],                                       SIZEOF_BUF(mn10300_serial_in_buf1)    );#elsestatic SERIAL_CHANNEL(mn10300_serial_channel1,                      mn10300_serial_funs,                       mn10300_serial_info1,                      CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_MN10300_SERIAL1_BAUD),                      CYG_SERIAL_STOP_DEFAULT,                      CYG_SERIAL_PARITY_DEFAULT,                      CYG_SERIAL_WORD_LENGTH_DEFAULT,                      CYG_SERIAL_FLAGS_DEFAULT    );#endif#endif // CYGPKG_IO_SERIAL_MN10300_SERIAL1#ifdef CYGPKG_IO_SERIAL_MN10300_SERIAL2#if CYGNUM_IO_SERIAL_MN10300_SERIAL2_BUFSIZE > 0static SERIAL_CHANNEL_USING_INTERRUPTS(mn10300_serial_channel2,                                       mn10300_serial_funs,                                        mn10300_serial_info2,                                       CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_MN10300_SERIAL2_BAUD),                                       CYG_SERIAL_STOP_DEFAULT,                                       CYG_SERIAL_PARITY_DEFAULT,                                       CYG_SERIAL_WORD_LENGTH_DEFAULT,                                       CYG_SERIAL_FLAGS_DEFAULT,                                       &mn10300_serial_out_buf2[0],                                       SIZEOF_BUF(mn10300_serial_out_buf2),                                       &mn10300_serial_in_buf2[0],                                       SIZEOF_BUF(mn10300_serial_in_buf2)    );#elsestatic SERIAL_CHANNEL(mn10300_serial_channel2,                      mn10300_serial_funs,                       mn10300_serial_info2,                      CYG_SERIAL_BAUD_RATE(CYGNUM_IO_SERIAL_MN10300_SERIAL2_BAUD),                      CYG_SERIAL_STOP_DEFAULT,                      CYG_SERIAL_PARITY_DEFAULT,                      CYG_SERIAL_WORD_LENGTH_DEFAULT,                      CYG_SERIAL_FLAGS_DEFAULT    );#endif#endif // CYGPKG_IO_SERIAL_MN10300_SERIAL2    //-------------------------------------------------------------------------

⌨️ 快捷键说明

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