/home/hillier_g/checkout/most4linux/most-kernel/serial-rt-debug.c

Go to the documentation of this file.
00001 /*
00002  *  Copyright(c) Siemens AG, Muenchen, Germany, 2005, 2006, 2007
00003  *                           Bernhard Walle <bernhard.walle@gmx.de>
00004  *                           Gernot Hillier <gernot.hillier@siemens.com>
00005  *
00006  * ----------------------------------------------------------------------------
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License version 2 as 
00009  * published by the Free Software Foundation;
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  * ----------------------------------------------------------------------------
00020  */
00021 #ifdef HAVE_CONFIG_H
00022 #include "config/config.h"
00023 #endif
00024 #include <rtdm/rtdm_driver.h>
00025 
00026 #include "serial-rt-debug.h"
00027 #include "most-common.h"
00028 
00041 #define PR                   "serial-rt-debug: "
00042 
00043 
00047 static const struct rtser_config serial_configuration = {
00048     .config_mask        = RTSER_SET_BAUD | RTSER_SET_PARITY | 
00049                           RTSER_SET_DATA_BITS | RTSER_SET_STOP_BITS |
00050                           RTSER_SET_HANDSHAKE,
00051     .baud_rate          = SERIAL_RT_BAUDRATE,
00052     .parity             = SERIAL_RT_PARITY,
00053     .data_bits          = SERIAL_RT_DATABITS,
00054     .stop_bits          = SERIAL_RT_STOPBITS,
00055     .handshake          = SERIAL_RT_HANDSHAKE
00056 };
00057 
00058 #ifdef SERIAL_RT_DEBUG
00059 
00063 static int s_fd;
00064 
00065 /*
00066  * Documentation: see header
00067  */
00068 int serial_rt_debug_init(void)
00069 {
00070     int       err;
00071 
00072     return_value_if_fails(s_fd <= 0, 0);
00073 
00074     s_fd = rtdm_open(SERIAL_RT_DEVICE, 0);
00075     if (unlikely(s_fd < 0)) {
00076         pr_warning(PR "rtdm_open failed with %d\n", s_fd);
00077         goto out;
00078     }
00079 
00080     err = rtdm_ioctl(s_fd, RTSER_RTIOC_SET_CONFIG, &serial_configuration);
00081     if (unlikely(err < 0)) {
00082         pr_warning(PR "rtdm_ioctl failed with %d\n", err);
00083         goto out_close;
00084     }
00085 
00086     return 0;
00087 
00088 out_close:
00089     rtdm_close(s_fd);
00090 out:
00091     return s_fd;
00092 }
00093 
00094 /*
00095  * Documentation: see header
00096  */
00097 int serial_rt_debug_write(const char *format, ...)
00098 {
00099     va_list         args;
00100     int             ret;
00101     int             err;
00102     static char     buffer[1024];
00103 
00104     return_value_if_fails_dbg(s_fd >= 0, -EINVAL);
00105 
00106     va_start(args, format);
00107     ret = vsnprintf(buffer, 1024, format, args);
00108     va_end(args);
00109 
00110     if (unlikely(ret < 0)) {
00111         pr_warning(PR "vsnprintf failed with %d\n", ret);
00112         return ret;
00113     }
00114     buffer[1023] = 0;
00115 
00116     /* write to the hardware */
00117     err = rtdm_write(s_fd, buffer, strlen(buffer));
00118     if (unlikely(err < 0)) {
00119         pr_warning(PR "rtdm_write failed with %d\n", err);
00120         return err;
00121     }
00122 
00123     return ret;
00124 }
00125 
00126 /*
00127  * Documentation: see header
00128  */
00129 void serial_rt_debug_finish(void)
00130 {
00131     return_if_fails(s_fd >= 0);
00132 
00133     rtdm_close(s_fd);
00134     s_fd = 0;
00135 }
00136 
00137 #endif /* SERIAL_RT_DEBUG */
00138 
00139 /* vim: set ts=4 et sw=4: */

Generated on Fri Mar 9 14:48:58 2007 for MOST Linux Drivers (Linux and RTAI) by  doxygen 1.5.0