Project

General

Profile

Revision 20

timer_test_int prototype

View differences:

lab2.c
4 4
#include <stdbool.h>
5 5
#include <stdint.h>
6 6

  
7
int no_interrupts = 0;
7 8

  
8 9
int main(int argc, char *argv[]) {
9 10
  // sets the language of LCF messages (can be either EN-US or PT-PT)
......
42 43
}
43 44

  
44 45
int(timer_test_int)(uint8_t time) {
45
  /* To be implemented by the students */
46
  printf("%s is not yet implemented!\n", __func__);
46
    int ipc_status, r;
47
    message msg;
47 48

  
48
  return 1;
49
    uint8_t hook = 0;
50
    int no_interrupts = 0;
51
    int freq = 60; // better way to get the frequency of the timer????
52

  
53
    timer_subscribe_int(&hook);
54

  
55
    while (no_interrupts < time * freq) {
56
        /* Get a request message. */
57
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
58
            printf("driver_receive failed with %d", r);
59
            continue;
60
        }
61
        if (is_ipc_notify(ipc_status)) { /* received notification */
62
            switch (_ENDPOINT_P(msg.m_source)) {
63
                case HARDWARE: /* hardware interrupt notification */
64
                    if (msg.m_notify.interrupts & irq_set) { /* subscribed interrupt */
65
                        timer_int_handler();
66
                    }
67
                    break;
68
                default:
69
                    break; /* no other notifications expected: do nothing */
70
            }
71
        } else { /* received standart message, not a notification */
72
            /* no standart message expected: do nothing */
73
        }
74
        if (!(no_interrupts % freq))
75
            timer_print_elapsed_time();
76
    }
77

  
78
    timer_unsubscribe_int(&hook);
79

  
80
  return 0;
49 81
}

Also available in: Unified diff