Default driver

This commit is contained in:
Thomas Klaehn
2021-06-09 07:41:08 +02:00
parent dd825149d9
commit 8cae731729
6 changed files with 124 additions and 119 deletions

12
inc/board.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef __BOARD_H__
#define __BOARD_H__
#include "driver.h"
#include "test_drv.h"
static const struct driver tst_drv = {
.fp = &tst_fp,
.dev = NULL
};
#endif

28
inc/driver.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef __DRIVER_H__
#define __DRIVER_H__
struct driver;
typedef int (*fp_open_t)(const struct driver *);
typedef int (*fp_close_t)(const struct driver *);
typedef int (*fp_read_t)(const struct driver *, char *, unsigned int);
typedef int (*fp_write_t)(const struct driver *, const char *, unsigned int);
struct driver_fp {
fp_open_t open;
fp_close_t close;
fp_read_t read;
fp_write_t write;
};
struct driver {
const struct driver_fp *fp;
const void *dev;
};
int drv_open(const struct driver *drv);
int drv_close(const struct driver *drv);
int drv_read(const struct driver *drv, char *buffer, unsigned int length);
int drv_write(const struct driver *drv, const char *buffer, unsigned int length);
#endif

20
inc/test_drv.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef __TEST_DRV_H__
#define __TEST_DRV_H__
#include <stdlib.h>
#include "driver.h"
int tst_open(const struct driver *drv);
int tst_close(const struct driver *drv);
int tst_read(const struct driver *drv, char *buffer, unsigned int length);
int tst_write(const struct driver *drv, const char *buffer, unsigned int length);
static const struct driver_fp tst_fp = {
.open = tst_open,
.close = tst_close,
.read = tst_read,
.write = tst_write
};
#endif