forked from MiSTer-devel/Main_MiSTer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.cpp
93 lines (79 loc) · 1.33 KB
/
scheduler.cpp
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
91
92
93
#include "scheduler.h"
#include <stdio.h>
#include "libco.h"
#include "menu.h"
#include "user_io.h"
#include "input.h"
#include "fpga_io.h"
#include "osd.h"
#include "profiling.h"
static cothread_t co_scheduler = nullptr;
static cothread_t co_poll = nullptr;
static cothread_t co_ui = nullptr;
static cothread_t co_last = nullptr;
static void scheduler_wait_fpga_ready(void)
{
while (!is_fpga_ready(1))
{
fpga_wait_to_reset();
}
}
static void scheduler_co_poll(void)
{
for (;;)
{
scheduler_wait_fpga_ready();
{
SPIKE_SCOPE("co_poll", 1000);
user_io_poll();
input_poll(0);
}
scheduler_yield();
}
}
static void scheduler_co_ui(void)
{
for (;;)
{
{
SPIKE_SCOPE("co_ui", 1000);
HandleUI();
OsdUpdate();
}
scheduler_yield();
}
}
static void scheduler_schedule(void)
{
if (co_last == co_poll)
{
co_last = co_ui;
co_switch(co_ui);
}
else
{
co_last = co_poll;
co_switch(co_poll);
}
}
void scheduler_init(void)
{
const unsigned int co_stack_size = 262144 * sizeof(void*);
co_poll = co_create(co_stack_size, scheduler_co_poll);
co_ui = co_create(co_stack_size, scheduler_co_ui);
}
void scheduler_run(void)
{
co_scheduler = co_active();
for (;;)
{
scheduler_schedule();
}
co_delete(co_ui);
co_delete(co_poll);
co_delete(co_scheduler);
}
void scheduler_yield(void)
{
co_switch(co_scheduler);
}