summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Borges <paulo.borges@openbossa.org>2013-12-25 23:47:54 -0300
committerPaulo Borges <paulo.borges@openbossa.org>2013-12-25 23:54:11 -0300
commitc8f0dfa4c574f3e00f3c0cc062e9aa81000b8cd7 (patch)
treedc2f3a2d2b4954cbff5eb9502f7ed39ac2b024d2
parent3937b4b36fd7092371021079c298b33f9757f91c (diff)
examples: Add radio-broadcaster examplenrf51822
This patch adds an example that implements the GAP broadcaster role using radio and timer APIs directly.
-rw-r--r--examples/radio-broadcaster/Makefile7
-rw-r--r--examples/radio-broadcaster/main.c88
2 files changed, 95 insertions, 0 deletions
diff --git a/examples/radio-broadcaster/Makefile b/examples/radio-broadcaster/Makefile
new file mode 100644
index 0000000..dfa2317
--- /dev/null
+++ b/examples/radio-broadcaster/Makefile
@@ -0,0 +1,7 @@
+# Makefile for radio-broadcaster example
+
+PROJECT_TARGET = radio-broadcaster-example
+PROJECT_SOURCE_FILES = main.c
+
+BLESTACK_PATH = ../..
+-include $(BLESTACK_PATH)/Makefile.common
diff --git a/examples/radio-broadcaster/main.c b/examples/radio-broadcaster/main.c
new file mode 100644
index 0000000..2ca52cb
--- /dev/null
+++ b/examples/radio-broadcaster/main.c
@@ -0,0 +1,88 @@
+/**
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013 Paulo B. de Oliveira Filho <pauloborgesfilho@gmail.com>
+ * Copyright (c) 2013 Claudio Takahasi <claudio.takahasi@gmail.com>
+ * Copyright (c) 2013 João Paulo Rechi Vita <jprvita@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <string.h>
+#include <stdint.h>
+
+#include "timer.h"
+#include "radio.h"
+#include "log.h"
+
+#define ADV_CHANNEL_AA 0x8E89BED6
+#define ADV_CHANNEL_CRC 0x555555
+
+#define ADV_EVENT 100
+#define ADV_INTERVAL 5
+
+static const uint8_t pdu[] = { 0x42, 0x06, 0xAA, 0xBB,
+ 0xCC, 0xDD, 0xEE, 0xFF };
+
+static uint8_t channels[] = { 37, 38, 39 };
+static uint8_t idx = 0;
+
+static int16_t adv_event;
+static int16_t adv_interval;
+
+void adv_interval_timeout(void *user_data)
+{
+ radio_send(channels[idx++], ADV_CHANNEL_AA, ADV_CHANNEL_CRC, pdu,
+ sizeof(pdu));
+
+ if (idx < 3)
+ timer_start(adv_interval, ADV_INTERVAL, NULL);
+}
+
+void adv_event_timeout(void *user_data)
+{
+ idx = 0;
+
+ radio_send(channels[idx++], ADV_CHANNEL_AA, ADV_CHANNEL_CRC, pdu,
+ sizeof(pdu));
+ timer_start(adv_interval, ADV_INTERVAL, NULL);
+}
+
+int main(void)
+{
+ log_init();
+ timer_init();
+ radio_init();
+
+ adv_interval = timer_create(TIMER_SINGLESHOT, adv_interval_timeout);
+ adv_event = timer_create(TIMER_REPEATED, adv_event_timeout);
+
+ DBG("Advertising with:");
+ DBG("Time between PDUs: %u ms", ADV_INTERVAL);
+ DBG("T_advEvent: %u ms", ADV_EVENT);
+
+ radio_send(channels[idx], ADV_CHANNEL_AA, ADV_CHANNEL_CRC, pdu,
+ sizeof(pdu));
+ timer_start(adv_interval, ADV_INTERVAL, NULL);
+ timer_start(adv_event, ADV_EVENT, NULL);
+
+ while (1);
+
+ return 0;
+}