summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Borges <paulo.borges@openbossa.org>2013-12-25 00:51:44 -0300
committerPaulo Borges <paulo.borges@openbossa.org>2013-12-25 23:54:11 -0300
commit3937b4b36fd7092371021079c298b33f9757f91c (patch)
tree8f28d2cf2a1ee2f9887a46c522903d2b070a0d9b
parent27cc7774dfae2dbb6ae2fcc365b92196f0148f5c (diff)
nrf51822: Implement radio_send()
-rw-r--r--platform/nrf51822/radio.c33
-rw-r--r--stack/radio.h2
2 files changed, 32 insertions, 3 deletions
diff --git a/platform/nrf51822/radio.c b/platform/nrf51822/radio.c
index 82b26d4..4e2f5d7 100644
--- a/platform/nrf51822/radio.c
+++ b/platform/nrf51822/radio.c
@@ -37,7 +37,8 @@
#define STATUS_INITIALIZED 1
#define STATUS_RX 2
-#define STATUS_BUSY STATUS_RX
+#define STATUS_TX 4
+#define STATUS_BUSY (STATUS_RX | STATUS_TX)
static radio_handler handler;
static uint8_t buf[MAX_BUF_LEN];
@@ -89,7 +90,10 @@ void RADIO_IRQHandler(void)
old_status = status;
status = STATUS_INITIALIZED;
- if ((old_status & STATUS_RX) && handler) {
+ if (handler == NULL)
+ return;
+
+ if (old_status & STATUS_RX) {
packet.len = buf[1] + 2;
packet.crc = NRF_RADIO->CRCSTATUS;
@@ -98,7 +102,30 @@ void RADIO_IRQHandler(void)
memcpy(packet.pdu + 2, buf + 3, buf[1]);
handler(RADIO_EVT_RX_COMPLETED, &packet);
- }
+ } else if (old_status & STATUS_TX)
+ handler(RADIO_EVT_TX_COMPLETED, NULL);
+}
+
+int16_t radio_send(uint8_t ch, uint32_t aa, uint32_t crc, const uint8_t *data,
+ uint8_t len)
+{
+ if (len > RADIO_MAX_PDU_LEN)
+ return -1;
+
+ if (len < RADIO_MIN_PDU_LEN)
+ return -1;
+
+ COMMON_INITIALIZATION(ch, aa, crc);
+
+ buf[0] = data[0];
+ buf[1] = data[1] & 0x3F;
+ buf[2] = (data[1] >> 6) & 0x3;
+ memcpy(buf + 3, data + 2, len - 2);
+
+ NRF_RADIO->TASKS_TXEN = 1UL;
+ status |= STATUS_TX;
+
+ return 0;
}
int16_t radio_recv(uint8_t ch, uint32_t aa, uint32_t crc)
diff --git a/stack/radio.h b/stack/radio.h
index 52f6be7..7f0a52f 100644
--- a/stack/radio.h
+++ b/stack/radio.h
@@ -25,8 +25,10 @@
*/
#define RADIO_MAX_PDU_LEN 39
+#define RADIO_MIN_PDU_LEN 2
#define RADIO_EVT_RX_COMPLETED 1
+#define RADIO_EVT_TX_COMPLETED 2
struct radio_packet {
uint8_t pdu[RADIO_MAX_PDU_LEN];