root / proj / libs / utils / include / utils.h @ 354
History | View | Annotate | Download (2.72 KB)
1 |
#ifndef UTILS_H_INCLUDED
|
---|---|
2 |
#define UTILS_H_INCLUDED
|
3 |
|
4 |
/**
|
5 |
* @defgroup utils utils
|
6 |
* @ingroup libs
|
7 |
* @brief Utilities module.
|
8 |
*
|
9 |
* @{
|
10 |
*/
|
11 |
|
12 |
/** @brief Get first digit (leftmost digit) of 8-bit BCD */
|
13 |
#define BCD_FIRST(n) (n >> 4) |
14 |
/** @brief Get second digit (rightmost digit) of 8-bit BCD */
|
15 |
#define BCD_SECOND(n) (n & 0x0F) |
16 |
|
17 |
/**
|
18 |
* @brief Gets the least significant byte of a 16-bit variable
|
19 |
* @param val 16-bit variable
|
20 |
* @param lsb Pointer to a 8-bit variable to store the value of the LSB
|
21 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
|
22 |
*/
|
23 |
int(util_get_LSB)(uint16_t val, uint8_t *lsb);
|
24 |
|
25 |
/**
|
26 |
* @brief Gets the most significant byte of a 16-bit variable
|
27 |
* @param val 16-bit variable
|
28 |
* @param msb Pointer to a 8-bit variable to store the value of the MSB
|
29 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
|
30 |
*/
|
31 |
int(util_get_MSB)(uint16_t val, uint8_t *msb);
|
32 |
|
33 |
/**
|
34 |
* @brief sys_inb wrapper
|
35 |
* @param port Port to read from
|
36 |
* @param value Pointer to byte to store value read
|
37 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
|
38 |
*/
|
39 |
int (util_sys_inb)(int port, uint8_t *value); |
40 |
|
41 |
/**
|
42 |
* @brief Unsubcribes Interrupts
|
43 |
* @param interrupt_id Interrupt ID, value via arguments on subscription of the interrupt_id
|
44 |
* @see subscribe_kbc_interrupt, subscribe_timer_interrupt
|
45 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
|
46 |
*/
|
47 |
int (unsubscribe_interrupt)(int *interrupt_id); |
48 |
|
49 |
/**
|
50 |
* @brief Gets the minimum value out of two values.
|
51 |
* @param a First value
|
52 |
* @param b Second value
|
53 |
* @return The minimum of the two values
|
54 |
*/
|
55 |
int16_t min_16(int16_t a, int16_t b); |
56 |
/// @overload
|
57 |
uint16_t min_u16(uint16_t a, uint16_t b); |
58 |
/// @overload
|
59 |
int32_t min_32(int32_t a, int32_t b); |
60 |
/// @overload
|
61 |
double min_d(double a, double b); |
62 |
|
63 |
/**
|
64 |
* @brief Gets the maximum value out of two values.
|
65 |
* @param a First value
|
66 |
* @param b Second value
|
67 |
* @return The maximum of the two values
|
68 |
*/
|
69 |
int16_t max_16(int16_t a, int16_t b); |
70 |
/// @overload
|
71 |
uint16_t max_u16(uint16_t a, uint16_t b); |
72 |
/// @overload
|
73 |
int32_t max_32(int32_t a, int32_t b); |
74 |
/// @overload
|
75 |
double max_d(double a, double b); |
76 |
|
77 |
/**
|
78 |
* @brief Get the absolute value of a double.
|
79 |
* @param a Argument
|
80 |
* @return Absolute value of a
|
81 |
*/
|
82 |
double abs_d(double a); |
83 |
|
84 |
/**
|
85 |
* @brief Compare if two doubles are approximately equal (within 1e-10).
|
86 |
* @param a First value
|
87 |
* @param b Second value
|
88 |
* @return true if the two numbers are approximately equal, false otherwise
|
89 |
*/
|
90 |
int eq_d(double a, double b); |
91 |
|
92 |
/**
|
93 |
* @}
|
94 |
*/
|
95 |
|
96 |
#endif //UTILS_H_INCLUDED |