Revision 11
Fix utils.c
timer.c | ||
---|---|---|
6 | 6 |
#include "i8254.h" |
7 | 7 |
|
8 | 8 |
int (timer_set_frequency)(uint8_t timer, uint32_t freq) { |
9 |
|
|
10 |
// counter_init = clock/feq |
|
11 |
|
|
12 | 9 |
uint8_t status = 0; |
13 |
|
|
14 | 10 |
if (timer_get_conf(timer, &status)) return 1; |
15 | 11 |
//Make command |
16 | 12 |
uint8_t write_cmd = 0; |
17 | 13 |
//Select timer |
18 | 14 |
switch(timer) { |
19 |
case 0: write_cmd |= TIMER_SEL0; |
|
20 |
break; |
|
21 |
case 1: write_cmd |= TIMER_SEL1; |
|
22 |
break; |
|
23 |
case 2: write_cmd |= TIMER_SEL2; |
|
24 |
break; |
|
25 |
default: return 1; break; |
|
15 |
case 0: write_cmd |= TIMER_SEL0; break; |
|
16 |
case 1: write_cmd |= TIMER_SEL1; break; |
|
17 |
case 2: write_cmd |= TIMER_SEL2; break; |
|
18 |
default: return 1; break; |
|
26 | 19 |
} |
27 | 20 |
//Change both LSB and MSB |
28 | 21 |
write_cmd |= TIMER_LSB_MSB; |
29 | 22 |
//Keep 4 least significant bits |
30 | 23 |
write_cmd |= (status & (TIMER_MODE_MASK | TIMER_BCD)); |
31 | 24 |
//Write cmd |
32 |
sys_outb(TIMER_CTRL, )
|
|
25 |
if (sys_outb(TIMER_CTRL, write_cmd)) return 1;
|
|
33 | 26 |
|
27 |
// counter_init = clock/freq |
|
28 |
uint16_t counter_init = (uint16_t)(TIMER_FREQ / freq); |
|
34 | 29 |
|
30 |
int timer_port = 0; |
|
31 |
switch(timer) { |
|
32 |
case 0: read_port = TIMER_0; break; |
|
33 |
case 1: read_port = TIMER_1; break; |
|
34 |
case 2: read_port = TIMER_2; break; |
|
35 |
default: return 1; break; |
|
36 |
} |
|
37 |
|
|
38 |
|
|
39 |
|
|
35 | 40 |
return 1; |
36 | 41 |
} |
37 | 42 |
|
Also available in: Unified diff