root / proj / libs / utils / src / utils.c @ 335
History | View | Annotate | Download (1.4 KB)
1 | 144 | up20180655 | #include <lcom/lcf.h> |
---|---|---|---|
2 | |||
3 | #include "utils.h" |
||
4 | |||
5 | #include <stdint.h> |
||
6 | #include "errors.h" |
||
7 | |||
8 | int(util_get_LSB)(uint16_t val, uint8_t *lsb) {
|
||
9 | if (lsb == NULL) return NULL_PTR; |
||
10 | 323 | up20180642 | *lsb = (uint8_t)val; |
11 | 144 | up20180655 | return SUCCESS;
|
12 | } |
||
13 | |||
14 | int(util_get_MSB)(uint16_t val, uint8_t *msb) {
|
||
15 | if (msb == NULL) return NULL_PTR; |
||
16 | *msb = (val >> 8);
|
||
17 | return SUCCESS;
|
||
18 | } |
||
19 | |||
20 | int (util_sys_inb)(int port, uint8_t *value) { |
||
21 | if(value == NULL) return NULL_PTR; |
||
22 | uint32_t n = 0;
|
||
23 | if(sys_inb(port, &n)) return READ_ERROR; |
||
24 | 323 | up20180642 | *value = (uint8_t)n; |
25 | 144 | up20180655 | return SUCCESS;
|
26 | } |
||
27 | |||
28 | 145 | up20180655 | int (unsubscribe_interrupt)(int *interrupt_id) { |
29 | if (interrupt_id == NULL) return NULL_PTR; |
||
30 | if(sys_irqrmpolicy(interrupt_id)) return UNSBCR_ERROR; |
||
31 | return SUCCESS;
|
||
32 | 144 | up20180655 | } |
33 | |||
34 | 335 | up20180642 | int16_t min_16(int16_t a, int16_t b){ return (b < a ? b : a); }
|
35 | uint16_t umin_16(uint16_t a, uint16_t b){ return (b < a ? b : a); }
|
||
36 | 323 | up20180642 | int32_t min32(int32_t a, int32_t b){ return (b < a ? b : a); }
|
37 | double dmin (double a, double b){ return (b < a ? b : a); } |
||
38 | 200 | up20180655 | |
39 | 335 | up20180642 | int16_t max_16(int16_t a, int16_t b){ return (a < b ? b : a); }
|
40 | uint16_t max_u16(uint16_t a, uint16_t b){ return (a < b ? b : a); }
|
||
41 | 323 | up20180642 | int32_t max32(int32_t a, int32_t b){ return (a < b ? b : a); }
|
42 | 335 | up20180642 | double max_d (double a, double b){ return (a < b ? b : a); } |
43 | 323 | up20180642 | |
44 | 335 | up20180642 | double abs_d(double a) { return (a < 0 ? -a: a); } |
45 | 323 | up20180642 | |
46 | 335 | up20180642 | int eq_d(double a, double b){ return (abs_d(a-b) < 1e-10 ? true : false); } |