source: mainline/uspace/srv/hid/fb/port/kchar.c@ 446ac2a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 446ac2a was 446ac2a, checked in by Martin Decky <martin@…>, 13 years ago

avoid compiler warning

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
3 * Copyright (c) 2008 Martin Decky
4 * All rights reserved.
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 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @file
31 */
32
33#include <sys/types.h>
34#include <errno.h>
35#include <sysinfo.h>
36#include <ddi.h>
37#include <as.h>
38#include <align.h>
39#include "../ctl/serial.h"
40#include "kchar.h"
41
42typedef struct {
43 uint8_t *addr;
44} kchar_t;
45
46static kchar_t kchar;
47
48static void kchar_putchar(wchar_t ch)
49{
50 if (ascii_check(ch))
51 *kchar.addr = ch;
52 else
53 *kchar.addr = '?';
54}
55
56static void kchar_control_puts(const char *str)
57{
58 while (*str)
59 *kchar.addr = *(str++);
60}
61
62int kchar_init(void)
63{
64 sysarg_t present;
65 int rc = sysinfo_get_value("fb", &present);
66 if (rc != EOK)
67 present = false;
68
69 if (!present)
70 return ENOENT;
71
72 sysarg_t kind;
73 rc = sysinfo_get_value("fb.kind", &kind);
74 if (rc != EOK)
75 kind = (sysarg_t) -1;
76
77 if (kind != 3)
78 return EINVAL;
79
80 sysarg_t paddr;
81 rc = sysinfo_get_value("fb.address.physical", &paddr);
82 if (rc != EOK)
83 return rc;
84
85 rc = physmem_map((void *) paddr,
86 ALIGN_UP(1, PAGE_SIZE) >> PAGE_WIDTH,
87 AS_AREA_READ | AS_AREA_WRITE, (void *) &kchar.addr);
88 if (rc != EOK)
89 return rc;
90
91 return serial_init(kchar_putchar, kchar_control_puts);
92}
93
94/** @}
95 */
Note: See TracBrowser for help on using the repository browser.