mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
syslog_rpmsg: update syslog_rpmsg to support non-overwrite
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
@@ -250,6 +250,14 @@ config SYSLOG_RPMSG_WORK_DELAY
|
|||||||
default 100
|
default 100
|
||||||
depends on SYSLOG_RPMSG
|
depends on SYSLOG_RPMSG
|
||||||
|
|
||||||
|
config SYSLOG_RPMSG_OVERWRITE
|
||||||
|
bool "SYSLOG RPMSG overwrite"
|
||||||
|
default n
|
||||||
|
depends on SYSLOG_RPMSG
|
||||||
|
---help---
|
||||||
|
Allow syslog rpmsg overwrite, maybe caused syslog lost.
|
||||||
|
Set 'n' if you don't want lost logs, but may harmful to preformance.
|
||||||
|
|
||||||
config SYSLOG_RPMSG_SERVER
|
config SYSLOG_RPMSG_SERVER
|
||||||
bool "Enable RPMSG server for SYSLOG"
|
bool "Enable RPMSG server for SYSLOG"
|
||||||
default n
|
default n
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ struct syslog_rpmsg_s
|
|||||||
bool suspend;
|
bool suspend;
|
||||||
bool transfer; /* The transfer flag */
|
bool transfer; /* The transfer flag */
|
||||||
ssize_t trans_len; /* The data length when transfer */
|
ssize_t trans_len; /* The data length when transfer */
|
||||||
|
|
||||||
|
sem_t sem;
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -147,31 +149,52 @@ static void syslog_rpmsg_work(FAR void *priv_)
|
|||||||
static void syslog_rpmsg_putchar(FAR struct syslog_rpmsg_s *priv, int ch,
|
static void syslog_rpmsg_putchar(FAR struct syslog_rpmsg_s *priv, int ch,
|
||||||
bool last)
|
bool last)
|
||||||
{
|
{
|
||||||
|
size_t next;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
next = priv->head + 1;
|
||||||
|
if (next >= priv->size)
|
||||||
|
{
|
||||||
|
next = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next == priv->tail)
|
||||||
|
{
|
||||||
|
#ifndef SYSLOG_RPMSG_OVERWRITE
|
||||||
|
if (!up_interrupt_context() && !sched_idletask())
|
||||||
|
{
|
||||||
|
nxsem_wait(&priv->sem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
/* Overwrite */
|
||||||
|
|
||||||
|
priv->buffer[priv->tail] = 0;
|
||||||
|
priv->tail += 1;
|
||||||
|
|
||||||
|
if (priv->tail >= priv->size)
|
||||||
|
{
|
||||||
|
priv->tail = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priv->transfer)
|
||||||
|
{
|
||||||
|
priv->trans_len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
priv->buffer[priv->head] = ch & 0xff;
|
priv->buffer[priv->head] = ch & 0xff;
|
||||||
|
priv->head = next;
|
||||||
priv->head += 1;
|
|
||||||
if (priv->head >= (priv->size))
|
|
||||||
{
|
|
||||||
priv->head = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allow overwrite */
|
|
||||||
|
|
||||||
if (priv->head == (priv->tail))
|
|
||||||
{
|
|
||||||
priv->buffer[priv->tail] = 0;
|
|
||||||
|
|
||||||
priv->tail += 1;
|
|
||||||
if (priv->tail >= priv->size)
|
|
||||||
{
|
|
||||||
priv->tail = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (priv->transfer)
|
|
||||||
{
|
|
||||||
priv->trans_len--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (last && !priv->suspend && !priv->transfer &&
|
if (last && !priv->suspend && !priv->transfer &&
|
||||||
is_rpmsg_ept_ready(&priv->ept))
|
is_rpmsg_ept_ready(&priv->ept))
|
||||||
@@ -246,6 +269,7 @@ static int syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|||||||
{
|
{
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
ssize_t len_end;
|
ssize_t len_end;
|
||||||
|
int sval;
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = enter_critical_section();
|
||||||
|
|
||||||
@@ -268,6 +292,12 @@ static int syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|||||||
{
|
{
|
||||||
priv->tail -= priv->size;
|
priv->tail -= priv->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nxsem_get_value(&priv->sem, &sval);
|
||||||
|
while (sval++ < 0)
|
||||||
|
{
|
||||||
|
nxsem_post(&priv->sem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->transfer = false;
|
priv->transfer = false;
|
||||||
@@ -338,6 +368,9 @@ void syslog_rpmsg_init_early(FAR void *buffer, size_t size)
|
|||||||
char cur;
|
char cur;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
nxsem_init(&priv->sem, 0, 0);
|
||||||
|
nxsem_set_protocol(&priv->sem, SEM_PRIO_NONE);
|
||||||
|
|
||||||
priv->buffer = buffer;
|
priv->buffer = buffer;
|
||||||
priv->size = size;
|
priv->size = size;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user