aboutsummaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorTravis Geiselbrecht <geist@foobox.com>2016-06-21 09:39:19 -0700
committerGitHub <noreply@github.com>2016-06-21 09:39:19 -0700
commit10bb61326be2639cdd3dd2e265f31b62062f19c4 (patch)
tree0426f1c70d091e9a09b01bd73dd072744756ecd0 /platform
parent6e4e6f40e817f504da556e25c515a40e65d20bd4 (diff)
parent6388cde233702124773edab0fdbbdc9ed87dff5e (diff)
downloadcommon-10bb61326be2639cdd3dd2e265f31b62062f19c4.tar.gz
Merge pull request #146 from littlekernel/pr/nrf52
Pr/nrf52
Diffstat (limited to 'platform')
-rw-r--r--platform/nrf52xxx/debug.c64
-rw-r--r--platform/nrf52xxx/gpio.c77
-rw-r--r--platform/nrf52xxx/include/platform/gpio.h29
-rw-r--r--platform/nrf52xxx/include/platform/nrf52.h37
-rw-r--r--platform/nrf52xxx/include/platform/platform_cm.h29
-rw-r--r--platform/nrf52xxx/init.c53
-rw-r--r--platform/nrf52xxx/rules.mk50
-rw-r--r--platform/nrf52xxx/timer.c104
-rw-r--r--platform/nrf52xxx/uart.c128
-rw-r--r--platform/nrf52xxx/vectab.c123
10 files changed, 694 insertions, 0 deletions
diff --git a/platform/nrf52xxx/debug.c b/platform/nrf52xxx/debug.c
new file mode 100644
index 00000000..da443746
--- /dev/null
+++ b/platform/nrf52xxx/debug.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2016 Eric Holland
+ *
+ * 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 <stdarg.h>
+#include <reg.h>
+#include <debug.h>
+#include <stdio.h>
+#include <kernel/thread.h>
+#include <dev/uart.h>
+#include <arch/ops.h>
+#include <arch/arm/cm.h>
+#include <platform/debug.h>
+#include <target/debugconfig.h>
+
+
+
+void nrf52_debug_early_init(void)
+{
+ uart_init_early();
+}
+
+/* later in the init process */
+void nrf52_debug_init(void)
+{
+ uart_init();
+}
+
+
+
+void platform_dputc(char c)
+{
+ if (c == '\n')
+ uart_putc(DEBUG_UART, '\r');
+ uart_putc(DEBUG_UART, c);
+}
+
+int platform_dgetc(char *c, bool wait)
+{
+ int ret = uart_getc(DEBUG_UART, wait);
+ if (ret == -1)
+ return -1;
+ *c = ret;
+ return 0;
+}
+
diff --git a/platform/nrf52xxx/gpio.c b/platform/nrf52xxx/gpio.c
new file mode 100644
index 00000000..55a6e2ee
--- /dev/null
+++ b/platform/nrf52xxx/gpio.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2016 Eric Holland
+ *
+ * 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 <debug.h>
+#include <assert.h>
+#include <dev/gpio.h>
+#include <platform/nrf52.h>
+#include <platform/gpio.h>
+
+int gpio_config(unsigned nr, unsigned flags)
+{
+ DEBUG_ASSERT(nr <= NRF_MAX_PIN_NUMBER);
+
+ unsigned init;
+
+ if (flags & GPIO_OUTPUT) {
+
+ NRF_P0->PIN_CNF[nr] = GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos | \
+ GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos | \
+ GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos | \
+ GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos;
+ } else { // GPIO_INPUT
+ if (flags & GPIO_PULLUP) {
+ init = GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos;
+ } else if (flags & GPIO_PULLDOWN) {
+ init = GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos;
+ } else {
+ init = GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos;
+ }
+ NRF_P0->PIN_CNF[nr] = GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos | \
+ GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos | \
+ init;
+ }
+ return 0;
+}
+
+void gpio_set(unsigned nr, unsigned on)
+{
+ DEBUG_ASSERT(nr <= NRF_MAX_PIN_NUMBER);
+
+ if (on > 0) {
+ NRF_P0->OUTSET = 1 << nr;
+ } else {
+ NRF_P0->OUTCLR = 1 << nr;
+ }
+}
+
+int gpio_get(unsigned nr)
+{
+ DEBUG_ASSERT( nr <= NRF_MAX_PIN_NUMBER );
+
+ if ( NRF_P0->IN & ( 1 << nr) ) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
diff --git a/platform/nrf52xxx/include/platform/gpio.h b/platform/nrf52xxx/include/platform/gpio.h
new file mode 100644
index 00000000..43e68974
--- /dev/null
+++ b/platform/nrf52xxx/include/platform/gpio.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2016 Eric Holland
+ *
+ * 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.
+ */
+
+#ifndef __PLATFORM_NRF52_GPIO_H
+#define __PLATFORM_NRF52_GPIO_H
+
+#define NRF_MAX_PIN_NUMBER 31
+
+#endif
diff --git a/platform/nrf52xxx/include/platform/nrf52.h b/platform/nrf52xxx/include/platform/nrf52.h
new file mode 100644
index 00000000..afb0e7ff
--- /dev/null
+++ b/platform/nrf52xxx/include/platform/nrf52.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016 Eric Holland
+ *
+ * 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.
+ */
+#ifndef __PLATFORM_NRF52_H
+#define __PLATFORM_NRF52_H
+
+#include <platform/nrf52xxx.h>
+
+void nrf52_debug_early_init(void);
+void nrf52_debug_init(void);
+void nrf52_timer_early_init(void);
+void nrf52_timer_init(void);
+void nrf52_gpio_early_init(void);
+void nrf52_flash_nor_early_init(void);
+void nrf52_flash_nor_init(void);
+
+#endif
+
diff --git a/platform/nrf52xxx/include/platform/platform_cm.h b/platform/nrf52xxx/include/platform/platform_cm.h
new file mode 100644
index 00000000..1cb665e0
--- /dev/null
+++ b/platform/nrf52xxx/include/platform/platform_cm.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2016 Eric Holland
+ *
+ * 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.
+ */
+#ifndef __PLATFORM_CM_H
+#define __PLATFORM_CM_H
+
+#include <platform/nrf52xxx.h>
+
+#endif
+
diff --git a/platform/nrf52xxx/init.c b/platform/nrf52xxx/init.c
new file mode 100644
index 00000000..c0a631e2
--- /dev/null
+++ b/platform/nrf52xxx/init.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2016 Eric Holland
+ *
+ * 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 <err.h>
+#include <debug.h>
+#include <arch/arm/cm.h>
+#include <dev/uart.h>
+#include <platform.h>
+#include <platform/nrf52.h>
+#include <platform/system_nrf52.h>
+
+
+
+void platform_early_init(void)
+{
+ // Crank up the clock before initing timers.
+ SystemInit();
+ arm_cm_systick_init(32768);
+}
+
+void platform_init(void)
+{
+ dprintf(SPEW, "Nordic nrf52xxx platform for lk...\n");
+ dprintf(SPEW, "\tFlash: %d pages of %d bytes each (%dk bytes total)\n", \
+ NRF_FICR->CODESIZE, NRF_FICR->CODEPAGESIZE, \
+ (NRF_FICR->CODESIZE * NRF_FICR->CODEPAGESIZE)>>10);
+ dprintf(SPEW, "\tRadio MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", \
+ (NRF_FICR->DEVICEADDR[1] >> 8) & 0xFF, \
+ (NRF_FICR->DEVICEADDR[1]) & 0xFF, \
+ (NRF_FICR->DEVICEADDR[0] >> 24) & 0xFF, \
+ (NRF_FICR->DEVICEADDR[0] >> 16) & 0xFF, \
+ (NRF_FICR->DEVICEADDR[0] >> 8) & 0xFF, \
+ (NRF_FICR->DEVICEADDR[0] >> 0) & 0xFF);
+}
diff --git a/platform/nrf52xxx/rules.mk b/platform/nrf52xxx/rules.mk
new file mode 100644
index 00000000..618c689a
--- /dev/null
+++ b/platform/nrf52xxx/rules.mk
@@ -0,0 +1,50 @@
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+# ROMBASE, MEMBASE, and MEMSIZE are required for the linker script
+ROMBASE := 0x0
+MEMBASE := 0x20000000
+# can be overridden by target
+
+ARCH := arm
+ARM_CPU := cortex-m4
+
+ifeq ($(NRF52_CHIP),nrf52832-qfaa)
+GLOBAL_DEFINES +=
+MEMSIZE ?= 65536
+endif
+ifeq ($(NRF52_CHIP),nrf52832-qfab)
+GLOBAL_DEFINES +=
+MEMSIZE ?= 32768
+endif
+ifeq ($(NRF52_CHIP),nrf52832-chaa)
+GLOBAL_DEFINES +=
+MEMSIZE ?= 65536
+endif
+ifeq ($(NRF52_CHIP),nrf52832-chab)
+GLOBAL_DEFINES +=
+MEMSIZE ?= 32768
+endif
+
+GLOBAL_INCLUDES += $(LOCAL_DIR)
+
+GLOBAL_DEFINES += \
+ MEMSIZE=$(MEMSIZE)
+
+MODULE_SRCS += \
+ $(LOCAL_DIR)/init.c \
+ $(LOCAL_DIR)/debug.c \
+ $(LOCAL_DIR)/uart.c \
+ $(LOCAL_DIR)/vectab.c \
+ $(LOCAL_DIR)/gpio.c \
+ $(LOCAL_DIR)/timer.c \
+
+LINKER_SCRIPT += \
+ $(BUILDDIR)/system-twosegment.ld
+
+MODULE_DEPS += \
+ platform/nrf52 \
+ lib/cbuf
+
+include make/module.mk
diff --git a/platform/nrf52xxx/timer.c b/platform/nrf52xxx/timer.c
new file mode 100644
index 00000000..5603a294
--- /dev/null
+++ b/platform/nrf52xxx/timer.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2015 Eric Holland
+ *
+ * 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 <err.h>
+#include <debug.h>
+#include <trace.h>
+#include <arch/arm/cm.h>
+#include <platform.h>
+#include <platform/nrf52.h>
+#include <platform/system_nrf52.h>
+#include <platform/timer.h>
+#include <sys/types.h>
+
+
+static volatile uint64_t ticks;
+static uint32_t tick_rate = 0;
+static uint32_t tick_rate_mhz = 0;
+static lk_time_t tick_interval_ms;
+
+static platform_timer_callback cb;
+static void *cb_args;
+
+typedef enum handler_return (*platform_timer_callback)(void *arg, lk_time_t now);
+
+status_t platform_set_periodic_timer(platform_timer_callback callback, void *arg, lk_time_t interval)
+{
+
+ cb = callback;
+ cb_args = arg;
+
+ tick_interval_ms = interval;
+
+ uint32_t ticks = tick_rate / ( 1000 / interval );
+
+ NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos;
+ NRF_CLOCK->TASKS_LFCLKSTART = 1;
+
+ NRF_RTC1->PRESCALER = ticks;
+ NRF_RTC1->INTENSET = RTC_INTENSET_TICK_Enabled << RTC_INTENSET_TICK_Pos;
+
+ NRF_RTC1->EVENTS_TICK = 0;
+ NRF_RTC1->TASKS_START = 1;
+ NVIC_EnableIRQ(RTC1_IRQn);
+
+ return NO_ERROR;
+}
+
+lk_time_t current_time(void)
+{
+ uint64_t t;
+
+ do {
+ t = ticks;
+ } while (ticks != t);
+
+ return t * tick_interval_ms;
+}
+
+lk_bigtime_t current_time_hires(void)
+{
+ return current_time() * 1000;
+}
+
+void nrf52_RTC1_IRQ(void)
+{
+ ticks++;
+ arm_cm_irq_entry();
+
+ NRF_RTC1->EVENTS_TICK = 0;
+
+ bool resched = false;
+ if (cb) {
+ lk_time_t now = current_time();
+ if (cb(cb_args, now) == INT_RESCHEDULE)
+ resched = true;
+ }
+ arm_cm_irq_exit(resched);
+}
+
+void arm_cm_systick_init(uint32_t mhz)
+{
+ tick_rate = mhz;
+ tick_rate_mhz = mhz / 1000000;
+}
+
diff --git a/platform/nrf52xxx/uart.c b/platform/nrf52xxx/uart.c
new file mode 100644
index 00000000..8e1f1d9d
--- /dev/null
+++ b/platform/nrf52xxx/uart.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2015 Eric Holland
+ *
+ * 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 <stdarg.h>
+#include <reg.h>
+#include <debug.h>
+#include <stdio.h>
+#include <assert.h>
+#include <err.h>
+#include <lib/cbuf.h>
+#include <arch/arm/cm.h>
+#include <arch/ops.h>
+#include <dev/uart.h>
+#include <dev/gpio.h>
+#include <kernel/thread.h>
+#include <platform/debug.h>
+#include <platform/gpio.h>
+#include <target/debugconfig.h>
+#include <target/gpioconfig.h>
+
+#define RXBUF_SIZE 16
+
+//cbuf_t uart0_rx_buf;
+
+
+
+void uart_init_early(void)
+{
+#ifdef ENABLE_UART0
+
+#ifdef UART0_TX_PIN
+ gpio_config(UART0_TX_PIN,GPIO_OUTPUT);
+ NRF_UART0->PSELTXD = UART0_TX_PIN;
+#endif
+#ifdef UART0_RX_PIN
+ gpio_config(UART0_RX_PIN,GPIO_INPUT);
+ NRF_UART0->PSELRXD = UART0_RX_PIN;
+#endif
+
+ NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud115200 << UART_BAUDRATE_BAUDRATE_Pos;
+ NRF_UART0->CONFIG = UART_CONFIG_HWFC_Disabled << UART_CONFIG_HWFC_Pos | \
+ UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos;
+ NVIC_DisableIRQ(UARTE0_UART0_IRQn);
+ NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos;
+ NRF_UART0->TXD = 'E';
+ NRF_UART0->TASKS_STARTTX=1;
+ NRF_UART0->TASKS_STARTRX=1;
+#endif //ENABLE_UART0
+}
+
+void uart_init(void)
+{
+#ifdef ENABLE_UART0
+// cbuf_initialize(&uart0_rx_buf, RXBUF_SIZE);
+// NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos;
+ NRF_UART0->EVENTS_RXDRDY = 0;
+// NVIC_EnableIRQ(UART0_IRQn);
+ char c = NRF_UART0->RXD;
+ (void)c;
+#endif //ENABLE_UART0
+}
+
+void nrf52_UARTE0_UART0_IRQ(void)
+{
+// char c;
+ arm_cm_irq_entry();
+ /*
+ bool resched = false;
+ while ( NRF_UART0->EVENTS_RXDRDY > 0 ) {
+ NRF_UART0->EVENTS_RXDRDY = 0;
+ c = NRF_UART0->RXD;
+ if (!cbuf_space_avail(&uart0_rx_buf)) {
+ break;
+ }
+ cbuf_write_char(&uart0_rx_buf, c, false);
+ resched = true;
+ }
+ */
+ arm_cm_irq_exit(false);
+}
+
+int uart_putc(int port, char c)
+{
+ while (NRF_UART0->EVENTS_TXDRDY == 0);
+ NRF_UART0->EVENTS_TXDRDY = 0;
+ NRF_UART0->TXD = c;
+ return 1;
+}
+
+int uart_getc(int port, bool wait)
+{
+ do {
+ if (NRF_UART0->EVENTS_RXDRDY > 0) {
+ NRF_UART0->EVENTS_RXDRDY=0;
+ return NRF_UART0->RXD;
+ }
+ } while (wait);
+ return -1;
+}
+
+void uart_flush_tx(int port) {}
+
+void uart_flush_rx(int port) {}
+
+void uart_init_port(int port, uint baud)
+{
+ // TODO - later
+ PANIC_UNIMPLEMENTED;
+}
diff --git a/platform/nrf52xxx/vectab.c b/platform/nrf52xxx/vectab.c
new file mode 100644
index 00000000..4594b51b
--- /dev/null
+++ b/platform/nrf52xxx/vectab.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2012 Travis Geiselbrecht
+ *
+ * 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 <debug.h>
+#include <compiler.h>
+#include <arch/arm/cm.h>
+#include <lib/cbuf.h>
+#include <platform/nrf52.h>
+#include <target/debugconfig.h>
+
+/* un-overridden irq handler */
+void nrf52_dummy_irq(void)
+{
+ arm_cm_irq_entry();
+ panic("unhandled irq\n");
+}
+
+/* a list of default handlers that are simply aliases to the dummy handler */
+#define DEFAULT_HANDLER(x) \
+void nrf52_##x(void) __WEAK_ALIAS("nrf52_dummy_irq");
+
+DEFAULT_HANDLER(POWER_CLOCK_IRQ);
+DEFAULT_HANDLER(RADIO_IRQ);
+DEFAULT_HANDLER(UARTE0_UART0_IRQ);
+DEFAULT_HANDLER(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQ);
+DEFAULT_HANDLER(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQ);
+DEFAULT_HANDLER(NFCT_IRQ);
+DEFAULT_HANDLER(GPIOTE_IRQ);
+DEFAULT_HANDLER(SAADC_IRQ);
+DEFAULT_HANDLER(TIMER0_IRQ);
+DEFAULT_HANDLER(TIMER1_IRQ);
+DEFAULT_HANDLER(TIMER2_IRQ);
+DEFAULT_HANDLER(RTC0_IRQ);
+DEFAULT_HANDLER(TEMP_IRQ);
+DEFAULT_HANDLER(RNG_IRQ);
+DEFAULT_HANDLER(ECB_IRQ);
+DEFAULT_HANDLER(CCM_AAR_IRQ);
+DEFAULT_HANDLER(WDT_IRQ);
+DEFAULT_HANDLER(RTC1_IRQ);
+DEFAULT_HANDLER(QDEC_IRQ);
+DEFAULT_HANDLER(COMP_LPCOMP_IRQ);
+DEFAULT_HANDLER(SWI0_EGU0_IRQ);
+DEFAULT_HANDLER(SWI1_EGU1_IRQ);
+DEFAULT_HANDLER(SWI2_EGU2_IRQ);
+DEFAULT_HANDLER(SWI3_EGU3_IRQ);
+DEFAULT_HANDLER(SWI4_EGU4_IRQ);
+DEFAULT_HANDLER(SWI5_EGU5_IRQ);
+DEFAULT_HANDLER(TIMER3_IRQ);
+DEFAULT_HANDLER(TIMER4_IRQ);
+DEFAULT_HANDLER(PWM0_IRQ);
+DEFAULT_HANDLER(PDM_IRQ);
+DEFAULT_HANDLER(MWU_IRQ);
+DEFAULT_HANDLER(PWM1_IRQ);
+DEFAULT_HANDLER(PWM2_IRQ);
+DEFAULT_HANDLER(SPIM2_SPIS2_SPI2_IRQ);
+DEFAULT_HANDLER(RTC2_IRQ);
+DEFAULT_HANDLER(I2S_IRQ);
+DEFAULT_HANDLER(FPU_IRQ);
+
+
+#define VECTAB_ENTRY(x) [x##n] = nrf52_##x
+
+/* appended to the end of the main vector table */
+const void *const __SECTION(".text.boot.vectab2") vectab2[] = {
+
+ VECTAB_ENTRY(POWER_CLOCK_IRQ),
+ VECTAB_ENTRY(RADIO_IRQ),
+ VECTAB_ENTRY(UARTE0_UART0_IRQ),
+ VECTAB_ENTRY(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQ),
+ VECTAB_ENTRY(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQ),
+ VECTAB_ENTRY(NFCT_IRQ),
+ VECTAB_ENTRY(GPIOTE_IRQ),
+ VECTAB_ENTRY(SAADC_IRQ),
+ VECTAB_ENTRY(TIMER0_IRQ),
+ VECTAB_ENTRY(TIMER1_IRQ),
+ VECTAB_ENTRY(TIMER2_IRQ),
+ VECTAB_ENTRY(RTC0_IRQ),
+ VECTAB_ENTRY(TEMP_IRQ),
+ VECTAB_ENTRY(RNG_IRQ),
+ VECTAB_ENTRY(ECB_IRQ),
+ VECTAB_ENTRY(CCM_AAR_IRQ),
+ VECTAB_ENTRY(WDT_IRQ),
+ VECTAB_ENTRY(RTC1_IRQ),
+ VECTAB_ENTRY(QDEC_IRQ),
+ VECTAB_ENTRY(COMP_LPCOMP_IRQ),
+ VECTAB_ENTRY(SWI0_EGU0_IRQ),
+ VECTAB_ENTRY(SWI1_EGU1_IRQ),
+ VECTAB_ENTRY(SWI2_EGU2_IRQ),
+ VECTAB_ENTRY(SWI3_EGU3_IRQ),
+ VECTAB_ENTRY(SWI4_EGU4_IRQ),
+ VECTAB_ENTRY(SWI5_EGU5_IRQ),
+ VECTAB_ENTRY(TIMER3_IRQ),
+ VECTAB_ENTRY(TIMER4_IRQ),
+ VECTAB_ENTRY(PWM0_IRQ),
+ VECTAB_ENTRY(PDM_IRQ),
+ VECTAB_ENTRY(MWU_IRQ),
+ VECTAB_ENTRY(PWM1_IRQ),
+ VECTAB_ENTRY(PWM2_IRQ),
+ VECTAB_ENTRY(SPIM2_SPIS2_SPI2_IRQ),
+ VECTAB_ENTRY(RTC2_IRQ),
+ VECTAB_ENTRY(I2S_IRQ),
+ VECTAB_ENTRY(FPU_IRQ),
+};
+