Project

General

Profile

Statistics
| Revision:

root / proj / libs / utils / include / utils.h @ 294

History | View | Annotate | Download (2.34 KB)

1
#ifndef UTILS_H_INCLUDED
2
#define UTILS_H_INCLUDED
3

    
4
#define BCD_FIRST(n)     (n >> 4)       /** @brief Get first digit (leftmost digit) of 8-bit BCD */
5
#define BCD_SECOND(n)    (n & 0x0F)     /** @brief Get second digit (rightmost digit) of 8-bit BCD */
6

    
7
/**
8
 * @brief Gets the least significant byte of a 16-bit variable
9
 * @param val 16-bit variable
10
 * @param lsb Pointer to a 8-bit variable to store the value of the LSB
11
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
12
 */
13
int(util_get_LSB)(uint16_t val, uint8_t *lsb);
14

    
15
/**
16
 * @brief Gets the most significant byte of a 16-bit variable
17
 * @param val 16-bit variable
18
 * @param lsb Pointer to a 8-bit variable to store the value of the MSB
19
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
20
 */
21
int(util_get_MSB)(uint16_t val, uint8_t *msb);
22

    
23
/**
24
 * @brief sys_inb wrapper
25
 * @param port Port to read from
26
 * @param value Pointer to byte to store value read
27
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
28
 */
29
int (util_sys_inb)(int port, uint8_t *value);
30

    
31
/**
32
 * @brief Unsubcribes Interrupts
33
 * @param interrupt_id Interrupt ID, value via arguments on subscription of the interrupt_id
34
 * @see subscribe_kbc_interrupt, subscribe_timer_interrupt
35
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
36
 */
37
int (unsubscribe_interrupt)(int *interrupt_id);
38

    
39
/**
40
 * @brief Gets the minimum value out of two values.
41
 * @param a     First value
42
 * @param b     Second value
43
 * @return  The minimum of the two values
44
 */
45
int32_t min(int32_t a, int32_t b);
46

    
47
/**
48
 * @brief Gets the maximum value out of two values.
49
 * @param a     First value
50
 * @param b     Second value
51
 * @return  The maximum of the two values
52
 */
53
int32_t max(int32_t a, int32_t b);
54

    
55
/**
56
 * @brief Gets the minimum value out of two doubles.
57
 * @param a     First value
58
 * @param b     Second value
59
 * @return  The minimum of the two values
60
 */
61
double min_d(double a, double b);
62

    
63
/**
64
 * @brief Gets the maximum value out of two doubles.
65
 * @param a     First value
66
 * @param b     Second value
67
 * @return  The maximum of the two values
68
 */
69
double max_d(double a, double b);
70

    
71

    
72
double abs_d(double a);
73

    
74

    
75
#endif //UTILS_H_INCLUDED