root / lab4 / .minix-src / include / lcom / timer.h @ 13
History | View | Annotate | Download (3.25 KB)
1 | 13 | up20180614 | #ifndef __TIMER_H
|
---|---|---|---|
2 | #define __TIMER_H
|
||
3 | |||
4 | #include <stdbool.h> |
||
5 | #include <stdint.h> |
||
6 | |||
7 | /** @defgroup timer timer
|
||
8 | * @{
|
||
9 | *
|
||
10 | * Functions for using the i8254 timers
|
||
11 | */
|
||
12 | |||
13 | /**
|
||
14 | * @brief Enumerated type for specifying the timer value initialization
|
||
15 | */
|
||
16 | enum timer_init {
|
||
17 | INVAL_val, /*!< Invalid initialization mode */
|
||
18 | LSB_only, /*!< Initialization only of the LSB */
|
||
19 | MSB_only, /*!< Initialization only of the MSB */
|
||
20 | MSB_after_LSB /*!< Initialization of LSB and MSB, in this order */
|
||
21 | }; |
||
22 | |||
23 | /**
|
||
24 | * @brief Enumerated type for identifying the timer status fields
|
||
25 | */
|
||
26 | enum timer_status_field {
|
||
27 | tsf_all, /*!< configuration/status */
|
||
28 | tsf_initial, /*!< timer initialization mode */
|
||
29 | tsf_mode, /*!< timer counting mode */
|
||
30 | tsf_base /*!< timer counting base */
|
||
31 | }; |
||
32 | |||
33 | /**
|
||
34 | * @brief Union for storing values of timer status fields, including the full status byte
|
||
35 | */
|
||
36 | union timer_status_field_val {
|
||
37 | uint8_t byte; /*!< status */
|
||
38 | enum timer_init in_mode; /*!< initialization mode */ |
||
39 | uint8_t count_mode; /*!< counting mode: 0, 1,.., 5 */
|
||
40 | bool bcd; /*!< counting base, true if BCD */ |
||
41 | }; |
||
42 | |||
43 | /**
|
||
44 | * @brief Changes the operating frequency of a timer
|
||
45 | *
|
||
46 | * Must use the read-back command so that it does not change
|
||
47 | * the 4 LSBs (mode and BCD/binary) of the timer's control word.
|
||
48 | *
|
||
49 | * @param timer Timer to configure. (Ranges from 0 to 2)
|
||
50 | * @param freq Timer operating frequency
|
||
51 | * @return Return 0 upon success and non-zero otherwise
|
||
52 | */
|
||
53 | int(timer_set_frequency)(uint8_t timer, uint32_t freq);
|
||
54 | |||
55 | /**
|
||
56 | * @brief Subscribes and enables Timer 0 interrupts
|
||
57 | *
|
||
58 | * @param bit_no address of memory to be initialized with the
|
||
59 | * bit number to be set in the mask returned upon an interrupt
|
||
60 | * @return Return 0 upon success and non-zero otherwise
|
||
61 | */
|
||
62 | int(timer_subscribe_int)(uint8_t *bit_no);
|
||
63 | |||
64 | /**
|
||
65 | * @brief Unsubscribes Timer 0 interrupts
|
||
66 | *
|
||
67 | * @return Return 0 upon success and non-zero otherwise
|
||
68 | */
|
||
69 | int(timer_unsubscribe_int)();
|
||
70 | |||
71 | /**
|
||
72 | * @brief Timer 0 interrupt handler
|
||
73 | *
|
||
74 | * Increments counter
|
||
75 | */
|
||
76 | void(timer_int_handler)();
|
||
77 | |||
78 | /**
|
||
79 | * @brief Reads the input timer configuration (status) via read-back command
|
||
80 | *
|
||
81 | * @param timer Timer whose configuration to read (Ranges from 0 to 2)
|
||
82 | * @param st Address of memory position to be filled with the timer config
|
||
83 | * @return Return 0 upon success and non-zero otherwise
|
||
84 | */
|
||
85 | int(timer_get_conf)(uint8_t timer, uint8_t *st);
|
||
86 | |||
87 | /**
|
||
88 | * @brief Shows timer configuration
|
||
89 | *
|
||
90 | * Displays, in a human friendly way, the specified field of a
|
||
91 | * timer status, which was read via the read-back command
|
||
92 | *
|
||
93 | * @param timer timer whose configuration should be displayed (Ranges from 0 to 2)
|
||
94 | * @param st status read via the read-back command
|
||
95 | * @param field status field to display in human friendly way
|
||
96 | * @return Return 0 upon success and non-zero otherwise
|
||
97 | */
|
||
98 | int(timer_display_conf)(uint8_t timer, uint8_t st, enum timer_status_field field); |
||
99 | |||
100 | /**
|
||
101 | * @brief Prints a timer config field value
|
||
102 | *
|
||
103 | * @return Returns 0 upon success and non-zero otherwise
|
||
104 | */
|
||
105 | int(timer_print_config)(uint8_t timer, enum timer_status_field field, |
||
106 | union timer_status_field_val val);
|
||
107 | |||
108 | /**
|
||
109 | * @brief Increments elapsed time count
|
||
110 | *
|
||
111 | * @return Returns the current time count
|
||
112 | */
|
||
113 | uint32_t(timer_print_elapsed_time)(); |
||
114 | |||
115 | #endif /* __TIMER_H */ |