mirror of
https://github.com/apache/nuttx.git
synced 2025-12-08 10:55:51 +08:00
note: add note stream drivers
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
@@ -92,10 +92,28 @@ config DRIVERS_NOTE_STRIP_FORMAT
|
||||
---help---
|
||||
Strip sched_note_printf format string.
|
||||
|
||||
config DRIVERS_NOTELOWEROUT
|
||||
bool "Note lower output"
|
||||
default n
|
||||
---help---
|
||||
Note uses lower output.
|
||||
|
||||
config DRIVERS_NOTEFILE
|
||||
bool "Note file driver"
|
||||
---help---
|
||||
The Note driver output to file.
|
||||
|
||||
config DRIVERS_NOTEFILE_PATH
|
||||
string "Note file path"
|
||||
depends on DRIVERS_NOTEFILE
|
||||
default "/dev/ttyS1"
|
||||
---help---
|
||||
The Note driver output to file path.
|
||||
|
||||
config DRIVERS_NOTELOG
|
||||
bool "Note syslog driver"
|
||||
---help---
|
||||
The note driver output to syslog.
|
||||
The Note driver output to syslog.
|
||||
|
||||
config DRIVERS_NOTESNAP
|
||||
bool "Last scheduling information"
|
||||
|
||||
@@ -25,6 +25,10 @@ ifeq ($(CONFIG_DRIVERS_NOTE),y)
|
||||
CSRCS += note_initialize.c
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_DRIVERS_NOTEFILE)$(CONFIG_DRIVERS_NOTELOWEROUT),)
|
||||
CSRCS += notestream_driver.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DRIVERS_NOTERAM),y)
|
||||
CSRCS += noteram_driver.c
|
||||
endif
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <nuttx/note/note_driver.h>
|
||||
#include <nuttx/note/noteram_driver.h>
|
||||
#include <nuttx/note/notelog_driver.h>
|
||||
#include <nuttx/note/notestream_driver.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/sched_note.h>
|
||||
#include <nuttx/instrument.h>
|
||||
@@ -191,7 +192,10 @@ FAR static struct note_driver_s *
|
||||
(FAR struct note_driver_s *)&g_noteram_driver,
|
||||
#endif
|
||||
#ifdef CONFIG_DRIVERS_NOTELOG
|
||||
&g_notelog_driver,
|
||||
(FAR struct note_driver_s *)&g_notelog_driver,
|
||||
#endif
|
||||
#ifdef CONFIG_DRIVERS_NOTELOWEROUT
|
||||
(FAR struct note_driver_s *)&g_notestream_lowerout,
|
||||
#endif
|
||||
#ifdef CONFIG_DRIVERS_NOTERPMSG
|
||||
(FAR struct note_driver_s *)&g_noterpmsg_driver,
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <nuttx/note/noteram_driver.h>
|
||||
#include <nuttx/note/notectl_driver.h>
|
||||
#include <nuttx/note/notesnap_driver.h>
|
||||
#include <nuttx/note/notestream_driver.h>
|
||||
#include <nuttx/segger/note_rtt.h>
|
||||
#include <nuttx/segger/sysview.h>
|
||||
|
||||
@@ -105,6 +106,15 @@ int note_initialize(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DRIVERS_NOTEFILE
|
||||
ret = notefile_register(CONFIG_DRIVERS_NOTEFILE_PATH);
|
||||
if (ret < 0)
|
||||
{
|
||||
serr("notefile_register failed %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NOTE_RTT
|
||||
ret = notertt_register();
|
||||
if (ret < 0)
|
||||
|
||||
115
drivers/note/notestream_driver.c
Normal file
115
drivers/note/notestream_driver.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/****************************************************************************
|
||||
* drivers/note/notestream_driver.c
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/note/notestream_driver.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_DRIVERS_NOTEFILE
|
||||
struct notestream_file_s
|
||||
{
|
||||
struct notestream_driver_s driver;
|
||||
struct lib_fileoutstream_s filestream;
|
||||
struct file file;
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void notestream_add(FAR struct note_driver_s *drv,
|
||||
FAR const void *note, size_t len);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const struct note_driver_ops_s g_notestream_ops =
|
||||
{
|
||||
notestream_add
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_DRIVERS_NOTELOWEROUT
|
||||
struct notestream_driver_s g_notestream_lowerout =
|
||||
{
|
||||
{
|
||||
&g_notestream_ops
|
||||
},
|
||||
&g_lowoutstream
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void notestream_add(FAR struct note_driver_s *drv,
|
||||
FAR const void *note, size_t len)
|
||||
{
|
||||
FAR struct notestream_driver_s *drivers =
|
||||
(FAR struct notestream_driver_s *)drv;
|
||||
lib_stream_puts(drivers->stream, note, len);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_DRIVERS_NOTEFILE
|
||||
int notefile_register(FAR const char *filename)
|
||||
{
|
||||
FAR struct notestream_file_s *notefile;
|
||||
int ret;
|
||||
|
||||
notefile = kmm_zalloc(sizeof(struct notestream_file_s));
|
||||
if (notefile == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
notefile->driver.stream = ¬efile->filestream.common;
|
||||
ret = file_open(¬efile->file, filename, O_WRONLY);
|
||||
if (ret < 0)
|
||||
{
|
||||
kmm_free(notefile);
|
||||
return ret;
|
||||
}
|
||||
|
||||
notefile->driver.driver.ops = &g_notestream_ops;
|
||||
lib_fileoutstream(¬efile->filestream, ¬efile->file);
|
||||
return note_driver_register(¬efile->driver.driver);
|
||||
}
|
||||
#endif
|
||||
|
||||
77
include/nuttx/note/notestream_driver.h
Normal file
77
include/nuttx/note/notestream_driver.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/note/notestream_driver.h
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_NOTE_NOTESTREAM_DRIVER_H
|
||||
#define __INCLUDE_NUTTX_NOTE_NOTESTREAM_DRIVER_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/note/note_driver.h>
|
||||
#include <nuttx/streams.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct notestream_driver_s
|
||||
{
|
||||
struct note_driver_s driver;
|
||||
struct lib_outstream_s *stream;
|
||||
};
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_DRIVERS_NOTELOWEROUT
|
||||
extern struct notestream_driver_s g_notestream_lowerout;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: note_driver_unregister
|
||||
****************************************************************************/
|
||||
#ifdef CONFIG_DRIVERS_NOTEFILE
|
||||
int notefile_register(FAR const char *filename);
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_NOTE_NOTESTREAM_DRIVER_H */
|
||||
Reference in New Issue
Block a user