Project

General

Profile

Revision 25

fixed interrupt subscription, implemented interrupt handler

View differences:

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

  
7
extern int no_interrupts;
8

  
9 7
int main(int argc, char *argv[]) {
10 8
  // sets the language of LCF messages (can be either EN-US or PT-PT)
11 9
  lcf_set_language("EN-US");
......
42 40
  return 0;
43 41
}
44 42

  
43
extern uint32_t no_interrupts;
44

  
45 45
int(timer_test_int)(uint8_t time) {
46 46
    int ipc_status, r;
47 47
    message msg;
48 48
    uint8_t hook = 0;
49 49
    no_interrupts = 0;
50
    uint8_t irq_set = 1;
51
    int freq = 60; // better way to get the frequency of the timer????
52

  
50
    int freq = 60; // better way to get the frequency of the timer???
51
    printf("Hook pre: %x\n", hook);
53 52
    timer_subscribe_int(&hook);
53
    printf("Hook pos: %x\n", hook);
54
    int irq_set = BIT(hook);
54 55

  
55 56
    while (time) {
56 57
        /* Get a request message. */
......
61 62
        if (is_ipc_notify(ipc_status)) { /* received notification */
62 63
            switch (_ENDPOINT_P(msg.m_source)) {
63 64
                case HARDWARE: /* hardware interrupt notification */
65
                    printf("%x\n", msg.m_notify.interrupts);
64 66
                    if (msg.m_notify.interrupts & irq_set) { /* subscribed interrupt */
65 67
                        timer_int_handler();
68

  
69
                        if (!(no_interrupts % freq)) {
70
                            timer_print_elapsed_time();
71
                            time--;
72
                        }
66 73
                    }
67 74
                    break;
68 75
                default:
......
71 78
        } else { /* received standart message, not a notification */
72 79
            /* no standart message expected: do nothing */
73 80
        }
74
        if (!(no_interrupts % freq)) {
75
            timer_print_elapsed_time();
76
            time--;
77
        }
78 81
    }
79 82

  
80 83
    timer_unsubscribe_int();

Also available in: Unified diff