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);
/* 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;
{
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;
}
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;
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);
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);
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");
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);
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;
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];
}
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];
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)
{
(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
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;
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,
/* 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;
/* 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);
{
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;
}
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 */
}
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++;
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;
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;
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;
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;
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;
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)
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)
#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>-------------------------------------------------*/
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);
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++;
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;
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++)
{
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);
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)
{
}
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 */
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);
}
/* 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 */
{
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;
}
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;
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;
/* 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);
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);
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;
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++)
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));
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);