mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
mm/circbuf: delete underscore about circular buffer naming conventions
N/A Change-Id: I66e08cdbe8b4c23948ebc20c2a29d9ef9f4156ab Signed-off-by: dongjiuzhu <dongjiuzhu1@xiaomi.com>
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
menuconfig DRIVERS_RC
|
||||
bool "Remote Control Device Support"
|
||||
select MM_CIRC_BUF
|
||||
select MM_CIRCBUF
|
||||
default n
|
||||
---help---
|
||||
Drivers for various remote control
|
||||
|
||||
+14
-14
@@ -30,8 +30,8 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/mm/circbuf.h>
|
||||
#include <nuttx/rc/lirc_dev.h>
|
||||
#include <nuttx/mm/circ_buf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@@ -63,7 +63,7 @@ struct lirc_fh_s
|
||||
{
|
||||
struct list_node node; /* list of open file handles */
|
||||
FAR struct lirc_lowerhalf_s *lower; /* the pointer to lirc_lowerhalf_s */
|
||||
struct circ_buf_s buffer; /* buffer for incoming IR */
|
||||
struct circbuf_s buffer; /* buffer for incoming IR */
|
||||
FAR struct pollfd *fd; /* poll structures of threads waiting for driver events */
|
||||
sem_t waitsem; /* sem of wait buffer for ready */
|
||||
int carrier_low; /* when setting the carrier range, first the low end must be
|
||||
@@ -164,7 +164,7 @@ static int lirc_open(FAR struct file *filep)
|
||||
fh->send_mode = LIRC_MODE_PULSE;
|
||||
}
|
||||
|
||||
ret = circ_buf_init(&fh->buffer, NULL, lower->buffer_bytes);
|
||||
ret = circbuf_init(&fh->buffer, NULL, lower->buffer_bytes);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto buffer_err;
|
||||
@@ -194,7 +194,7 @@ static int lirc_open(FAR struct file *filep)
|
||||
|
||||
open_err:
|
||||
nxsem_destroy(&fh->waitsem);
|
||||
circ_buf_uninit(&fh->buffer);
|
||||
circbuf_uninit(&fh->buffer);
|
||||
buffer_err:
|
||||
kmm_free(fh);
|
||||
return ret;
|
||||
@@ -213,7 +213,7 @@ static int lirc_close(FAR struct file *filep)
|
||||
leave_critical_section(flags);
|
||||
|
||||
nxsem_destroy(&fh->waitsem);
|
||||
circ_buf_uninit(&fh->buffer);
|
||||
circbuf_uninit(&fh->buffer);
|
||||
|
||||
kmm_free(fh);
|
||||
if (list_is_empty(&upper->fh))
|
||||
@@ -244,7 +244,7 @@ static int lirc_poll(FAR struct file *filep,
|
||||
fh->fd = fds;
|
||||
fds->priv = &fh->fd;
|
||||
|
||||
if (!circ_buf_is_empty(&fh->buffer))
|
||||
if (!circbuf_is_empty(&fh->buffer))
|
||||
{
|
||||
eventset = (fds->events & (POLLIN | POLLRDNORM));
|
||||
}
|
||||
@@ -688,7 +688,7 @@ static ssize_t lirc_read_scancode(FAR struct file *filep, FAR char *buffer,
|
||||
flags = enter_critical_section();
|
||||
do
|
||||
{
|
||||
if (circ_buf_is_empty(&fh->buffer))
|
||||
if (circbuf_is_empty(&fh->buffer))
|
||||
{
|
||||
if (filep->f_oflags & O_NONBLOCK)
|
||||
{
|
||||
@@ -703,7 +703,7 @@ static ssize_t lirc_read_scancode(FAR struct file *filep, FAR char *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
len = circ_buf_read(&fh->buffer, buffer, length);
|
||||
len = circbuf_read(&fh->buffer, buffer, length);
|
||||
}
|
||||
while (len <= 0);
|
||||
|
||||
@@ -728,7 +728,7 @@ static ssize_t lirc_read_mode2(FAR struct file *filep, FAR char *buffer,
|
||||
flags = enter_critical_section();
|
||||
do
|
||||
{
|
||||
if (circ_buf_is_empty(&fh->buffer))
|
||||
if (circbuf_is_empty(&fh->buffer))
|
||||
{
|
||||
if (filep->f_oflags & O_NONBLOCK)
|
||||
{
|
||||
@@ -743,7 +743,7 @@ static ssize_t lirc_read_mode2(FAR struct file *filep, FAR char *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
len = circ_buf_read(&fh->buffer, buffer, length);
|
||||
len = circbuf_read(&fh->buffer, buffer, length);
|
||||
}
|
||||
while (len <= 0);
|
||||
|
||||
@@ -936,7 +936,7 @@ void lirc_raw_event(FAR struct lirc_lowerhalf_s *lower,
|
||||
list_for_every_safe(&upper->fh, node, tmp)
|
||||
{
|
||||
fh = (FAR struct lirc_fh_s *)node;
|
||||
if (circ_buf_write(&fh->buffer, &gap, sizeof(int)) > 0)
|
||||
if (circbuf_write(&fh->buffer, &gap, sizeof(int)) > 0)
|
||||
{
|
||||
lirc_pollnotify(fh, POLLIN | POLLRDNORM);
|
||||
nxsem_get_value(&fh->waitsem, &semcount);
|
||||
@@ -964,7 +964,7 @@ void lirc_raw_event(FAR struct lirc_lowerhalf_s *lower,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (circ_buf_write(&fh->buffer, &sample, sizeof(unsigned int)) > 0)
|
||||
if (circbuf_write(&fh->buffer, &sample, sizeof(unsigned int)) > 0)
|
||||
{
|
||||
lirc_pollnotify(fh, POLLIN | POLLRDNORM);
|
||||
nxsem_get_value(&fh->waitsem, &semcount);
|
||||
@@ -1008,7 +1008,7 @@ void lirc_scancode_event(FAR struct lirc_lowerhalf_s *lower,
|
||||
list_for_every_safe(&upper->fh, node, tmp)
|
||||
{
|
||||
fh = (FAR struct lirc_fh_s *)node;
|
||||
if (circ_buf_write(&fh->buffer, lsc, sizeof(*lsc)) > 0)
|
||||
if (circbuf_write(&fh->buffer, lsc, sizeof(*lsc)) > 0)
|
||||
{
|
||||
lirc_pollnotify(fh, POLLIN | POLLRDNORM);
|
||||
nxsem_get_value(&fh->waitsem, &semcount);
|
||||
@@ -1054,7 +1054,7 @@ void lirc_sample_event(FAR struct lirc_lowerhalf_s *lower,
|
||||
list_for_every_safe(&upper->fh, node, tmp)
|
||||
{
|
||||
fh = (FAR struct lirc_fh_s *)node;
|
||||
if (circ_buf_write(&fh->buffer, &sample, sizeof(unsigned int)) > 0)
|
||||
if (circbuf_write(&fh->buffer, &sample, sizeof(unsigned int)) > 0)
|
||||
{
|
||||
lirc_pollnotify(fh, POLLIN | POLLRDNORM);
|
||||
nxsem_get_value(&fh->waitsem, &semcount);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
menuconfig SENSORS
|
||||
bool "Sensor Device Support"
|
||||
select MM_CIRC_BUF
|
||||
select MM_CIRCBUF
|
||||
default n
|
||||
---help---
|
||||
Drivers for various sensors
|
||||
|
||||
+13
-13
@@ -34,8 +34,8 @@
|
||||
#include <poll.h>
|
||||
#include <fcntl.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/mm/circbuf.h>
|
||||
#include <nuttx/sensors/sensor.h>
|
||||
#include <nuttx/mm/circ_buf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@@ -68,7 +68,7 @@ struct sensor_upperhalf_s
|
||||
|
||||
FAR struct pollfd *fds[CONFIG_SENSORS_NPOLLWAITERS];
|
||||
FAR struct sensor_lowerhalf_s *lower; /* the handle of lower half driver */
|
||||
struct circ_buf_s buffer; /* The circular buffer of sensor device */
|
||||
struct circbuf_s buffer; /* The circular buffer of sensor device */
|
||||
uint8_t esize; /* The element size of circular buffer */
|
||||
uint8_t crefs; /* Number of times the device has been opened */
|
||||
sem_t exclsem; /* Manages exclusive access to file operations */
|
||||
@@ -195,7 +195,7 @@ static int sensor_open(FAR struct file *filep)
|
||||
{
|
||||
/* Initialize sensor buffer */
|
||||
|
||||
ret = circ_buf_init(&upper->buffer, NULL, lower->buffer_size);
|
||||
ret = circbuf_init(&upper->buffer, NULL, lower->buffer_size);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto err;
|
||||
@@ -228,7 +228,7 @@ static int sensor_close(FAR struct file *filep)
|
||||
if (ret >= 0)
|
||||
{
|
||||
upper->enabled = false;
|
||||
circ_buf_uninit(&upper->buffer);
|
||||
circbuf_uninit(&upper->buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ static ssize_t sensor_read(FAR struct file *filep, FAR char *buffer,
|
||||
* that have just entered the buffer.
|
||||
*/
|
||||
|
||||
while (circ_buf_is_empty(&upper->buffer))
|
||||
while (circbuf_is_empty(&upper->buffer))
|
||||
{
|
||||
if (filep->f_oflags & O_NONBLOCK)
|
||||
{
|
||||
@@ -307,7 +307,7 @@ static ssize_t sensor_read(FAR struct file *filep, FAR char *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
ret = circ_buf_read(&upper->buffer, buffer, len);
|
||||
ret = circbuf_read(&upper->buffer, buffer, len);
|
||||
|
||||
/* Release some buffer space when current mode isn't batch mode
|
||||
* and last mode is batch mode, and the number of bytes avaliable
|
||||
@@ -315,10 +315,10 @@ static ssize_t sensor_read(FAR struct file *filep, FAR char *buffer,
|
||||
*/
|
||||
|
||||
if (upper->latency == 0 &&
|
||||
circ_buf_size(&upper->buffer) > lower->buffer_size &&
|
||||
circ_buf_used(&upper->buffer) <= lower->buffer_size)
|
||||
circbuf_size(&upper->buffer) > lower->buffer_size &&
|
||||
circbuf_used(&upper->buffer) <= lower->buffer_size)
|
||||
{
|
||||
ret = circ_buf_resize(&upper->buffer, lower->buffer_size);
|
||||
ret = circbuf_resize(&upper->buffer, lower->buffer_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
upper->interval * upper->esize +
|
||||
lower->buffer_size, upper->esize);
|
||||
|
||||
ret = circ_buf_resize(&upper->buffer, bytes);
|
||||
ret = circbuf_resize(&upper->buffer, bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -421,7 +421,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
if (*val != 0)
|
||||
{
|
||||
lower->buffer_size = ROUNDUP(*val, upper->esize);
|
||||
ret = circ_buf_resize(&upper->buffer, lower->buffer_size);
|
||||
ret = circbuf_resize(&upper->buffer, lower->buffer_size);
|
||||
if (ret >= 0)
|
||||
{
|
||||
*val = lower->buffer_size;
|
||||
@@ -504,7 +504,7 @@ static int sensor_poll(FAR struct file *filep,
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!circ_buf_is_empty(&upper->buffer))
|
||||
else if (!circbuf_is_empty(&upper->buffer))
|
||||
{
|
||||
eventset |= (fds->events & POLLIN);
|
||||
}
|
||||
@@ -543,7 +543,7 @@ static void sensor_push_event(FAR void *priv, FAR const void *data,
|
||||
return;
|
||||
}
|
||||
|
||||
circ_buf_overwrite(&upper->buffer, data, bytes);
|
||||
circbuf_overwrite(&upper->buffer, data, bytes);
|
||||
sensor_pollnotify(upper, POLLIN);
|
||||
nxsem_get_value(&upper->buffersem, &semcount);
|
||||
if (semcount < 1)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/mm/circ_buf.h
|
||||
* include/nuttx/mm/circbuf.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
@@ -18,8 +18,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_MM_CIRC_BUF_H
|
||||
#define __INCLUDE_NUTTX_MM_CIRC_BUF_H
|
||||
#ifndef __INCLUDE_NUTTX_MM_CIRCBUF_H
|
||||
#define __INCLUDE_NUTTX_MM_CIRCBUF_H
|
||||
|
||||
/* Note about locking: There is no locking required while only one reader
|
||||
* and one writer is using the circular buffer.
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
/* This structure describes circular buffer */
|
||||
|
||||
struct circ_buf_s
|
||||
struct circbuf_s
|
||||
{
|
||||
FAR void *base; /* The pointer to buffer space */
|
||||
size_t size; /* The size of buffer space */
|
||||
@@ -64,7 +64,7 @@ extern "C"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_init
|
||||
* Name: circbuf_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize a circular buffer.
|
||||
@@ -82,11 +82,11 @@ extern "C"
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int circ_buf_init(FAR struct circ_buf_s *circ,
|
||||
int circbuf_init(FAR struct circbuf_s *circ,
|
||||
FAR void *base, size_t bytes);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_resize
|
||||
* Name: circbuf_resize
|
||||
*
|
||||
* Description:
|
||||
* Resize a circular buffer (change buffer size).
|
||||
@@ -100,10 +100,10 @@ int circ_buf_init(FAR struct circ_buf_s *circ,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int circ_buf_resize(FAR struct circ_buf_s *circ, size_t bytes);
|
||||
int circbuf_resize(FAR struct circbuf_s *circ, size_t bytes);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_uninit
|
||||
* Name: circbuf_uninit
|
||||
*
|
||||
* Description:
|
||||
* Free the circular buffer.
|
||||
@@ -112,10 +112,10 @@ int circ_buf_resize(FAR struct circ_buf_s *circ, size_t bytes);
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
void circ_buf_uninit(FAR struct circ_buf_s *circ);
|
||||
void circbuf_uninit(FAR struct circbuf_s *circ);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_reset
|
||||
* Name: circbuf_reset
|
||||
*
|
||||
* Description:
|
||||
* Remove the entire circular buffer content.
|
||||
@@ -124,10 +124,10 @@ void circ_buf_uninit(FAR struct circ_buf_s *circ);
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
void circ_buf_reset(FAR struct circ_buf_s *circ);
|
||||
void circbuf_reset(FAR struct circbuf_s *circ);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_is_full
|
||||
* Name: circbuf_is_full
|
||||
*
|
||||
* Description:
|
||||
* Return true if the circular buffer is full.
|
||||
@@ -136,10 +136,10 @@ void circ_buf_reset(FAR struct circ_buf_s *circ);
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
bool circ_buf_is_full(FAR struct circ_buf_s *circ);
|
||||
bool circbuf_is_full(FAR struct circbuf_s *circ);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_is_empty
|
||||
* Name: circbuf_is_empty
|
||||
*
|
||||
* Description:
|
||||
* Return true if the circular buffer is empty.
|
||||
@@ -148,10 +148,10 @@ bool circ_buf_is_full(FAR struct circ_buf_s *circ);
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
bool circ_buf_is_empty(FAR struct circ_buf_s *circ);
|
||||
bool circbuf_is_empty(FAR struct circbuf_s *circ);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_size
|
||||
* Name: circbuf_size
|
||||
*
|
||||
* Description:
|
||||
* Return size of the circular buffer.
|
||||
@@ -160,10 +160,10 @@ bool circ_buf_is_empty(FAR struct circ_buf_s *circ);
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
size_t circ_buf_size(FAR struct circ_buf_s *circ);
|
||||
size_t circbuf_size(FAR struct circbuf_s *circ);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_used
|
||||
* Name: circbuf_used
|
||||
*
|
||||
* Description:
|
||||
* Return the used bytes of the circular buffer.
|
||||
@@ -172,10 +172,10 @@ size_t circ_buf_size(FAR struct circ_buf_s *circ);
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
size_t circ_buf_used(FAR struct circ_buf_s *circ);
|
||||
size_t circbuf_used(FAR struct circbuf_s *circ);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_space
|
||||
* Name: circbuf_space
|
||||
*
|
||||
* Description:
|
||||
* Return the remaing space of the circular buffer.
|
||||
@@ -184,10 +184,10 @@ size_t circ_buf_used(FAR struct circ_buf_s *circ);
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
size_t circ_buf_space(FAR struct circ_buf_s *circ);
|
||||
size_t circbuf_space(FAR struct circbuf_s *circ);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_peek
|
||||
* Name: circbuf_peek
|
||||
*
|
||||
* Description:
|
||||
* Get data form the circular buffer without removing
|
||||
@@ -206,11 +206,11 @@ size_t circ_buf_space(FAR struct circ_buf_s *circ);
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circ_buf_peek(FAR struct circ_buf_s *circ,
|
||||
ssize_t circbuf_peek(FAR struct circbuf_s *circ,
|
||||
FAR void *dst, size_t bytes);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_read
|
||||
* Name: circbuf_read
|
||||
*
|
||||
* Description:
|
||||
* Get data form the circular buffer.
|
||||
@@ -229,11 +229,11 @@ ssize_t circ_buf_peek(FAR struct circ_buf_s *circ,
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circ_buf_read(FAR struct circ_buf_s *circ,
|
||||
ssize_t circbuf_read(FAR struct circbuf_s *circ,
|
||||
FAR void *dst, size_t bytes);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_skip
|
||||
* Name: circbuf_skip
|
||||
*
|
||||
* Description:
|
||||
* Skip data form the circular buffer.
|
||||
@@ -251,10 +251,10 @@ ssize_t circ_buf_read(FAR struct circ_buf_s *circ,
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circ_buf_skip(FAR struct circ_buf_s *circ, size_t bytes);
|
||||
ssize_t circbuf_skip(FAR struct circbuf_s *circ, size_t bytes);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_write
|
||||
* Name: circbuf_write
|
||||
*
|
||||
* Description:
|
||||
* Write data to the circular buffer.
|
||||
@@ -273,18 +273,18 @@ ssize_t circ_buf_skip(FAR struct circ_buf_s *circ, size_t bytes);
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circ_buf_write(FAR struct circ_buf_s *circ,
|
||||
ssize_t circbuf_write(FAR struct circbuf_s *circ,
|
||||
FAR const void *src, size_t bytes);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_overwrite
|
||||
* Name: circbuf_overwrite
|
||||
*
|
||||
* Description:
|
||||
* Write data to the circular buffer. It can overwrite old data when
|
||||
* circular buffer don't have enough space to store data.
|
||||
*
|
||||
* Note:
|
||||
* Usage circ_buf_overwrite () is dangerous. It should be only called
|
||||
* Usage circbuf_overwrite () is dangerous. It should be only called
|
||||
* when the buffer is exclusived locked or when it is secured that no
|
||||
* other thread is accessing the buffer.
|
||||
*
|
||||
@@ -298,7 +298,7 @@ ssize_t circ_buf_write(FAR struct circ_buf_s *circ,
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circ_buf_overwrite(FAR struct circ_buf_s *circ,
|
||||
ssize_t circbuf_overwrite(FAR struct circbuf_s *circ,
|
||||
FAR const void *src, size_t bytes);
|
||||
|
||||
#undef EXTERN
|
||||
+1
-1
@@ -155,7 +155,7 @@ config MM_FILL_ALLOCATIONS
|
||||
Fill all malloc() allocations with 0xAA. This helps
|
||||
detecting uninitialized variable errors.
|
||||
|
||||
config MM_CIRC_BUF
|
||||
config MM_CIRCBUF
|
||||
bool "Circular buffer support"
|
||||
default n
|
||||
---help---
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ include kmm_heap/Make.defs
|
||||
include mm_gran/Make.defs
|
||||
include shm/Make.defs
|
||||
include iob/Make.defs
|
||||
include circ_buf/Make.defs
|
||||
include circbuf/Make.defs
|
||||
|
||||
BINDIR ?= bin
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
############################################################################
|
||||
# mm/circ_buf/Make.defs
|
||||
# mm/circbuf/Make.defs
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
@@ -20,11 +20,11 @@
|
||||
|
||||
# Circular buffer management
|
||||
|
||||
ifeq ($(CONFIG_MM_CIRC_BUF),y)
|
||||
CSRCS += circ_buf.c
|
||||
ifeq ($(CONFIG_MM_CIRCBUF),y)
|
||||
CSRCS += circbuf.c
|
||||
|
||||
# Add the circular buffer directory to the build
|
||||
|
||||
DEPPATH += --dep-path circ_buf
|
||||
VPATH += :circ_buf
|
||||
DEPPATH += --dep-path circbuf
|
||||
VPATH += :circbuf
|
||||
endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* mm/circ_buf/circ_buf.c
|
||||
* mm/circbuf/circbuf.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/mm/circ_buf.h>
|
||||
#include <nuttx/mm/circbuf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
@@ -43,7 +43,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_init
|
||||
* Name: circbuf_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize a circular buffer.
|
||||
@@ -61,7 +61,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int circ_buf_init(FAR struct circ_buf_s *circ, FAR void *base, size_t bytes)
|
||||
int circbuf_init(FAR struct circbuf_s *circ, FAR void *base, size_t bytes)
|
||||
{
|
||||
DEBUGASSERT(circ);
|
||||
DEBUGASSERT(!base || bytes);
|
||||
@@ -86,7 +86,7 @@ int circ_buf_init(FAR struct circ_buf_s *circ, FAR void *base, size_t bytes)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_resize
|
||||
* Name: circbuf_resize
|
||||
*
|
||||
* Description:
|
||||
* Resize a circular buffer (change buffer size).
|
||||
@@ -100,7 +100,7 @@ int circ_buf_init(FAR struct circ_buf_s *circ, FAR void *base, size_t bytes)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int circ_buf_resize(FAR struct circ_buf_s *circ, size_t bytes)
|
||||
int circbuf_resize(FAR struct circbuf_s *circ, size_t bytes)
|
||||
{
|
||||
FAR void *tmp;
|
||||
size_t len;
|
||||
@@ -114,14 +114,14 @@ int circ_buf_resize(FAR struct circ_buf_s *circ, size_t bytes)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
len = circ_buf_used(circ);
|
||||
len = circbuf_used(circ);
|
||||
if (bytes < len)
|
||||
{
|
||||
circ_buf_skip(circ, len - bytes);
|
||||
circbuf_skip(circ, len - bytes);
|
||||
len = bytes;
|
||||
}
|
||||
|
||||
circ_buf_read(circ, tmp, len);
|
||||
circbuf_read(circ, tmp, len);
|
||||
|
||||
kmm_free(circ->base);
|
||||
|
||||
@@ -134,7 +134,7 @@ int circ_buf_resize(FAR struct circ_buf_s *circ, size_t bytes)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_reset
|
||||
* Name: circbuf_reset
|
||||
*
|
||||
* Description:
|
||||
* Remove the entire circular buffer content.
|
||||
@@ -143,14 +143,14 @@ int circ_buf_resize(FAR struct circ_buf_s *circ, size_t bytes)
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
void circ_buf_reset(FAR struct circ_buf_s *circ)
|
||||
void circbuf_reset(FAR struct circbuf_s *circ)
|
||||
{
|
||||
DEBUGASSERT(circ);
|
||||
circ->head = circ->tail = 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_uninit
|
||||
* Name: circbuf_uninit
|
||||
*
|
||||
* Description:
|
||||
* Free the circular buffer.
|
||||
@@ -159,7 +159,7 @@ void circ_buf_reset(FAR struct circ_buf_s *circ)
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
void circ_buf_uninit(FAR struct circ_buf_s *circ)
|
||||
void circbuf_uninit(FAR struct circbuf_s *circ)
|
||||
{
|
||||
DEBUGASSERT(circ);
|
||||
|
||||
@@ -172,7 +172,7 @@ void circ_buf_uninit(FAR struct circ_buf_s *circ)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_size
|
||||
* Name: circbuf_size
|
||||
*
|
||||
* Description:
|
||||
* Return size of the circular buffer.
|
||||
@@ -181,14 +181,14 @@ void circ_buf_uninit(FAR struct circ_buf_s *circ)
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
size_t circ_buf_size(FAR struct circ_buf_s *circ)
|
||||
size_t circbuf_size(FAR struct circbuf_s *circ)
|
||||
{
|
||||
DEBUGASSERT(circ);
|
||||
return circ->size;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_used
|
||||
* Name: circbuf_used
|
||||
*
|
||||
* Description:
|
||||
* Return the used bytes of the circular buffer.
|
||||
@@ -197,14 +197,14 @@ size_t circ_buf_size(FAR struct circ_buf_s *circ)
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
size_t circ_buf_used(FAR struct circ_buf_s *circ)
|
||||
size_t circbuf_used(FAR struct circbuf_s *circ)
|
||||
{
|
||||
DEBUGASSERT(circ);
|
||||
return circ->head - circ->tail;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_space
|
||||
* Name: circbuf_space
|
||||
*
|
||||
* Description:
|
||||
* Return the remaing space of the circular buffer.
|
||||
@@ -213,13 +213,13 @@ size_t circ_buf_used(FAR struct circ_buf_s *circ)
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
size_t circ_buf_space(FAR struct circ_buf_s *circ)
|
||||
size_t circbuf_space(FAR struct circbuf_s *circ)
|
||||
{
|
||||
return circ_buf_size(circ) - circ_buf_used(circ);
|
||||
return circbuf_size(circ) - circbuf_used(circ);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_is_empty
|
||||
* Name: circbuf_is_empty
|
||||
*
|
||||
* Description:
|
||||
* Return true if the circular buffer is empty.
|
||||
@@ -228,13 +228,13 @@ size_t circ_buf_space(FAR struct circ_buf_s *circ)
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
bool circ_buf_is_empty(FAR struct circ_buf_s *circ)
|
||||
bool circbuf_is_empty(FAR struct circbuf_s *circ)
|
||||
{
|
||||
return !circ_buf_used(circ);
|
||||
return !circbuf_used(circ);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_is_full
|
||||
* Name: circbuf_is_full
|
||||
*
|
||||
* Description:
|
||||
* Return true if the circular buffer is full.
|
||||
@@ -243,13 +243,13 @@ bool circ_buf_is_empty(FAR struct circ_buf_s *circ)
|
||||
* circ - Address of the circular buffer to be used.
|
||||
****************************************************************************/
|
||||
|
||||
bool circ_buf_is_full(FAR struct circ_buf_s *circ)
|
||||
bool circbuf_is_full(FAR struct circbuf_s *circ)
|
||||
{
|
||||
return !circ_buf_space(circ);
|
||||
return !circbuf_space(circ);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_peek
|
||||
* Name: circbuf_peek
|
||||
*
|
||||
* Description:
|
||||
* Get data form the circular buffer without removing
|
||||
@@ -268,7 +268,7 @@ bool circ_buf_is_full(FAR struct circ_buf_s *circ)
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circ_buf_peek(FAR struct circ_buf_s *circ,
|
||||
ssize_t circbuf_peek(FAR struct circbuf_s *circ,
|
||||
FAR void *dst, size_t bytes)
|
||||
{
|
||||
size_t len;
|
||||
@@ -276,7 +276,7 @@ ssize_t circ_buf_peek(FAR struct circ_buf_s *circ,
|
||||
|
||||
DEBUGASSERT(circ);
|
||||
|
||||
len = circ_buf_used(circ);
|
||||
len = circbuf_used(circ);
|
||||
off = circ->tail % circ->size;
|
||||
|
||||
if (bytes > len)
|
||||
@@ -297,7 +297,7 @@ ssize_t circ_buf_peek(FAR struct circ_buf_s *circ,
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_read
|
||||
* Name: circbuf_read
|
||||
*
|
||||
* Description:
|
||||
* Get data form the circular buffer.
|
||||
@@ -316,20 +316,20 @@ ssize_t circ_buf_peek(FAR struct circ_buf_s *circ,
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circ_buf_read(FAR struct circ_buf_s *circ,
|
||||
ssize_t circbuf_read(FAR struct circbuf_s *circ,
|
||||
FAR void *dst, size_t bytes)
|
||||
{
|
||||
DEBUGASSERT(circ);
|
||||
DEBUGASSERT(dst || !bytes);
|
||||
|
||||
bytes = circ_buf_peek(circ, dst, bytes);
|
||||
bytes = circbuf_peek(circ, dst, bytes);
|
||||
circ->tail += bytes;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_skip
|
||||
* Name: circbuf_skip
|
||||
*
|
||||
* Description:
|
||||
* Skip data form the circular buffer.
|
||||
@@ -347,13 +347,13 @@ ssize_t circ_buf_read(FAR struct circ_buf_s *circ,
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circ_buf_skip(FAR struct circ_buf_s *circ, size_t bytes)
|
||||
ssize_t circbuf_skip(FAR struct circbuf_s *circ, size_t bytes)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
DEBUGASSERT(circ);
|
||||
|
||||
len = circ_buf_used(circ);
|
||||
len = circbuf_used(circ);
|
||||
|
||||
if (bytes > len)
|
||||
{
|
||||
@@ -366,7 +366,7 @@ ssize_t circ_buf_skip(FAR struct circ_buf_s *circ, size_t bytes)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_write
|
||||
* Name: circbuf_write
|
||||
*
|
||||
* Description:
|
||||
* Write data to the circular buffer.
|
||||
@@ -385,7 +385,7 @@ ssize_t circ_buf_skip(FAR struct circ_buf_s *circ, size_t bytes)
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circ_buf_write(FAR struct circ_buf_s *circ,
|
||||
ssize_t circbuf_write(FAR struct circbuf_s *circ,
|
||||
FAR const void *src, size_t bytes)
|
||||
{
|
||||
size_t space;
|
||||
@@ -394,7 +394,7 @@ ssize_t circ_buf_write(FAR struct circ_buf_s *circ,
|
||||
DEBUGASSERT(circ);
|
||||
DEBUGASSERT(src || !bytes);
|
||||
|
||||
space = circ_buf_space(circ);
|
||||
space = circbuf_space(circ);
|
||||
off = circ->head % circ->size;
|
||||
if (bytes > space)
|
||||
{
|
||||
@@ -415,14 +415,14 @@ ssize_t circ_buf_write(FAR struct circ_buf_s *circ,
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: circ_buf_overwrite
|
||||
* Name: circbuf_overwrite
|
||||
*
|
||||
* Description:
|
||||
* Write data to the circular buffer. It can overwrite old data when
|
||||
* circular buffer don't have enough space to store data.
|
||||
*
|
||||
* Note:
|
||||
* Usage circ_buf_overwrite () is dangerous. It should be only called
|
||||
* Usage circbuf_overwrite () is dangerous. It should be only called
|
||||
* when the buffer is exclusived locked or when it is secured that no
|
||||
* other thread is accessing the buffer.
|
||||
*
|
||||
@@ -436,7 +436,7 @@ ssize_t circ_buf_write(FAR struct circ_buf_s *circ,
|
||||
* A negated errno value is returned on any failure.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t circ_buf_overwrite(FAR struct circ_buf_s *circ,
|
||||
ssize_t circbuf_overwrite(FAR struct circbuf_s *circ,
|
||||
FAR const void *src, size_t bytes)
|
||||
{
|
||||
size_t overwrite = 0;
|
||||
@@ -452,7 +452,7 @@ ssize_t circ_buf_overwrite(FAR struct circ_buf_s *circ,
|
||||
bytes = circ->size;
|
||||
}
|
||||
|
||||
space = circ_buf_space(circ);
|
||||
space = circbuf_space(circ);
|
||||
if (bytes > space)
|
||||
{
|
||||
overwrite = bytes - space;
|
||||
Reference in New Issue
Block a user