-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlab2.c
More file actions
83 lines (67 loc) · 2.93 KB
/
Copy pathlab2.c
File metadata and controls
83 lines (67 loc) · 2.93 KB
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
#include <lcom/lcf.h>
#include <lcom/lab2.h>
#include <stdbool.h>
#include <stdint.h>
extern uint32_t counter;
int main(int argc, char *argv[]) {
// sets the language of LCF messages (can be either EN-US or PT-PT)
lcf_set_language("EN-US");
// enables to log function invocations that are being "wrapped" by LCF
// [comment this out if you don't want/need it]
lcf_trace_calls("/home/lcom/labs/lab2/trace.txt");
// enables to save the output of printf function calls on a file
// [comment this out if you don't want/need it]
lcf_log_output("/home/lcom/labs/lab2/output.txt");
// handles control over to LCF
// [LCF handles command line arguments and invokes the right function]
if (lcf_start(argc, argv))
return 1;
// LCF clean up tasks
// [must be the last statement before return]
lcf_cleanup();
return 0;
}
int(timer_test_read_config)(uint8_t timer, enum timer_status_field field) {
uint8_t configuration; // variável que vai conter a configuração do timer
if (timer_get_conf(timer, &configuration) != 0) return 1; // chamar a função que preenche a configuração
if (timer_display_conf(timer, configuration, field) != 0) return 1; // display das configurações segundo o field
return 0;
}
int(timer_test_time_base)(uint8_t timer, uint32_t freq) {
if (freq < 19 || timer > 2) return 1; // se o timer não for válido ou a frequência menor que 19 aborta a missão
if (timer_set_frequency(timer, freq) != 0) return 1; // muda a frequência
return 0;
}
int(timer_test_int)(uint8_t time) {
int ipc_status, r;
uint8_t irq_set;
message msg;
if(timer_subscribe_int(&irq_set) != 0) return 1;
while(time > 0) { /* time */
/* Get a request message. */
if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
printf("driver_receive failed with: %d", r);
continue;
}
if (is_ipc_notify(ipc_status)) { /* received notification */
switch (_ENDPOINT_P(msg.m_source)) {
case HARDWARE: /* hardware interrupt notification */
if (msg.m_notify.interrupts & irq_set) { /* subscribed interrupt */
timer_int_handler();
//if (counter == (UINT32_MAX - (UINT32_MAX % 60)) ) { counter = 0; } // "esvazia" o counter para evitar overflow e preserva a lógica do módulo para o lab
if(counter%60==0){
timer_print_elapsed_time();
time--;
}
}
break;
default:
break; /* no other notifications expected: do nothing */
}
} else { /* received a standard message, not a notification */
/* no standard messages expected: do nothing */
}
}
if (timer_unsubscribe_int() != 0) return 1;
return 0;
}