Project

General

Profile

Statistics
| Revision:

root / lab2 / utils.c @ 24

History | View | Annotate | Download (541 Bytes)

1 4 up20180655
#include <lcom/lcf.h>
2
3
#include <stdint.h>
4
5 20 up20180655
/* Byte Masks */
6
#define LSB 0xFF /**< @brief mask to filter least significant byte */
7
8 4 up20180655
int(util_get_LSB)(uint16_t val, uint8_t *lsb) {
9 20 up20180655
    if (lsb == NULL) return 1;
10 4 up20180655
11 20 up20180655
    *lsb = val & LSB;
12 7 up20180655
    return 0;
13 4 up20180655
}
14
15
int(util_get_MSB)(uint16_t val, uint8_t *msb) {
16 20 up20180655
    if (msb == NULL) return 1;
17 7 up20180655
    *msb = val >> 8;
18
    return 0;
19 4 up20180655
}
20
21
int (util_sys_inb)(int port, uint8_t *value) {
22 8 up20180642
    if(value == NULL) return 1;
23 5 up20180642
    uint32_t n = 0;
24 9 up20180642
    if(sys_inb(port, &n)) return 1;
25 20 up20180655
    *value = n & LSB;
26 9 up20180642
    return 0;
27 4 up20180655
}