Exemple #1
0
/**@brief Function for SPI master event callback.
 *
 * Upon receiving an SPI transaction complete event, checks if received data are valid.
 *
 * @param[in] spi_master_evt    SPI master driver event.
 */
static void spi_master_event_handler(spi_master_evt_t spi_master_evt)
{
    uint32_t err_code = NRF_SUCCESS;
    bool result = false;

    switch (spi_master_evt.evt_type)
    {
        case SPI_MASTER_EVT_TRANSFER_COMPLETED:

            // Check if data are vaild.
            result = buf_check(m_rx_data, spi_master_evt.data_count);
            APP_ERROR_CHECK_BOOL(result);

            err_code = bsp_indication_set(BSP_INDICATE_RCV_OK);
            APP_ERROR_CHECK(err_code);

            // Inform application that transfer is completed.
            m_transfer_completed = true;
            break;

        default:
            // No implementation needed.
            break;
    }
}
Exemple #2
0
int device_fpgas_rw(struct device *device)
{
	int result;
	int num;
	for (num = 0; num < device->num_of_fpgas; num++) {
		struct fpga *fpga = &device->fpga[num];
		//if (!fpga->valid) // currently if r/w error on some FPGA, the entire device invalidated
		//	continue;

		//fpga_select(fpga); // unlike select_fpga() from Ztex SDK, it waits for i/o timeout
		result = fpga_select_setup_io(fpga); // combines fpga_select(), fpga_get_io_state() and fpga_setup_output() in 1 USB request
		if (result < 0) {
			fprintf(stderr, "SN %s FPGA #%d fpga_select_setup_io() error: %d\n",
				device->ztex_device->snString, num, result);
			return result;
		}

		// write
		if (!fpga->wr.wr_count || fpga->wr.wr_done) {
			// FPGA-based application processes in 2-byte words, don't write unaligned
			int len = 2* (random() % (max_len+1 - min_len)/2) + min_len;
			fpga->wr.len = len;
			fpga->data_out = buf_set(fpga->wr.buf, fpga->wr.len, fpga->data_out);
		}
		result = fpga_write(fpga);
		if (result < 0) {
			fprintf(stderr, "SN %s FPGA #%d write error: %d (%s)\n",
				device->ztex_device->snString, num, result, libusb_strerror(result));
			fpga->valid = 0;
			return result;
		}
		if (result > 0) {
			wr_byte_count += fpga->wr.len;
			if ( wr_byte_count/1024/1024 != (wr_byte_count - fpga->wr.len)/1024/1024 ) {
				printf(".");
				fflush(stdout);
			}
		}

		// read
		result = fpga_read(fpga);
		if (result < 0) {
			fprintf(stderr, "SN %s FPGA #%d read error: %d (%s)\n",
				device->ztex_device->snString, num, result, libusb_strerror(result));
			fpga->valid = 0;
			return result;
		}
		if (result > 0) {
			rd_byte_count += fpga->rd.read_limit;
			if (buf_check(fpga->rd.buf, fpga->rd.len, &fpga->data_in) < 0) {
				return -1;
			}
			partial_read_count += fpga->rd.partial_read_count;
			fpga->rd.partial_read_count = 0;
		}

	} // for( ;num_of_fpgas ;)
	return 1;
}
int block_test_pages(PPartition *ppt,unsigned int block, unsigned int *buf, unsigned int ppb)
{
        int ret = 0;
        unsigned char *writebuf = (unsigned char *)buf;
        unsigned int writesize =ppt->byteperpage;
        unsigned char *readbuf = (unsigned char *)buf+writesize * ppb;
        struct platform_nand_partition *pnand_pt =(struct platform_nand_partition *)ppt->prData;
        unsigned int v_ppb=ppb;
        BlockList blocklist;
        dprintf("\n****** go into block_test_pages  *****\n");
        /*	ret =g_vnand.operator->IsBadBlock(block);
                if(ret)
                dprintf("block %d is badblock\n",block);
                else
                dprintf("block %d is goodblock\n",block);
                ret =g_vnand.operator->IsBadBlock(block+1);
                if(ret)
                dprintf("block %d is badblock\n",block+1);
                else
                dprintf("block %d is goodblock\n",block+1);
                */	
        blocklist.startBlock =block;
        blocklist.BlockCount =2;
        blocklist.head.next =0;
        nand_test_erase(ppt,&blocklist);

        printk("test blockid = %d\n",block);
        if(pnand_pt->use_planes)
                v_ppb =ppb*2;
        /*init databuf with 1 2 3 ... */
        buf_init(writebuf, writesize * ppb);
        creat_pagelist(v_ppb*block,writebuf,readbuf,ppb*2);

        dprintf("\n******nand_test_write_pages start*****\n");
        ret = nand_test_write_pages(ppt,head_write);
        dprintf("\n******nand_test_write_pages finish*****\n");
        if(ret <0){
                check_pagelist(head_write);
                return 0;
        }
        dprintf("\n******nand_test_write_pages OK*****\n");
//	while(1);
        /*clear buf for read*/
        memset(readbuf,0xFF, writesize*ppb);

        ret = nand_test_read_pages(ppt,head_read);
        if(ret){
                check_pagelist(head_read);
                return 0;
        }

        buf_check(writebuf, readbuf, writesize*ppb);

        return ret;
}
int spl_test(PPartition *ppt,unsigned int block, unsigned int *buf, unsigned int ppb)
{
        int ret = 0,i=0;
        unsigned char *writebuf = (unsigned char *)buf;
        unsigned int writesize =ppt->byteperpage;
        unsigned char *readbuf = (unsigned char *)(buf + writesize * 3);
        struct platform_nand_partition *pnand_pt =(struct platform_nand_partition *)ppt->prData;
        unsigned int v_ppb=0;
        BlockList blocklist;
        while(i<8){		
                ret =vnand_interface->iIsBadBlock(ppt,block+i);
                if(ret)
                        dprintf("block %d is badblock\n",block+i);
                else
                        dprintf("block %d is goodblock\n",block+i);
                i++;
        }
        blocklist.startBlock =block;
        blocklist.BlockCount =5;
        blocklist.head.next =0;
        nand_test_erase(ppt,&blocklist);
        if(pnand_pt->use_planes)
                v_ppb =ppb*2;
        /*init databuf with 1 2 3 ... */
        buf_init(writebuf, writesize * ppb);
        creat_spl_pagelist(v_ppb*block,writebuf,readbuf,ppb);

        ret = nand_test_write_pages(ppt,head_write);
        if(ret <0){
                check_pagelist(head_write);
                return 0;
        }
        dprintf("\n******nand_test_write_pages OK*****\n");
        /*clear buf for read*/
        memset(readbuf,0xFF, writesize*ppb);

        ret = nand_test_read_pages(ppt,head_read);
        if(ret){
                check_pagelist(head_read);
                return 0;
        }
        buf_check(writebuf, readbuf, writesize*ppb);

        return ret;
}
Exemple #5
0
int ch_fill(struct channel *ch)
{
	ssize_t res;
	size_t count;

	count = buf_check(&ch->buf_max, ch->buf_cur, CHANNEL_CHUNK_SIZE);
	assert(count != 0);
	res = read(ch->sock.fd, ch->buf + ch->buf_cur, count);
	Debug("%s:read %zd bytes (asked for %zd bytes)\n",
		ch->desc, res, count);
	Debug("%s:cur=%zd max=%zd\n", ch->desc, ch->buf_cur, ch->buf_max);
	if (res <= 0) {
		if (res < 0)
			perror(ch->desc);
		return -1;
	}
	buf_commit(ch->buf_max, &ch->buf_cur, res);
	return 1;

}
Exemple #6
0
/**@brief Function for SPI master event callback.
 *
 * Upon receiving an SPI transaction complete event, checks if received data are valid.
 *
 * @param[in] spi_master_evt    SPI master driver event.
 */
static void spi_master_event_handler(nrf_drv_spi_event_t event)
{
    uint32_t err_code = NRF_SUCCESS;
    bool result = false;

    switch (event)
    {
        case NRF_DRV_SPI_EVENT_DONE:
            // Check if data are valid.
            result = buf_check(m_rx_data, TX_RX_BUF_LENGTH);
            APP_ERROR_CHECK_BOOL(result);

            err_code = bsp_indication_set(BSP_INDICATE_RCV_OK);
            APP_ERROR_CHECK(err_code);

            // Inform application that transfer is completed.
            m_transfer_completed = true;
            break;

        default:
            // No implementation needed.
            break;
    }
}