aboutsummaryrefslogtreecommitdiff
path: root/usr/main.c
blob: b6cfee36a9f75e8cb63725d30eb90945b14b9867 (plain)
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
94
95
96
97
98
99
100
#include <graphics/lfb.h>
#include <globals.h>
#include <symbols.h>
#include <sys/schedule.h>
#include <util/time.h>

void loop(void);

void handle_data(unsigned char data)
{
	// Newline Case
	if (data == 0x0D) {
	// Backspace Case
	} else if (data == 0x08 || data == 0x7F) {
	} else if (data == 0x61) {
		add_thread(uart_scheduler, 0, 2);
	} else if (data == 0x62) {
		//add_thread(test_entry, 0, 2);
	}
	// Draw it on the screen
	{
		draw_chex32(0, 9, data, 0xAA00FF);
	}
}

char* ulong_to_string(unsigned long value, char* data)
{
	unsigned long t = value;
	unsigned long c;
	char* dptr = data + 10;
	for (int i = 0; i <= 10; i++) {
		c = t%10;
		*dptr = 0x30 + (c&0xF);
		t /= 10;
		if (t==0)
			break;
		dptr -= 1;
		if (i == 5) {
			*dptr = '.';
			dptr -= 1;
		}
	}
	return dptr;
}

void loop(void)
{
	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++;
	wait_msec(3000);
	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 == 2)
		unsubscribe_irq(SYS_TIMER_1_IRQ);
	if (cnt == 0)
		unsubscribe_irq(SYS_TIMER_0_IRQ);
}

static struct SysTimerInfo stime_0 = {
	.tick_rate = 5000000,
	.priority = 0,
	.arg = 0,
};

static struct SysTimerInfo stime_1 = {
	.tick_rate = 300000,
	.priority = 0,
	.arg = 0,
};

static struct UartInfo UART_INFO = {
	.priority = 2,
};

void main(void)
{
	subscribe_irq(UART_IRQ, handle_data, &UART_INFO);
	subscribe_irq(SYS_TIMER_0_IRQ, loopt, &stime_0);
	subscribe_irq(SYS_TIMER_1_IRQ, loopt, &stime_1);
	add_thread(loop, 0, 0);
}