Project

General

Profile

Statistics
| Revision:

root / lab2 / utils.c @ 13

History | View | Annotate | Download (803 Bytes)

1 3 up20180645
#include <lcom/lcf.h>
2
3
#include <stdint.h>
4
5
int(util_get_LSB)(uint16_t val, uint8_t *lsb) {
6 4 up20180645
  *lsb = (uint8_t) val;             //truncation of 16 bit to 8 bit (maintains the LSB)
7 3 up20180645
8 4 up20180645
  return 0;
9 3 up20180645
}
10
11
int(util_get_MSB)(uint16_t val, uint8_t *msb) {
12 4 up20180645
  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 3 up20180645
15 4 up20180645
  return 0;
16 3 up20180645
}
17
18 4 up20180645
int (util_sys_inb)(int port, uint8_t *value) { //transform 8 bit into 32 bit
19 3 up20180645
20 5 up20180645
  uint32_t new_val;                           //initializing 32 bit variable
21 4 up20180645
22 5 up20180645
  if(sys_inb(port,&new_val)!=0){              //verifies if there is an error
23 4 up20180645
      printf("Error in util_sys_inb\n");
24
      return 1;
25
  }
26 5 up20180645
  *value=new_val & 0xFF;                      //dereferencing "value"
27 4 up20180645
28
  return 0;
29 3 up20180645
}