rename CEIL as DIV_ROUND_UP
authorZachary T Welch <zw@superlucidity.net>
Mon, 16 Nov 2009 10:53:57 +0000 (02:53 -0800)
committerZachary T Welch <zw@superlucidity.net>
Mon, 16 Nov 2009 17:58:11 +0000 (09:58 -0800)
Improves the name of this macro, moves it to types.h, and adds a block
of Doxygen comments to describe what it does.

19 files changed:
src/flash/at91sam7.c
src/flash/lpc2000.c
src/flash/str9xpec.c
src/helper/binarybuffer.c
src/helper/binarybuffer.h
src/helper/types.h
src/jtag/commands.c
src/jtag/core.c
src/jtag/driver.c
src/jtag/ft2232.c
src/jtag/jtag.h
src/jtag/tcl.c
src/pld/virtex2.c
src/server/gdb_server.c
src/target/algorithm.c
src/target/etb.c
src/target/target.c
src/target/target_request.c
src/xsvf/xsvf.c

index e0b83d5722ea8f56a49267a3d097cb8d8702e983..9d05d7b5847d4b356463d92a386115186c3e19c1 100644 (file)
@@ -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;
index 79f580458f4b5780c759cdf7f61ab42f598bf138..a3f97180ff9a93e3893c9720ed38794bf5a22a4b 100644 (file)
@@ -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;
        }
 
index 4bf5bcaec49c12625af577143f50788c7460bc84..7f6d8bed71f4f2c8190b4398eacf8bc3e7203885 100644 (file)
@@ -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);
 
index 53ad4d395da899ea33de8d40a27c7777749cc070..081cc037ebd6c346ae2b360124f81f463914a99c 100644 (file)
@@ -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];
index 9e0cc9b72c9774edec4f73dab214b9104e6d1110..460d0178ad17a1ef8e9176e47818d81f7320508e 100644 (file)
@@ -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)
 {
index a8753c5f149115c539e2e39d3eeb07256344f172..8f6283b57bdd8878a8c4b5dfddfb6e45568f6f17 100644 (file)
@@ -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
index ccd6d0f13fedb4b680789406a6bb742b27194441..4e8ce40f141f87a0e0d66a250456257f074e9953 100644 (file)
@@ -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,
index 1841dde9f4c311a3e5967b3511cdd063e798b41c..c8a76e885e550aa8d3a07a0bb25c926a99fef984 100644 (file)
@@ -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);
index 6469358d9bfc3ebe73013ca97bb73eea28b7cc1c..cadd88e8f400fc634cd3dbf24704be1c5306ddea 100644 (file)
@@ -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++;
index cee55e0cf933053c05623b3d4bb8bbcc39b58af2..7acdf1a04802c97f6c2ffcb535d2eae67103d796 100644 (file)
@@ -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)
index 30d62fd92791c5c96685a32ef9dced21c32090a4..5328ff81861e4d9ac918d81c6518e6e9e9c96dc1 100644 (file)
@@ -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>-------------------------------------------------*/
 
index 75732ef0d786d73a589acc63c3084fb4cf89b06d..71e7bd5a7505663170b2850ad407543b0efa1c5b 100644 (file)
@@ -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++;
index ea9ee0cec5b51e99b90c328bf41e22f2b2f3c4b1..c07931e73603d6b18a6142f7c3d5f0eae1b0ead7 100644 (file)
@@ -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;
 
index f6b44cd298911225eea2cc08ae3aa3996ee8906b..55ec7d4e1be3b2c8febf9ca5eaa81e4b7dbf883f 100644 (file)
@@ -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 */
 
index 7643e3cb0391fd40f071c3a193bc1bc5e19b752b..76cf48bc589ffec25651ea9d56017518ae3d609a 100644 (file)
@@ -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;
 }
 
index 72474cd09f8faaeff120e8b87e1996a9aa5d6eae..21c375c35a1d28a35275710251116f016fb36178 100644 (file)
@@ -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;
index f5a092a707ed1b5e764a9531a72b17524abbf6f7..c24085f142a0f116e6f905c6f8789a4e096b2347 100644 (file)
@@ -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);
index 721515552c9d0463c18b21d3052254caa85cc668..be176ca3e4b22516fabb5760226ef7e533efb3d8 100644 (file)
@@ -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++)
index 3fe2c0fd5317ba0393ec478904daaf573827a361..2e78447acc148b7c5072c1c0d1bd1f8ec7e536d2 100644 (file)
@@ -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);