[target][platform] Nordic nrf51xxx platform support and test projects
This commit is contained in:
committed by
Travis Geiselbrecht
parent
3d7e1f4968
commit
a619f2e9cd
64
platform/nrf51xxx/debug.c
Normal file
64
platform/nrf51xxx/debug.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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 <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 nrf51_debug_early_init(void)
|
||||
{
|
||||
uart_init_early();
|
||||
}
|
||||
|
||||
/* later in the init process */
|
||||
void nrf51_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;
|
||||
}
|
||||
|
||||
77
platform/nrf51xxx/gpio.c
Normal file
77
platform/nrf51xxx/gpio.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 <debug.h>
|
||||
#include <assert.h>
|
||||
#include <dev/gpio.h>
|
||||
#include <platform/nrf51.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_GPIO->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_GPIO->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_GPIO->OUTSET = 1 << nr;
|
||||
} else {
|
||||
NRF_GPIO->OUTCLR = 1 << nr;
|
||||
}
|
||||
}
|
||||
|
||||
int gpio_get(unsigned nr)
|
||||
{
|
||||
DEBUG_ASSERT( nr <= NRF_MAX_PIN_NUMBER );
|
||||
|
||||
if ( NRF_GPIO->IN & ( 1 << nr) ) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
29
platform/nrf51xxx/include/platform/gpio.h
Normal file
29
platform/nrf51xxx/include/platform/gpio.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __PLATFORM_NRF51_GPIO_H
|
||||
#define __PLATFORM_NRF51_GPIO_H
|
||||
|
||||
#define NRF_MAX_PIN_NUMBER 31
|
||||
|
||||
#endif
|
||||
37
platform/nrf51xxx/include/platform/nrf51.h
Normal file
37
platform/nrf51xxx/include/platform/nrf51.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef __PLATFORM_NRF51_H
|
||||
#define __PLATFORM_NRF51_H
|
||||
|
||||
#include <platform/nrf518xx.h>
|
||||
|
||||
void nrf51_debug_early_init(void);
|
||||
void nrf51_debug_init(void);
|
||||
void nrf51_timer_early_init(void);
|
||||
void nrf51_timer_init(void);
|
||||
void nrf51_gpio_early_init(void);
|
||||
void nrf51_flash_nor_early_init(void);
|
||||
void nrf51_flash_nor_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
1286
platform/nrf51xxx/include/platform/nrf518xx.h
Normal file
1286
platform/nrf51xxx/include/platform/nrf518xx.h
Normal file
File diff suppressed because it is too large
Load Diff
6878
platform/nrf51xxx/include/platform/nrf518xx_bitfields.h
Normal file
6878
platform/nrf51xxx/include/platform/nrf518xx_bitfields.h
Normal file
File diff suppressed because it is too large
Load Diff
29
platform/nrf51xxx/include/platform/platform_cm.h
Normal file
29
platform/nrf51xxx/include/platform/platform_cm.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef __PLATFORM_CM_H
|
||||
#define __PLATFORM_CM_H
|
||||
|
||||
#include <platform/nrf518xx.h>
|
||||
|
||||
#endif
|
||||
|
||||
69
platform/nrf51xxx/include/platform/system_nrf51.h
Normal file
69
platform/nrf51xxx/include/platform/system_nrf51.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Copyright (c) 2015, Nordic Semiconductor ASA
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SYSTEM_NRF51_H
|
||||
#define SYSTEM_NRF51_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
|
||||
|
||||
/**
|
||||
* Initialize the system
|
||||
*
|
||||
* @param none
|
||||
* @return none
|
||||
*
|
||||
* @brief Setup the microcontroller system.
|
||||
* Initialize the System and update the SystemCoreClock variable.
|
||||
*/
|
||||
extern void SystemInit (void);
|
||||
|
||||
/**
|
||||
* Update SystemCoreClock variable
|
||||
*
|
||||
* @param none
|
||||
* @return none
|
||||
*
|
||||
* @brief Updates the SystemCoreClock with current core Clock
|
||||
* retrieved from cpu registers.
|
||||
*/
|
||||
extern void SystemCoreClockUpdate (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SYSTEM_NRF51_H */
|
||||
58
platform/nrf51xxx/init.c
Normal file
58
platform/nrf51xxx/init.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 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 <err.h>
|
||||
#include <debug.h>
|
||||
#include <arch/arm/cm.h>
|
||||
#include <dev/uart.h>
|
||||
#include <platform.h>
|
||||
#include <platform/nrf51.h>
|
||||
#include <platform/system_nrf51.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 nrf51xxx 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, "\tRAM: %d blocks of %d bytes each (%dk bytes total)\n", \
|
||||
NRF_FICR->NUMRAMBLOCK, NRF_FICR->SIZERAMBLOCKS, \
|
||||
(NRF_FICR->NUMRAMBLOCK * NRF_FICR->SIZERAMBLOCKS)>>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);
|
||||
dprintf(SPEW, "\tHWID: 0x%04x\n",NRF_FICR->CONFIGID & 0x0000ffff);
|
||||
|
||||
}
|
||||
59
platform/nrf51xxx/rules.mk
Normal file
59
platform/nrf51xxx/rules.mk
Normal file
@@ -0,0 +1,59 @@
|
||||
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-m0
|
||||
|
||||
ifeq ($(NRF51_CHIP),nrf51822-qfaa)
|
||||
GLOBAL_DEFINES +=
|
||||
MEMSIZE ?= 16384
|
||||
endif
|
||||
ifeq ($(NRF51_CHIP),nrf51822-ceaa)
|
||||
GLOBAL_DEFINES +=
|
||||
MEMSIZE ?= 16384
|
||||
endif
|
||||
ifeq ($(NRF51_CHIP),nrf51822-qfab)
|
||||
GLOBAL_DEFINES +=
|
||||
MEMSIZE ?= 16384
|
||||
endif
|
||||
ifeq ($(NRF51_CHIP),nrf51822-cdab)
|
||||
GLOBAL_DEFINES +=
|
||||
MEMSIZE ?= 16384
|
||||
endif
|
||||
ifeq ($(NRF51_CHIP),nrf51822-qfac)
|
||||
GLOBAL_DEFINES +=
|
||||
MEMSIZE ?= 32768
|
||||
endif
|
||||
ifeq ($(NRF51_CHIP),nrf51822-cfac)
|
||||
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 \
|
||||
$(LOCAL_DIR)/system_nrf51.c
|
||||
|
||||
|
||||
LINKER_SCRIPT += \
|
||||
$(BUILDDIR)/system-twosegment.ld
|
||||
|
||||
MODULE_DEPS += \
|
||||
lib/cbuf
|
||||
|
||||
include make/module.mk
|
||||
121
platform/nrf51xxx/system_nrf51.c
Normal file
121
platform/nrf51xxx/system_nrf51.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/* Copyright (c) 2015, Nordic Semiconductor ASA
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: Template files (including this one) are application specific and therefore expected to
|
||||
be copied into the application project folder prior to its use! */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <platform/nrf51.h>
|
||||
#include <platform/system_nrf51.h>
|
||||
|
||||
/*lint ++flb "Enter library region" */
|
||||
|
||||
|
||||
#define __SYSTEM_CLOCK (16000000UL) /*!< nRF51 devices use a fixed System Clock Frequency of 16MHz */
|
||||
|
||||
static bool is_manual_peripheral_setup_needed(void);
|
||||
static bool is_disabled_in_debug_needed(void);
|
||||
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
|
||||
#elif defined ( __ICCARM__ )
|
||||
__root uint32_t SystemCoreClock = __SYSTEM_CLOCK;
|
||||
#elif defined ( __GNUC__ )
|
||||
uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
|
||||
#endif
|
||||
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
SystemCoreClock = __SYSTEM_CLOCK;
|
||||
}
|
||||
|
||||
void SystemInit(void)
|
||||
{
|
||||
/* If desired, switch off the unused RAM to lower consumption by the use of RAMON register.
|
||||
It can also be done in the application main() function. */
|
||||
|
||||
/* Prepare the peripherals for use as indicated by the PAN 26 "System: Manual setup is required
|
||||
to enable the use of peripherals" found at Product Anomaly document for your device found at
|
||||
https://www.nordicsemi.com/. The side effect of executing these instructions in the devices
|
||||
that do not need it is that the new peripherals in the second generation devices (LPCOMP for
|
||||
example) will not be available. */
|
||||
if (is_manual_peripheral_setup_needed())
|
||||
{
|
||||
*(uint32_t volatile *)0x40000504 = 0xC007FFDF;
|
||||
*(uint32_t volatile *)0x40006C18 = 0x00008000;
|
||||
}
|
||||
|
||||
/* Disable PROTENSET registers under debug, as indicated by PAN 59 "MPU: Reset value of DISABLEINDEBUG
|
||||
register is incorrect" found at Product Anomaly document four your device found at
|
||||
https://www.nordicsemi.com/. There is no side effect of using these instruction if not needed. */
|
||||
if (is_disabled_in_debug_needed())
|
||||
{
|
||||
NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool is_manual_peripheral_setup_needed(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x00) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x10) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool is_disabled_in_debug_needed(void)
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
|
||||
{
|
||||
if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*lint --flb "Leave library region" */
|
||||
104
platform/nrf51xxx/timer.c
Normal file
104
platform/nrf51xxx/timer.c
Normal file
@@ -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/nrf51.h>
|
||||
#include <platform/system_nrf51.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 nrf51_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;
|
||||
}
|
||||
|
||||
128
platform/nrf51xxx/uart.c
Normal file
128
platform/nrf51xxx/uart.c
Normal file
@@ -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(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 nrf51_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->TXD = c;
|
||||
NRF_UART0->EVENTS_TXDRDY = 0;
|
||||
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;
|
||||
}
|
||||
108
platform/nrf51xxx/vectab.c
Normal file
108
platform/nrf51xxx/vectab.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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/nrf51.h>
|
||||
#include <target/debugconfig.h>
|
||||
|
||||
/* un-overridden irq handler */
|
||||
void nrf51_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 nrf51_##x(void) __WEAK_ALIAS("nrf51_dummy_irq");
|
||||
|
||||
DEFAULT_HANDLER(POWER_CLOCK_IRQ);
|
||||
DEFAULT_HANDLER(RADIO_IRQ);
|
||||
DEFAULT_HANDLER(UART0_IRQ);
|
||||
DEFAULT_HANDLER(SPI0_TWI0_IRQ);
|
||||
DEFAULT_HANDLER(SPI1_TWI1_IRQ);
|
||||
|
||||
DEFAULT_HANDLER(RESERVED_IRQ);
|
||||
DEFAULT_HANDLER(GPIOTE_IRQ);
|
||||
DEFAULT_HANDLER(ADC_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(LPCOMP_IRQ);
|
||||
DEFAULT_HANDLER(SWI0_IRQ);
|
||||
|
||||
DEFAULT_HANDLER(SWI1_IRQ);
|
||||
DEFAULT_HANDLER(SWI2_IRQ);
|
||||
DEFAULT_HANDLER(SWI3_IRQ);
|
||||
DEFAULT_HANDLER(SWI4_IRQ);
|
||||
DEFAULT_HANDLER(SWI5_IRQ);
|
||||
|
||||
|
||||
#define VECTAB_ENTRY(x) [x##n] = nrf51_##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(UART0_IRQ),
|
||||
VECTAB_ENTRY(SPI0_TWI0_IRQ),
|
||||
VECTAB_ENTRY(SPI1_TWI1_IRQ),
|
||||
VECTAB_ENTRY(RESERVED_IRQ),
|
||||
VECTAB_ENTRY(GPIOTE_IRQ),
|
||||
VECTAB_ENTRY(ADC_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(LPCOMP_IRQ),
|
||||
VECTAB_ENTRY(SWI0_IRQ),
|
||||
|
||||
VECTAB_ENTRY(SWI1_IRQ),
|
||||
VECTAB_ENTRY(SWI2_IRQ),
|
||||
VECTAB_ENTRY(SWI3_IRQ),
|
||||
VECTAB_ENTRY(SWI4_IRQ),
|
||||
VECTAB_ENTRY(SWI5_IRQ),
|
||||
};
|
||||
|
||||
7
project/nrf51-pca10000-test.mk
Normal file
7
project/nrf51-pca10000-test.mk
Normal file
@@ -0,0 +1,7 @@
|
||||
MODULES += \
|
||||
app/shell \
|
||||
|
||||
|
||||
|
||||
|
||||
include project/target/nrf-pca10000.mk
|
||||
8
project/nrf51-pca10028-test.mk
Normal file
8
project/nrf51-pca10028-test.mk
Normal file
@@ -0,0 +1,8 @@
|
||||
MODULES += \
|
||||
app/shell \
|
||||
app/tests \
|
||||
|
||||
|
||||
|
||||
|
||||
include project/target/nrf-pca10028.mk
|
||||
3
project/target/nrf-pca10000.mk
Normal file
3
project/target/nrf-pca10000.mk
Normal file
@@ -0,0 +1,3 @@
|
||||
LOCAL_DIR := $(GET_LOCAL_DIR)
|
||||
|
||||
TARGET := nrf-pca10000
|
||||
3
project/target/nrf-pca10028.mk
Normal file
3
project/target/nrf-pca10028.mk
Normal file
@@ -0,0 +1,3 @@
|
||||
LOCAL_DIR := $(GET_LOCAL_DIR)
|
||||
|
||||
TARGET := nrf-pca10028
|
||||
28
target/nrf-pca10000/include/target/debugconfig.h
Normal file
28
target/nrf-pca10000/include/target/debugconfig.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef __TARGET_DEBUGCONFIG_H
|
||||
#define __TARGET_DEBUGCONFIG_H
|
||||
|
||||
#define DEBUG_UART 1
|
||||
|
||||
#endif
|
||||
38
target/nrf-pca10000/include/target/gpioconfig.h
Normal file
38
target/nrf-pca10000/include/target/gpioconfig.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef __TARGET_GPIOCONFIG_H
|
||||
#define __TARGET_GPIOCONFIG_H
|
||||
|
||||
#include <platform/gpio.h>
|
||||
|
||||
#define GPIO_LED1 21
|
||||
#define GPIO_LED2 22
|
||||
#define GPIO_LED3 23
|
||||
|
||||
#define UART0_RTS_PIN 8
|
||||
#define UART0_TX_PIN 9
|
||||
#define UART0_RX_PIN 11
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
79
target/nrf-pca10000/init.c
Normal file
79
target/nrf-pca10000/init.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 <err.h>
|
||||
#include <debug.h>
|
||||
#include <target.h>
|
||||
#include <compiler.h>
|
||||
#include <dev/gpio.h>
|
||||
#include <kernel/timer.h>
|
||||
#include <platform/gpio.h>
|
||||
#include <platform/nrf51.h>
|
||||
#include <target/gpioconfig.h>
|
||||
|
||||
|
||||
static timer_t blinktimer;
|
||||
static bool heartbeat = false;
|
||||
|
||||
void target_early_init(void)
|
||||
{
|
||||
NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_16MHz;
|
||||
|
||||
/* configure the usart1 pins */
|
||||
gpio_config(GPIO_LED1, GPIO_OUTPUT);
|
||||
gpio_config(GPIO_LED2, GPIO_OUTPUT);
|
||||
gpio_config(GPIO_LED3, GPIO_OUTPUT);
|
||||
|
||||
gpio_set(GPIO_LED1,1);
|
||||
gpio_set(GPIO_LED2,1);
|
||||
gpio_set(GPIO_LED3,1);
|
||||
|
||||
gpio_config(UART0_RTS_PIN, GPIO_OUTPUT);
|
||||
gpio_set(UART0_RTS_PIN,0); //placate flow control requirements of pca10000
|
||||
|
||||
nrf51_debug_early_init();
|
||||
}
|
||||
|
||||
static enum handler_return blinker(timer_t * timer, lk_time_t now, void * args){
|
||||
|
||||
if (heartbeat) {
|
||||
heartbeat = false;
|
||||
gpio_set(GPIO_LED1,1); //turn off led
|
||||
timer_set_oneshot(timer,950, blinker, NULL);
|
||||
} else {
|
||||
heartbeat = true;
|
||||
gpio_set(GPIO_LED1,0);
|
||||
timer_set_oneshot(timer,50, blinker, NULL);
|
||||
}
|
||||
return INT_RESCHEDULE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void target_init(void)
|
||||
{
|
||||
nrf51_debug_init();
|
||||
dprintf(SPEW,"Target: PCA10000 DK...\n");
|
||||
timer_initialize(&blinktimer);
|
||||
timer_set_oneshot(&blinktimer, 1000, blinker, NULL);
|
||||
}
|
||||
17
target/nrf-pca10000/rules.mk
Normal file
17
target/nrf-pca10000/rules.mk
Normal file
@@ -0,0 +1,17 @@
|
||||
LOCAL_DIR := $(GET_LOCAL_DIR)
|
||||
|
||||
MODULE := $(LOCAL_DIR)
|
||||
|
||||
NRF51_CHIP := nrf51822-qfaa
|
||||
|
||||
PLATFORM := nrf51xxx
|
||||
|
||||
GLOBAL_DEFINES += \
|
||||
ENABLE_UART0=1 \
|
||||
|
||||
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/init.c
|
||||
|
||||
include make/module.mk
|
||||
|
||||
28
target/nrf-pca10028/include/target/debugconfig.h
Normal file
28
target/nrf-pca10028/include/target/debugconfig.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef __TARGET_DEBUGCONFIG_H
|
||||
#define __TARGET_DEBUGCONFIG_H
|
||||
|
||||
#define DEBUG_UART 1
|
||||
|
||||
#endif
|
||||
38
target/nrf-pca10028/include/target/gpioconfig.h
Normal file
38
target/nrf-pca10028/include/target/gpioconfig.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef __TARGET_GPIOCONFIG_H
|
||||
#define __TARGET_GPIOCONFIG_H
|
||||
|
||||
#include <platform/gpio.h>
|
||||
|
||||
#define GPIO_LED1 21
|
||||
#define GPIO_LED2 22
|
||||
#define GPIO_LED3 23
|
||||
#define GPIO_LED4 24
|
||||
|
||||
#define UART0_TX_PIN 9
|
||||
#define UART0_RX_PIN 11
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
53
target/nrf-pca10028/init.c
Normal file
53
target/nrf-pca10028/init.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 <err.h>
|
||||
#include <debug.h>
|
||||
#include <target.h>
|
||||
#include <compiler.h>
|
||||
#include <dev/gpio.h>
|
||||
#include <platform/gpio.h>
|
||||
#include <platform/nrf51.h>
|
||||
#include <target/gpioconfig.h>
|
||||
|
||||
void target_early_init(void)
|
||||
{
|
||||
/* configure the usart1 pins */
|
||||
gpio_config(GPIO_LED1, GPIO_OUTPUT);
|
||||
gpio_config(GPIO_LED2, GPIO_OUTPUT);
|
||||
gpio_config(GPIO_LED3, GPIO_OUTPUT);
|
||||
gpio_config(GPIO_LED4, GPIO_OUTPUT);
|
||||
|
||||
gpio_set(GPIO_LED1,1);
|
||||
gpio_set(GPIO_LED2,1);
|
||||
gpio_set(GPIO_LED3,0);
|
||||
gpio_set(GPIO_LED4,0);
|
||||
|
||||
nrf51_debug_early_init();
|
||||
}
|
||||
|
||||
|
||||
void target_init(void)
|
||||
{
|
||||
nrf51_debug_init();
|
||||
dprintf(SPEW,"Target: PCA10028 DK...\n");
|
||||
}
|
||||
17
target/nrf-pca10028/rules.mk
Normal file
17
target/nrf-pca10028/rules.mk
Normal file
@@ -0,0 +1,17 @@
|
||||
LOCAL_DIR := $(GET_LOCAL_DIR)
|
||||
|
||||
MODULE := $(LOCAL_DIR)
|
||||
|
||||
NRF51_CHIP := nrf51822-qfac
|
||||
|
||||
PLATFORM := nrf51xxx
|
||||
|
||||
GLOBAL_DEFINES += \
|
||||
ENABLE_UART0=1 \
|
||||
|
||||
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/init.c
|
||||
|
||||
include make/module.mk
|
||||
|
||||
Reference in New Issue
Block a user