From: Álvaro Neira Ayuso anayuso@sysmocom.de
Before, this patch the program try to catch the info of the temperature sensor in a wrong ubication file.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- src/osmo-bts-sysmo/misc/sysmobts_misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_misc.c b/src/osmo-bts-sysmo/misc/sysmobts_misc.c index 74414d0..c043045 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_misc.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_misc.c @@ -45,7 +45,7 @@ * Temperature handling *********************************************************************/
-#define TEMP_PATH "/sys/class/hwmon/hwmon0/device%u_%s" +#define TEMP_PATH "/sys/class/hwmon/hwmon0/device/temp%u_%s"
static const char *temp_type_str[_NUM_TEMP_TYPES] = { [SYSMOBTS_TEMP_INPUT] = "input",
From: Álvaro Neira Ayuso anayuso@sysmocom.de
Add function for requesting the temperature information to the microcontroller. I have added a function that we can extend for requesting more information but in this case we only need to know the temperature. I have added to a microcontroller temperature handling function in the manager for monitoring this information.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 29 +++++ src/osmo-bts-sysmo/misc/sysmobts_misc.c | 167 +++++++++++++++++++++++++++++++ src/osmo-bts-sysmo/misc/sysmobts_misc.h | 22 ++++ 3 files changed, 218 insertions(+)
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index 171f79b..71b889e 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -53,6 +53,31 @@ void *tall_mgr_ctx; /* every 1 hours means 365*24 = 8760 EEprom writes per year (max) */ #define HOURS_TIMER_SECS (1 * 3600)
+static struct osmo_timer_list temp_uc_timer; +static void check_uctemp_timer_cb(void *unused) +{ + struct uc ucontrol0 = { + .id = 0, + .path = "/dev/ttyS0" + }; + int val; + + if (sysmobts_par_get_int(SYSMOBTS_PAR_MODEL_NR, &val) < 0) + return; + + if (val == 2050) { + if (sysmobts_par_get_int(SYSMOBTS_PAR_TRX_NR, &val) < 0) + return; + + if (val == 0) + sbts2050_uc_check_temp(ucontrol0); + } + + osmo_timer_schedule(&temp_uc_timer, TEMP_TIMER_SECS, 0); + + +} + static struct osmo_timer_list temp_timer; static void check_temp_timer_cb(void *unused) { @@ -305,6 +330,10 @@ int main(int argc, char **argv) temp_timer.cb = check_temp_timer_cb; check_temp_timer_cb(NULL);
+ /* start uc temperature check timer */ + temp_uc_timer.cb = check_uctemp_timer_cb; + check_uctemp_timer_cb(NULL); + /* start operational hours timer */ hours_timer.cb = hours_timer_cb; hours_timer_cb(NULL); diff --git a/src/osmo-bts-sysmo/misc/sysmobts_misc.c b/src/osmo-bts-sysmo/misc/sysmobts_misc.c index c043045..aee892d 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_misc.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_misc.c @@ -32,6 +32,8 @@
#include <osmocom/core/talloc.h> #include <osmocom/core/utils.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/serial.h> #include <osmocom/core/application.h> #include <osmocom/vty/telnet_interface.h> #include <osmocom/vty/logging.h> @@ -39,7 +41,172 @@ #include "sysmobts_misc.h" #include "sysmobts_par.h" #include "sysmobts_mgr.h" +#include "sbts2050_header.h"
+#define SERIAL_ALLOC_SIZE 300 +#define SIZE_HEADER_RSP 5 +#define SIZE_HEADER_CMD 4 + +/********************************************************************** + * Functions read/write from serial interface + *********************************************************************/ +int hand_serial_read(int fd, struct msgb *msg, int numbytes) +{ + int rc, bread = 0; + + if (numbytes > msg->data_len) + return -ENOSPC; + + while (bread < numbytes) { + rc = read(fd, msg->tail, numbytes - bread); + if (rc < 0) + return -1; + if (rc == 0) + break; + + bread += rc; + msgb_put(msg, rc); + } + + return bread; +} + +int hand_serial_write(int fd, struct msgb *msg) +{ + int rc, bwritten = 0; + + while (msg->len > 0) { + rc = write(fd, msg->data, msg->len); + if (rc < 0) + return -1; + + msgb_pull(msg, rc); + bwritten += rc; + } + + return bwritten; +} + +/********************************************************************** + * Functions request information to Microcontroller + *********************************************************************/ +static void add_parity(cmdpkt_t *command) +{ + int n; + uint8_t parity = 0x00; + for (n = 0; n < SIZE_HEADER_CMD+command->u8Len; n++) + parity ^= ((uint8_t *)command)[n]; + + command->cmd.raw[command->u8Len] = parity; +} + +struct msgb *sbts2050_ucinfo_get(struct uc ucontrol, struct ucinfo info) +{ + int fd, num, rc; + cmdpkt_t *command; + rsppkt_t *response; + struct msgb *msg; + fd_set fdread; + struct timeval tout = { + .tv_sec = 10, + }; + + switch (info.id) { + case SBTS2050_TEMP_RQT: + num = sizeof(command->cmd.tempGet); + break; + default: + return NULL; + } + num = num + SIZE_HEADER_CMD+1; + + msg = msgb_alloc(SERIAL_ALLOC_SIZE, "Message Microcontroller"); + if (msg == NULL) { + LOGP(DTEMP, LOGL_ERROR, "Error creating msg\n"); + return NULL; + } + command = (cmdpkt_t *) msgb_put(msg, num); + + command->u16Magic = 0xCAFE; + switch (info.id) { + case SBTS2050_TEMP_RQT: + command->u8Id = info.id; + command->u8Len = sizeof(command->cmd.tempGet); + break; + default: + goto err_free; + } + + add_parity(command); + + fd = osmo_serial_init(ucontrol.path, 115200); + if (fd < 0) + goto err_free; + + if (hand_serial_write(fd, msg) < 0) + goto err; + + msgb_reset(msg); + + FD_ZERO(&fdread); + FD_SET(fd, &fdread); + + num = SIZE_HEADER_RSP; + while (1) { + rc = select(fd+1, &fdread, NULL, NULL, &tout); + if (rc > 0) { + if (hand_serial_read(fd, msg, num) < 0) + goto err; + + response = (rsppkt_t *)msg->data; + + if (response->u8Id != info.id || msg->len <= 0 || + response->i8Error != RQT_SUCCESS) + goto err; + + if (msg->len == SIZE_HEADER_RSP + response->u8Len + 1) + break; + + num = response->u8Len + 1; + } else + goto err; + } + close(fd); + + return msg; + +err: + close(fd); +err_free: + msgb_free(msg); + return NULL; +} + +/********************************************************************** + * Uc temperature handling + *********************************************************************/ +void sbts2050_uc_check_temp(struct uc ucontrol) +{ + rsppkt_t *response; + struct msgb *msg; + struct ucinfo info = { + .id = SBTS2050_TEMP_RQT, + }; + + msg = sbts2050_ucinfo_get(ucontrol, info); + + if (msg == NULL) { + LOGP(DTEMP, LOGL_ERROR, "Error reading temperature\n"); + return; + } + + response = (rsppkt_t *)msg->data; + + LOGP(DTEMP, LOGL_DEBUG, "Temperature Board: %+3d C\n" + "Tempeture PA: %+3d C\n", + response->rsp.tempGet.i8BrdTemp, + response->rsp.tempGet.i8PaTemp); +}
/********************************************************************* * Temperature handling diff --git a/src/osmo-bts-sysmo/misc/sysmobts_misc.h b/src/osmo-bts-sysmo/misc/sysmobts_misc.h index 8f7da47..f80df16 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_misc.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_misc.h @@ -1,6 +1,8 @@ #ifndef _SYSMOBTS_MISC_H #define _SYSMOBTS_MISC_H
+#define RQT_SUCCESS 0 + enum sysmobts_temp_sensor { SYSMOBTS_TEMP_DIGITAL = 1, SYSMOBTS_TEMP_RF = 2, @@ -13,11 +15,31 @@ enum sysmobts_temp_type { _NUM_TEMP_TYPES };
+enum sbts2050_ids_request { + SBTS2050_TEMP_RQT = 0x10 +}; + +struct uc { + int id; + const char *path; +}; + +struct ucinfo { + uint16_t id; + int master; + int slave; + int pa; +}; + int sysmobts_temp_get(enum sysmobts_temp_sensor sensor, enum sysmobts_temp_type type);
void sysmobts_check_temp(int no_eeprom_write);
+struct msgb *sbts2050_ucinfo_get(struct uc ucontrol, struct ucinfo info); + +void sbts2050_uc_check_temp(struct uc ucontrol); + int sysmobts_update_hours(int no_epprom_write);
enum sysmobts_firmware_type {
From: Álvaro Neira Ayuso anayuso@sysmocom.de
and requesting status power
I have extended the principal function that we use for requesting information to the microcontroller for switching off/on the board and the PA. And i have extended too with a function for requesting the power status information of the board and the PA.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- src/osmo-bts-sysmo/misc/sysmobts_misc.c | 78 +++++++++++++++++++++++++++++++ src/osmo-bts-sysmo/misc/sysmobts_misc.h | 12 +++++ 2 files changed, 90 insertions(+)
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_misc.c b/src/osmo-bts-sysmo/misc/sysmobts_misc.c index aee892d..4737ff1 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_misc.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_misc.c @@ -115,6 +115,12 @@ struct msgb *sbts2050_ucinfo_get(struct uc ucontrol, struct ucinfo info) case SBTS2050_TEMP_RQT: num = sizeof(command->cmd.tempGet); break; + case SBTS2050_PWR_RQT: + num = sizeof(command->cmd.pwrSetState); + break; + case SBTS2050_PWR_STATUS: + num = sizeof(command->cmd.pwrGetStatus); + break; default: return NULL; } @@ -133,6 +139,17 @@ struct msgb *sbts2050_ucinfo_get(struct uc ucontrol, struct ucinfo info) command->u8Id = info.id; command->u8Len = sizeof(command->cmd.tempGet); break; + case SBTS2050_PWR_RQT: + command->u8Id = info.id; + command->u8Len = sizeof(command->cmd.pwrSetState); + command->cmd.pwrSetState.u1MasterEn = !!info.master; + command->cmd.pwrSetState.u1SlaveEn = !!info.slave; + command->cmd.pwrSetState.u1PwrAmpEn = !!info.pa; + break; + case SBTS2050_PWR_STATUS: + command->u8Id = info.id; + command->u8Len = sizeof(command->cmd.pwrGetStatus); + break; default: goto err_free; } @@ -183,6 +200,67 @@ err_free: }
/********************************************************************** + * Get power status function + *********************************************************************/ +int sbts2050_uc_status(struct uc ucontrol, enum sbts2050_status_rqt status) +{ + struct msgb *msg; + struct ucinfo info = { + .id = SBTS2050_PWR_STATUS, + }; + rsppkt_t *response; + + msg = sbts2050_ucinfo_get(ucontrol, info); + + if (msg == NULL) { + LOGP(DTEMP, LOGL_ERROR, "Error switching off some unit"); + return -1; + } + + response = (rsppkt_t *)msg->data; + + switch (status) { + case SBTS2050_STATUS_MASTER: + return response->rsp.pwrGetStatus.u1MasterEn; + case SBTS2050_STATUS_SLAVE: + return response->rsp.pwrGetStatus.u1SlaveEn; + case SBTS2050_STATUS_PA: + return response->rsp.pwrGetStatus.u1PwrAmpEn; + default: + return -1; + } +} + +/********************************************************************** + * Uc Power Switching handling + *********************************************************************/ +void sbts2050_uc_power(struct uc ucontrol, int pmaster, int pslave, int ppa) +{ + struct msgb *msg; + struct ucinfo info = { + .id = 0x00, + .master = pmaster, + .slave = pslave, + .pa = ppa + }; + + msg = sbts2050_ucinfo_get(ucontrol, info); + + if (msg == NULL) { + LOGP(DTEMP, LOGL_ERROR, "Error switching off some unit"); + return; + } + + LOGP(DTEMP, LOGL_DEBUG, "Switch off/on success:\n" + "MASTER %s\n" + "SLAVE %s\n" + "PA %s\n", + pmaster ? "ON" : "OFF", + pslave ? "ON" : "OFF", + ppa ? "ON" : "OFF"); +} + +/********************************************************************** * Uc temperature handling *********************************************************************/ void sbts2050_uc_check_temp(struct uc ucontrol) diff --git a/src/osmo-bts-sysmo/misc/sysmobts_misc.h b/src/osmo-bts-sysmo/misc/sysmobts_misc.h index f80df16..3d74a12 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_misc.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_misc.h @@ -16,9 +16,17 @@ enum sysmobts_temp_type { };
enum sbts2050_ids_request { + SBTS2050_PWR_RQT = 0x00, + SBTS2050_PWR_STATUS = 0x01, SBTS2050_TEMP_RQT = 0x10 };
+enum sbts2050_status_rqt { + SBTS2050_STATUS_MASTER, + SBTS2050_STATUS_SLAVE, + SBTS2050_STATUS_PA +}; + struct uc { int id; const char *path; @@ -40,6 +48,10 @@ struct msgb *sbts2050_ucinfo_get(struct uc ucontrol, struct ucinfo info);
void sbts2050_uc_check_temp(struct uc ucontrol);
+void sbts2050_uc_power(struct uc ucontrol, int pmaster, int pslave, int ppa); + +int sbts2050_uc_status(struct uc ucontrol, enum sbts2050_status_rqt status); + int sysmobts_update_hours(int no_epprom_write);
enum sysmobts_firmware_type {