diff options
author | Zachary T Welch <zw@superlucidity.net> | 2009-11-16 02:53:57 -0800 |
---|---|---|
committer | Zachary T Welch <zw@superlucidity.net> | 2009-11-16 09:58:11 -0800 |
commit | a94748ec6da9bdc6e25a7f73bbea723b8b55fa33 (patch) | |
tree | c6aebc5e8f39d0918f9a88dd43e373ea9d28e210 /src | |
parent | f0ce88b3af9a6090ac986160950d66317de5087e (diff) | |
download | openocd_libswd-a94748ec6da9bdc6e25a7f73bbea723b8b55fa33.tar.gz openocd_libswd-a94748ec6da9bdc6e25a7f73bbea723b8b55fa33.tar.bz2 openocd_libswd-a94748ec6da9bdc6e25a7f73bbea723b8b55fa33.tar.xz openocd_libswd-a94748ec6da9bdc6e25a7f73bbea723b8b55fa33.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/flash/at91sam7.c | 4 | ||||
-rw-r--r-- | src/flash/lpc2000.c | 2 | ||||
-rw-r--r-- | src/flash/str9xpec.c | 10 | ||||
-rw-r--r-- | src/helper/binarybuffer.c | 8 | ||||
-rw-r--r-- | src/helper/binarybuffer.h | 2 | ||||
-rw-r--r-- | src/helper/types.h | 9 | ||||
-rw-r--r-- | src/jtag/commands.c | 4 | ||||
-rw-r--r-- | src/jtag/core.c | 4 | ||||
-rw-r--r-- | src/jtag/driver.c | 6 | ||||
-rw-r--r-- | src/jtag/ft2232.c | 14 | ||||
-rw-r--r-- | src/jtag/jtag.h | 2 | ||||
-rw-r--r-- | src/jtag/tcl.c | 4 | ||||
-rw-r--r-- | src/pld/virtex2.c | 2 | ||||
-rw-r--r-- | src/server/gdb_server.c | 22 | ||||
-rw-r--r-- | src/target/algorithm.c | 2 | ||||
-rw-r--r-- | src/target/etb.c | 4 | ||||
-rw-r--r-- | src/target/target.c | 2 | ||||
-rw-r--r-- | src/target/target_request.c | 8 | ||||
-rw-r--r-- | src/xsvf/xsvf.c | 4 |
19 files changed, 60 insertions, 53 deletions
diff --git a/src/flash/at91sam7.c b/src/flash/at91sam7.c index e0b83d57..9d05d7b5 100644 --- a/src/flash/at91sam7.c +++ b/src/flash/at91sam7.c @@ -979,7 +979,7 @@ static int at91sam7_write(struct flash_bank *bank, uint8_t *buffer, uint32_t off return ERROR_FLASH_BANK_NOT_PROBED; first_page = offset/dst_min_alignment; - last_page = CEIL(offset + count, dst_min_alignment); + last_page = DIV_ROUND_UP(offset + count, dst_min_alignment); LOG_DEBUG("first_page: %i, last_page: %i, count %i", (int)first_page, (int)last_page, (int)count); @@ -997,7 +997,7 @@ static int at91sam7_write(struct flash_bank *bank, uint8_t *buffer, uint32_t off /* Write one block to the PageWriteBuffer */ buffer_pos = (pagen-first_page)*dst_min_alignment; - wcount = CEIL(count,4); + wcount = DIV_ROUND_UP(count,4); if ((retval = target_write_memory(target, bank->base + pagen*dst_min_alignment, 4, wcount, buffer + buffer_pos)) != ERROR_OK) { return retval; diff --git a/src/flash/lpc2000.c b/src/flash/lpc2000.c index 79f58045..a3f97180 100644 --- a/src/flash/lpc2000.c +++ b/src/flash/lpc2000.c @@ -573,7 +573,7 @@ static int lpc2000_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offs { if (offset >= bank->sectors[i].offset) first_sector = i; - if (offset + CEIL(count, dst_min_alignment) * dst_min_alignment > bank->sectors[i].offset) + if (offset + DIV_ROUND_UP(count, dst_min_alignment) * dst_min_alignment > bank->sectors[i].offset) last_sector = i; } diff --git a/src/flash/str9xpec.c b/src/flash/str9xpec.c index 4bf5bcae..7f6d8bed 100644 --- a/src/flash/str9xpec.c +++ b/src/flash/str9xpec.c @@ -44,7 +44,7 @@ int str9xpec_set_instr(struct jtag_tap *tap, uint32_t new_instr, tap_state_t end field.tap = tap; field.num_bits = tap->ir_length; - field.out_value = calloc(CEIL(field.num_bits, 8), 1); + field.out_value = calloc(DIV_ROUND_UP(field.num_bits, 8), 1); buf_set_u32(field.out_value, 0, field.num_bits, new_instr); field.in_value = NULL; @@ -289,7 +289,7 @@ static int str9xpec_blank_check(struct flash_bank *bank, int first, int last) return ERROR_FLASH_OPERATION_FAILED; } - buffer = calloc(CEIL(64, 8), 1); + buffer = calloc(DIV_ROUND_UP(64, 8), 1); LOG_DEBUG("blank check: first_bank: %i, last_bank: %i", first, last); @@ -378,7 +378,7 @@ static int str9xpec_erase_area(struct flash_bank *bank, int first, int last) return ISC_STATUS_ERROR; } - buffer = calloc(CEIL(64, 8), 1); + buffer = calloc(DIV_ROUND_UP(64, 8), 1); LOG_DEBUG("erase: first_bank: %i, last_bank: %i", first, last); @@ -618,7 +618,7 @@ static int str9xpec_write(struct flash_bank *bank, uint8_t *buffer, uint32_t off LOG_DEBUG("first_sector: %i, last_sector: %i", first_sector, last_sector); - scanbuf = calloc(CEIL(64, 8), 1); + scanbuf = calloc(DIV_ROUND_UP(64, 8), 1); LOG_DEBUG("ISC_PROGRAM"); @@ -745,7 +745,7 @@ COMMAND_HANDLER(str9xpec_handle_part_id_command) str9xpec_info = bank->driver_priv; tap = str9xpec_info->tap; - buffer = calloc(CEIL(32, 8), 1); + buffer = calloc(DIV_ROUND_UP(32, 8), 1); str9xpec_set_instr(tap, ISC_IDCODE, TAP_IRPAUSE); diff --git a/src/helper/binarybuffer.c b/src/helper/binarybuffer.c index 53ad4d39..081cc037 100644 --- a/src/helper/binarybuffer.c +++ b/src/helper/binarybuffer.c @@ -54,7 +54,7 @@ void* buf_cpy(const void *from, void *_to, unsigned size) return NULL; // copy entire buffer - memcpy(_to, from, CEIL(size, 8)); + memcpy(_to, from, DIV_ROUND_UP(size, 8)); /* mask out bits that don't belong to the buffer */ unsigned trailing_bits = size % 8; @@ -191,11 +191,11 @@ char* buf_to_str(const void *_buf, unsigned buf_len, unsigned radix) return NULL; } - unsigned str_len = ceil_f_to_u32(CEIL(buf_len, 8) * factor); + unsigned str_len = ceil_f_to_u32(DIV_ROUND_UP(buf_len, 8) * factor); char *str = calloc(str_len + 1, 1); const uint8_t *buf = _buf; - int b256_len = CEIL(buf_len, 8); + int b256_len = DIV_ROUND_UP(buf_len, 8); for (int i = b256_len - 1; i >= 0; i--) { uint32_t tmp = buf[i]; @@ -300,7 +300,7 @@ int str_to_buf(const char *str, unsigned str_len, } uint8_t *buf = _buf; - for (unsigned j = 0; j < CEIL(buf_len, 8); j++) + for (unsigned j = 0; j < DIV_ROUND_UP(buf_len, 8); j++) { if (j < b256_len) buf[j] = b256_buf[j]; diff --git a/src/helper/binarybuffer.h b/src/helper/binarybuffer.h index 9e0cc9b7..460d0178 100644 --- a/src/helper/binarybuffer.h +++ b/src/helper/binarybuffer.h @@ -124,8 +124,6 @@ int str_to_buf(const char *str, unsigned len, void *bin_buf, unsigned buf_size, unsigned radix); char* buf_to_str(const void *buf, unsigned size, unsigned radix); -#define CEIL(m, n) (((m) + (n) - 1) / (n)) - /* read a uint32_t from a buffer in target memory endianness */ static inline uint32_t fast_target_buffer_get_u32(const void *p, bool le) { diff --git a/src/helper/types.h b/src/helper/types.h index a8753c5f..8f6283b5 100644 --- a/src/helper/types.h +++ b/src/helper/types.h @@ -73,6 +73,15 @@ typedef bool _Bool; (type *)( (char *)__mptr - offsetof(type,member) );}) +/** + * Rounds @c m up to the nearest multiple of @c n using division. + * @params m The value to round up to @c n. + * @params n Round @c m up to a multiple of this number. + * @returns The rounded integer value. + */ +#define DIV_ROUND_UP(m, n) (((m) + (n) - 1) / (n)) + + /* DANGER!!!! here be dragons! * * Leave these fn's as byte accesses because it is safe 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) /*-----</Macros>-------------------------------------------------*/ 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++; diff --git a/src/pld/virtex2.c b/src/pld/virtex2.c index ea9ee0ce..c07931e7 100644 --- a/src/pld/virtex2.c +++ b/src/pld/virtex2.c @@ -37,7 +37,7 @@ static int virtex2_set_instr(struct jtag_tap *tap, uint32_t new_instr) field.tap = tap; field.num_bits = tap->ir_length; - field.out_value = calloc(CEIL(field.num_bits, 8), 1); + field.out_value = calloc(DIV_ROUND_UP(field.num_bits, 8), 1); buf_set_u32(field.out_value, 0, field.num_bits, new_instr); field.in_value = NULL; diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index f6b44cd2..55ec7d4e 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -871,7 +871,7 @@ void gdb_str_to_target(struct target *target, char *tstr, struct reg *reg) uint8_t *buf; int buf_len; buf = reg->value; - buf_len = CEIL(reg->size, 8); + buf_len = DIV_ROUND_UP(reg->size, 8); for (i = 0; i < buf_len; i++) { @@ -940,25 +940,25 @@ int gdb_get_registers_packet(struct connection *connection, struct target *targe reg_packet_size += reg_list[i]->size; } - reg_packet = malloc(CEIL(reg_packet_size, 8) * 2); + reg_packet = malloc(DIV_ROUND_UP(reg_packet_size, 8) * 2); reg_packet_p = reg_packet; for (i = 0; i < reg_list_size; i++) { gdb_str_to_target(target, reg_packet_p, reg_list[i]); - reg_packet_p += CEIL(reg_list[i]->size, 8) * 2; + reg_packet_p += DIV_ROUND_UP(reg_list[i]->size, 8) * 2; } #ifdef _DEBUG_GDB_IO_ { char *reg_packet_p; - reg_packet_p = strndup(reg_packet, CEIL(reg_packet_size, 8) * 2); + reg_packet_p = strndup(reg_packet, DIV_ROUND_UP(reg_packet_size, 8) * 2); LOG_DEBUG("reg_packet: %s", reg_packet_p); free(reg_packet_p); } #endif - gdb_put_packet(connection, reg_packet, CEIL(reg_packet_size, 8) * 2); + gdb_put_packet(connection, reg_packet, DIV_ROUND_UP(reg_packet_size, 8) * 2); free(reg_packet); free(reg_list); @@ -997,7 +997,7 @@ int gdb_set_registers_packet(struct connection *connection, struct target *targe for (i = 0; i < reg_list_size; i++) { uint8_t *bin_buf; - int chars = (CEIL(reg_list[i]->size, 8) * 2); + int chars = (DIV_ROUND_UP(reg_list[i]->size, 8) * 2); if (packet_p + chars > packet + packet_size) { @@ -1005,7 +1005,7 @@ int gdb_set_registers_packet(struct connection *connection, struct target *targe } struct reg_arch_type *arch_type; - bin_buf = malloc(CEIL(reg_list[i]->size, 8)); + bin_buf = malloc(DIV_ROUND_UP(reg_list[i]->size, 8)); gdb_target_to_reg(target, packet_p, chars, bin_buf); /* get register arch_type, and call set method */ @@ -1051,11 +1051,11 @@ int gdb_get_register_packet(struct connection *connection, struct target *target exit(-1); } - reg_packet = malloc(CEIL(reg_list[reg_num]->size, 8) * 2); + reg_packet = malloc(DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2); gdb_str_to_target(target, reg_packet, reg_list[reg_num]); - gdb_put_packet(connection, reg_packet, CEIL(reg_list[reg_num]->size, 8) * 2); + gdb_put_packet(connection, reg_packet, DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2); free(reg_list); free(reg_packet); @@ -1093,8 +1093,8 @@ int gdb_set_register_packet(struct connection *connection, struct target *target } /* convert from GDB-string (target-endian) to hex-string (big-endian) */ - bin_buf = malloc(CEIL(reg_list[reg_num]->size, 8)); - int chars = (CEIL(reg_list[reg_num]->size, 8) * 2); + bin_buf = malloc(DIV_ROUND_UP(reg_list[reg_num]->size, 8)); + int chars = (DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2); /* fix!!! add some sanity checks on packet size here */ diff --git a/src/target/algorithm.c b/src/target/algorithm.c index 7643e3cb..76cf48bc 100644 --- a/src/target/algorithm.c +++ b/src/target/algorithm.c @@ -43,7 +43,7 @@ void init_reg_param(struct reg_param *param, char *reg_name, uint32_t size, enum { param->reg_name = reg_name; param->size = size; - param->value = malloc(CEIL(size, 8)); + param->value = malloc(DIV_ROUND_UP(size, 8)); param->direction = direction; } diff --git a/src/target/etb.c b/src/target/etb.c index 72474cd0..21c375c3 100644 --- a/src/target/etb.c +++ b/src/target/etb.c @@ -57,7 +57,7 @@ static int etb_set_instr(struct etb *etb, uint32_t new_instr) field.tap = tap; field.num_bits = tap->ir_length; - field.out_value = calloc(CEIL(field.num_bits, 8), 1); + field.out_value = calloc(DIV_ROUND_UP(field.num_bits, 8), 1); buf_set_u32(field.out_value, 0, field.num_bits, new_instr); field.in_value = NULL; @@ -78,7 +78,7 @@ static int etb_scann(struct etb *etb, uint32_t new_scan_chain) field.tap = etb->tap; field.num_bits = 5; - field.out_value = calloc(CEIL(field.num_bits, 8), 1); + field.out_value = calloc(DIV_ROUND_UP(field.num_bits, 8), 1); buf_set_u32(field.out_value, 0, field.num_bits, new_scan_chain); field.in_value = NULL; diff --git a/src/target/target.c b/src/target/target.c index f5a092a7..c24085f1 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -1967,7 +1967,7 @@ COMMAND_HANDLER(handle_reg_command) /* set register value */ if (argc == 2) { - uint8_t *buf = malloc(CEIL(reg->size, 8)); + uint8_t *buf = malloc(DIV_ROUND_UP(reg->size, 8)); str_to_buf(args[1], strlen(args[1]), buf, reg->size, 0); struct reg_arch_type *arch_type = register_get_arch_type(reg->arch_type); diff --git a/src/target/target_request.c b/src/target/target_request.c index 72151555..be176ca3 100644 --- a/src/target/target_request.c +++ b/src/target/target_request.c @@ -40,10 +40,10 @@ static int charmsg_mode = 0; static int target_asciimsg(struct target *target, uint32_t length) { - char *msg = malloc(CEIL(length + 1, 4) * 4); + char *msg = malloc(DIV_ROUND_UP(length + 1, 4) * 4); struct debug_msg_receiver *c = target->dbgmsg; - target->type->target_request_data(target, CEIL(length, 4), (uint8_t*)msg); + target->type->target_request_data(target, DIV_ROUND_UP(length, 4), (uint8_t*)msg); msg[length] = 0; LOG_DEBUG("%s", msg); @@ -66,7 +66,7 @@ static int target_charmsg(struct target *target, uint8_t msg) static int target_hexmsg(struct target *target, int size, uint32_t length) { - uint8_t *data = malloc(CEIL(length * size, 4) * 4); + uint8_t *data = malloc(DIV_ROUND_UP(length * size, 4) * 4); char line[128]; int line_len; struct debug_msg_receiver *c = target->dbgmsg; @@ -74,7 +74,7 @@ static int target_hexmsg(struct target *target, int size, uint32_t length) LOG_DEBUG("size: %i, length: %i", (int)size, (int)length); - target->type->target_request_data(target, CEIL(length * size, 4), (uint8_t*)data); + target->type->target_request_data(target, DIV_ROUND_UP(length * size, 4), (uint8_t*)data); line_len = 0; for (i = 0; i < length; i++) diff --git a/src/xsvf/xsvf.c b/src/xsvf/xsvf.c index 3fe2c0fd..2e78447a 100644 --- a/src/xsvf/xsvf.c +++ b/src/xsvf/xsvf.c @@ -479,7 +479,7 @@ COMMAND_HANDLER(handle_xsvf_command) field.tap = tap; field.num_bits = xsdrsize; field.out_value = dr_out_buf; - field.in_value = calloc(CEIL(field.num_bits, 8), 1); + field.in_value = calloc(DIV_ROUND_UP(field.num_bits, 8), 1); if (tap == NULL) jtag_add_plain_dr_scan(1, &field, jtag_set_end_state(TAP_DRPAUSE)); @@ -933,7 +933,7 @@ COMMAND_HANDLER(handle_xsvf_command) field.tap = tap; field.num_bits = xsdrsize; field.out_value = dr_out_buf; - field.in_value = calloc(CEIL(field.num_bits, 8), 1); + field.in_value = calloc(DIV_ROUND_UP(field.num_bits, 8), 1); if (attempt > 0 && verbose) LOG_USER("LSDR retry %d", attempt); |