Ejemplo n.º 1
0
static s32 usart1_read_length(u8* buff, u32 want_len)
{
	 u8 BoxErr = 0;				//邮箱接收错误标志
	 s32 len   = 0;
#if SYS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
		SYS_CPU_SR	cpu_sr = 0;
#endif
	
	 SYS_ENTER_CRITICAL();
	 
	 len = kfifo_len(&rx_fifo);
	 if(len >= want_len)
	 {		  
			len = kfifo_get(&rx_fifo,buff,want_len);
		  SYS_EXIT_CRITICAL();
			return len;
	 }
	 
	 rx_length = want_len;
	 SYS_EXIT_CRITICAL();
	 

	 SysMboxPend(rx_event, rx_timeout_ticks, &BoxErr);		//邮箱接收挂起

	 if(BoxErr != 0)
	 {
			return 0;
	 }

	 SYS_ENTER_CRITICAL();
	 len = kfifo_get(&rx_fifo,buff,want_len);
	 SYS_EXIT_CRITICAL();
	 
	 return len;
}
Ejemplo n.º 2
0
static void stp_uart_rx_handling(unsigned long func_data){
    unsigned int how_much_get = 0;
    unsigned int how_much_to_get = 0;
    unsigned int flag = 0;
    
//    read_lock(&g_stp_uart_rx_handling_lock);
    how_much_to_get = kfifo_len(g_stp_uart_rx_fifo);
    
    if (how_much_to_get >= RX_BUFFER_LEN)
    {
        flag = 1;
        UART_INFO_FUNC ("fifolen(%d)\n", how_much_to_get);
    }
    
    do{
        #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35))
        how_much_get= kfifo_get(g_stp_uart_rx_fifo, g_rx_data, RX_BUFFER_LEN);
        #else
        how_much_get= kfifo_out(g_stp_uart_rx_fifo, g_rx_data, RX_BUFFER_LEN);
        #endif
        //UART_INFO_FUNC ("fifoget(%d)\n", how_much_get);
        mtk_wcn_stp_parser_data((UINT8 *)g_rx_data, how_much_get);
        how_much_to_get = kfifo_len(g_stp_uart_rx_fifo);
    }while(how_much_to_get > 0);
    
//    read_unlock(&g_stp_uart_rx_handling_lock);
    if (1 == flag)
    {
        UART_INFO_FUNC ("finish, fifolen(%d)\n", kfifo_len(g_stp_uart_rx_fifo));
    }
}
Ejemplo n.º 3
0
static void omap_plane_post_apply(struct omap_drm_apply *apply)
{
	struct omap_plane *omap_plane =
			container_of(apply, struct omap_plane, apply);
	struct drm_plane *plane = &omap_plane->base;
	struct omap_overlay_info *info = &omap_plane->info;
	struct drm_gem_object *bo = NULL;
	struct callback cb;

	cb = omap_plane->apply_done_cb;
	omap_plane->apply_done_cb.fxn = NULL;

	while (kfifo_get(&omap_plane->unpin_fifo, &bo)) {
		omap_gem_put_paddr(bo);
		drm_gem_object_unreference_unlocked(bo);
	}

	if (cb.fxn)
		cb.fxn(cb.arg);

	if (omap_plane->enabled) {
		omap_framebuffer_flush(plane->fb, info->pos_x, info->pos_y,
				info->out_width, info->out_height);
	}
}
Ejemplo n.º 4
0
static int tftp_write(struct device_d *_dev, FILE *f, const void *inbuf,
		size_t insize)
{
	struct file_priv *priv = f->inode;
	size_t size, now;
	int ret;

	debug("%s: %zu\n", __func__, insize);

	size = insize;

	while (size) {
		now = kfifo_put(priv->fifo, inbuf, size);

		while (kfifo_len(priv->fifo) >= priv->blocksize) {
			kfifo_get(priv->fifo, priv->buf, priv->blocksize);

			tftp_send_write(priv, priv->buf, priv->blocksize);
			tftp_timer_reset(priv);

			while (priv->state == STATE_WAITACK) {
				ret = tftp_poll(priv);
				if (ret == TFTP_ERR_RESEND)
					tftp_send_write(priv, priv->buf,
							priv->blocksize);
				if (ret < 0)
					return ret;
			}
		}
		size -= now;
		inbuf += now;
	}

	return insize;
}
Ejemplo n.º 5
0
static int __init testfunc(void)
{
	unsigned char	buf[6];
	unsigned char	i, j;
	unsigned int	ret;

	printk(KERN_INFO "[fifo]byte stream fifo test start\n");

	/* put string into the fifo */
	kfifo_in(&test, "hello", 5);

	/* put values into the fifo */
	for (i = 0; i != 10; i++)
		kfifo_put(&test, &i);

	/* show the number of used elements */
	printk(KERN_INFO "[fifo]fifo len: %u\n", kfifo_len(&test));

	/* get max of 5 bytes from the fifo */
	i = kfifo_out(&test, buf, 5);
	printk(KERN_INFO "[fifo]buf: %.*s\n", i, buf);

	/* get max of 2 elements from the fifo */
	ret = kfifo_out(&test, buf, 2);
	printk(KERN_INFO "[fifo]ret: %d\n", ret);
	/* and put it back to the end of the fifo */
	ret = kfifo_in(&test, buf, ret);
	printk(KERN_INFO "[fifo]ret: %d\n", ret);

	/* skip first element of the fifo */
	printk(KERN_INFO "[fifo]skip 1st element\n");
	kfifo_skip(&test);

	/* put values into the fifo until is full */
	for (i = 20; kfifo_put(&test, &i); i++)
		;

	printk(KERN_INFO "[fifo]queue len: %u\n", kfifo_len(&test));

	/* show the first value without removing from the fifo */
	if (kfifo_peek(&test, &i))
		printk(KERN_INFO "[fifo]%d\n", i);

	/* check the correctness of all values in the fifo */
	j = 0;
	while (kfifo_get(&test, &i)) {
		printk(KERN_INFO "item = %d\n", i);
		if (i != expected_result[j++]) {
			printk(KERN_WARNING "value mismatch: test failed\n");
			return -EIO;
		}
	}
	if (j != ARRAY_SIZE(expected_result)) {
		printk(KERN_WARNING "size mismatch: test failed\n");
		return -EIO;
	}
	printk(KERN_INFO "[fifo]test passed\n");

	return 0;
}
Ejemplo n.º 6
0
static int tftp_read(struct device_d *dev, FILE *f, void *buf, size_t insize)
{
	struct file_priv *priv = f->inode;
	size_t outsize = 0, now;
	int ret;

	debug("%s %zu\n", __func__, insize);

	while (insize) {
		now = kfifo_get(priv->fifo, buf, insize);
		if (priv->state == STATE_DONE)
			return outsize + now;
		if (now) {
			outsize += now;
			buf += now;
			insize -= now;
		}

		if (TFTP_FIFO_SIZE - kfifo_len(priv->fifo) >= priv->blocksize)
			tftp_send(priv);

		ret = tftp_poll(priv);
		if (ret == TFTP_ERR_RESEND)
			tftp_send(priv);
		if (ret < 0)
			return ret;
	}

	return outsize;
}
Ejemplo n.º 7
0
static ssize_t threadrw_write_onece(
	struct threadrw_write_task *task,
	struct file *file,
	struct stream_buf_s *stbuf,
	const char __user *buf, size_t count)
{
	struct threadrw_buf *rwbuf = NULL;
	int ret = 0;
	int to_write;

	if (!kfifo_get(&task->freefifo, (void *)&rwbuf)) {
		if (task->errors)
			return task->errors;
		return -EAGAIN;
	}

	to_write = min_t(u32, rwbuf->buffer_size, count);
	if (copy_from_user(rwbuf->vbuffer, buf, to_write)) {
		kfifo_put(&task->freefifo, (const void *)buf);
		ret = -EFAULT;
		goto err;
	}
	rwbuf->data_size = to_write;
	rwbuf->write_off = 0;
	kfifo_put(&task->datafifo, (const void *)rwbuf);
	threadrw_schedule_delayed_work(task, 0);
	return to_write;
err:
	return ret;
}
Ejemplo n.º 8
0
static int nfs_read(struct device_d *dev, FILE *file, void *buf, size_t insize)
{
	struct file_priv *priv = file->inode;
	int now, outsize = 0, ret, pos = file->pos;

	while (insize) {
		now = kfifo_get(priv->fifo, buf, insize);
		outsize += now;
		buf += now;
		insize -= now;

		if (insize) {
			/* do not use min as insize is a size_t */
			if (insize < 1024)
				now = insize;
			else
				now = 1024;

			if (pos + now > file->size)
				now = file->size - pos;

			ret = nfs_read_req(priv, pos, now);
			if (ret)
				return ret;
			pos += now;
		}
	}

	return outsize;
}
Ejemplo n.º 9
0
static ssize_t tcpprobe_read(struct file *file, char __user *buf,
			     size_t len, loff_t *ppos)
{
	int error = 0, cnt = 0;
	unsigned char *tbuf;

	if (!buf || len < 0)
		return -EINVAL;

	if (len == 0)
		return 0;

	tbuf = vmalloc(len);
	if (!tbuf)
		return -ENOMEM;

	error = wait_event_interruptible(tcpw.wait,
					 __kfifo_len(tcpw.fifo) != 0);
	if (error)
		goto out_free;

	cnt = kfifo_get(tcpw.fifo, tbuf, len);
	error = copy_to_user(buf, tbuf, cnt);

out_free:
	vfree(tbuf);

	return error ? error : cnt;
}
Ejemplo n.º 10
0
void mt76x2_mac_process_tx_status_fifo(struct mt76x2_dev *dev)
{
	struct mt76x2_tx_status stat;
	u8 update = 1;

	while (kfifo_get(&dev->txstatus_fifo, &stat))
		mt76x2_send_tx_status(dev, &stat, &update);
}
Ejemplo n.º 11
0
static int gpio_keys_getc(struct console_device *cdev)
{
	int code = 0;
	struct gpio_keys_platform_data *pdata = cdev_to_gk_pdata(cdev);

	kfifo_get(pdata->recv_fifo, (u_char*)&code, sizeof(int));
	return code;
}
Ejemplo n.º 12
0
/*
 * Interrupt functions.
 */
static void rt2800pci_wakeup(struct rt2x00_dev *rt2x00dev)
{
	struct ieee80211_conf conf = { .flags = 0 };
	struct rt2x00lib_conf libconf = { .conf = &conf };

	rt2800_config(rt2x00dev, &libconf, IEEE80211_CONF_CHANGE_PS);
}

static void rt2800pci_txdone(struct rt2x00_dev *rt2x00dev)
{
	struct data_queue *queue;
	struct queue_entry *entry;
	u32 status;
	u8 qid;

	while (kfifo_get(&rt2x00dev->txstatus_fifo, &status)) {
		qid = rt2x00_get_field32(status, TX_STA_FIFO_PID_QUEUE);
		if (qid >= QID_RX) {
			/*
			 * Unknown queue, this shouldn't happen. Just drop
			 * this tx status.
			 */
			WARNING(rt2x00dev, "Got TX status report with "
					   "unexpected pid %u, dropping\n", qid);
			break;
		}

		queue = rt2x00queue_get_queue(rt2x00dev, qid);
		if (unlikely(queue == NULL)) {
			/*
			 * The queue is NULL, this shouldn't happen. Stop
			 * processing here and drop the tx status
			 */
			WARNING(rt2x00dev, "Got TX status for an unavailable "
					   "queue %u, dropping\n", qid);
			break;
		}

		if (rt2x00queue_empty(queue)) {
			/*
			 * The queue is empty. Stop processing here
			 * and drop the tx status.
			 */
			WARNING(rt2x00dev, "Got TX status for an empty "
					   "queue %u, dropping\n", qid);
			break;
		}

		entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
		rt2800_txdone_entry(entry, status);
	}
}

static void rt2800pci_txstatus_tasklet(unsigned long data)
{
	rt2800pci_txdone((struct rt2x00_dev *)data);
}
Ejemplo n.º 13
0
static void armada_drm_unref_work(struct work_struct *work)
{
    struct armada_private *priv =
        container_of(work, struct armada_private, fb_unref_work);
    struct drm_framebuffer *fb;

    while (kfifo_get(&priv->fb_unref, &fb))
        drm_framebuffer_unreference(fb);
}
Ejemplo n.º 14
0
/* Receiver */
static int cx25840_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
			      ssize_t *num)
{
	struct cx25840_ir_state *ir_state = to_ir_state(sd);
	bool invert;
	u16 divider;
	unsigned int i, n;
	union cx25840_ir_fifo_rec *p;
	unsigned u, v;

	if (ir_state == NULL)
		return -ENODEV;

	invert = (bool) atomic_read(&ir_state->rx_invert);
	divider = (u16) atomic_read(&ir_state->rxclk_divider);

	n = count / sizeof(union cx25840_ir_fifo_rec)
		* sizeof(union cx25840_ir_fifo_rec);
	if (n == 0) {
		*num = 0;
		return 0;
	}

	n = kfifo_get(ir_state->rx_kfifo, buf, n);

	n /= sizeof(union cx25840_ir_fifo_rec);
	*num = n * sizeof(union cx25840_ir_fifo_rec);

	for (p = (union cx25840_ir_fifo_rec *) buf, i = 0; i < n; p++, i++) {

		if ((p->hw_fifo_data & FIFO_RXTX_RTO) == FIFO_RXTX_RTO) {
			/* Assume RTO was because of no IR light input */
			u = 0;
			v4l2_dbg(2, ir_debug, sd, "rx read: end of rx\n");
		} else {
			u = (p->hw_fifo_data & FIFO_RXTX_LVL) ? 1 : 0;
			if (invert)
				u = u ? 0 : 1;
		}

		v = (unsigned) pulse_width_count_to_ns(
				  (u16) (p->hw_fifo_data & FIFO_RXTX), divider);
		if (v > IR_MAX_DURATION)
			v = IR_MAX_DURATION;

		init_ir_raw_event(&p->ir_core_data);
		p->ir_core_data.pulse = u;
		p->ir_core_data.duration = v;

		v4l2_dbg(2, ir_debug, sd, "rx read: %10u ns  %s\n",
			 v, u ? "mark" : "space");
	}
	return 0;
}
Ejemplo n.º 15
0
static int do_write_work_in(struct threadrw_write_task *task)
{
	struct threadrw_buf *rwbuf = NULL;
	int ret;
	int need_re_write = 0;
	int write_len = 0;
	unsigned long flags;

	if (kfifo_is_empty(&task->datafifo))
		return 0;
	if (!kfifo_peek(&task->datafifo, (void *)&rwbuf))
		return 0;
	if (task->codec_mm_buffer && !rwbuf->write_off)
		codec_mm_dma_flush(rwbuf->vbuffer,
				rwbuf->data_size,
				DMA_TO_DEVICE);

	ret = task->write(task->file, task->sbuf,
		(const char __user *)rwbuf->dma_handle + rwbuf->write_off,
		rwbuf->data_size,
		3);	/* noblock,phy addr */
	if (ret == -EAGAIN) {
		need_re_write = 0;
		/*do later retry. */
	} else if (ret >= rwbuf->data_size) {
		write_len += rwbuf->data_size;
		if (kfifo_get(&task->datafifo, (void *)&rwbuf)) {
			rwbuf->data_size = 0;
			kfifo_put(&task->freefifo, (const void *)rwbuf);
			/*wakeup write thread. */
			wake_up_interruptible(&task->wq);
		} else
			pr_err("write ok,but kfifo_get data failed.!!!\n");
		need_re_write = 1;
	} else if (ret > 0) {
		rwbuf->data_size -= ret;	/* half data write */
		rwbuf->write_off += ret;
		write_len += ret;
		need_re_write = 1;
	} else {		/*ret <=0 */
		pr_err("get errors ret=%d size=%d\n", ret,
			rwbuf->data_size);
		task->errors = ret;
	}
	if (write_len > 0) {
		task->passed_data_len += write_len;
		spin_lock_irqsave(&task->lock, flags);
		task->buffered_data_size -= write_len;
		spin_unlock_irqrestore(&task->lock, flags);
	}
	return need_re_write;

}
Ejemplo n.º 16
0
static void flip_worker(struct work_struct *w)
{
	struct drm_flip_work *work = container_of(w, struct drm_flip_work, worker);
	uint32_t count = atomic_read(&work->count);
	void *val = NULL;

	atomic_sub(count, &work->count);

	while(count--)
		if (!WARN_ON(!kfifo_get(&work->fifo, &val)))
			work->func(work, val);
}
Ejemplo n.º 17
0
static s32 usart1_read_keychar(u8* buff, u32 buff_len)
{
	 u8 BoxErr = 0;				//邮箱接收错误标志
	 SysMboxPend(rx_event, rx_timeout_ticks, &BoxErr);		//邮箱接收挂起

	 if(BoxErr != 0)
	 {
			return 0;
	 }
	 return kfifo_get(&rx_fifo,buff,buff_len);
		
}
static int __init testfunc(void)
{
	int		buf[6];
	int		i, j;
	unsigned int	ret;

	printk(KERN_INFO "int fifo test start\n");

	
	for (i = 0; i != 10; i++)
		kfifo_put(&test, &i);

	
	printk(KERN_INFO "fifo len: %u\n", kfifo_len(&test));

	
	ret = kfifo_out(&test, buf, 2);
	printk(KERN_INFO "ret: %d\n", ret);
	
	ret = kfifo_in(&test, buf, ret);
	printk(KERN_INFO "ret: %d\n", ret);

	
	printk(KERN_INFO "skip 1st element\n");
	kfifo_skip(&test);

	
	for (i = 20; kfifo_put(&test, &i); i++)
		;

	printk(KERN_INFO "queue len: %u\n", kfifo_len(&test));

	
	if (kfifo_peek(&test, &i))
		printk(KERN_INFO "%d\n", i);

	
	j = 0;
	while (kfifo_get(&test, &i)) {
		printk(KERN_INFO "item = %d\n", i);
		if (i != expected_result[j++]) {
			printk(KERN_WARNING "value mismatch: test failed\n");
			return -EIO;
		}
	}
	if (j != ARRAY_SIZE(expected_result)) {
		printk(KERN_WARNING "size mismatch: test failed\n");
		return -EIO;
	}
	printk(KERN_INFO "test passed\n");

	return 0;
}
Ejemplo n.º 19
0
struct iu_entry *srp_iu_get(struct srp_target *target)
{
	struct iu_entry *iue = NULL;

	kfifo_get(target->iu_queue.queue, (void *) &iue, sizeof(void *));
	if (!iue)
		return iue;
	iue->target = target;
	INIT_LIST_HEAD(&iue->ilist);
	iue->flags = 0;
	return iue;
}
Ejemplo n.º 20
0
Archivo: kfifo.c Proyecto: rosrez/drv2
static int __init fifo_init(void)
{
    int i, val, ret;

    ret = kfifo_alloc(&fifo, size * sizeof(int), GFP_KERNEL);
    if (ret)
        return -ENOMEM;

    printk("%s: populating fifo\n", MODNAME);
    for (i = 0; i < size; i++) 
        kfifo_put(&fifo, i + 1);

#if 0
    printk("%s: iterating over fifo\n", MODNAME);
    print_fifo(&fifo);
#endif


    /* dequeue one item -- and discard it */
    if (!kfifo_get(&fifo, &val))
        /* use the result and silence the compiler */;

    /* enqueue one more item */
    kfifo_put(&fifo, size + 1);

#if 0
    printk("%s: iterating over updated fifo\n", MODNAME);
    print_fifo(&fifo);   
#endif

    printk("printing -- draining the queue\n");
    i = 1;
    while(kfifo_get(&fifo, &val)) {
        printk("item[%d] = %d\n", i++, val);
    }
 
    printk("%s: init complete\n", MODNAME);
    return 0;
}
Ejemplo n.º 21
0
/**
 * usb_serial_generic_write_start - kick off an URB write
 * @port:	Pointer to the &struct usb_serial_port data
 *
 * Returns the number of bytes queued on success. This will be zero if there
 * was nothing to send. Otherwise, it returns a negative errno value
 */
static int usb_serial_generic_write_start(struct usb_serial_port *port)
{
    struct usb_serial *serial = port->serial;
    unsigned char *data;
    int result;
    int count;
    unsigned long flags;
    bool start_io;

    /* Atomically determine whether we can and need to start a USB
     * operation. */
    spin_lock_irqsave(&port->lock, flags);
    if (port->write_urb_busy)
        start_io = false;
    else {
        start_io = (__kfifo_len(port->write_fifo) != 0);
        port->write_urb_busy = start_io;
    }
    spin_unlock_irqrestore(&port->lock, flags);

    if (!start_io)
        return 0;

    data = port->write_urb->transfer_buffer;
    count = kfifo_get(port->write_fifo, data, port->bulk_out_size);
    usb_serial_debug_data(debug, &port->dev, __func__, count, data);

    /* set up our urb */
    usb_fill_bulk_urb(port->write_urb, serial->dev,
                      usb_sndbulkpipe(serial->dev,
                                      port->bulk_out_endpointAddress),
                      port->write_urb->transfer_buffer, count,
                      ((serial->type->write_bulk_callback) ?
                       serial->type->write_bulk_callback :
                       usb_serial_generic_write_bulk_callback),
                      port);

    /* send the data out the bulk port */
    result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
    if (result) {
        dev_err(&port->dev,
                "%s - failed submitting write urb, error %d\n",
                __func__, result);
        /* don't have to grab the lock here, as we will
           retry if != 0 */
        port->write_urb_busy = 0;
    } else
        result = count;

    return result;
}
Ejemplo n.º 22
0
int
efrm_filter_resource_alloc(struct vi_resource *vi_parent,
			   struct filter_resource **frs_out)
{
	struct filter_resource *frs;
	int rc, instance;

	EFRM_ASSERT(frs_out);
	EFRM_ASSERT(efrm_filter_manager);
	EFRM_RESOURCE_MANAGER_ASSERT_VALID(&efrm_filter_manager->rm);
	EFRM_ASSERT(vi_parent != NULL);
	EFRM_ASSERT(EFRM_RESOURCE_TYPE(vi_parent->rs.rs_handle) ==
		    EFRM_RESOURCE_VI);

	/* Allocate resource data structure.  This is called in atomic
	 * context by the onload driver.
	 */
	frs = kmalloc(sizeof(struct filter_resource), GFP_ATOMIC);
	if (!frs)
		return -ENOMEM;

	/* Allocate an instance. */
	rc = kfifo_get(efrm_filter_manager->free_ids,
		       (unsigned char *)&instance, sizeof(instance));
	if (rc != sizeof(instance)) {
		EFRM_TRACE("%s: out of instances", __FUNCTION__);
		EFRM_ASSERT(rc == 0);
		rc = -EBUSY;
		goto fail1;
	}

	/* Initialise the resource DS. */
	efrm_resource_init(&frs->rs, EFRM_RESOURCE_FILTER, instance);
	frs->pt = vi_parent;
	efrm_resource_ref(&frs->pt->rs);
	frs->filter_idx = -1;

	EFRM_TRACE("%s: " EFRM_RESOURCE_FMT " VI %d", __FUNCTION__,
		   EFRM_RESOURCE_PRI_ARG(frs->rs.rs_handle),
		   EFRM_RESOURCE_INSTANCE(vi_parent->rs.rs_handle));

	efrm_client_add_resource(vi_parent->rs.rs_client, &frs->rs);
	*frs_out = frs;
	return 0;

fail1:
	memset(frs, 0, sizeof(*frs));
	kfree(frs);
	return rc;
}
Ejemplo n.º 23
0
// Reading from the SPI device
ssize_t dv_spi_read(struct file *filp, char __user *buf, size_t count, loff_t
                    *f_pos)
{
    Uarray buf_val;
    ssize_t	status = 0;

    if((NULL == buf)||(count <= 0))
    {
        return -1;
    }
#if 0
    len = kfifo_len(g_kfifo);
    if(count > len)
    {
        count = len ;
    }
    memset(g_readbuf,0,sizeof(g_readbuf));
    kfifo_get(g_kfifo,g_readbuf,count);
    // Transferring data to user space
    status = copy_to_user(buf, g_readbuf, count);
    if(0 == status)
    {
        return count;
    }
    else
    {
        return -1;
    }
#else
    if(SPIBUF_RXEMPTY_MASK & SPI_REG(SPIBUF))
    {
        buf_val.udata = SPI_REG(SPIBUF);
        count = (g_dataformat == format_8bit)?1:2;
        // Transferring data to user space
        status = copy_to_user(buf, buf_val.uarray,count);
        if(0 == status)
        {
            return count;
        }
        else
        {
            return -1;
        }
    }
    else
    {
        return -1;
    }
#endif
}
Ejemplo n.º 24
0
/* Receiver */
static int cx23888_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
			      ssize_t *num)
{
	struct cx23888_ir_state *state = to_state(sd);
	bool invert = (bool) atomic_read(&state->rx_invert);
	u16 divider = (u16) atomic_read(&state->rxclk_divider);

	unsigned int i, n;
	u32 *p;
	u32 u, v;

	n = count / sizeof(u32) * sizeof(u32);
	if (n == 0) {
		*num = 0;
		return 0;
	}

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
	n = kfifo_get(state->rx_kfifo, buf, n);
#else
	n = kfifo_out_locked(&state->rx_kfifo, buf, n, &state->rx_kfifo_lock);
#endif

	n /= sizeof(u32);
	*num = n * sizeof(u32);

	for (p = (u32 *) buf, i = 0; i < n; p++, i++) {
		if ((*p & FIFO_RXTX_RTO) == FIFO_RXTX_RTO) {
			*p = V4L2_SUBDEV_IR_PULSE_RX_SEQ_END;
			v4l2_dbg(2, ir_888_debug, sd, "rx read: end of rx\n");
			continue;
		}

		u = (*p & FIFO_RXTX_LVL) ? V4L2_SUBDEV_IR_PULSE_LEVEL_MASK : 0;
		if (invert)
			u = u ? 0 : V4L2_SUBDEV_IR_PULSE_LEVEL_MASK;

		v = (u32) pulse_width_count_to_ns((u16) (*p & FIFO_RXTX),
						  divider);
		if (v >= V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS)
			v = V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS - 1;

		*p = u | v;

		v4l2_dbg(2, ir_888_debug, sd, "rx read: %10u ns  %s\n",
			 v, u ? "mark" : "space");
	}
	return 0;
}
Ejemplo n.º 25
0
//字符超时接收模式读取函数
static s32 usart1_read_packet(u8* buff, u32 buff_len)
{
	 u8 BoxErr = 0;				//邮箱接收错误标志
	 s32 ret = 0;
#if SYS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
	 SYS_CPU_SR	cpu_sr = 0;
#endif
	 if(kfifo_len(&rx_fifo) > 0)
	 {
				return kfifo_get(&rx_fifo,buff,buff_len);
	 }
	 SysMboxPend(rx_event, rx_timeout_ticks, &BoxErr);		//邮箱接收挂起
	
	 if(BoxErr != 0)
	 {
			return 0;
	 }

	SYS_ENTER_CRITICAL();
	ret = kfifo_get(&rx_fifo,buff,buff_len);
	SYS_EXIT_CRITICAL();
	 
	return ret;
}
Ejemplo n.º 26
0
/* hclge_dbg_dump_mac_tnl_status: print message about mac tnl interrupt
 * @hdev: pointer to struct hclge_dev
 */
static void hclge_dbg_dump_mac_tnl_status(struct hclge_dev *hdev)
{
#define HCLGE_BILLION_NANO_SECONDS 1000000000

	struct hclge_mac_tnl_stats stats;
	unsigned long rem_nsec;

	dev_info(&hdev->pdev->dev, "Recently generated mac tnl interruption:\n");

	while (kfifo_get(&hdev->mac_tnl_log, &stats)) {
		rem_nsec = do_div(stats.time, HCLGE_BILLION_NANO_SECONDS);
		dev_info(&hdev->pdev->dev, "[%07lu.%03lu]status = 0x%x\n",
			 (unsigned long)stats.time, rem_nsec / 1000,
			 stats.status);
	}
}
Ejemplo n.º 27
0
static size_t uart16550_read(struct file *filp, const char *buffer, size_t size, loff_t *offset) 
{
    struct task_struct **task_user_get_data = ftask_user_get_data(filp->private_data);
    struct kfifo *data_from_device = fdata_from_device (filp->private_data);
    uint8_t u8;
    int i;
    char* pos = buffer;
    for(i =0;i<size;i++)
    {
        wait_for_queue(task_user_get_data,can_read,data_from_device);
        kfifo_get(data_from_device,&u8);
        put_user(u8ToChar(u8),pos+i);
    }
   
   return size;
}
Ejemplo n.º 28
0
/*********functions which permit to communicate with the board****************/
UNS8 canReceive_driver(CAN_HANDLE fd0, Message *m)
{
	long ret = wait_event_interruptible (((CANPipe*)fd0)->w_queue,
		kfifo_len (((CANPipe*)fd0)->pipe) >= sizeof(Message));

	// interrupted by signal
	if (ret == -ERESTARTSYS)
		return 2;

	if (kfifo_get (((CANPipe*)fd0)->pipe, (unsigned char *)m, sizeof(Message)) != sizeof(Message))
	{
		printk(KERN_NOTICE "can_virtual: error receiving data from kernel fifo.\n");
		return 1;
	}
	
	return 0;
}
Ejemplo n.º 29
0
struct iu_entry *srp_iu_get(struct srp_target *target)
{
	struct iu_entry *iue = NULL;

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
	kfifo_get(target->iu_queue.queue, (void *) &iue, sizeof(void *));
#else
	if (kfifo_out_locked(&target->iu_queue.queue, (void *) &iue,
		sizeof(void *), &target->iu_queue.lock) != sizeof(void *)) {
			WARN_ONCE(1, "unexpected fifo state");
			return NULL;
	}
#endif
	if (!iue)
		return iue;
	iue->target = target;
	iue->flags = 0;
	return iue;
}
Ejemplo n.º 30
0
static int __init testfunc(void)
{
	unsigned char	buf[6];
	unsigned char	i;
	unsigned int	ret;

	printk(KERN_INFO "byte stream fifo test start\n");

	/* put string into the fifo */
	kfifo_in(&test, "hello", 5);

	/* put values into the fifo */
	for (i = 0; i != 10; i++)
		kfifo_put(&test, &i);

	/* show the number of used elements */
	printk(KERN_INFO "fifo len: %u\n", kfifo_len(&test));

	/* get max of 5 bytes from the fifo */
	i = kfifo_out(&test, buf, 5);
	printk(KERN_INFO "buf: %.*s\n", i, buf);

	/* get max of 2 elements from the fifo */
	ret = kfifo_out(&test, buf, 2);
	printk(KERN_INFO "ret: %d\n", ret);
	/* and put it back to the end of the fifo */
	ret = kfifo_in(&test, buf, ret);
	printk(KERN_INFO "ret: %d\n", ret);

	/* put values into the fifo until is full */
	for (i = 20; kfifo_put(&test, &i); i++)
		;

	printk(KERN_INFO "queue len: %u\n", kfifo_len(&test));

	/* print out all values in the fifo */
	while (kfifo_get(&test, &i))
		printk("%d ", i);
	printk("\n");

	return 0;
}