root / lab2 / utils.c @ 5
History | View | Annotate | Download (803 Bytes)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
|
3 |
#include <stdint.h> |
4 |
|
5 |
int(util_get_LSB)(uint16_t val, uint8_t *lsb) {
|
6 |
*lsb = (uint8_t) val; //truncation of 16 bit to 8 bit (maintains the LSB)
|
7 |
|
8 |
return 0; |
9 |
} |
10 |
|
11 |
int(util_get_MSB)(uint16_t val, uint8_t *msb) {
|
12 |
val= val>>8; //8 bit shift, gets rid of LSB |
13 |
*msb=(uint8_t)val; //truncation of 16 bit to 8 bit (this time we have the MSB)
|
14 |
|
15 |
return 0; |
16 |
} |
17 |
|
18 |
int (util_sys_inb)(int port, uint8_t *value) { //transform 8 bit into 32 bit |
19 |
|
20 |
uint32_t new_val; //initializing 32 bit variable
|
21 |
|
22 |
if(sys_inb(port,&new_val)!=0){ //verifies if there is an error |
23 |
printf("Error in util_sys_inb\n");
|
24 |
return 1; |
25 |
} |
26 |
*value=new_val & 0xFF; //dereferencing "value" |
27 |
|
28 |
return 0; |
29 |
} |