1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) 2017, 2020 embedded brains GmbH (http://www.embedded-brains.de) |
---|
5 | * |
---|
6 | * Redistribution and use in source and binary forms, with or without |
---|
7 | * modification, are permitted provided that the following conditions |
---|
8 | * are met: |
---|
9 | * 1. Redistributions of source code must retain the above copyright |
---|
10 | * notice, this list of conditions and the following disclaimer. |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer in the |
---|
13 | * documentation and/or other materials provided with the distribution. |
---|
14 | * |
---|
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
25 | * POSSIBILITY OF SUCH DAMAGE. |
---|
26 | */ |
---|
27 | |
---|
28 | #if HAVE_CONFIG_H |
---|
29 | #include "config.h" |
---|
30 | #endif |
---|
31 | |
---|
32 | #include <rtems/console.h> |
---|
33 | #include <rtems/bspIo.h> |
---|
34 | #include <rtems/imfs.h> |
---|
35 | |
---|
36 | #include "consolesimple.h" |
---|
37 | |
---|
38 | static ssize_t _Console_simple_Write( |
---|
39 | rtems_libio_t *iop, |
---|
40 | const void *buffer, |
---|
41 | size_t count |
---|
42 | ) |
---|
43 | { |
---|
44 | const char *buf; |
---|
45 | ssize_t i; |
---|
46 | ssize_t n; |
---|
47 | |
---|
48 | buf = buffer; |
---|
49 | n = (ssize_t) count; |
---|
50 | |
---|
51 | for ( i = 0; i < n; ++i ) { |
---|
52 | rtems_putc( buf[ i ] ); |
---|
53 | } |
---|
54 | |
---|
55 | return n; |
---|
56 | } |
---|
57 | |
---|
58 | static const rtems_filesystem_file_handlers_r _Console_simple_Handlers = { |
---|
59 | .open_h = rtems_filesystem_default_open, |
---|
60 | .close_h = rtems_filesystem_default_close, |
---|
61 | .read_h = _Console_simple_Read, |
---|
62 | .write_h = _Console_simple_Write, |
---|
63 | .ioctl_h = rtems_filesystem_default_ioctl, |
---|
64 | .lseek_h = rtems_filesystem_default_lseek, |
---|
65 | .fstat_h = IMFS_stat, |
---|
66 | .ftruncate_h = rtems_filesystem_default_ftruncate, |
---|
67 | .fsync_h = rtems_filesystem_default_fsync_or_fdatasync, |
---|
68 | .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync, |
---|
69 | .fcntl_h = rtems_filesystem_default_fcntl, |
---|
70 | .readv_h = rtems_filesystem_default_readv, |
---|
71 | .writev_h = rtems_filesystem_default_writev, |
---|
72 | .mmap_h = rtems_filesystem_default_mmap |
---|
73 | }; |
---|
74 | |
---|
75 | static const IMFS_node_control |
---|
76 | _Console_simple_Node_control = IMFS_NODE_CONTROL_INITIALIZER( |
---|
77 | &_Console_simple_Handlers, |
---|
78 | IMFS_node_initialize_default, |
---|
79 | IMFS_do_nothing_destroy |
---|
80 | ); |
---|
81 | |
---|
82 | static const char _Console_simple_Name[] = "console"; |
---|
83 | |
---|
84 | static IMFS_jnode_t _Console_simple_Node = IMFS_NODE_INITIALIZER( |
---|
85 | &_Console_simple_Node_control, |
---|
86 | _Console_simple_Name, |
---|
87 | sizeof( _Console_simple_Name ) - 1, |
---|
88 | S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO |
---|
89 | ); |
---|
90 | |
---|
91 | void _Console_simple_Initialize( void ) |
---|
92 | { |
---|
93 | IMFS_add_node( "/dev", &_Console_simple_Node, NULL ); |
---|
94 | } |
---|