Skip to content

Commit 453cde9

Browse files
Gary-Hobsonxiaoxiang781216
authored andcommitted
note: add note stream drivers
Signed-off-by: yinshengkai <[email protected]>
1 parent 43d96a5 commit 453cde9

File tree

6 files changed

+230
-2
lines changed

6 files changed

+230
-2
lines changed

drivers/note/Kconfig

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,28 @@ config DRIVERS_NOTE_STRIP_FORMAT
9292
---help---
9393
Strip sched_note_printf format string.
9494

95+
config DRIVERS_NOTELOWEROUT
96+
bool "Note lower output"
97+
default n
98+
---help---
99+
Note uses lower output.
100+
101+
config DRIVERS_NOTEFILE
102+
bool "Note file driver"
103+
---help---
104+
The Note driver output to file.
105+
106+
config DRIVERS_NOTEFILE_PATH
107+
string "Note file path"
108+
depends on DRIVERS_NOTEFILE
109+
default "/dev/ttyS1"
110+
---help---
111+
The Note driver output to file path.
112+
95113
config DRIVERS_NOTELOG
96114
bool "Note syslog driver"
97115
---help---
98-
The note driver output to syslog.
116+
The Note driver output to syslog.
99117

100118
config DRIVERS_NOTESNAP
101119
bool "Last scheduling information"

drivers/note/Make.defs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ ifeq ($(CONFIG_DRIVERS_NOTE),y)
2525
CSRCS += note_initialize.c
2626
endif
2727

28+
ifneq ($(CONFIG_DRIVERS_NOTEFILE)$(CONFIG_DRIVERS_NOTELOWEROUT),)
29+
CSRCS += notestream_driver.c
30+
endif
31+
2832
ifeq ($(CONFIG_DRIVERS_NOTERAM),y)
2933
CSRCS += noteram_driver.c
3034
endif

drivers/note/note_driver.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <nuttx/note/note_driver.h>
3939
#include <nuttx/note/noteram_driver.h>
4040
#include <nuttx/note/notelog_driver.h>
41+
#include <nuttx/note/notestream_driver.h>
4142
#include <nuttx/spinlock.h>
4243
#include <nuttx/sched_note.h>
4344
#include <nuttx/instrument.h>
@@ -191,7 +192,10 @@ FAR static struct note_driver_s *
191192
(FAR struct note_driver_s *)&g_noteram_driver,
192193
#endif
193194
#ifdef CONFIG_DRIVERS_NOTELOG
194-
&g_notelog_driver,
195+
(FAR struct note_driver_s *)&g_notelog_driver,
196+
#endif
197+
#ifdef CONFIG_DRIVERS_NOTELOWEROUT
198+
(FAR struct note_driver_s *)&g_notestream_lowerout,
195199
#endif
196200
#ifdef CONFIG_DRIVERS_NOTERPMSG
197201
(FAR struct note_driver_s *)&g_noterpmsg_driver,

drivers/note/note_initialize.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <nuttx/note/noteram_driver.h>
2929
#include <nuttx/note/notectl_driver.h>
3030
#include <nuttx/note/notesnap_driver.h>
31+
#include <nuttx/note/notestream_driver.h>
3132
#include <nuttx/segger/note_rtt.h>
3233
#include <nuttx/segger/sysview.h>
3334

@@ -105,6 +106,15 @@ int note_initialize(void)
105106
}
106107
#endif
107108

109+
#ifdef CONFIG_DRIVERS_NOTEFILE
110+
ret = notefile_register(CONFIG_DRIVERS_NOTEFILE_PATH);
111+
if (ret < 0)
112+
{
113+
serr("notefile_register failed %d\n", ret);
114+
return ret;
115+
}
116+
#endif
117+
108118
#ifdef CONFIG_NOTE_RTT
109119
ret = notertt_register();
110120
if (ret < 0)

drivers/note/notestream_driver.c

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/****************************************************************************
2+
* drivers/note/notestream_driver.c
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
/****************************************************************************
22+
* Included Files
23+
****************************************************************************/
24+
25+
#include <stdint.h>
26+
#include <fcntl.h>
27+
28+
#include <nuttx/kmalloc.h>
29+
#include <nuttx/note/notestream_driver.h>
30+
31+
/****************************************************************************
32+
* Private Types
33+
****************************************************************************/
34+
35+
#ifdef CONFIG_DRIVERS_NOTEFILE
36+
struct notestream_file_s
37+
{
38+
struct notestream_driver_s driver;
39+
struct lib_fileoutstream_s filestream;
40+
struct file file;
41+
};
42+
#endif
43+
44+
/****************************************************************************
45+
* Private Function Prototypes
46+
****************************************************************************/
47+
48+
static void notestream_add(FAR struct note_driver_s *drv,
49+
FAR const void *note, size_t len);
50+
51+
/****************************************************************************
52+
* Private Data
53+
****************************************************************************/
54+
55+
static const struct note_driver_ops_s g_notestream_ops =
56+
{
57+
notestream_add
58+
};
59+
60+
/****************************************************************************
61+
* Public Data
62+
****************************************************************************/
63+
64+
#ifdef CONFIG_DRIVERS_NOTELOWEROUT
65+
struct notestream_driver_s g_notestream_lowerout =
66+
{
67+
{
68+
&g_notestream_ops
69+
},
70+
&g_lowoutstream
71+
};
72+
#endif
73+
74+
/****************************************************************************
75+
* Private Functions
76+
****************************************************************************/
77+
78+
static void notestream_add(FAR struct note_driver_s *drv,
79+
FAR const void *note, size_t len)
80+
{
81+
FAR struct notestream_driver_s *drivers =
82+
(FAR struct notestream_driver_s *)drv;
83+
lib_stream_puts(drivers->stream, note, len);
84+
}
85+
86+
/****************************************************************************
87+
* Public Functions
88+
****************************************************************************/
89+
90+
#ifdef CONFIG_DRIVERS_NOTEFILE
91+
int notefile_register(FAR const char *filename)
92+
{
93+
FAR struct notestream_file_s *notefile;
94+
int ret;
95+
96+
notefile = kmm_zalloc(sizeof(struct notestream_file_s));
97+
if (notefile == NULL)
98+
{
99+
return -ENOMEM;
100+
}
101+
102+
notefile->driver.stream = &notefile->filestream.common;
103+
ret = file_open(&notefile->file, filename, O_WRONLY);
104+
if (ret < 0)
105+
{
106+
kmm_free(notefile);
107+
return ret;
108+
}
109+
110+
notefile->driver.driver.ops = &g_notestream_ops;
111+
lib_fileoutstream(&notefile->filestream, &notefile->file);
112+
return note_driver_register(&notefile->driver.driver);
113+
}
114+
#endif
115+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/****************************************************************************
2+
* include/nuttx/note/notestream_driver.h
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
#ifndef __INCLUDE_NUTTX_NOTE_NOTESTREAM_DRIVER_H
22+
#define __INCLUDE_NUTTX_NOTE_NOTESTREAM_DRIVER_H
23+
24+
/****************************************************************************
25+
* Included Files
26+
****************************************************************************/
27+
28+
#include <nuttx/note/note_driver.h>
29+
#include <nuttx/streams.h>
30+
31+
/****************************************************************************
32+
* Pre-processor Definitions
33+
****************************************************************************/
34+
35+
/****************************************************************************
36+
* Public Types
37+
****************************************************************************/
38+
39+
struct notestream_driver_s
40+
{
41+
struct note_driver_s driver;
42+
struct lib_outstream_s *stream;
43+
};
44+
45+
#if defined(__cplusplus)
46+
extern "C"
47+
{
48+
#endif
49+
50+
/****************************************************************************
51+
* Public Function Prototypes
52+
****************************************************************************/
53+
54+
/****************************************************************************
55+
* Public Data
56+
****************************************************************************/
57+
58+
#ifdef CONFIG_DRIVERS_NOTELOWEROUT
59+
extern struct notestream_driver_s g_notestream_lowerout;
60+
#endif
61+
62+
/****************************************************************************
63+
* Public Function Prototypes
64+
****************************************************************************/
65+
66+
/****************************************************************************
67+
* Name: note_driver_unregister
68+
****************************************************************************/
69+
#ifdef CONFIG_DRIVERS_NOTEFILE
70+
int notefile_register(FAR const char *filename);
71+
#endif
72+
73+
#if defined(__cplusplus)
74+
}
75+
#endif
76+
77+
#endif /* __INCLUDE_NUTTX_NOTE_NOTESTREAM_DRIVER_H */

0 commit comments

Comments
 (0)