root / proj / proj.c @ 149
History | View | Annotate | Download (2.73 KB)
1 | 144 | up20180655 | #include <lcom/lcf.h> |
---|---|---|---|
2 | #include <lcom/proj.h> |
||
3 | #include <lcom/liblm.h> |
||
4 | |||
5 | 147 | up20180655 | #include <stdbool.h> |
6 | 144 | up20180655 | #include <stdint.h> |
7 | |||
8 | 149 | up20180655 | #include "i8254.h" |
9 | #include "kbc_macros.h" |
||
10 | #include "graphics_macros.h" |
||
11 | #include "proj_macros.h" |
||
12 | #include "errors.h" |
||
13 | 147 | up20180655 | |
14 | 149 | up20180655 | #include "kbc.h" |
15 | #include "graphics.h" |
||
16 | #include "timer.h" |
||
17 | #include "keyboard.h" |
||
18 | #include "utils.h" |
||
19 | |||
20 | 144 | up20180655 | int main(int argc, char* argv[]) { |
21 | |||
22 | lcf_set_language("EN-US");
|
||
23 | |||
24 | //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
|
||
25 | |||
26 | //lcf_log_output("/home/lcom/labs/proj/output.txt");
|
||
27 | |||
28 | if (lcf_start(argc, argv)) return 1; |
||
29 | |||
30 | lcf_cleanup(); |
||
31 | |||
32 | return 0; |
||
33 | } |
||
34 | 147 | up20180655 | |
35 | 149 | up20180655 | int(proj_main_loop)(int argc, char *argv[]) { |
36 | 147 | up20180655 | |
37 | 149 | up20180655 | /// loop stuff
|
38 | int ipc_status, r;
|
||
39 | message msg; |
||
40 | /// Keyboard interrupt handling
|
||
41 | uint8_t kbc_irq_bit = KBC_IRQ; |
||
42 | int kbc_id = 0; |
||
43 | int kbc_irq = BIT(kbc_irq_bit);
|
||
44 | if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) {
|
||
45 | return 1; |
||
46 | } |
||
47 | 147 | up20180655 | |
48 | 149 | up20180655 | /// Timer interrupt handling
|
49 | //const uint32_t frequency = sys_hz(); // Frequency asummed at 60Hz
|
||
50 | uint8_t timer_irq_bit = TIMER0_IRQ; |
||
51 | int timer_id = 0; |
||
52 | int timer_irq = BIT(timer_irq_bit);
|
||
53 | if(subscribe_timer_interrupt(timer_irq_bit, &timer_id)) {
|
||
54 | if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
||
55 | if (free_memory_map()) {
|
||
56 | printf("%s: lm_free failed\n", __func__);
|
||
57 | } |
||
58 | return 1; |
||
59 | } |
||
60 | |||
61 | 147 | up20180655 | /// cycle
|
62 | int good = 1; |
||
63 | while (good) {
|
||
64 | /* Get a request message. */
|
||
65 | if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
||
66 | printf("driver_receive failed with %d", r);
|
||
67 | continue;
|
||
68 | } |
||
69 | if (is_ipc_notify(ipc_status)) { /* received notification */ |
||
70 | switch (_ENDPOINT_P(msg.m_source)) {
|
||
71 | case HARDWARE: /* hardware interrupt notification */ |
||
72 | if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */ |
||
73 | kbc_ih(); |
||
74 | if (scancode[0] == ESC_BREAK_CODE) good = 0; |
||
75 | } |
||
76 | 149 | up20180655 | if (msg.m_notify.interrupts & timer_irq) { /* subscribed interrupt */ |
77 | timer_int_handler(); |
||
78 | } |
||
79 | 147 | up20180655 | break;
|
80 | default:
|
||
81 | break; /* no other notifications expected: do nothing */ |
||
82 | } |
||
83 | } else { /* received standart message, not a notification */ |
||
84 | /* no standart message expected: do nothing */
|
||
85 | } |
||
86 | } |
||
87 | 149 | up20180655 | |
88 | // Unsubscribe Keyboard interrupts
|
||
89 | if (unsubscribe_interrupt(&kbc_id)) {
|
||
90 | return 1; |
||
91 | }; |
||
92 | |||
93 | // Unsubscribe Timer Interrupts
|
||
94 | if (unsubscribe_interrupt(&timer_id)) {
|
||
95 | return 1; |
||
96 | } |
||
97 | |||
98 | return 0; |
||
99 | 147 | up20180655 | } |