From 8fb2a023eb315f593babf9ab6fd6ffb5bb2b0c88 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 24 Jul 2021 21:17:50 +0200 Subject: [PATCH 1/8] Update radio.c --- src/lmic/radio.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index d6cc9088..cb7d2a86 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -1176,6 +1176,60 @@ u1_t radio_rssi () { return r; } +// Reads the raw temperature +// \retval New raw temperature reading in 2's complement format +s1_t radio_GetRawTemp(void) { + +#define RF_IMAGECAL_TEMPMONITOR_MASK 0xFE +#define RF_IMAGECAL_TEMPMONITOR_ON 0x00 +#define RF_IMAGECAL_TEMPMONITOR_OFF 0x01 + + int8_t temp = 0; + uint8_t previousOpMode, RegTemp; + + // Save current Operation Mode + previousOpMode = readReg(RegOpMode); + + // Put device in FSK Sleep Mode + opmode(OPMODE_SLEEP); + + // select FSK modem (from sleep mode) + opmodeFSK(); + ASSERT((readReg(RegOpMode) & OPMODE_LORA) == 0); + + // Put device in FSK RxSynth + opmode(OPMODE_FSRX); + + // Enable Temperature reading + writeReg(FSKRegImageCal, (readReg(RegOpMode) & RF_IMAGECAL_TEMPMONITOR_MASK) | + RF_IMAGECAL_TEMPMONITOR_ON); + + // Wait 150us + hal_waitUntil(os_getTime() + us2osticks(150)); + + // Disable Temperature reading + writeReg(FSKRegImageCal, (readReg(RegOpMode) & RF_IMAGECAL_TEMPMONITOR_MASK) | + RF_IMAGECAL_TEMPMONITOR_OFF); + + // Put device in FSK Sleep Mode + opmode(OPMODE_SLEEP); + + // Read temperature + RegTemp = readReg(FSKRegTemp); + + if ((RegTemp & 0x80) == 0x80) { + temp = 255 - RegTemp; + } else { + temp = RegTemp; + temp *= -1; + } + + // Reload previous Op Mode + writeReg(RegOpMode, previousOpMode); + + return temp; +} + /// \brief get the current RSSI on the current channel. /// /// monitor rssi for specified number of ostime_t ticks, and return statistics From 5689a9471383e78e852fd7d0c3a1475bd6754d54 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 24 Jul 2021 21:18:56 +0200 Subject: [PATCH 2/8] Update oslmic.h --- src/lmic/oslmic.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lmic/oslmic.h b/src/lmic/oslmic.h index 448b0290..c0847f39 100644 --- a/src/lmic/oslmic.h +++ b/src/lmic/oslmic.h @@ -115,6 +115,7 @@ int os_init_ex (const void *pPinMap); void os_runloop (void); void os_runloop_once (void); u1_t radio_rssi (void); +s1_t radio_GetRawTemp(void); void radio_monitor_rssi(ostime_t n, oslmic_radio_rssi_t *pRssi); //================================================================================ From 876f39ac3ad9bbae50a4eb0be5fcd6127d1f4eab Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 24 Jul 2021 21:26:27 +0200 Subject: [PATCH 3/8] Update radio.c --- src/lmic/radio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index cb7d2a86..db2977bf 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -1184,8 +1184,8 @@ s1_t radio_GetRawTemp(void) { #define RF_IMAGECAL_TEMPMONITOR_ON 0x00 #define RF_IMAGECAL_TEMPMONITOR_OFF 0x01 - int8_t temp = 0; - uint8_t previousOpMode, RegTemp; + s1_t temp = 0; + u1_t previousOpMode, RegTemp; // Save current Operation Mode previousOpMode = readReg(RegOpMode); From af109515497eb1af5000d2e1a0febf9803107dbd Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 25 Jul 2021 12:22:54 +0200 Subject: [PATCH 4/8] Update lmic.h --- src/lmic/lmic.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lmic/lmic.h b/src/lmic/lmic.h index 49703ae9..1b8d23ca 100644 --- a/src/lmic/lmic.h +++ b/src/lmic/lmic.h @@ -486,6 +486,8 @@ struct lmic_radio_data_s { ostime_t txlate_ticks; // number of tx late launches. unsigned txlate_count; + // radio chip raw temperature value. + s1_t temperature; }; /* From 7bd0683d925e3e11e55317051d2bc59b2ef680e3 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 25 Jul 2021 12:23:25 +0200 Subject: [PATCH 5/8] Update oslmic.h --- src/lmic/oslmic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lmic/oslmic.h b/src/lmic/oslmic.h index c0847f39..9904769b 100644 --- a/src/lmic/oslmic.h +++ b/src/lmic/oslmic.h @@ -115,7 +115,7 @@ int os_init_ex (const void *pPinMap); void os_runloop (void); void os_runloop_once (void); u1_t radio_rssi (void); -s1_t radio_GetRawTemp(void); +s1_t radio_raw_temp(void); void radio_monitor_rssi(ostime_t n, oslmic_radio_rssi_t *pRssi); //================================================================================ From 3eddf00ffc68fb90ccf885c3af0eba8354dbf30e Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 25 Jul 2021 12:25:51 +0200 Subject: [PATCH 6/8] Update radio.c --- src/lmic/radio.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index cb7d2a86..6930d8af 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -861,6 +861,12 @@ static void txlora () { // start transmitter (buf=LMIC.frame, len=LMIC.dataLen) static void starttx () { u1_t const rOpMode = readReg(RegOpMode); + + // update radio chip raw temperature value + LMIC.radio.temperature = radio_raw_temp(); +#if LMIC_DEBUG_LEVEL > 0 + LMIC_DEBUG_PRINTF("RegTemp=%d\n", LMIC.radio.temperature); +#endif // originally, this code ASSERT()ed, but asserts are both bad and // blunt instruments. If we see that we're not in sleep mode, @@ -1177,21 +1183,14 @@ u1_t radio_rssi () { } // Reads the raw temperature -// \retval New raw temperature reading in 2's complement format -s1_t radio_GetRawTemp(void) { +// \retval New raw temperature reading +s1_t radio_raw_temp(void) { #define RF_IMAGECAL_TEMPMONITOR_MASK 0xFE #define RF_IMAGECAL_TEMPMONITOR_ON 0x00 #define RF_IMAGECAL_TEMPMONITOR_OFF 0x01 - int8_t temp = 0; - uint8_t previousOpMode, RegTemp; - - // Save current Operation Mode - previousOpMode = readReg(RegOpMode); - - // Put device in FSK Sleep Mode - opmode(OPMODE_SLEEP); + s1_t RegTemp = 0; // select FSK modem (from sleep mode) opmodeFSK(); @@ -1218,16 +1217,12 @@ s1_t radio_GetRawTemp(void) { RegTemp = readReg(FSKRegTemp); if ((RegTemp & 0x80) == 0x80) { - temp = 255 - RegTemp; + RegTemp = 255 - RegTemp; } else { - temp = RegTemp; - temp *= -1; + RegTemp *= -1; } - // Reload previous Op Mode - writeReg(RegOpMode, previousOpMode); - - return temp; + return RegTemp; } /// \brief get the current RSSI on the current channel. From 5f06c3900991e89944711c40cec9ab009d1ad470 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 25 Jul 2021 15:21:11 +0200 Subject: [PATCH 7/8] Update radio.c --- src/lmic/radio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 6930d8af..66b1ec2a 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -861,12 +861,6 @@ static void txlora () { // start transmitter (buf=LMIC.frame, len=LMIC.dataLen) static void starttx () { u1_t const rOpMode = readReg(RegOpMode); - - // update radio chip raw temperature value - LMIC.radio.temperature = radio_raw_temp(); -#if LMIC_DEBUG_LEVEL > 0 - LMIC_DEBUG_PRINTF("RegTemp=%d\n", LMIC.radio.temperature); -#endif // originally, this code ASSERT()ed, but asserts are both bad and // blunt instruments. If we see that we're not in sleep mode, @@ -878,6 +872,12 @@ static void starttx () { opmode(OPMODE_SLEEP); hal_waitUntil(os_getTime() + ms2osticks(1)); } + + // update radio chip raw temperature value + LMIC.radio.temperature = radio_raw_temp(); +#if LMIC_DEBUG_LEVEL > 0 + LMIC_DEBUG_PRINTF("RegTemp=%d\n", LMIC.radio.temperature); +#endif if (LMIC.lbt_ticks > 0) { oslmic_radio_rssi_t rssi; From cd8d7ea667561fc3eed9562a71838e42acce5c99 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Fri, 29 Jul 2022 20:27:11 +0200 Subject: [PATCH 8/8] Update radio.c fix configPower for sx1272 --- src/lmic/radio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lmic/radio.c b/src/lmic/radio.c index d6cc9088..7522b64b 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -668,9 +668,9 @@ static void configPower () { if (req_pw >= 20) { policy = LMICHAL_radio_tx_power_policy_20dBm; eff_pw = 20; - } else if (eff_pw >= 14) { + } else if (req_pw >= 14) { policy = LMICHAL_radio_tx_power_policy_paboost; - if (eff_pw > 17) { + if (req_pw > 17) { eff_pw = 17; } else { eff_pw = req_pw;