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