root / lab2 / src / utils.c @ 252
History | View | Annotate | Download (981 Bytes)
1 | 196 | up20180642 | #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 | *lsb = val; |
||
11 | 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 | 198 | up20180642 | #ifdef LAB3
|
21 | uint32_t sys_inb_counter = 0;
|
||
22 | #endif
|
||
23 | |||
24 | 196 | up20180642 | int (util_sys_inb)(int port, uint8_t *value) { |
25 | if(value == NULL) return NULL_PTR; |
||
26 | uint32_t n = 0;
|
||
27 | if(sys_inb(port, &n)) return READ_ERROR; |
||
28 | *value = n; |
||
29 | 198 | up20180642 | #ifdef LAB3
|
30 | ++sys_inb_counter; |
||
31 | #endif
|
||
32 | 196 | up20180642 | return SUCCESS;
|
33 | } |
||
34 | |||
35 | int (unsubscribe_interrupt)(int *interrupt_id) { |
||
36 | if (interrupt_id == NULL) return NULL_PTR; |
||
37 | if(sys_irqrmpolicy(interrupt_id)) return UNSBCR_ERROR; |
||
38 | return SUCCESS;
|
||
39 | } |
||
40 | |||
41 | int32_t min(int32_t a, int32_t b){ return (b < a ? b : a); }
|
||
42 | int32_t max(int32_t a, int32_t b){ return (a < b ? b : a); } |