Commit 8d72c2a7 authored by Dmitry Frank's avatar Dmitry Frank Committed by Cesanta Bot

Add HTTP example for nRF

PUBLISHED_FROM=d9d979057d5269ac32d16545dd2489485bda642a
parent c722cfec
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# `wildcard ./*/` works in both linux and linux/wine, while `wildcard */` enumerates nothing under wine # `wildcard ./*/` works in both linux and linux/wine, while `wildcard */` enumerates nothing under wine
SUBDIRS = $(sort $(dir $(wildcard ./*/))) SUBDIRS = $(sort $(dir $(wildcard ./*/)))
SUBDIRS:=$(filter-out ./ ./CC3200/ ./ESP8266_RTOS/ ./MSP432/ ./NXP_K64/ ./PIC32/ ./STM32F4_CC3100/ ./mbed/, $(SUBDIRS)) SUBDIRS:=$(filter-out ./ ./CC3200/ ./ESP8266_RTOS/ ./MSP432/ ./NXP_K64/ ./PIC32/ ./STM32F4_CC3100/ ./mbed/ ./nRF52/, $(SUBDIRS))
ifeq ($(OS), Windows_NT) ifeq ($(OS), Windows_NT)
SUBDIRS:=$(filter-out ./load_balancer/ ./netcat/ ./raspberry_pi_mjpeg_led/ ./captive_dns_server/, $(SUBDIRS)) SUBDIRS:=$(filter-out ./load_balancer/ ./netcat/ ./raspberry_pi_mjpeg_led/ ./captive_dns_server/, $(SUBDIRS))
......
target extended-remote localhost:2331
file out/example.out
SDK ?= $(shell cat sdk.version)
SRC_DIR ?= $(realpath ../../..)
.PHONY: all clean flash gdbserver gdb jlinkexe rtt
MAKEFLAGS += w
ifeq ("$(VERBOSE)","1")
V :=
else
V := @
endif
ADD_DOCKER_ARGS =
# For communication with the device, we need docker container to be able
# to access it.
flash gdbserver gdb jlinkexe rtt: \
ADD_DOCKER_ARGS = --privileged -v /dev/bus/usb:/dev/bus/usb --net=host
all clean flash gdbserver gdb jlinkexe rtt:
$(V)docker run --rm -it $(ADD_DOCKER_ARGS) -v $(SRC_DIR):/src $(SDK) \
/bin/bash -c "\
make -C /src/mongoose mongoose.c mongoose.h && \
make -C /src/mongoose/examples/nRF52 -f Makefile.build $@ -$(MAKEFLAGS) \
"
.PHONY: all clean flash gdbserver gdb jlinkexe rtt
APP_ROOT=.
MONGOOSE_ROOT=../..
BUILD_DIR=.build
OUT_DIR=out
PROJECT=example
NRF_IOT_SDK_ROOT=/opt/nrf5_iot_sdk
GNU_PREFIX := arm-none-eabi
LD_PATH=$(APP_ROOT)/ld
#echo suspend
ifeq ("$(VERBOSE)","1")
V :=
else
V := @
endif
# Toolchain commands
CC := '$(GNU_PREFIX)-gcc'
AS := '$(GNU_PREFIX)-as'
AR := '$(GNU_PREFIX)-ar' -r
LD := '$(GNU_PREFIX)-ld'
NM := '$(GNU_PREFIX)-nm'
OBJDUMP := '$(GNU_PREFIX)-objdump'
OBJCOPY := '$(GNU_PREFIX)-objcopy'
SIZE := '$(GNU_PREFIX)-size'
IPATH_SDK = . \
$(NRF_IOT_SDK_ROOT)/components/iot/errno \
$(NRF_IOT_SDK_ROOT)/components/softdevice/s1xx_iot/headers \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/common \
$(NRF_IOT_SDK_ROOT)/components/softdevice/common/softdevice_handler \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/include \
$(NRF_IOT_SDK_ROOT)/components/iot/ble_6lowpan \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/hal \
$(NRF_IOT_SDK_ROOT)/components/ble/common \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/port \
$(NRF_IOT_SDK_ROOT)/components/libraries/fifo \
$(NRF_IOT_SDK_ROOT)/components/libraries/trace \
$(NRF_IOT_SDK_ROOT)/components/device \
$(NRF_IOT_SDK_ROOT)/components/libraries/uart \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/rng \
$(NRF_IOT_SDK_ROOT)/components/iot/medium \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/config \
$(NRF_IOT_SDK_ROOT)/components/libraries/mem_manager \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/uart \
$(NRF_IOT_SDK_ROOT)/components/iot/ble_ipsp \
$(NRF_IOT_SDK_ROOT)/components/libraries/scheduler \
$(NRF_IOT_SDK_ROOT)/components/iot/iot_timer \
$(NRF_IOT_SDK_ROOT)/components/iot/tls/mbedtls/tls/config \
$(NRF_IOT_SDK_ROOT)/external/mbedtls/include \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/include/netif \
$(NRF_IOT_SDK_ROOT)/components/iot/medium/commissioning \
$(NRF_IOT_SDK_ROOT)/components/iot/tls \
$(NRF_IOT_SDK_ROOT)/components/iot/include \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/pstorage \
$(NRF_IOT_SDK_ROOT)/components/iot/tls \
$(NRF_IOT_SDK_ROOT)/components/iot/context_manager \
$(NRF_IOT_SDK_ROOT)/components/iot_timer \
$(NRF_IOT_SDK_ROOT)/components/toolchain/gcc \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/delay \
$(NRF_IOT_SDK_ROOT)/components/iot/medium/ble_ncfgs \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/gpiote \
$(NRF_IOT_SDK_ROOT)/components/iot/mqtt \
$(NRF_IOT_SDK_ROOT)/components/softdevice/s1xx_iot/headers/nrf52 \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/include/lwip \
$(NRF_IOT_SDK_ROOT)/components/iot/common \
$(NRF_IOT_SDK_ROOT)/components/libraries/timer \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/port/arch \
$(NRF_IOT_SDK_ROOT)/components/libraries/button \
$(NRF_IOT_SDK_ROOT)/components/libraries/util \
$(NRF_IOT_SDK_ROOT)/examples/bsp \
$(NRF_IOT_SDK_ROOT)/components/toolchain \
$(NRF_IOT_SDK_ROOT)/components/iot/medium/include \
IPATH_RTT = $(APP_ROOT)/rtt/RTT
IPATH_APP = $(APP_ROOT) $(APP_ROOT)/config
IPATH = . $(IPATH_APP) $(IPATH_RTT) $(IPATH_SDK)
SOURCES_NRF_IOT_SDK = \
$(NRF_IOT_SDK_ROOT)/examples/bsp/bsp.c \
$(NRF_IOT_SDK_ROOT)/components/libraries/button/app_button.c \
$(NRF_IOT_SDK_ROOT)/components/libraries/util/app_error.c \
$(NRF_IOT_SDK_ROOT)/components/libraries/fifo/app_fifo.c \
$(NRF_IOT_SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
$(NRF_IOT_SDK_ROOT)/components/libraries/timer/app_timer.c \
$(NRF_IOT_SDK_ROOT)/components/libraries/timer/app_timer_appsh.c \
$(NRF_IOT_SDK_ROOT)/components/libraries/trace/app_trace.c \
$(NRF_IOT_SDK_ROOT)/components/libraries/mem_manager/mem_manager.c \
$(NRF_IOT_SDK_ROOT)/components/libraries/util/nrf_assert.c \
$(NRF_IOT_SDK_ROOT)/components/libraries/uart/retarget.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/def.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/dhcp.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/dhcp6.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/dns.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv4/icmp.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/icmp6.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/inet6.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/inet_chksum.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/init.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv4/ip4.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv4/ip4_addr.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/ip6.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/ip6_addr.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/memp.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/mld6.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/nd6.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/netif.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/port/nrf_platform_port.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/pbuf.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/raw.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/sys.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/tcp.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/tcp_in.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/tcp_out.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/timers.c \
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/udp.c \
$(NRF_IOT_SDK_ROOT)/components/libraries/uart/app_uart_fifo.c \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/delay/nrf_delay.c \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/common/nrf_drv_common.c \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/gpiote/nrf_drv_gpiote.c \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/uart/nrf_drv_uart.c \
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/pstorage/pstorage.c \
$(NRF_IOT_SDK_ROOT)/components/ble/common/ble_advdata.c \
$(NRF_IOT_SDK_ROOT)/components/ble/common/ble_conn_params.c \
$(NRF_IOT_SDK_ROOT)/components/ble/common/ble_srv_common.c \
$(NRF_IOT_SDK_ROOT)/components/iot/errno/errno.c \
$(NRF_IOT_SDK_ROOT)/components/iot/context_manager/iot_context_manager.c \
$(NRF_IOT_SDK_ROOT)/components/iot/iot_timer/iot_timer.c \
$(NRF_IOT_SDK_ROOT)/components/iot/medium/ipv6_medium_ble.c \
$(NRF_IOT_SDK_ROOT)/components/iot/common/ipv6_parse.c \
$(NRF_IOT_SDK_ROOT)/components/toolchain/system_nrf52.c \
$(NRF_IOT_SDK_ROOT)/components/iot/medium/ble_ncfgs/ble_ncfgs.c \
$(NRF_IOT_SDK_ROOT)/components/iot/medium/commissioning/commissioning.c \
$(NRF_IOT_SDK_ROOT)/components/softdevice/common/softdevice_handler/softdevice_handler.c \
$(NRF_IOT_SDK_ROOT)/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.c \
SOURCES_RTT = \
$(APP_ROOT)/rtt/RTT/SEGGER_RTT.c \
$(APP_ROOT)/rtt/RTT/SEGGER_RTT_printf.c \
$(APP_ROOT)/rtt/Syscalls/RTT_Syscalls_GCC.c \
SOURCES_APP = \
$(APP_ROOT)/main.c \
$(APP_ROOT)/bleconfig.c \
$(MONGOOSE_ROOT)/mongoose.c \
SOURCES = $(SOURCES_APP) $(SOURCES_NRF_IOT_SDK) $(SOURCES_RTT)
LIBS = $(NRF_IOT_SDK_ROOT)/components/iot/ble_6lowpan/lib/ble_6lowpan.a
ASM_SOURCES = $(APP_ROOT)/gcc_startup_nrf52.s
LINKER_SCRIPT = $(LD_PATH)/mongoose_example_nrf52.ld
C_SOURCE_FILE_NAMES = $(notdir $(SOURCES))
C_PATHS = $(sort $(dir $(SOURCES) ) )
ASM_PATHS = $(sort $(dir $(ASM_SOURCES) ))
C_OBJECTS = $(addprefix $(BUILD_DIR)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCES))
ASM_PATHS = $(sort $(dir $(ASM_SOURCES) ))
ASM_OBJECTS = $(addprefix $(BUILD_DIR)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )
INCDIRS = $(addprefix -I,$(IPATH))
vpath %.c $(C_PATHS)
vpath %.s $(ASM_PATHS)
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
# Mongoose features
MG_FEATURES_TINY = \
-DMG_DISABLE_HTTP_DIGEST_AUTH \
-DMG_DISABLE_MD5 \
-DMG_DISABLE_HTTP_KEEP_ALIVE \
-DMG_ENABLE_HTTP_SSI=0 \
-DMG_ENABLE_HTTP_STREAMING_MULTIPART \
-DMG_NO_BSD_SOCKETS
#flags common to all targets
CFLAGS = -D__HEAP_SIZE=512
CFLAGS += -DSWI_DISABLE0
CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -DBOARD_PCA10040
CFLAGS += -DNRF52
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DBLE_STACK_SUPPORT_REQD
CFLAGS += -Ds1xx
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -w -g3 -Os
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in separate section. This will allow linker to dump
# unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin --short-enums
CFLAGS += -DCS_ENABLE_STDIO
#CFLAGS += -DCS_ENABLE_DEBUG
# This macro is needed for stdout to be retargeted to either UART or RTT
CFLAGS += -DENABLE_DEBUG_LOG_SUPPORT
# Don't retarget stdout to UART; it'll be retargeted to RTT
CFLAGS += -DNRF_LOG_USES_RTT
# Mongoose flags
CFLAGS += -DCS_PLATFORM=CS_P_NRF52 $(MG_FEATURES_TINY) -DMG_MODULE_LINES
LDFLAGS += -Xlinker -Map=$(OUT_DIR)/$(PROJECT).map
LDFLAGS += -mthumb -mabi=aapcs -L $(LD_PATH) -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m4
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs -lc -lnosys
# Assembler flags
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -D__HEAP_SIZE=512
ASMFLAGS += -DSWI_DISABLE0
ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DBOARD_PCA10040
ASMFLAGS += -DNRF52
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += -DENABLE_DEBUG_LOG_SUPPORT
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
ASMFLAGS += -Ds1xx
ASMFLAGS += -g3
INC_PATHS=$(addprefix -I,$(IPATH))
BUILD_DIRECTORIES := $(BUILD_DIR) $(OUT_DIR)
# Create objects from C SRC files
$(BUILD_DIR)/%.o: %.c
@echo Compiling file: $(notdir $<)
$(V)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
# Assemble files
$(BUILD_DIR)/%.o: %.s
@echo Assembly file: $(notdir $<)
$(V)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $<
# Create binary .hex file from the .out file
%.hex: %.out
@echo Generating HEX file: $@
$(V)$(OBJCOPY) -O ihex $< $@
OUT_FILENAME=$(OUT_DIR)/$(PROJECT).out
HEX_FILENAME=$(OUT_DIR)/$(PROJECT).hex
all: $(OUT_FILENAME) $(HEX_FILENAME)
$(OUT_FILENAME): $(BUILD_DIRECTORIES) $(OBJECTS)
@echo Linking target: $(OUT_FILENAME)
$(V)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUT_FILENAME)
## Create build directories
$(BUILD_DIRECTORIES):
mkdir $@
clean:
rm -rf $(BUILD_DIR) $(OUT_DIR) \
# Flash the program
flash: $(HEX_FILENAME)
@echo Flashing: $<
/opt/nordic/nrfjprog/nrfjprog --program $< -f nrf52 --sectorerase
/opt/nordic/nrfjprog/nrfjprog --reset -f nrf52
# start GDB server. It is needed to be done in a separate terminal before we
# can invoke `gdb` target
gdbserver:
/opt/SEGGER/JLink_V610g/JLinkGDBServer -device NRF52 -speed 4000 -if SWD
# run GDB (for that to work, `make gdbserver` should run in parallel)
gdb:
arm-none-eabi-gdb
# start JLinkExe; it is needed to be done in a separate terminal before we
# can invoke `rtt` target
jlinkexe:
/opt/SEGGER/JLink_V610g/JLinkExe -device NRF52 -speed 4000 -if SWD
# run RTT client (for that to work, `make jlinkexe` should run in parallel)
rtt:
/opt/SEGGER/JLink_V610g/JLinkRTTClient
# nRF52 example project
This example shows how to use mongoose on nRF52 boards.
To run it you will need:
- [nRF52 DK](https://www.nordicsemi.com/Products/Getting-started-with-the-nRF52-Development-Kit) dev board
- Linux machine with 6lowpan module enabled. There are a few tutorials out there,
e.g [this one](https://devzone.nordicsemi.com/blogs/972/setting-up-ipv6-over-ble-using-nrf52-series-and-co/)
- [Docker](https://docs.docker.com/engine/installation/linux/)
## Building firmware and cleaning
Nothing special: `make` and `make clean`.
## Flashing
`make flash`
## Watch debug output
This is a two-step process:
- In a separate terminal, invoke `make jlinkexe`. It will run `JLinkExe`
utility, in which you'll need to type `connect`. You can actually do a lot of
things there, including halting and stopping the target, flashing firmware,
etc. You can type `?` to get the list of all available commands.
- Now, in another terminal, invoke `make rtt`. It will start RTT client which
will connect to the running `JLinkExe` and will show logs from the device.
## Debug with GDB
This is a two-step process:
- In a separate terminal, invoke `make gdbserver`. Note that `make jlinkexe`
and `make gdbserver`, unfortunately, cannot run sumultaneously.
- Now, in another terminal, invoke `make gdb`. It will start GDB session which
will connect to the running GDB server.
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
/* clang-format off */
#include <stdbool.h>
#include <stdint.h>
#include "boards.h"
#include "sdk_config.h"
#include "app_timer_appsh.h"
#include "app_scheduler.h"
#include "app_button.h"
#include "nordic_common.h"
#include "softdevice_handler_appsh.h"
#include "ble_advdata.h"
#include "ble_srv_common.h"
#include "ble_ipsp.h"
#include "ble_6lowpan.h"
#include "mem_manager.h"
#include "app_trace.h"
#include "lwip/init.h"
#include "lwip/inet6.h"
#include "lwip/ip6.h"
#include "lwip/ip6_addr.h"
#include "lwip/netif.h"
/*lint -save -e607 */
#include "lwip/tcp.h"
/*lint -restore */
#include "lwip/timers.h"
#include "nrf_platform_port.h"
#include "app_util_platform.h"
#include "iot_timer.h"
#include "ipv6_medium.h"
#include "SEGGER_RTT.h"
#include "myboard.h"
#include "app_cfg.h"
#define SCHED_MAX_EVENT_DATA_SIZE 128 /**< Maximum size of scheduler events. */
#define SCHED_QUEUE_SIZE 12 /**< Maximum number of events in the scheduler queue. */
#if COMMISSIONING_ENABLED
#define ERASE_BUTTON_PIN_NO BSP_BUTTON_3 /**< Button used to erase commissioning settings. */
#endif // COMMISSIONING_ENABLED
#define APP_TIMER_OP_QUEUE_SIZE 5
#define LWIP_SYS_TICK_MS 100 /**< Interval for timer used as trigger to send. */
#define LED_BLINK_INTERVAL_MS 300 /**< LED blinking interval. */
#define MAX_LENGTH_FILENAME 128 /**< Max length of filename to copy for the debug error handler. */
#define APPL_LOG app_trace_log /**< Macro for logging application messages on UART, in case ENABLE_DEBUG_LOG_SUPPORT is not defined, no logging occurs. */
#define APPL_DUMP app_trace_dump /**< Macro for dumping application data on UART, in case ENABLE_DEBUG_LOG_SUPPORT is not defined, no logging occurs. */
#define TCP_SERVER_PORT 9000 /**< TCP server listen port number. */
#define TCP_DATA_SIZE 8 /**< UDP Data size sent on remote. */
typedef enum
{
TCP_STATE_IDLE,
TCP_STATE_REQUEST_CONNECTION,
TCP_STATE_CONNECTED,
TCP_STATE_DATA_TX_IN_PROGRESS,
TCP_STATE_DISCONNECTED
}tcp_state_t;
APP_TIMER_DEF(m_iot_timer_tick_src_id); /**< System Timer used to service CoAP and LWIP periodically. */
eui64_t eui64_local_iid; /**< Local EUI64 value that is used as the IID for*/
static ipv6_medium_instance_t m_ipv6_medium;
static struct tcp_pcb * mp_tcp_port; /**< TCP Port to listen on. */
static tcp_state_t m_tcp_state; /**< TCP State information. */
#if COMMISSIONING_ENABLED
static bool m_power_off_on_failure = false;
static bool m_identity_mode_active;
#endif // COMMISSIONING_ENABLED
/**@brief Function to handle interface up event. */
void nrf_driver_interface_up(void)
{
#if COMMISSIONING_ENABLED
commissioning_joining_mode_timer_ctrl(JOINING_MODE_TIMER_STOP_RESET);
#endif // COMMISSIONING_ENABLED
APPL_LOG ("[APPL]: IPv6 interface up.\r\n");
sys_check_timeouts();
m_tcp_state = TCP_STATE_REQUEST_CONNECTION;
LEDS_OFF(LED_ONE);
LEDS_ON(LED_TWO);
}
/**@brief Function to handle interface down event. */
void nrf_driver_interface_down(void)
{
#if COMMISSIONING_ENABLED
commissioning_joining_mode_timer_ctrl(JOINING_MODE_TIMER_START);
#endif // COMMISSIONING_ENABLED
APPL_LOG ("[APPL]: IPv6 interface down.\r\n");
LEDS_OFF((DISPLAY_LED_0 | DISPLAY_LED_1 | DISPLAY_LED_2 | DISPLAY_LED_3));
LEDS_ON(LED_ONE);
m_tcp_state = TCP_STATE_DISCONNECTED;
}
/**@brief Timer callback used for periodic servicing of LwIP protocol timers.
*
* @details Timer callback used for periodic servicing of LwIP protocol timers.
*
* @param[in] p_context Pointer used for passing context. No context used in this application.
*/
static void system_timer_callback(iot_timer_time_in_ms_t wall_clock_value)
{
UNUSED_VARIABLE(wall_clock_value);
sys_check_timeouts();
}
/**@brief Function for starting connectable mode.
*/
static void connectable_mode_enter(void)
{
uint32_t err_code = ipv6_medium_connectable_mode_enter(m_ipv6_medium.ipv6_medium_instance_id);
APP_ERROR_CHECK(err_code);
APPL_LOG("[APPL]: Physical layer in connectable mode.\r\n");
LEDS_OFF(LED_TWO);
LEDS_ON(LED_ONE);
}
/**@brief Function for updating the wall clock of the IoT Timer module.
*/
static void iot_timer_tick_callback(void * p_context)
{
UNUSED_VARIABLE(p_context);
uint32_t err_code = iot_timer_update();
APP_ERROR_CHECK(err_code);
}
/**@brief Function for the LEDs initialization.
*
* @details Initializes all LEDs used by this application.
*/
static void leds_init(void)
{
// Configure application LED pins.
LEDS_CONFIGURE(ALL_APP_LED);
// Turn off all LED on initialization.
LEDS_OFF(ALL_APP_LED);
}
#if COMMISSIONING_ENABLED
/**@brief Timer callback used for controlling board LEDs to represent application state.
*
*/
static void blink_timeout_handler(iot_timer_time_in_ms_t wall_clock_value)
{
UNUSED_PARAMETER(wall_clock_value);
static bool id_mode_previously_enabled;
if ((id_mode_previously_enabled == false) && (m_identity_mode_active == true))
{
LEDS_OFF(LED_THREE | LED_FOUR);
}
if ((id_mode_previously_enabled == true) && (m_identity_mode_active == true))
{
LEDS_INVERT(LED_THREE | LED_FOUR);
}
if ((id_mode_previously_enabled == true) && (m_identity_mode_active == false))
{
LEDS_OFF(LED_THREE | LED_FOUR);
}
id_mode_previously_enabled = m_identity_mode_active;
}
#endif // COMMISSIONING_ENABLED
/**@brief Function for the Timer initialization.
*
* @details Initializes the timer module. This creates and starts application timers.
*/
static void timers_init(void)
{
uint32_t err_code;
// Initialize timer module.
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
// Create a sys timer.
err_code = app_timer_create(&m_iot_timer_tick_src_id,
APP_TIMER_MODE_REPEATED,
iot_timer_tick_callback);
APP_ERROR_CHECK(err_code);
}
/**@brief Function for initializing the IoT Timer. */
static void iot_timer_init(void)
{
uint32_t err_code;
static const iot_timer_client_t list_of_clients[] =
{
{system_timer_callback, LWIP_SYS_TICK_MS},
#if COMMISSIONING_ENABLED
{blink_timeout_handler, LED_BLINK_INTERVAL_MS},
{commissioning_time_tick, SEC_TO_MILLISEC(COMMISSIONING_TICK_INTERVAL_SEC)}
#endif // COMMISSIONING_ENABLED
};
// The list of IoT Timer clients is declared as a constant.
static const iot_timer_clients_list_t iot_timer_clients =
{
(sizeof(list_of_clients) / sizeof(iot_timer_client_t)),
&(list_of_clients[0]),
};
// Passing the list of clients to the IoT Timer module.
err_code = iot_timer_client_list_set(&iot_timer_clients);
APP_ERROR_CHECK(err_code);
// Starting the app timer instance that is the tick source for the IoT Timer.
err_code = app_timer_start(m_iot_timer_tick_src_id, \
APP_TIMER_TICKS(IOT_TIMER_RESOLUTION_IN_MS, APP_TIMER_PRESCALER), \
NULL);
APP_ERROR_CHECK(err_code);
}
/**@brief Function for initializing IP stack.
*
* @details Initialize the IP Stack and its driver.
*/
static void ip_stack_init(void)
{
uint32_t err_code;
err_code = ipv6_medium_eui64_get(m_ipv6_medium.ipv6_medium_instance_id, \
&eui64_local_iid);
APP_ERROR_CHECK(err_code);
err_code = nrf_mem_init();
APP_ERROR_CHECK(err_code);
//Initialize LwIP stack.
lwip_init();
//Initialize LwIP stack driver.
err_code = nrf_driver_init();
APP_ERROR_CHECK(err_code);
}
#if COMMISSIONING_ENABLED
/**@brief Function for handling button events.
*
* @param[in] pin_no The pin number of the button pressed.
* @param[in] button_action The action performed on button.
*/
static void button_event_handler(uint8_t pin_no, uint8_t button_action)
{
if ((button_action == APP_BUTTON_PUSH) && (pin_no == ERASE_BUTTON_PIN_NO))
{
APPL_LOG("[APPL]: Erasing all commissioning settings from persistent storage... \r\n");
commissioning_settings_clear();
return;
}
return;
}
/**@brief Function for the Button initialization.
*
* @details Initializes all Buttons used by this application.
*/
static void buttons_init(void)
{
uint32_t err_code;
static app_button_cfg_t buttons[] =
{
#if COMMISSIONING_ENABLED
{ERASE_BUTTON_PIN_NO, false, BUTTON_PULL, button_event_handler}
#endif // COMMISSIONING_ENABLED
};
#define BUTTON_DETECTION_DELAY APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)
err_code = app_button_init(buttons, \
sizeof(buttons) / sizeof(buttons[0]), \
BUTTON_DETECTION_DELAY);
APP_ERROR_CHECK(err_code);
err_code = app_button_enable();
APP_ERROR_CHECK(err_code);
}
#endif // COMMISSIONING_ENABLED
/**@brief Function for the Event Scheduler initialization.
*/
static void scheduler_init(void)
{
APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);
}
static void on_ipv6_medium_evt(ipv6_medium_evt_t * p_ipv6_medium_evt)
{
switch (p_ipv6_medium_evt->ipv6_medium_evt_id)
{
case IPV6_MEDIUM_EVT_CONN_UP:
{
APPL_LOG("[APPL]: Physical layer: connected.\r\n");
LEDS_OFF(LED_ONE);
LEDS_ON(LED_TWO);
break;
}
case IPV6_MEDIUM_EVT_CONN_DOWN:
{
APPL_LOG("[APPL]: Physical layer: disconnected.\r\n");
connectable_mode_enter();
break;
}
default:
{
break;
}
}
}
static void on_ipv6_medium_error(ipv6_medium_error_t * p_ipv6_medium_error)
{
// Do something.
}
#if COMMISSIONING_ENABLED
void commissioning_id_mode_cb(mode_control_cmd_t control_command)
{
switch (control_command)
{
case CMD_IDENTITY_MODE_ENTER:
{
LEDS_OFF(LED_THREE | LED_FOUR);
m_identity_mode_active = true;
break;
}
case CMD_IDENTITY_MODE_EXIT:
{
m_identity_mode_active = false;
LEDS_OFF((LED_THREE | LED_FOUR));
break;
}
default:
{
break;
}
}
}
void commissioning_power_off_cb(bool power_off_on_failure)
{
m_power_off_on_failure = power_off_on_failure;
APPL_LOG("[APPL]: Commissioning: do power_off on failure: %s.\r\n", \
m_power_off_on_failure ? "true" : "false");
}
#endif // COMMISSIONING_ENABLED
void bleconfig_init(void) {
uint32_t err_code;
//Initialize.
app_trace_init();
leds_init();
timers_init();
iot_timer_init();
#if COMMISSIONING_ENABLED
err_code = pstorage_init();
APP_ERROR_CHECK(err_code);
buttons_init();
#endif // COMMISSIONING_ENABLED
static ipv6_medium_init_params_t ipv6_medium_init_params;
memset(&ipv6_medium_init_params, 0x00, sizeof(ipv6_medium_init_params));
ipv6_medium_init_params.ipv6_medium_evt_handler = on_ipv6_medium_evt;
ipv6_medium_init_params.ipv6_medium_error_handler = on_ipv6_medium_error;
ipv6_medium_init_params.use_scheduler = true;
#if COMMISSIONING_ENABLED
ipv6_medium_init_params.commissioning_id_mode_cb = commissioning_id_mode_cb;
ipv6_medium_init_params.commissioning_power_off_cb = commissioning_power_off_cb;
#endif // COMMISSIONING_ENABLED
err_code = ipv6_medium_init(&ipv6_medium_init_params, \
IPV6_MEDIUM_ID_BLE, \
&m_ipv6_medium);
APP_ERROR_CHECK(err_code);
eui48_t ipv6_medium_eui48;
err_code = ipv6_medium_eui48_get(m_ipv6_medium.ipv6_medium_instance_id, \
&ipv6_medium_eui48);
ipv6_medium_eui48.identifier[EUI_48_SIZE - 1] = 0x00;
err_code = ipv6_medium_eui48_set(m_ipv6_medium.ipv6_medium_instance_id, \
&ipv6_medium_eui48);
APP_ERROR_CHECK(err_code);
ip_stack_init();
scheduler_init();
//Start execution.
connectable_mode_enter();
APPL_LOG(0, "BLE init done\n");
}
void bleconfig_poll(void) {
//Execute event schedule.
app_sched_execute();
}
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
/* clang-format off */
void bleconfig_init(void);
void bleconfig_poll(void);
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#if !defined(COMMISSIONING_ENABLED) /* ifdef-ok */
# define COMMISSIONING_ENABLED 0
#endif
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*/
/** @cond To make doxygen skip this file */
/** @file
* This header contains defines with respect to the IPv6 medium that are specific to
* the BLE implementation and the application use case.
* @{
*/
#ifndef IPV6_MEDIUM_BLE_CONFIG_H__
#define IPV6_MEDIUM_BLE_CONFIG_H__
#include "app_util.h"
#define DEVICE_NAME "TCP_Server" /**< Device name used in BLE undirected advertisement. */
#define IS_SRVC_CHANGED_CHARACT_PRESENT 0
#define COMPANY_IDENTIFIER 0x0059 /**< Company identifier for Nordic Semiconductor ASA as per www.bluetooth.org. */
#define APP_TIMER_PRESCALER 31 /**< Value of the RTC1 PRESCALER register. */
#define APP_ADV_ADV_INTERVAL MSEC_TO_UNITS(333, UNIT_0_625_MS) /**< The advertising interval. This value can vary between 100ms to 10.24s). */
#define APP_ADV_TIMEOUT 0 /**< Time for which the device must be advertising in non-connectable mode (in seconds). 0 disables timeout. */
/*lint -emacro(524, MIN_CONN_INTERVAL) // Loss of precision */
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(7.5, UNIT_1_25_MS) /**< Minimum connection interval (7.5 ms) */
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(30, UNIT_1_25_MS) /**< Maximum connection interval (30 ms). */
#define SLAVE_LATENCY 6 /**< Slave latency. */
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(430, UNIT_10_MS) /**< Connection supervisory timeout (430 ms). */
#ifdef COMMISSIONING_ENABLED
#define CONFIG_MODE_DEVICE_NAME "NodeCFG" /**< Name of device. Will be included in the advertising data. */
/*lint -emacro(524, MIN_CONN_INTERVAL) // Loss of precision */
#define CONFIG_MODE_MIN_CONN_INTERVAL MSEC_TO_UNITS(400, UNIT_1_25_MS) /**< Config mode: Minimum acceptable connection interval (0.4 seconds). */
#define CONFIG_MODE_MAX_CONN_INTERVAL MSEC_TO_UNITS(650, UNIT_1_25_MS) /**< Config mode: Maximum acceptable connection interval (0.65 second). */
#define CONFIG_MODE_SLAVE_LATENCY 0 /**< Config mode: Slave latency. */
#define CONFIG_MODE_CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) /**< Config mode: Connection supervisory timeout (4 seconds). */
#define CONFIG_MODE_ADV_ADV_INTERVAL MSEC_TO_UNITS(333, UNIT_0_625_MS) /**< Config mode: The advertising interval. This value can vary between 100ms to 10.24s). */
#define CONFIG_MODE_ADV_TIMEOUT 0 /**< Config mode: Time for which the device must be advertising in non-connectable mode (in seconds). 0 disables timeout. */
#define JOINING_MODE_MIN_CONN_INTERVAL MSEC_TO_UNITS(400, UNIT_1_25_MS) /**< Joining mode: Minimum acceptable connection interval (0.4 seconds). */
#define JOINING_MODE_MAX_CONN_INTERVAL MSEC_TO_UNITS(650, UNIT_1_25_MS) /**< Joining mode: Maximum acceptable connection interval (0.65 second). */
#define JOINING_MODE_SLAVE_LATENCY 0 /**< Joining mode: Slave latency. */
#define JOINING_MODE_CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) /**< Joining mode: Connection supervisory timeout (4 seconds). */
#define JOINING_MODE_ADV_ADV_INTERVAL MSEC_TO_UNITS(333, UNIT_0_625_MS) /**< Joining mode: The advertising interval. This value can vary between 100ms to 10.24s). */
#define JOINING_MODE_ADV_TIMEOUT 0 /**< Joining mode: Time for which the device must be advertising in non-connectable mode (in seconds). 0 disables timeout. */
#endif // COMMISSIONING_ENABLED
#endif // IPV6_MEDIUM_BLE_CONFIG_H__
/** @} */
/** @endcond */
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*/
/** @cond To make doxygen skip this file */
/** @file
* This header needs to include the desired IPv6 medium implementation(s).
* Based on the chosen implementation, it also definitions that are specific to
* the IPv6 medium implementation(s) and the application use case.
* @{
*/
#ifndef IPV6_MEDIUM_PLATFORM_H__
#define IPV6_MEDIUM_PLATFORM_H__
#include "ipv6_medium_ble.h"
#ifdef COMMISSIONING_ENABLED
#include "commissioning.h"
#endif // COMMISSIONING_ENABLED
typedef union
{
ipv6_medium_ble_cb_params_t ble;
#ifdef COMMISSIONING_ENABLED
commissioning_evt_t commissioning;
#endif // COMMISSIONING_ENABLED
} ipv6_medium_cb_params_union_t;
typedef union
{
ipv6_medium_ble_error_params_t ble;
#ifdef COMMISSIONING_ENABLED
commissioning_evt_t commissioning;
#endif // COMMISSIONING_ENABLED
} ipv6_medium_err_params_union_t;
#endif // IPV6_MEDIUM_PLATFORM_H__
/** @} */
/** @endcond */
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
#ifndef NRF_DRV_CONFIG_H
#define NRF_DRV_CONFIG_H
/* CLOCK */
#define CLOCK_CONFIG_XTAL_FREQ NRF_CLOCK_XTALFREQ_Default
#define CLOCK_CONFIG_LF_SRC NRF_CLOCK_LF_SRC_Xtal
#define CLOCK_CONFIG_LF_RC_CAL_INTERVAL RC_2000MS_CALIBRATION_INTERVAL
#define CLOCK_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
/* GPIOTE */
#define GPIOTE_ENABLED 1
#if (GPIOTE_ENABLED == 1)
#define GPIOTE_CONFIG_USE_SWI_EGU false
#define GPIOTE_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 4
#endif
/* TIMER */
#define TIMER0_ENABLED 0
#if (TIMER0_ENABLED == 1)
#define TIMER0_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz
#define TIMER0_CONFIG_MODE TIMER_MODE_MODE_Timer
#define TIMER0_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_32Bit
#define TIMER0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define TIMER0_INSTANCE_INDEX 0
#endif
#define TIMER1_ENABLED 0
#if (TIMER1_ENABLED == 1)
#define TIMER1_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz
#define TIMER1_CONFIG_MODE TIMER_MODE_MODE_Timer
#define TIMER1_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit
#define TIMER1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define TIMER1_INSTANCE_INDEX (TIMER0_ENABLED)
#endif
#define TIMER2_ENABLED 0
#if (TIMER2_ENABLED == 1)
#define TIMER2_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz
#define TIMER2_CONFIG_MODE TIMER_MODE_MODE_Timer
#define TIMER2_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit
#define TIMER2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define TIMER2_INSTANCE_INDEX (TIMER1_ENABLED+TIMER0_ENABLED)
#endif
#define TIMER3_ENABLED 0
#if (TIMER3_ENABLED == 1)
#define TIMER3_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz
#define TIMER3_CONFIG_MODE TIMER_MODE_MODE_Timer
#define TIMER3_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit
#define TIMER3_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define TIMER3_INSTANCE_INDEX (TIMER2_ENABLED+TIMER1_ENABLED+TIMER0_ENABLED)
#endif
#define TIMER4_ENABLED 0
#if (TIMER4_ENABLED == 1)
#define TIMER4_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz
#define TIMER4_CONFIG_MODE TIMER_MODE_MODE_Timer
#define TIMER4_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit
#define TIMER4_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define TIMER4_INSTANCE_INDEX (TIMER3_ENABLED+TIMER2_ENABLED+TIMER1_ENABLED+TIMER0_ENABLED)
#endif
#define TIMER_COUNT (TIMER0_ENABLED + TIMER1_ENABLED + TIMER2_ENABLED + TIMER3_ENABLED + TIMER4_ENABLED)
/* RTC */
#define RTC0_ENABLED 0
#if (RTC0_ENABLED == 1)
#define RTC0_CONFIG_FREQUENCY 32678
#define RTC0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define RTC0_CONFIG_RELIABLE false
#define RTC0_INSTANCE_INDEX 0
#endif
#define RTC1_ENABLED 0
#if (RTC1_ENABLED == 1)
#define RTC1_CONFIG_FREQUENCY 32768
#define RTC1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define RTC1_CONFIG_RELIABLE false
#define RTC1_INSTANCE_INDEX (RTC0_ENABLED)
#endif
#define RTC_COUNT (RTC0_ENABLED+RTC1_ENABLED)
#define NRF_MAXIMUM_LATENCY_US 2000
/* RNG */
#define RNG_ENABLED 0
#if (RNG_ENABLED == 1)
#define RNG_CONFIG_ERROR_CORRECTION true
#define RNG_CONFIG_POOL_SIZE 8
#define RNG_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#endif
/* SPI */
#define SPI0_ENABLED 0
#if (SPI0_ENABLED == 1)
#define SPI0_USE_EASY_DMA 0
#define SPI0_CONFIG_SCK_PIN 2
#define SPI0_CONFIG_MOSI_PIN 3
#define SPI0_CONFIG_MISO_PIN 4
#define SPI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define SPI0_INSTANCE_INDEX 0
#endif
#define SPI1_ENABLED 0
#if (SPI1_ENABLED == 1)
#define SPI1_USE_EASY_DMA 0
#define SPI1_CONFIG_SCK_PIN 2
#define SPI1_CONFIG_MOSI_PIN 3
#define SPI1_CONFIG_MISO_PIN 4
#define SPI1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define SPI1_INSTANCE_INDEX (SPI0_ENABLED)
#endif
#define SPI2_ENABLED 0
#if (SPI2_ENABLED == 1)
#define SPI2_USE_EASY_DMA 0
#define SPI2_CONFIG_SCK_PIN 2
#define SPI2_CONFIG_MOSI_PIN 3
#define SPI2_CONFIG_MISO_PIN 4
#define SPI2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define SPI2_INSTANCE_INDEX (SPI0_ENABLED + SPI1_ENABLED)
#endif
#define SPI_COUNT (SPI0_ENABLED + SPI1_ENABLED + SPI2_ENABLED)
/* SPIS */
#define SPIS0_ENABLED 0
#if (SPIS0_ENABLED == 1)
#define SPIS0_CONFIG_SCK_PIN 2
#define SPIS0_CONFIG_MOSI_PIN 3
#define SPIS0_CONFIG_MISO_PIN 4
#define SPIS0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define SPIS0_INSTANCE_INDEX 0
#endif
#define SPIS1_ENABLED 0
#if (SPIS1_ENABLED == 1)
#define SPIS1_CONFIG_SCK_PIN 2
#define SPIS1_CONFIG_MOSI_PIN 3
#define SPIS1_CONFIG_MISO_PIN 4
#define SPIS1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define SPIS1_INSTANCE_INDEX SPIS0_ENABLED
#endif
#define SPIS2_ENABLED 0
#if (SPIS2_ENABLED == 1)
#define SPIS2_CONFIG_SCK_PIN 2
#define SPIS2_CONFIG_MOSI_PIN 3
#define SPIS2_CONFIG_MISO_PIN 4
#define SPIS2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define SPIS2_INSTANCE_INDEX (SPIS0_ENABLED + SPIS1_ENABLED)
#endif
#define SPIS_COUNT (SPIS0_ENABLED + SPIS1_ENABLED + SPIS2_ENABLED)
/* UART */
#define UART0_ENABLED 1
#if (UART0_ENABLED == 1)
#define UART0_CONFIG_HWFC NRF_UART_HWFC_DISABLED
#define UART0_CONFIG_PARITY NRF_UART_PARITY_EXCLUDED
#define UART0_CONFIG_BAUDRATE NRF_UART_BAUDRATE_38400
#define UART0_CONFIG_PSEL_TXD 6
#define UART0_CONFIG_PSEL_RXD 8
#define UART0_CONFIG_PSEL_CTS 7
#define UART0_CONFIG_PSEL_RTS 5
#define UART0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#ifdef NRF52
#define UART0_CONFIG_USE_EASY_DMA false
//Compile time flag
#define UART_EASY_DMA_SUPPORT 1
#define UART_LEGACY_SUPPORT 1
#endif //NRF52
#endif
#define TWI0_ENABLED 0
#if (TWI0_ENABLED == 1)
#define TWI0_CONFIG_FREQUENCY NRF_TWI_FREQ_100K
#define TWI0_CONFIG_SCL 0
#define TWI0_CONFIG_SDA 1
#define TWI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define TWI0_INSTANCE_INDEX 0
#endif
#define TWI1_ENABLED 0
#if (TWI1_ENABLED == 1)
#define TWI1_CONFIG_FREQUENCY NRF_TWI_FREQ_100K
#define TWI1_CONFIG_SCL 0
#define TWI1_CONFIG_SDA 1
#define TWI1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define TWI1_INSTANCE_INDEX (TWI0_ENABLED)
#endif
#define TWI_COUNT (TWI0_ENABLED+TWI1_ENABLED)
/* TWIS */
#define TWIS0_ENABLED 0
#if (TWIS0_ENABLED == 1)
#define TWIS0_CONFIG_ADDR0 0
#define TWIS0_CONFIG_ADDR1 0 /* 0: Disabled */
#define TWIS0_CONFIG_SCL 0
#define TWIS0_CONFIG_SDA 1
#define TWIS0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define TWIS0_INSTANCE_INDEX 0
#endif
#define TWIS1_ENABLED 0
#if (TWIS1_ENABLED == 1)
#define TWIS1_CONFIG_ADDR0 0
#define TWIS1_CONFIG_ADDR1 0 /* 0: Disabled */
#define TWIS1_CONFIG_SCL 0
#define TWIS1_CONFIG_SDA 1
#define TWIS1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define TWIS1_INSTANCE_INDEX (TWIS0_ENABLED)
#endif
#define TWIS_COUNT (TWIS0_ENABLED + TWIS1_ENABLED)
/* For more documentation see nrf_drv_twis.h file */
#define TWIS_ASSUME_INIT_AFTER_RESET_ONLY 0
/* For more documentation see nrf_drv_twis.h file */
#define TWIS_NO_SYNC_MODE 0
/**
* @brief Definition for patching PAN problems
*
* Set this definition to nonzero value to patch anomalies
* from MPW3 - first lunch microcontroller.
*
* Concerns:
* - PAN-29: TWIS: incorrect bits in ERRORSRC
* - PAN-30: TWIS: STOP task does not work as expected
*/
#define NRF_TWIS_PATCH_FOR_MPW3 1
/* QDEC */
#define QDEC_ENABLED 0
#if (QDEC_ENABLED == 1)
#define QDEC_CONFIG_REPORTPER NRF_QDEC_REPORTPER_10
#define QDEC_CONFIG_SAMPLEPER NRF_QDEC_SAMPLEPER_16384us
#define QDEC_CONFIG_PIO_A 1
#define QDEC_CONFIG_PIO_B 2
#define QDEC_CONFIG_PIO_LED 3
#define QDEC_CONFIG_LEDPRE 511
#define QDEC_CONFIG_LEDPOL NRF_QDEC_LEPOL_ACTIVE_HIGH
#define QDEC_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define QDEC_CONFIG_DBFEN false
#define QDEC_CONFIG_SAMPLE_INTEN false
#endif
/* SAADC */
#define SAADC_ENABLED 0
#if (SAADC_ENABLED == 1)
#define SAADC_CONFIG_RESOLUTION NRF_SAADC_RESOLUTION_10BIT
#define SAADC_CONFIG_OVERSAMPLE NRF_SAADC_OVERSAMPLE_DISABLED
#define SAADC_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#endif
/* LPCOMP */
#define LPCOMP_ENABLED 0
#if (LPCOMP_ENABLED == 1)
#define LPCOMP_CONFIG_REFERENCE NRF_LPCOMP_REF_SUPPLY_4_8
#define LPCOMP_CONFIG_DETECTION NRF_LPCOMP_DETECT_DOWN
#define LPCOMP_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define LPCOMP_CONFIG_INPUT NRF_LPCOMP_INPUT_0
#endif
/* WDT */
#define WDT_ENABLED 0
#if (WDT_ENABLED == 1)
#define WDT_CONFIG_BEHAVIOUR NRF_WDT_BEHAVIOUR_RUN_SLEEP
#define WDT_CONFIG_RELOAD_VALUE 2000
#define WDT_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_HIGH
#endif
/* SWI EGU */
#ifdef NRF52
#define EGU_ENABLED 0
#endif
#include "nrf_drv_config_validation.h"
#endif // NRF_DRV_CONFIG_H
/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
/** @cond To make doxygen skip this file */
/** @file
* This header contains defines with respect persistent storage that are specific to
* persistent storage implementation and application use case.
*/
#ifndef PSTORAGE_PL_H__
#define PSTORAGE_PL_H__
#include <stdint.h>
#include "nrf.h"
static __INLINE uint16_t pstorage_flash_page_size()
{
return (uint16_t)NRF_FICR->CODEPAGESIZE;
}
#define PSTORAGE_FLASH_PAGE_SIZE pstorage_flash_page_size() /**< Size of one flash page. */
#define PSTORAGE_FLASH_EMPTY_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */
#ifdef NRF51
#define BOOTLOADER_ADDRESS (NRF_UICR->BOOTLOADERADDR)
#elif defined NRF52
#define BOOTLOADER_ADDRESS (PSTORAGE_FLASH_EMPTY_MASK)
#endif
#define PSTORAGE_FLASH_PAGE_END \
((BOOTLOADER_ADDRESS != PSTORAGE_FLASH_EMPTY_MASK) \
? (BOOTLOADER_ADDRESS / PSTORAGE_FLASH_PAGE_SIZE) \
: NRF_FICR->CODESIZE)
#define PSTORAGE_NUM_OF_PAGES 2 /**< Number of flash pages allocated for the pstorage module excluding the swap page, configurable based on system requirements. */
#define PSTORAGE_MIN_BLOCK_SIZE 0x0010 /**< Minimum size of block that can be registered with the module. Should be configured based on system requirements, recommendation is not have this value to be at least size of word. */
#define PSTORAGE_DATA_START_ADDR ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_NUM_OF_PAGES - 1) \
* PSTORAGE_FLASH_PAGE_SIZE) /**< Start address for persistent data, configurable according to system requirements. */
#define PSTORAGE_DATA_END_ADDR ((PSTORAGE_FLASH_PAGE_END - 1) * PSTORAGE_FLASH_PAGE_SIZE) /**< End address for persistent data, configurable according to system requirements. */
#define PSTORAGE_SWAP_ADDR PSTORAGE_DATA_END_ADDR /**< Top-most page is used as swap area for clear and update. */
#define PSTORAGE_MAX_BLOCK_SIZE PSTORAGE_FLASH_PAGE_SIZE /**< Maximum size of block that can be registered with the module. Should be configured based on system requirements. And should be greater than or equal to the minimum size. */
#define PSTORAGE_CMD_QUEUE_SIZE 30 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */
/** Abstracts persistently memory block identifier. */
typedef uint32_t pstorage_block_t;
typedef struct
{
uint32_t module_id; /**< Module ID.*/
pstorage_block_t block_id; /**< Block ID.*/
} pstorage_handle_t;
typedef uint16_t pstorage_size_t; /** Size of length and offset fields. */
/**@brief Handles Flash Access Result Events. To be called in the system event dispatcher of the application. */
void pstorage_sys_event_handler (uint32_t sys_evt);
#endif // PSTORAGE_PL_H__
/** @} */
/** @endcond */
/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
#ifndef SDK_CONFIG_H__
#define SDK_CONFIG_H__
/**
* @defgroup sdk_config SDK Configuration
* @{
* @ingroup sdk_common
* @{
* @details All parameters that allow configuring/tuning the SDK based on application/ use case
* are defined here.
*/
/**
* @defgroup mem_manager_config Memory Manager Configuration
* @{
* @addtogroup sdk_config
* @{
* @details This section defines configuration of memory manager module.
*/
/**
* @brief Maximum memory blocks identified as 'small' blocks.
*
* @details Maximum memory blocks identified as 'small' blocks.
* Minimum value : 0 (Setting to 0 disables all 'small' blocks)
* Maximum value : 255
* Dependencies : None.
*/
#define MEMORY_MANAGER_SMALL_BLOCK_COUNT 8
/**
* @brief Size of each memory blocks identified as 'small' block.
*
* @details Size of each memory blocks identified as 'small' block.
* Memory block are recommended to be word-sized.
* Minimum value : 32
* Maximum value : A value less than the next pool size. If only small pool is used, this
* can be any value based on availability of RAM.
* Dependencies : MEMORY_MANAGER_SMALL_BLOCK_COUNT is non-zero.
*/
#define MEMORY_MANAGER_SMALL_BLOCK_SIZE 128
/**
* @brief Maximum memory blocks identified as 'medium' blocks.
*
* @details Maximum memory blocks identified as 'medium' blocks.
* Minimum value : 0 (Setting to 0 disables all 'medium' blocks)
* Maximum value : 255
* Dependencies : None.
*/
#define MEMORY_MANAGER_MEDIUM_BLOCK_COUNT 4
/**
* @brief Size of each memory blocks identified as 'medium' block.
*
* @details Size of each memory blocks identified as 'medium' block.
* Memory block are recommended to be word-sized.
* Minimum value : A value greater than the small pool size if defined, else 32.
* Maximum value : A value less than the next pool size. If only medium pool is used, this
* can be any value based on availability of RAM.
* Dependencies : MEMORY_MANAGER_MEDIUM_BLOCK_COUNT is non-zero.
*/
#define MEMORY_MANAGER_MEDIUM_BLOCK_SIZE 256
/**
* @brief Maximum memory blocks identified as 'medium' blocks.
*
* @details Maximum memory blocks identified as 'medium' blocks.
* Minimum value : 0 (Setting to 0 disables all 'large' blocks)
* Maximum value : 255
* Dependencies : None.
*/
#define MEMORY_MANAGER_LARGE_BLOCK_COUNT 3
/**
* @brief Size of each memory blocks identified as 'medium' block.
*
* @details Size of each memory blocks identified as 'medium' block.
* Memory block are recommended to be word-sized.
* Minimum value : A value greater than the small &/ medium pool size if defined, else 32.
* Maximum value : Any value based on availability of RAM.
* Dependencies : MEMORY_MANAGER_MEDIUM_BLOCK_COUNT is non-zero.
*/
#define MEMORY_MANAGER_LARGE_BLOCK_SIZE 1024
/**
* @brief Disable debug trace in the module.
*
* @details Set this define to 1 to enable debug trace in the module, else set to 0.
* Possible values : 0 or 1.
* Dependencies : ENABLE_DEBUG_LOG_SUPPORT. If this flag is not defined, no
* trace is observed even if this define is set to 1.
*/
#define MEM_MANAGER_ENABLE_LOGS 0
/**
* @brief Disables API parameter checks in the module.
*
* @details Set this define to 1 to disable checks on API parameters in the module.
* API parameter checks are added to ensure right parameters are passed to the
* module. These checks are useful during development phase but be redundant
* once application is developed. Disabling this can result in some code saving.
* Possible values : 0 or 1.
* Dependencies : None.
*/
#define MEM_MANAGER_DISABLE_API_PARAM_CHECK 0
/** @} */
/** @} */
/**
* @defgroup iot_context_manager Context Manager Configurations.
* @{
* @addtogroup iot_config
* @{
* @details This section defines configuration of Context Manager.
*/
/**
* @brief Disable debug trace in the module.
*
* @details Set this define to 1 to enable debug trace in the module, else set to 0.
* Possible values : 0 or 1.
* Dependencies : ENABLE_DEBUG_LOG_SUPPORT. If this flag is not defined, no
* trace is observed even if this define is set to 1.
*/
#define IOT_CONTEXT_MANAGER_ENABLE_LOGS 0
/**
* @brief Disables API parameter checks in the module.
*
* @details Set this define to 1 to disable checks on API parameters in the module.
* API parameter checks are added to ensure right parameters are passed to the
* module. These checks are useful during development phase but be redundant
* once application is developed. Disabling this can result in some code saving.
* Possible values : 0 or 1.
* Dependencies : None.
*/
#define IOT_CONTEXT_MANAGER_DISABLE_API_PARAM_CHECK 0
/**
* @brief Maximum number of supported context identifiers.
*
* @details Maximum value of 16 is preferable to correct decompression.
* Minimum value : 1
* Maximum value : 16
* Dependencies : None.
*/
#define IOT_CONTEXT_MANAGER_MAX_CONTEXTS 16
/**
* @brief Maximum number of supported context's table.
*
* @details If value is equal to BLE_IPSP_MAX_CHANNELS then all interface will have
* its own table which is preferable.
* Minimum value : 1
* Maximum value : BLE_IPSP_MAX_CHANNELS
* Dependencies : None.
*/
#define IOT_CONTEXT_MANAGER_MAX_TABLES 1
/** @} */
/** @} */
/**
* @defgroup lwip_nrf_driver nRF lwIP driver
* @{
* @addtogroup iot_config
* @{
* @details This section defines configuration of nRF lwIP driver.
*/
/**
* @brief Disable debug trace in the module.
*
* @details Set this define to 1 to enable debug trace in the module, else set to 0.
* Possible values : 0 or 1.
* Dependencies : ENABLE_DEBUG_LOG_SUPPORT. If this flag is not defined, no
* trace is observed even if this define is set to 1.
*/
#define NRF_LWIP_DRIVER_ENABLE_LOGS 0
/** @} */
/** @} */
/**
* @defgroup iot_timer IoT SDK Timer
* @{
* @addtogroup iot_config
* @{
* @details This section defines configuration of the IoT Timer.
*/
/**
* @brief Wall clock resolution in milliseconds.
*
* @details The wall clock of the IoT Timer module has to be updated from an external source at
* regular intervals. This define needs to be set to the interval between updates.
* Minimum value : 1.
* Dependencies : None.
*
*/
#define IOT_TIMER_RESOLUTION_IN_MS 100
/**
* @brief Disables API parameter checks in the module.
*
* @details Set this define to 1 to disable checks on API parameters in the module.
* API parameter checks are added to ensure right parameters are passed to the
* module. These checks are useful during development phase but be redundant
* once application is developed. Disabling this can result in some code saving.
* Possible values : 0 or 1.
* Dependencies : None.
*/
#define IOT_TIMER_DISABLE_API_PARAM_CHECK 0
/** @} */
/** @} */
#endif // SDK_CONFIG_H__
/*
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!
*/
.syntax unified
.arch armv7e-m
.section .stack
.align 3
#ifdef __STACK_SIZE
.equ Stack_Size, __STACK_SIZE
#else
.equ Stack_Size, 4096
#endif
.globl __StackTop
.globl __StackLimit
__StackLimit:
.space Stack_Size
.size __StackLimit, . - __StackLimit
__StackTop:
.size __StackTop, . - __StackTop
.section .heap
.align 3
#ifdef __HEAP_SIZE
.equ Heap_Size, __HEAP_SIZE
#else
.equ Heap_Size, 4096
#endif
.globl __HeapBase
.globl __HeapLimit
__HeapBase:
.if Heap_Size
.space Heap_Size
.endif
.size __HeapBase, . - __HeapBase
__HeapLimit:
.size __HeapLimit, . - __HeapLimit
.section .Vectors
.align 2
.globl __Vectors
__Vectors:
.long __StackTop /* Top of Stack */
.long Reset_Handler
.long NMI_Handler
.long HardFault_Handler
.long MemoryManagement_Handler
.long BusFault_Handler
.long UsageFault_Handler
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long SVC_Handler
.long 0 /*Reserved */
.long 0 /*Reserved */
.long PendSV_Handler
.long SysTick_Handler
/* External Interrupts */
.long POWER_CLOCK_IRQHandler
.long RADIO_IRQHandler
.long UARTE0_UART0_IRQHandler
.long SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler
.long SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler
.long NFCT_IRQHandler
.long GPIOTE_IRQHandler
.long SAADC_IRQHandler
.long TIMER0_IRQHandler
.long TIMER1_IRQHandler
.long TIMER2_IRQHandler
.long RTC0_IRQHandler
.long TEMP_IRQHandler
.long RNG_IRQHandler
.long ECB_IRQHandler
.long CCM_AAR_IRQHandler
.long WDT_IRQHandler
.long RTC1_IRQHandler
.long QDEC_IRQHandler
.long COMP_LPCOMP_IRQHandler
.long SWI0_EGU0_IRQHandler
.long SWI1_EGU1_IRQHandler
.long SWI2_EGU2_IRQHandler
.long SWI3_EGU3_IRQHandler
.long SWI4_EGU4_IRQHandler
.long SWI5_EGU5_IRQHandler
.long TIMER3_IRQHandler
.long TIMER4_IRQHandler
.long PWM0_IRQHandler
.long PDM_IRQHandler
.long 0 /*Reserved */
.long 0 /*Reserved */
.long MWU_IRQHandler
.long PWM1_IRQHandler
.long PWM2_IRQHandler
.long SPIM2_SPIS2_SPI2_IRQHandler
.long RTC2_IRQHandler
.long I2S_IRQHandler
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.long 0 /*Reserved */
.size __Vectors, . - __Vectors
/* Reset Handler */
.text
.thumb
.thumb_func
.align 1
.globl Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
.fnstart
/* Loop to copy data from read only memory to RAM. The ranges
* of copy from/to are specified by following symbols evaluated in
* linker script.
* __etext: End of code section, i.e., begin of data sections to copy from.
* __data_start__/__data_end__: RAM address range that data should be
* copied to. Both must be aligned to 4 bytes boundary. */
ldr r1, =__etext
ldr r2, =__data_start__
ldr r3, =__data_end__
subs r3, r2
ble .LC0
.LC1:
subs r3, 4
ldr r0, [r1,r3]
str r0, [r2,r3]
bgt .LC1
.LC0:
LDR R0, =SystemInit
BLX R0
LDR R0, =_start
BX R0
.pool
.cantunwind
.fnend
.size Reset_Handler,.-Reset_Handler
.section ".text"
/* Dummy Exception Handlers (infinite loops which can be modified) */
.weak NMI_Handler
.type NMI_Handler, %function
NMI_Handler:
B .
.size NMI_Handler, . - NMI_Handler
.weak HardFault_Handler
.type HardFault_Handler, %function
HardFault_Handler:
B .
.size HardFault_Handler, . - HardFault_Handler
.weak MemoryManagement_Handler
.type MemoryManagement_Handler, %function
MemoryManagement_Handler:
B .
.size MemoryManagement_Handler, . - MemoryManagement_Handler
.weak BusFault_Handler
.type BusFault_Handler, %function
BusFault_Handler:
B .
.size BusFault_Handler, . - BusFault_Handler
.weak UsageFault_Handler
.type UsageFault_Handler, %function
UsageFault_Handler:
B .
.size UsageFault_Handler, . - UsageFault_Handler
.weak SVC_Handler
.type SVC_Handler, %function
SVC_Handler:
B .
.size SVC_Handler, . - SVC_Handler
.weak PendSV_Handler
.type PendSV_Handler, %function
PendSV_Handler:
B .
.size PendSV_Handler, . - PendSV_Handler
.weak SysTick_Handler
.type SysTick_Handler, %function
SysTick_Handler:
B .
.size SysTick_Handler, . - SysTick_Handler
/* IRQ Handlers */
.globl Default_Handler
.type Default_Handler, %function
Default_Handler:
B .
.size Default_Handler, . - Default_Handler
.macro IRQ handler
.weak \handler
.set \handler, Default_Handler
.endm
IRQ POWER_CLOCK_IRQHandler
IRQ RADIO_IRQHandler
IRQ UARTE0_UART0_IRQHandler
IRQ SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler
IRQ SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler
IRQ NFCT_IRQHandler
IRQ GPIOTE_IRQHandler
IRQ SAADC_IRQHandler
IRQ TIMER0_IRQHandler
IRQ TIMER1_IRQHandler
IRQ TIMER2_IRQHandler
IRQ RTC0_IRQHandler
IRQ TEMP_IRQHandler
IRQ RNG_IRQHandler
IRQ ECB_IRQHandler
IRQ CCM_AAR_IRQHandler
IRQ WDT_IRQHandler
IRQ RTC1_IRQHandler
IRQ QDEC_IRQHandler
IRQ COMP_LPCOMP_IRQHandler
IRQ SWI0_EGU0_IRQHandler
IRQ SWI1_EGU1_IRQHandler
IRQ SWI2_EGU2_IRQHandler
IRQ SWI3_EGU3_IRQHandler
IRQ SWI4_EGU4_IRQHandler
IRQ SWI5_EGU5_IRQHandler
IRQ TIMER3_IRQHandler
IRQ TIMER4_IRQHandler
IRQ PWM0_IRQHandler
IRQ PDM_IRQHandler
IRQ MWU_IRQHandler
IRQ PWM1_IRQHandler
IRQ PWM2_IRQHandler
IRQ SPIM2_SPIS2_SPI2_IRQHandler
IRQ RTC2_IRQHandler
IRQ I2S_IRQHandler
.end
/* Linker script to configure memory regions. */
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x1f000, LENGTH = 0x61000
RAM (rwx) : ORIGIN = 0x20002800, LENGTH = 0xd800
}
INCLUDE "nrf5x_common.ld"
\ No newline at end of file
/* Linker script for Nordic Semiconductor nRF5 devices
*
* Version: Sourcery G++ 4.5-1
* Support: https://support.codesourcery.com/GNUToolchain/
*
* Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc.
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
/* Linker script to place sections and symbol values. Should be used together
* with other linker script that defines memory regions FLASH and RAM.
* It references following symbols, which must be defined in code:
* Reset_Handler : Entry of reset handler
*
* It defines following symbols, which code can use without definition:
* __exidx_start
* __exidx_end
* __etext
* __data_start__
* __preinit_array_start
* __preinit_array_end
* __init_array_start
* __init_array_end
* __fini_array_start
* __fini_array_end
* __data_end__
* __bss_start__
* __bss_end__
* __end__
* end
* __HeapLimit
* __StackLimit
* __StackTop
* __stack
*/
ENTRY(Reset_Handler)
SECTIONS
{
.text :
{
KEEP(*(.Vectors))
*(.text*)
KEEP(*(.init))
KEEP(*(.fini))
/* .ctors */
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
/* .dtors */
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)
*(.rodata*)
*(.eh_frame*)
. = ALIGN(4);
} > FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
. = ALIGN(4);
} > FLASH
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
. = ALIGN(4);
} > FLASH
__exidx_end = .;
__etext = .;
.data : AT (__etext)
{
__data_start__ = .;
*(vtable)
*(.data*)
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
/* init data */
PROVIDE_HIDDEN (__init_array_start = .);
*(SORT(.init_array.*))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .);
*(SORT(.fini_array.*))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);
*(.jcr)
. = ALIGN(4);
/* All data end */
__data_end__ = .;
} > RAM
.bss :
{
. = ALIGN(4);
__bss_start__ = .;
*(.bss*)
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
} > RAM
.heap (COPY):
{
__end__ = .;
end = __end__;
*(.heap*)
__HeapLimit = .;
} > RAM
/* .stack_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later */
.stack_dummy (COPY):
{
*(.stack*)
} > RAM
/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);
/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
}
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#include "bleconfig.h"
#include "myboard.h"
#include "../../mongoose.h"
/*
* This is a callback invoked by Mongoose to signal that a poll is needed soon.
* Since we're in a tight polling loop anyway (see below), we don't need to do anything.
*/
void mg_lwip_mgr_schedule_poll(struct mg_mgr *mgr) {
}
// Define an event handler function
void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
if (ev == MG_EV_POLL) return;
/* printf("ev %d\r\n", ev); */
switch (ev) {
case MG_EV_ACCEPT: {
char addr[32];
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
printf("%p: Connection from %s\r\n", nc, addr);
break;
}
case MG_EV_HTTP_REQUEST: {
struct http_message *hm = (struct http_message *) ev_data;
char addr[32];
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
printf("%p: %.*s %.*s\r\n", nc, (int) hm->method.len, hm->method.p,
(int) hm->uri.len, hm->uri.p);
mg_send_response_line(nc, 200,
"Content-Type: text/html\r\n"
"Connection: close");
mg_printf(nc,
"\r\n<h1>Hello, %s!</h1>\r\n"
"You asked for %.*s\r\n",
addr, (int) hm->uri.len, hm->uri.p);
nc->flags |= MG_F_SEND_AND_CLOSE;
LEDS_INVERT(LED_THREE);
break;
}
case MG_EV_CLOSE: {
printf("%p: Connection closed\r\n", nc);
break;
}
}
}
/**
* @brief Function for application main entry.
*/
int main(void)
{
cs_log_set_file(stdout);
bleconfig_init();
{
struct mg_mgr mgr;
mg_mgr_init(&mgr, NULL); // Initialize event manager object
// Note that many connections can be added to a single event manager
// Connections can be created at any point, e.g. in event handler function
const char *err;
struct mg_bind_opts opts = {};
opts.error_string = &err;
struct mg_connection *nc = mg_bind_opt(&mgr, "80", ev_handler, opts); // Create listening connection and add it to the event manager
if (nc == NULL) {
printf("Failed to create listener: %s\n", err);
return 1;
}
mg_set_protocol_http_websocket(nc);
for (;;) { // Start infinite event loop
bleconfig_poll();
sys_check_timeouts();
mg_mgr_poll(&mgr, 0);
}
mg_mgr_free(&mgr);
return 0;
}
}
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
/* clang-format off */
#include "boards.h"
#define LED_ONE BSP_LED_0_MASK /**< Is on when device is advertising. */
#define LED_TWO BSP_LED_1_MASK /**< Is on when device is connected. */
#define LED_THREE BSP_LED_2_MASK
#define LED_FOUR BSP_LED_3_MASK
#define TCP_CONNECTED_LED BSP_LED_2_MASK /**< Is on when a TCP connection is established. */
#define DISPLAY_LED_0 BSP_LED_0_MASK /**< LED used for displaying mod 4 of data payload received on UDP port. */
#define DISPLAY_LED_1 BSP_LED_1_MASK /**< LED used for displaying mod 4 of data payload received on UDP port. */
#define DISPLAY_LED_2 BSP_LED_2_MASK /**< LED used for displaying mod 4 of data payload received on UDP port. */
#define DISPLAY_LED_3 BSP_LED_3_MASK /**< LED used for displaying mod 4 of data payload received on UDP port. */
#define ALL_APP_LED (BSP_LED_0_MASK | BSP_LED_1_MASK | \
BSP_LED_2_MASK | BSP_LED_3_MASK) /**< Define used for simultaneous operation of all application LEDs. */
README.txt for the SEGGER RTT Implementation Pack.
Date: 17 Dec 2014
Included files:
===============
Root Directory
- Examples
- RTT_MenuApp.c - Sample application to demonstrate RTT bi-directional functionality. No OS.
- RTT_embOS_SpeedTestApp.c - Sample application for measuring RTT performance. embOS needed.
- RTT
- SEGGER_RTT.c - The RTT implementation.
- SEGGER_RTT.h - Header for RTT implementation.
- SEGGER_RTT_Conf.h - Pre-processor configuration for the RTT implementation.
- SEGGER_RTT_Printf.c - Simple implementation of printf to write formatted strings via RTT.
- Syscalls
- RTT_Syscalls_GCC.c - Low-level syscalls to retarget printf() to RTT with GCC / Newlib.
- RTT_Syscalls_IAR.c - Low-level syscalls to retarget printf() to RTT with IAR compiler.
- RTT_Syscalls_KEIL.c - Low-level syscalls to retarget printf() to RTT with KEIL/uVision compiler.
\ No newline at end of file
/*********************************************************************
* SEGGER MICROCONTROLLER GmbH & Co. KG *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 2014-2014 SEGGER Microcontroller GmbH & Co. KG *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
----------------------------------------------------------------------
File : SEGGER_RTT.c
Date : 17 Dec 2014
Purpose : Implementation of SEGGER real-time terminal (RTT) which allows
real-time terminal communication on targets which support
debugger memory accesses while the CPU is running.
Type "int" is assumed to be 32-bits in size
H->T Host to target communication
T->H Target to host communication
RTT channel 0 is always present and reserved for Terminal usage.
Name is fixed to "Terminal"
---------------------------END-OF-HEADER------------------------------
*/
#include "SEGGER_RTT_Conf.h"
#include "SEGGER_RTT.h"
#include <string.h> // for memcpy
/*********************************************************************
*
* Defines, configurable
*
**********************************************************************
*/
#ifndef BUFFER_SIZE_UP
#define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host
#endif
#ifndef BUFFER_SIZE_DOWN
#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input)
#endif
#ifndef SEGGER_RTT_MAX_NUM_UP_BUFFERS
#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (1) // Number of up-buffers (T->H) available on this target
#endif
#ifndef SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (1) // Number of down-buffers (H->T) available on this target
#endif
#ifndef SEGGER_RTT_LOCK
#define SEGGER_RTT_LOCK()
#endif
#ifndef SEGGER_RTT_UNLOCK
#define SEGGER_RTT_UNLOCK()
#endif
#ifndef SEGGER_RTT_IN_RAM
#define SEGGER_RTT_IN_RAM (0)
#endif
/*********************************************************************
*
* Defines, fixed
*
**********************************************************************
*/
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MEMCPY(a, b, c) memcpy((a),(b),(c))
//
// For some environments, NULL may not be defined until certain headers are included
//
#ifndef NULL
#define NULL 0
#endif
/*********************************************************************
*
* Types
*
**********************************************************************
*/
//
// Description for a circular buffer (also called "ring buffer")
// which is used as up- (T->H) or down-buffer (H->T)
//
typedef struct {
const char* sName; // Optional name. Standard names so far are: "Terminal", "VCom"
char* pBuffer; // Pointer to start of buffer
int SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
volatile int WrOff; // Position of next item to be written by either host (down-buffer) or target (up-buffer). Must be volatile since it may be modified by host (down-buffer)
volatile int RdOff; // Position of next item to be read by target (down-buffer) or host (up-buffer). Must be volatile since it may be modified by host (up-buffer)
int Flags; // Contains configuration flags
} RING_BUFFER;
//
// RTT control block which describes the number of buffers available
// as well as the configuration for each buffer
//
//
typedef struct {
char acID[16]; // Initialized to "SEGGER RTT"
int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
RING_BUFFER aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host
RING_BUFFER aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target
} SEGGER_RTT_CB;
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
//
// Allocate buffers for channel 0
//
static char _acUpBuffer [BUFFER_SIZE_UP];
static char _acDownBuffer[BUFFER_SIZE_DOWN];
//
// Initialize SEGGER Real-time-Terminal control block (CB)
//
static SEGGER_RTT_CB _SEGGER_RTT = {
#if SEGGER_RTT_IN_RAM
"SEGGER RTTI",
#else
"SEGGER RTT",
#endif
SEGGER_RTT_MAX_NUM_UP_BUFFERS,
SEGGER_RTT_MAX_NUM_DOWN_BUFFERS,
{{ "Terminal", &_acUpBuffer[0], sizeof(_acUpBuffer), 0, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP }},
{{ "Terminal", &_acDownBuffer[0], sizeof(_acDownBuffer), 0, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP }},
};
static char _ActiveTerminal;
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _strlen
*
* Function description
* ANSI compatible function to determine the length of a string
*
* Return value
* Length of string in bytes.
*
* Parameters
* s Pointer to \0 terminated string.
*
* Notes
* (1) s needs to point to an \0 terminated string. Otherwise proper functionality of this function is not guaranteed.
*/
static int _strlen(const char* s) {
int Len;
Len = 0;
if (s == NULL) {
return 0;
}
do {
if (*s == 0) {
break;
}
Len++;
s++;
} while (1);
return Len;
}
/*********************************************************************
*
* _Init
*
* Function description
* In case SEGGER_RTT_IN_RAM is defined,
* _Init() modifies the ID of the RTT CB to allow identifying the
* RTT Control Block Structure in the data segment.
*/
static void _Init(void) {
#if SEGGER_RTT_IN_RAM
if (_SEGGER_RTT.acID[10] == 'I') {
_SEGGER_RTT.acID[10] = '\0';
}
#endif
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* SEGGER_RTT_Read
*
* Function description
* Reads characters from SEGGER real-time-terminal control block
* which have been previously stored by the host.
*
* Parameters
* BufferIndex Index of Down-buffer to be used. (e.g. 0 for "Terminal")
* pBuffer Pointer to buffer provided by target application, to copy characters from RTT-down-buffer to.
* BufferSize Size of the target application buffer
*
* Return values
* Number of bytes that have been read
*/
int SEGGER_RTT_Read(unsigned BufferIndex, char* pBuffer, unsigned BufferSize) {
int NumBytesRem;
unsigned NumBytesRead;
int RdOff;
int WrOff;
SEGGER_RTT_LOCK();
_Init();
RdOff = _SEGGER_RTT.aDown[BufferIndex].RdOff;
WrOff = _SEGGER_RTT.aDown[BufferIndex].WrOff;
NumBytesRead = 0;
//
// Read from current read position to wrap-around of buffer, first
//
if (RdOff > WrOff) {
NumBytesRem = _SEGGER_RTT.aDown[BufferIndex].SizeOfBuffer - RdOff;
NumBytesRem = MIN(NumBytesRem, (int)BufferSize);
MEMCPY(pBuffer, _SEGGER_RTT.aDown[BufferIndex].pBuffer + RdOff, NumBytesRem);
NumBytesRead += NumBytesRem;
pBuffer += NumBytesRem;
BufferSize -= NumBytesRem;
RdOff += NumBytesRem;
//
// Handle wrap-around of buffer
//
if (RdOff == _SEGGER_RTT.aDown[BufferIndex].SizeOfBuffer) {
RdOff = 0;
}
}
//
// Read remaining items of buffer
//
NumBytesRem = WrOff - RdOff;
NumBytesRem = MIN(NumBytesRem, (int)BufferSize);
if (NumBytesRem > 0) {
MEMCPY(pBuffer, _SEGGER_RTT.aDown[BufferIndex].pBuffer + RdOff, NumBytesRem);
NumBytesRead += NumBytesRem;
pBuffer += NumBytesRem;
BufferSize -= NumBytesRem;
RdOff += NumBytesRem;
}
if (NumBytesRead) {
_SEGGER_RTT.aDown[BufferIndex].RdOff = RdOff;
}
SEGGER_RTT_UNLOCK();
return NumBytesRead;
}
/*********************************************************************
*
* SEGGER_RTT_Write
*
* Function description
* Stores a specified number of characters in SEGGER RTT
* control block which is then read by the host.
*
* Parameters
* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")
* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.
* NumBytes Number of bytes to be stored in the SEGGER RTT control block.
*
* Return values
* Number of bytes which have been stored in the "Up"-buffer.
*
* Notes
* (1) If there is not enough space in the "Up"-buffer, remaining characters of pBuffer are dropped.
*/
int SEGGER_RTT_Write(unsigned BufferIndex, const char* pBuffer, unsigned NumBytes) {
int NumBytesToWrite;
unsigned NumBytesWritten;
int RdOff;
//
// Target is not allowed to perform other RTT operations while string still has not been stored completely.
// Otherwise we would probably end up with a mixed string in the buffer.
//
SEGGER_RTT_LOCK();
_Init();
//
// In case we are not in blocking mode,
// we need to calculate, how many bytes we can put into the buffer at all.
//
if ((_SEGGER_RTT.aUp[BufferIndex].Flags & SEGGER_RTT_MODE_MASK) != SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL) {
RdOff = _SEGGER_RTT.aUp[BufferIndex].RdOff;
NumBytesToWrite = RdOff - _SEGGER_RTT.aUp[BufferIndex].WrOff - 1;
if (NumBytesToWrite < 0) {
NumBytesToWrite += _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer;
}
//
// If the complete data does not fit in the buffer, check if we have to skip it completely or trim the data
//
if ((int)NumBytes > NumBytesToWrite) {
if ((_SEGGER_RTT.aUp[BufferIndex].Flags & SEGGER_RTT_MODE_MASK) == SEGGER_RTT_MODE_NO_BLOCK_SKIP) {
SEGGER_RTT_UNLOCK();
return 0;
} else {
NumBytes = NumBytesToWrite;
}
}
}
//
// Early out if nothing is to do
//
if (NumBytes == 0) {
SEGGER_RTT_UNLOCK();
return 0;
}
//
// Write data to buffer and handle wrap-around if necessary
//
NumBytesWritten = 0;
do {
RdOff = _SEGGER_RTT.aUp[BufferIndex].RdOff; // May be changed by host (debug probe) in the meantime
NumBytesToWrite = RdOff - _SEGGER_RTT.aUp[BufferIndex].WrOff - 1;
if (NumBytesToWrite < 0) {
NumBytesToWrite += _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer;
}
NumBytesToWrite = MIN(NumBytesToWrite, (_SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer - _SEGGER_RTT.aUp[BufferIndex].WrOff)); // Number of bytes that can be written until buffer wrap-around
NumBytesToWrite = MIN(NumBytesToWrite, (int)NumBytes);
MEMCPY(_SEGGER_RTT.aUp[BufferIndex].pBuffer + _SEGGER_RTT.aUp[BufferIndex].WrOff, pBuffer, NumBytesToWrite);
NumBytesWritten += NumBytesToWrite;
pBuffer += NumBytesToWrite;
NumBytes -= NumBytesToWrite;
_SEGGER_RTT.aUp[BufferIndex].WrOff += NumBytesToWrite;
if (_SEGGER_RTT.aUp[BufferIndex].WrOff == _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer) {
_SEGGER_RTT.aUp[BufferIndex].WrOff = 0;
}
} while (NumBytes);
SEGGER_RTT_UNLOCK();
return NumBytesWritten;
}
/*********************************************************************
*
* SEGGER_RTT_WriteString
*
* Function description
* Stores string in SEGGER RTT control block.
* This data is read by the host.
*
* Parameters
* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")
* s Pointer to string.
*
* Return values
* Number of bytes which have been stored in the "Up"-buffer.
*
* Notes
* (1) If there is not enough space in the "Up"-buffer, depending on configuration,
* remaining characters may be dropped or RTT module waits until there is more space in the buffer.
* (2) String passed to this function has to be \0 terminated
* (3) \0 termination character is *not* stored in RTT buffer
*/
int SEGGER_RTT_WriteString(unsigned BufferIndex, const char* s) {
int Len;
Len = _strlen(s);
return SEGGER_RTT_Write(BufferIndex, s, Len);
}
/*********************************************************************
*
* SEGGER_RTT_GetKey
*
* Function description
* Reads one character from the SEGGER RTT buffer.
* Host has previously stored data there.
*
* Return values
* < 0 No character available (buffer empty).
* >= 0 Character which has been read. (Possible values: 0 - 255)
*
* Notes
* (1) This function is only specified for accesses to RTT buffer 0.
*/
int SEGGER_RTT_GetKey(void) {
char c;
int r;
r = SEGGER_RTT_Read(0, &c, 1);
if (r == 1) {
return (int)(unsigned char)c;
}
return -1;
}
/*********************************************************************
*
* SEGGER_RTT_WaitKey
*
* Function description
* Waits until at least one character is avaible in the SEGGER RTT buffer.
* Once a character is available, it is read and this function returns.
*
* Return values
* >=0 Character which has been read.
*
* Notes
* (1) This function is only specified for accesses to RTT buffer 0
* (2) This function is blocking if no character is present in RTT buffer
*/
int SEGGER_RTT_WaitKey(void) {
int r;
do {
r = SEGGER_RTT_GetKey();
} while (r < 0);
return r;
}
/*********************************************************************
*
* SEGGER_RTT_HasKey
*
* Function description
* Checks if at least one character for reading is available in the SEGGER RTT buffer.
*
* Return values
* 0 No characters are available to read.
* 1 At least one character is available.
*
* Notes
* (1) This function is only specified for accesses to RTT buffer 0
*/
int SEGGER_RTT_HasKey(void) {
int RdOff;
_Init();
RdOff = _SEGGER_RTT.aDown[0].RdOff;
if (RdOff != _SEGGER_RTT.aDown[0].WrOff) {
return 1;
}
return 0;
}
/*********************************************************************
*
* SEGGER_RTT_ConfigUpBuffer
*
* Function description
* Run-time configuration of a specific up-buffer (T->H).
* Buffer to be configured is specified by index.
* This includes: Buffer address, size, name, flags, ...
*
* Return value
* >= 0 O.K.
* < 0 Error
*/
int SEGGER_RTT_ConfigUpBuffer(unsigned BufferIndex, const char* sName, char* pBuffer, int BufferSize, int Flags) {
_Init();
if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {
SEGGER_RTT_LOCK();
if (BufferIndex > 0) {
_SEGGER_RTT.aUp[BufferIndex].sName = sName;
_SEGGER_RTT.aUp[BufferIndex].pBuffer = pBuffer;
_SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer = BufferSize;
_SEGGER_RTT.aUp[BufferIndex].RdOff = 0;
_SEGGER_RTT.aUp[BufferIndex].WrOff = 0;
}
_SEGGER_RTT.aUp[BufferIndex].Flags = Flags;
SEGGER_RTT_UNLOCK();
return 0;
}
return -1;
}
/*********************************************************************
*
* SEGGER_RTT_ConfigDownBuffer
*
* Function description
* Run-time configuration of a specific down-buffer (H->T).
* Buffer to be configured is specified by index.
* This includes: Buffer address, size, name, flags, ...
*
* Return value
* >= 0 O.K.
* < 0 Error
*/
int SEGGER_RTT_ConfigDownBuffer(unsigned BufferIndex, const char* sName, char* pBuffer, int BufferSize, int Flags) {
_Init();
if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {
SEGGER_RTT_LOCK();
if (BufferIndex > 0) {
_SEGGER_RTT.aDown[BufferIndex].sName = sName;
_SEGGER_RTT.aDown[BufferIndex].pBuffer = pBuffer;
_SEGGER_RTT.aDown[BufferIndex].SizeOfBuffer = BufferSize;
_SEGGER_RTT.aDown[BufferIndex].RdOff = 0;
_SEGGER_RTT.aDown[BufferIndex].WrOff = 0;
}
_SEGGER_RTT.aDown[BufferIndex].Flags = Flags;
SEGGER_RTT_UNLOCK();
return 0;
}
return -1;
}
/*********************************************************************
*
* SEGGER_RTT_Init
*
* Function description
* Initializes the RTT Control Block.
* Should be used in RAM targets, at start of the application.
*
*/
void SEGGER_RTT_Init (void) {
_Init();
}
/*********************************************************************
*
* SEGGER_RTT_SetTerminal
*
* Function description
* Sets the terminal to be used for output on channel 0.
*
*/
void SEGGER_RTT_SetTerminal (char TerminalId) {
char ac[2];
ac[0] = 0xFF;
if (TerminalId < 10) {
ac[1] = '0' + TerminalId;
} else if (TerminalId < 16) {
ac[1] = 'A' + (TerminalId - 0x0A);
} else {
return; // RTT only supports up to 16 virtual terminals.
}
_ActiveTerminal = TerminalId;
SEGGER_RTT_Write(0, ac, 2);
}
/*********************************************************************
*
* SEGGER_RTT_TerminalOut
*
* Function description
* Writes a string to the given terminal
* without changing the terminal for channel 0.
*
*/
int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) {
char ac[2];
int r;
ac[0] = 0xFF;
if (TerminalId < 10) {
ac[1] = '0' + TerminalId;
} else if (TerminalId < 16) {
ac[1] = 'A' + (TerminalId - 0x0A);
} else {
return -1; // RTT only supports up to 16 virtual terminals.
}
SEGGER_RTT_Write(0, ac, 2);
r = SEGGER_RTT_WriteString(0, s);
if (TerminalId < 10) {
ac[1] = '0' + _ActiveTerminal;
} else if (TerminalId < 16) {
ac[1] = 'A' + (_ActiveTerminal - 0x0A);
}
SEGGER_RTT_Write(0, ac, 2);
return r;
}
/*************************** End of file ****************************/
/*********************************************************************
* SEGGER MICROCONTROLLER SYSTEME GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996-2014 SEGGER Microcontroller Systeme GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
----------------------------------------------------------------------
File : SEGGER_RTT.h
Date : 17 Dec 2014
Purpose : Implementation of SEGGER real-time terminal which allows
real-time terminal communication on targets which support
debugger memory accesses while the CPU is running.
---------------------------END-OF-HEADER------------------------------
*/
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define SEGGER_RTT_MODE_MASK (3 << 0)
#define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0)
#define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1 << 0)
#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (1 << 1)
#define RTT_CTRL_RESET ""
#define RTT_CTRL_CLEAR ""
#define RTT_CTRL_TEXT_BLACK ""
#define RTT_CTRL_TEXT_RED ""
#define RTT_CTRL_TEXT_GREEN ""
#define RTT_CTRL_TEXT_YELLOW ""
#define RTT_CTRL_TEXT_BLUE ""
#define RTT_CTRL_TEXT_MAGENTA ""
#define RTT_CTRL_TEXT_CYAN ""
#define RTT_CTRL_TEXT_WHITE ""
#define RTT_CTRL_TEXT_BRIGHT_BLACK ""
#define RTT_CTRL_TEXT_BRIGHT_RED ""
#define RTT_CTRL_TEXT_BRIGHT_GREEN ""
#define RTT_CTRL_TEXT_BRIGHT_YELLOW ""
#define RTT_CTRL_TEXT_BRIGHT_BLUE ""
#define RTT_CTRL_TEXT_BRIGHT_MAGENTA ""
#define RTT_CTRL_TEXT_BRIGHT_CYAN ""
#define RTT_CTRL_TEXT_BRIGHT_WHITE ""
#define RTT_CTRL_BG_BLACK ""
#define RTT_CTRL_BG_RED ""
#define RTT_CTRL_BG_GREEN ""
#define RTT_CTRL_BG_YELLOW ""
#define RTT_CTRL_BG_BLUE ""
#define RTT_CTRL_BG_MAGENTA ""
#define RTT_CTRL_BG_CYAN ""
#define RTT_CTRL_BG_WHITE ""
#define RTT_CTRL_BG_BRIGHT_BLACK ""
#define RTT_CTRL_BG_BRIGHT_RED ""
#define RTT_CTRL_BG_BRIGHT_GREEN ""
#define RTT_CTRL_BG_BRIGHT_YELLOW ""
#define RTT_CTRL_BG_BRIGHT_BLUE ""
#define RTT_CTRL_BG_BRIGHT_MAGENTA ""
#define RTT_CTRL_BG_BRIGHT_CYAN ""
#define RTT_CTRL_BG_BRIGHT_WHITE ""
/*********************************************************************
*
* RTT API functions
*
**********************************************************************
*/
int SEGGER_RTT_Read (unsigned BufferIndex, char* pBuffer, unsigned BufferSize);
int SEGGER_RTT_Write (unsigned BufferIndex, const char* pBuffer, unsigned NumBytes);
int SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s);
int SEGGER_RTT_GetKey (void);
int SEGGER_RTT_WaitKey (void);
int SEGGER_RTT_HasKey (void);
int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, char* pBuffer, int BufferSize, int Flags);
int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, char* pBuffer, int BufferSize, int Flags);
void SEGGER_RTT_Init (void);
/*********************************************************************
*
* RTT "Terminal" API functions
*
**********************************************************************
*/
void SEGGER_RTT_SetTerminal (char TerminalId);
int SEGGER_RTT_TerminalOut (char TerminalId, const char* s);
/*********************************************************************
*
* RTT printf functions (require SEGGER_RTT_printf.c)
*
**********************************************************************
*/
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
/*************************** End of file ****************************/
/*********************************************************************
* SEGGER MICROCONTROLLER SYSTEME GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996-2014 SEGGER Microcontroller Systeme GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
----------------------------------------------------------------------
File : SEGGER_RTT_Conf.h
Date : 17 Dec 2014
Purpose : Implementation of SEGGER real-time terminal which allows
real-time terminal communication on targets which support
debugger memory accesses while the CPU is running.
---------------------------END-OF-HEADER------------------------------
*/
/*********************************************************************
*
* Defines, configurable
*
**********************************************************************
*/
#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (2) // Max. number of up-buffers (T->H) available on this target (Default: 2)
#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (2) // Max. number of down-buffers (H->T) available on this target (Default: 2)
#define BUFFER_SIZE_UP (512) // Size of the buffer for terminal output of target, up to host (Default: 1k)
#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
//
// Target is not allowed to perform other RTT operations while string still has not been stored completely.
// Otherwise we would probably end up with a mixed string in the buffer.
// If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
//
#define SEGGER_RTT_LOCK()
#define SEGGER_RTT_UNLOCK()
//
// Define SEGGER_RTT_IN_RAM as 1
// when using RTT in RAM targets (init and data section both in RAM).
// This prevents the host to falsly identify the RTT Callback Structure
// in the init segment as the used Callback Structure.
//
// When defined as 1,
// the first call to an RTT function will modify the ID of the RTT Callback Structure.
// To speed up identifying on the host,
// especially when RTT functions are not called at the beginning of execution,
// SEGGER_RTT_Init() should be called at the start of the application.
//
#define SEGGER_RTT_IN_RAM (0)
/*************************** End of file ****************************/
/*********************************************************************
* SEGGER MICROCONTROLLER GmbH & Co. KG *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 2014-2014 SEGGER Microcontroller GmbH & Co. KG *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
----------------------------------------------------------------------
File : SEGGER_RTT_printf.c
Date : 17 Dec 2014
Purpose : Replacement for printf to write formatted data via RTT
---------------------------END-OF-HEADER------------------------------
*/
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
/*********************************************************************
*
* Defines, configurable
*
**********************************************************************
*/
#ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64)
#endif
#include <stdlib.h>
#include <stdarg.h>
#define FORMAT_FLAG_LEFT_JUSTIFY (1 << 0)
#define FORMAT_FLAG_PAD_ZERO (1 << 1)
#define FORMAT_FLAG_PRINT_SIGN (1 << 2)
#define FORMAT_FLAG_ALTERNATE (1 << 3)
/*********************************************************************
*
* Types
*
**********************************************************************
*/
typedef struct {
char* pBuffer;
int BufferSize;
int Cnt;
int ReturnValue;
unsigned RTTBufferIndex;
} SEGGER_RTT_PRINTF_DESC;
/*********************************************************************
*
* Function prototypes
*
**********************************************************************
*/
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _StoreChar
*/
static void _StoreChar(SEGGER_RTT_PRINTF_DESC * p, char c) {
int Cnt;
Cnt = p->Cnt;
if ((Cnt + 1) <= p->BufferSize) {
*(p->pBuffer + Cnt) = c;
p->Cnt = Cnt + 1;
p->ReturnValue++;
}
//
// Write part of string, when the buffer is full
//
if (p->Cnt == p->BufferSize) {
if (SEGGER_RTT_Write(p->RTTBufferIndex, p->pBuffer, p->Cnt) != p->Cnt) {
p->ReturnValue = -1;
} else {
p->Cnt = 0;
}
}
}
/*********************************************************************
*
* _PrintUnsigned
*/
static void _PrintUnsigned(SEGGER_RTT_PRINTF_DESC * pBufferDesc, unsigned v, unsigned Base, int NumDigits, unsigned FieldWidth, unsigned FormatFlags) {
static const char _aV2C[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
unsigned Div;
unsigned Digit = 1;
unsigned Number;
unsigned Width;
char c;
Number = v;
//
// Get actual field width
//
Width = 1;
while (Number >= Base) {
Number = (Number / Base);
Width++;
}
if ((unsigned)NumDigits > Width) {
Width = NumDigits;
}
//
// Print leading chars if necessary
//
if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0) {
if (FieldWidth != 0) {
if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && (NumDigits == 0)) {
c = '0';
} else {
c = ' ';
}
while ((FieldWidth != 0) && (Width < FieldWidth--)) {
_StoreChar(pBufferDesc, c);
if (pBufferDesc->ReturnValue < 0) {
return;
}
}
}
}
//
// Count how many digits are required by precision
//
while (((v / Digit) >= Base) | (NumDigits-- > 1)) {
Digit *= Base;
}
//
// Output digits
//
do {
Div = v / Digit;
v -= Div * Digit;
_StoreChar(pBufferDesc, _aV2C[Div]);
if (pBufferDesc->ReturnValue < 0) {
break;
}
Digit /= Base;
} while (Digit);
//
// Print trailing spaces if necessary
//
if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == FORMAT_FLAG_LEFT_JUSTIFY) {
if (FieldWidth != 0) {
while ((FieldWidth != 0) && (Width < FieldWidth--)) {
_StoreChar(pBufferDesc, ' ');
if (pBufferDesc->ReturnValue < 0) {
return;
}
}
}
}
}
/*********************************************************************
*
* _PrintInt
*/
static void _PrintInt(SEGGER_RTT_PRINTF_DESC * pBufferDesc, int v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) {
unsigned Width;
unsigned Number;
Number = (v < 0) ? -v : v;
//
// Get actual field width
//
Width = 1;
while (Number >= Base) {
Number = (Number / Base);
Width++;
}
if (NumDigits > Width) {
Width = NumDigits;
}
if ((FieldWidth > 0) && ((v < 0) || ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN))) {
FieldWidth--;
}
//
// Print leading spaces if necessary
//
if ((((FormatFlags & FORMAT_FLAG_PAD_ZERO) == 0) || (NumDigits != 0)) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0)) {
if (FieldWidth != 0) {
while ((FieldWidth != 0) && (Width < FieldWidth--)) {
_StoreChar(pBufferDesc, ' ');
if (pBufferDesc->ReturnValue < 0) {
return;
}
}
}
}
//
// Print sign if necessary
//
if (v < 0) {
v = -v;
_StoreChar(pBufferDesc, '-');
if (pBufferDesc->ReturnValue < 0) {
return;
}
} else if ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN) {
_StoreChar(pBufferDesc, '+');
if (pBufferDesc->ReturnValue < 0) {
return;
}
}
//
// Print leading zeros if necessary
//
if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0) && (NumDigits == 0)) {
if (FieldWidth != 0) {
while ((FieldWidth != 0) && (Width < FieldWidth--)) {
_StoreChar(pBufferDesc, '0');
if (pBufferDesc->ReturnValue < 0) {
return;
}
}
}
}
//
// Print number without sign
//
_PrintUnsigned(pBufferDesc, v, Base, NumDigits, FieldWidth, FormatFlags);
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* SEGGER_RTT_vprintf
*
* Function description
* Stores a formatted string in SEGGER RTT control block.
* This data is read by the host.
*
* Parameters
* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")
* sFormat Pointer to format string
* pParamList Pointer to the list of arguments for the format string
*
* Return values
* >= 0: Number of bytes which have been stored in the "Up"-buffer.
* < 0: Error
*/
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList) {
char c;
SEGGER_RTT_PRINTF_DESC BufferDesc;
int v;
unsigned NumDigits;
unsigned FormatFlags;
unsigned FieldWidth;
char acBuffer[SEGGER_RTT_PRINTF_BUFFER_SIZE];
BufferDesc.pBuffer = acBuffer;
BufferDesc.BufferSize = SEGGER_RTT_PRINTF_BUFFER_SIZE;
BufferDesc.Cnt = 0;
BufferDesc.RTTBufferIndex = BufferIndex;
BufferDesc.ReturnValue = 0;
do {
c = *sFormat++;
if (c == 0) {
break;
}
if (c == '%') {
//
// Filter out flags
//
FormatFlags = 0;
do {
c = *sFormat;
switch (c) {
case '-': FormatFlags |= FORMAT_FLAG_LEFT_JUSTIFY; sFormat++; break;
case '0': FormatFlags |= FORMAT_FLAG_PAD_ZERO; sFormat++; break;
case '+': FormatFlags |= FORMAT_FLAG_PRINT_SIGN; sFormat++; break;
case '#': FormatFlags |= FORMAT_FLAG_ALTERNATE; sFormat++; break;
default: goto FilterFieldWidth; break;
}
} while (1);
//
// filter out field with
//
FilterFieldWidth:
FieldWidth = 0;
do {
c = *sFormat;
if (c < '0' || c > '9') {
break;
}
sFormat++;
FieldWidth = FieldWidth * 10 + (c - '0');
} while (1);
//
// Filter out precision (number of digits to display)
//
NumDigits = 0;
c = *sFormat;
if (c == '.') {
sFormat++;
do {
c = *sFormat;
if (c < '0' || c > '9') {
break;
}
sFormat++;
NumDigits = NumDigits * 10 + (c - '0');
} while (1);
}
//
// Filter out length modifier
//
c = *sFormat;
do {
if (c == 'l' || c == 'h') {
c = *sFormat++;
continue;
}
break;
} while (1);
//
// Handle specifiers
//
switch (c) {
case 'c': {
char c0;
v = va_arg(*pParamList, int);
c0 = (char)v;
_StoreChar(&BufferDesc, c0);
break;
}
case 'd':
v = va_arg(*pParamList, int);
_PrintInt(&BufferDesc, v, 10, NumDigits, FieldWidth, FormatFlags);
break;
case 'u':
v = va_arg(*pParamList, int);
_PrintUnsigned(&BufferDesc, v, 10, NumDigits, FieldWidth, FormatFlags);
break;
case 'x':
case 'X':
v = va_arg(*pParamList, int);
_PrintUnsigned(&BufferDesc, v, 16, NumDigits, FieldWidth, FormatFlags);
break;
case 's':
{
const char * s = va_arg(*pParamList, const char *);
do {
c = *s++;
if (c == 0) {
break;
}
_StoreChar(&BufferDesc, c);
} while (BufferDesc.ReturnValue >= 0);
}
break;
case 'p':
v = va_arg(*pParamList, int);
_PrintUnsigned(&BufferDesc, v, 16, 8, 8, 0);
break;
case '%':
_StoreChar(&BufferDesc, '%');
break;
}
sFormat++;
} else {
_StoreChar(&BufferDesc, c);
}
} while (BufferDesc.ReturnValue >= 0);
if (BufferDesc.ReturnValue > 0) {
//
// Write remaining data, if any
//
if (BufferDesc.Cnt != 0) {
SEGGER_RTT_Write(BufferIndex, acBuffer, BufferDesc.Cnt);
}
BufferDesc.ReturnValue += BufferDesc.Cnt;
}
return BufferDesc.ReturnValue;
}
/*********************************************************************
*
* SEGGER_RTT_printf
*
* Function description
* Stores a formatted string in SEGGER RTT control block.
* This data is read by the host.
*
* Parameters
* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")
* sFormat Pointer to format string, followed by the arguments for conversion
*
* Return values
* >= 0: Number of bytes which have been stored in the "Up"-buffer.
* < 0: Error
*
* Notes
* (1) Conversion specifications have following syntax:
* %[flags][FieldWidth][.Precision]ConversionSpecifier
* (2) Supported flags:
* -: Left justify within the field width
* +: Always print sign extension for signed conversions
* 0: Pad with 0 instead of spaces. Ignored when using '-'-flag or precision
* Supported conversion specifiers:
* c: Print the argument as one char
* d: Print the argument as a signed integer
* u: Print the argument as an unsigned integer
* x: Print the argument as an hexadecimal integer
* s: Print the string pointed to by the argument
* p: Print the argument as an 8-digit hexadecimal integer. (Argument shall be a pointer to void.)
*/
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...) {
va_list ParamList;
va_start(ParamList, sFormat);
return SEGGER_RTT_vprintf(BufferIndex, sFormat, &ParamList);
}
/*************************** End of file ****************************/
/*********************************************************************
* SEGGER MICROCONTROLLER GmbH & Co KG *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 2014 SEGGER Microcontroller GmbH & Co KG *
* *
* www.segger.com Support: support@segger.com *
* *
**********************************************************************
----------------------------------------------------------------------
File : RTT_Syscalls.c
Purpose : Low-level functions for using printf() via RTT in GCC
-------- END-OF-HEADER ---------------------------------------------
*/
#include <stdlib.h>
#include "SEGGER_RTT.h"
/*********************************************************************
*
* Function prototypes
*
**********************************************************************
*/
int _write(int file, char *ptr, int len);
int _write_r(struct _reent *r, int file, char *ptr, int len);
/*********************************************************************
*
* Global functions
*
**********************************************************************
*/
/*********************************************************************
*
* _write()
*
* Function description
* Low-level write function.
* libc subroutines will use this system routine for output to all files,
* including stdout.
* Write data via RTT.
*/
int _write(int file, char *ptr, int len) {
(void) file; /* Not used, avoid warning */
SEGGER_RTT_Write(0, ptr, len);
return len;
}
/*********************************************************************
*
* _write_r()
*
* Function description
* Low-level reentrant write function.
* libc subroutines will use this system routine for output to all files,
* including stdout.
* Write data via RTT.
*/
int _write_r(struct _reent *r, int file, char *ptr, int len) {
(void) file; /* Not used, avoid warning */
(void) r; /* Not used, avoid warning */
SEGGER_RTT_Write(0, ptr, len);
return len;
}
/*********************************************************************
* SEGGER MICROCONTROLLER GmbH & Co KG *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 2014 SEGGER Microcontroller GmbH & Co KG *
* *
* www.segger.com Support: support@segger.com *
* *
**********************************************************************
----------------------------------------------------------------------
File : RTT_Syscalls.c
Purpose : Low-level functions for using printf() via RTT in IAR
-------- END-OF-HEADER ---------------------------------------------
*/
#include <yfuns.h>
#include "SEGGER_RTT.h"
#pragma module_name = "?__write"
/*********************************************************************
*
* Function prototypes
*
**********************************************************************
*/
size_t __write(int handle, const unsigned char * buffer, size_t size);
/*********************************************************************
*
* Global functions
*
**********************************************************************
*/
/*********************************************************************
*
* __write()
*
* Function description
* Low-level write function.
* libc subroutines will use this system routine for output to all files,
* including stdout.
* Write data via RTT.
*/
size_t __write(int handle, const unsigned char * buffer, size_t size) {
(void) handle; /* Not used, avoid warning */
SEGGER_RTT_Write(0, buffer, size);
return size;
}
/****** End Of File *************************************************/
\ No newline at end of file
/*********************************************************************
* SEGGER MICROCONTROLLER GmbH & Co KG *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 2014 SEGGER Microcontroller GmbH & Co KG *
* *
* www.segger.com Support: support@segger.com *
* *
**********************************************************************
----------------------------------------------------------------------
File : RTT_Syscalls_KEIL.c
Purpose : Retargeting module for KEIL MDK-CM3.
Low-level functions for using printf() via RTT
--------- END-OF-HEADER --------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rt_sys.h>
#include <rt_misc.h>
#include "SEGGER_RTT.h"
/*********************************************************************
*
* #pragmas
*
**********************************************************************
*/
#pragma import(__use_no_semihosting)
#ifdef _MICROLIB
#pragma import(__use_full_stdio)
#endif
/*********************************************************************
*
* Defines non-configurable
*
**********************************************************************
*/
/* Standard IO device handles - arbitrary, but any real file system handles must be
less than 0x8000. */
#define STDIN 0x8001 // Standard Input Stream
#define STDOUT 0x8002 // Standard Output Stream
#define STDERR 0x8003 // Standard Error Stream
/*********************************************************************
*
* Public const
*
**********************************************************************
*/
const char __stdin_name[] = "STDIN";
const char __stdout_name[] = "STDOUT";
const char __stderr_name[] = "STDERR";
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* _ttywrch
*
* Function description:
* Outputs a character to the console
*
* Parameters:
* c - character to output
*
*/
void _ttywrch(int c) {
fputc(c, stdout); // stdout
fflush(stdout);
}
/*********************************************************************
*
* _sys_open
*
* Function description:
* Opens the device/file in order to do read/write operations
*
* Parameters:
* sName - sName of the device/file to open
* OpenMode - This parameter is currently ignored
*
* Return value:
* != 0 - Handle to the object to open, otherwise
* == 0 -"device" is not handled by this module
*
*/
FILEHANDLE _sys_open(const char * sName, int OpenMode) {
// Register standard Input Output devices.
if (strcmp(sName, __stdout_name) == 0) {
return (STDOUT);
} else if (strcmp(sName, __stderr_name) == 0) {
return (STDERR);
} else
return (0); // Not implemented
}
/*********************************************************************
*
* _sys_close
*
* Function description:
* Closes the handle to the open device/file
*
* Parameters:
* hFile - Handle to a file opened via _sys_open
*
* Return value:
* 0 - device/file closed
*
*/
int _sys_close(FILEHANDLE hFile) {
return 0; // Not implemented
}
/*********************************************************************
*
* _sys_write
*
* Function description:
* Writes the data to an open handle.
* Currently this function only outputs data to the console
*
* Parameters:
* hFile - Handle to a file opened via _sys_open
* pBuffer - Pointer to the data that shall be written
* NumBytes - Number of bytes to write
* Mode - The Mode that shall be used
*
* Return value:
* Number of bytes *not* written to the file/device
*
*/
int _sys_write(FILEHANDLE hFile, const unsigned char * pBuffer, unsigned NumBytes, int Mode) {
int r = 0;
if (hFile == STDOUT) {
return NumBytes - SEGGER_RTT_Write(0, (const char*)pBuffer, NumBytes);
}
return r;
}
/*********************************************************************
*
* _sys_read
*
* Function description:
* Reads data from an open handle.
* Currently this modules does nothing.
*
* Parameters:
* hFile - Handle to a file opened via _sys_open
* pBuffer - Pointer to buffer to store the read data
* NumBytes - Number of bytes to read
* Mode - The Mode that shall be used
*
* Return value:
* Number of bytes read from the file/device
*
*/
int _sys_read(FILEHANDLE hFile, unsigned char * pBuffer, unsigned NumBytes, int Mode) {
return (0); // Not implemented
}
/*********************************************************************
*
* _sys_istty
*
* Function description:
* This function shall return whether the opened file
* is a console device or not.
*
* Parameters:
* hFile - Handle to a file opened via _sys_open
*
* Return value:
* 1 - Device is a console
* 0 - Device is not a console
*
*/
int _sys_istty(FILEHANDLE hFile) {
if (hFile > 0x8000) {
return (1);
}
return (0); // Not implemented
}
/*********************************************************************
*
* _sys_seek
*
* Function description:
* Seeks via the file to a specific position
*
* Parameters:
* hFile - Handle to a file opened via _sys_open
* Pos -
*
* Return value:
* int -
*
*/
int _sys_seek(FILEHANDLE hFile, long Pos) {
return (0); // Not implemented
}
/*********************************************************************
*
* _sys_ensure
*
* Function description:
*
*
* Parameters:
* hFile - Handle to a file opened via _sys_open
*
* Return value:
* int -
*
*/
int _sys_ensure(FILEHANDLE hFile) {
return (-1); // Not implemented
}
/*********************************************************************
*
* _sys_flen
*
* Function description:
* Returns the length of the opened file handle
*
* Parameters:
* hFile - Handle to a file opened via _sys_open
*
* Return value:
* Length of the file
*
*/
long _sys_flen(FILEHANDLE hFile) {
return (0); // Not implemented
}
/*********************************************************************
*
* _sys_tmpnam
*
* Function description:
* This function converts the file number fileno for a temporary
* file to a unique filename, for example, tmp0001.
*
* Parameters:
* pBuffer - Pointer to a buffer to store the name
* FileNum - file number to convert
* MaxLen - Size of the buffer
*
* Return value:
* 1 - Error
* 0 - Success
*
*/
int _sys_tmpnam(char * pBuffer, int FileNum, unsigned MaxLen) {
return (1); // Not implemented
}
/*********************************************************************
*
* _sys_command_string
*
* Function description:
* This function shall execute a system command.
*
* Parameters:
* cmd - Pointer to the command string
* len - Length of the string
*
* Return value:
* == NULL - Command was not successfully executed
* == sCmd - Command was passed successfully
*
*/
char * _sys_command_string(char * cmd, int len) {
return cmd; // Not implemented
}
/*********************************************************************
*
* _sys_exit
*
* Function description:
* This function is called when the application returns from main
*
* Parameters:
* ReturnCode - Return code from the main function
*
*
*/
void _sys_exit(int ReturnCode) {
while (1); // Not implemented
}
docker.cesanta.com/nrf52-build:0.9.0
...@@ -836,6 +836,8 @@ int inet_pton(int af, const char *src, void *dst); ...@@ -836,6 +836,8 @@ int inet_pton(int af, const char *src, void *dst);
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#define to64(x) strtoll(x, NULL, 10)
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL #define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
#define LWIP_TIMEVAL_PRIVATE 0 #define LWIP_TIMEVAL_PRIVATE 0
#define LWIP_PROVIDE_ERRNO 1 #define LWIP_PROVIDE_ERRNO 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment