From a94748ec6da9bdc6e25a7f73bbea723b8b55fa33 Mon Sep 17 00:00:00 2001 From: Zachary T Welch Date: Mon, 16 Nov 2009 02:53:57 -0800 Subject: rename CEIL as DIV_ROUND_UP Improves the name of this macro, moves it to types.h, and adds a block of Doxygen comments to describe what it does. --- src/jtag/commands.c | 4 ++-- src/jtag/core.c | 4 ++-- src/jtag/driver.c | 6 +++--- src/jtag/ft2232.c | 14 +++++++------- src/jtag/jtag.h | 2 +- src/jtag/tcl.c | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/jtag') diff --git a/src/jtag/commands.c b/src/jtag/commands.c index ccd6d0f1..4e8ce40f 100644 --- a/src/jtag/commands.c +++ b/src/jtag/commands.c @@ -179,7 +179,7 @@ int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer) int i; bit_count = jtag_scan_size(cmd); - *buffer = calloc(1,CEIL(bit_count, 8)); + *buffer = calloc(1,DIV_ROUND_UP(bit_count, 8)); bit_count = 0; @@ -235,7 +235,7 @@ int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd) if (cmd->fields[i].in_value) { int num_bits = cmd->fields[i].num_bits; - uint8_t *captured = buf_set_buf(buffer, bit_count, malloc(CEIL(num_bits, 8)), 0, num_bits); + uint8_t *captured = buf_set_buf(buffer, bit_count, malloc(DIV_ROUND_UP(num_bits, 8)), 0, num_bits); #ifdef _DEBUG_JTAG_IO_ char *char_buf = buf_to_str(captured, diff --git a/src/jtag/core.c b/src/jtag/core.c index 1841dde9..c8a76e88 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -1193,7 +1193,7 @@ static int jtag_validate_ircapture(void) /* increase length to add 2 bit sentinel after scan */ total_ir_length += 2; - ir_test = malloc(CEIL(total_ir_length, 8)); + ir_test = malloc(DIV_ROUND_UP(total_ir_length, 8)); if (ir_test == NULL) return ERROR_FAIL; @@ -1293,7 +1293,7 @@ void jtag_tap_init(struct jtag_tap *tap) /* if we're autoprobing, cope with potentially huge ir_length */ ir_len_bits = tap->ir_length ? : JTAG_IRLEN_MAX; - ir_len_bytes = CEIL(ir_len_bits, 8); + ir_len_bytes = DIV_ROUND_UP(ir_len_bits, 8); tap->expected = calloc(1, ir_len_bytes); tap->expected_mask = calloc(1, ir_len_bytes); diff --git a/src/jtag/driver.c b/src/jtag/driver.c index 6469358d..cadd88e8 100644 --- a/src/jtag/driver.c +++ b/src/jtag/driver.c @@ -64,7 +64,7 @@ static void cmd_queue_scan_field_clone(struct scan_field * dst, const struct sca { dst->tap = src->tap; dst->num_bits = src->num_bits; - dst->out_value = buf_cpy(src->out_value, cmd_queue_alloc(CEIL(src->num_bits, 8)), src->num_bits); + dst->out_value = buf_cpy(src->out_value, cmd_queue_alloc(DIV_ROUND_UP(src->num_bits, 8)), src->num_bits); dst->in_value = src->in_value; } @@ -128,7 +128,7 @@ int interface_jtag_add_ir_scan(int in_num_fields, const struct scan_field *in_fi field->tap = tap; field->num_bits = tap->ir_length; - field->out_value = buf_set_ones(cmd_queue_alloc(CEIL(tap->ir_length, 8)), tap->ir_length); + field->out_value = buf_set_ones(cmd_queue_alloc(DIV_ROUND_UP(tap->ir_length, 8)), tap->ir_length); field->in_value = NULL; /* do not collect input for tap's in bypass */ } @@ -317,7 +317,7 @@ void interface_jtag_add_dr_out(struct jtag_tap *target_tap, field->tap = tap; field->num_bits = scan_size; - field->out_value = buf_cpy(out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size); + field->out_value = buf_cpy(out_value, cmd_queue_alloc(DIV_ROUND_UP(scan_size, 8)), scan_size); field->in_value = NULL; field++; diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c index cee55e0c..7acdf1a0 100644 --- a/src/jtag/ft2232.c +++ b/src/jtag/ft2232.c @@ -721,7 +721,7 @@ static int ft2232_send_and_recv(struct jtag_command* first, struct jtag_command* if (type != SCAN_OUT) { scan_size = jtag_scan_size(cmd->cmd.scan); - buffer = calloc(CEIL(scan_size, 8), 1); + buffer = calloc(DIV_ROUND_UP(scan_size, 8), 1); ft2232_read_scan(type, buffer, scan_size); if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) retval = ERROR_JTAG_QUEUE_FAILED; @@ -962,7 +962,7 @@ static int ft2232_large_scan(struct scan_command* cmd, enum scan_type type, uint int bits_left = scan_size; int cur_byte = 0; int last_bit; - uint8_t* receive_buffer = malloc(CEIL(scan_size, 8)); + uint8_t* receive_buffer = malloc(DIV_ROUND_UP(scan_size, 8)); uint8_t* receive_pointer = receive_buffer; uint32_t bytes_written; uint32_t bytes_read; @@ -1182,7 +1182,7 @@ static int ft2232_predict_scan_out(int scan_size, enum scan_type type) if (type == SCAN_IN) /* only from device to host */ { /* complete bytes */ - predicted_size += CEIL(num_bytes, 65536) * 3; + predicted_size += DIV_ROUND_UP(num_bytes, 65536) * 3; /* remaining bits - 1 (up to 7) */ predicted_size += ((scan_size - 1) % 8) ? 2 : 0; @@ -1190,7 +1190,7 @@ static int ft2232_predict_scan_out(int scan_size, enum scan_type type) else /* host to device, or bidirectional */ { /* complete bytes */ - predicted_size += num_bytes + CEIL(num_bytes, 65536) * 3; + predicted_size += num_bytes + DIV_ROUND_UP(num_bytes, 65536) * 3; /* remaining bits -1 (up to 7) */ predicted_size += ((scan_size - 1) % 8) ? 3 : 0; @@ -1206,7 +1206,7 @@ static int ft2232_predict_scan_in(int scan_size, enum scan_type type) if (type != SCAN_OUT) { /* complete bytes */ - predicted_size += (CEIL(scan_size, 8) > 1) ? (CEIL(scan_size, 8) - 1) : 0; + predicted_size += (DIV_ROUND_UP(scan_size, 8) > 1) ? (DIV_ROUND_UP(scan_size, 8) - 1) : 0; /* remaining bits - 1 */ predicted_size += ((scan_size - 1) % 8) ? 1 : 0; @@ -1506,7 +1506,7 @@ static int ft2232_execute_runtest(struct jtag_command *cmd) predicted_size = 0; if (tap_get_state() != TAP_IDLE) predicted_size += 3; - predicted_size += 3 * CEIL(cmd->cmd.runtest->num_cycles, 7); + predicted_size += 3 * DIV_ROUND_UP(cmd->cmd.runtest->num_cycles, 7); if (cmd->cmd.runtest->end_state != TAP_IDLE) predicted_size += 3; if (tap_get_end_state() != TAP_IDLE) @@ -1605,7 +1605,7 @@ static int ft2232_execute_pathmove(struct jtag_command *cmd) tap_state_name(path[num_states-1])); /* only send the maximum buffer size that FT2232C can handle */ - predicted_size = 3 * CEIL(num_states, 7); + predicted_size = 3 * DIV_ROUND_UP(num_states, 7); if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE) { if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK) diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h index 30d62fd9..5328ff81 100644 --- a/src/jtag/jtag.h +++ b/src/jtag/jtag.h @@ -47,7 +47,7 @@ #define DIM(x) (sizeof(x)/sizeof((x)[0])) /** Calculate the number of bytes required to hold @a n TAP scan bits */ -#define TAP_SCAN_BYTES(n) CEIL(n, 8) +#define TAP_SCAN_BYTES(n) DIV_ROUND_UP(n, 8) /*------------------------------------------------------*/ diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 75732ef0..71e7bd5a 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -1129,7 +1129,7 @@ COMMAND_HANDLER(handle_irscan_command) int field_size = tap->ir_length; fields[i].tap = tap; fields[i].num_bits = field_size; - fields[i].out_value = malloc(CEIL(field_size, 8)); + fields[i].out_value = malloc(DIV_ROUND_UP(field_size, 8)); uint32_t value; retval = parse_u32(args[i * 2 + 1], &value); @@ -1257,7 +1257,7 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args fields[field_count].tap = tap; fields[field_count].num_bits = bits; - fields[field_count].out_value = malloc(CEIL(bits, 8)); + fields[field_count].out_value = malloc(DIV_ROUND_UP(bits, 8)); str_to_buf(str, len, fields[field_count].out_value, bits, 0); fields[field_count].in_value = fields[field_count].out_value; field_count++; -- cgit v1.2.3