diff --git a/Makefile b/Makefile index 2e6218a..c80fc6c 100644 --- a/Makefile +++ b/Makefile @@ -3,55 +3,61 @@ TARGETS := nrf51822_xxaa OUTPUT_DIRECTORY := _build SDK_ROOT := $(PWD)/../../nRF_SDK/nRF5_SDK_12.3.0_d7731ad -PROJ_DIR := ./ +PROJ_DIR := $(PWD) $(OUTPUT_DIRECTORY)/nrf51822_xxaa.out: \ - LINKER_SCRIPT := uart_gcc_nrf51.ld + LINKER_SCRIPT := nrf51_xxaa.ld # Source files common to all targets SRC_FILES += \ - $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \ - $(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \ - $(SDK_ROOT)/components/libraries/util/app_error.c \ - $(SDK_ROOT)/components/libraries/util/app_error_weak.c \ - $(SDK_ROOT)/components/libraries/fifo/app_fifo.c \ - $(SDK_ROOT)/components/libraries/uart/app_uart_fifo.c \ - $(SDK_ROOT)/components/libraries/util/app_util_platform.c \ - $(SDK_ROOT)/components/libraries/util/nrf_assert.c \ - $(SDK_ROOT)/components/libraries/uart/retarget.c \ - $(SDK_ROOT)/components/libraries/util/sdk_errors.c \ - $(SDK_ROOT)/components/boards/boards.c \ - $(SDK_ROOT)/components/drivers_nrf/common/nrf_drv_common.c \ - $(SDK_ROOT)/components/drivers_nrf/uart/nrf_drv_uart.c \ $(PROJ_DIR)/main.c \ - $(SDK_ROOT)/external/segger_rtt/RTT_Syscalls_GCC.c \ - $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \ - $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \ $(SDK_ROOT)/components/toolchain/gcc/gcc_startup_nrf51.S \ $(SDK_ROOT)/components/toolchain/system_nrf51.c \ + $(SDK_ROOT)/components/boards/boards.c \ + $(SDK_ROOT)/components/drivers_nrf/clock/nrf_drv_clock.c \ + $(SDK_ROOT)/components/drivers_nrf/power/nrf_drv_power.c \ + $(SDK_ROOT)/components/drivers_nrf/common/nrf_drv_common.c \ + $(SDK_ROOT)/components/drivers_nrf/uart/nrf_drv_uart.c \ + $(SDK_ROOT)/components/libraries/util/app_error.c \ + $(SDK_ROOT)/components/libraries/util/nrf_assert.c \ + $(SDK_ROOT)/components/libraries/util/app_error_weak.c \ + $(SDK_ROOT)/components/libraries/util/app_util_platform.c \ + $(SDK_ROOT)/components/libraries/util/sdk_errors.c \ + $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \ + $(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \ + $(SDK_ROOT)/external/freertos/source/tasks.c \ + $(SDK_ROOT)/external/freertos/source/list.c \ + $(SDK_ROOT)/external/freertos/source/timers.c \ + $(SDK_ROOT)/external/freertos/source/queue.c \ + $(SDK_ROOT)/external/freertos/source/portable/MemMang/heap_4.c \ + $(SDK_ROOT)/external/freertos/portable/GCC/nrf51/port.c \ + $(SDK_ROOT)/external/freertos/portable/CMSIS/nrf51/port_cmsis.c \ + $(SDK_ROOT)/external/freertos/portable/CMSIS/nrf51/port_cmsis_systick.c # Include folders common to all targets INC_FOLDERS += \ - $(SDK_ROOT)/components \ - $(SDK_ROOT)/components/libraries/util \ - $(SDK_ROOT)/components/toolchain/gcc \ - $(SDK_ROOT)/components/drivers_nrf/uart \ - config \ - $(SDK_ROOT)/external/segger_rtt \ - $(SDK_ROOT)/components/drivers_nrf/common \ $(PROJ_DIR) \ - $(SDK_ROOT)/components/libraries/fifo \ - $(SDK_ROOT)/components/libraries/bsp \ - $(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \ - $(SDK_ROOT)/components/toolchain \ - $(SDK_ROOT)/components/libraries/uart \ - $(SDK_ROOT)/components/device \ - $(SDK_ROOT)/components/libraries/log \ + $(PROJ_DIR)/config \ + $(SDK_ROOT)/components \ $(SDK_ROOT)/components/boards \ - $(SDK_ROOT)/components/drivers_nrf/delay \ - $(SDK_ROOT)/components/toolchain/cmsis/include \ + $(SDK_ROOT)/components/device \ + $(SDK_ROOT)/components/drivers_nrf/common \ $(SDK_ROOT)/components/drivers_nrf/hal \ + $(SDK_ROOT)/components/drivers_nrf/clock \ + $(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \ + $(SDK_ROOT)/components/drivers_nrf/gpiote \ + $(SDK_ROOT)/components/drivers_nrf/uart \ + $(SDK_ROOT)/components/libraries/bsp \ + $(SDK_ROOT)/components/libraries/button \ + $(SDK_ROOT)/components/libraries/util \ + $(SDK_ROOT)/components/libraries/log \ $(SDK_ROOT)/components/libraries/log/src \ + $(SDK_ROOT)/components/toolchain \ + $(SDK_ROOT)/components/toolchain/cmsis/include \ + $(SDK_ROOT)/external/freertos/source/include \ + $(SDK_ROOT)/external/freertos/portable/GCC/nrf51 \ + $(SDK_ROOT)/external/freertos/portable/CMSIS/nrf51 + # Libraries common to all targets LIB_FILES += \ @@ -59,8 +65,8 @@ LIB_FILES += \ # C flags common to all targets CFLAGS += -DNRF51 CFLAGS += -DNRF51822 +CFLAGS += -DFREERTOS CFLAGS += -DBOARD_CUSTOM -CFLAGS += -DBSP_DEFINES_ONLY CFLAGS += -mcpu=cortex-m0 CFLAGS += -mthumb -mabi=aapcs CFLAGS += -Wall -Werror -O3 -g3 diff --git a/config/FreeRTOSConfig.h b/config/FreeRTOSConfig.h new file mode 100644 index 0000000..3b5b885 --- /dev/null +++ b/config/FreeRTOSConfig.h @@ -0,0 +1,229 @@ +/* + FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to !<< + >>! distribute a combined work that includes FreeRTOS without being !<< + >>! obliged to provide the source code for proprietary components !<< + >>! outside of the FreeRTOS kernel. !<< + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#ifdef SOFTDEVICE_PRESENT +#include "nrf_soc.h" +#endif + +/*----------------------------------------------------------- + * Possible configurations for system timer + */ +#define FREERTOS_USE_RTC 0 /**< Use real time clock for the system */ +#define FREERTOS_USE_SYSTICK 1 /**< Use SysTick timer for system */ + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +#define configTICK_SOURCE FREERTOS_USE_RTC + +#define configUSE_PREEMPTION 1 +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#define configUSE_TICKLESS_IDLE 1 +#define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG 1 /* See into vPortSuppressTicksAndSleep source code for explanation */ +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ 1000 +#define configMAX_PRIORITIES ( 3 ) +#define configMINIMAL_STACK_SIZE ( 60 ) +#define configTOTAL_HEAP_SIZE ( 8192 ) +#define configMAX_TASK_NAME_LEN ( 4 ) +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configUSE_ALTERNATIVE_API 0 /* Deprecated! */ +#define configQUEUE_REGISTRY_SIZE 2 +#define configUSE_QUEUE_SETS 0 +#define configUSE_TIME_SLICING 0 +#define configUSE_NEWLIB_REENTRANT 0 +#define configENABLE_BACKWARD_COMPATIBILITY 1 + +/* Hook function related definitions. */ +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_MALLOC_FAILED_HOOK 0 + +/* Run time and task stats gathering related definitions. */ +#define configGENERATE_RUN_TIME_STATS 0 +#define configUSE_TRACE_FACILITY 0 +#define configUSE_STATS_FORMATTING_FUNCTIONS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Software timer definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY ( 2 ) +#define configTIMER_QUEUE_LENGTH 32 +#define configTIMER_TASK_STACK_DEPTH ( 80 ) + +/* Tickless Idle configuration. */ +#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2 + +/* Tickless idle/low power functionality. */ + + +/* Define to trap errors during development. */ +#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) +#define configASSERT( x ) ASSERT(x) +#endif + +/* FreeRTOS MPU specific definitions. */ +#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 1 + +/* Optional functions - most linkers will remove unused functions anyway. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_xResumeFromISR 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 +#define INCLUDE_xTaskGetIdleTaskHandle 1 +#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 +#define INCLUDE_pcTaskGetTaskName 1 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xEventGroupSetBitFromISR 1 +#define INCLUDE_xTimerPendFunctionCall 1 + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 1 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY configLIBRARY_LOWEST_INTERRUPT_PRIORITY +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names - or at least those used in the unmodified vector table. */ + +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler + + +/*----------------------------------------------------------- + * Settings that are generated automatically + * basing on the settings above + */ +#if (configTICK_SOURCE == FREERTOS_USE_SYSTICK) + // do not define configSYSTICK_CLOCK_HZ for SysTick to be configured automatically + // to CPU clock source + #define xPortSysTickHandler SysTick_Handler +#elif (configTICK_SOURCE == FREERTOS_USE_RTC) + #define configSYSTICK_CLOCK_HZ ( 32768UL ) + #define xPortSysTickHandler RTC1_IRQHandler +#else + #error Unsupported configTICK_SOURCE value +#endif + +/* Code below should be only used by the compiler, and not the assembler. */ +#if !(defined(__ASSEMBLY__) || defined(__ASSEMBLER__)) + #include "nrf.h" + #include "nrf_assert.h" + + /* This part of definitions may be problematic in assembly - it uses definitions from files that are not assembly compatible. */ + /* Cortex-M specific definitions. */ + #ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS + #else + #error "This port requires __NVIC_PRIO_BITS to be defined" + #endif + + /* Access to current system core clock is required only if we are ticking the system by systimer */ + #if (configTICK_SOURCE == FREERTOS_USE_SYSTICK) + #include + extern uint32_t SystemCoreClock; + #endif +#endif /* !assembler */ + +#endif /* FREERTOS_CONFIG_H */ diff --git a/config/custom_board.h b/config/custom_board.h index 8556623..0c7c042 100644 --- a/config/custom_board.h +++ b/config/custom_board.h @@ -1,88 +1,62 @@ -/** - * Copyright (c) 2014 - 2017, 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: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, 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. - * - * 3. 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. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 AQI_SENSOR_H -#define AQI_SENSOR_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define LEDS_NUMBER 4 - -#define LED_1 10 -#define LED_2 9 -#define LED_3 21 -#define LED_4 22 - -#define LEDS_LIST { LED_1, LED_2, LED_3, LED_4 } - -#define LEDS_ACTIVE_STATE 1 - -#define BSP_LED_0 LED_1 -#define BSP_LED_1 LED_2 -#define BSP_LED_2 LED_3 -#define BSP_LED_3 LED_4 - -#define LEDS_INV_MASK LEDS_MASK - -#define BUTTONS_NUMBER 1 - -#define SW_1 0 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -#define BUTTONS_LIST { SW_1 } - -#define BUTTONS_ACTIVE_STATE 0 - -#define BSP_BUTTON_0 SW_1 - -#define RX_PIN_NUMBER 6 -#define TX_PIN_NUMBER 7 -#define HWFC false - -#define SER_CON_RX_PIN 6 -#define SER_CON_TX_PIN 7 - - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef __CUSTOM_BOARD_H +#define __CUSTOM_BOARD_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define LEDS_NUMBER 5 + +#define LED_OB_0 18 +#define LED_OB_1 19 +#define LED_OB_2 20 +#define LED_OB_3 21 +#define LED_OB_4 22 + +#define LED_START LED_OB_0 +#define BSP_LED_0 LED_OB_0 +#define BSP_LED_1 LED_OB_1 +#define BSP_LED_2 LED_OB_2 +#define BSP_LED_3 LED_OB_3 +#define BSP_LED_4 LED_OB_4 +#define LED_STOP LED_OB_4 + +#define LEDS_ACTIVE_STATE 1 +#define LEDS_LIST { LED_OB_0, LED_OB_1, LED_OB_2, LED_OB_3, LED_OB_4 } + +#define BUTTONS_NUMBER 2 + +#define BTN_OB_0 16 +#define BTN_OB_1 17 + +#define BUTTON_START BTN_OB_0 +#define BSP_BUTTON_0 BTN_OB_0 +#define BSP_BUTTON_1 BTN_OB_1 +#define BUTTON_STOP BTN_OB_1 + +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +#define BUTTONS_ACTIVE_STATE 0 +#define BUTTONS_LIST { BTN_OB_0, BTN_OB_1 } + +#define RX_PIN_NUMBER 11 +#define TX_PIN_NUMBER 9 +#define CTS_PIN_NUMBER 10 +#define RTS_PIN_NUMBER 8 + +#define HWFC true + +#ifdef S210 +#define NRF_CLOCK_LFCLKSRC NRF_CLOCK_LFCLKSRC_XTAL_20_PPM +#else +#define NRF_CLOCK_LFCLKSRC { .source = NRF_CLOCK_LF_SRC_XTAL, \ + .rc_ctiv = 0, \ + .rc_temp_ctiv = 0, \ + .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM } +#endif + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/config/custom_board_aqi.h b/config/custom_board_aqi.h new file mode 100644 index 0000000..6129edb --- /dev/null +++ b/config/custom_board_aqi.h @@ -0,0 +1,65 @@ +#ifndef __CUSTOM_BOARD_H +#define __CUSTOM_BOARD_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define LEDS_NUMBER 4 + +#define LED_RING_GR 9 +#define LED_RING_RD 10 +#define LED_BATT_RD 21 +#define LED_STAT_BL 22 + +#define LED_START LED_RING_GR +#define BSP_LED_0 LED_RING_GR +#define BSP_LED_1 LED_RING_RD +#define BSP_LED_2 LED_BATT_RD +#define BSP_LED_3 LED_STAT_BL +#define LED_STOP LED_STAT_BL + +#define LEDS_ACTIVE_STATE 0 +#define LEDS_LIST { LED_RING_GR, LED_RING_RD, LED_BATT_RD, LED_STAT_BL } + +#define BUTTONS_NUMBER 1 + +#define BUTTON_CENTER 30 + +#define BUTTON_START BUTTON_CENTER +#define BSP_BUTTON_0 BUTTON_CENTER +#define BUTTON_STOP BUTTON_CENTER + +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +#define BUTTONS_ACTIVE_STATE 0 +#define BUTTONS_LIST { BUTTON_CENTER } + +#define RX_PIN_NUMBER 6 +#define TX_PIN_NUMBER 7 +#define CTS_PIN_NUMBER 0 +#define RTS_PIN_NUMBER 0 + +#define HWFC false + +#define PIN_POWER_LATCH 29 +#define PIN_POWER_WAKE_BTN 30 +#define PIN_POWER_WAKE_RTC 0 + +#define PIN_PMS_UART_TX 5 +#define PIN_PMS_UART_RX 4 +#define PIN_PMS_RST 0 +#define PIN_PMS_SLP 0 + +#define PIN_RTC_I2C_SDA 23 +#define PIN_RTC_I2C_SCL 24 + +#define PIN_BAT_SENSE 3 +#define PIN_BM_CHRG 11 +#define PIN_BM_STDBY 12 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/config/sdk_config.h b/config/sdk_config.h index 864fb54..757cb24 100644 --- a/config/sdk_config.h +++ b/config/sdk_config.h @@ -8,6 +8,103 @@ #endif // nRF_Drivers +//========================================================== +// CLOCK_ENABLED - nrf_drv_clock - CLOCK peripheral driver +//========================================================== +#ifndef CLOCK_ENABLED +#define CLOCK_ENABLED 1 +#endif +#if CLOCK_ENABLED +// CLOCK_CONFIG_XTAL_FREQ - HF XTAL Frequency + +// <0=> Default (64 MHz) +// <255=> Default (16 MHz) +// <0=> 32 MHz + +#ifndef CLOCK_CONFIG_XTAL_FREQ +#define CLOCK_CONFIG_XTAL_FREQ 255 +#endif + +// CLOCK_CONFIG_LF_SRC - LF Clock Source + +// <0=> RC +// <1=> XTAL +// <2=> Synth + +#ifndef CLOCK_CONFIG_LF_SRC +#define CLOCK_CONFIG_LF_SRC 1 +#endif + +// CLOCK_CONFIG_IRQ_PRIORITY - Interrupt priority + + +// Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice +// <0=> 0 (highest) +// <1=> 1 +// <2=> 2 +// <3=> 3 + +#ifndef CLOCK_CONFIG_IRQ_PRIORITY +#define CLOCK_CONFIG_IRQ_PRIORITY 3 +#endif + + +// CLOCK_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef CLOCK_CONFIG_LOG_ENABLED +#define CLOCK_CONFIG_LOG_ENABLED 0 +#endif +#if CLOCK_CONFIG_LOG_ENABLED +// CLOCK_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef CLOCK_CONFIG_LOG_LEVEL +#define CLOCK_CONFIG_LOG_LEVEL 3 +#endif + +// CLOCK_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef CLOCK_CONFIG_INFO_COLOR +#define CLOCK_CONFIG_INFO_COLOR 0 +#endif + +// CLOCK_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef CLOCK_CONFIG_DEBUG_COLOR +#define CLOCK_CONFIG_DEBUG_COLOR 0 +#endif + +#endif //CLOCK_CONFIG_LOG_ENABLED +// + +#endif //CLOCK_ENABLED +// + //========================================================== // PERIPHERAL_RESOURCE_SHARING_ENABLED - nrf_drv_common - Peripheral drivers common module //========================================================== @@ -164,7 +261,7 @@ // UART_CONFIG_LOG_ENABLED - Enables logging in the module. //========================================================== #ifndef UART_CONFIG_LOG_ENABLED -#define UART_CONFIG_LOG_ENABLED 0 +#define UART_CONFIG_LOG_ENABLED 1 #endif #if UART_CONFIG_LOG_ENABLED // UART_CONFIG_LOG_LEVEL - Default Severity level @@ -176,7 +273,7 @@ // <4=> Debug #ifndef UART_CONFIG_LOG_LEVEL -#define UART_CONFIG_LOG_LEVEL 3 +#define UART_CONFIG_LOG_LEVEL 4 #endif // UART_CONFIG_INFO_COLOR - ANSI escape code prefix. @@ -192,7 +289,7 @@ // <8=> White #ifndef UART_CONFIG_INFO_COLOR -#define UART_CONFIG_INFO_COLOR 0 +#define UART_CONFIG_INFO_COLOR 3 #endif // UART_CONFIG_DEBUG_COLOR - ANSI escape code prefix. @@ -208,7 +305,7 @@ // <8=> White #ifndef UART_CONFIG_DEBUG_COLOR -#define UART_CONFIG_DEBUG_COLOR 0 +#define UART_CONFIG_DEBUG_COLOR 6 #endif #endif //UART_CONFIG_LOG_ENABLED @@ -263,13 +360,13 @@ // NRF_LOG_ENABLED - nrf_log - Logging //========================================================== #ifndef NRF_LOG_ENABLED -#define NRF_LOG_ENABLED 0 +#define NRF_LOG_ENABLED 1 #endif #if NRF_LOG_ENABLED // NRF_LOG_USES_COLORS - If enabled then ANSI escape code for colors is prefixed to every string //========================================================== #ifndef NRF_LOG_USES_COLORS -#define NRF_LOG_USES_COLORS 0 +#define NRF_LOG_USES_COLORS 1 #endif #if NRF_LOG_USES_COLORS // NRF_LOG_COLOR_DEFAULT - ANSI escape code prefix. @@ -285,7 +382,7 @@ // <8=> White #ifndef NRF_LOG_COLOR_DEFAULT -#define NRF_LOG_COLOR_DEFAULT 0 +#define NRF_LOG_COLOR_DEFAULT 6 #endif // NRF_LOG_ERROR_COLOR - ANSI escape code prefix. @@ -301,7 +398,7 @@ // <8=> White #ifndef NRF_LOG_ERROR_COLOR -#define NRF_LOG_ERROR_COLOR 0 +#define NRF_LOG_ERROR_COLOR 2 #endif // NRF_LOG_WARNING_COLOR - ANSI escape code prefix. @@ -317,7 +414,7 @@ // <8=> White #ifndef NRF_LOG_WARNING_COLOR -#define NRF_LOG_WARNING_COLOR 0 +#define NRF_LOG_WARNING_COLOR 4 #endif #endif //NRF_LOG_USES_COLORS @@ -332,7 +429,7 @@ // <4=> Debug #ifndef NRF_LOG_DEFAULT_LEVEL -#define NRF_LOG_DEFAULT_LEVEL 3 +#define NRF_LOG_DEFAULT_LEVEL 4 #endif // NRF_LOG_DEFERRED - Enable deffered logger. diff --git a/main.c b/main.c index 20ac092..6a8bdd2 100644 --- a/main.c +++ b/main.c @@ -2,16 +2,58 @@ #include #include -#include "app_uart.h" -#include "app_error.h" -#include "nrf_delay.h" -#include "nrf.h" #include "bsp.h" +#include "nrf_drv_clock.h" +#include "nordic_common.h" +#include "sdk_errors.h" +#include "app_error.h" + +#include "FreeRTOS.h" +#include "task.h" +#include "timers.h" + +#define APP_TIMER_PRESCALER 0 +#define APP_TIMER_OP_QUEUE_SIZE 4 + +TaskHandle_t xTaskBlinkLEDHandle = NULL; +void vTaskBlinkLED(void *pvParameters); + +TimerHandle_t xTimerBlinkAnotherLEDHandle = NULL; +void xTimerBlinkAnotherLEDCallback(void *pvParameters); + int main(void) { + ret_code_t err_code; + + err_code = nrf_drv_clock_init(); + APP_ERROR_CHECK(err_code); + bsp_board_leds_init(); - while (true) { - nrf_delay_ms(1000); - bsp_board_led_invert(3); + bsp_board_leds_off(); + + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + + UNUSED_VARIABLE(xTaskCreate(vTaskBlinkLED, "TASKLED0", 128, NULL, 2, xTaskBlinkLEDHandle)); + xTimerBlinkAnotherLEDHandle = xTimerCreate("TIMERLED1", pdMS_TO_TICKS(200), pdTRUE, NULL, xTimerBlinkAnotherLEDCallback); + UNUSED_VARIABLE(xTimerStart(xTimerBlinkAnotherLEDHandle, 0)); + + vTaskStartScheduler(); + + for(;;) { + // } } + +void vTaskBlinkLED(void *pvParameters) { + UNUSED_VARIABLE(pvParameters); + + for(;;) { + bsp_board_led_invert(BSP_BOARD_LED_0); + vTaskDelay(1000); + } +} + +void xTimerBlinkAnotherLEDCallback(void *pvParameters) { + UNUSED_VARIABLE(pvParameters); + bsp_board_led_invert(BSP_BOARD_LED_1); +} \ No newline at end of file diff --git a/uart_gcc_nrf51.ld b/nrf51_xxaa.ld similarity index 100% rename from uart_gcc_nrf51.ld rename to nrf51_xxaa.ld diff --git a/nrf51_xxac.ld b/nrf51_xxac.ld new file mode 100644 index 0000000..d0996bc --- /dev/null +++ b/nrf51_xxac.ld @@ -0,0 +1,28 @@ +/* Linker script to configure memory regions. */ + +SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x40000 + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x8000 +} + +SECTIONS +{ + .fs_data : + { + PROVIDE(__start_fs_data = .); + KEEP(*(.fs_data)) + PROVIDE(__stop_fs_data = .); + } > RAM + .pwr_mgmt_data : + { + PROVIDE(__start_pwr_mgmt_data = .); + KEEP(*(.pwr_mgmt_data)) + PROVIDE(__stop_pwr_mgmt_data = .); + } > RAM +} INSERT AFTER .data; + +INCLUDE "nrf5x_common.ld"