| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <stdint.h> |
| 21 |
#include <unistd.h> |
| 22 |
#include <stdlib.h> |
| 23 |
#include <string.h> |
| 24 |
#include <errno.h> |
| 25 |
#include <fcntl.h> |
| 26 |
#include <limits.h> |
| 27 |
|
| 28 |
#include <osmocom/core/utils.h> |
| 29 |
|
| 30 |
#include "lc15bts_temp.h" |
| 31 |
|
| 32 |
static const char *temp_devs[_NUM_TEMP_SENSORS] = { |
| 33 |
[LC15BTS_TEMP_SUPPLY] = "/var/lc15/temp/main-supply/temp", |
| 34 |
[LC15BTS_TEMP_SOC] = "/var/lc15/temp/cpu/temp", |
| 35 |
[LC15BTS_TEMP_FPGA] = "/var/lc15/temp/fpga/temp", |
| 36 |
[LC15BTS_TEMP_RMSDET] = "/var/lc15/temp/rmsdet/temp", |
| 37 |
[LC15BTS_TEMP_OCXO] = "/var/lc15/temp/ocxo/temp", |
| 38 |
[LC15BTS_TEMP_TX0] = "/var/lc15/temp/tx0/temp", |
| 39 |
[LC15BTS_TEMP_TX1] = "/var/lc15/temp/tx1/temp", |
| 40 |
[LC15BTS_TEMP_PA0] = "/var/lc15/temp/pa0/temp", |
| 41 |
[LC15BTS_TEMP_PA1] = "/var/lc15/temp/pa1/temp", |
| 42 |
}; |
| 43 |
|
| 44 |
int lc15bts_temp_get(enum lc15bts_temp_sensor sensor, int *temp) |
| 45 |
{ |
| 46 |
char buf[PATH_MAX]; |
| 47 |
char tempstr[8]; |
| 48 |
int fd, rc; |
| 49 |
|
| 50 |
if (sensor < 0 || sensor >= _NUM_TEMP_SENSORS) |
| 51 |
return -EINVAL; |
| 52 |
|
| 53 |
snprintf(buf, sizeof(buf)-1, "%s", temp_devs[sensor]); |
| 54 |
buf[sizeof(buf)-1] = '\0'; |
| 55 |
|
| 56 |
fd = open(buf, O_RDONLY); |
| 57 |
if (fd < 0) |
| 58 |
return fd; |
| 59 |
|
| 60 |
rc = read(fd, tempstr, sizeof(tempstr)); |
| 61 |
tempstr[sizeof(tempstr)-1] = '\0'; |
| 62 |
if (rc < 0) { |
| 63 |
close(fd); |
| 64 |
return rc; |
| 65 |
} |
| 66 |
if (rc == 0) { |
| 67 |
close(fd); |
| 68 |
return -EIO; |
| 69 |
} |
| 70 |
close(fd); |
| 71 |
*temp = atoi(tempstr); |
| 72 |
return 0; |
| 73 |
} |
| 74 |
|