Import a framework to program PICs
This commit is contained in:
parent
3f044e4d09
commit
5f4514de4f
52
src/drivers/pic.c
Normal file
52
src/drivers/pic.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS uKernel */
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "pic.h"
|
||||
|
||||
|
||||
/* private */
|
||||
/* variables */
|
||||
static ukPIC * _pic = NULL;
|
||||
|
||||
|
||||
/* functions */
|
||||
/* pic_init */
|
||||
ukPIC * pic_init(ukBus * bus, char const * name)
|
||||
{
|
||||
const ukPIC * drivers[] = {
|
||||
};
|
||||
size_t i;
|
||||
ukPIC * pic = NULL;
|
||||
|
||||
for(i = 0; i < sizeof(drivers) / sizeof(*drivers); i++)
|
||||
if(strncmp(drivers[i]->name, name,
|
||||
strlen(drivers[i]->name)) == 0
|
||||
&& drivers[i]->init != NULL)
|
||||
{
|
||||
fprintf(stderr, "%s PIC%s%s\n", name, (bus != NULL)
|
||||
? " at " : "",
|
||||
(bus != NULL) ? bus->name : "");
|
||||
pic = drivers[i]->init(bus);
|
||||
}
|
||||
if(pic == NULL)
|
||||
errno = ENODEV;
|
||||
else if(_pic == NULL)
|
||||
_pic = pic;
|
||||
return pic;
|
||||
}
|
||||
|
||||
|
||||
/* accessors */
|
||||
/* pic_get_default */
|
||||
ukPIC * pic_get_default(void)
|
||||
{
|
||||
if(_pic == NULL)
|
||||
errno = ENODEV;
|
||||
return _pic;
|
||||
}
|
38
src/drivers/pic.h
Normal file
38
src/drivers/pic.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS uKernel */
|
||||
|
||||
|
||||
|
||||
#ifndef UKERNEL_DRIVERS_PIC_H
|
||||
# define UKERNEL_DRIVERS_PIC_H
|
||||
|
||||
# include <stdint.h>
|
||||
# include "bus.h"
|
||||
|
||||
|
||||
/* public */
|
||||
/* types */
|
||||
typedef struct _ukPIC ukPIC;
|
||||
|
||||
typedef struct _ukPICData ukPICData;
|
||||
|
||||
struct _ukPIC
|
||||
{
|
||||
char name[16];
|
||||
|
||||
ukPIC * (*init)(ukBus * bus);
|
||||
void (*destroy)(ukPIC * pic);
|
||||
|
||||
ukPICData * data;
|
||||
};
|
||||
|
||||
|
||||
/* prototypes */
|
||||
ukPIC * pic_init(ukBus * bus, char const * name);
|
||||
void pic_destroy(ukPIC * pic);
|
||||
|
||||
/* accessors */
|
||||
ukPIC * pic_get_default(void);
|
||||
|
||||
#endif /* !UKERNEL_DRIVERS_PIC_H */
|
5
src/drivers/pic/project.conf
Normal file
5
src/drivers/pic/project.conf
Normal file
|
@ -0,0 +1,5 @@
|
|||
cppflags_force=-nostdinc -isystem ../../../include -I../..
|
||||
cflags_force=`../../../tools/platform.sh -V UKERNEL_CFLAGS -C "$$ARCH"`
|
||||
cflags=-W -Wall -g -O2
|
||||
ldflags_force=`../../../tools/platform.sh -V UKERNEL_LDFLAGS -C "$$ARCH"`
|
||||
dist=Makefile
|
Loading…
Reference in New Issue
Block a user