summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMyles Watson <mylesgw@chromium.org>2014-12-23 16:59:56 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-08-02 12:17:10 -0700
commitc88b86852b1033e7623630554eb8ee0f4647b091 (patch)
tree6a3e5a0a67cea57325968e5fc77a20343415ac4f
parent0a1ab50bcfdcb828f665a7e1dc983c8fed25d1e4 (diff)
downloadchrome-ec-c88b86852b1033e7623630554eb8ee0f4647b091.tar.gz
nrf51: Add generic radio support
Add functions to initialize and disable the radio. Add packet definitions. Update the spelling of the FICR_OVERRIDEEN register. BUG=None BRANCH=None TEST=make buildall -j Change-Id: I3a9e500d0f177b6ce77a3b6ed6a42acd4f49eb7e Signed-off-by: Myles Watson <mylesgw@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/362175 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Levi Oliver <levio@google.com>
-rw-r--r--chip/nrf51/build.mk1
-rw-r--r--chip/nrf51/radio.c59
-rw-r--r--chip/nrf51/radio.h35
-rw-r--r--chip/nrf51/registers.h8
4 files changed, 99 insertions, 4 deletions
diff --git a/chip/nrf51/build.mk b/chip/nrf51/build.mk
index db64c6f618..88509bba3c 100644
--- a/chip/nrf51/build.mk
+++ b/chip/nrf51/build.mk
@@ -13,6 +13,7 @@ CFLAGS_CPU+=-march=armv6-m -mcpu=cortex-m0
chip-y+=gpio.o system.o uart.o
chip-y+=jtag.o watchdog.o ppi.o
+chip-$(CONFIG_BLUETOOTH_LE)+=radio.o
chip-$(CONFIG_COMMON_TIMER)+=hwtimer.o clock.o
chip-$(CONFIG_I2C)+=i2c.o
chip-$(HAS_TASK_KEYSCAN)+=keyboard_raw.o
diff --git a/chip/nrf51/radio.c b/chip/nrf51/radio.c
new file mode 100644
index 0000000000..af9d029a0d
--- /dev/null
+++ b/chip/nrf51/radio.c
@@ -0,0 +1,59 @@
+/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "radio.h"
+
+int radio_disable(void)
+{
+ int timeout = 10000;
+
+ NRF51_RADIO_DISABLED = 0;
+ NRF51_RADIO_DISABLE = 1;
+
+ while (!NRF51_RADIO_DISABLED && timeout > 0)
+ timeout--;
+
+ if (timeout == 0)
+ return EC_ERROR_TIMEOUT;
+
+ return EC_SUCCESS;
+}
+
+int radio_init(enum nrf51_radio_mode_t mode)
+{
+ int err_code = radio_disable();
+
+ if (mode == BLE_1MBIT) {
+ NRF51_RADIO_MODE = NRF51_RADIO_MODE_BLE_1MBIT;
+
+ NRF51_RADIO_TIFS = 150; /* Bluetooth 4.1 Vol 6 pg 58 4.1 */
+
+ /*
+ * BLE never sends or receives two packets in a row.
+ * Enabling the radio means we want to transmit or receive.
+ * After transmission, disable as quickly as possible.
+ */
+ NRF51_RADIO_SHORTS = NRF51_RADIO_SHORTS_READY_START |
+ NRF51_RADIO_SHORTS_END_DISABLE;
+
+ /* Use factory parameters if available */
+ if (!(NRF51_FICR_OVERRIDEEN & NRF51_FICR_OVERRIDEEN_BLE_BIT_N)
+ ) {
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ NRF51_RADIO_OVERRIDE(i) =
+ NRF51_FICR_BLE_1MBIT(i);
+ }
+ NRF51_RADIO_OVERRIDE(4) = NRF51_FICR_BLE_1MBIT(4) |
+ NRF51_RADIO_OVERRIDE_EN;
+ }
+ } else {
+ return EC_ERROR_UNIMPLEMENTED;
+ }
+
+ return err_code;
+}
+
diff --git a/chip/nrf51/radio.h b/chip/nrf51/radio.h
new file mode 100644
index 0000000000..43232202f2
--- /dev/null
+++ b/chip/nrf51/radio.h
@@ -0,0 +1,35 @@
+/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Radio interface for Chrome EC */
+
+#ifndef __NRF51_RADIO_H
+#define __NRF51_RADIO_H
+
+#include "common.h"
+#include "registers.h"
+
+#ifndef NRF51_RADIO_MAX_PAYLOAD
+ #define NRF51_RADIO_MAX_PAYLOAD 253
+#endif
+
+#define RADIO_DONE (NRF51_RADIO_END == 1)
+
+enum nrf51_radio_mode_t {
+ BLE_1MBIT = NRF51_RADIO_MODE_BLE_1MBIT,
+};
+
+struct nrf51_radio_packet_t {
+ uint8_t s0; /* First byte */
+ uint8_t length; /* Length field */
+ uint8_t s1; /* Bits after length */
+ uint8_t payload[NRF51_RADIO_MAX_PAYLOAD];
+} __packed;
+
+int radio_init(enum nrf51_radio_mode_t mode);
+
+int radio_disable(void);
+
+#endif /* __NRF51_RADIO_H */
diff --git a/chip/nrf51/registers.h b/chip/nrf51/registers.h
index ebf49b4a93..3f60828fa1 100644
--- a/chip/nrf51/registers.h
+++ b/chip/nrf51/registers.h
@@ -100,15 +100,15 @@
#define NRF51_FICR_IR(n) REG32(NRF51_FICR_BASE + 0x090 + ((n)*4))
#define NRF51_FICR_DEVICEADDRTYPE REG32(NRF51_FICR_BASE + 0x0A0)
#define NRF51_FICR_DEVICEADDR(n) REG32(NRF51_FICR_BASE + 0x0A4 + ((n)*4))
-#define NRF51_FICR_OVERRIDDEN REG32(NRF51_FICR_BASE + 0x0AC)
+#define NRF51_FICR_OVERRIDEEN REG32(NRF51_FICR_BASE + 0x0AC)
#define NRF51_FICR_BLE_1MBIT(n) REG32(NRF51_FICR_BASE + 0x0EC + ((n)*4))
/* DEVICEADDRTYPE */
#define NRF51_FICR_DEVICEADDRTYPE_RANDOM 1
-/* OVERRIDDEN */
-#define NRF51_FICR_OVERRIDDEN_NRF_BIT_N 1
-#define NRF51_FICR_OVERRIDDEN_BLE_BIT_N 8
+/* OVERRIDEEN */
+#define NRF51_FICR_OVERRIDEEN_NRF_BIT_N 1
+#define NRF51_FICR_OVERRIDEEN_BLE_BIT_N 8
/*
* UICR