usart3sc16is752.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 by Rittal GmbH & Co. KG,
00003  * Ulrich Prinz <prinz.u@rittal.de> All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. Neither the name of the copyright holders nor the names of
00015  *    contributors may be used to endorse or promote products derived
00016  *    from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00019  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00022  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00023  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00024  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00025  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00026  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00027  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00028  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00029  * SUCH DAMAGE.
00030  *
00031  * For additional information see http://www.ethernut.de/
00032  *
00033  */
00034 
00035 /*
00036  * $Log$
00037  *
00038  * Revision 1.0  2009/04/13 ulrichprinz
00039  * First checkin, new twi driver for SC16IS752 dual usart chip
00040  * (currently SAM7X256 is tested only)
00041  *
00042  */
00043 
00044 
00045 #include <cfg/os.h>
00046 #include <cfg/clock.h>
00047 #include <cfg/arch.h>
00048 #include <cfg/uart.h>
00049 
00050 //#include <string.h>
00051 
00052 #include <sys/atom.h>
00053 #include <sys/event.h>
00054 #include <sys/timer.h>
00055 
00056 #include <dev/irqreg.h>
00057 #include <dev/usartsc16is752.h>
00058 
00059 #define DEV_    1
00060 #define CH_     1
00061 #define NUTDEV_ devUsartsc16is752d
00062 #if defined(__linux__)
00063 #define IRQ_    1
00064 #else
00065 #define IRQ_    sig_INTERRUPT0
00066 #endif
00067 
00068 // static void Sc16is752UsartEnable_(void)
00069 // {
00070 //     Sc16is752UsartEnable(DEV_, CH_);
00071 // }
00072 //
00073 // static void Sc16is752UsartDisable_(void)
00074 // {
00075 //     Sc16is752UsartDisable(DEV_, CH_);
00076 // }
00077 
00078 NUTDEVICE devUsartsc16is752d;
00079 
00080 static uint32_t Sc16is752UsartGetSpeed_(void)
00081 {
00082     return Sc16is752UsartGetSpeed(DEV_, CH_);
00083 }
00084 
00085 static int Sc16is752UsartSetSpeed_(uint32_t rate)
00086 {
00087     return Sc16is752UsartSetSpeed(rate, DEV_, CH_);
00088 }
00089 
00090 static uint8_t Sc16is752UsartGetDataBits_(void)
00091 {
00092     return Sc16is752UsartGetDataBits(DEV_, CH_);
00093 }
00094 
00095 static int Sc16is752UsartSetDataBits_(uint8_t bits)
00096 {
00097     return Sc16is752UsartSetDataBits(bits, DEV_, CH_);
00098 }
00099 
00100 static uint8_t Sc16is752UsartGetParity_(void)
00101 {
00102     return Sc16is752UsartGetParity(DEV_, CH_);
00103 }
00104 
00105 static int Sc16is752UsartSetParity_(uint8_t mode)
00106 {
00107     return Sc16is752UsartSetParity(mode, DEV_, CH_);
00108 }
00109 
00110 static uint8_t Sc16is752UsartGetStopBits_(void)
00111 {
00112     return Sc16is752UsartGetStopBits(DEV_, CH_);
00113 }
00114 
00115 static int Sc16is752UsartSetStopBits_(uint8_t bits)
00116 {
00117     return Sc16is752UsartSetStopBits(bits, DEV_, CH_);
00118 }
00119 
00120 static uint32_t Sc16is752UsartGetStatus_(void)
00121 {
00122     return Sc16is752UsartGetStatus(DEV_, CH_);
00123 }
00124 
00125 static int Sc16is752UsartSetStatus_(uint32_t flags)
00126 {
00127     return Sc16is752UsartSetStatus(flags, DEV_, CH_);
00128 }
00129 
00130 static uint8_t Sc16is752UsartGetClockMode_(void)
00131 {
00132     return Sc16is752UsartGetClockMode(DEV_, CH_);
00133 }
00134 
00135 static int Sc16is752UsartSetClockMode_(uint8_t mode)
00136 {
00137     return Sc16is752UsartSetClockMode(mode, DEV_, CH_);
00138 }
00139 
00140 static uint32_t Sc16is752UsartGetFlowControl_(void)
00141 {
00142     return Sc16is752UsartGetFlowControl(DEV_, CH_);
00143 }
00144 
00145 static int Sc16is752UsartSetFlowControl_(uint32_t flags)
00146 {
00147     return Sc16is752UsartSetFlowControl(flags, DEV_, CH_);
00148 }
00149 
00150 static void Sc16is752UsartTxStart_(void)
00151 {
00152     Sc16is752UsartTxStart(DEV_, CH_);
00153 }
00154 
00155 static void Sc16is752UsartRxStart_(void)
00156 {
00157     Sc16is752UsartRxStart(DEV_, CH_);
00158 }
00159 
00160 static int Sc16is752UsartInit_(void)
00161 {
00162 #if defined(__linux__)
00163     return Sc16is752UsartInit(DEV_, CH_, &NUTDEV_, 1);
00164 #else
00165     return Sc16is752UsartInit(DEV_, CH_, &NUTDEV_, &IRQ_);
00166 #endif
00167 }
00168 
00169 static int Sc16is752UsartDeinit_(void)
00170 {
00171 #if defined(__linux__)
00172     return Sc16is752UsartDeinit(DEV_, CH_, 1);
00173 #else
00174     return Sc16is752UsartDeinit(DEV_, CH_, &IRQ_);
00175 #endif
00176 }
00177 
00178 
00179 
00184 
00185 
00189 static USARTDCB dcb_usartd = {
00190     0,                             /* dcb_modeflags */
00191     0,                             /* dcb_statusflags */
00192     0,                             /* dcb_rtimeout */
00193     0,                             /* dcb_wtimeout */
00194     {0, 0, 0, 0, 0, 0, 0, 0},      /* dcb_tx_rbf */
00195     {0, 0, 0, 0, 0, 0, 0, 0},      /* dcb_rx_rbf */
00196     0,                             /* dbc_last_eol */
00197     Sc16is752UsartInit_,           /* dcb_init */
00198     Sc16is752UsartDeinit_,         /* dcb_deinit */
00199     Sc16is752UsartTxStart_,        /* dcb_tx_start */
00200     Sc16is752UsartRxStart_,        /* dcb_rx_start */
00201     Sc16is752UsartSetFlowControl_, /* dcb_set_flow_control */
00202     Sc16is752UsartGetFlowControl_, /* dcb_get_flow_control */
00203     Sc16is752UsartSetSpeed_,       /* dcb_set_speed */
00204     Sc16is752UsartGetSpeed_,       /* dcb_get_speed */
00205     Sc16is752UsartSetDataBits_,    /* dcb_set_data_bits */
00206     Sc16is752UsartGetDataBits_,    /* dcb_get_data_bits */
00207     Sc16is752UsartSetParity_,      /* dcb_set_parity */
00208     Sc16is752UsartGetParity_,      /* dcb_get_parity */
00209     Sc16is752UsartSetStopBits_,    /* dcb_set_stop_bits */
00210     Sc16is752UsartGetStopBits_,    /* dcb_get_stop_bits */
00211     Sc16is752UsartSetStatus_,      /* dcb_set_status */
00212     Sc16is752UsartGetStatus_,      /* dcb_get_status */
00213     Sc16is752UsartSetClockMode_,   /* dcb_set_clock_mode */
00214     Sc16is752UsartGetClockMode_,   /* dcb_get_clock_mode */
00215 };
00216 
00232 NUTDEVICE devUsartsc16is752d = {
00233     0,                          /* Pointer to next device, dev_next. */
00234     {'u', 'a', 'r', 't', 'd', 0, 0, 0, 0},    /* Unique device name, dev_name. */
00235     IFTYP_CHAR,                 /* Type of device, dev_type. */
00236     (DEV_<<8)|CH_,              /* Base address, used for dev & ch: (dev<<8)|ch */
00237     0,                          /* First interrupt number, dev_irq (not used). */
00238     0,                          /* Interface control block, dev_icb (not used). */
00239     &dcb_usartd,                /* Driver control block, dev_dcb. */
00240     UsartInit,                  /* Driver initialization routine, dev_init. */
00241     UsartIOCtl,                 /* Driver specific control function, dev_ioctl. */
00242     UsartRead,                  /* Read from device, dev_read. */
00243     UsartWrite,                 /* Write to device, dev_write. */
00244 #ifdef __HARVARD_ARCH__
00245     UsartWrite_P,               /* Write program memory to device, dev_write_P. */
00246 #endif
00247     UsartOpen,                  /* Open a device or file, dev_open. */
00248     UsartClose,                 /* Close a device or file, dev_close. */
00249     UsartSize                   /* Request file size, dev_size. */
00250 };
00251 
00252 
00253 
00254 
00258 

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/