Project

General

Profile

Revision 20

timer_test_int prototype

View differences:

lab2/i8254.h
9 9
 * Constants for programming the i8254 Timer. Needs to be completed.
10 10
 */
11 11

  
12
#define TIMER_FREQ 1193182 /**< @brief clock frequency for timer in PC and AT */
12
#define TIMER_FREQ     1193182 /**< @brief clock frequency for timer in PC and AT */
13 13
#define TIMER_MIN_FREQ 19 /**< @brief mininum frequency for timer */
14
#define TIMER0_IRQ 0 /**< @brief Timer 0 IRQ line */
14
#define TIMER0_IRQ     0 /**< @brief Timer 0 IRQ line */
15 15

  
16

  
17 16
/* I/O port addresses */
18 17

  
19 18
#define TIMER_0    0x40 /**< @brief Timer 0 count register */
lab2/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
}
lab2/timer.c
63 63
}
64 64

  
65 65
void (timer_int_handler)() {
66
    /* To be implemented by the students */
67
    printf("%s is not yet implemented!\n", __func__);
66
    int no_interrupts = 0; //should be the global
67

  
68
    no_interrupts++;
68 69
}
69 70

  
70 71
int (timer_get_conf)(uint8_t timer, uint8_t *st) {
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

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

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

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

  
20 21
int (util_sys_inb)(int port, uint8_t *value) {
21
    /* To be implemented by the students */
22 22
    if(value == NULL) return 1;
23 23
    uint32_t n = 0;
24 24
    if(sys_inb(port, &n)) return 1;
25
    *value = n;
25
    *value = n & LSB;
26 26
    return 0;
27 27
}

Also available in: Unified diff