forked from EtchedPixels/FUZIX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevices.c
91 lines (78 loc) · 2.46 KB
/
devices.c
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <kernel.h>
#include <version.h>
#include <kdata.h>
#include <devsys.h>
#include <blkdev.h>
#include <tty.h>
#include <devtty.h>
#include <dev/devsd.h>
#include <printf.h>
#include "globals.h"
#include "picosdk.h"
#include <hardware/irq.h>
#include "core1.h"
struct devsw dev_tab[] = /* The device driver switch table */
{
// minor open close read write ioctl
// ---------------------------------------------------------------------
/* 0: /dev/hd - block device interface */
{ blkdev_open, no_close, blkdev_read, blkdev_write, blkdev_ioctl},
/* 1: /dev/fd - Floppy disk block devices */
{ no_open, no_close, no_rdwr, no_rdwr, no_ioctl},
/* 2: /dev/tty TTY devices */
{ tty_open, tty_close, tty_read, tty_write, tty_ioctl },
/* 3: /dev/lpr Printer devices */
{ no_open, no_close, no_rdwr, no_rdwr, no_ioctl },
/* 4: /dev/mem etc System devices (one offs) */
{ no_open, sys_close, sys_read, sys_write, sys_ioctl },
/* Pack to 7 with nxio if adding private devices and start at 8 */
};
static absolute_time_t now;
bool validdev(uint16_t dev)
{
/* This is a bit uglier than needed but the right hand side is
a constant this way */
if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1)
return false;
else
return true;
}
static void timer_tick_cb(unsigned alarm)
{
irqflags_t irq = di();
udata.u_ininterrupt = 1;
absolute_time_t next;
update_us_since_boot(&next, to_us_since_boot(now) + (1000000 / TICKSPERSEC));
tty_interrupt();
timer_interrupt();
if (hardware_alarm_set_target(0, next))
{
update_us_since_boot(&next, time_us_64() + (1000000 / TICKSPERSEC));
hardware_alarm_set_target(0, next);
}
udata.u_ininterrupt = 0;
irqrestore(irq);
}
#ifdef CONFIG_NET
extern void netdev_init(void);
#endif
void device_init(void)
{
/* Timer interrup must be initialized before blcok devices.
set_boot_line uses pause syscall which will not be operational otherwise. */
hardware_alarm_claim(0);
update_us_since_boot(&now, time_us_64());
hardware_alarm_set_callback(0, timer_tick_cb);
hardware_alarm_force_irq(0);
/* The flash device is too small to be useful, and a corrupt flash will
* cause a crash on startup... oddly. */
#ifdef CONFIG_PICO_FLASH
flash_dev_init();
#endif
#ifdef CONFIG_NET
netdev_init();
#endif
sd_rawinit();
devsd_init();
}
/* vim: sw=4 ts=4 et: */