source: mainline/kernel/generic/include/console/chardev.h@ 3061bc1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3061bc1 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
RevLine 
[2677758]1/*
[df4ed85]2 * Copyright (c) 2005 Jakub Jermar
[2677758]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
[06e1e95]29/** @addtogroup genericconsole
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[06e1e95]35#ifndef KERN_CHARDEV_H_
36#define KERN_CHARDEV_H_
[2677758]37
[b9c7425]38#include <adt/list.h>
[83dab11]39#include <stdbool.h>
40#include <stddef.h>
[2677758]41#include <synch/waitq.h>
42#include <synch/spinlock.h>
43
[8030f49]44#define INDEV_BUFLEN 512
[2677758]45
[7ddc2c7]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
[8030f49]52struct indev;
[b3f8fb7]53
[7ddc2c7]54/** Input character device operations interface. */
[b3f8fb7]55typedef struct {
[80bcaed]56 /** Read character directly from device, assume interrupts disabled. */
[d1dabe1f]57 wchar_t (* poll)(struct indev *);
[7ddc2c7]58
59 /** Signal out-of-band condition. */
60 void (* signal)(struct indev *, indev_signal_t);
[8030f49]61} indev_operations_t;
[2677758]62
63/** Character input device. */
[8030f49]64typedef struct indev {
[a000878c]65 const char *name;
[2677758]66 waitq_t wq;
[8030f49]67
[80bcaed]68 /** Protects everything below. */
[da1bafb]69 IRQ_SPINLOCK_DECLARE(lock);
[d1dabe1f]70 wchar_t buffer[INDEV_BUFLEN];
[98000fb]71 size_t counter;
[8030f49]72
73 /** Implementation of indev operations. */
74 indev_operations_t *op;
[98000fb]75 size_t index;
[973be64e]76 void *data;
[8030f49]77} indev_t;
78
79struct outdev;
80
[7ddc2c7]81/** Output character device operations interface. */
[8030f49]82typedef struct {
83 /** Write character to output. */
[b366a6f4]84 void (* write)(struct outdev *, wchar_t);
[a71c158]85
86 /** Redraw any previously cached characters. */
87 void (* redraw)(struct outdev *);
[7ddc2c7]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 *);
[8030f49]94} outdev_operations_t;
95
[b9c7425]96/** Character output device. */
[8030f49]97typedef struct outdev {
[a000878c]98 const char *name;
[8030f49]99
100 /** Protects everything below. */
101 SPINLOCK_DECLARE(lock);
102
[b9c7425]103 /** Fields suitable for multiplexing. */
104 link_t link;
[55b77d9]105 list_t list;
[b9c7425]106
[8030f49]107 /** Implementation of outdev operations. */
108 outdev_operations_t *op;
109 void *data;
110} outdev_t;
111
[da1bafb]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 *);
[7ddc2c7]116extern void indev_signal(indev_t *, indev_signal_t);
[2677758]117
[da1bafb]118extern void outdev_initialize(const char *, outdev_t *,
119 outdev_operations_t *);
[2677758]120
[da1bafb]121extern bool check_poll(indev_t *);
[44b7783]122
[06e1e95]123#endif /* KERN_CHARDEV_H_ */
[b45c443]124
[06e1e95]125/** @}
[b45c443]126 */
Note: See TracBrowser for help on using the repository browser.