/*
	Receives the pitch and roll from the transmitter and parses the packet for the angles
	Input:
	float* pitch, float* roll  = pointers to the angles
	uint8_t* ctrl2 = pointer to the control value so that we can update it.
*/
uint16_t receive_pitchroll(float* pitch, float* roll, uint8_t* ctrl2) {
  // assume already in RX
    // Wait for a transmisson to be read. When this happens, the CC2500 will move to the idle state
    wait_for_idle();
    
    // Determine number of bytes to read
    uint8_t bytesToRead;
    CC2500_Read(&bytesToRead, CC2500_RXBYTES,1);
    bytesToRead = bytesToRead & 0x7F;
      
    uint8_t buffer[bytesToRead];
    CC2500_Read(&buffer[0], CC2500_FIFOADDR, bytesToRead); 
    bytesToRead -= 2;
    
    //printf("Data: %x %x %x %x %x %x %x %x %x %x \n ",buffer[0],buffer[1],buffer[2],buffer[3],
    //  buffer[4],buffer[5],buffer[6],buffer[7],buffer[8],buffer[9]);
    
    packet_t *pkt_pnt = (packet_t *) &buffer[0]; 
    *pitch = pkt_pnt->f1;
    *roll = pkt_pnt->f2;
    uint8_t ctrl1 = pkt_pnt->b1;
    *ctrl2 = pkt_pnt->b2;
    
    // Exract data
    //*pitch = buffer[0]; 
    //*roll = (float) buffer[4]; 
    uint16_t ctrl  = buffer[8];
    //printf("   Pitch: %f Roll: %f \n",pkt_pnt->f1,pkt_pnt->f2); 
  
    // Move back to recieve state 
    CC2500_CommandProbe(CC2500_READBIT, CC2500_SRX);
    return ctrl; 
}
Esempio n. 2
0
static int rockchip_spi_pio_transfer(struct rockchip_spi *rs)
{
	int remain = 0;

	do {
		if (rs->tx) {
			remain = rs->tx_end - rs->tx;
			rockchip_spi_pio_writer(rs);
		}

		if (rs->rx) {
			remain = rs->rx_end - rs->rx;
			rockchip_spi_pio_reader(rs);
		}

		cpu_relax();
	} while (remain);

	/* If tx, wait until the FIFO data completely. */
	if (rs->tx)
		wait_for_idle(rs);

	spi_enable_chip(rs, 0);

	return 0;
}
/*
	Receive Keypad variables.
	uint8_t *ctrl = pointer to control value 
	float *value	= pointer to the value you are expecting in the keypad sequence, i.e. pitch,roll,time
	
*/
void receive_keypad(uint8_t *ctrl, float *value) {
    wait_for_idle();
  
    // Determine number of bytes to read
    uint8_t bytesToRead;
    CC2500_Read(&bytesToRead, CC2500_RXBYTES,1);
    bytesToRead = bytesToRead & 0x7F;
      
    uint8_t buffer[bytesToRead];
    CC2500_Read(&buffer[0], CC2500_FIFOADDR, bytesToRead); 
    bytesToRead -= 2;
    
    
    packet_t *pkt_pnt = (packet_t *) &buffer[0]; 
    *value = pkt_pnt->f1;
    *ctrl = pkt_pnt->b1;
    //uint8_t ctrl2 = pkt_pnt->b2;
    
    // Exract data
    //*pitch = buffer[0]; 
    //*roll = (float) buffer[4]; 
    //uint16_t ctrl  = buffer[8];
    //printf("   Pitch: %f Roll: %f \n",pkt_pnt->f1,pkt_pnt->f2); 
  
    // Move back to recieve state 
    CC2500_CommandProbe(CC2500_READBIT, CC2500_SRX);

}
Esempio n. 4
0
void riva_setup_accel(struct rivafb_info *rinfo)
{
	RIVA_FIFO_FREE(rinfo->riva, Clip, 2);
	rinfo->riva.Clip->TopLeft     = 0x0;
	rinfo->riva.Clip->WidthHeight = 0x80008000;
	riva_setup_ROP(rinfo);
	wait_for_idle(rinfo);
}
Esempio n. 5
0
/*
    In most cases this will not totally flush the queue, as when streaming
    gcode there is one stalled waiting for space in the queue, in
    queue_head_block() so after this flush, once main_loop runs again one more
    gcode gets stuck in the queue, this is bad. Current work around is to call
    this when the queue in not full and streaming has stopped
*/
void Conveyor::flush_queue()
{
    allow_fetch = false;
    flush= true;

    // TODO force deceleration of last block

    // now wait until the block queue has been flushed
    wait_for_idle(false);

    flush= false;
}
Esempio n. 6
0
/** \brief Read bytes over I2C-Bus from a slave. This function tries only one
 *         time to transmit data. In case of an error (abort) error code is
 *         returned. Retransmission has to be done from caller!
 * @param bus  Number of the I2C-controller to use (0...6)
 * @param chip 7 Bit of the slave address on I2C bus
 * @param addr Address inside slave where to read from
 * @param *buf Pointer to the buffer where to store read data
 * @param len  Number of bytes to read
 * @return     I2C_SUCCESS when read was successful, otherwise error code
 */
int i2c_read(unsigned bus, unsigned chip, unsigned addr,
			uint8_t *buf, unsigned len)
{
	int i = 0;
	char *base_ptr = NULL;
	device_t dev;
	unsigned int val;
	int stat;

	/* Get base address of desired I2C-controller */
	dev = dev_find_slot(0, PCI_DEVFN(I2C1_DEV, bus + 1));
	base_ptr = (char *)pci_read_config32(dev, PCI_BASE_ADDRESS_0);
	if (base_ptr == NULL) {
		printk(BIOS_INFO, "I2C: Invalid Base address\n");
		return I2C_ERR_INVALID_ADR;
	}

	/* Ensure I2C controller is not active before setting slave address */
	stat = wait_for_idle(base_ptr);
	if (stat != I2C_SUCCESS)
		return stat;

	/* clear any abort status from a previous transaction */
	read32(base_ptr + I2C_CLR_TX_ABRT);

	/* Now we can program the desired slave address and start transfer */
	write32(base_ptr + I2C_TARGET_ADR, chip & 0xff);
	/* Send address inside slave to read from */
	write32(base_ptr + I2C_DATA_CMD, addr & 0xff);

	/* For the next byte we need a repeated start condition */
	val = I2C_RW_CMD | I2C_RESTART;
	/* Now we can read desired amount of data over I2C */
	for (i = 0; i < len; i++) {
		/* A read is initiated by writing dummy data to the DATA-register */
		write32(base_ptr + I2C_DATA_CMD, val);
		stat = wait_rx_fifo(base_ptr);
		if (stat)
			return stat;
		buf[i] = read32(base_ptr + I2C_DATA_CMD) & 0xff;
		val = I2C_RW_CMD;
		if (i == (len - 2)) {
			/* For the last byte we need a stop condition to be generated */
			val |= I2C_STOP;
		}
	}
	return I2C_SUCCESS;
}
Esempio n. 7
0
static void rockchip_spi_dma_txcb(void *data)
{
	unsigned long flags;
	struct rockchip_spi *rs = data;

	/* Wait until the FIFO data completely. */
	wait_for_idle(rs);

	spin_lock_irqsave(&rs->lock, flags);

	rs->state &= ~TXBUSY;
	if (!(rs->state & RXBUSY))
		spi_finalize_current_transfer(rs->master);

	spin_unlock_irqrestore(&rs->lock, flags);
}
Esempio n. 8
0
/** \brief Write bytes over I2C-Bus from a slave. This function tries only one
 *         time to transmit data. In case of an error (abort) error code is
 *         returned. Retransmission has to be done from caller!
 * @param bus  Number of the I2C-controller to use (0...6)
 * @param chip 7 Bit of the slave address on I2C bus
 * @param addr Address inside slave where to write to
 * @param *buf Pointer to the buffer where data to write is stored
 * @param len  Number of bytes to write
 * @return     I2C_SUCCESS when read was successful, otherwise error code
 */
int i2c_write(unsigned bus, unsigned chip, unsigned addr,
			const uint8_t *buf, unsigned len)
{
	int i;
	char *base_ptr;
	device_t dev;
	unsigned int val;
	int stat;

	/* Get base address of desired I2C-controller */
	dev = dev_find_slot(0, PCI_DEVFN(I2C1_DEV, bus + 1));
	base_ptr = (char *)pci_read_config32(dev, PCI_BASE_ADDRESS_0);
	if (base_ptr == NULL) {
		return I2C_ERR_INVALID_ADR;
	}

	/* Ensure I2C controller is not active yet */
	stat = wait_for_idle(base_ptr);
	if (stat) {
		return stat;
	}

	/* clear any abort status from a previous transaction */
	read32(base_ptr + I2C_CLR_TX_ABRT);

	/* Program slave address to use for this transfer */
	write32(base_ptr + I2C_TARGET_ADR, chip & 0xff);

	/* Send address inside slave to write data to */
	write32(base_ptr + I2C_DATA_CMD, addr & 0xff);

	for (i = 0; i < len; i++) {
		val = (unsigned int)(buf[i] & 0xff);	/* Take only 8 bits */
		if (i == (len - 1)) {
			/* For the last byte we need a stop condition */
			val |= I2C_STOP;
		}
		stat = wait_tx_fifo(base_ptr);
		if (stat) {
			return stat;
		}
		write32(base_ptr + I2C_DATA_CMD, val);
	}
	return I2C_SUCCESS;
}
/*
	Receives a sequence of angles from the transmitter
	Input:
	float *pitchBuffer, float *rollBuffer = pointers to the buffers that will store the sequence
	float *time_interval = pointer to the variable which indicates how long the time interval the sequnce
		should execute in.
*/
void receive_record_sequence(float *pitchBuffer, float *rollBuffer, float *time_interval) {
		uint8_t ctrl1 = PACKET_CTRL1_RECORD_PKT;
		uint8_t index;
		packet_t pkt;
	
		while (ctrl1 != PACKET_CTRL1_RECORD_END) {
			wait_for_idle();
			read_packet(&pkt);
      ctrl1 = pkt.b1;
			if (ctrl1 == PACKET_CTRL1_RECORD_PKT) {
        pitchBuffer[pkt.b2] = pkt.f1;
        rollBuffer[pkt.b2] = pkt.f2;
        
      
        printf("Recieved recorded data pkt %i \n", pkt.b2);
      }
		}
}
Esempio n. 10
0
static void fbcon_riva_bmove(struct display *p, int sy, int sx, int dy, int dx,
			    int height, int width)
{
	struct rivafb_info *rinfo = (struct rivafb_info *)(p->fb_info);

	sx *= fontwidth(p);
	sy *= fontheight(p);
	dx *= fontwidth(p);
	dy *= fontheight(p);
	width *= fontwidth(p);
	height *= fontheight(p);

	RIVA_FIFO_FREE(rinfo->riva, Blt, 3);
	rinfo->riva.Blt->TopLeftSrc  = (sy << 16) | sx;
	rinfo->riva.Blt->TopLeftDst  = (dy << 16) | dx;
	rinfo->riva.Blt->WidthHeight = (height  << 16) | width;

	wait_for_idle(rinfo);
}
Esempio n. 11
0
void aty_init_engine(struct atyfb_par *par, struct fb_info *info)
{
	u32 pitch_value;
	u32 vxres;

	/* determine modal information from global mode structure */
	pitch_value = info->fix.line_length / (info->var.bits_per_pixel / 8);
	vxres = info->var.xres_virtual;

	if (info->var.bits_per_pixel == 24) {
		/* In 24 bpp, the engine is in 8 bpp - this requires that all */
		/* horizontal coordinates and widths must be adjusted */
		pitch_value *= 3;
		vxres *= 3;
	}

	/* On GTC (RagePro), we need to reset the 3D engine before */
	if (M64_HAS(RESET_3D))
		reset_GTC_3D_engine(par);

	/* Reset engine, enable, and clear any engine errors */
	aty_reset_engine(par);
	/* Ensure that vga page pointers are set to zero - the upper */
	/* page pointers are set to 1 to handle overflows in the */
	/* lower page */
	aty_st_le32(MEM_VGA_WP_SEL, 0x00010000, par);
	aty_st_le32(MEM_VGA_RP_SEL, 0x00010000, par);

	/* ---- Setup standard engine context ---- */

	/* All GUI registers here are FIFOed - therefore, wait for */
	/* the appropriate number of empty FIFO entries */
	wait_for_fifo(14, par);

	/* enable all registers to be loaded for context loads */
	aty_st_le32(CONTEXT_MASK, 0xFFFFFFFF, par);

	/* set destination pitch to modal pitch, set offset to zero */
	aty_st_le32(DST_OFF_PITCH, (pitch_value / 8) << 22, par);

	/* zero these registers (set them to a known state) */
	aty_st_le32(DST_Y_X, 0, par);
	aty_st_le32(DST_HEIGHT, 0, par);
	aty_st_le32(DST_BRES_ERR, 0, par);
	aty_st_le32(DST_BRES_INC, 0, par);
	aty_st_le32(DST_BRES_DEC, 0, par);

	/* set destination drawing attributes */
	aty_st_le32(DST_CNTL, DST_LAST_PEL | DST_Y_TOP_TO_BOTTOM |
		    DST_X_LEFT_TO_RIGHT, par);

	/* set source pitch to modal pitch, set offset to zero */
	aty_st_le32(SRC_OFF_PITCH, (pitch_value / 8) << 22, par);

	/* set these registers to a known state */
	aty_st_le32(SRC_Y_X, 0, par);
	aty_st_le32(SRC_HEIGHT1_WIDTH1, 1, par);
	aty_st_le32(SRC_Y_X_START, 0, par);
	aty_st_le32(SRC_HEIGHT2_WIDTH2, 1, par);

	/* set source pixel retrieving attributes */
	aty_st_le32(SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT, par);

	/* set host attributes */
	wait_for_fifo(13, par);
	aty_st_le32(HOST_CNTL, 0, par);

	/* set pattern attributes */
	aty_st_le32(PAT_REG0, 0, par);
	aty_st_le32(PAT_REG1, 0, par);
	aty_st_le32(PAT_CNTL, 0, par);

	/* set scissors to modal size */
	aty_st_le32(SC_LEFT, 0, par);
	aty_st_le32(SC_TOP, 0, par);
	aty_st_le32(SC_BOTTOM, par->crtc.vyres - 1, par);
	aty_st_le32(SC_RIGHT, vxres - 1, par);

	/* set background color to minimum value (usually BLACK) */
	aty_st_le32(DP_BKGD_CLR, 0, par);

	/* set foreground color to maximum value (usually WHITE) */
	aty_st_le32(DP_FRGD_CLR, 0xFFFFFFFF, par);

	/* set write mask to effect all pixel bits */
	aty_st_le32(DP_WRITE_MASK, 0xFFFFFFFF, par);

	/* set foreground mix to overpaint and background mix to */
	/* no-effect */
	aty_st_le32(DP_MIX, FRGD_MIX_S | BKGD_MIX_D, par);

	/* set primary source pixel channel to foreground color */
	/* register */
	aty_st_le32(DP_SRC, FRGD_SRC_FRGD_CLR, par);

	/* set compare functionality to false (no-effect on */
	/* destination) */
	wait_for_fifo(3, par);
	aty_st_le32(CLR_CMP_CLR, 0, par);
	aty_st_le32(CLR_CMP_MASK, 0xFFFFFFFF, par);
	aty_st_le32(CLR_CMP_CNTL, 0, par);

	/* set pixel depth */
	wait_for_fifo(2, par);
	aty_st_le32(DP_PIX_WIDTH, par->crtc.dp_pix_width, par);
	aty_st_le32(DP_CHAIN_MASK, par->crtc.dp_chain_mask, par);

	wait_for_fifo(5, par);
 	aty_st_le32(SCALE_3D_CNTL, 0, par);
	aty_st_le32(Z_CNTL, 0, par);
	aty_st_le32(CRTC_INT_CNTL, aty_ld_le32(CRTC_INT_CNTL, par) & ~0x20,
		    par);
	aty_st_le32(GUI_TRAJ_CNTL, 0x100023, par);

	/* insure engine is idle before leaving */
	wait_for_idle(par);
}
Esempio n. 12
0
static int __igt_reset_engine(struct drm_i915_private *i915, bool active)
{
	struct intel_engine_cs *engine;
	enum intel_engine_id id;
	struct hang h;
	int err = 0;

	/* Check that we can issue an engine reset on an idle engine (no-op) */

	if (!intel_has_reset_engine(i915))
		return 0;

	if (active) {
		mutex_lock(&i915->drm.struct_mutex);
		err = hang_init(&h, i915);
		mutex_unlock(&i915->drm.struct_mutex);
		if (err)
			return err;
	}

	for_each_engine(engine, i915, id) {
		unsigned int reset_count, reset_engine_count;
		IGT_TIMEOUT(end_time);

		if (active && !intel_engine_can_store_dword(engine))
			continue;

		if (!wait_for_idle(engine)) {
			pr_err("%s failed to idle before reset\n",
			       engine->name);
			err = -EIO;
			break;
		}

		reset_count = i915_reset_count(&i915->gpu_error);
		reset_engine_count = i915_reset_engine_count(&i915->gpu_error,
							     engine);

		set_bit(I915_RESET_ENGINE + id, &i915->gpu_error.flags);
		do {
			u32 seqno = intel_engine_get_seqno(engine);

			if (active) {
				struct i915_request *rq;

				mutex_lock(&i915->drm.struct_mutex);
				rq = hang_create_request(&h, engine);
				if (IS_ERR(rq)) {
					err = PTR_ERR(rq);
					mutex_unlock(&i915->drm.struct_mutex);
					break;
				}

				i915_request_get(rq);
				i915_request_add(rq);
				mutex_unlock(&i915->drm.struct_mutex);

				if (!wait_until_running(&h, rq)) {
					struct drm_printer p = drm_info_printer(i915->drm.dev);

					pr_err("%s: Failed to start request %x, at %x\n",
					       __func__, rq->fence.seqno, hws_seqno(&h, rq));
					intel_engine_dump(engine, &p,
							  "%s\n", engine->name);

					i915_request_put(rq);
					err = -EIO;
					break;
				}

				GEM_BUG_ON(!rq->global_seqno);
				seqno = rq->global_seqno - 1;
				i915_request_put(rq);
			}

			err = i915_reset_engine(engine, NULL);
			if (err) {
				pr_err("i915_reset_engine failed\n");
				break;
			}

			if (i915_reset_count(&i915->gpu_error) != reset_count) {
				pr_err("Full GPU reset recorded! (engine reset expected)\n");
				err = -EINVAL;
				break;
			}

			reset_engine_count += active;
			if (i915_reset_engine_count(&i915->gpu_error, engine) !=
			    reset_engine_count) {
				pr_err("%s engine reset %srecorded!\n",
				       engine->name, active ? "not " : "");
				err = -EINVAL;
				break;
			}

			if (!wait_for_idle(engine)) {
				struct drm_printer p =
					drm_info_printer(i915->drm.dev);

				pr_err("%s failed to idle after reset\n",
				       engine->name);
				intel_engine_dump(engine, &p,
						  "%s\n", engine->name);

				err = -EIO;
				break;
			}
		} while (time_before(jiffies, end_time));
		clear_bit(I915_RESET_ENGINE + id, &i915->gpu_error.flags);

		if (err)
			break;

		err = igt_flush_test(i915, 0);
		if (err)
			break;
	}
void aty_init_engine(struct atyfb_par *par, struct fb_info *info)
{
	u32 pitch_value;
	u32 vxres;

	
	pitch_value = info->fix.line_length / (info->var.bits_per_pixel / 8);
	vxres = info->var.xres_virtual;

	if (info->var.bits_per_pixel == 24) {
		
		
		pitch_value *= 3;
		vxres *= 3;
	}

	
	if (M64_HAS(RESET_3D))
		reset_GTC_3D_engine(par);

	
	aty_reset_engine(par);
	
	
	
	aty_st_le32(MEM_VGA_WP_SEL, 0x00010000, par);
	aty_st_le32(MEM_VGA_RP_SEL, 0x00010000, par);

	

	
	
	wait_for_fifo(14, par);

	
	aty_st_le32(CONTEXT_MASK, 0xFFFFFFFF, par);

	
	aty_st_le32(DST_OFF_PITCH, (pitch_value / 8) << 22, par);

	
	aty_st_le32(DST_Y_X, 0, par);
	aty_st_le32(DST_HEIGHT, 0, par);
	aty_st_le32(DST_BRES_ERR, 0, par);
	aty_st_le32(DST_BRES_INC, 0, par);
	aty_st_le32(DST_BRES_DEC, 0, par);

	
	aty_st_le32(DST_CNTL, DST_LAST_PEL | DST_Y_TOP_TO_BOTTOM |
		    DST_X_LEFT_TO_RIGHT, par);

	
	aty_st_le32(SRC_OFF_PITCH, (pitch_value / 8) << 22, par);

	
	aty_st_le32(SRC_Y_X, 0, par);
	aty_st_le32(SRC_HEIGHT1_WIDTH1, 1, par);
	aty_st_le32(SRC_Y_X_START, 0, par);
	aty_st_le32(SRC_HEIGHT2_WIDTH2, 1, par);

	
	aty_st_le32(SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT, par);

	
	wait_for_fifo(13, par);
	aty_st_le32(HOST_CNTL, 0, par);

	
	aty_st_le32(PAT_REG0, 0, par);
	aty_st_le32(PAT_REG1, 0, par);
	aty_st_le32(PAT_CNTL, 0, par);

	
	aty_st_le32(SC_LEFT, 0, par);
	aty_st_le32(SC_TOP, 0, par);
	aty_st_le32(SC_BOTTOM, par->crtc.vyres - 1, par);
	aty_st_le32(SC_RIGHT, vxres - 1, par);

	
	aty_st_le32(DP_BKGD_CLR, 0, par);

	
	aty_st_le32(DP_FRGD_CLR, 0xFFFFFFFF, par);

	
	aty_st_le32(DP_WRITE_MASK, 0xFFFFFFFF, par);

	
	
	aty_st_le32(DP_MIX, FRGD_MIX_S | BKGD_MIX_D, par);

	
	
	aty_st_le32(DP_SRC, FRGD_SRC_FRGD_CLR, par);

	
	
	wait_for_fifo(3, par);
	aty_st_le32(CLR_CMP_CLR, 0, par);
	aty_st_le32(CLR_CMP_MASK, 0xFFFFFFFF, par);
	aty_st_le32(CLR_CMP_CNTL, 0, par);

	
	wait_for_fifo(2, par);
	aty_st_le32(DP_PIX_WIDTH, par->crtc.dp_pix_width, par);
	aty_st_le32(DP_CHAIN_MASK, par->crtc.dp_chain_mask, par);

	wait_for_fifo(5, par);
 	aty_st_le32(SCALE_3D_CNTL, 0, par);
	aty_st_le32(Z_CNTL, 0, par);
	aty_st_le32(CRTC_INT_CNTL, aty_ld_le32(CRTC_INT_CNTL, par) & ~0x20,
		    par);
	aty_st_le32(GUI_TRAJ_CNTL, 0x100023, par);

	
	wait_for_idle(par);
}
Esempio n. 14
0
int main(int argc, char** argv) {

    std::string read_file = "./test_reads.txt";
    //std::string kmer_file_name = "./test_kmers.txt";
    std::string kmer_file_name = "./solid_kmers.txt";
    std::ifstream input_file(read_file.c_str());
    std::ifstream kmer_file(kmer_file_name.c_str());
    std::string read_string;
    std::string line_id;
    std::string line_misc;
    std::string quality_string("IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII00000000000000000000000000000000IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII");
    std::string kmer_string;
    int32_t read_length=112;
    int32_t kmer_length=30;
    int32_t threshold;
    uint8_t level0;
    uint8_t level1;
    uint8_t level2;
    uint8_t level3;
    int num_reads_processed = 0;
    int num_reads_per_iteration = 512;
    int num_kmers_per_iteration = 512 * 4;

    char* kmer_space;
    uint32_t** correction_space;
    char* candidate_space;
    char* read_space;
    int32_t* index_space;
    struct correction_item* correction_array;


//First program solid k-mers into the bloom-filter
    if (posix_memalign((void**)&kmer_space, 128, num_kmers_per_iteration * 64) != 0) {
        std::cout << "ERROR!!!" << std::endl;
    }

    open_device((uint64_t) 0)
    uint32_t val;
    cxl_mmio_read32(afu_h,CONTROL,&val);
    std::cout << val << std::endl;
    cxl_mmio_read32(afu_h,THRESHOLD,&val);
    std::cout << val << std::endl;
    cxl_mmio_read32(afu_h,READ_BASE,&val);
    std::cout << val << std::endl;
    cxl_mmio_read32(afu_h,WRITE_BASE,&val);
    std::cout << val << std::endl;
    cxl_mmio_read32(afu_h,READS_RECEIVED,&val);
    std::cout << val << std::endl;
    cxl_mmio_read32(afu_h,READS_WRITTEN,&val);
    std::cout << val << std::endl;
    cxl_mmio_read32(afu_h,NUM_ITEMS,&val);
    std::cout << val << std::endl;
    cxl_mmio_read32(afu_h,START,&val);
    std::cout << val << std::endl;
    cxl_mmio_read32(afu_h,RESET,&val);
    std::cout << val << std::endl;
    cxl_mmio_read32(afu_h,STATUS,&val);
    std::cout << val << std::endl;
    cxl_mmio_read32(afu_h,DDR3_BASE,&val);
    std::cout << val << std::endl;
    wait_for_idle(afu_h);
    clear_status(afu_h);
    if (!kmer_file.is_open()) {
        std::cout << "Cannot open k-mer file!!!" << std::endl;
        return -1;
    }
    int32_t num_kmers = 0;
    while (std::getline(kmer_file, kmer_string)) {
        memcpy(kmer_space + (num_kmers % num_kmers_per_iteration) * 64, kmer_string.c_str(), kmer_length);
        num_kmers++;
        if (num_kmers % num_kmers_per_iteration == 0) {
            std::cout << "Completed collecting k-mers" << std::endl;
            set_kmer_program_mode(afu_h, num_kmers_per_iteration, kmer_length, kmer_space);
            Start;
#ifdef DEBUG
            FILE* debug = fopen("./debug", "w");
            for (int x = 0; x < num_kmers_per_iteration; x++) {
                char* kmerToPrint = kmer_space + x * 64;
                for (int y = 63; y > 0; y--) {
                    fprintf(debug,"%02x", kmerToPrint[y]);
                }
                fprintf(debug, "\n");
            }
#endif
            //Wait for IDLE
            bool success = wait_for_idle(afu_h);
            if (!success) {
                std::cout << "Cannot complete AFU transactions. Exiting!!!" << std::endl;
                return -1;
            }
            clear_status(afu_h);
            std::cout << "Completed iteration" << std::endl;
        }
    }

    if (num_kmers % num_kmers_per_iteration != 0) {
        std::cout << "The last set of k-mers going to be tested ... " << std::endl;
        int32_t num_remaining = num_kmers % num_kmers_per_iteration;
        set_kmer_program_mode(afu_h, num_remaining, kmer_length, kmer_space);
        Start;
        bool success = wait_for_idle(afu_h);
        if (!success) {
            std::cout << "Cannot complete AFU transactions. Exiting!!!" << std::endl;
            return -1;
        }
        clear_status(afu_h);
        std::cout << "Completed last iteration" << std::endl;
    }

////First convert each read to a correction item
//    if (!(input_file.is_open())) {
//        std::cout << "Cannot open input file" << std::endl;
//        return 1;
//    }
//
//    //256 bytes per read = 2 cache lines = 2048 bits
//    if (posix_memalign((void**)&read_space, 128, num_reads_per_iteration * 256) != 0) {
//        std::cout << "ERROR!!! Cannot allocate aligned space for read_space" << std::endl;
//    }
//
//    //256 bytes per packed index space = 2 cache lines = 2048 bits = 32 * 2 * (32 indices)
//    if (posix_memalign((void**)&index_space, 128, num_reads_per_iteration * 256) != 0) {
//        std::cout << "ERROR!!! Cannot allocate aligned space for read_space" << std::endl;
//    }
//    
//    while (std::getline(input_file, read_string)) {
//        if (!std::getline(input_file, read_string)) {
//            std::cout << "Error in file format" << std::endl;
//            return 1;
//        }
//        if (!std::getline(input_file, quality_string)) {
//            std::cout << "Error in file format" << std::endl;
//            return 1;
//        }
//        if (!std::getline(input_file, quality_string)) {
//            std::cout << "Error in file format" << std::endl;
//            return 1;
//        }
//
//        char* read_item = read_space + 256 * (num_reads_processed % num_reads_per_iteration);
//        memcpy(read_space + 256 * (num_reads_processed % num_reads_per_iteration), read_string.c_str(), read_length);
//        read_item[255] = read_length;
//        num_reads_processed++;
//
//        //Flatten out stuff - in case it is all to go back to C
//        //correction_array[num_reads_processed].read_string    = (uint32_t*) read_space[num_reads_processed*2];
//        //correction_array[num_reads_processed].quality_string = (uint32_t*) read_space[num_reads_processed*2+1];
//        //correction_array[num_reads_processed].read_length    = read_string.length();
//        //correction_array[num_reads_processed].island_indices = (int32_t*) index_space[num_reads_processed];
//        if (num_reads_processed % num_reads_per_iteration == 0) {
//            int32_t num_corrections = 0;
//            uint64_t wed = 0;
//
//            std::cout << "Reads processed, proceeding to procure island information ... " << std::endl;
//           
//            //1. Profile the reads
//            set_read_profile_mode(afu_h, num_reads_per_iteration, kmer_length, index_space, read_space);
//            Start;
//
//            bool success = wait_for_idle(afu_h);
//            if (!success) {
//                std::cout << "ERROR! Read profile doesn't complete!!!" << std::endl;
//            }
//            clear_status(afu_h);
//
//            //Print the indices
//            for (int m = 0; m < num_reads_per_iteration; m++) { 
//                int32_t* index_base = index_space + 32 * 2 * m;
//                std::cout << "For " << m << "-th read" << std::endl;
//                for (int n = 0; n < 32; n++) {
//                    int position = index_base[2*n];
//                    int length = index_base[2*n+1];
//                    //if ((position != -1) && (length != -1)) {
//                        std::cout << "(" << position << "," << length << ")" << std::endl;
//                    //} else {
//                      //  break;
//                    //}
//                }
//            }
//            
//            ////2. Adjust solid islands
//            ////adjust_solid_islands(index_space,num_reads_per_iteration);
//
//            ////3. Set correction types for each read and collect reads to be corrected in a particular space
//            //num_corrections = set_correction_types(correction_array, num_reads_per_iteration, candidate_space, correction_space);
//
//            ////4. Correct errors
//            //set_read_correct_mode(afu_h, num_reads_per_iteration, threshold, kmer_length, level0, level1, level2, level3, candidate_space, correction_space);
//            //Start;
//
//            ////5. Post process each correction, and then combine
//            ////post_process_corrections(correction_array, num_reads_per_iteration);
//            //
//            ////TBD 9: Write out results
//
//            //for (int k = 0; k < num_corrections; k++) {
//            //    delete[] correction_space[k];
//            //    for (int m = 0; m < 32; m++) {
//            //        delete[] candidate_space[32*k+m];
//            //    }
//            //}
//
//            //for (int k = 0; k < num_reads_per_iteration; k++) {
//            //    delete[] correction_array[k].candidates;
//            //    delete[] correction_array[k].start_position;
//            //    delete[] correction_array[k].end_position;
//            //}
//        }
//    }
//
//    if (num_reads_processed % num_reads_per_iteration != 0) {
//        int32_t num_corrections = 0;
//        uint64_t wed = 0;
//
//        std::cout << "Processing last read batch for island information ... " << std::endl;
//       
//        //1. Profile the reads
//        set_read_profile_mode(afu_h, num_reads_processed % num_reads_per_iteration, kmer_length, index_space, read_space);
//        Start;
//
//        bool success = wait_for_idle(afu_h);
//        if (!success) {
//            std::cout << "ERROR! Read profile doesn't complete!!!" << std::endl;
//        }
//        clear_status(afu_h);
//
//        for (int m = 0; m < num_reads_processed % num_reads_per_iteration; m++) { 
//            int32_t* index_base = index_space + 32 * 2 * m;
//            std::cout << "For " << m << "-th read" << std::endl;
//            for (int n = 0; n < 32; n++) {
//                int position = index_base[2*n];
//                int length = index_base[2*n+1];
//                //if ((position != -1) && (length != -1)) {
//                    std::cout << "(" << position << "," << length << ")" << std::endl;
//                //} else {
//                 //   break;
//                //}
//            }
//        }
//    }

    
//    open_device((uint64_t) 0)
//    clear_status(afu_h);
 
    std::ifstream test_file("./stimulus.txt");
    if (!test_file.is_open()) {
        std::cout << "ERROR!! Cannot open stimulus file" << std::endl;
    }

    if (posix_memalign((void**)&read_space, 128, num_reads_per_iteration * 256 *2) != 0) {
        std::cout << "ERROR!!!" << std::endl;
    }

    if (posix_memalign((void**)&candidate_space, 128, num_reads_per_iteration * 256 * 32) != 0) {
        std::cout << "ERROR!!!" << std::endl;
    }

    num_reads_processed = 0;
    char quality_string_c[113]; //= quality_string.c_str();
    memcpy(quality_string_c, quality_string.c_str(), read_length);
    for (int p = 40; p < 70; p++) {
        quality_string_c[p] = 0;
    }
    while (std::getline(test_file, read_string)) {
        uint32_t start_position, end_position;
        char read_string_c[113];
        sscanf(read_string.c_str(), "%s %d %d", read_string_c, &start_position, &end_position); read_string_c[read_length] = '\0';
        std::cout << "Read : " << read_string_c << " start: " << (char) start_position << " end: " << (char) end_position << std::endl;

        memcpy(read_space + 512 * (num_reads_processed % num_reads_per_iteration), read_string_c, read_length);
        memcpy(read_space + 512 * (num_reads_processed % num_reads_per_iteration) + 256, quality_string_c, read_length);

        char* read_item = read_space + 512 * (num_reads_processed % num_reads_per_iteration);
 
        read_item[255] = read_length;
        read_item[254] = start_position;
        read_item[253] = end_position;
       
        num_reads_processed++;

        if (num_reads_processed % num_reads_per_iteration == 0) {
            set_read_correct_mode(afu_h, num_reads_per_iteration, 1, kmer_length, 0, 20, 60, 80, candidate_space, read_space);
            Start;
            bool success = wait_for_idle(afu_h);
            if (!success) {
                std::cout << "ERROR! Read profile doesn't complete!!!" << std::endl;
                return -1;
            }
            clear_status(afu_h);

            for (int m = 0; m < num_reads_per_iteration; m++) {
                char* candidate_local_space = candidate_space + m * 256 * 32;
                char* read = read_space + m * 512; read[read_length] = '\0';
                int32_t num_candidates = (int32_t) candidate_local_space[255]; //The last byte of every read provides us with the number of candidates
                //std::cout << "Read " << read << " has " << num_candidates << " candidates" << std::endl;
                printf("Candidate for %s is at %lu\n", read, (uint64_t) candidate_local_space);
                printf("Read %s has %d candidates\n", read, num_candidates);
                for (int n = 0; n < num_candidates; n++) {
                    char* candidate = candidate_local_space + n * 256;
                    int32_t num_candidates_to_print = (int32_t) candidate[255];
                    candidate[read_length] = '\0';
                    //candidate[read_length] = '\0';
                    printf("Read:%s:%s:%d\n", read,candidate,num_candidates_to_print);
                }
                std::cout << "Completed printing candidates ... " << std::endl;
            }
        }
    }

    if (num_reads_processed % num_reads_per_iteration != 0) {
        std::cout << "Entering the final iteration" << std::endl;
        set_read_correct_mode(afu_h, num_reads_processed % num_reads_per_iteration, 1, kmer_length, 0, 20, 60, 80, candidate_space, read_space);
        Start;
        bool success = wait_for_idle(afu_h);
        if (!success) {
            std::cout << "ERROR! Read profile doesn't complete!!!" << std::endl;
            return -1;
        }
        clear_status(afu_h);

        for (int m = 0; m < num_reads_processed % num_reads_per_iteration; m++) {
            char* candidate_local_space = candidate_space + m * 256 * 32;
            char* read = read_space + m * 512; read[read_length] = '\0';
            int32_t num_candidates = (int32_t) candidate_local_space[255]; //The last byte of every read provides us with the number of candidates
            printf("Candidate for %s is at %lu\n", read, (uint64_t) candidate_local_space);
            printf("Read %s has %d candidates\n", read, num_candidates);
            for (int n = 0; n < num_candidates; n++) {
                char* candidate = candidate_local_space + n * 256; 
                int32_t num_candidates_to_print = (int32_t) candidate[255];
                candidate[read_length] = '\0';
                //std::cout << "Read " << read << ":" << candidate << ":" << num_candidates << std::endl;
                printf("Read:%s:%s:%d\n",read,candidate,num_candidates_to_print);
            }
            std::cout << "Completed printing candidates ... " << std::endl;
        }
    }

    close_device

    std::cout << "Closing program ... " << std::endl;
    return 0;
}
Esempio n. 15
0
static gboolean
test_button_folder_states_for_action (GtkFileChooserAction action, gboolean use_dialog, gboolean set_folder_on_dialog)
{
  gboolean passed;
  GtkWidget *window;
  GtkWidget *button;
  char *folder;
  GtkWidget *dialog;
  char *current_working_dir;
  gboolean must_have_cwd;

  passed = TRUE;

  current_working_dir = g_get_current_dir ();
  must_have_cwd = !(use_dialog && set_folder_on_dialog);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  if (use_dialog)
    {
      dialog = gtk_file_chooser_dialog_new ("Test", NULL, action,
					    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					    GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
					    NULL);
      button = gtk_file_chooser_button_new_with_dialog (dialog);

      if (set_folder_on_dialog)
	gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), g_get_home_dir ());
    }
  else
    {
      button = gtk_file_chooser_button_new ("Test", action);
      dialog = NULL; /* keep gcc happy */
    }

  gtk_container_add (GTK_CONTAINER (window), button);

  /* Pre-map; no folder is set */
  wait_for_idle ();

  folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button));
  if (must_have_cwd)
    passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
  else
    passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);

  log_test (passed, "test_button_folder_states_for_action(): %s, use_dialog=%d, set_folder_on_dialog=%d, pre-map, %s",
	    get_action_name (action),
	    use_dialog,
	    set_folder_on_dialog,
	    must_have_cwd ? "must have $cwd" : "must have explicit folder");

  /* Map; folder should be set */

  gtk_widget_show_all (window);
  gtk_widget_show_now (window);

  wait_for_idle ();

  folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button));

  if (must_have_cwd)
    passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
  else
    passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);

  log_test (passed, "test_button_folder_states_for_action(): %s, use_dialog=%d, set_folder_on_dialog=%d, mapped, %s",
	    get_action_name (action),
	    use_dialog,
	    set_folder_on_dialog,
	    must_have_cwd ? "must have $cwd" : "must have explicit folder");
  g_free (folder);

  /* Unmap; folder should be set */

  gtk_widget_hide (window);
  wait_for_idle ();
  folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button));

  if (must_have_cwd)
    passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
  else
    passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);

  log_test (passed, "test_button_folder_states_for_action(): %s, use_dialog=%d, set_folder_on_dialog=%d, unmapped, %s",
	    get_action_name (action),
	    use_dialog,
	    set_folder_on_dialog,
	    must_have_cwd ? "must have $cwd" : "must have explicit folder");
  g_free (folder);

  /* Re-map; folder should be set */

  gtk_widget_show_now (window);
  folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button));

  if (must_have_cwd)
    passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
  else
    passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
  wait_for_idle ();
  log_test (passed, "test_button_folder_states_for_action(): %s, use_dialog=%d, set_folder_on_dialog=%d, re-mapped, %s",
	    get_action_name (action),
	    use_dialog,
	    set_folder_on_dialog,
	    must_have_cwd ? "must have $cwd" : "must have explicit folder");
  g_free (folder);

  g_free (current_working_dir);

  gtk_widget_destroy (window);

  return passed;
}
Esempio n. 16
0
static gboolean
test_reload_sequence (gboolean set_folder_before_map)
{
  GtkWidget *dialog;
  GtkFileChooserDefault *impl;
  gboolean passed;
  char *folder;
  char *current_working_dir;

  passed = TRUE;

  current_working_dir = g_get_current_dir ();

  dialog = gtk_file_chooser_dialog_new ("Test file chooser",
					NULL,
					GTK_FILE_CHOOSER_ACTION_OPEN,
					GTK_STOCK_CANCEL,
					GTK_RESPONSE_CANCEL,
					GTK_STOCK_OK,
					GTK_RESPONSE_ACCEPT,
					NULL);
  impl = get_impl_from_dialog (dialog);

  if (set_folder_before_map)
    {
      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), g_get_home_dir ());

      wait_for_idle ();

      passed = passed && (impl->current_folder != NULL
			  && impl->browse_files_model != NULL
			  && (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
			  && impl->reload_state == RELOAD_HAS_FOLDER
			  && (impl->load_state == LOAD_PRELOAD ? (impl->load_timeout_id != 0) : TRUE)
			  && ((impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
			      ? (impl->load_timeout_id == 0 && impl->sort_model != NULL)
			      : TRUE));

      wait_for_idle ();

      folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
      passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
      g_free (folder);
    }
  else
    {
      /* Initially, no folder is not loaded or pending */
      passed = passed && (impl->current_folder == NULL
			  && impl->sort_model == NULL
			  && impl->browse_files_model == NULL
			  && impl->load_state == LOAD_EMPTY
			  && impl->reload_state == RELOAD_EMPTY
			  && impl->load_timeout_id == 0);

      wait_for_idle ();

      folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
      passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
    }

  log_test (passed, "test_reload_sequence(): initial status");

  /* After mapping, it is loading some folder, either the one that was explicitly set or the default one */

  gtk_widget_show_now (dialog);

  wait_for_idle ();

  passed = passed && (impl->current_folder != NULL
		      && impl->browse_files_model != NULL
		      && (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
		      && impl->reload_state == RELOAD_HAS_FOLDER
		      && (impl->load_state == LOAD_PRELOAD ? (impl->load_timeout_id != 0) : TRUE)
		      && ((impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
			  ? (impl->load_timeout_id == 0 && impl->sort_model != NULL)
			  : TRUE));

  folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
  if (set_folder_before_map)
    passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
  else
    passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);

  g_free (folder);

  log_test (passed, "test_reload_sequence(): status after map");

  /* Unmap it; we should still have a folder */

  gtk_widget_hide (dialog);

  wait_for_idle ();

  passed = passed && (impl->current_folder != NULL
		      && impl->browse_files_model != NULL
		      && (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
		      && (impl->load_state == LOAD_PRELOAD ? (impl->load_timeout_id != 0) : TRUE)
		      && ((impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
			  ? (impl->load_timeout_id == 0 && impl->sort_model != NULL)
			  : TRUE));

  folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
  if (set_folder_before_map)
    passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
  else
    passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);

  g_free (folder);

  log_test (passed, "test_reload_sequence(): status after unmap");

  /* Map it again! */

  gtk_widget_show_now (dialog);

  wait_for_idle ();

  passed = passed && (impl->current_folder != NULL
		      && impl->browse_files_model != NULL
		      && (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
		      && impl->reload_state == RELOAD_HAS_FOLDER
		      && (impl->load_state == LOAD_PRELOAD ? (impl->load_timeout_id != 0) : TRUE)
		      && ((impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
			  ? (impl->load_timeout_id == 0 && impl->sort_model != NULL)
			  : TRUE));

  folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
  if (set_folder_before_map)
    passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
  else
    passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);

  g_free (folder);

  log_test (passed, "test_reload_sequence(): status after re-map");

  gtk_widget_destroy (dialog);
  g_free (current_working_dir);

  return passed;
}