Project

General

Profile

Statistics
| Revision:

root / lab2 / lab2.c @ 9

History | View | Annotate | Download (3.14 KB)

1
#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) 
64
  {
65
    printf("INVALID TIME!");
66
  return 1;
67
  }
68

    
69
  int ipc_status;
70
  message msg;
71
  uint8_t r;
72
  uint8_t bit_no = 0;
73
  timer_subscribe_int(&bit_no);
74
  while( (cont/DEFAULT_FREQ)<time )
75
 { /* You may want to use a different condition */
76
     /* Get a request message. */
77
     // printf("1\n");
78
     //printf("cont:%d, time:%d\n\n",cont/60,time);
79
     if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) 
80
     { 
81
        printf("driver_receive failed with: %d", r);
82
       continue;
83
    }
84
    if (is_ipc_notify(ipc_status)) { /* received notification */
85
        switch (_ENDPOINT_P(msg.m_source)) {
86
            case HARDWARE: /* hardware interrupt notification */                                
87
                if (msg.m_notify.interrupts  & BIT(0)) { /* subscribed interrupt */
88
                   timer_int_handler();
89
                   if(cont%DEFAULT_FREQ==0)
90
                   timer_print_elapsed_time();
91
                   //printf("cont:%d\n",cont);
92
               }
93
                //printf("msg:%x\n",msg.m_notify.interrupts);
94
                break;
95
            default:
96
                //printf("2\n");
97
                break; /* no other notifications expected: do nothing */        
98
        }
99
    } else {
100
     // printf("3\n"); /* received a standard message, not a notification */
101
        /* no standard messages expected: do nothing */
102
    }
103
 }
104
 if(timer_unsubscribe_int()!=0) return 1;
105

    
106

    
107
  //printf("%s is not yet implemented!\n", __func__);
108

    
109
  return 0;
110
}
111
//dois primeiros bits sao 1, (TIMER_RB_CNTRL|BIT(5))
112
//SYS_OUTB para controlo->0x43, Config timer 0, dizer que queremos escrever para o controlo, e depois ler a parte corresponder
113
//g9