本文整理汇总了C++中CIRC_CNT_TO_END函数的典型用法代码示例。如果您正苦于以下问题:C++ CIRC_CNT_TO_END函数的具体用法?C++ CIRC_CNT_TO_END怎么用?C++ CIRC_CNT_TO_END使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CIRC_CNT_TO_END函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copy_sleep_history
static int copy_sleep_history(struct sleep_history *buf, int count)
{
int c, err;
int head, tail;
struct sleep_history *ring_buf;
if (!buf) {
err = -EINVAL;
goto err_invalid;
}
memset(buf, 0, count * sizeof(struct sleep_history));
ring_buf = (struct sleep_history *)(sleep_history_data.sleep_history.buf);
head = sleep_history_data.sleep_history.head;
tail = sleep_history_data.sleep_history.tail;
c = CIRC_CNT(head, tail, SLEEP_HISTORY_RINGBUFFER_SIZE);
if (c == 0) {
err = -EINVAL;
goto err_read;
} else if (c == SLEEP_HISTORY_RINGBUFFER_SIZE - 1) {
c = CIRC_CNT_TO_END(head, tail, SLEEP_HISTORY_RINGBUFFER_SIZE);
memcpy(buf, ring_buf + tail, c * sizeof(struct sleep_history));
memcpy(buf + c, ring_buf,
(SLEEP_HISTORY_RINGBUFFER_SIZE-c) * sizeof(struct sleep_history));
c = SLEEP_HISTORY_RINGBUFFER_SIZE - 1;
} else
memcpy(buf, ring_buf + tail, c * sizeof(struct sleep_history));
return c;
err_invalid:
err_read:
return err;
}
示例2: tegra_start_next_tx
/* Called with u->lock taken */
static void tegra_start_next_tx(struct tegra_uart_port *t)
{
unsigned long tail;
unsigned long count;
struct circ_buf *xmit;
xmit = &t->uport.state->xmit;
tail = (unsigned long)&xmit->buf[xmit->tail];
count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
dev_vdbg(t->uport.dev, "+%s %lu %d\n", __func__, count,
t->tx_in_progress);
if (count == 0)
goto out;
if (!t->use_tx_dma || count < TEGRA_UART_MIN_DMA)
tegra_start_pio_tx(t, count);
else if (BYTES_TO_ALIGN(tail) > 0)
tegra_start_pio_tx(t, BYTES_TO_ALIGN(tail));
else
tegra_start_dma_tx(t, count);
out:
dev_vdbg(t->uport.dev, "-%s", __func__);
}
示例3: uart_task_action
static void uart_task_action(unsigned long data)
{
struct uart_pxa_port *up = (struct uart_pxa_port *)data;
struct circ_buf *xmit = &up->port.state->xmit;
unsigned char *tmp = up->uart_dma.txdma_addr;
unsigned long flags;
int count = 0, c;
/* if the tx is stop, just return.*/
if (up->uart_dma.tx_stop)
return;
spin_lock_irqsave(&up->port.lock, flags);
if (up->uart_dma.dma_status & TX_DMA_RUNNING) {
spin_unlock_irqrestore(&up->port.lock, flags);
return;
}
up->uart_dma.dma_status |= TX_DMA_RUNNING;
while (1) {
c = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
if (c <= 0)
break;
memcpy(tmp, xmit->buf + xmit->tail, c);
xmit->tail = (xmit->tail + c) & (UART_XMIT_SIZE - 1);
tmp += c;
count += c;
up->port.icount.tx += c;
}
spin_unlock_irqrestore(&up->port.lock, flags);
pr_debug("count =%d", count);
pxa_uart_transmit_dma_start(up, count);
}
示例4: stmp_appuart_copy_tx
static int stmp_appuart_copy_tx(struct uart_port *u, u8 *target,
int tx_buffer_size)
{
int last = 0, portion;
struct circ_buf *xmit = &u->info->xmit;
while (last < tx_buffer_size) { /* let's fill the only descriptor */
if (u->x_char) {
target[last++] = u->x_char;
u->x_char = 0;
} else if (!uart_circ_empty(xmit) && !uart_tx_stopped(u)) {
portion = min((u32)tx_buffer_size,
(u32)uart_circ_chars_pending(xmit));
portion = min((u32)portion,
(u32)CIRC_CNT_TO_END(xmit->head, xmit->tail,
UART_XMIT_SIZE));
memcpy(target + last, &xmit->buf[xmit->tail], portion);
xmit->tail = (xmit->tail + portion) &
(UART_XMIT_SIZE - 1);
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
uart_write_wakeup(u);
last += portion;
} else { /* All tx data copied into buffer */
return last;
}
}
return last;
}
示例5: spi_read
static int spi_read(struct bathos_pipe *pipe, char *buf, int len)
{
struct spi_data *data = &spi_data;
int flags;
int l;
interrupt_disable(flags);
l = min(len, CIRC_CNT_TO_END(data->cbufrx.head, data->cbufrx.tail,
SPI_BUF_SIZE));
if (!l) {
interrupt_restore(flags);
return -EAGAIN;
}
memcpy(buf, &data->bufrx[data->cbufrx.tail], l);
data->cbufrx.tail = (data->cbufrx.tail + l) & (SPI_BUF_SIZE - 1);
data->overrun = 0;
if (CIRC_CNT(data->cbufrx.head, data->cbufrx.tail, SPI_BUF_SIZE))
pipe_dev_trigger_event(&__spi_dev, &evt_pipe_input_ready,
EVT_PRIO_MAX);
interrupt_restore(flags);
return l;
}
示例6: main
/********************************************************************************
* Description:
* Input Args:
* Output Args:
* Return Value:
********************************************************************************/
int main (int argc, char **argv)
{
int i, len;
struct circ_buf tx_ring;
char data[LEN];
char buf[LEN];
memset(&tx_ring, 0, sizeof(struct circ_buf));
tx_ring.buf = malloc(CIRC_BUF_SIZE);
if( NULL == tx_ring.buf )
{
printf("Allocate Ring buffer failure.\n");
return -1;
}
memset(data, 0, sizeof(data));
/* Prepare for the data */
for(i=0; i<sizeof(data); i++)
{
data[i] = 30+i;
}
printf("CIRC_SPACE: %d\n", CIRC_SPACE(tx_ring.head, tx_ring.tail, CIRC_BUF_SIZE));
printf("CIRC_SPACE_TO_END: %d\n", CIRC_SPACE_TO_END(tx_ring.head, tx_ring.tail, CIRC_BUF_SIZE));
printf("CIRC_CNT: %d\n", CIRC_CNT(tx_ring.head, tx_ring.tail, CIRC_BUF_SIZE));
printf("CIRC_CNT_TO_END: %d\n", CIRC_CNT_TO_END(tx_ring.head, tx_ring.tail, CIRC_BUF_SIZE));
while(1)
{
produce_item(&tx_ring, data, sizeof(data));
len = consume_item(&tx_ring, buf, sizeof(buf) );
sleep(1);
}
return 0;
} /* ----- End of main() ----- */
示例7: userio_char_read
static ssize_t userio_char_read(struct file *file, char __user *user_buffer,
size_t count, loff_t *ppos)
{
struct userio_device *userio = file->private_data;
int error;
size_t nonwrap_len, copylen;
unsigned char buf[USERIO_BUFSIZE];
unsigned long flags;
/*
* By the time we get here, the data that was waiting might have
* been taken by another thread. Grab the buffer lock and check if
* there's still any data waiting, otherwise repeat this process
* until we have data (unless the file descriptor is non-blocking
* of course).
*/
for (;;) {
spin_lock_irqsave(&userio->buf_lock, flags);
nonwrap_len = CIRC_CNT_TO_END(userio->head,
userio->tail,
USERIO_BUFSIZE);
copylen = min(nonwrap_len, count);
if (copylen) {
memcpy(buf, &userio->buf[userio->tail], copylen);
userio->tail = (userio->tail + copylen) %
USERIO_BUFSIZE;
}
spin_unlock_irqrestore(&userio->buf_lock, flags);
if (nonwrap_len)
break;
/* buffer was/is empty */
if (file->f_flags & O_NONBLOCK)
return -EAGAIN;
/*
* count == 0 is special - no IO is done but we check
* for error conditions (see above).
*/
if (count == 0)
return 0;
error = wait_event_interruptible(userio->waitq,
userio->head != userio->tail);
if (error)
return error;
}
if (copylen)
if (copy_to_user(user_buffer, buf, copylen))
return -EFAULT;
return copylen;
}
示例8: whitebox_user_source_data_available
size_t whitebox_user_source_data_available(struct whitebox_user_source *user_source,
unsigned long *src)
{
long head, tail, data;
head = ACCESS_ONCE(user_source->buf.head);
tail = user_source->buf.tail;
data = CIRC_CNT_TO_END(head, tail, user_source->buf_size);
d_printk(7, "%ld\n", data);
*src = (long)user_source->buf.buf + tail;
return data;
}
示例9: serial8250_tx_dma
int serial8250_tx_dma(struct uart_8250_port *p)
{
struct uart_8250_dma *dma = p->dma;
struct circ_buf *xmit = &p->port.state->xmit;
struct dma_async_tx_descriptor *desc;
int ret;
if (dma->tx_running)
return 0;
if (uart_tx_stopped(&p->port) || uart_circ_empty(xmit)) {
/* We have been called from __dma_tx_complete() */
serial8250_rpm_put_tx(p);
return 0;
}
dma->tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
desc = dmaengine_prep_slave_single(dma->txchan,
dma->tx_addr + xmit->tail,
dma->tx_size, DMA_MEM_TO_DEV,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
if (!desc) {
ret = -EBUSY;
goto err;
}
dma->tx_running = 1;
desc->callback = __dma_tx_complete;
desc->callback_param = p;
dma->tx_cookie = dmaengine_submit(desc);
dma_sync_single_for_device(dma->txchan->device->dev, dma->tx_addr,
UART_XMIT_SIZE, DMA_TO_DEVICE);
dma_async_issue_pending(dma->txchan);
if (dma->tx_err) {
dma->tx_err = 0;
if (p->ier & UART_IER_THRI) {
p->ier &= ~UART_IER_THRI;
serial_out(p, UART_IER, p->ier);
}
}
return 0;
err:
dma->tx_err = 1;
return ret;
}
示例10: sprd_tx_buf_remap
static int sprd_tx_buf_remap(struct uart_port *port)
{
struct sprd_uart_port *sp =
container_of(port, struct sprd_uart_port, port);
struct circ_buf *xmit = &port->state->xmit;
sp->tx_dma.trans_len =
CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
sp->tx_dma.phys_addr = dma_map_single(port->dev,
(void *)&(xmit->buf[xmit->tail]),
sp->tx_dma.trans_len,
DMA_TO_DEVICE);
return dma_mapping_error(port->dev, sp->tx_dma.phys_addr);
}
示例11: transmit_chars_write
static void transmit_chars_write(struct uart_port *port, struct circ_buf *xmit)
{
while (!uart_circ_empty(xmit)) {
unsigned long ra = __pa(xmit->buf + xmit->tail);
unsigned long len, status, sent;
len = CIRC_CNT_TO_END(xmit->head, xmit->tail,
UART_XMIT_SIZE);
status = sun4v_con_write(ra, len, &sent);
if (status != HV_EOK)
break;
xmit->tail = (xmit->tail + sent) & (UART_XMIT_SIZE - 1);
port->icount.tx += sent;
}
}
示例12: tegra_tcu_uart_start_tx
static void tegra_tcu_uart_start_tx(struct uart_port *port)
{
struct tegra_tcu *tcu = port->private_data;
struct circ_buf *xmit = &port->state->xmit;
unsigned long count;
for (;;) {
count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
if (!count)
break;
tegra_tcu_write(tcu, &xmit->buf[xmit->tail], count);
xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
}
uart_write_wakeup(port);
}
示例13: serial_buf_get
/*
* serial_buf_get
*
* Get data from the circular buffer and copy to the given buffer.
* Restrict to the amount of data available.
*
* Return the number of bytes copied.
*/
static int serial_buf_get(struct circ_buf *cb, char *buf, int count)
{
int c, ret = 0;
while (1) {
c = CIRC_CNT_TO_END(cb->head, cb->tail, AIRCABLE_BUF_SIZE);
if (count < c)
c = count;
if (c <= 0)
break;
memcpy(buf, cb->buf + cb->tail, c);
cb->tail = (cb->tail + c) & (AIRCABLE_BUF_SIZE-1);
buf += c;
count -= c;
ret= c;
}
return ret;
}
示例14: arcmsr_sysfs_iop_message_read
static ssize_t arcmsr_sysfs_iop_message_read(struct file *filp,
struct kobject *kobj,
struct bin_attribute *bin,
char *buf, loff_t off,
size_t count)
{
struct device *dev = container_of(kobj,struct device,kobj);
struct Scsi_Host *host = class_to_shost(dev);
struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
uint8_t *ptmpQbuffer;
int32_t allxfer_len = 0;
unsigned long flags;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
/* do message unit read. */
ptmpQbuffer = (uint8_t *)buf;
spin_lock_irqsave(&acb->rqbuffer_lock, flags);
if (acb->rqbuf_getIndex != acb->rqbuf_putIndex) {
unsigned int tail = acb->rqbuf_getIndex;
unsigned int head = acb->rqbuf_putIndex;
unsigned int cnt_to_end = CIRC_CNT_TO_END(head, tail, ARCMSR_MAX_QBUFFER);
allxfer_len = CIRC_CNT(head, tail, ARCMSR_MAX_QBUFFER);
if (allxfer_len > ARCMSR_API_DATA_BUFLEN)
allxfer_len = ARCMSR_API_DATA_BUFLEN;
if (allxfer_len <= cnt_to_end)
memcpy(ptmpQbuffer, acb->rqbuffer + tail, allxfer_len);
else {
memcpy(ptmpQbuffer, acb->rqbuffer + tail, cnt_to_end);
memcpy(ptmpQbuffer + cnt_to_end, acb->rqbuffer, allxfer_len - cnt_to_end);
}
acb->rqbuf_getIndex = (acb->rqbuf_getIndex + allxfer_len) % ARCMSR_MAX_QBUFFER;
}
if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) {
struct QBUFFER __iomem *prbuffer;
acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW;
prbuffer = arcmsr_get_iop_rqbuffer(acb);
if (arcmsr_Read_iop_rqbuffer_data(acb, prbuffer) == 0)
acb->acb_flags |= ACB_F_IOPDATA_OVERFLOW;
}
spin_unlock_irqrestore(&acb->rqbuffer_lock, flags);
return allxfer_len;
}
示例15: iforce_usb_xmit
void iforce_usb_xmit(struct iforce *iforce)
{
int n, c;
unsigned long flags;
spin_lock_irqsave(&iforce->xmit_lock, flags);
if (iforce->xmit.head == iforce->xmit.tail) {
clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
spin_unlock_irqrestore(&iforce->xmit_lock, flags);
return;
}
((char *)iforce->out->transfer_buffer)[0] = iforce->xmit.buf[iforce->xmit.tail];
XMIT_INC(iforce->xmit.tail, 1);
n = iforce->xmit.buf[iforce->xmit.tail];
XMIT_INC(iforce->xmit.tail, 1);
iforce->out->transfer_buffer_length = n + 1;
iforce->out->dev = iforce->usbdev;
/* Copy rest of data then */
c = CIRC_CNT_TO_END(iforce->xmit.head, iforce->xmit.tail, XMIT_SIZE);
if (n < c) c=n;
memcpy(iforce->out->transfer_buffer + 1,
&iforce->xmit.buf[iforce->xmit.tail],
c);
if (n != c) {
memcpy(iforce->out->transfer_buffer + 1 + c,
&iforce->xmit.buf[0],
n-c);
}
XMIT_INC(iforce->xmit.tail, n);
if ( (n=usb_submit_urb(iforce->out, GFP_ATOMIC)) ) {
clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
dev_warn(&iforce->intf->dev, "usb_submit_urb failed %d\n", n);
}
/* The IFORCE_XMIT_RUNNING bit is not cleared here. That's intended.
* As long as the urb completion handler is not called, the transmiting
* is considered to be running */
spin_unlock_irqrestore(&iforce->xmit_lock, flags);
}