2019-11-02 18:30:33 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/syslog/syslog_rpmsg.c
|
|
|
|
*
|
2020-08-22 18:36:57 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2019-11-02 18:30:33 +01:00
|
|
|
*
|
2020-08-22 18:36:57 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2019-11-02 18:30:33 +01:00
|
|
|
*
|
2020-08-22 18:36:57 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2019-11-02 18:30:33 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2021-12-14 11:30:47 +01:00
|
|
|
#include <assert.h>
|
2019-11-02 18:30:33 +01:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2022-06-27 10:45:44 +02:00
|
|
|
#include <sys/boardctl.h>
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2021-12-13 14:37:02 +01:00
|
|
|
#ifdef CONFIG_ARCH_LOWPUTC
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#endif
|
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/rptun/openamp.h>
|
|
|
|
#include <nuttx/syslog/syslog_rpmsg.h>
|
|
|
|
#include <nuttx/wqueue.h>
|
|
|
|
|
|
|
|
#include "syslog_rpmsg.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-06-24 12:32:04 +02:00
|
|
|
#if CONFIG_SYSLOG_RPMSG_WORK_DELAY
|
|
|
|
# define SYSLOG_RPMSG_WORK_DELAY MSEC2TICK(CONFIG_SYSLOG_RPMSG_WORK_DELAY)
|
|
|
|
#else
|
|
|
|
# define SYSLOG_RPMSG_WORK_DELAY MSEC2TICK(100)
|
|
|
|
#endif
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2021-12-14 11:30:47 +01:00
|
|
|
#define SYSLOG_RPMSG_COUNT(p) ((p)->head - (p)->tail)
|
|
|
|
#define SYSLOG_RPMSG_SPACE(p) ((p)->size - 1 - SYSLOG_RPMSG_COUNT(p))
|
|
|
|
#define SYSLOG_RPMSG_HEADOFF(p) ((p)->head & ((p)->size -1))
|
|
|
|
#define SYSLOG_RPMSG_TAILOFF(p) ((p)->tail & ((p)->size -1))
|
|
|
|
#define SYSLOG_RPMSG_FLUSHOFF(p) ((p)->flush & ((p)->size -1))
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct syslog_rpmsg_s
|
|
|
|
{
|
2021-12-13 14:37:02 +01:00
|
|
|
volatile size_t head; /* The head index (where data is added) */
|
|
|
|
volatile size_t tail; /* The tail index (where data is removed) */
|
|
|
|
volatile size_t flush; /* The tail index of flush (where data is removed) */
|
|
|
|
size_t size; /* Size of the RAM buffer */
|
|
|
|
FAR char *buffer; /* Circular RAM buffer */
|
|
|
|
struct work_s work; /* Used for deferred callback work */
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
struct rpmsg_endpoint ept;
|
|
|
|
bool suspend;
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void syslog_rpmsg_work(FAR void *priv_);
|
2020-04-07 14:39:53 +02:00
|
|
|
static void syslog_rpmsg_putchar(FAR struct syslog_rpmsg_s *priv, int ch,
|
|
|
|
bool last);
|
2019-11-02 18:30:33 +01:00
|
|
|
static void syslog_rpmsg_device_created(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv_);
|
|
|
|
static void syslog_rpmsg_device_destroy(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv_);
|
|
|
|
static int syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|
|
|
FAR void *data, size_t len, uint32_t src,
|
|
|
|
FAR void *priv_);
|
2022-06-27 05:30:02 +02:00
|
|
|
#ifdef CONFIG_SYSLOG_RPMSG_CHARDEV
|
|
|
|
static ssize_t syslog_rpmsg_file_read(FAR struct file *filep,
|
|
|
|
FAR char *buffer, size_t len);
|
|
|
|
static ssize_t syslog_rpmsg_file_write(FAR struct file *filep,
|
|
|
|
FAR const char *buffer, size_t len);
|
|
|
|
#endif
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static struct syslog_rpmsg_s g_syslog_rpmsg;
|
|
|
|
|
2022-06-27 05:30:02 +02:00
|
|
|
#ifdef CONFIG_SYSLOG_RPMSG_CHARDEV
|
|
|
|
static const struct file_operations g_syslog_rpmsgfops =
|
|
|
|
{
|
|
|
|
NULL, /* open */
|
|
|
|
NULL, /* close */
|
|
|
|
syslog_rpmsg_file_read, /* read */
|
|
|
|
syslog_rpmsg_file_write, /* write */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
static bool syslog_rpmsg_transfer(FAR struct syslog_rpmsg_s *priv, bool wait)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
|
|
|
FAR struct syslog_rpmsg_transfer_s *msg = NULL;
|
|
|
|
irqstate_t flags;
|
|
|
|
uint32_t space;
|
|
|
|
size_t len;
|
2021-12-14 07:59:20 +01:00
|
|
|
size_t off;
|
2019-11-02 18:30:33 +01:00
|
|
|
size_t len_end;
|
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
do
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
2022-06-28 14:03:05 +02:00
|
|
|
msg = rpmsg_get_tx_payload_buffer(&priv->ept, &space, wait);
|
|
|
|
if (!msg)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
memset(msg, 0, sizeof(*msg));
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
flags = enter_critical_section();
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
space -= sizeof(*msg);
|
|
|
|
len = SYSLOG_RPMSG_COUNT(priv);
|
|
|
|
off = SYSLOG_RPMSG_TAILOFF(priv);
|
|
|
|
len_end = priv->size - off;
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
if (len > space)
|
|
|
|
{
|
|
|
|
len = space;
|
|
|
|
}
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
if (len > len_end)
|
|
|
|
{
|
|
|
|
memcpy(msg->data, &priv->buffer[off], len_end);
|
|
|
|
memcpy(msg->data + len_end, priv->buffer, len - len_end);
|
|
|
|
memset(&priv->buffer[off], 0, len_end);
|
|
|
|
memset(priv->buffer, 0, len - len_end);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(msg->data, &priv->buffer[off], len);
|
|
|
|
memset(&priv->buffer[off], 0, len);
|
|
|
|
}
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
msg->count = len;
|
|
|
|
priv->tail += len;
|
|
|
|
msg->header.command = SYSLOG_RPMSG_TRANSFER;
|
|
|
|
rpmsg_send_nocopy(&priv->ept, msg, sizeof(*msg) + len);
|
|
|
|
len = SYSLOG_RPMSG_COUNT(priv);
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
2019-11-02 18:30:33 +01:00
|
|
|
}
|
2022-06-28 14:03:05 +02:00
|
|
|
while (len > 0);
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
static void syslog_rpmsg_work(FAR void *priv_)
|
|
|
|
{
|
|
|
|
FAR struct syslog_rpmsg_s *priv = priv_;
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
if (!syslog_rpmsg_transfer(priv, false))
|
|
|
|
{
|
|
|
|
work_queue(HPWORK, &priv->work, syslog_rpmsg_work, priv,
|
|
|
|
SYSLOG_RPMSG_WORK_DELAY);
|
|
|
|
}
|
2019-11-02 18:30:33 +01:00
|
|
|
}
|
|
|
|
|
2020-04-07 14:39:53 +02:00
|
|
|
static void syslog_rpmsg_putchar(FAR struct syslog_rpmsg_s *priv, int ch,
|
|
|
|
bool last)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
2022-06-28 14:03:05 +02:00
|
|
|
if (priv->head + 1 - priv->tail >= priv->size)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
2022-06-28 14:03:05 +02:00
|
|
|
if (!priv->flush && !up_interrupt_context() && !sched_idletask())
|
2021-12-07 15:40:00 +01:00
|
|
|
{
|
2022-06-28 14:03:05 +02:00
|
|
|
syslog_rpmsg_transfer(priv, true);
|
2021-12-07 15:40:00 +01:00
|
|
|
}
|
|
|
|
else
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
2022-06-28 14:03:05 +02:00
|
|
|
/* Overwrite */
|
|
|
|
|
|
|
|
priv->buffer[SYSLOG_RPMSG_TAILOFF(priv)] = 0;
|
|
|
|
priv->tail++;
|
2019-11-02 18:30:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-14 11:30:47 +01:00
|
|
|
priv->buffer[SYSLOG_RPMSG_HEADOFF(priv)] = ch & 0xff;
|
2022-06-28 14:03:05 +02:00
|
|
|
priv->head++;
|
2021-12-07 15:40:00 +01:00
|
|
|
|
2021-12-20 17:09:00 +01:00
|
|
|
if (priv->flush)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_ARCH_LOWPUTC)
|
|
|
|
up_putc(ch);
|
|
|
|
#endif
|
|
|
|
priv->flush++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
if (last && !priv->suspend && is_rpmsg_ept_ready(&priv->ept))
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
|
|
|
clock_t delay = SYSLOG_RPMSG_WORK_DELAY;
|
2021-12-14 07:59:20 +01:00
|
|
|
size_t space = SYSLOG_RPMSG_SPACE(priv);
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-28 14:03:05 +02:00
|
|
|
/* Start work immediately when data more then 75% and meet last */
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-24 12:32:04 +02:00
|
|
|
if (space < priv->size / 4)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
|
|
|
delay = 0;
|
|
|
|
}
|
2022-06-24 12:32:04 +02:00
|
|
|
#if CONFIG_SYSLOG_RPMSG_WORK_DELAY == 0
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
work_queue(HPWORK, &priv->work, syslog_rpmsg_work, priv, delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void syslog_rpmsg_device_created(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv_)
|
|
|
|
{
|
|
|
|
FAR struct syslog_rpmsg_s *priv = priv_;
|
|
|
|
int ret;
|
|
|
|
|
2021-04-22 16:36:01 +02:00
|
|
|
if (priv->buffer && strcmp(CONFIG_SYSLOG_RPMSG_SERVER_NAME,
|
|
|
|
rpmsg_get_cpuname(rdev)) == 0)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
|
|
|
priv->ept.priv = priv;
|
|
|
|
|
|
|
|
ret = rpmsg_create_ept(&priv->ept, rdev, SYSLOG_RPMSG_EPT_NAME,
|
|
|
|
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
|
|
|
|
syslog_rpmsg_ept_cb, NULL);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
2022-06-24 12:32:04 +02:00
|
|
|
work_queue(HPWORK, &priv->work, syslog_rpmsg_work, priv, 0);
|
2019-11-02 18:30:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void syslog_rpmsg_device_destroy(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv_)
|
|
|
|
{
|
|
|
|
FAR struct syslog_rpmsg_s *priv = priv_;
|
|
|
|
|
2021-04-22 16:36:01 +02:00
|
|
|
if (priv->buffer && strcmp(CONFIG_SYSLOG_RPMSG_SERVER_NAME,
|
|
|
|
rpmsg_get_cpuname(rdev)) == 0)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
|
|
|
rpmsg_destroy_ept(&priv->ept);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-15 11:45:28 +02:00
|
|
|
static int syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|
|
|
FAR void *data, size_t len, uint32_t src,
|
|
|
|
FAR void *priv_)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
|
|
|
FAR struct syslog_rpmsg_s *priv = priv_;
|
|
|
|
FAR struct syslog_rpmsg_header_s *header = data;
|
|
|
|
|
|
|
|
if (header->command == SYSLOG_RPMSG_SUSPEND)
|
|
|
|
{
|
|
|
|
work_cancel(HPWORK, &priv->work);
|
|
|
|
priv->suspend = true;
|
|
|
|
}
|
|
|
|
else if (header->command == SYSLOG_RPMSG_RESUME)
|
|
|
|
{
|
|
|
|
priv->suspend = false;
|
2022-06-24 12:32:04 +02:00
|
|
|
work_queue(HPWORK, &priv->work, syslog_rpmsg_work, priv, 0);
|
2019-11-02 18:30:33 +01:00
|
|
|
}
|
2022-06-28 08:55:35 +02:00
|
|
|
else if (header->command == SYSLOG_RPMSG_SYNC)
|
|
|
|
{
|
|
|
|
syslog_rpmsg_transfer(priv, true);
|
|
|
|
rpmsg_send(ept, data, len);
|
|
|
|
}
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-27 05:30:02 +02:00
|
|
|
#ifdef CONFIG_SYSLOG_RPMSG_CHARDEV
|
|
|
|
static ssize_t syslog_rpmsg_file_read(FAR struct file *filep,
|
|
|
|
FAR char *buffer, size_t len)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct syslog_rpmsg_s *priv;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Some sanity checking */
|
|
|
|
|
|
|
|
DEBUGASSERT(inode && inode->i_private);
|
|
|
|
priv = (FAR struct syslog_rpmsg_s *)inode->i_private;
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
2022-06-28 14:03:05 +02:00
|
|
|
if (!priv->suspend && is_rpmsg_ept_ready(&priv->ept))
|
2022-06-27 05:30:02 +02:00
|
|
|
{
|
|
|
|
work_queue(HPWORK, &priv->work, syslog_rpmsg_work, priv, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t syslog_rpmsg_file_write(FAR struct file *filep,
|
|
|
|
FAR const char *buffer, size_t len)
|
|
|
|
{
|
|
|
|
syslog(LOG_INFO, "%.*s", (int)len, buffer);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-29 14:36:58 +02:00
|
|
|
int syslog_rpmsg_putc(FAR struct syslog_channel_s *channel, int ch)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
|
|
|
FAR struct syslog_rpmsg_s *priv = &g_syslog_rpmsg;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
2020-04-07 14:39:53 +02:00
|
|
|
syslog_rpmsg_putchar(priv, ch, true);
|
2019-11-02 18:30:33 +01:00
|
|
|
leave_critical_section(flags);
|
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2021-03-29 14:36:58 +02:00
|
|
|
int syslog_rpmsg_flush(FAR struct syslog_channel_s *channel)
|
2020-04-27 06:15:11 +02:00
|
|
|
{
|
2021-12-13 14:37:02 +01:00
|
|
|
FAR struct syslog_rpmsg_s *priv = &g_syslog_rpmsg;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
2022-07-27 09:43:20 +02:00
|
|
|
if (priv->head > priv->flush &&
|
|
|
|
priv->head - priv->flush > priv->size)
|
2021-12-13 14:37:02 +01:00
|
|
|
{
|
|
|
|
priv->flush = priv->tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (priv->flush < priv->head)
|
|
|
|
{
|
2021-12-20 17:09:00 +01:00
|
|
|
#if defined(CONFIG_ARCH_LOWPUTC)
|
2021-12-14 11:30:47 +01:00
|
|
|
up_putc(priv->buffer[SYSLOG_RPMSG_FLUSHOFF(priv)]);
|
2021-12-20 17:09:00 +01:00
|
|
|
#endif
|
2021-12-14 11:30:47 +01:00
|
|
|
priv->flush++;
|
2021-12-13 14:37:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
2020-04-27 06:15:11 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2021-03-29 14:36:58 +02:00
|
|
|
ssize_t syslog_rpmsg_write(FAR struct syslog_channel_s *channel,
|
|
|
|
FAR const char *buffer, size_t buflen)
|
2020-04-27 06:15:11 +02:00
|
|
|
{
|
|
|
|
FAR struct syslog_rpmsg_s *priv = &g_syslog_rpmsg;
|
|
|
|
irqstate_t flags;
|
|
|
|
size_t nwritten;
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
for (nwritten = 1; nwritten <= buflen; nwritten++)
|
|
|
|
{
|
|
|
|
syslog_rpmsg_putchar(priv, *buffer++, nwritten == buflen);
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
|
|
|
|
return buflen;
|
|
|
|
}
|
|
|
|
|
2021-04-22 16:36:01 +02:00
|
|
|
void syslog_rpmsg_init_early(FAR void *buffer, size_t size)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
|
|
|
FAR struct syslog_rpmsg_s *priv = &g_syslog_rpmsg;
|
2022-06-27 10:45:44 +02:00
|
|
|
#ifdef CONFIG_BOARDCTL_RESET_CAUSE
|
|
|
|
struct boardioc_reset_cause_s cause;
|
|
|
|
int ret;
|
|
|
|
#endif
|
2021-07-07 15:58:21 +02:00
|
|
|
char prev;
|
|
|
|
char cur;
|
2019-11-02 18:30:33 +01:00
|
|
|
size_t i;
|
|
|
|
|
2021-12-14 11:30:47 +01:00
|
|
|
DEBUGASSERT((size & (size - 1)) == 0);
|
|
|
|
|
2021-12-13 14:37:02 +01:00
|
|
|
priv->buffer = buffer;
|
|
|
|
priv->size = size;
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-06-27 10:45:44 +02:00
|
|
|
#ifdef CONFIG_BOARDCTL_RESET_CAUSE
|
|
|
|
memset(&cause, 0, sizeof(cause));
|
|
|
|
ret = boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&cause);
|
|
|
|
if (ret >= 0 && cause.cause == BOARDIOC_RESETCAUSE_SYS_CHIPPOR)
|
|
|
|
{
|
|
|
|
memset(buffer, 0, size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-12-08 05:20:35 +01:00
|
|
|
prev = priv->buffer[size - 1];
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
2021-12-08 05:20:35 +01:00
|
|
|
cur = priv->buffer[i];
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2021-12-08 05:20:35 +01:00
|
|
|
if (!isascii(cur))
|
|
|
|
{
|
|
|
|
memset(priv->buffer, 0, size);
|
|
|
|
break;
|
2019-11-02 18:30:33 +01:00
|
|
|
}
|
2021-12-08 05:20:35 +01:00
|
|
|
else if (prev && !cur)
|
|
|
|
{
|
|
|
|
priv->head = i;
|
|
|
|
}
|
|
|
|
else if (!prev && cur)
|
|
|
|
{
|
|
|
|
priv->tail = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = cur;
|
2019-11-02 18:30:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i != size)
|
|
|
|
{
|
|
|
|
priv->head = priv->tail = 0;
|
|
|
|
}
|
2022-04-12 09:35:26 +02:00
|
|
|
else if (priv->head < priv->tail)
|
|
|
|
{
|
|
|
|
priv->head += priv->size;
|
|
|
|
}
|
2019-11-02 18:30:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int syslog_rpmsg_init(void)
|
|
|
|
{
|
2022-06-27 05:30:02 +02:00
|
|
|
#ifdef CONFIG_SYSLOG_RPMSG_CHARDEV
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = register_driver(CONFIG_SYSLOG_DEVPATH, &g_syslog_rpmsgfops,
|
|
|
|
0666, &g_syslog_rpmsg);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
return rpmsg_register_callback(&g_syslog_rpmsg,
|
|
|
|
syslog_rpmsg_device_created,
|
|
|
|
syslog_rpmsg_device_destroy,
|
2022-06-06 10:38:11 +02:00
|
|
|
NULL,
|
2019-11-02 18:30:33 +01:00
|
|
|
NULL);
|
|
|
|
}
|