From fc6515ef027d94412228875095708b949b801496 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 16 Nov 2010 14:51:59 +0100 Subject: Add basic device handling infrastructure --- device.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 device.c (limited to 'device.c') diff --git a/device.c b/device.c new file mode 100644 index 0000000..249d778 --- /dev/null +++ b/device.c @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2010 Tobias Klauser + * Copyright (C) 2010 chysun2000@gmail.com + * + * This file is part of nios2sim-ng. + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive + * for more details. + */ + +#include + +#include "nios2sim-ng.h" +#include "device.h" +#include "uart.h" +#include "jtag_uart.h" + +static struct device *devices[] = { + &uart_core, + &jtag_uart_core, +}; +#define DEVICES_COUNT ARRAY_SIZE(devices) + +int device_init_all(void) +{ + unsigned int i; + int ret = 0; + + for (i = 0; i < DEVICES_COUNT; i++) { + struct device *dev = devices[i]; + + if (dev->init == NULL) + continue; + + ret = dev->init(dev); + if (ret) { + err("Failed to initialize device '%s'\n", dev->name); + break; + } + + vinfo("%s at 0x%08x\n", dev->name, dev->base); + } + + return ret; +} -- cgit v1.2.3-54-g00ecf