root / lab2 / timer.c @ 9
History | View | Annotate | Download (2.13 KB)
1 | 4 | up20180655 | #include <lcom/lcf.h> |
---|---|---|---|
2 | #include <lcom/timer.h> |
||
3 | |||
4 | #include <stdint.h> |
||
5 | |||
6 | #include "i8254.h" |
||
7 | |||
8 | int (timer_set_frequency)(uint8_t timer, uint32_t freq) {
|
||
9 | 5 | up20180642 | /* To be implemented by the students */
|
10 | printf("%s is not yet implemented!\n", __func__);
|
||
11 | 4 | up20180655 | |
12 | 5 | up20180642 | return 1; |
13 | 4 | up20180655 | } |
14 | |||
15 | int (timer_subscribe_int)(uint8_t *bit_no) {
|
||
16 | /* To be implemented by the students */
|
||
17 | 5 | up20180642 | printf("%s is not yet implemented!\n", __func__);
|
18 | 4 | up20180655 | |
19 | 5 | up20180642 | return 1; |
20 | 4 | up20180655 | } |
21 | |||
22 | int (timer_unsubscribe_int)() {
|
||
23 | 5 | up20180642 | /* To be implemented by the students */
|
24 | printf("%s is not yet implemented!\n", __func__);
|
||
25 | 4 | up20180655 | |
26 | 5 | up20180642 | return 1; |
27 | 4 | up20180655 | } |
28 | |||
29 | void (timer_int_handler)() {
|
||
30 | 5 | up20180642 | /* To be implemented by the students */
|
31 | printf("%s is not yet implemented!\n", __func__);
|
||
32 | 4 | up20180655 | } |
33 | |||
34 | int (timer_get_conf)(uint8_t timer, uint8_t *st) {
|
||
35 | 9 | up20180642 | // Write read-back command to TIMER_CTRL
|
36 | 5 | up20180642 | int write_port = TIMER_CTRL;
|
37 | u32_t cmd = TIMER_RB_CMD | TIMER_RB_COUNT_ | TIMER_RB_SEL(timer); |
||
38 | if(sys_outb(write_port, cmd)) return 1; |
||
39 | 4 | up20180655 | |
40 | 5 | up20180642 | int read_port;
|
41 | 7 | up20180655 | switch(timer) {
|
42 | 5 | up20180642 | case 0: read_port = TIMER_0; break; |
43 | case 1: read_port = TIMER_1; break; |
||
44 | case 2: read_port = TIMER_2; break; |
||
45 | 6 | up20180642 | default: return 1; break; |
46 | 5 | up20180642 | } |
47 | if(util_sys_inb(read_port, st)) return 1; |
||
48 | return 0; |
||
49 | 4 | up20180655 | } |
50 | |||
51 | 6 | up20180642 | int (timer_display_conf)(uint8_t timer, uint8_t st, enum timer_status_field field) { |
52 | union timer_status_field_val conf;
|
||
53 | uint8_t in_mode; |
||
54 | if(field == tsf_all || field == tsf_initial){
|
||
55 | in_mode = (st & TIMER_INMODE_MASK) >> TIMER_INMODE_POS; |
||
56 | switch(in_mode){
|
||
57 | 9 | up20180642 | case 0: conf.in_mode = INVAL_val ; break; //000 |
58 | case 1: conf.in_mode = LSB_only ; break; //001 |
||
59 | case 2: conf.in_mode = MSB_only ; break; //010 |
||
60 | case 3: conf.in_mode = MSB_after_LSB; break; //011 |
||
61 | 6 | up20180642 | default: return 1; break; |
62 | } |
||
63 | if(timer_print_config(timer, field, conf)) return 1; |
||
64 | 5 | up20180642 | } |
65 | 8 | up20180642 | if(field == tsf_mode){
|
66 | 6 | up20180642 | conf.count_mode = (st & TIMER_MODE_MASK)>>TIMER_MODE_POS; |
67 | if(timer_print_config(timer, field, conf)) return 1; |
||
68 | } |
||
69 | 8 | up20180642 | if(field == tsf_base){
|
70 | 6 | up20180642 | conf.bcd = st & TIMER_BCD; |
71 | if(timer_print_config(timer, field, conf)) return 1; |
||
72 | } |
||
73 | return 0; |
||
74 | } |