diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index 625a41f6a..226d8be9f 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -186,6 +186,31 @@ cc2538_rf_set_addr(uint16_t pan) REG(RFCORE_FFSM_SHORT_ADDR1) = rimeaddr_node_addr.u8[RIMEADDR_SIZE - 2]; } /*---------------------------------------------------------------------------*/ +int +cc2538_rf_read_rssi(void) +{ + int rssi; + + /* If we are off, turn on first */ + if((REG(RFCORE_XREG_FSMSTAT0) & RFCORE_XREG_FSMSTAT0_FSM_FFCTRL_STATE) == 0) { + rf_flags |= WAS_OFF; + on(); + } + + /* Wait on RSSI_VALID */ + while((REG(RFCORE_XREG_RSSISTAT) & RFCORE_XREG_RSSISTAT_RSSI_VALID) == 0); + + rssi = ((int8_t)REG(RFCORE_XREG_RSSI)) - RSSI_OFFSET; + + /* If we were off, turn back off */ + if((rf_flags & WAS_OFF) == WAS_OFF) { + rf_flags &= ~WAS_OFF; + off(); + } + + return rssi; +} +/*---------------------------------------------------------------------------*/ /* Netstack API radio driver functions */ /*---------------------------------------------------------------------------*/ static int @@ -720,5 +745,14 @@ cc2538_rf_err_isr(void) ENERGEST_OFF(ENERGEST_TYPE_IRQ); } /*---------------------------------------------------------------------------*/ - +void +cc2538_rf_set_promiscous_mode(char p) +{ + if(p) { + REG(RFCORE_XREG_FRMFILT0) &= ~RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN; + } else { + REG(RFCORE_XREG_FRMFILT0) |= RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN; + } +} +/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/cpu/cc2538/dev/cc2538-rf.h b/cpu/cc2538/dev/cc2538-rf.h index e6f420fe6..75b4ca3e4 100644 --- a/cpu/cc2538/dev/cc2538-rf.h +++ b/cpu/cc2538/dev/cc2538-rf.h @@ -144,7 +144,7 @@ int8_t cc2538_rf_channel_set(uint8_t channel); * \brief Get the current operating channel * \return Returns a value in [11,26] representing the current channel */ -uint8_t cc2538_rf_channel_get(); +uint8_t cc2538_rf_channel_get(void); /** * \brief Sets RF TX power @@ -167,6 +167,27 @@ uint8_t cc2538_rf_power_set(uint8_t new_power); * are thus simply copied over from there. */ void cc2538_rf_set_addr(uint16_t pan); + +/** + * \brief Reads the current signal strength (RSSI) + * \return The current RSSI + * + * This function reads the current RSSI on the currently configured + * channel. + */ +int cc2538_rf_read_rssi(void); + +/** + * \brief Turn promiscous mode on or off + * \param p If promiscous mode should be on (1) or off (0) + * + * This function turns promiscous mode on or off. In promiscous mode, + * every received frame is returned from the RF core. In + * non-promiscous mode, only broadcast frames or frames with our + * address as the receive address are returned from the RF core. + */ +void cc2538_rf_set_promiscous_mode(char p); + /*---------------------------------------------------------------------------*/ #endif /* CC2538_RF_H__ */