static int get_malloc_bytes( int num_bases )
{
	int num_bytes = get_num_bytes(num_bases);
	int remainder = num_bytes % sizeof(short);
	if(remainder!=0) {
		num_bytes += sizeof(short) - remainder;
	}
	return num_bytes;
}
Пример #2
0
static int fusb302_tcpm_get_message(int port, uint32_t *payload, int *head)
{
	/*
	 * this is the buffer that will get the burst-read data
	 * from the fusb302.
	 *
	 * it's re-used in a couple different spots, the worst of which
	 * is the PD packet (not header) and CRC.
	 * maximum size necessary = 28 + 4 = 32
	 */
	uint8_t buf[32];
	int rv = 0;
	int len;

	/* NOTE: Assuming enough memory has been allocated for payload. */

	/*
	 * PART 1 OF BURST READ: Write in register address.
	 * Issue a START, no STOP.
	 */
	tcpc_lock(port, 1);
	buf[0] = TCPC_REG_FIFOS;
	rv |= tcpc_xfer(port, buf, 1, 0, 0, I2C_XFER_START);

	/*
	 * PART 2 OF BURST READ: Read up to the header.
	 * Issue a repeated START, no STOP.
	 * only grab three bytes so we can get the header
	 * and determine how many more bytes we need to read.
	 */
	rv |= tcpc_xfer(port, 0, 0, buf, 3, I2C_XFER_START);

	/* Grab the header */
	*head = (buf[1] & 0xFF);
	*head |= ((buf[2] << 8) & 0xFF00);

	/* figure out packet length, subtract header bytes */
	len = get_num_bytes(*head) - 2;

	/*
	 * PART 3 OF BURST READ: Read everything else.
	 * No START, but do issue a STOP at the end.
	 * add 4 to len to read CRC out
	 */
	rv |= tcpc_xfer(port, 0, 0, buf, len+4, I2C_XFER_STOP);

	tcpc_lock(port, 0);

	/* return the data */
	memcpy(payload, buf, len);

	return rv;
}
Пример #3
0
static int fusb302_send_message(int port, uint16_t header, const uint32_t *data,
				 uint8_t *buf, int buf_pos)
{
	int rv;
	int reg;
	int len;

	len = get_num_bytes(header);

	/*
	 * packsym tells the TXFIFO that the next X bytes are payload,
	 * and should not be interpreted as special tokens.
	 * The 5 LSBs represent X, the number of bytes.
	 */
	reg = FUSB302_TKN_PACKSYM;
	reg |= (len & 0x1F);

	buf[buf_pos++] = reg;

	/* write in the header */
	reg = header;
	buf[buf_pos++] = reg & 0xFF;

	reg >>= 8;
	buf[buf_pos++] = reg & 0xFF;

	/* header is done, subtract from length to make this for-loop simpler */
	len -= 2;

	/* write data objects, if present */
	memcpy(&buf[buf_pos], data, len);
	buf_pos += len;

	/* put in the CRC */
	buf[buf_pos++] = FUSB302_TKN_JAMCRC;

	/* put in EOP */
	buf[buf_pos++] = FUSB302_TKN_EOP;

	/* Turn transmitter off after sending message */
	buf[buf_pos++] = FUSB302_TKN_TXOFF;

	/* Start transmission */
	reg = FUSB302_TKN_TXON;
	buf[buf_pos++] = FUSB302_TKN_TXON;

	/* burst write for speed! */
	tcpc_lock(port, 1);
	rv = tcpc_xfer(port, buf, buf_pos, 0, 0, I2C_XFER_SINGLE);
	tcpc_lock(port, 0);

	return rv;
}
void cseq_write( FILE * file, struct cseq *c )
{
	if(!c) {
		// special case: null pointer indicates the end of a list.
		fprintf(file,">>\n");
	} else {
		int num_bytes = get_num_bytes(c->num_bases);
		fprintf(file, ">%s %d %d %s\n", c->name, c->num_bases, num_bytes, c->metadata);
		fwrite(c->data,1,num_bytes,file);
		fputc('\n',file);
	}
}
Пример #5
0
void Array::allocate(cl_vars_t clv)
{
  size_t dim0 = MYMAX(get_property_int("dim0"), 1);
  size_t dim1 = MYMAX(get_property_int("dim1"), 1);
  bytes_per_element = get_num_bytes(properties["dtype"]);
  nbytes = dim0 * dim1 * bytes_per_element;
#ifdef VERBOSE_COMPILATION
  docs.compilation_ss << "Allocating: " << nbytes << "\tFor array: " << properties["name"] << std::endl; 
#endif
  cpu_data = (char *) calloc(nbytes, sizeof(char));
  for(int i = 0 ; i < clv.num_devices ; i++)
  {
    cl_int err;
    gpu_data[i] = clCreateBuffer(clv.context, CL_MEM_READ_WRITE, nbytes, NULL, &err);
    CHK_ERR(err);
  }
}
int cseq_sprint( char *buf, struct cseq *c, const char *extra_data )
{
	int total = 0;

	if(!c) {
		// special case: null pointer indicates the end of a list.
		total += sprintf(buf,">>\n");
	} else {
		int num_bytes = get_num_bytes(c->num_bases);

		total += sprintf(buf, ">%s %d %d %s %s\n", c->name, c->num_bases, num_bytes, c->metadata, extra_data);
		buf += total;

		memcpy(buf,c->data,num_bytes);
		buf += num_bytes;
		total += num_bytes;

		strcpy(buf,"\n");
		buf += 1;
		total += 1;
	}

	return total;
}
Пример #7
0
 // Print some info.
 virtual void print_info(const std::string& name, std::ostream& os = std::cout) {
     os << "grid '" << name << "' allocated at " << _elems << " in " <<
         printWithPow2Multiplier(get_num_bytes()) << " byte(s): " <<
         printWithPow2Multiplier(get_num_elems()) << " element(s) * " <<
         sizeof(T) << " byte(s)." << std::endl;
 }
size_t cseq_size( struct cseq *c)
{
	return get_num_bytes(c->num_bases) + 100;
}