#include "defs.h"
#include "serial.h"
#ifdef _WIN32
#include <windows.h>
#endif
#ifdef _WIN32
static int (*dll_do_command) (const char *, char *);
#endif
static int
ocd_open (serial_t scb, const char *name)
{
#ifdef _WIN32
if (dll_do_command == NULL)
{
HINSTANCE handle;
handle = LoadLibrary ("Wigglers.dll");
if (handle == NULL)
error ("Can't load Wigglers.dll");
dll_do_command = ((int (*) (const char *, char *))
GetProcAddress (handle, "do_command"));
if (dll_do_command == NULL)
error ("Can't find do_command function in Wigglers.dll");
}
#else
error ("Wiggler library not available for this type of host.");
#endif
return 0;
}
static int
ocd_noop (serial_t scb)
{
return 0;
}
static void
ocd_raw (serial_t scb)
{
}
#define WIGGLER_BUFF_SIZE 512
unsigned char from_wiggler_buffer[WIGGLER_BUFF_SIZE];
unsigned char *wiggler_buffer_ptr;
static int
ocd_readchar (serial_t scb, int timeout)
{
if (wiggler_buffer_ptr >
(from_wiggler_buffer + (sizeof (char *) * WIGGLER_BUFF_SIZE)))
error ("ocd_readchar asked to read past the end of the buffer!");
return (int) *wiggler_buffer_ptr++;
}
struct ocd_ttystate
{
int dummy;
};
static serial_ttystate
ocd_get_tty_state (serial_t scb)
{
struct ocd_ttystate *state;
state = (struct ocd_ttystate *) xmalloc (sizeof *state);
return (serial_ttystate) state;
}
static int
ocd_set_tty_state (serial_t scb, serial_ttystate ttystate)
{
return 0;
}
static int
ocd_noflush_set_tty_state (serial_t scb, serial_ttystate new_ttystate,
serial_ttystate old_ttystate)
{
return 0;
}
static void
ocd_print_tty_state (serial_t scb,
serial_ttystate ttystate,
struct ui_file *stream)
{
return;
}
static int
ocd_setbaudrate (serial_t scb, int rate)
{
return 0;
}
static int
ocd_write (serial_t scb, const char *str, int len)
{
#ifdef _WIN32
dll_do_command (str, from_wiggler_buffer);
wiggler_buffer_ptr = from_wiggler_buffer;
#endif
return 0;
}
static void
ocd_close (serial_t scb)
{
}
static struct serial_ops ocd_ops =
{
"ocd",
0,
ocd_open,
ocd_close,
ocd_readchar,
ocd_write,
ocd_noop,
ocd_noop,
ocd_noop,
ocd_raw,
ocd_get_tty_state,
ocd_set_tty_state,
ocd_print_tty_state,
ocd_noflush_set_tty_state,
ocd_setbaudrate,
ocd_noop,
};
void
_initialize_ser_ocd_bdm (void)
{
serial_add_interface (&ocd_ops);
}