Revision 4
All functions running, review code
utils.c | ||
---|---|---|
3 | 3 |
#include <stdint.h> |
4 | 4 |
|
5 | 5 |
int(util_get_LSB)(uint16_t val, uint8_t *lsb) { |
6 |
/* To be implemented by the students */ |
|
7 |
printf("%s is not yet implemented!\n", __func__); |
|
6 |
*lsb = (uint8_t) val; //truncation of 16 bit to 8 bit (maintains the LSB) |
|
8 | 7 |
|
9 |
return 1;
|
|
8 |
return 0;
|
|
10 | 9 |
} |
11 | 10 |
|
12 | 11 |
int(util_get_MSB)(uint16_t val, uint8_t *msb) { |
13 |
/* To be implemented by the students */
|
|
14 |
printf("%s is not yet implemented!\n", __func__);
|
|
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)
|
|
15 | 14 |
|
16 |
return 1;
|
|
15 |
return 0;
|
|
17 | 16 |
} |
18 | 17 |
|
19 |
int (util_sys_inb)(int port, uint8_t *value) { |
|
20 |
/* To be implemented by the students */ |
|
21 |
printf("%s is not yet implemented!\n", __func__); |
|
18 |
int (util_sys_inb)(int port, uint8_t *value) { //transform 8 bit into 32 bit |
|
22 | 19 |
|
23 |
return 1; |
|
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; |
|
24 | 29 |
} |
Also available in: Unified diff