X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fjtag%2Fgw16012.c;h=7845e778892c7c14e679fdfd01cc63438bd4adf3;hb=7c7fed0283e5c6e434de94af443218ef78175e87;hp=3d72aa27e4799d7e2a3b41dcf2c827e47eea08d0;hpb=e77ae9096a40707d3b878b46969a60a06656dc06;p=openocd.git diff --git a/src/jtag/gw16012.c b/src/jtag/gw16012.c index 3d72aa27e4..7845e77889 100644 --- a/src/jtag/gw16012.c +++ b/src/jtag/gw16012.c @@ -21,10 +21,9 @@ #include "config.h" #endif -#include "replacements.h" - #include "jtag.h" + #if 1 #define _DEBUG_GW16012_IO_ #endif @@ -33,7 +32,6 @@ /* -ino: 060521-1036 */ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -#include #include #include #define ioperm(startport,length,enable)\ @@ -41,14 +39,8 @@ #else -#ifdef _WIN32 -#include "errno.h" -#endif /* _WIN32 */ - #endif /* __FreeBSD__, __FreeBSD_kernel__ */ -#include -#include #if PARPORT_USE_PPDEV == 1 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) @@ -68,14 +60,10 @@ #endif #endif -#if PARPORT_USE_GIVEIO == 1 -#if IS_CYGWIN == 1 +#if PARPORT_USE_GIVEIO == 1 && IS_CYGWIN == 1 #include -#include -#endif #endif -#include "log.h" /* configuration */ u16 gw16012_port; @@ -89,13 +77,13 @@ static u8 gw16012_control_value = 0x0; static int device_handle; #endif -int gw16012_execute_queue(void); -int gw16012_register_commands(struct command_context_s *cmd_ctx); -int gw16012_speed(int speed); -int gw16012_init(void); -int gw16012_quit(void); +static int gw16012_execute_queue(void); +static int gw16012_register_commands(struct command_context_s *cmd_ctx); +static int gw16012_speed(int speed); +static int gw16012_init(void); +static int gw16012_quit(void); -int gw16012_handle_parport_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +static int gw16012_handle_parport_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); jtag_interface_t gw16012_interface = { @@ -109,7 +97,7 @@ jtag_interface_t gw16012_interface = .quit = gw16012_quit, }; -int gw16012_register_commands(struct command_context_s *cmd_ctx) +static int gw16012_register_commands(struct command_context_s *cmd_ctx) { register_command(cmd_ctx, NULL, "parport_port", gw16012_handle_parport_port_command, COMMAND_CONFIG, NULL); @@ -117,7 +105,7 @@ int gw16012_register_commands(struct command_context_s *cmd_ctx) return ERROR_OK; } -void gw16012_data(u8 value) +static void gw16012_data(u8 value) { value = (value & 0x7f) | gw16012_msb; gw16012_msb ^= 0x80; /* toggle MSB */ @@ -137,7 +125,7 @@ void gw16012_data(u8 value) #endif } -void gw16012_control(u8 value) +static void gw16012_control(u8 value) { if (value != gw16012_control_value) { @@ -159,7 +147,7 @@ void gw16012_control(u8 value) } } -void gw16012_input(u8 *value) +static void gw16012_input(u8 *value) { #if PARPORT_USE_PPDEV == 1 ioctl(device_handle, PPRSTATUS, value); @@ -173,7 +161,7 @@ void gw16012_input(u8 *value) } /* (1) assert or (0) deassert reset lines */ -void gw16012_reset(int trst, int srst) +static void gw16012_reset(int trst, int srst) { LOG_DEBUG("trst: %i, srst: %i", trst, srst); @@ -188,13 +176,13 @@ void gw16012_reset(int trst, int srst) gw16012_control(0x0b); } -int gw16012_speed(int speed) +static int gw16012_speed(int speed) { return ERROR_OK; } -void gw16012_end_state(int state) +static void gw16012_end_state(tap_state_t state) { if (tap_is_state_stable(state)) tap_set_end_state(state); @@ -205,7 +193,7 @@ void gw16012_end_state(int state) } } -void gw16012_state_move(void) +static void gw16012_state_move(void) { int i=0, tms=0; u8 tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state()); @@ -221,7 +209,7 @@ void gw16012_state_move(void) tap_set_state(tap_get_end_state()); } -void gw16012_path_move(pathmove_command_t *cmd) +static void gw16012_path_move(pathmove_command_t *cmd) { int num_states = cmd->num_states; int state_count; @@ -252,7 +240,7 @@ void gw16012_path_move(pathmove_command_t *cmd) tap_set_end_state(tap_get_state()); } -void gw16012_runtest(int num_cycles) +static void gw16012_runtest(int num_cycles) { tap_state_t saved_end_state = tap_get_end_state(); int i; @@ -275,7 +263,7 @@ void gw16012_runtest(int num_cycles) gw16012_state_move(); } -void gw16012_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size) +static void gw16012_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size) { int bits_left = scan_size; int bit_count = 0; @@ -348,7 +336,7 @@ void gw16012_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size) } } -int gw16012_execute_queue(void) +static int gw16012_execute_queue(void) { jtag_command_t *cmd = jtag_command_queue; /* currently processed command */ int scan_size; @@ -369,7 +357,7 @@ int gw16012_execute_queue(void) #ifdef _DEBUG_JTAG_IO_ LOG_DEBUG("end_state: %i", cmd->cmd.end_state->end_state); #endif - if (cmd->cmd.end_state->end_state != -1) + if (cmd->cmd.end_state->end_state != TAP_INVALID) gw16012_end_state(cmd->cmd.end_state->end_state); break; case JTAG_RESET: @@ -386,7 +374,7 @@ int gw16012_execute_queue(void) #ifdef _DEBUG_JTAG_IO_ LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); #endif - if (cmd->cmd.runtest->end_state != -1) + if (cmd->cmd.runtest->end_state != TAP_INVALID) gw16012_end_state(cmd->cmd.runtest->end_state); gw16012_runtest(cmd->cmd.runtest->num_cycles); break; @@ -394,7 +382,7 @@ int gw16012_execute_queue(void) #ifdef _DEBUG_JTAG_IO_ LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state); #endif - if (cmd->cmd.statemove->end_state != -1) + if (cmd->cmd.statemove->end_state != TAP_INVALID) gw16012_end_state(cmd->cmd.statemove->end_state); gw16012_state_move(); break; @@ -405,7 +393,7 @@ int gw16012_execute_queue(void) gw16012_path_move(cmd->cmd.pathmove); break; case JTAG_SCAN: - if (cmd->cmd.scan->end_state != -1) + if (cmd->cmd.scan->end_state != TAP_INVALID) gw16012_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); type = jtag_scan_type(cmd->cmd.scan); @@ -436,7 +424,7 @@ int gw16012_execute_queue(void) } #if PARPORT_USE_GIVEIO == 1 -int gw16012_get_giveio_access() +static int gw16012_get_giveio_access(void) { HANDLE h; OSVERSIONINFO version; @@ -461,65 +449,83 @@ int gw16012_get_giveio_access() } #endif -int gw16012_init(void) -{ -#if PARPORT_USE_PPDEV == 1 - char buffer[256]; - int i = 0; -#endif - u8 status_port; - #if PARPORT_USE_PPDEV == 1 - if (device_handle>0) - { - LOG_ERROR("device is already opened"); - return ERROR_JTAG_INIT_FAILED; - } #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - LOG_DEBUG("opening /dev/ppi%d...", gw16012_port); - snprintf(buffer, 256, "/dev/ppi%d", gw16012_port); - device_handle = open(buffer, O_WRONLY); -#else - LOG_DEBUG("opening /dev/parport%d...", gw16012_port); +#define GW16012_PPDEV_NAME "ppi" - snprintf(buffer, 256, "/dev/parport%d", gw16012_port); - device_handle = open(buffer, O_WRONLY); -#endif - if (device_handle<0) +static int gw16012_init_ioctls(void) +{ + int temp = 0; + temp = ioctl(device_handle, PPCLAIM); + if (temp < 0) { - LOG_ERROR("cannot open device. check it exists and that user read and write rights are set"); + LOG_ERROR("cannot claim device"); return ERROR_JTAG_INIT_FAILED; } - LOG_DEBUG("...open"); + temp = PARPORT_MODE_COMPAT; + temp = ioctl(device_handle, PPSETMODE, &temp); + if (temp < 0) + { + LOG_ERROR(" cannot set compatible mode to device"); + return ERROR_JTAG_INIT_FAILED; + } -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - i=ioctl(device_handle, PPCLAIM); - if (i<0) + temp = IEEE1284_MODE_COMPAT; + temp = ioctl(device_handle, PPNEGOT, &temp); + if (temp < 0) { - LOG_ERROR("cannot claim device"); + LOG_ERROR("cannot set compatible 1284 mode to device"); return ERROR_JTAG_INIT_FAILED; } + return ERROR_OK; +} +#else + +#define GW16012_PPDEV_NAME "parport" - i = PARPORT_MODE_COMPAT; - i= ioctl(device_handle, PPSETMODE, & i); - if (i<0) +static int gw16012_init_ioctls(void) +{ + return ERROR_OK; +} + +#endif // defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + +static int gw16012_init_device(void) +{ + const char *device_name = GW16012_PPDEV_NAME; + char buffer[256]; + + if (device_handle > 0) { - LOG_ERROR(" cannot set compatible mode to device"); + LOG_ERROR("device is already opened"); return ERROR_JTAG_INIT_FAILED; } - i = IEEE1284_MODE_COMPAT; - i = ioctl(device_handle, PPNEGOT, & i); - if (i<0) + snprintf(buffer, 256, "/dev/%s%d", device_name, gw16012_port); + LOG_DEBUG("opening %s...", buffer); + + device_handle = open(buffer, O_WRONLY); + if (device_handle<0) { - LOG_ERROR("cannot set compatible 1284 mode to device"); + LOG_ERROR("cannot open device. check it exists and that user read and write rights are set"); return ERROR_JTAG_INIT_FAILED; } -#endif -#else + + LOG_DEBUG("...open"); + + if (gw16012_init_ioctls() != ERROR_OK) + return ERROR_JTAG_INIT_FAILED; + + return ERROR_OK; +} + +#else // PARPORT_USE_PPDEV + +static int gw16012_init_device(void) +{ if (gw16012_port == 0) { gw16012_port = 0x378; @@ -544,7 +550,17 @@ int gw16012_init(void) #else outb(0x0, gw16012_port + 2); #endif -#endif /* PARPORT_USE_PPDEV */ + return ERROR_OK; +} + +#endif // PARPORT_USE_PPDEV + +static int gw16012_init(void) +{ + u8 status_port; + + if (gw16012_init_device() != ERROR_OK) + return ERROR_JTAG_INIT_FAILED; gw16012_input(&status_port); gw16012_msb = (status_port & 0x80) ^ 0x80; @@ -555,13 +571,13 @@ int gw16012_init(void) return ERROR_OK; } -int gw16012_quit(void) +static int gw16012_quit(void) { return ERROR_OK; } -int gw16012_handle_parport_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int gw16012_handle_parport_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { if (argc == 0) return ERROR_OK;