serial: Allow more than one serial device to be registered
This commit is contained in:
parent
828beb45bd
commit
0b7e14c69b
@ -21,16 +21,21 @@
|
||||
#include <init.h>
|
||||
#include <drivers/serial.h>
|
||||
|
||||
struct serial_dev *first_serial_dev;
|
||||
struct dlist_node serial_dev_list;
|
||||
|
||||
int serial_register_device(struct serial_dev *sdev) {
|
||||
if (!first_serial_dev)
|
||||
first_serial_dev = sdev;
|
||||
if (!sdev)
|
||||
return -1;
|
||||
|
||||
insert_before(&serial_dev_list, &sdev->list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct serial_dev *serial_first_device() {
|
||||
return first_serial_dev;
|
||||
if (list_empty(&serial_dev_list))
|
||||
return 0;
|
||||
|
||||
return container(serial_dev_list.next, struct serial_dev, list);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -40,5 +45,5 @@ struct serial_dev *serial_first_device() {
|
||||
* initialized in earlyinitcalls.
|
||||
*/
|
||||
void serial_init() {
|
||||
first_serial_dev = 0;
|
||||
init_list(&serial_dev_list);
|
||||
}
|
||||
|
@ -18,9 +18,12 @@
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <list.h>
|
||||
|
||||
struct serial_dev {
|
||||
//TODO add more functions and attributes here
|
||||
int (*putc)(char);
|
||||
struct dlist_node list;
|
||||
};
|
||||
|
||||
int serial_register_device(struct serial_dev *sdev);
|
||||
|
Loading…
Reference in New Issue
Block a user