diff options
author | Tobias Klauser <klto@zhaw.ch> | 2010-11-16 14:51:59 +0100 |
---|---|---|
committer | Tobias Klauser <klto@zhaw.ch> | 2010-11-16 14:52:20 +0100 |
commit | fc6515ef027d94412228875095708b949b801496 (patch) | |
tree | 2640edc09346a4d97cf09bb39d2ea8b21feceb86 /device.c | |
parent | 6f8db3bda1c2644adfc25b83b73285df9a80585d (diff) |
Add basic device handling infrastructure
Diffstat (limited to 'device.c')
-rw-r--r-- | device.c | 46 |
1 files changed, 46 insertions, 0 deletions
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 <tklauser@distanz.ch> + * 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 <stdio.h> + +#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; +} |