1/**
2 * \file
3 * \brief Serial port driver.
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2010, 2011, 2012, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, CAB F.78, Universitaetstr. 6, CH-8092 Zurich,
13 * Attn: Systems Group.
14 */
15
16#include <barrelfish/barrelfish.h>
17#include <barrelfish/inthandler.h>
18#include <driverkit/driverkit.h>
19#include "serial.h"
20
21static void
22serial_interrupt(void *arg) {
23    char c;
24    errval_t err= sys_getchar(&c);
25    assert(err_is_ok(err));
26
27    //printf("'%c'\n", c);
28
29    serial_input(&c, 1);
30}
31
32errval_t serial_init(struct serial_params *params)
33{
34    errval_t err;
35
36    if(params->irq == SERIAL_IRQ_INVALID)
37        USER_PANIC("serial_kernel requires an irq= parameter");
38
39    /* Register interrupt handler. */
40    err = inthandler_setup_arm(serial_interrupt, NULL, params->irq);
41    if (err_is_fail(err)) {
42        USER_PANIC_ERR(err, "interrupt setup failed.");
43    }
44
45    // offer service now we're up
46    start_service();
47    return SYS_ERR_OK;
48}
49
50
51void serial_write(const char *c, size_t len)
52{
53    sys_print(c, len);
54}
55