* ser-ocd.c: If _WIN32, include <windows.h>.
[deliverable/binutils-gdb.git] / gdb / ser-ocd.c
1 /* Remote serial interface for Macraigor Systems implementation of
2 On-Chip Debugging using serial target box or serial wiggler
3
4 Copyright 1994, 1997 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22 #include "defs.h"
23 #include "serial.h"
24
25 #ifdef _WIN32
26 #include <windows.h>
27 #endif
28
29 static int ser_ocd_open PARAMS ((serial_t scb, const char *name));
30 static void ser_ocd_raw PARAMS ((serial_t scb));
31 static int ser_ocd_readchar PARAMS ((serial_t scb, int timeout));
32 static int ser_ocd_setbaudrate PARAMS ((serial_t scb, int rate));
33 static int ser_ocd_write PARAMS ((serial_t scb, const char *str, int len));
34 static void ser_ocd_close PARAMS ((serial_t scb));
35 static serial_ttystate ser_ocd_get_tty_state PARAMS ((serial_t scb));
36 static int ser_ocd_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
37
38 #ifdef _WIN32
39 /* On Windows, this function pointer is initialized to a function in
40 the wiggler DLL. */
41 static int (*dll_do_command) PARAMS ((const char *, char *));
42 #endif
43
44 static int
45 ocd_open (scb, name)
46 serial_t scb;
47 const char *name;
48 {
49 #ifdef _WIN32
50 /* Find the wiggler DLL which talks to the board. */
51 if (dll_do_command == NULL)
52 {
53 HINSTANCE handle;
54
55 /* FIXME: Should the user be able to configure this? */
56 handle = LoadLibrary ("Wigglers.dll");
57 if (handle == NULL)
58 error ("Can't load Wigglers.dll");
59
60 dll_do_command = ((int (*) PARAMS ((const char *, char *)))
61 GetProcAddress (handle, "do_command"));
62 if (dll_do_command == NULL)
63 error ("Can't find do_command function in Wigglers.dll");
64 }
65 #endif
66
67 return 0;
68 }
69
70 static int
71 ocd_noop (scb)
72 serial_t scb;
73 {
74 return 0;
75 }
76
77 static void
78 ocd_raw (scb)
79 serial_t scb;
80 {
81 /* Always in raw mode */
82 }
83
84 /* We need a buffer to store responses from the Wigglers.dll */
85 #define WIGGLER_BUFF_SIZE 512
86 unsigned char from_wiggler_buffer[WIGGLER_BUFF_SIZE];
87 unsigned char * wiggler_buffer_ptr; /* curr spot in buffer */
88
89 static void
90 ocd_readremote ()
91 {
92 }
93
94 static int
95 ocd_readchar (scb, timeout)
96 serial_t scb;
97 int timeout;
98 {
99 return (int) *wiggler_buffer_ptr++; /* return curr char and increment ptr */
100 }
101
102 struct ocd_ttystate {
103 int dummy;
104 };
105
106 /* ocd_{get set}_tty_state() are both dummys to fill out the function
107 vector. Someday, they may do something real... */
108
109 static serial_ttystate
110 ocd_get_tty_state (scb)
111 serial_t scb;
112 {
113 struct ocd_ttystate *state;
114
115 state = (struct ocd_ttystate *) xmalloc (sizeof *state);
116
117 return (serial_ttystate) state;
118 }
119
120 static int
121 ocd_set_tty_state (scb, ttystate)
122 serial_t scb;
123 serial_ttystate ttystate;
124 {
125 return 0;
126 }
127
128 static int
129 ocd_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
130 serial_t scb;
131 serial_ttystate new_ttystate;
132 serial_ttystate old_ttystate;
133 {
134 return 0;
135 }
136
137 static void
138 ocd_print_tty_state (scb, ttystate)
139 serial_t scb;
140 serial_ttystate ttystate;
141 {
142 /* Nothing to print. */
143 return;
144 }
145
146 static int
147 ocd_setbaudrate (scb, rate)
148 serial_t scb;
149 int rate;
150 {
151 return 0;
152 }
153
154 static int
155 ocd_write (scb, str, len)
156 serial_t scb;
157 const char *str;
158 int len;
159 {
160 char c;
161
162 #ifdef __CYGWIN32__
163 /* send packet to Wigglers.dll and store response so we can give it to
164 remote-wiggler.c when get_packet is run */
165 dll_do_command (str, from_wiggler_buffer);
166 wiggler_buffer_ptr = from_wiggler_buffer;
167 #endif
168
169 return 0;
170 }
171
172 static void
173 ocd_close (scb)
174 serial_t scb;
175 {
176 }
177
178 static struct serial_ops ocd_ops =
179 {
180 "ocd",
181 0,
182 ocd_open,
183 ocd_close,
184 ocd_readchar,
185 ocd_write,
186 ocd_noop, /* flush output */
187 ocd_noop, /* flush input */
188 ocd_noop, /* send break -- currently used only for nindy */
189 ocd_raw,
190 ocd_get_tty_state,
191 ocd_set_tty_state,
192 ocd_print_tty_state,
193 ocd_noflush_set_tty_state,
194 ocd_setbaudrate,
195 };
196
197 void
198 _initialize_ser_ocd_bdm ()
199 {
200 serial_add_interface (&ocd_ops);
201 }
This page took 0.047688 seconds and 4 git commands to generate.