microbit: add RSSI to MicroBitRadio

Added the ability to capture the RSSI value, and an accessor and
mutator for the last received RSSI value.
This commit is contained in:
James Devine 2016-02-04 03:45:57 +00:00
parent ffc217e7ac
commit af13c940c1
2 changed files with 64 additions and 4 deletions

View File

@ -115,6 +115,18 @@ class MicroBitRadio : MicroBitComponent
*/
int queueRxBuf();
/**
* Sets the RSSI for the most recent packet.
*
* @param rssi the new rssi value
*/
int setRSSI(uint8_t rssi);
/**
* Retrieves the current RSSI for the most recent packet.
*/
int getRSSI();
/**
* Initialises the radio for use as a multipoint sender/receiver
* @return MICROBIT_OK on success, MICROBIT_NOT_SUPPORTED if SoftDevice is enabled.

View File

@ -31,9 +31,28 @@ extern "C" void RADIO_IRQHandler(void)
MicroBitRadio::instance->queueRxBuf();
NRF_RADIO->PACKETPTR = (uint32_t) MicroBitRadio::instance->getRxBuf();
// Start listening for the next packet.
NRF_RADIO->EVENTS_END = 0;
NRF_RADIO->TASKS_START = 1;
if(NRF_RADIO->EVENTS_READY)
{
NRF_RADIO->EVENTS_READY = 0;
// Start listening and wait for the END event
NRF_RADIO->TASKS_START = 1;
}
if(NRF_RADIO->EVENTS_END)
{
NRF_RADIO->EVENTS_END = 0;
if(NRF_RADIO->CRCSTATUS == 1)
{
uint8_t sample = NRF_RADIO->RSSISAMPLE;
uBit.radio.setRSSI(sample);
}
// Start listening and wait for the END event
NRF_RADIO->TASKS_START = 1;
}
}
/**
@ -48,6 +67,7 @@ MicroBitRadio::MicroBitRadio(uint16_t id) : datagram()
this->status = 0;
this->group = 0;
this->queueDepth = 0;
this->rssi = 0;
this->rxQueue = NULL;
this->rxBuf = NULL;
@ -148,6 +168,34 @@ int MicroBitRadio::queueRxBuf()
return MICROBIT_OK;
}
/**
* Sets the RSSI for the most recent packet.
*
* @param rssi the new rssi value
*
* @note should only be called from RADIO_IRQHandler...
*/
int MicroBitRadio::setRSSI(uint8_t rssi)
{
if (!(status & MICROBIT_RADIO_STATUS_INITIALISED))
return MICROBIT_NOT_SUPPORTED;
this->rssi = rssi;
return MICROBIT_OK;
}
/**
* Retrieves the current RSSI for the most recent packet.
*/
int MicroBitRadio::getRSSI()
{
if (!(status & MICROBIT_RADIO_STATUS_INITIALISED))
return MICROBIT_NOT_SUPPORTED;
return this->rssi;
}
/**
* Initialises the radio for use as a multipoint sender/receiver.
* This is currently only possible if the BLE stack (Soft Device) is disabled.