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