root / lab2 / lab2.c @ 25
History | View | Annotate | Download (2.58 KB)
1 | 4 | up20180655 | #include <lcom/lcf.h> |
---|---|---|---|
2 | #include <lcom/lab2.h> |
||
3 | |||
4 | #include <stdbool.h> |
||
5 | #include <stdint.h> |
||
6 | |||
7 | int main(int argc, char *argv[]) { |
||
8 | // sets the language of LCF messages (can be either EN-US or PT-PT)
|
||
9 | lcf_set_language("EN-US");
|
||
10 | |||
11 | // enables to log function invocations that are being "wrapped" by LCF
|
||
12 | // [comment this out if you don't want/need it]
|
||
13 | lcf_trace_calls("/home/lcom/labs/lab2/trace.txt");
|
||
14 | |||
15 | // enables to save the output of printf function calls on a file
|
||
16 | // [comment this out if you don't want/need it]
|
||
17 | lcf_log_output("/home/lcom/labs/lab2/output.txt");
|
||
18 | |||
19 | // handles control over to LCF
|
||
20 | // [LCF handles command line arguments and invokes the right function]
|
||
21 | if (lcf_start(argc, argv))
|
||
22 | return 1; |
||
23 | |||
24 | // LCF clean up tasks
|
||
25 | // [must be the last statement before return]
|
||
26 | lcf_cleanup(); |
||
27 | |||
28 | return 0; |
||
29 | } |
||
30 | |||
31 | 6 | up20180642 | int(timer_test_read_config)(uint8_t timer, enum timer_status_field field){ |
32 | 5 | up20180642 | uint8_t state = 0;
|
33 | if(timer_get_conf(timer, &state)) return 1; |
||
34 | 6 | up20180642 | if(timer_display_conf(timer, state, field)) return 1; |
35 | 5 | up20180642 | return 0; |
36 | 4 | up20180655 | } |
37 | |||
38 | int(timer_test_time_base)(uint8_t timer, uint32_t freq) {
|
||
39 | 15 | up20180655 | if (timer_set_frequency(timer, freq)) return 1; |
40 | return 0; |
||
41 | 4 | up20180655 | } |
42 | |||
43 | 25 | up20180655 | extern uint32_t no_interrupts;
|
44 | |||
45 | 4 | up20180655 | int(timer_test_int)(uint8_t time) {
|
46 | 20 | up20180655 | int ipc_status, r;
|
47 | message msg; |
||
48 | uint8_t hook = 0;
|
||
49 | 23 | up20180655 | no_interrupts = 0;
|
50 | 25 | up20180655 | int freq = 60; // better way to get the frequency of the timer??? |
51 | printf("Hook pre: %x\n", hook);
|
||
52 | 20 | up20180655 | timer_subscribe_int(&hook); |
53 | 25 | up20180655 | printf("Hook pos: %x\n", hook);
|
54 | int irq_set = BIT(hook);
|
||
55 | 20 | up20180655 | |
56 | 23 | up20180655 | while (time) {
|
57 | 20 | up20180655 | /* Get a request message. */
|
58 | if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
||
59 | printf("driver_receive failed with %d", r);
|
||
60 | continue;
|
||
61 | } |
||
62 | if (is_ipc_notify(ipc_status)) { /* received notification */ |
||
63 | switch (_ENDPOINT_P(msg.m_source)) {
|
||
64 | case HARDWARE: /* hardware interrupt notification */ |
||
65 | 25 | up20180655 | printf("%x\n", msg.m_notify.interrupts);
|
66 | 20 | up20180655 | if (msg.m_notify.interrupts & irq_set) { /* subscribed interrupt */ |
67 | timer_int_handler(); |
||
68 | 25 | up20180655 | |
69 | if (!(no_interrupts % freq)) {
|
||
70 | timer_print_elapsed_time(); |
||
71 | time--; |
||
72 | } |
||
73 | 20 | up20180655 | } |
74 | break;
|
||
75 | default:
|
||
76 | break; /* no other notifications expected: do nothing */ |
||
77 | } |
||
78 | } else { /* received standart message, not a notification */ |
||
79 | /* no standart message expected: do nothing */
|
||
80 | } |
||
81 | } |
||
82 | |||
83 | 22 | up20180642 | timer_unsubscribe_int(); |
84 | 20 | up20180655 | |
85 | return 0; |
||
86 | 4 | up20180655 | } |