source: rtems/cpukit/libcsupport/src/consolesimple.c @ ac28f15

5
Last change on this file since ac28f15 was ac28f15, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 3, 2017 at 7:33:16 AM

Add simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 * Copyright (c) 2017 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#include <rtems/console.h>
16#include <rtems/bspIo.h>
17#include <rtems/imfs.h>
18
19static ssize_t _Console_simple_Read(
20  rtems_libio_t *iop,
21  void          *buffer,
22  size_t         count
23)
24{
25  char    *buf;
26  ssize_t  i;
27  ssize_t  n;
28
29  buf = buffer;
30  n = (ssize_t) count;
31
32  for ( i = 0; i < n; ++i ) {
33    int c;
34
35    do {
36      c = getchark();
37    } while (c == -1);
38
39    buf[ i ] = (char) c;
40  }
41
42  return n;
43}
44
45static ssize_t _Console_simple_Write(
46  rtems_libio_t *iop,
47  const void    *buffer,
48  size_t         count
49)
50{
51  const char *buf;
52  ssize_t     i;
53  ssize_t     n;
54
55  buf = buffer;
56  n = (ssize_t) count;
57
58  for ( i = 0; i < n; ++i ) {
59    rtems_putc( buf[ i ] );
60  }
61
62  return n;
63}
64
65static const rtems_filesystem_file_handlers_r _Console_simple_Handlers = {
66  .open_h = rtems_filesystem_default_open,
67  .close_h = rtems_filesystem_default_close,
68  .read_h = _Console_simple_Read,
69  .write_h = _Console_simple_Write,
70  .ioctl_h = rtems_filesystem_default_ioctl,
71  .lseek_h = rtems_filesystem_default_lseek,
72  .fstat_h = IMFS_stat,
73  .ftruncate_h = rtems_filesystem_default_ftruncate,
74  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
75  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
76  .fcntl_h = rtems_filesystem_default_fcntl,
77  .readv_h = rtems_filesystem_default_readv,
78  .writev_h = rtems_filesystem_default_writev,
79  .mmap_h = rtems_filesystem_default_mmap
80};
81
82static const IMFS_node_control
83_Console_simple_Node_control = IMFS_GENERIC_INITIALIZER(
84  &_Console_simple_Handlers,
85  IMFS_node_initialize_default,
86  IMFS_node_destroy_default
87);
88
89void _Console_simple_Initialize( void )
90{
91  IMFS_make_generic_node(
92    CONSOLE_DEVICE_NAME,
93    S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
94    &_Console_simple_Node_control,
95    NULL
96  );
97}
Note: See TracBrowser for help on using the repository browser.