diff --git a/Makefile b/Makefile index 4fa74f75..1df965ab 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,15 @@ #Put your personal build config in config.mk and DO NOT COMMIT IT! -include config.mk +PLATFORM ?= cf2 +-include platform/platform_$(PLATFORM).mk + CLOAD_SCRIPT ?= python3 -m cfloader S110 ?= 1 # SoftDevice flashed or not BLE ?= 1 # BLE mode activated or not. If disabled, CRTP mode is active DEBUG_PRINT_ON_SEGGER_RTT ?= 0 # debug prints -PLATFORM ?= cf2 - CROSS_COMPILE?=arm-none-eabi- CC=$(CROSS_COMPILE)gcc @@ -42,45 +43,50 @@ CFLAGS+=$(PROCESSOR) $(NRF) $(PERSONAL_DEFINES) $(INCLUDES) $(CONFIG) $(BUILD_OP ASFLAGS=$(PROCESSOR) LDFLAGS=$(PROCESSOR) --specs=nano.specs -Wl,-Map=$(PROGRAM).map# -Wl,--gc-sections ifdef SEMIHOSTING -LDFLAGS+= --specs=rdimon.specs -lc -lrdimon -CFLAGS+= -DSEMIHOSTING + LDFLAGS+= --specs=rdimon.specs -lc -lrdimon + CFLAGS+= -DSEMIHOSTING endif +CFLAGS += -I$(NRF51_SDK)/Include/gcc +CFLAGS += -I$(NRF51_SDK)/Include/ + +## S110 ################################################################ ifeq ($(strip $(S110)), 1) -LDFLAGS += -T gcc_nrf51_s110_xxaa.ld -CFLAGS += -DS110=1 + LDFLAGS += -T gcc_nrf51_s110_xxaa.ld + CFLAGS += -DS110=1 + + CFLAGS += -I$(NRF_S110)/s110_nrf51822_7.3.0_API/include + CFLAGS += -I$(NRF_S110)/Include/ else -LDFLAGS += -T gcc_nrf51_blank_xxaa.ld + LDFLAGS += -T gcc_nrf51_blank_xxaa.ld endif +## BLE ################################################################ ifeq ($(strip $(BLE)), 1) -CFLAGS += -DBLE=1 + CFLAGS += -DBLE=1 + + CFLAGS += -DBLE_STACK_SUPPORT_REQD -DNRF51 + CFLAGS += -I$(NRF51_SDK)/Include/ble/ + CFLAGS += -I$(NRF51_SDK)/Include/ble/ble_services/ + CFLAGS += -I$(NRF51_SDK)/Include/ble/device_manager/ + CFLAGS += -I$(NRF51_SDK)/Include/app_common/ + CFLAGS += -I$(NRF51_SDK)/Include/sd_common/ + CFLAGS += -I$(NRF51_SDK)/Include/sdk/ + + OBJS += src/ble/ble.o + OBJS += src/ble/ble_crazyflies.o + OBJS += src/ble/timeslot.o + + OBJS += $(NRF51_SDK)/Source/ble/ble_advdata.o + OBJS += $(NRF51_SDK)/Source/ble/ble_conn_params.o + OBJS += $(NRF51_SDK)/Source/ble/ble_services/ble_srv_common.o + OBJS += $(NRF51_SDK)/Source/ble/ble_services/ble_dis.o + OBJS += $(NRF51_SDK)/Source/ble/device_manager/device_manager_peripheral.o + OBJS += $(NRF51_SDK)/Source/sd_common/softdevice_handler.o + OBJS += $(NRF51_SDK)/Source/app_common/app_timer.o + OBJS += $(NRF51_SDK)/Source/app_common/pstorage.o endif -OBJS += src/ble/ble.o -OBJS += src/ble/ble_crazyflies.o -OBJS += src/ble/timeslot.o - -OBJS += $(NRF51_SDK)/Source/ble/ble_advdata.o -OBJS += $(NRF51_SDK)/Source/ble/ble_conn_params.o -OBJS += $(NRF51_SDK)/Source/ble/ble_services/ble_srv_common.o -OBJS += $(NRF51_SDK)/Source/ble/ble_services/ble_dis.o -OBJS += $(NRF51_SDK)/Source/sd_common/softdevice_handler.o -OBJS += $(NRF51_SDK)/Source/app_common/app_timer.o -OBJS += $(NRF51_SDK)/Source/app_common/pstorage.o -OBJS += $(NRF51_SDK)/Source/ble/device_manager/device_manager_peripheral.o - -CFLAGS += -DBLE_STACK_SUPPORT_REQD -DNRF51 -CFLAGS += -I$(NRF51_SDK)/Include/gcc -CFLAGS += -I$(NRF51_SDK)/Include/ -CFLAGS += -I$(NRF51_SDK)/Include/ble/ -CFLAGS += -I$(NRF51_SDK)/Include/ble/ble_services/ -CFLAGS += -I$(NRF51_SDK)/Include/ble/device_manager/ -CFLAGS += -I$(NRF_S110)/s110_nrf51822_7.3.0_API/include -CFLAGS += -I$(NRF_S110)/Include/ -CFLAGS += -I$(NRF51_SDK)/Include/app_common/ -CFLAGS += -I$(NRF51_SDK)/Include/sd_common/ -CFLAGS += -I$(NRF51_SDK)/Include/sdk/ OBJS += src/main.o gcc_startup_nrf51.o system_nrf51.o src/uart.o \ src/syslink.o src/pm.o src/systick.o src/button.o src/swd.o src/ow.o \ diff --git a/interface/pm.h b/interface/pm.h index 56dc50df..27834b29 100644 --- a/interface/pm.h +++ b/interface/pm.h @@ -24,6 +24,7 @@ #ifndef __PM_H__ #define __PM_H__ #include +#include typedef enum {pmAllOff=0, pmSysOff=1, pmSysPowered=2, pmSysBootSetup=3, pmSysRunning=4} PmState; diff --git a/platform/platform_bolt.mk b/platform/platform_bolt.mk new file mode 100644 index 00000000..2976350b --- /dev/null +++ b/platform/platform_bolt.mk @@ -0,0 +1,2 @@ +S110=1 +BLE=0 diff --git a/platform/platform_cf2.mk b/platform/platform_cf2.mk new file mode 100644 index 00000000..c623cd32 --- /dev/null +++ b/platform/platform_cf2.mk @@ -0,0 +1,2 @@ +S110=1 +BLE=1 diff --git a/platform/platform_flapper.mk b/platform/platform_flapper.mk new file mode 100644 index 00000000..c623cd32 --- /dev/null +++ b/platform/platform_flapper.mk @@ -0,0 +1,2 @@ +S110=1 +BLE=1 diff --git a/platform/platform_tag.mk b/platform/platform_tag.mk new file mode 100644 index 00000000..2976350b --- /dev/null +++ b/platform/platform_tag.mk @@ -0,0 +1,2 @@ +S110=1 +BLE=0 diff --git a/src/ble/ble.c b/src/ble/ble.c index 52057a2e..ce86aa2f 100644 --- a/src/ble/ble.c +++ b/src/ble/ble.c @@ -13,6 +13,9 @@ /* Core of the Crazyflie bluetooth implementation. Instanciate Crazyflie * service */ +#ifndef S110 +#error S110 shall be used when using BLE +#endif #include #include @@ -40,10 +43,6 @@ #include "ble_crazyflies.h" -#if S110==0 -#error S110 shall be used when using BLE -#endif - #define DEVICE_NAME "Crazyflie" /**< Name of device. Will be included in the advertising data. */ #define MANUFACTURER_NAME "Bitcraze" /**< Manufacturer. Will be passed to Device Information Service. */ #define APP_ADV_INTERVAL 200 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 125 ms). */ diff --git a/src/esb.c b/src/esb.c index 66805991..b1e56225 100644 --- a/src/esb.c +++ b/src/esb.c @@ -32,9 +32,6 @@ #include -#include -#include - #define RXQ_LEN 8 #define TXQ_LEN 8 @@ -468,14 +465,18 @@ void esbSetDatarate(EsbDatarate dr) esbReset(); } + +#ifdef BLE void ble_advertising_stop(void); void advertising_start(void); void ble_sd_stop(void); +#endif void esbSetContwave(bool enable) { contwave = enable; +#ifdef BLE if (bleEnabled) { if (enable) { ble_advertising_stop(); @@ -483,6 +484,7 @@ void esbSetContwave(bool enable) advertising_start(); } } +#endif esbReset(); } diff --git a/src/main.c b/src/main.c index 576fe06f..03c8fdcf 100644 --- a/src/main.c +++ b/src/main.c @@ -39,15 +39,17 @@ #include "pm.h" #include "pinout.h" #include "systick.h" -#include "nrf_sdm.h" -#include "nrf_soc.h" #include "version.h" #include "shutdown.h" +#ifdef BLE +#include "nrf_sdm.h" +#include "ble_crazyflies.h" +#endif + #include "memory.h" #include "ownet.h" -#include "ble_crazyflies.h" extern void initialise_monitor_handles(void); extern int ble_init(void); @@ -115,7 +117,9 @@ int main() msDelay(1000); if (bleEnabled) { +#ifdef BLE ble_init(); +#endif } else { NRF_CLOCK->TASKS_HFCLKSTART = 1UL; while(!NRF_CLOCK->EVENTS_HFCLKSTARTED); @@ -180,7 +184,7 @@ void mainloop() while(1) { - +#ifdef BLE if (bleEnabled) { if ((esbReceived == false) && bleCrazyfliesIsPacketReceived()) { EsbPacket* packet = bleCrazyfliesGetRxPacket(); @@ -190,6 +194,7 @@ void mainloop() bleCrazyfliesReleaseRxPacket(packet); } } +#endif #ifndef CONT_WAVE_TEST @@ -292,6 +297,7 @@ static void handleSyslinkEvents(bool slReceived) bzero(slRxPacket.data, SYSLINK_MTU); } +#ifdef BLE if (bleEnabled) { if (slRxPacket.length < SYSLINK_MTU) { static EsbPacket pk; @@ -300,6 +306,7 @@ static void handleSyslinkEvents(bool slReceived) bleCrazyfliesSendPacket(&pk); } } +#endif break; case SYSLINK_RADIO_CHANNEL: @@ -559,9 +566,11 @@ static void handleBootloaderCmd(struct esbPacket_s *packet) memcpy(&(txpk.data[3]), (uint32_t*)NRF_FICR->DEVICEADDR, 6); txpk.size = 9; +#ifdef BLE if (bleEnabled) { bleCrazyfliesSendPacket(&txpk); } +#endif if (esbCanTxPacket()) { struct esbPacket_s *pk = esbGetTxPacket(); @@ -580,7 +589,9 @@ static void handleBootloaderCmd(struct esbPacket_s *packet) NRF_POWER->GPREGRET |= 0x20U; } if (bleEnabled) { +#ifdef BLE sd_nvic_SystemReset(); +#endif } else { NVIC_SystemReset(); } @@ -626,9 +637,12 @@ static void handleBootloaderCmd(struct esbPacket_s *packet) } static void disableBle() { +#ifdef BLE if (bleEnabled) { sd_softdevice_disable(); - bleEnabled = 0; esbInit(); } +#endif + + bleEnabled = 0; } diff --git a/src/pm.c b/src/pm.c index 905908cf..35b4cafa 100644 --- a/src/pm.c +++ b/src/pm.c @@ -25,7 +25,10 @@ #include #include + +#ifdef S110 #include +#endif #include "pm.h" #include "button.h" @@ -165,7 +168,9 @@ static void pmNrfPower(bool enable) NRF_POWER->GPREGRET |= 0x01; // Workaround for not being able to determine reset reason... if (bleEnabled) { +#ifdef BLE sd_power_system_off(); +#endif } else { NRF_POWER->SYSTEMOFF = 1UL; }