root / proj / libs / utils / include / utils.h @ 334
History | View | Annotate | Download (2.61 KB)
1 |
#ifndef UTILS_H_INCLUDED
|
---|---|
2 |
#define UTILS_H_INCLUDED
|
3 |
|
4 |
/**
|
5 |
* @defgroup utils utils
|
6 |
* @brief Utilities module.
|
7 |
*
|
8 |
* @{
|
9 |
*/
|
10 |
|
11 |
/** @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 |
/**
|
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 |
* @param msb Pointer to a 8-bit variable to store the value of the MSB
|
28 |
* @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 |
* @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 |
* @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 |
int16_t min16(int16_t a, int16_t b); |
55 |
uint16_t umin16(uint16_t a, uint16_t b); |
56 |
int32_t min32(int32_t a, int32_t b); |
57 |
double dmin (double a, double b); |
58 |
|
59 |
/**
|
60 |
* @brief Gets the maximum value out of two values.
|
61 |
* @param a First value
|
62 |
* @param b Second value
|
63 |
* @return The maximum of the two values
|
64 |
*/
|
65 |
int16_t max16(int16_t a, int16_t b); |
66 |
uint16_t umax16(uint16_t a, uint16_t b); |
67 |
int32_t max32(int32_t a, int32_t b); |
68 |
double dmax (double a, double b); |
69 |
|
70 |
/**
|
71 |
* @brief Get the absolute value of a double.
|
72 |
* @param a Argument
|
73 |
* @return Absolute value of a
|
74 |
*/
|
75 |
double dabs(double a); |
76 |
|
77 |
/**
|
78 |
* @brief Compare if two doubles are approximately equal (within 1e-10).
|
79 |
* @param a First value
|
80 |
* @param b Second value
|
81 |
* @return true if the two numbers are approximately equal, false otherwise
|
82 |
*/
|
83 |
int deq(double a, double b); |
84 |
|
85 |
/**
|
86 |
* @}
|
87 |
*/
|
88 |
|
89 |
#endif //UTILS_H_INCLUDED |