From 54a8b313b4bac5b3853d8e9bcea5385651354651 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 31 Jul 2014 20:08:33 +0200 Subject: sysmobts: There is only one uc make it a singleton Move the init and polling into the sysmoBTS related part. In the future we should have _one_ temperature control. --- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 61 +------------------------ src/osmo-bts-sysmo/misc/sysmobts_mgr_2050.c | 71 ++++++++++++++++++++++++++--- src/osmo-bts-sysmo/misc/sysmobts_misc.h | 18 ++++---- 3 files changed, 76 insertions(+), 74 deletions(-) (limited to 'src/osmo-bts-sysmo') diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index ba3aa2ef..2864ec9b 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -39,7 +39,6 @@ #include #include -#include "btsconfig.h" #include "misc/sysmobts_misc.h" #include "misc/sysmobts_mgr.h" #include "misc/sysmobts_nl.h" @@ -50,64 +49,6 @@ static int daemonize = 0; static const char *cfgfile = "sysmobts-mgr.cfg"; void *tall_mgr_ctx; -/* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ -#define TEMP_TIMER_SECS (6 * 3600) - -/* every 1 hours means 365*24 = 8760 EEprom writes per year (max) */ -#define HOURS_TIMER_SECS (1 * 3600) - -#ifdef BUILD_SBTS2050 -static struct osmo_timer_list temp_uc_timer; -static void check_uctemp_timer_cb(void *data) -{ - int temp_pa = 0, temp_board = 0; - struct uc *ucontrol0 = data; - - sbts2050_uc_check_temp(ucontrol0, &temp_pa, &temp_board); - - osmo_timer_schedule(&temp_uc_timer, TEMP_TIMER_SECS, 0); -} -#endif - -static void initialize_sbts2050(void) -{ -#ifdef BUILD_SBTS2050 - static struct uc ucontrol0 = { - .id = 0, - .path = "/dev/ttyS0" - }; - int val; - - if (sysmobts_par_get_int(SYSMOBTS_PAR_MODEL_NR, &val) < 0) { - LOGP(DFIND, LOGL_ERROR, - "Failed to get Model number\n"); - return; - } - - if (val != 2050) - return; - - if (sysmobts_par_get_int(SYSMOBTS_PAR_TRX_NR, &val) < 0) { - LOGP(DFIND, LOGL_ERROR, "Failed to get the TRX number\n"); - return; - } - - if (val != 0) - return; - - ucontrol0.fd = osmo_serial_init(ucontrol0.path, 115200); - if (ucontrol0.fd < 0) { - LOGP(DFIND, LOGL_ERROR, - "Failed to open the serial interface\n"); - return; - } - - temp_uc_timer.cb = check_uctemp_timer_cb; - temp_uc_timer.data = &ucontrol0; - check_uctemp_timer_cb(&ucontrol0); -#endif -} - static struct osmo_timer_list temp_timer; static void check_temp_timer_cb(void *unused) { @@ -414,7 +355,7 @@ int main(int argc, char **argv) hours_timer_cb(NULL); /* start uc temperature check timer */ - initialize_sbts2050(); + sbts2050_uc_initialize(); /* handle broadcast messages for ipaccess-find */ fd.cb = ipaccess_bcast; diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr_2050.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr_2050.c index c480a7a9..50e35dc1 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr_2050.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_2050.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -35,6 +36,12 @@ #define SIZE_HEADER_RSP 5 #define SIZE_HEADER_CMD 4 +struct uc { + int id; + int fd; + const char *path; +}; + struct ucinfo { uint16_t id; int master; @@ -42,6 +49,11 @@ struct ucinfo { int pa; }; +static struct uc ucontrol0 = { + .id = 0, + .path = "/dev/ttyS0" +}; + /********************************************************************** * Functions read/write from serial interface *********************************************************************/ @@ -190,7 +202,7 @@ err: /********************************************************************** * Get power status function *********************************************************************/ -int sbts2050_uc_get_status(struct uc *ucontrol, enum sbts2050_status_rqt status) +int sbts2050_uc_get_status(enum sbts2050_status_rqt status) { struct msgb *msg; const struct ucinfo info = { @@ -199,7 +211,7 @@ int sbts2050_uc_get_status(struct uc *ucontrol, enum sbts2050_status_rqt status) rsppkt_t *response; int val_status; - msg = sbts2050_ucinfo_get(ucontrol, &info); + msg = sbts2050_ucinfo_get(&ucontrol0, &info); if (msg == NULL) { LOGP(DTEMP, LOGL_ERROR, @@ -230,7 +242,7 @@ int sbts2050_uc_get_status(struct uc *ucontrol, enum sbts2050_status_rqt status) /********************************************************************** * Uc Power Switching handling *********************************************************************/ -void sbts2050_uc_set_power(struct uc *ucontrol, int pmaster, int pslave, int ppa) +void sbts2050_uc_set_power(int pmaster, int pslave, int ppa) { struct msgb *msg; const struct ucinfo info = { @@ -240,7 +252,7 @@ void sbts2050_uc_set_power(struct uc *ucontrol, int pmaster, int pslave, int ppa .pa = ppa }; - msg = sbts2050_ucinfo_get(ucontrol, &info); + msg = sbts2050_ucinfo_get(&ucontrol0, &info); if (msg == NULL) { LOGP(DTEMP, LOGL_ERROR, "Error switching off some unit.\n"); @@ -261,7 +273,7 @@ void sbts2050_uc_set_power(struct uc *ucontrol, int pmaster, int pslave, int ppa /********************************************************************** * Uc temperature handling *********************************************************************/ -void sbts2050_uc_check_temp(struct uc *ucontrol, int *temp_pa, int *temp_board) +void sbts2050_uc_check_temp(int *temp_pa, int *temp_board) { rsppkt_t *response; struct msgb *msg; @@ -269,7 +281,7 @@ void sbts2050_uc_check_temp(struct uc *ucontrol, int *temp_pa, int *temp_board) .id = SBTS2050_TEMP_RQT, }; - msg = sbts2050_ucinfo_get(ucontrol, &info); + msg = sbts2050_ucinfo_get(&ucontrol0, &info); if (msg == NULL) { LOGP(DTEMP, LOGL_ERROR, "Error reading temperature\n"); @@ -287,4 +299,51 @@ void sbts2050_uc_check_temp(struct uc *ucontrol, int *temp_pa, int *temp_board) response->rsp.tempGet.i8PaTemp); msgb_free(msg); } + +static struct osmo_timer_list temp_uc_timer; +static void check_uctemp_timer_cb(void *data) +{ + int temp_pa = 0, temp_board = 0; + + sbts2050_uc_check_temp(&temp_pa, &temp_board); + + osmo_timer_schedule(&temp_uc_timer, TEMP_TIMER_SECS, 0); +} + +void sbts2050_uc_initialize(void) +{ + int val; + + if (sysmobts_par_get_int(SYSMOBTS_PAR_MODEL_NR, &val) < 0) { + LOGP(DFIND, LOGL_ERROR, + "Failed to get Model number\n"); + return; + } + + if (val != 2050) + return; + + if (sysmobts_par_get_int(SYSMOBTS_PAR_TRX_NR, &val) < 0) { + LOGP(DFIND, LOGL_ERROR, "Failed to get the TRX number\n"); + return; + } + + if (val != 0) + return; + + ucontrol0.fd = osmo_serial_init(ucontrol0.path, 115200); + if (ucontrol0.fd < 0) { + LOGP(DFIND, LOGL_ERROR, + "Failed to open the serial interface\n"); + return; + } + + temp_uc_timer.cb = check_uctemp_timer_cb; + check_uctemp_timer_cb(NULL); +} +#else +void sbts2050_uc_initialize(void) +{ + LOGP(DTEMP, LOGL_NOTICE, "sysmoBTS2050 was not enabled at compile time.\n"); +} #endif diff --git a/src/osmo-bts-sysmo/misc/sysmobts_misc.h b/src/osmo-bts-sysmo/misc/sysmobts_misc.h index 7df35874..f3b85c2c 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_misc.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_misc.h @@ -3,6 +3,12 @@ #include +/* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ +#define TEMP_TIMER_SECS (6 * 3600) + +/* every 1 hours means 365*24 = 8760 EEprom writes per year (max) */ +#define HOURS_TIMER_SECS (1 * 3600) + enum sysmobts_temp_sensor { SYSMOBTS_TEMP_DIGITAL = 1, SYSMOBTS_TEMP_RF = 2, @@ -37,13 +43,9 @@ enum sysmobts_firmware_type { int sysmobts_firmware_reload(enum sysmobts_firmware_type type); -struct uc { - int id; - int fd; - const char *path; -}; -void sbts2050_uc_check_temp(struct uc *ucontrol, int *temp_pa, int *temp_board); -void sbts2050_uc_set_power(struct uc *ucontrol, int pmaster, int pslave, int ppa); -int sbts2050_uc_get_status(struct uc *ucontrol, enum sbts2050_status_rqt status); +void sbts2050_uc_check_temp(int *temp_pa, int *temp_board); +void sbts2050_uc_set_power(int pmaster, int pslave, int ppa); +int sbts2050_uc_get_status(enum sbts2050_status_rqt status); +void sbts2050_uc_initialize(); #endif -- cgit v1.2.3