mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
drivers/noteram: change ni_buffer to point
ni_buffer is defined in the initialized structure, put it in the data segment, it will increase the flash size Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
@@ -44,11 +44,12 @@
|
||||
|
||||
struct noteram_info_s
|
||||
{
|
||||
FAR uint8_t *ni_buffer;
|
||||
size_t ni_bufsize;
|
||||
unsigned int ni_overwrite;
|
||||
volatile unsigned int ni_head;
|
||||
volatile unsigned int ni_tail;
|
||||
volatile unsigned int ni_read;
|
||||
uint8_t ni_buffer[CONFIG_DRIVERS_NOTERAM_BUFSIZE];
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@@ -76,8 +77,12 @@ static const struct file_operations g_noteram_fops =
|
||||
noteram_ioctl, /* ioctl */
|
||||
};
|
||||
|
||||
static uint8_t g_ramnote_buffer[CONFIG_DRIVERS_NOTERAM_BUFSIZE];
|
||||
|
||||
static struct noteram_info_s g_noteram_info =
|
||||
{
|
||||
g_ramnote_buffer,
|
||||
CONFIG_DRIVERS_NOTERAM_BUFSIZE,
|
||||
#ifdef CONFIG_DRIVERS_NOTERAM_DEFAULT_NOOVERWRITE
|
||||
NOTERAM_MODE_OVERWRITE_DISABLE
|
||||
#else
|
||||
@@ -149,9 +154,9 @@ static inline unsigned int noteram_next(unsigned int ndx,
|
||||
unsigned int offset)
|
||||
{
|
||||
ndx += offset;
|
||||
if (ndx >= CONFIG_DRIVERS_NOTERAM_BUFSIZE)
|
||||
if (ndx >= g_noteram_info.ni_bufsize)
|
||||
{
|
||||
ndx -= CONFIG_DRIVERS_NOTERAM_BUFSIZE;
|
||||
ndx -= g_noteram_info.ni_bufsize;
|
||||
}
|
||||
|
||||
return ndx;
|
||||
@@ -178,7 +183,7 @@ static unsigned int noteram_length(void)
|
||||
|
||||
if (tail > head)
|
||||
{
|
||||
head += CONFIG_DRIVERS_NOTERAM_BUFSIZE;
|
||||
head += g_noteram_info.ni_bufsize;
|
||||
}
|
||||
|
||||
return head - tail;
|
||||
@@ -205,7 +210,7 @@ static unsigned int noteram_unread_length(void)
|
||||
|
||||
if (read > head)
|
||||
{
|
||||
head += CONFIG_DRIVERS_NOTERAM_BUFSIZE;
|
||||
head += g_noteram_info.ni_bufsize;
|
||||
}
|
||||
|
||||
return head - read;
|
||||
@@ -236,7 +241,7 @@ static void noteram_remove(void)
|
||||
/* Get the tail index of the circular buffer */
|
||||
|
||||
tail = g_noteram_info.ni_tail;
|
||||
DEBUGASSERT(tail < CONFIG_DRIVERS_NOTERAM_BUFSIZE);
|
||||
DEBUGASSERT(tail < g_noteram_info.ni_bufsize);
|
||||
|
||||
/* Get the length of the note at the tail index */
|
||||
|
||||
@@ -295,7 +300,7 @@ static ssize_t noteram_get(FAR uint8_t *buffer, size_t buflen)
|
||||
/* Get the read index of the circular buffer */
|
||||
|
||||
read = g_noteram_info.ni_read;
|
||||
DEBUGASSERT(read < CONFIG_DRIVERS_NOTERAM_BUFSIZE);
|
||||
DEBUGASSERT(read < g_noteram_info.ni_bufsize);
|
||||
|
||||
/* Get the length of the note at the read index */
|
||||
|
||||
@@ -370,7 +375,7 @@ static ssize_t noteram_size(void)
|
||||
/* Get the read index of the circular buffer */
|
||||
|
||||
read = g_noteram_info.ni_read;
|
||||
DEBUGASSERT(read < CONFIG_DRIVERS_NOTERAM_BUFSIZE);
|
||||
DEBUGASSERT(read < g_noteram_info.ni_bufsize);
|
||||
|
||||
/* Get the length of the note at the read index */
|
||||
|
||||
@@ -579,8 +584,8 @@ static void noteram_add(FAR struct note_driver_s *drv,
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUGASSERT(note != NULL && notelen < CONFIG_DRIVERS_NOTERAM_BUFSIZE);
|
||||
remain = CONFIG_DRIVERS_NOTERAM_BUFSIZE - noteram_length();
|
||||
DEBUGASSERT(note != NULL && notelen < g_noteram_info.ni_bufsize);
|
||||
remain = g_noteram_info.ni_bufsize - noteram_length();
|
||||
|
||||
if (remain < notelen)
|
||||
{
|
||||
@@ -599,13 +604,13 @@ static void noteram_add(FAR struct note_driver_s *drv,
|
||||
do
|
||||
{
|
||||
noteram_remove();
|
||||
remain = CONFIG_DRIVERS_NOTERAM_BUFSIZE - noteram_length();
|
||||
remain = g_noteram_info.ni_bufsize - noteram_length();
|
||||
}
|
||||
while (remain < notelen);
|
||||
}
|
||||
|
||||
head = g_noteram_info.ni_head;
|
||||
space = CONFIG_DRIVERS_NOTERAM_BUFSIZE - head;
|
||||
space = g_noteram_info.ni_bufsize - head;
|
||||
space = space < notelen ? space : notelen;
|
||||
memcpy(g_noteram_info.ni_buffer + head, note, space);
|
||||
memcpy(g_noteram_info.ni_buffer, buf + space, notelen - space);
|
||||
|
||||
Reference in New Issue
Block a user