Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo PR for issue #772 - add API to get temperature value of SX 127x chip #774

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions src/lmic/lmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/*
Expand Down
1 change: 1 addition & 0 deletions src/lmic/oslmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_raw_temp(void);
void radio_monitor_rssi(ostime_t n, oslmic_radio_rssi_t *pRssi);

//================================================================================
Expand Down
53 changes: 51 additions & 2 deletions src/lmic/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -872,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;
Expand Down Expand Up @@ -1176,6 +1182,49 @@ u1_t radio_rssi () {
return r;
}

// Reads the raw temperature
// \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

s1_t RegTemp = 0;

// 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) {
RegTemp = 255 - RegTemp;
} else {
RegTemp *= -1;
}

return RegTemp;
}

/// \brief get the current RSSI on the current channel.
///
/// monitor rssi for specified number of ostime_t ticks, and return statistics
Expand Down
Loading