genode/os/src/drivers/uart/omap4/main.cc

89 lines
1.9 KiB
C++

/*
* \brief Driver for OMAP4 UARTs
* \author Ivan Loskutov <ivan.loskutov@ksyslabs.org>
* \date 2012-11-08
*/
/*
* Copyright (C) 2012 Ksys Labs LLC
* Copyright (C) 2011-2012 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <base/printf.h>
#include <base/sleep.h>
#include <os/config.h>
#include <cap_session/connection.h>
#include <os/attached_io_mem_dataspace.h>
#include <uart_defs.h>
/* local includes */
#include "omap_uart.h"
#include "uart_component.h"
int main(int argc, char **argv)
{
using namespace Genode;
PDBG("--- OMAP4 UART driver started ---\n");
/**
* Factory used by 'Terminal::Root' at session creation/destruction time
*/
struct Omap_uart_driver_factory : Uart::Driver_factory
{
Omap_uart *created[UARTS_NUM];
/**
* Constructor
*/
Omap_uart_driver_factory()
{
for (unsigned i = 0; i < UARTS_NUM; i++)
created[i] = 0;
}
Uart::Driver *create(unsigned index,
Uart::Char_avail_callback &callback)
{
if (index > UARTS_NUM)
throw Uart::Driver_factory::Not_available();
Omap_uart_cfg *cfg = &omap_uart_cfg[index];
Omap_uart *uart = created[index];
Genode::Attached_io_mem_dataspace *uart_mmio = new (env()->heap())
Genode::Attached_io_mem_dataspace(cfg->mmio_base, cfg->mmio_size);
if (!uart) {
uart = new (env()->heap())
Omap_uart(uart_mmio, cfg->irq_number, BAUD_115200, callback);
/* update 'created' table */
created[index] = uart;
}
return uart;
}
void destroy(Uart::Driver *driver) { /* TODO */ }
} driver_factory;
enum { STACK_SIZE = 0x2000 };
static Cap_connection cap;
static Rpc_entrypoint ep(&cap, STACK_SIZE, "uart_ep");
static Uart::Root uart_root(&ep, env()->heap(), driver_factory);
env()->parent()->announce(ep.manage(&uart_root));
sleep_forever();
return 0;
}