microbit: fixed formatting issues in MicroBitRadio

Removed trailing whitespace.
master
James Devine 2016-02-04 03:44:25 +00:00
parent a255711e8f
commit ffc217e7ac
2 changed files with 42 additions and 40 deletions

View File

@ -9,7 +9,7 @@
* The nrf51822 RADIO module supports a number of proprietary modes of operation in addition to the typical BLE usage.
* This class uses one of these modes to enable simple, point to multipoint communication directly between micro:bits.
*
* TODO: The protocols implemented here do not currently perform any significant form of energy management,
* TODO: The protocols implemented here do not currently perform any significant form of energy management,
* which means that they will consume far more energy than their BLE equivalent. Later versions of the protocol
* should look to address this through energy efficient broadcast techniques / sleep scheduling. In particular, the GLOSSY
* approach to efficienct rebroadcast and network synchronisation would likely provide an effective future step.
@ -17,7 +17,7 @@
* TODO: Meshing should also be considered - again a GLOSSY approach may be effective here, and highly complementary to
* the master/slave arachitecture of BLE.
*
* TODO: This implementation only operates whilst the BLE stack is disabled. The nrf51822 provides a timeslot API to allow
* TODO: This implementation only operates whilst the BLE stack is disabled. The nrf51822 provides a timeslot API to allow
* BLE to cohabit with other protocols. Future work to allow this colocation would be benefical, and would also allow for the
* creation of wireless BLE bridges.
*
@ -31,12 +31,12 @@
// Default configuration values
#define MICROBIT_RADIO_BASE_ADDRESS 0x75626974
#define MICROBIT_RADIO_DEFAULT_GROUP 0
#define MICROBIT_RADIO_DEFAULT_GROUP 0
#define MICROBIT_RADIO_DEFAULT_TX_POWER 6
#define MICROBIT_RADIO_DEFAULT_FREQUENCY 7
#define MICROBIT_RADIO_MAX_PACKET_SIZE 32
#define MICROBIT_RADIO_HEADER_SIZE 4
#define MICROBIT_RADIO_MAXIMUM_RX_BUFFERS 4
#define MICROBIT_RADIO_MAX_PACKET_SIZE 32
#define MICROBIT_RADIO_HEADER_SIZE 4
#define MICROBIT_RADIO_MAXIMUM_RX_BUFFERS 4
// Known Protocol Numbers
#define MICROBIT_RADIO_PROTOCOL_DATAGRAM 1 // A simple, single frame datagram. a little like UDP but with smaller packets. :-)
@ -63,6 +63,7 @@ class MicroBitRadio : MicroBitComponent
{
uint8_t group; // The radio group to which this micro:bit belongs.
uint8_t queueDepth; // The number of packets in the receiver queue.
uint8_t rssi;
PacketBuffer *rxQueue; // A linear list of incoming packets, queued awaiting processing.
PacketBuffer *rxBuf; // A pointer to the buffer being actively used by the RADIO hardware.
@ -74,7 +75,7 @@ class MicroBitRadio : MicroBitComponent
/**
* Constructor.
*
* Initialise the MicroBitRadio. Note that this class is demand activated, so most resources are only
* Initialise the MicroBitRadio. Note that this class is demand activated, so most resources are only
* committed if send/recv or event registrations calls are made.
*/
MicroBitRadio(uint16_t id);
@ -82,7 +83,7 @@ class MicroBitRadio : MicroBitComponent
/**
* Change the output power level of the transmitter to the given value.
*
* @param power a value in the range 0..7, where 0 is the lowest power and 7 is the highest.
* @param power a value in the range 0..7, where 0 is the lowest power and 7 is the highest.
* @return MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the value is out of range.
*
*/
@ -92,7 +93,7 @@ class MicroBitRadio : MicroBitComponent
* Change the transmission and reception band of the radio to the given channel
*
* @param band a frequency band in the range 0 - 100. Each step is 1MHz wide, based at 2400MHz.
* @return MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the value is out of range,
* @return MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the value is out of range,
* or MICROBIT_NOT_SUPPORTED if the BLE stack is running.
*
*/
@ -102,7 +103,7 @@ class MicroBitRadio : MicroBitComponent
* Retrieve a pointer to the currently allocated recieve buffer. This is the area of memory
* actively being used by the radio hardware to store incoming data.
*
* @return a pointer to the current receive buffer
* @return a pointer to the current receive buffer
*/
PacketBuffer* getRxBuf();
@ -138,7 +139,7 @@ class MicroBitRadio : MicroBitComponent
* A background, low priority callback that is triggered whenever the processor is idle.
* Here, we empty our queue of received packets, and pass them onto higher level protocol handlers.
*
* We provide optimised handling of well known, simple protocols and events on the MicroBitMessageBus
* We provide optimised handling of well known, simple protocols and events on the MicroBitMessageBus
* to provide extensibility to other protocols that may be written in the future.
*/
virtual void idleTick();
@ -152,9 +153,9 @@ class MicroBitRadio : MicroBitComponent
/**
* Retrieves the next packet from the receive buffer.
* If a data packet is available, then it will be returned immediately to
* the caller. This call will also dequeue the buffer.
* the caller. This call will also dequeue the buffer.
*
* NOTE: Once recv() has been called, it is the callers resposibility to
* NOTE: Once recv() has been called, it is the callers resposibility to
* delete the buffer when appropriate.
*
* @return The buffer containing the the packet. If no data is available, NULL is returned.

View File

@ -6,7 +6,7 @@
* The nrf51822 RADIO module supports a number of proprietary modes of operation oher than the typical BLE usage.
* This class uses one of these modes to enable simple, point to multipoint communication directly between micro:bits.
*
* TODO: The protocols implemented here do not currently perform any significant form of energy management,
* TODO: The protocols implemented here do not currently perform any significant form of energy management,
* which means that they will consume far more energy than their BLE equivalent. Later versions of the protocol
* should look to address this through energy efficient broadcast techbiques / sleep scheduling. In particular, the GLOSSY
* approach to efficient rebroadcast and network synchronisation would likely provide an effective future step.
@ -14,7 +14,7 @@
* TODO: Meshing should also be considered - again a GLOSSY approach may be effective here, and highly complementary to
* the master/slave arachitecture of BLE.
*
* TODO: This implementation may only operated whilst the BLE stack is disabled. The nrf51822 provides a timeslot API to allow
* TODO: This implementation may only operated whilst the BLE stack is disabled. The nrf51822 provides a timeslot API to allow
* BLE to cohabit with other protocols. Future work to allow this colocation would be benefical, and would also allow for the
* creation of wireless BLE bridges.
*
@ -39,7 +39,7 @@ extern "C" void RADIO_IRQHandler(void)
/**
* Constructor.
*
* Initialise the MicroBitRadio. Note that this class is demand activated, so most resources are only committed
* Initialise the MicroBitRadio. Note that this class is demand activated, so most resources are only committed
* if send/recv or event registrations calls are made.
*/
MicroBitRadio::MicroBitRadio(uint16_t id) : datagram()
@ -57,7 +57,7 @@ MicroBitRadio::MicroBitRadio(uint16_t id) : datagram()
/**
* Change the output power level of the transmitter to the given value.
*
* @param power a value in the range 0..7, where 0 is the lowest power and 7 is the highest.
* @param power a value in the range 0..7, where 0 is the lowest power and 7 is the highest.
* @return MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the value is out of range.
*
*/
@ -75,7 +75,7 @@ int MicroBitRadio::setTransmitPower(int power)
* Change the transmission and reception band of the radio to the given channel
*
* @param band a frequency band in the range 0 - 100. Each step is 1MHz wide, based at 2400MHz.
* @return MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the value is out of range,
* @return MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the value is out of range,
* or MICROBIT_NOT_SUPPORTED if the BLE stack is running.
*
*/
@ -96,7 +96,7 @@ int MicroBitRadio::setFrequencyBand(int band)
* Retrieve a pointer to the currently allocated receive buffer. This is the area of memory
* actively being used by the radio hardware to store incoming data.
*
* @return a pointer to the current receive buffer
* @return a pointer to the current receive buffer
*/
PacketBuffer* MicroBitRadio::getRxBuf()
{
@ -181,15 +181,15 @@ int MicroBitRadio::enable()
setTransmitPower(MICROBIT_RADIO_DEFAULT_TX_POWER);
setFrequencyBand(MICROBIT_RADIO_DEFAULT_FREQUENCY);
// Configure for 1Mbps throughput.
// Configure for 1Mbps throughput.
// This may sound excessive, but running a high data rates reduces the chances of collisions...
NRF_RADIO->MODE = RADIO_MODE_MODE_Nrf_1Mbit;
// Configure the addresses we use for this protocol. We run ANONYMOUSLY at the core.
// A 40 bit addresses is used. The first 32 bits match the ASCII character code for "uBit".
// A 40 bit addresses is used. The first 32 bits match the ASCII character code for "uBit".
// Statistically, this provides assurance to avoid other similar 2.4GHz protocols that may be in the vicinity.
// We also map the assigned 8-bit GROUP id into the PREFIX field. This allows the RADIO hardware to perform
// address matching for us, and only generate an interrupt when a packet matching our group is received.
// We also map the assigned 8-bit GROUP id into the PREFIX field. This allows the RADIO hardware to perform
// address matching for us, and only generate an interrupt when a packet matching our group is received.
NRF_RADIO->BASE0 = MICROBIT_RADIO_BASE_ADDRESS;
// Join the default group. This will configure the remaining byte in the RADIO hardware module.
@ -197,8 +197,8 @@ int MicroBitRadio::enable()
// The RADIO hardware module supports the use of multiple addresses, but as we're running anonymously, we only need one.
// Configure the RADIO module to use the default address (address 0) for both send and receive operations.
NRF_RADIO->TXADDRESS = 0;
NRF_RADIO->RXADDRESSES = 1;
NRF_RADIO->TXADDRESS = 0;
NRF_RADIO->RXADDRESSES = 1;
// Packet layout configuration. The nrf51822 has a highly capable and flexible RADIO module that, in addition to transmission
// and reception of data, also contains a LENGTH field, two optional additional 1 byte fields (S0 and S1) and a CRC calculation.
@ -212,21 +212,23 @@ int MicroBitRadio::enable()
// and we know we can't trust it. The nrf51822 RADIO uses a CRC for this - a very effective checksum calculation.
//
// Enable automatic 16bit CRC generation and checking, and configure how the CRC is calculated.
NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
NRF_RADIO->CRCINIT = 0xFFFF;
NRF_RADIO->CRCPOLY = 0x11021;
NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
NRF_RADIO->CRCINIT = 0xFFFF;
NRF_RADIO->CRCPOLY = 0x11021;
// Set the start random value of the data whitening algorithm. This can be any non zero number.
NRF_RADIO->DATAWHITEIV = 0x18;
NRF_RADIO->DATAWHITEIV = 0x18;
// Set up the RADIO module to read and write from our internal buffer.
NRF_RADIO->PACKETPTR = (uint32_t)rxBuf;
// Set up the RADIO module to read and write from our internal buffer.
NRF_RADIO->PACKETPTR = (uint32_t)rxBuf;
// Configure the hardware to issue an interrupt whenever a task is complete (e.g. send/receive).
NRF_RADIO->INTENSET = 0x00000008;
NVIC_ClearPendingIRQ(RADIO_IRQn);
NVIC_EnableIRQ(RADIO_IRQn);
NRF_RADIO->SHORTS |= RADIO_SHORTS_ADDRESS_RSSISTART_Msk;
// Start listening for the next packet
NRF_RADIO->EVENTS_READY = 0;
NRF_RADIO->TASKS_RXEN = 1;
@ -253,7 +255,7 @@ int MicroBitRadio::disable()
// Only attempt to enable.disable the radio if the protocol is alreayd running.
if (uBit.ble)
return MICROBIT_NOT_SUPPORTED;
if (!(status & MICROBIT_RADIO_STATUS_INITIALISED))
return MICROBIT_OK;
@ -294,7 +296,7 @@ int MicroBitRadio::setGroup(uint8_t group)
* A background, low priority callback that is triggered whenever the processor is idle.
* Here, we empty our queue of received packets, and pass them onto higher level protocol handlers.
*
* We provide optimised handling of well known, simple protocols and events on the MicroBitMessageBus
* We provide optimised handling of well known, simple protocols and events on the MicroBitMessageBus
* to provide extensibility to other protocols that may be written in the future.
*/
void MicroBitRadio::idleTick()
@ -314,11 +316,11 @@ void MicroBitRadio::idleTick()
event.packetReceived();
break;
default:
default:
MicroBitEvent(MICROBIT_ID_RADIO_DATA_READY, p->protocol);
}
// If the packet was processed, it will have been recv'd, and taken from the queue.
// If the packet was processed, it will have been recv'd, and taken from the queue.
// If this was a packet for an unknown protocol, it will still be there, so simply free it.
if (p == rxQueue)
{
@ -340,9 +342,9 @@ int MicroBitRadio::dataReady()
/**
* Retrieves the next packet from the receive buffer.
* If a data packet is available, then it will be returned immediately to
* the caller. This call will also dequeue the buffer.
* the caller. This call will also dequeue the buffer.
*
* NOTE: Once recv() has been called, it is the callers resposibility to
* NOTE: Once recv() has been called, it is the callers resposibility to
* delete the buffer when appropriate.
*
* @return The buffer containing the the packet. If no data is available, NULL is returned.
@ -365,7 +367,7 @@ PacketBuffer* MicroBitRadio::recv()
* The call will wait until the transmission of the packet has completed before returning.
*
* @param data The packet contents to transmit.
* @return MICROBIT_OK on success, or MICROBIT_NOT_SUPPORTED if the BLE stack is running.
* @return MICROBIT_OK on success, or MICROBIT_NOT_SUPPORTED if the BLE stack is running.
*/
int MicroBitRadio::send(PacketBuffer *buffer)
{
@ -421,4 +423,3 @@ int MicroBitRadio::send(PacketBuffer *buffer)
return MICROBIT_OK;
}