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

Broadcast support #15

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion interface/esb.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef struct esbPacket_s {
union {
uint8_t s1;
struct {
uint8_t noack :1;
uint8_t ack :1;
uint8_t pid :2;
};
};
Expand All @@ -48,6 +48,7 @@ typedef struct esbPacket_s {
* from uint32_t to uint8_t without lose of precision */
uint8_t rssi;
unsigned int crc;
uint8_t match;
} EsbPacket;

typedef enum esbDatarate_e { esbDatarate250K=0,
Expand Down
13 changes: 7 additions & 6 deletions interface/syslink.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ bool syslinkSend(struct syslinkPacket *packet);


// Defined packet types
#define SYSLINK_RADIO_RAW 0x00
#define SYSLINK_RADIO_CHANNEL 0x01
#define SYSLINK_RADIO_DATARATE 0x02
#define SYSLINK_RADIO_CONTWAVE 0x03
#define SYSLINK_RADIO_RSSI 0x04
#define SYSLINK_RADIO_ADDRESS 0x05
#define SYSLINK_RADIO_RAW 0x00
#define SYSLINK_RADIO_CHANNEL 0x01
#define SYSLINK_RADIO_DATARATE 0x02
#define SYSLINK_RADIO_CONTWAVE 0x03
#define SYSLINK_RADIO_RSSI 0x04
#define SYSLINK_RADIO_ADDRESS 0x05
#define SYSLINK_RADIO_RAW_BROADCAST 0x06


#define SYSLINK_PM_SOURCE 0x10
Expand Down
28 changes: 18 additions & 10 deletions src/esb.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ void esbInterruptHandler()
pk = &rxPackets[rxq_head];
pk->rssi = (uint8_t) NRF_RADIO->RSSISAMPLE;
pk->crc = NRF_RADIO->RXCRC;
pk->match = NRF_RADIO->RXMATCH;

// If no more space available on RX queue, drop packet!
if (((rxq_head+1)%RXQ_LEN) == rxq_tail) {
Expand All @@ -202,7 +203,7 @@ void esbInterruptHandler()
}

// If this packet is a retry, send the same ACK again
if (isRetry(pk)) {
if (pk->ack && isRetry(pk)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we test for the pipe here instead of testing for the ACK bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that should fix it. Sorry, I didn't manage to actually test that so far, otherwise I would have updated the PR already.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem I can update and test it so that we get rid of the PR.

setupTx(true);
return;
}
Expand All @@ -226,12 +227,19 @@ void esbInterruptHandler()
curr_up = 1-curr_up;
}


if (!has_safelink || (pk->data[0]&0x04) != curr_down<<2) {
curr_down = 1-curr_down;
setupTx(false);
} else {
setupTx(true);
if (pk->ack)
{
if (!has_safelink || (pk->data[0]&0x04) != curr_down<<2) {
curr_down = 1-curr_down;
setupTx(false);
} else {
setupTx(true);
}
} else
{
// broadcast => no ack
NRF_RADIO->PACKETPTR = (uint32_t)&rxPackets[rxq_head];
NRF_RADIO->TASKS_START = 1UL;
}


Expand Down Expand Up @@ -297,12 +305,12 @@ void esbInit()

// Radio address config
// Using logical address 0 so only BASE0 and PREFIX0 & 0xFF are used
NRF_RADIO->PREFIX0 = 0xC4C3C200UL | (bytewise_bitswap(address >> 32) & 0xFF); // Prefix byte of addresses 3 to 0
NRF_RADIO->PREFIX0 = 0xC4C3FF00UL | (bytewise_bitswap(address >> 32) & 0xFF); // Prefix byte of addresses 3 to 0
NRF_RADIO->PREFIX1 = 0xC5C6C7C8UL; // Prefix byte of addresses 7 to 4
NRF_RADIO->BASE0 = bytewise_bitswap((uint32_t)address); // Base address for prefix 0
NRF_RADIO->BASE1 = 0x00C2C2C2UL; // Base address for prefix 1-7
NRF_RADIO->BASE1 = 0xE7E7E7E7UL; // Base address for prefix 1-7
NRF_RADIO->TXADDRESS = 0x00UL; // Set device address 0 to use when transmitting
NRF_RADIO->RXADDRESSES = 0x01UL; // Enable device address 0 to use which receiving
NRF_RADIO->RXADDRESSES = (1<<0) | (1<<1); // Enable device address 0 and 1 to use which receiving

// Packet configuration
NRF_RADIO->PCNF0 = (PACKET0_S1_SIZE << RADIO_PCNF0_S1LEN_Pos) |
Expand Down
8 changes: 7 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void mainloop()
static int vbatSendTime;
static int radioRSSISendTime;
static uint8_t rssi;
static bool broadcast;

while(1)
{
Expand All @@ -163,6 +164,7 @@ void mainloop()
EsbPacket* packet = esbGetRxPacket();
//Store RSSI here so that we can send it to STM later
rssi = packet->rssi;
broadcast = packet->match == 1;
memcpy(esbRxPacket.data, packet->data, packet->size);
esbRxPacket.size = packet->size;
esbReceived = true;
Expand All @@ -186,7 +188,11 @@ void mainloop()
{
memcpy(slTxPacket.data, packet->data, packet->size);
slTxPacket.length = packet->size;
slTxPacket.type = SYSLINK_RADIO_RAW;
if (broadcast) {
slTxPacket.type = SYSLINK_RADIO_RAW_BROADCAST;
} else {
slTxPacket.type = SYSLINK_RADIO_RAW;
}

syslinkSend(&slTxPacket);
}
Expand Down