os4ec /Chapter_07_Threads/04_Monitor/kernel/devices.h

Language C/C++ Header Lines 61
MD5 Hash 7b0c73dd59c1b8be301001f3b5f3eedb
Repository https://github.com/l30nard0/os4ec.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*! Devices - common interface */

#pragma once

#include <lib/types.h>

/*! syscall wrappers -------------------------------------------------------- */

int sys__device_open ( char *dev_name, void **dev );
int sys__device_close ( void *dev );
int sys__device_send ( void *data, size_t size, int flags, void *dev );
int sys__device_recv ( void *data, size_t size, int flags, void *dev );
int sys__device_lock ( void *dev, int wait );
int sys__device_unlock ( void *dev );
int sys__set_default_stdin ( char *dev_name, void **dev );
int sys__set_default_stdout ( char *dev_name, void **dev );

#ifndef _KERNEL_

typedef void kdevice_t;

#else /* _KERNEL_ */

#include <lib/list.h>
#include <devices/devices.h>
#include <kernel/thread.h>

/*! Kernel device object */
typedef struct _kdevice_t_
{
	device_t dev;

	int open;

	/* locking device */
	int locked; /* is locked */
	kthread_q thrq; /* locked threads wait in queue */

	list_h list; /* all devices are in list */
}
kdevice_t;

/* interface */
int k_devices_init ();
kdevice_t *k_device_add ( device_t *kdev );
int k_device_init ( kdevice_t *kdev, int flags, void *params, void *callback );
int k_device_remove ( kdevice_t *kdev );

kdevice_t *k_device_open ( char *name );
void k_device_close ( kdevice_t *kdev );

int k_device_send ( void *data, size_t size, int flags, kdevice_t *kdev );
int k_device_recv ( void *data, size_t size, int flags, kdevice_t *kdev );

int k_device_lock ( kdevice_t *dev, int wait );
int k_device_unlock ( kdevice_t *dev );

/* include device headers */
#include <arch/devices.h>

#endif /* _KERNEL_ */
Back to Top