OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [libmisc/] [serdbg/] [serdbgio.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*===============================================================*\
2
| File: serdbgio.c                                                |
3
+-----------------------------------------------------------------+
4
|                    Copyright (c) 2002 IMD                       |
5
|      Ingenieurbuero fuer Microcomputertechnik Th. Doerfler      |
6
|      Hebststr. 8, 82178 Puchheim, Germany                       |
7
|      <Thomas.Doerfler@imd-systems.de>                           |
8
|  The license and distribution terms for this file may be        |
9
|  found in the file LICENSE in this distribution or at           |
10
|  http://www.OARcorp.com/rtems/license.html.                     |
11
|                       all rights reserved                       |
12
+-----------------------------------------------------------------+
13
| TERMIOS serial gdb interface support                            |
14
| the functions in this file allow the standard gdb stubs like    |
15
| "m68k-stub.c" to access any serial interfaces that work with    |
16
| RTEMS termios in polled mode                                    |
17
|                                                                 |
18
+-----------------------------------------------------------------+
19
|   date                      history                        ID   |
20
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
21
| 10.05.02  creation                                         doe  |
22
|*****************************************************************|
23
|* serdbgio.c,v 1.1 2002/06/27 21:25:13 joel Exp
24
 *
25
|*****************************************************************|
26
\*===============================================================*/
27
 
28
#include <rtems.h>
29
#include <rtems/libio_.h>
30
#include <errno.h>
31
#include <stdio.h>
32
#include <fcntl.h>
33
#include <termios.h>
34
 
35
#include <rtems/termiostypes.h>
36
#include <serdbg.h>
37
 
38
 
39
/*
40
 * internal variables
41
 */
42
int serdbg_fd = -1;
43
struct rtems_termios_tty *serdbg_tty;
44
 
45
/*=========================================================================*\
46
| Function:                                                                 |
47
\*-------------------------------------------------------------------------*/
48
int serdbg_open
49
 
50
/*-------------------------------------------------------------------------*\
51
| Purpose:                                                                  |
52
|    try to open given serial debug port                                    |
53
+---------------------------------------------------------------------------+
54
| Input Parameters:                                                         |
55
\*-------------------------------------------------------------------------*/
56
(
57
 const char *dev_name, /* name of device to open */
58
 unsigned32 baudrate   /* baud rate to use       */
59
)
60
/*-------------------------------------------------------------------------*\
61
| Return Value:                                                             |
62
|    0 on success, -1 and errno otherwise                                   |
63
\*=========================================================================*/
64
{
65
  boolean err_occurred = FALSE;
66
  rtems_libio_t *iop = NULL;
67
  struct termios act_termios;
68
  tcflag_t baudcode = B0;
69
 
70
#define FD_STORE_CNT 3
71
  int fd_store[FD_STORE_CNT];
72
  int fd_store_used = 0;
73
 
74
  /*
75
   * translate baudrate into baud code
76
   */
77
  switch(baudrate) {
78
  case     50: baudcode =     B50; break;
79
  case     75: baudcode =     B75; break;
80
  case    110: baudcode =    B110; break;
81
  case    134: baudcode =    B134; break;
82
  case    150: baudcode =    B150; break;
83
  case    200: baudcode =    B200; break;
84
  case    300: baudcode =    B300; break;
85
  case    600: baudcode =    B600; break;
86
  case   1200: baudcode =   B1200; break;
87
  case   1800: baudcode =   B1800; break;
88
  case   2400: baudcode =   B2400; break;
89
  case   4800: baudcode =   B4800; break;
90
  case   9600: baudcode =   B9600; break;
91
  case  19200: baudcode =  B19200; break;
92
  case  38400: baudcode =  B38400; break;
93
  case  57600: baudcode =  B57600; break;
94
  case 115200: baudcode = B115200; break;
95
  case 230400: baudcode = B230400; break;
96
  case 460800: baudcode = B460800; break;
97
  default    :   err_occurred = TRUE; errno = EINVAL; break;
98
  }
99
 
100
 /*
101
  * open device for serdbg operation
102
  * skip any fds that are between 0..2, because they are
103
  * reserved for stdin/out/err
104
  */
105
  if (!err_occurred &&
106
      (dev_name != NULL) &&
107
      (dev_name[0] != '\0')) {
108
    do {
109
      serdbg_fd = open(dev_name,O_RDWR);
110
      if (serdbg_fd < 0) {
111
        err_occurred = TRUE;
112
      }
113
      else {
114
        if (serdbg_fd < 3) {
115
          if (fd_store_used >= FD_STORE_CNT) {
116
            err_occurred = TRUE;
117
          }
118
          else {
119
            fd_store[fd_store_used++] = serdbg_fd;
120
          }
121
        }
122
      }
123
    } while (!err_occurred &&
124
             (serdbg_fd < 3));
125
  }
126
  /*
127
   * close any fds, that have been placed in fd_store
128
   * so fd 0..2 are reusable again
129
   */
130
  while (--fd_store_used >= 0) {
131
    close(fd_store[fd_store_used]);
132
  }
133
 
134
  /*
135
   * capture tty structure
136
   */
137
  if (!err_occurred) {
138
    iop = &rtems_libio_iops[serdbg_fd];
139
    serdbg_tty = iop->data1;
140
  }
141
  /*
142
   * set device baudrate
143
   * (and transp mode, this is not really needed)
144
   * ...
145
   */
146
  /*
147
   * ... get fd settings
148
   */
149
  if (!err_occurred &&
150
      (0 != tcgetattr(serdbg_fd,&act_termios))) {
151
      err_occurred = TRUE;
152
  }
153
  if (!err_occurred) {
154
    act_termios.c_iflag
155
      &=  ~(IGNBRK|BRKINT|PARMRK|ISTRIP
156
            |INLCR|IGNCR|ICRNL|IXON);
157
    act_termios.c_oflag
158
      &= ~OPOST;
159
 
160
    act_termios.c_lflag
161
      &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
162
 
163
    cfsetospeed(&act_termios,baudcode);
164
    cfsetispeed(&act_termios,baudcode);
165
 
166
    if (0 != tcsetattr(serdbg_fd,TCSANOW,&act_termios)) {
167
        err_occurred = TRUE;
168
    }
169
  }
170
  return (err_occurred
171
          ? -1
172
          : 0);
173
}
174
 
175
void putDebugChar(char c) __attribute__ ((__weak__));
176
/*=========================================================================*\
177
| Function:                                                                 |
178
\*-------------------------------------------------------------------------*/
179
void putDebugChar
180
/*-------------------------------------------------------------------------*\
181
| Purpose:                                                                  |
182
|    send one character to serial port                                      |
183
+---------------------------------------------------------------------------+
184
| Input Parameters:                                                         |
185
\*-------------------------------------------------------------------------*/
186
(
187
 char c  /* character to print */
188
)
189
/*-------------------------------------------------------------------------*\
190
| Return Value:                                                             |
191
|    <none>                                                                 |
192
\*=========================================================================*/
193
{
194
  /*
195
   * call serdbg polling callout, if available
196
   */
197
  if (serdbg_conf.callout != NULL) {
198
    serdbg_conf.callout();
199
  }
200
  /*
201
   * check, whether debug serial port is available
202
   */
203
  if ((serdbg_tty != NULL) &&
204
      (serdbg_tty->device.write != NULL)) {
205
    /*
206
     * send character to debug serial port
207
     */
208
    serdbg_tty->device.write(serdbg_tty->minor,&c,1);
209
  }
210
}
211
 
212
int getDebugChar(void) __attribute__ ((__weak__));
213
/*=========================================================================*\
214
| Function:                                                                 |
215
\*-------------------------------------------------------------------------*/
216
int getDebugChar
217
/*-------------------------------------------------------------------------*\
218
| Purpose:                                                                  |
219
|    wait for one character from serial port                                |
220
+---------------------------------------------------------------------------+
221
| Input Parameters:                                                         |
222
\*-------------------------------------------------------------------------*/
223
(
224
 void  /* none */
225
)
226
/*-------------------------------------------------------------------------*\
227
| Return Value:                                                             |
228
|    received character                                                     |
229
\*=========================================================================*/
230
{
231
  int c = -1;
232
  /*
233
   * check, whether debug serial port is available
234
   */
235
  if ((serdbg_tty != NULL) &&
236
      (serdbg_tty->device.pollRead != NULL)) {
237
    do {
238
      /*
239
       * call serdbg polling callout, if available
240
       */
241
      if (serdbg_conf.callout != NULL) {
242
        serdbg_conf.callout();
243
      }
244
      /*
245
       * get character from debug serial port
246
       */
247
      c = serdbg_tty->device.pollRead(serdbg_tty->minor);
248
    } while (c < 0);
249
  }
250
  return c;
251
}
252
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.