Esempio n. 1
0
//------------------------------------------------
// Write to sub_sectors function for JNA 
//
bool writeJNA(uint64_t division, char* message, uint32_t write_size){

	void *p_buffer = cf_valloc(g_device->read_bytes);

	if (! p_buffer) {
		printf("=> ERROR: read buffer cf_valloc()\n");
		return false;
	}

	uint64_t offset = division / g_ref_tab_columns;
	offset = (offset % g_device->num_read_offsets) * g_device->min_op_bytes;

	if(is_sector_free(offset/g_device->read_bytes, division % g_ref_tab_columns)){
		prep_to_sector_div(offset, division % g_ref_tab_columns, p_buffer, message, write_size);
		if (! write_to_device(g_device, offset, g_device->read_bytes, p_buffer)){
				printf("=> ERROR write op on offset: %" PRIu64 "\n", offset);
				free(p_buffer);
				return false;
		}else{
			add_sector_ref(offset/g_device->read_bytes, division % g_ref_tab_columns);
		}
	}else{
		printf("=> Sector ALREADY referenced!\n");
	}
	
	free(p_buffer);
	return true;
}
Esempio n. 2
0
File: act.c Progetto: aanguss/act
//------------------------------------------------
// Do one large block write operation and report.
//
static void write_and_report_large_block(device* p_device) {
	salter* p_salter;

	if (g_num_write_buffers > 1) {
		p_salter = &g_salters[rand_32() % g_num_write_buffers];

		pthread_mutex_lock(&p_salter->lock);
		*(uint32_t*)p_salter->p_buffer = p_salter->stamp++;
	}
	else {
		p_salter = &g_salters[0];
	}

	uint64_t offset = random_large_block_offset(p_device);
	uint64_t start_time = cf_getus();
	uint64_t stop_time = write_to_device(p_device, offset,
		g_large_block_ops_bytes, p_salter->p_buffer);

	if (g_num_write_buffers > 1) {
		pthread_mutex_unlock(&p_salter->lock);
	}

	if (stop_time != -1) {
		histogram_insert_data_point(g_p_large_block_write_histogram,
			safe_delta_us(start_time, stop_time));
	}
}
Esempio n. 3
0
/*
 * A simple program to test the System Timer driver
 ******************************************************************************
 */
int main (int argc, char* argv[])
{
	const char *files[] = {"/dev/CS", "/dev/CLO", "/dev/CHI", "/dev/C0", "/dev/C1", "/dev/C2", "/dev/C3"} ;
	//const unsigned int file_count = sizeof (files) / sizeof (char*) ;

	/*  */
	if (argv[1] == NULL || argv[2] == NULL)
	{		
		print_syntax () ;
		exit (1) ;
	}

	/*  */
	int device_number = atoi(argv[1]) ;
	unsigned int write_value ;

	sscanf (atoi(argv[2]), "%u", &write_value) ;

	/*  */
	for (int repeat = 1 ; repeat <= 1 ; repeat++)
		write_to_device (files[device_number], &value) ;
	
	
  /* Program exists cleanly */
	return 0 ;
} //main
Esempio n. 4
0
/* send stop request to MAC */
static int send_stop_request(struct sdio_func *func)
{
	struct hostif_stop_request_t *pp;
	struct ks_sdio_card *card;
	size_t size;

	card = sdio_get_drvdata(func);

	pp = kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL);
	if (!pp) {
		DPRINTK(3, "allocate memory failed..\n");
		return -ENOMEM;
	}

	size = sizeof(*pp) - sizeof(pp->header.size);
	pp->header.size = cpu_to_le16((uint16_t)size);
	pp->header.event = cpu_to_le16((uint16_t)HIF_STOP_REQ);

	sdio_claim_host(func);
	write_to_device(card->priv, (unsigned char *)pp,
			hif_align_size(sizeof(*pp)));
	sdio_release_host(func);

	kfree(pp);
	return 0;
}
Esempio n. 5
0
static void tx_device_task(struct ks_wlan_private *priv)
{
	struct tx_device_buffer *sp;
	int ret;

	DPRINTK(4, "\n");
	if (cnt_txqbody(priv) <= 0 ||
	    atomic_read(&priv->psstatus.status) == PS_SNOOZE)
		return;

	sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qhead];
	if (priv->dev_state >= DEVICE_STATE_BOOT) {
		ret = write_to_device(priv, sp->sendp, sp->size);
		if (ret) {
			DPRINTK(1, "write_to_device error !!(%d)\n", ret);
			queue_delayed_work(priv->wq, &priv->rw_dwork, 1);
			return;
		}
	}
	kfree(sp->sendp);
	if (sp->complete_handler)	/* TX Complete */
		(*sp->complete_handler)(priv, sp->skb);
	inc_txqhead(priv);

	if (cnt_txqbody(priv) > 0)
		queue_delayed_work(priv->wq, &priv->rw_dwork, 0);
}
Esempio n. 6
0
static void tx_device_task(void *dev)
{
	struct ks_wlan_private *priv = (struct ks_wlan_private *)dev;
	struct tx_device_buffer *sp;
	int rc = 0;

	DPRINTK(4, "\n");
	if (cnt_txqbody(priv) > 0
	    && atomic_read(&priv->psstatus.status) != PS_SNOOZE) {
		sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qhead];
		if (priv->dev_state >= DEVICE_STATE_BOOT) {
			rc = write_to_device(priv, sp->sendp, sp->size);
			if (rc) {
				DPRINTK(1, "write_to_device error !!(%d)\n",
					rc);
				queue_delayed_work(priv->ks_wlan_hw.
						   ks7010sdio_wq,
						   &priv->ks_wlan_hw.rw_wq, 1);
				return;
			}

		}
		kfree(sp->sendp);	/* allocated memory free */
		if (sp->complete_handler != NULL)	/* TX Complete */
			(*sp->complete_handler) (sp->arg1, sp->arg2);
		inc_txqhead(priv);

		if (cnt_txqbody(priv) > 0) {
			queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
					   &priv->ks_wlan_hw.rw_wq, 0);
		}
	}
	return;
}
Esempio n. 7
0
//------------------------------------------------
// Do one large block write operation and report.
//
static void
write_and_report_large_block(device* dev, uint8_t* buf, uint64_t count)
{
	// Salt the block each time.
	rand_fill(buf, g_scfg.large_block_ops_bytes);

	uint64_t offset = random_large_block_offset(dev);
	uint64_t start_time = get_ns();
	uint64_t stop_time = write_to_device(dev, offset,
			g_scfg.large_block_ops_bytes, buf);

	if (stop_time != -1) {
		histogram_insert_data_point(g_large_block_write_hist,
				safe_delta_ns(start_time, stop_time));
	}
}
Esempio n. 8
0
//------------------------------------------------
// Do one transaction write operation and report.
//
static void
write_and_report(trans_req* write_req, uint8_t* buf)
{
	// Salt each record.
	rand_fill(buf, write_req->size);

	uint64_t raw_start_time = get_ns();
	uint64_t stop_time = write_to_device(write_req->dev, write_req->offset,
			write_req->size, buf);

	if (stop_time != -1) {
		histogram_insert_data_point(g_raw_write_hist,
				safe_delta_ns(raw_start_time, stop_time));
		histogram_insert_data_point(g_write_hist,
				safe_delta_ns(write_req->start_time, stop_time));
		histogram_insert_data_point(write_req->dev->raw_write_hist,
				safe_delta_ns(raw_start_time, stop_time));
	}
}
Esempio n. 9
0
//--------------------------------------------------------------------------
main() {
    int job, flag = 0;
    if ((fd = open_device()) == -1) {
	printf("\ncan not open device ...\n");
        exit(1);
    }

    while (1) {
	system ("clear");
	printf("\n\n             << This is an application to use device driver >>\n");
	printf("\n\n\n1) read data\n");
	printf("2) write data\n");
	printf("3) exit\n");
	printf("\n\nselect (1-3) : ");
	scanf("%d", &job);

	switch (job) {
	    case 1:
		read_from_device();
		break;
	    case 2:
		write_to_device();
		break;
	    case 3:
		flag = 1;
		break;
	    default:
		printf("\nwrong number ...\n");
	}

	if (flag == 1) break;
	printf("\n\n\npress ENTER to continue ...\n");
	getchar();
	getchar();
    }

    close (fd);
}
Esempio n. 10
0
static void ks7010_sdio_remove(struct sdio_func *func)
{
	int ret;
	struct ks_sdio_card *card;
	struct ks_wlan_private *priv;
	struct net_device *netdev;
	DPRINTK(1, "ks7010_sdio_remove()\n");

	card = sdio_get_drvdata(func);

	if (card == NULL)
		return;

	DPRINTK(1, "priv = card->priv\n");
	priv = card->priv;
	netdev = priv->net_dev;
	if (priv) {
		ks_wlan_net_stop(netdev);
		DPRINTK(1, "ks_wlan_net_stop\n");

		/* interrupt disable */
		sdio_claim_host(func);
		sdio_writeb(func, 0, INT_ENABLE, &ret);
		sdio_writeb(func, 0xff, INT_PENDING, &ret);
		sdio_release_host(func);
		DPRINTK(1, "interrupt disable\n");

		/* send stop request to MAC */
		{
			struct hostif_stop_request_t *pp;
			pp = (struct hostif_stop_request_t *)
			    kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL);
			if (pp == NULL) {
				DPRINTK(3, "allocate memory failed..\n");
				return;	/* to do goto ni suru */
			}
			pp->header.size =
			    cpu_to_le16((uint16_t)
					(sizeof(*pp) -
					 sizeof(pp->header.size)));
			pp->header.event = cpu_to_le16((uint16_t) HIF_STOP_REQ);

			sdio_claim_host(func);
			write_to_device(priv, (unsigned char *)pp,
					hif_align_size(sizeof(*pp)));
			sdio_release_host(func);
			kfree(pp);
		}
		DPRINTK(1, "STOP Req\n");

		if (priv->ks_wlan_hw.ks7010sdio_wq) {
			flush_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
			destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
		}
		DPRINTK(1,
			"destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);\n");

		hostif_exit(priv);
		DPRINTK(1, "hostif_exit\n");

		unregister_netdev(netdev);

		trx_device_exit(priv);
		if (priv->ks_wlan_hw.read_buf) {
			kfree(priv->ks_wlan_hw.read_buf);
		}
		free_netdev(priv->net_dev);
		card->priv = NULL;
	}

	sdio_claim_host(func);
	sdio_release_irq(func);
	DPRINTK(1, "sdio_release_irq()\n");
	sdio_disable_func(func);
	DPRINTK(1, "sdio_disable_func()\n");
	sdio_release_host(func);

	sdio_set_drvdata(func, NULL);

	kfree(card);
	DPRINTK(1, "kfree()\n");

	DPRINTK(5, " Bye !!\n");
	return;
}
Esempio n. 11
0
/*
 * A simple program to test the System Timer driver
 ******************************************************************************
 */
int main (int argc, char* argv[])
{
	/*  */	
	unsigned int  read_value ;
	unsigned int write_value = 0 ;

	const char *files[] = {"/dev/CS", "/dev/CLO", "/dev/CHI", "/dev/C0", "/dev/C1", "/dev/C2", "/dev/C3"} ;
	//const unsigned int file_count = sizeof (files) / sizeof (char*) ;

	/*  */
	if (argv[1] == NULL)
	{
		print_syntax () ;
		exit (1) ;
	}

	/*  */
	piHiPri (100) ;

	/*  */
	unsigned int interval ;
	sscanf (argv[1], "%u", &interval) ;

	/* 	 */
	read_from_device (files[1], &read_value) ;
	write_value = (read_value / 10000000 + 1) * 10000000 ;
	write_to_device  (files[4], &write_value) ;



	/*  */
	sigset_t block_mask, oldmask ;
	
	/* Set up the mask of signals to temporarily block. */ 
	sigemptyset (&block_mask) ;
	sigaddset (&block_mask, SIGUSR1) ;
	sigaddset (&block_mask, SIGUSR2) ;

	/*  */
	struct sigaction action ;
  
  /* Establish the signal handler.  */
  action.sa_handler = signal_handler ;
  action.sa_mask = block_mask ;
  action.sa_flags = 0 ;
  
  /*  */
  sigaction (SIGUSR1, &action, NULL) ;
	sigaction (SIGUSR2, &action, NULL) ;

	/*  */
	sigprocmask (SIG_BLOCK, &block_mask, &oldmask) ;
	
	/* Wait for a signal to arrive. */
	while (1)
	  sigsuspend (&oldmask) ;

	/*  */
	sigprocmask (SIG_UNBLOCK, &block_mask, NULL) ;

	
  /* Program exists cleanly */
	return 0 ;
} //main