Project

General

Profile

Statistics
| Revision:

root / lab4 / lab3 / lab2.c @ 13

History | View | Annotate | Download (3.1 KB)

1 13 up20180614
#include <lcom/lcf.h>
2
#include <lcom/lab2.h>
3
4
#include <stdbool.h>
5
#include <stdint.h>
6
7
#include "i8254.h"
8
//#include "timer.c"
9
extern uint32_t cont;
10
11
12
int main(int argc, char *argv[]) {
13
14
  // sets the language of LCF messages (can be either EN-US or PT-PT)
15
  lcf_set_language("EN-US");
16
17
  // enables to log function invocations that are being "wrapped" by LCF
18
  // [comment this out if you don't want/need it]
19
  lcf_trace_calls("/home/lcom/labs/lab2/trace.txt");
20
21
  // enables to save the output of printf function calls on a file
22
  // [comment this out if you don't want/need it]
23
  lcf_log_output("/home/lcom/labs/lab2/output.txt");
24
25
  // handles control over to LCF
26
  // [LCF handles command line arguments and invokes the right function]
27
  if (lcf_start(argc, argv))
28
    return 1;
29
30
  // LCF clean up tasks
31
  // [must be the last statement before return]
32
  lcf_cleanup();
33
34
  return 0;
35
}
36
37
int(timer_test_read_config)(uint8_t timer, enum timer_status_field field) {
38
  /* To be implemented by the students */
39
  uint8_t st;
40
  if(timer_get_conf(timer,&st)==1) return 1;
41
  if(timer_display_conf(timer,st,field)==1) return 1;
42
43
  return 0;
44
 // printf("%s is not yet implemented!\n", __func__);
45
46
}
47
48
int(timer_test_time_base)(uint8_t timer, uint32_t freq) {
49
  /* To be implemented by the students */
50
  if(freq<MIN_FREQ || freq>TIMER_FREQ)
51
  {
52
    printf("OUT OF RANGE FREQUENCY\n");
53
    return 1;
54
  }
55
  return(timer_set_frequency(timer,freq));
56
  //printf("%s is not yet implemented!\n", __func__);
57
58
}
59
60
int(timer_test_int)(uint8_t time) {
61
  /* To be implemented by the students */
62
63
  if(time<0) return 1;
64
65
  int ipc_status;
66
  message msg;
67
  uint8_t r;
68
  uint8_t bit_no = 0;
69
  timer_subscribe_int(&bit_no);
70
  while( (cont/DEFAULT_FREQ)<time )
71
 { /* You may want to use a different condition */
72
     /* Get a request message. */
73
     // printf("1\n");
74
     //printf("cont:%d, time:%d\n\n",cont/60,time);
75
     if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 )
76
     {
77
        printf("driver_receive failed with: %d", r);
78
       continue;
79
    }
80
    if (is_ipc_notify(ipc_status)) { /* received notification */
81
        switch (_ENDPOINT_P(msg.m_source)) {
82
            case HARDWARE: /* hardware interrupt notification */
83
                if (msg.m_notify.interrupts  & BIT(0)) { /* subscribed interrupt */
84
                   timer_int_handler();
85
                   if(cont%DEFAULT_FREQ==0)
86
                   timer_print_elapsed_time();
87
                   //printf("cont:%d\n",cont);
88
               }
89
                //printf("msg:%x\n",msg.m_notify.interrupts);
90
                break;
91
            default:
92
                //printf("2\n");
93
                break; /* no other notifications expected: do nothing */
94
        }
95
    } else {
96
     // printf("3\n"); /* received a standard message, not a notification */
97
        /* no standard messages expected: do nothing */
98
    }
99
 }
100
 if(timer_unsubscribe_int()!=0) return 1;
101
102
103
  //printf("%s is not yet implemented!\n", __func__);
104
105
  return 0;
106
}
107
//dois primeiros bits sao 1, (TIMER_RB_CNTRL|BIT(5))
108
//SYS_OUTB para controlo->0x43, Config timer 0, dizer que queremos escrever para o controlo, e depois ler a parte corresponder
109
//g9