root / lab4 / utils.c @ 331
History | View | Annotate | Download (757 Bytes)
1 | 53 | up20180655 | #include <lcom/lcf.h> |
---|---|---|---|
2 | |||
3 | 68 | up20180642 | #include "utils.h" |
4 | |||
5 | 53 | up20180655 | #include <stdint.h> |
6 | 68 | up20180642 | #include "errors.h" |
7 | 53 | up20180655 | |
8 | 64 | up20180642 | int(util_get_LSB)(uint16_t val, uint8_t *lsb) {
|
9 | 68 | up20180642 | if (lsb == NULL) return NULL_PTR; |
10 | 64 | up20180642 | *lsb = val; |
11 | 68 | up20180642 | return SUCCESS;
|
12 | 64 | up20180642 | } |
13 | |||
14 | int(util_get_MSB)(uint16_t val, uint8_t *msb) {
|
||
15 | 68 | up20180642 | if (msb == NULL) return NULL_PTR; |
16 | 64 | up20180642 | *msb = (val >> 8);
|
17 | 68 | up20180642 | return SUCCESS;
|
18 | 64 | up20180642 | } |
19 | |||
20 | #ifdef LAB3
|
||
21 | uint32_t sys_inb_counter = 0;
|
||
22 | #endif
|
||
23 | |||
24 | 53 | up20180655 | int (util_sys_inb)(int port, uint8_t *value) { |
25 | 68 | up20180642 | if(value == NULL) return NULL_PTR; |
26 | 53 | up20180655 | uint32_t n = 0;
|
27 | 68 | up20180642 | if(sys_inb(port, &n)) return READ_ERROR; |
28 | 53 | up20180655 | *value = n; |
29 | 64 | up20180642 | #ifdef LAB3
|
30 | ++sys_inb_counter; |
||
31 | #endif
|
||
32 | 68 | up20180642 | return SUCCESS;
|
33 | 53 | up20180655 | } |
34 | 79 | up20180655 | |
35 | int16_t abs16(int16_t x) { |
||
36 | return (x >= 0) ? (int16_t)(x) : (int16_t)(-x); |
||
37 | } |