Revision 29
minor changes and comments
timer.c | ||
---|---|---|
22 | 22 |
case 0: write_cmd |= TIMER_SEL0; break; |
23 | 23 |
case 1: write_cmd |= TIMER_SEL1; break; |
24 | 24 |
case 2: write_cmd |= TIMER_SEL2; break; |
25 |
default: return 1; break;
|
|
25 |
default: return 1; |
|
26 | 26 |
} |
27 | 27 |
//Change both LSB and MSB |
28 | 28 |
write_cmd |= TIMER_LSB_MSB; |
... | ... | |
39 | 39 |
case 0: timer_port = TIMER_0; break; |
40 | 40 |
case 1: timer_port = TIMER_1; break; |
41 | 41 |
case 2: timer_port = TIMER_2; break; |
42 |
default: return 1; break;
|
|
42 |
default: return 1; |
|
43 | 43 |
} |
44 | 44 |
uint8_t lsb = 0, msb = 0; |
45 |
/* Split the 16 bits word in two bytes */ |
|
45 | 46 |
if (util_get_LSB(counter_init, &lsb)) return 1; |
46 | 47 |
if (util_get_MSB(counter_init, &msb)) return 1; |
47 | 48 |
|
49 |
/* Write the 8 LSB of the counter */ |
|
48 | 50 |
if (sys_outb(timer_port, lsb)) return 1; |
51 |
/* Write the 8 MSB of the counter */ |
|
49 | 52 |
if (sys_outb(timer_port, msb)) return 1; |
50 | 53 |
|
51 | 54 |
return 0; |
... | ... | |
54 | 57 |
int hook_id; |
55 | 58 |
|
56 | 59 |
int (timer_subscribe_int)(uint8_t *bit_no) { |
60 |
if(bit_no == NULL) return 1; |
|
57 | 61 |
hook_id = 2; |
58 |
if(bit_no == NULL) return 1; |
|
59 | 62 |
*bit_no = hook_id; |
63 |
/* Subscribe Timer 0 Interrupts */ |
|
60 | 64 |
return sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE, &hook_id); |
61 | 65 |
} |
62 | 66 |
|
63 | 67 |
int (timer_unsubscribe_int)() { |
68 |
/* Unsubscribe Timer 0 Interrupts */ |
|
64 | 69 |
if(sys_irqrmpolicy(&hook_id)) return 1; |
65 | 70 |
return 0; |
66 | 71 |
} |
... | ... | |
80 | 85 |
case 0: read_port = TIMER_0; break; |
81 | 86 |
case 1: read_port = TIMER_1; break; |
82 | 87 |
case 2: read_port = TIMER_2; break; |
83 |
default: return 1; break;
|
|
88 |
default: return 1; |
|
84 | 89 |
} |
85 | 90 |
if(util_sys_inb(read_port, st)) return 1; |
86 | 91 |
return 0; |
... | ... | |
91 | 96 |
uint8_t in_mode; |
92 | 97 |
switch(field){ |
93 | 98 |
case tsf_all: |
94 |
conf.byte = st; |
|
99 |
conf.byte = st; /* Full Status Byte */
|
|
95 | 100 |
break; |
96 | 101 |
case tsf_initial: |
102 |
/* Counter Initial Value Loading Mode */ |
|
97 | 103 |
in_mode = (st & TIMER_INMODE_MASK) >> TIMER_INMODE_POS; |
98 | 104 |
switch(in_mode){ |
99 | 105 |
case 0: conf.in_mode = INVAL_val ; break; //000 |
100 | 106 |
case 1: conf.in_mode = LSB_only ; break; //001 |
101 | 107 |
case 2: conf.in_mode = MSB_only ; break; //010 |
102 | 108 |
case 3: conf.in_mode = MSB_after_LSB; break; //011 |
103 |
default: return 1; break;
|
|
109 |
default: return 1; |
|
104 | 110 |
} |
105 | 111 |
break; |
106 | 112 |
case tsf_mode: |
113 |
/* Counting Mode */ |
|
107 | 114 |
conf.count_mode = (st & TIMER_MODE_MASK)>>TIMER_MODE_POS; |
108 | 115 |
if(conf.count_mode == TIMER_MODE_2ALT || conf.count_mode == TIMER_MODE_3ALT) |
109 | 116 |
conf.count_mode &= TIMER_MODE_RED2; |
110 | 117 |
break; |
111 | 118 |
case tsf_base: |
119 |
/* Representation of Counter Initial Value */ |
|
112 | 120 |
conf.bcd = st & TIMER_BCD; |
113 | 121 |
break; |
114 |
default: return 1; break;
|
|
122 |
default: return 1; |
|
115 | 123 |
} |
116 | 124 |
if(timer_print_config(timer, field, conf)) return 1; |
117 | 125 |
return 0; |
Also available in: Unified diff