From: kc8apf Date: Tue, 10 Feb 2009 18:21:17 +0000 (+0000) Subject: Use C89/C99/C++ compliant boolean types X-Git-Tag: v0.2.0~1131 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e77ae9096a40707d3b878b46969a60a06656dc06;p=openocd Use C89/C99/C++ compliant boolean types git-svn-id: svn://svn.berlios.de/openocd/trunk@1370 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- diff --git a/configure.in b/configure.in index 792e6f8c..e6c6473e 100644 --- a/configure.in +++ b/configure.in @@ -11,6 +11,7 @@ AC_CHECK_HEADERS(sys/param.h) AC_CHECK_HEADERS(sys/time.h) AC_CHECK_HEADERS(elf.h) AC_CHECK_HEADERS(strings.h) +AC_CHECK_HEADERS(stdbool.h) AC_HEADER_TIME diff --git a/src/helper/types.h b/src/helper/types.h index 82368a92..047f76c2 100644 --- a/src/helper/types.h +++ b/src/helper/types.h @@ -45,6 +45,21 @@ typedef unsigned long long u64; typedef struct jtag_tap_s jtag_tap_t; +#ifdef HAVE_STDBOOL_H +#include +#else /* HAVE_STDBOOL_H */ +#define __bool_true_false_are_defined 1 + +#ifndef __cplusplus + +#define false 0 +#define true 1 + +#define bool _Bool +typedef int _Bool; +#endif /* __cplusplus */ + +#endif /* HAVE_STDBOOL_H */ /* DANGER!!!! here be dragons! * diff --git a/src/jtag/bitbang.c b/src/jtag/bitbang.c index 48bda0f4..92ba6cc0 100644 --- a/src/jtag/bitbang.c +++ b/src/jtag/bitbang.c @@ -112,11 +112,11 @@ void bitbang_path_move(pathmove_command_t *cmd) state_count = 0; while (num_states) { - if (tap_state_transition(tap_get_state(), FALSE) == cmd->path[state_count]) + if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count]) { tms = 0; } - else if (tap_state_transition(tap_get_state(), TRUE) == cmd->path[state_count]) + else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count]) { tms = 1; } diff --git a/src/jtag/bitq.c b/src/jtag/bitq.c index 392e3d3d..0d71c301 100644 --- a/src/jtag/bitq.c +++ b/src/jtag/bitq.c @@ -194,9 +194,9 @@ void bitq_path_move(pathmove_command_t* cmd) for (i = 0; i<=cmd->num_states; i++) { - if (tap_state_transition(tap_get_state(), FALSE) == cmd->path[i]) + if (tap_state_transition(tap_get_state(), false) == cmd->path[i]) bitq_io(0, 0, 0); - else if (tap_state_transition(tap_get_state(), TRUE) == cmd->path[i]) + else if (tap_state_transition(tap_get_state(), true) == cmd->path[i]) bitq_io(1, 0, 0); else { diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c index 9a3c986f..115cd7c2 100644 --- a/src/jtag/ft2232.c +++ b/src/jtag/ft2232.c @@ -562,9 +562,9 @@ void ft2232_add_pathmove(pathmove_command_t* cmd) while (num_states_batch--) { - if (tap_state_transition(tap_get_state(), FALSE) == cmd->path[state_count]) + if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count]) buf_set_u32(&tms_byte, bit_count++, 1, 0x0); - else if (tap_state_transition(tap_get_state(), TRUE) == cmd->path[state_count]) + else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count]) buf_set_u32(&tms_byte, bit_count++, 1, 0x1); else { diff --git a/src/jtag/gw16012.c b/src/jtag/gw16012.c index 622c81f3..3d72aa27 100644 --- a/src/jtag/gw16012.c +++ b/src/jtag/gw16012.c @@ -230,11 +230,11 @@ void gw16012_path_move(pathmove_command_t *cmd) while (num_states) { gw16012_control(0x0); /* single-bit mode */ - if (tap_state_transition(tap_get_state(), FALSE) == cmd->path[state_count]) + if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count]) { gw16012_data(0x0); /* TCK cycle with TMS low */ } - else if (tap_state_transition(tap_get_state(), TRUE) == cmd->path[state_count]) + else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count]) { gw16012_data(0x2); /* TCK cycle with TMS high */ } diff --git a/src/jtag/jlink.c b/src/jtag/jlink.c index 26f92330..bfd3a780 100644 --- a/src/jtag/jlink.c +++ b/src/jtag/jlink.c @@ -366,11 +366,11 @@ void jlink_path_move(int num_states, tap_state_t *path) for (i = 0; i < num_states; i++) { - if (path[i] == tap_state_transition(tap_get_state(), FALSE)) + if (path[i] == tap_state_transition(tap_get_state(), false)) { jlink_tap_append_step(0, 0); } - else if (path[i] == tap_state_transition(tap_get_state(), TRUE)) + else if (path[i] == tap_state_transition(tap_get_state(), true)) { jlink_tap_append_step(1, 0); } diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c index b811cb7d..ae51ebc1 100644 --- a/src/jtag/jtag.c +++ b/src/jtag/jtag.c @@ -957,8 +957,8 @@ void jtag_add_pathmove(int num_states, tap_state_t *path) LOG_ERROR("BUG: TAP_RESET is not a valid state for pathmove sequences"); exit(-1); } - if ( tap_state_transition(cur_state, 1) != path[i] - && tap_state_transition(cur_state, 0) != path[i]) + if ( tap_state_transition(cur_state, true) != path[i] + && tap_state_transition(cur_state, false) != path[i]) { LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(cur_state), tap_state_name(path[i])); exit(-1); @@ -2920,6 +2920,7 @@ void jtag_tap_handle_event( jtag_tap_t * tap, enum jtag_tap_event e) } } + /*--------------------------------------------*/ /* these Cable Helper API functions are all documented in the jtag.h header file, @@ -2964,6 +2965,7 @@ tap_state_t tap_get_end_state() return end_state_follower; } + int tap_move_ndx( tap_state_t astate ) { /* given a stable state, return the index into the tms_seqs[] array within tap_get_tms_path() */ @@ -2994,6 +2996,7 @@ int tap_move_ndx( tap_state_t astate ) return ndx; } + int tap_get_tms_path( tap_state_t from, tap_state_t to ) { /* tap_move[i][j]: tap movement command to go from state i to state j @@ -3035,9 +3038,10 @@ int tap_get_tms_path( tap_state_t from, tap_state_t to ) return tms_seqs[tap_move_ndx(from)][tap_move_ndx(to)]; } -int tap_is_state_stable(tap_state_t astate) + +bool tap_is_state_stable(tap_state_t astate) { - int is_stable; + bool is_stable; /* A switch() is used because it is symbol dependent (not value dependent like an array), and can also check bounds. @@ -3050,16 +3054,16 @@ int tap_is_state_stable(tap_state_t astate) case TAP_DRPAUSE: case TAP_IRSHIFT: case TAP_IRPAUSE: - is_stable = 1; + is_stable = true; break; default: - is_stable = 0; + is_stable = false; } return is_stable; } -tap_state_t tap_state_transition(tap_state_t cur_state, int tms) +tap_state_t tap_state_transition(tap_state_t cur_state, bool tms) { tap_state_t new_state; diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h index 895afe1f..386d517e 100644 --- a/src/jtag/jtag.h +++ b/src/jtag/jtag.h @@ -29,6 +29,7 @@ #include "command.h" + #if 0 #define _DEBUG_JTAG_IO_ #endif @@ -37,6 +38,7 @@ #define DEBUG_JTAG_IOZ 64 #endif + /* 16 Tap States, from page 21 of ASSET InterTech, Inc.'s svf.pdf */ enum tap_state { @@ -57,6 +59,7 @@ typedef struct tap_transition_s //extern tap_transition_t tap_transitions[16]; /* describe the TAP state diagram */ + /*------------------------------------------------*/ /* The "Cable Helper API" is what the cable drivers can use to help implement @@ -147,9 +150,9 @@ int tap_move_ndx(tap_state_t astate); /** * Function tap_is_state_stable - * returns TRUE if the \a astate is stable. + * returns true if the \a astate is stable. */ -int tap_is_state_stable(tap_state_t astate); +bool tap_is_state_stable(tap_state_t astate); /** * Function tap_state_transition @@ -158,7 +161,7 @@ int tap_is_state_stable(tap_state_t astate); * @param tms is either zero or non-zero, just like a real TMS line in a jtag interface. * @return tap_state_t - the next state a TAP would enter. */ -tap_state_t tap_state_transition(tap_state_t current_state, int tms); +tap_state_t tap_state_transition(tap_state_t current_state, bool tms); /** * Function tap_state_name @@ -168,6 +171,7 @@ const char* tap_state_name(tap_state_t state); /*-----------------------------------------------*/ + extern tap_state_t cmd_queue_end_state; /* finish DR scans in dr_end_state */ extern tap_state_t cmd_queue_cur_state; /* current TAP state */ diff --git a/src/jtag/rlink/rlink.c b/src/jtag/rlink/rlink.c index 80bd08af..380d451b 100644 --- a/src/jtag/rlink/rlink.c +++ b/src/jtag/rlink/rlink.c @@ -927,11 +927,11 @@ void rlink_path_move(pathmove_command_t *cmd) state_count = 0; while (num_states) { - if (tap_state_transition(tap_get_state(), FALSE) == cmd->path[state_count]) + if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count]) { tms = 0; } - else if (tap_state_transition(tap_get_state(), TRUE) == cmd->path[state_count]) + else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count]) { tms = 1; } diff --git a/src/jtag/usbprog.c b/src/jtag/usbprog.c index 773f2977..6c62afc1 100644 --- a/src/jtag/usbprog.c +++ b/src/jtag/usbprog.c @@ -268,13 +268,13 @@ void usbprog_path_move(pathmove_command_t *cmd) state_count = 0; while (num_states) { - if (tap_state_transition(tap_get_state(), FALSE) == cmd->path[state_count]) + if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count]) { /* LOG_INFO("1"); */ usbprog_write(0, 0, 0); usbprog_write(1, 0, 0); } - else if (tap_state_transition(tap_get_state(), TRUE) == cmd->path[state_count]) + else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count]) { /* LOG_INFO("2"); */ usbprog_write(0, 1, 0); diff --git a/src/jtag/vsllink.c b/src/jtag/vsllink.c index fd2b397e..8cf7e52e 100644 --- a/src/jtag/vsllink.c +++ b/src/jtag/vsllink.c @@ -634,11 +634,11 @@ void vsllink_add_path(int start, int num, tap_state_t *path) vsllink_usb_out_buffer[vsllink_usb_out_buffer_idx] = 0; } - if (path[i - start] == tap_state_transition(tap_get_state(), TRUE)) + if (path[i - start] == tap_state_transition(tap_get_state(), true)) { vsllink_usb_out_buffer[vsllink_usb_out_buffer_idx] |= 1 << (i & 7); } - else if (path[i - start] == tap_state_transition(tap_get_state(), FALSE)) + else if (path[i - start] == tap_state_transition(tap_get_state(), false)) { // nothing to do } diff --git a/src/jtag/zy1000.c b/src/jtag/zy1000.c index de13ba4d..a2c14573 100644 --- a/src/jtag/zy1000.c +++ b/src/jtag/zy1000.c @@ -764,11 +764,11 @@ int interface_jtag_add_pathmove(int num_states, tap_state_t *path) while (num_states) { - if (tap_state_transition(cur_state, FALSE) == path[state_count]) + if (tap_state_transition(cur_state, false) == path[state_count]) { tms = 0; } - else if (tap_state_transition(cur_state, TRUE) == path[state_count]) + else if (tap_state_transition(cur_state, true) == path[state_count]) { tms = 1; } diff --git a/src/xsvf/xsvf.c b/src/xsvf/xsvf.c index 855021df..e3153a3e 100644 --- a/src/xsvf/xsvf.c +++ b/src/xsvf/xsvf.c @@ -201,11 +201,11 @@ static void xsvf_add_statemove(tap_state_t state) int j = (move >> i) & 1; if (j) { - curstate = tap_state_transition(curstate, TRUE); + curstate = tap_state_transition(curstate, true); } else { - curstate = tap_state_transition(curstate, FALSE); + curstate = tap_state_transition(curstate, false); } moves[i] = curstate; }