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
|
#define USR_TIMED_C
#include <cpu.h>
#include <globals.h>
#include <graphics/lfb.h>
#include <symbols.h>
#include <usr/string.h>
#include <usr/timed.h>
#include <util/time.h>
static unsigned long simulated = 0;
void producer(void)
{
draw_string(0, 15, "Producing...");
sys1(SYS_SEMAPHORE_V, &simulated);
draw_string(0, 15, "Produced! ");
}
void consumer(void)
{
add_thread(producer, 0, 4);
while (1) {
draw_string(0, 16, "Consuming...");
sys1(SYS_SEMAPHORE_P, &simulated);
draw_string(0, 16, "Consumed! ");
}
}
void loop(void)
{
unsigned long long ti, tf;
sys0_64(SYS_TIME, &ti);
static char str[13];
static unsigned long previous = 0;
char* start;
unsigned long current = *(volatile unsigned long*)SYS_TIMER_CHI;
start = ulong_to_string(current, str);
draw_string(0, 10, " ");
draw_string(0, 10, start);
start = ulong_to_string(previous, str);
draw_string(0, 11, " ");
draw_string(0, 11, start);
start = ulong_to_string(nextpid, str);
draw_string(0, 12, " ");
draw_string(0, 12, start);
previous++;
//unsigned long gplev0 = *(volatile unsigned long*)GPLEV0;
//static unsigned long count = 0;
//draw_hex32(0, 13, gplev0);
//if (gplev0 & (1 << 16)) {
// draw_hex32(0, 17, count++);
// add_thread(producer, 0, 4);
//}
sys0_64(SYS_TIME, &tf);
draw_hex32(0, 13, tf-ti);
wait_msec(30000);
//add_thread(loop, 0, 3);
}
void loopt(void)
{
static char str[13];
static char cnt = 18;
draw_string(0, 14, ulong_to_string(*(volatile unsigned long*)SYS_TIMER_CHI, str));
cnt--;
if (cnt == 6)
unsubscribe_irq(SYS_TIMER_3_IRQ);
if (cnt == 4)
unsubscribe_irq(SYS_TIMER_2_IRQ);
else if (cnt == 2)
unsubscribe_irq(SYS_TIMER_1_IRQ);
else if (cnt == 0)
unsubscribe_irq(SYS_TIMER_0_IRQ);
}
|