Nut/OS  4.10.3
API Reference
usart0sc16is752.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 by Ulrich Prinz (uprinz2@netscape.net)
00003  * Copyright (C) 2010 by Rittal GmbH & Co. KG. 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 SCDEV   0
00060 #define CH_     0
00061 #define NUTDEV  devUsartsc16is752a
00062 
00063 #if defined(__linux__)
00064 #define IRQ_    0
00065 #else
00066 extern IRQ_HANDLER sig_INTERRUPT1;
00067 #define IRQ_    sig_INTERRUPT1
00068 #endif
00069 
00070 // static void Sc16is752UsartEnable_(void)
00071 // {
00072 //     Sc16is752UsartEnable(SCDEV, CH_);
00073 // }
00074 //
00075 // static void Sc16is752UsartDisable_(void)
00076 // {
00077 //     Sc16is752UsartDisable(SCDEV, CH_);
00078 // }
00079 
00080 NUTDEVICE NUTDEV;
00081 
00082 static uint32_t Sc16is752UsartGetSpeed_(void)
00083 {
00084     return Sc16is752UsartGetSpeed(SCDEV, CH_);
00085 }
00086 
00087 static int Sc16is752UsartSetSpeed_(uint32_t rate)
00088 {
00089     return Sc16is752UsartSetSpeed(rate, SCDEV, CH_);
00090 }
00091 
00092 static uint8_t Sc16is752UsartGetDataBits_(void)
00093 {
00094     return Sc16is752UsartGetDataBits(SCDEV, CH_);
00095 }
00096 
00097 static int Sc16is752UsartSetDataBits_(uint8_t bits)
00098 {
00099     return Sc16is752UsartSetDataBits(bits, SCDEV, CH_);
00100 }
00101 
00102 static uint8_t Sc16is752UsartGetParity_(void)
00103 {
00104     return Sc16is752UsartGetParity(SCDEV, CH_);
00105 }
00106 
00107 static int Sc16is752UsartSetParity_(uint8_t mode)
00108 {
00109     return Sc16is752UsartSetParity(mode, SCDEV, CH_);
00110 }
00111 
00112 static uint8_t Sc16is752UsartGetStopBits_(void)
00113 {
00114     return Sc16is752UsartGetStopBits(SCDEV, CH_);
00115 }
00116 
00117 static int Sc16is752UsartSetStopBits_(uint8_t bits)
00118 {
00119     return Sc16is752UsartSetStopBits(bits, SCDEV, CH_);
00120 }
00121 
00122 static uint32_t Sc16is752UsartGetStatus_(void)
00123 {
00124     return Sc16is752UsartGetStatus(SCDEV, CH_);
00125 }
00126 
00127 static int Sc16is752UsartSetStatus_(uint32_t flags)
00128 {
00129     return Sc16is752UsartSetStatus(flags, SCDEV, CH_);
00130 }
00131 
00132 static uint8_t Sc16is752UsartGetClockMode_(void)
00133 {
00134     return Sc16is752UsartGetClockMode(SCDEV, CH_);
00135 }
00136 
00137 static int Sc16is752UsartSetClockMode_(uint8_t mode)
00138 {
00139     return Sc16is752UsartSetClockMode(mode, SCDEV, CH_);
00140 }
00141 
00142 static uint32_t Sc16is752UsartGetFlowControl_(void)
00143 {
00144     return Sc16is752UsartGetFlowControl(SCDEV, CH_);
00145 }
00146 
00147 static int Sc16is752UsartSetFlowControl_(uint32_t flags)
00148 {
00149     return Sc16is752UsartSetFlowControl(flags, SCDEV, CH_);
00150 }
00151 
00152 static void Sc16is752UsartTxStart_(void)
00153 {
00154     Sc16is752UsartTxStart(SCDEV, CH_);
00155 }
00156 
00157 static void Sc16is752UsartRxStart_(void)
00158 {
00159     Sc16is752UsartRxStart(SCDEV, CH_);
00160 }
00161 
00162 static int Sc16is752UsartInit_(void)
00163 {
00164     return Sc16is752UsartInit(SCDEV, CH_, &NUTDEV, &IRQ_);
00165 }
00166 
00167 static int Sc16is752UsartDeinit_(void)
00168 {
00169     return Sc16is752UsartDeinit(SCDEV, CH_, &IRQ_);
00170 }
00171 
00172 
00173 
00178 
00179 
00183 static USARTDCB dcb_usarta = {
00184     0,                             /* dcb_modeflags */
00185     0,                             /* dcb_statusflags */
00186     0,                             /* dcb_rtimeout */
00187     0,                             /* dcb_wtimeout */
00188     {0, 0, 0, 0, 0, 0, 0, 0},      /* dcb_tx_rbf */
00189     {0, 0, 0, 0, 0, 0, 0, 0},      /* dcb_rx_rbf */
00190     0,                             /* dbc_last_eol */
00191     Sc16is752UsartInit_,           /* dcb_init */
00192     Sc16is752UsartDeinit_,         /* dcb_deinit */
00193     Sc16is752UsartTxStart_,        /* dcb_tx_start */
00194     Sc16is752UsartRxStart_,        /* dcb_rx_start */
00195     Sc16is752UsartSetFlowControl_, /* dcb_set_flow_control */
00196     Sc16is752UsartGetFlowControl_, /* dcb_get_flow_control */
00197     Sc16is752UsartSetSpeed_,       /* dcb_set_speed */
00198     Sc16is752UsartGetSpeed_,       /* dcb_get_speed */
00199     Sc16is752UsartSetDataBits_,    /* dcb_set_data_bits */
00200     Sc16is752UsartGetDataBits_,    /* dcb_get_data_bits */
00201     Sc16is752UsartSetParity_,      /* dcb_set_parity */
00202     Sc16is752UsartGetParity_,      /* dcb_get_parity */
00203     Sc16is752UsartSetStopBits_,    /* dcb_set_stop_bits */
00204     Sc16is752UsartGetStopBits_,    /* dcb_get_stop_bits */
00205     Sc16is752UsartSetStatus_,      /* dcb_set_status */
00206     Sc16is752UsartGetStatus_,      /* dcb_get_status */
00207     Sc16is752UsartSetClockMode_,   /* dcb_set_clock_mode */
00208     Sc16is752UsartGetClockMode_,   /* dcb_get_clock_mode */
00209 };
00210 
00226 NUTDEVICE devUsartsc16is752a = {
00227     0,                          /* Pointer to next device, dev_next. */
00228     {'u', 'a', 'r', 't', '_', 'a', 0, 0, 0},    /* Unique device name, dev_name. */
00229     IFTYP_CHAR,                 /* Type of device, dev_type. */
00230     (SCDEV<<8)|CH_,              /* Base address, used for dev & ch: (dev<<8)|ch */
00231     0,                          /* First interrupt number, dev_irq (not used). */
00232     0,                          /* Interface control block, dev_icb (not used). */
00233     &dcb_usarta,                /* Driver control block, dev_dcb. */
00234     UsartInit,                  /* Driver initialization routine, dev_init. */
00235     UsartIOCtl,                 /* Driver specific control function, dev_ioctl. */
00236     UsartRead,                  /* Read from device, dev_read. */
00237     UsartWrite,                 /* Write to device, dev_write. */
00238 #ifdef __HARVARD_ARCH__
00239     UsartWrite_P,               /* Write program memory to device, dev_write_P. */
00240 #endif
00241     UsartOpen,                  /* Open a device or file, dev_open. */
00242     UsartClose,                 /* Close a device or file, dev_close. */
00243     UsartSize                   /* Request file size, dev_size. */
00244 };
00245 
00246 
00247 
00248 
00252