Revision 10
Update timer.c
timer.c | ||
---|---|---|
6 | 6 |
#include "i8254.h" |
7 | 7 |
|
8 | 8 |
int (timer_set_frequency)(uint8_t timer, uint32_t freq) { |
9 |
/* To be implemented by the students */ |
|
10 |
printf("%s is not yet implemented!\n", __func__); |
|
11 | 9 |
|
10 |
// counter_init = clock/feq |
|
11 |
|
|
12 |
uint8_t status = 0; |
|
13 |
|
|
14 |
if (timer_get_conf(timer, &status)) return 1; |
|
15 |
//Make command |
|
16 |
uint8_t write_cmd = 0; |
|
17 |
//Select timer |
|
18 |
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; |
|
26 |
} |
|
27 |
//Change both LSB and MSB |
|
28 |
write_cmd |= TIMER_LSB_MSB; |
|
29 |
//Keep 4 least significant bits |
|
30 |
write_cmd |= (status & (TIMER_MODE_MASK | TIMER_BCD)); |
|
31 |
//Write cmd |
|
32 |
sys_outb(TIMER_CTRL, ) |
|
33 |
|
|
34 |
|
|
12 | 35 |
return 1; |
13 | 36 |
} |
14 | 37 |
|
... | ... | |
33 | 56 |
|
34 | 57 |
int (timer_get_conf)(uint8_t timer, uint8_t *st) { |
35 | 58 |
// Write read-back command to TIMER_CTRL |
36 |
int write_port = TIMER_CTRL; |
|
37 | 59 |
u32_t cmd = TIMER_RB_CMD | TIMER_RB_COUNT_ | TIMER_RB_SEL(timer); |
38 |
if(sys_outb(write_port, cmd)) return 1;
|
|
60 |
if(sys_outb(TIMER_CTRL, cmd)) return 1;
|
|
39 | 61 |
|
40 | 62 |
int read_port; |
41 | 63 |
switch(timer) { |
Also available in: Unified diff