Project

General

Profile

Revision 27

beautifying

View differences:

lab2/i8254.h
10 10
 */
11 11

  
12 12
#define TIMER_FREQ     1193182 /**< @brief clock frequency for timer in PC and AT */
13
#define TIMER_MIN_FREQ 19 /**< @brief mininum frequency for timer */
13
#define TIMER_MIN_FREQ (TIMER_FREQ/UINT16_MAX) + ((TIMER_FREQ % UINT16_MAX) ? 1 : 0) /**< @brief mininum frequency for timer */
14 14
#define TIMER0_IRQ     0 /**< @brief Timer 0 IRQ line */
15 15

  
16 16
/* I/O port addresses */
lab2/lab2.c
43 43
extern int no_interrupts;
44 44

  
45 45
int(timer_test_int)(uint8_t time) {
46
    const uint32_t frequency = 60; // Frequency asummed at 60Hz
46 47
    int ipc_status, r;
47 48
    message msg;
48 49
    uint8_t hook = 0;
49 50
    no_interrupts = 0;
50
    int freq = 60; // better way to get the frequency of the timer???
51 51
    timer_subscribe_int(&hook);
52 52
    int irq_set = BIT(hook);
53 53
    while (time) {
......
61 61
                case HARDWARE: /* hardware interrupt notification */
62 62
                    if (msg.m_notify.interrupts & irq_set) { /* subscribed interrupt */
63 63
                        timer_int_handler();
64
                        if (!(no_interrupts % freq)) {
64
                        if (!(no_interrupts % frequency)) {
65 65
                            timer_print_elapsed_time();
66 66
                            time--;
67 67
                        }
lab2/timer.c
8 8
int (timer_set_frequency)(uint8_t timer, uint32_t freq) {
9 9

  
10 10
    // Frequencies out this range are not supported (by limitation of hardware)
11
    if (freq > TIMER_FREQ || freq < TIMER_MIN_FREQ) return 1;
11
    if (freq > TIMER_FREQ || freq < TIMER_MIN_FREQ) {
12
        printf("%s: Frequency out of range, must be between %d and %d.\n", __func__, TIMER_MIN_FREQ, TIMER_FREQ);
13
        return 1;
14
    }
12 15

  
13 16
    uint8_t status = 0;
14 17
    if (timer_get_conf(timer, &status)) return 1;
......
48 51
    return 0;
49 52
}
50 53

  
51
int hook_id = 2;
54
int hook_id;
52 55

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

  
60 63
int (timer_unsubscribe_int)() {

Also available in: Unified diff