Пример #1
0
/*
 * gs_buf_put
 *
 * Copy data data from a user buffer and put it into the circular buffer.
 * Restrict to the amount of space available.
 *
 * Return the number of bytes copied.
 */
static unsigned gs_buf_put(struct gs_buf *gb, const char *buf, unsigned count)
{
	unsigned len;

	/* USB deactived, gs buffer is freed by gs_close */
	if (gb->buf_buf == NULL)
	{
		return 0;
	}

	len = gs_buf_space_avail(gb);
	if (count > len)
		count = len;

	if (count == 0)
		return 0;

	len = gb->buf_buf + gb->buf_size - gb->buf_put;
	if (count > len) {
		memcpy(gb->buf_put, buf, len);
		memcpy(gb->buf_buf, buf + len, count - len);
		gb->buf_put = gb->buf_buf + count - len;
	} else {
		memcpy(gb->buf_put, buf, count);
		if (count < len)
			gb->buf_put += count;
		else		/* count == len */
			gb->buf_put = gb->buf_buf;
	}

	return count;
}
Пример #2
0
/*
 * gs_buf_put
 *
 * Copy data data from a user buffer and put it into the circular buffer.
 * Restrict to the amount of space available.
 *
 * Return the number of bytes copied.
 */
static unsigned
gs_buf_put(struct gs_buf *gb, const char *buf, unsigned count)
{
	unsigned len;

	len  = gs_buf_space_avail(gb);
	if (count > len)
		count = len;

	if (count == 0)
		return 0;

	len = gb->buf_buf + gb->buf_size - gb->buf_put;
	if (count > len) {
		memcpy(gb->buf_put, buf, len);
		memcpy(gb->buf_buf, buf+len, count - len);
		gb->buf_put = gb->buf_buf + count - len;
	} else {
		memcpy(gb->buf_put, buf, count);
		if (count < len)
			gb->buf_put += count;
		else /* count == len */
			gb->buf_put = gb->buf_buf;
	}

	return count;
}
Пример #3
0
static int gs_write_room(struct tty_struct *tty)
{
	struct gs_port	*port = tty->driver_data;
	unsigned long	flags;
	int		room = 0;

	//ALPS00423739
	if(!port)
	{
		printk("ERROR!!! port is closed!! %s, line %d: port = %p\n", __func__, __LINE__, port);
		/*abort immediately after disconnect */
		return -EINVAL;
	}
	//ALPS00423739

	spin_lock_irqsave(&port->port_lock, flags);
	if (port->port_usb)
		room = gs_buf_space_avail(&port->port_write_buf);
	spin_unlock_irqrestore(&port->port_lock, flags);

	pr_vdebug("gs_write_room: (%d,%p) room=%d\n",
		port->port_num, tty, room);

	return room;
}
Пример #4
0
static int gs_write_room(struct tty_struct *tty)
{
	struct gs_port	*port = NULL;
	unsigned long	flags;
	int		room = 0;

	if(!tty){
		pr_err("%s error: wrong parameter! *tty=0x%x", __func__, (unsigned int) tty);
		return 0;
	}
	port = tty->driver_data;
	if(!port){
		pr_err("%s error: port = NULL! already closed??\n", __func__);
		return 0;
	}

	spin_lock_irqsave(&port->port_lock, flags);
	if (port->port_usb)
		room = gs_buf_space_avail(&port->port_write_buf);
	spin_unlock_irqrestore(&port->port_lock, flags);

	pr_vdebug("gs_write_room: (%d,%p) room=%d\n",
		port->port_num, tty, room);

	return room;
}
Пример #5
0
/*
 * gs_buf_putr
 *
 * As per gs_buf_put, but add '\r' to any '\n's
 */
static unsigned
gs_buf_putr(struct gs_buf *gb,const char *buf,unsigned count)
{
	unsigned i;
	unsigned j;
	unsigned ret;

	for(i = 0, j = 0; i < count; i++){
		if(buf[i] != '\n')
			continue;
		ret = gs_buf_put(gb,buf+j,i-j);
		if(ret !=i-j)
			return j+ret;
		j += ret;
		/* Do not lose an \n on a buffer seam. */
		if(gs_buf_space_avail(gb) < 2)
			return j;
		gs_buf_put(gb,"\r\n",2);
		j++;
	}

	if( j < count ){
		j += gs_buf_put(gb,buf+j, count = j);
	}
	return j;
}
Пример #6
0
static int gs_write_room(struct tty_struct *tty)
{
	struct gs_port	*port = tty->driver_data;
	unsigned long	flags;
	int		room = 0;

	spin_lock_irqsave(&port->port_lock, flags);
	if (port->port_usb)
		room = gs_buf_space_avail(&port->port_write_buf);
	spin_unlock_irqrestore(&port->port_lock, flags);

	pr_vdebug("gs_write_room: (%d,%p) room=%d\n",
		port->port_num, tty, room);

	return room;
}
static int gs_write_room(struct tty_struct *tty)
{
	struct gs_port	*port = tty->driver_data;
	unsigned long	flags;
	/* if usb not connect, return room available;
	   to avoid thread in sleep */
	int		room = WRITE_BUF_SIZE - 1;

	spin_lock_irqsave(&port->port_lock, flags);
	if (port->port_usb)
		room = gs_buf_space_avail(&port->port_write_buf);
	spin_unlock_irqrestore(&port->port_lock, flags);

	pr_vdebug("gs_write_room: (%d,%p) room=%d\n",
		port->port_num, tty, room);

	return room;
}
static void gs_console_write(struct console *co,
					const char *buf, unsigned count)
{
    struct gs_port *port = ports[ACM_CONSOLE_IDX].port;
    unsigned long flags;
    int no_data = 0;

    if (count == 0 || NULL == port)
		return;

    /* write the data to usb console buffer */
    spin_lock_irqsave(&gs_console_ctx.lock, flags);
    if (gs_buf_space_avail(&gs_console_ctx.buf_info) < count) {
        port->stat_con_write_no_room++;
        no_data = 1;
    }
    (void)gs_buf_put(&gs_console_ctx.buf_info, buf, count);
    spin_unlock_irqrestore(&gs_console_ctx.lock, flags);

    /* we can delay a little time to get the more msg */
    if (!no_data)
        schedule_delayed_work(&gs_console_ctx.write_work, 1);
    return;
}