00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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
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
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
00138
00139