Project

General

Profile

Revision 25

fixed interrupt subscription, implemented interrupt handler

View differences:

lab2/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();
lab2/timer.c
5 5

  
6 6
#include "i8254.h"
7 7

  
8
int no_interrupts = 0;
9

  
10 8
int (timer_set_frequency)(uint8_t timer, uint32_t freq) {
11 9

  
12 10
    // Frequencies out this range are not supported (by limitation of hardware)
......
53 51
int hook_id = 2;
54 52

  
55 53
int (timer_subscribe_int)(uint8_t *bit_no) {
54
    *bit_no = hook_id;
56 55
    if(sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE, &hook_id)) return 1;
57
    *bit_no = hook_id;
58 56
    return 0;
59 57
}
60 58

  
......
63 61
    return 0;
64 62
}
65 63

  
64
uint32_t no_interrupts = 0;
66 65
void (timer_int_handler)() {
67 66
    no_interrupts++;
68 67
}
lab2/utils.c
2 2

  
3 3
#include <stdint.h>
4 4

  
5
/* Byte Masks */
6
#define LSB 0xFF /**< @brief mask to filter least significant byte */
7

  
8 5
int(util_get_LSB)(uint16_t val, uint8_t *lsb) {
9 6
    if (lsb == NULL) return 1;
10 7

  
11
    *lsb = val & LSB;
8
    *lsb = (uint8_t)val;
12 9
    return 0;
13 10
}
14 11

  
15 12
int(util_get_MSB)(uint16_t val, uint8_t *msb) {
16 13
    if (msb == NULL) return 1;
17
    *msb = val >> 8;
14
    *msb = (uint8_t)(val >> 8);
18 15
    return 0;
19 16
}
20 17

  
......
22 19
    if(value == NULL) return 1;
23 20
    uint32_t n = 0;
24 21
    if(sys_inb(port, &n)) return 1;
25
    *value = n & LSB;
22
    *value = (uint8_t)n;
26 23
    return 0;
27 24
}

Also available in: Unified diff