aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-litecell15
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2017-07-17 17:32:03 +0200
committerMax <msuraev@sysmocom.de>2017-07-18 11:41:56 +0000
commitf690e5d45cbbcaf1309a429e934829bd06b00dd7 (patch)
tree4612e59d0586c3dd9118278d7545fd3c72639f4d /src/osmo-bts-litecell15
parenta59fb6220b723b2c89477838697628474378aeea (diff)
lc15: cleanup board parameters reading
* move common code into separate function * print error similar to parameter reading code Change-Id: Icf3285d7bb921d212cb8945e835be2c81189fb87 Related: SYS#3728
Diffstat (limited to 'src/osmo-bts-litecell15')
-rw-r--r--src/osmo-bts-litecell15/misc/lc15bts_bid.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/osmo-bts-litecell15/misc/lc15bts_bid.c b/src/osmo-bts-litecell15/misc/lc15bts_bid.c
index 06a126a..ba2037a 100644
--- a/src/osmo-bts-litecell15/misc/lc15bts_bid.c
+++ b/src/osmo-bts-litecell15/misc/lc15bts_bid.c
@@ -24,12 +24,13 @@
#include <string.h>
#include <errno.h>
#include <fcntl.h>
+#include <stdbool.h>
#include "lc15bts_bid.h"
#define BOARD_REV_SYSFS "/var/lc15/platform/revision"
#define BOARD_OPT_SYSFS "/var/lc15/platform/option"
-
+
static const int option_type_mask[_NUM_OPTION_TYPES] = {
[LC15BTS_OPTION_OCXO] = 0x07,
[LC15BTS_OPTION_FPGA] = 0x03,
@@ -72,6 +73,21 @@ static const int option_type_shift[_NUM_OPTION_TYPES] = {
static int board_rev = -1;
static int board_option = -1;
+static inline bool read_board(const char *src, const char *spec, void *dst)
+{
+ FILE *fp = fopen(src, "r");
+ if (!fp) {
+ fprintf(stderr, "Failed to open %s due to '%s' error\n", src, strerror(errno));
+ return false;
+ }
+
+ if (fscanf(fp, spec, dst) != 1) {
+ fclose(fp);
+ fprintf(stderr, "Failed to read %s due to '%s' error\n", src, strerror(errno));
+ return false;
+ }
+ fclose(fp);
+}
int lc15bts_rev_get(void)
{
@@ -82,14 +98,8 @@ int lc15bts_rev_get(void)
return board_rev;
}
- fp = fopen(BOARD_REV_SYSFS, "r");
- if (fp == NULL) return -1;
-
- if (fscanf(fp, "%c", &rev) != 1) {
- fclose( fp );
- return -1;
- }
- fclose(fp);
+ if (!read_board(BOARD_REV_SYSFS, "%c", &rev))
+ return -1;
board_rev = rev;
return board_rev;
@@ -99,22 +109,15 @@ int lc15bts_model_get(void)
{
FILE *fp;
int opt;
+ bool rc;
+ if (board_option != -1)
+ return board_option;
- if (board_option == -1) {
- fp = fopen(BOARD_OPT_SYSFS, "r");
- if (fp == NULL) {
- return -1;
- }
-
- if (fscanf(fp, "%X", &opt) != 1) {
- fclose( fp );
- return -1;
- }
- fclose(fp);
+ if (!read_board(BOARD_OPT_SYSFS, "%X", &opt))
+ return -1;
- board_option = opt;
- }
+ board_option = opt;
return board_option;
}