source: mainline/kernel/generic/include/console/chardev.h@ 431c402

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 431c402 was 83dab11, checked in by Jiri Svoboda <jiri@…>, 8 years ago

Replace usage of typedefs.h with includes of more specific, standard headers, where applicable.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2005 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - 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 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup genericconsole
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_CHARDEV_H_
36#define KERN_CHARDEV_H_
37
38#include <adt/list.h>
39#include <stdbool.h>
40#include <stddef.h>
41#include <synch/waitq.h>
42#include <synch/spinlock.h>
43
44#define INDEV_BUFLEN 512
45
46/** Input character device out-of-band signal type. */
47typedef enum {
48 INDEV_SIGNAL_SCROLL_UP = 0,
49 INDEV_SIGNAL_SCROLL_DOWN
50} indev_signal_t;
51
52struct indev;
53
54/** Input character device operations interface. */
55typedef struct {
56 /** Read character directly from device, assume interrupts disabled. */
57 wchar_t (* poll)(struct indev *);
58
59 /** Signal out-of-band condition. */
60 void (* signal)(struct indev *, indev_signal_t);
61} indev_operations_t;
62
63/** Character input device. */
64typedef struct indev {
65 const char *name;
66 waitq_t wq;
67
68 /** Protects everything below. */
69 IRQ_SPINLOCK_DECLARE(lock);
70 wchar_t buffer[INDEV_BUFLEN];
71 size_t counter;
72
73 /** Implementation of indev operations. */
74 indev_operations_t *op;
75 size_t index;
76 void *data;
77} indev_t;
78
79struct outdev;
80
81/** Output character device operations interface. */
82typedef struct {
83 /** Write character to output. */
84 void (* write)(struct outdev *, wchar_t);
85
86 /** Redraw any previously cached characters. */
87 void (* redraw)(struct outdev *);
88
89 /** Scroll up in the device cache. */
90 void (* scroll_up)(struct outdev *);
91
92 /** Scroll down in the device cache. */
93 void (* scroll_down)(struct outdev *);
94} outdev_operations_t;
95
96/** Character output device. */
97typedef struct outdev {
98 const char *name;
99
100 /** Protects everything below. */
101 SPINLOCK_DECLARE(lock);
102
103 /** Fields suitable for multiplexing. */
104 link_t link;
105 list_t list;
106
107 /** Implementation of outdev operations. */
108 outdev_operations_t *op;
109 void *data;
110} outdev_t;
111
112extern void indev_initialize(const char *, indev_t *,
113 indev_operations_t *);
114extern void indev_push_character(indev_t *, wchar_t);
115extern wchar_t indev_pop_character(indev_t *);
116extern void indev_signal(indev_t *, indev_signal_t);
117
118extern void outdev_initialize(const char *, outdev_t *,
119 outdev_operations_t *);
120
121extern bool check_poll(indev_t *);
122
123#endif /* KERN_CHARDEV_H_ */
124
125/** @}
126 */
Note: See TracBrowser for help on using the repository browser.