Project

General

Profile

Revision 26

minor changes

View differences:

lab2/lab2.c
40 40
  return 0;
41 41
}
42 42

  
43
extern uint32_t no_interrupts;
43
extern int no_interrupts;
44 44

  
45 45
int(timer_test_int)(uint8_t time) {
46 46
    int ipc_status, r;
......
48 48
    uint8_t hook = 0;
49 49
    no_interrupts = 0;
50 50
    int freq = 60; // better way to get the frequency of the timer???
51
    printf("Hook pre: %x\n", hook);
52 51
    timer_subscribe_int(&hook);
53
    printf("Hook pos: %x\n", hook);
54 52
    int irq_set = BIT(hook);
55

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

  
69 64
                        if (!(no_interrupts % freq)) {
70 65
                            timer_print_elapsed_time();
71 66
                            time--;
......
79 74
            /* no standart message expected: do nothing */
80 75
        }
81 76
    }
82

  
83 77
    timer_unsubscribe_int();
84

  
85 78
  return 0;
86 79
}
lab2/timer.c
51 51
int hook_id = 2;
52 52

  
53 53
int (timer_subscribe_int)(uint8_t *bit_no) {
54
    if(bit_no == NULL) return 1;
54 55
    *bit_no = hook_id;
55 56
    if(sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE, &hook_id)) return 1;
56 57
    return 0;
......
61 62
    return 0;
62 63
}
63 64

  
64
uint32_t no_interrupts = 0;
65
int no_interrupts = 0;
65 66
void (timer_int_handler)() {
66 67
    no_interrupts++;
67 68
}
68 69

  
69 70
int (timer_get_conf)(uint8_t timer, uint8_t *st) {
71
    if(st == NULL) return 1;
70 72
    // Write read-back command to TIMER_CTRL
71 73
    u32_t cmd = TIMER_RB_CMD | TIMER_RB_COUNT_ | TIMER_RB_SEL(timer);
72 74
    if(sys_outb(TIMER_CTRL, cmd)) return 1;
73

  
74 75
    int read_port;
75 76
    switch(timer) {
76 77
        case 0: read_port = TIMER_0; break;
lab2/utils.c
4 4

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

  
8 7
    *lsb = (uint8_t)val;
9 8
    return 0;
10 9
}

Also available in: Unified diff