diff --git a/Makefile b/Makefile index 2885a76..a8e77ac 100644 --- a/Makefile +++ b/Makefile @@ -47,89 +47,28 @@ PROGEXT = .elf PROGS = lora.gw lora.irr SRCS.lora.gw = main.c +SRCS.lora.gw+= $(SRCS.NODE151) SRCS.lora.irr = irr_main.c SRCS.lora.irr+= comms.c SRCS.lora.irr+= strobe_rng_init.c SRCS.lora.irr+= $(STROBE_SRCS) - -SRCS+= board.c -SRCS+= misc.c -.if 0 -SRCS+= rng_save.c -.endif +SRCS.lora.irr+= $(SRCS.NODE151) CFLAGS+= -I$(.CURDIR) CFLAGS+= -g #CFLAGS+= -DNDEBUG CFLAGS+= -I$(.OBJDIR) # for shared_key.h -# Strobe -.PATH: $(.CURDIR)/strobe -CFLAGS+= -I$(.CURDIR)/strobe -STROBE_SRCS+= strobe.c \ - x25519.c - -# LoRamac (SX1276) radio code -LORAMAC_SRC = $(.CURDIR)/loramac/src -.PATH: $(LORAMAC_SRC)/radio/sx1276 $(LORAMAC_SRC)/system $(LORAMAC_SRC)/boards/mcu $(LORAMAC_SRC)/boards/NucleoL152 -CFLAGS+= -I$(LORAMAC_SRC)/boards -CFLAGS+= -I$(LORAMAC_SRC)/system -CFLAGS+= -I$(LORAMAC_SRC)/radio -CFLAGS+= -DUSE_HAL_DRIVER -DSX1276MB1LAS -SRCS+= sx1276.c -SRCS+= utilities.c -SRCS+= adc.c timer.c delay.c gpio.c uart.c fifo.c -SRCS+= adc-board.c delay-board.c gpio-board.c rtc-board.c lpm-board.c sx1276mb1las-board.c spi-board.c uart-board.c - -# Microcontroller -STM32=$(.CURDIR)/stm32 -.PATH: $(STM32)/l151ccux -LINKER_SCRIPT=$(STM32)/l151ccux/STM32L151CCUX_FLASH.ld -SRCS+= \ - startup_stm32l151ccux.s \ - stm32l1xx_hal.c \ - stm32l1xx_hal_adc.c \ - stm32l1xx_hal_adc_ex.c \ - stm32l1xx_hal_cortex.c \ - stm32l1xx_hal_dma.c \ - stm32l1xx_hal_flash.c \ - stm32l1xx_hal_flash_ex.c \ - stm32l1xx_hal_gpio.c \ - stm32l1xx_hal_pcd.c \ - stm32l1xx_hal_pcd_ex.c \ - stm32l1xx_hal_pwr.c \ - stm32l1xx_hal_pwr_ex.c \ - stm32l1xx_hal_rcc.c \ - stm32l1xx_hal_rcc_ex.c \ - stm32l1xx_hal_rtc.c \ - stm32l1xx_hal_rtc_ex.c \ - stm32l1xx_hal_spi.c \ - stm32l1xx_hal_uart.c \ - system_stm32l1xx.c - -SRCS+= \ - stm32l1xx_it.c \ - stm32l1xx_hal_msp.c - -CFLAGS+= -I$(STM32) -CFLAGS+= -I$(STM32)/l151ccux -CFLAGS+= -DSTM32L151xC - -# USB -.PATH: $(STM32)/usb -SRCS+= \ - stm32l1xx_ll_usb.c \ - usb_device.c \ - usbd_cdc.c \ - usbd_cdc_if.c \ - usbd_conf.c \ - usbd_core.c \ - usbd_ctlreq.c \ - usbd_desc.c \ - usbd_ioreq.c - -CFLAGS+= -I$(STM32)/usb +WITH_STROBE=yes + +WITH_SX1276=yes + +WITH_NODE151=yes + +WITH_USB_CDC=yes + +.include CFLAGS+= -Werror -Wall @@ -183,7 +122,7 @@ $(i).list: $(i)$(PROGEXT) all: $(ALLTGTS) .PHONY: runbuild -runbuild: $(SRCS) +runbuild: $(SRCS) Makefile mk/*.mk for i in $(.MAKEFILE_LIST) $(.ALLSRC) $$(cat $(DEPENDS) | gsed ':x; /\\$$/ { N; s/\\\n//; tx }' | sed -e 's/^[^:]*://'); do if [ "$$i" != ".." ]; then echo $$i; fi; done | sort -u | entr -d sh -c 'echo starting...; cd $(.CURDIR) && $(MAKE) $(.MAKEFLAGS) depend && $(MAKE) $(.MAKEFLAGS) all' .PHONY: runtests diff --git a/mk/boards.mk b/mk/boards.mk new file mode 100644 index 0000000..8d53689 --- /dev/null +++ b/mk/boards.mk @@ -0,0 +1,83 @@ +SRCS.NODE151+= board.c +SRCS.NODE151+= misc.c + +.include + +# Strobe +.if ${MK_STROBE} == "yes" +.PATH: $(.CURDIR)/strobe +CFLAGS+= -I$(.CURDIR)/strobe +STROBE_SRCS+= strobe.c \ + x25519.c +.endif + +# LoRamac (SX1276) radio code +.if ${MK_SX1276} == "yes" +LORAMAC_SRC = $(.CURDIR)/loramac/src +.PATH: $(LORAMAC_SRC)/radio/sx1276 $(LORAMAC_SRC)/system $(LORAMAC_SRC)/boards/mcu $(LORAMAC_SRC)/boards/NucleoL152 +CFLAGS+= -I$(LORAMAC_SRC)/boards +CFLAGS+= -I$(LORAMAC_SRC)/system +CFLAGS+= -I$(LORAMAC_SRC)/radio +CFLAGS+= -DUSE_HAL_DRIVER -DSX1276MB1LAS +SRCS+= sx1276.c +SRCS+= utilities.c +SRCS+= adc.c timer.c delay.c gpio.c uart.c fifo.c +SRCS+= adc-board.c delay-board.c gpio-board.c rtc-board.c lpm-board.c sx1276mb1las-board.c spi-board.c uart-board.c +.endif + +# NODE151 Microcontroller +.if ${MK_NODE151} == "yes" +STM32=$(.CURDIR)/stm32 +.PATH: $(STM32)/l151ccux +LINKER_SCRIPT=$(STM32)/l151ccux/STM32L151CCUX_FLASH.ld +SRCS+= \ + startup_stm32l151ccux.s \ + stm32l1xx_hal.c \ + stm32l1xx_hal_adc.c \ + stm32l1xx_hal_adc_ex.c \ + stm32l1xx_hal_cortex.c \ + stm32l1xx_hal_dma.c \ + stm32l1xx_hal_flash.c \ + stm32l1xx_hal_flash_ex.c \ + stm32l1xx_hal_gpio.c \ + stm32l1xx_hal_pcd.c \ + stm32l1xx_hal_pcd_ex.c \ + stm32l1xx_hal_pwr.c \ + stm32l1xx_hal_pwr_ex.c \ + stm32l1xx_hal_rcc.c \ + stm32l1xx_hal_rcc_ex.c \ + stm32l1xx_hal_rtc.c \ + stm32l1xx_hal_rtc_ex.c \ + stm32l1xx_hal_spi.c \ + stm32l1xx_hal_uart.c \ + system_stm32l1xx.c + +SRCS+= \ + stm32l1xx_it.c \ + stm32l1xx_hal_msp.c + +CFLAGS+= -I$(STM32) +CFLAGS+= -I$(STM32)/l151ccux +CFLAGS+= -DSTM32L151xC +.endif + +# USB CDC +.if ${MK_USB_CDC} == "yes" +.PATH: $(STM32)/usb +SRCS+= \ + usb_device.c \ + usbd_cdc.c \ + usbd_cdc_if.c \ + usbd_conf.c \ + usbd_core.c \ + usbd_ctlreq.c \ + usbd_desc.c \ + usbd_ioreq.c + +CFLAGS+= -I$(STM32)/usb +.endif + +.if ${MK_USB_CDC} == "yes" && ${MK_NODE151} == "yes" +SRCS+= \ + stm32l1xx_ll_usb.c +.endif diff --git a/mk/bsd.mkopt.mk b/mk/bsd.mkopt.mk new file mode 100644 index 0000000..5b469eb --- /dev/null +++ b/mk/bsd.mkopt.mk @@ -0,0 +1,97 @@ +# https://cgit.freebsd.org/src/plain/share/mk/bsd.mkopt.mk?id=36435ca5d3faa869c76f488c41daa9d195496f1f' +# +# $FreeBSD$ +# +# Generic mechanism to deal with WITH and WITHOUT options and turn +# them into MK_ options. +# +# For each option FOO in __DEFAULT_YES_OPTIONS, MK_FOO is set to +# "yes", unless WITHOUT_FOO is defined, in which case it is set to +# "no". +# +# For each option FOO in __DEFAULT_NO_OPTIONS, MK_FOO is set to "no", +# unless WITH_FOO is defined, in which case it is set to "yes". +# +# For each entry FOO/BAR in __DEFAULT_DEPENDENT_OPTIONS, +# MK_FOO is set to "no" if WITHOUT_FOO is defined, +# "yes" if WITH_FOO is defined, otherwise the value of MK_BAR. +# +# If both WITH_FOO and WITHOUT_FOO are defined, WITHOUT_FOO wins and +# MK_FOO is set to "no" regardless of which list it was in. +# +# All of __DEFAULT_YES_OPTIONS, __DEFAULT_NO_OPTIONS and +# __DEFAULT_DEPENDENT_OPTIONS are undef'd after all this processing, +# allowing this file to be included multiple times with different lists. +# +# Other parts of the build system will set BROKEN_OPTIONS to a list +# of options that are broken on this platform. This will not be unset +# before returning. Clients are expected to always += this variable. +# +# Users should generally define WITH_FOO or WITHOUT_FOO, but the build +# system should use MK_FOO={yes,no} when it needs to override the +# user's desires or default behavior. +# + +# +# MK_* options which default to "yes". +# +.for var in ${__DEFAULT_YES_OPTIONS} +.if !defined(MK_${var}) +.if defined(WITH_${var}) && ${WITH_${var}} == "no" +.warning "Use WITHOUT_${var}=1 instead of WITH_${var}=no" +.endif +.if defined(WITHOUT_${var}) # WITHOUT always wins +MK_${var}:= no +.else +MK_${var}:= yes +.endif +.else +.if ${MK_${var}} != "yes" && ${MK_${var}} != "no" +.error "Illegal value for MK_${var}: ${MK_${var}}" +.endif +.endif # !defined(MK_${var}) +.endfor +.undef __DEFAULT_YES_OPTIONS + +# +# MK_* options which default to "no". +# +.for var in ${__DEFAULT_NO_OPTIONS} +.if !defined(MK_${var}) +.if defined(WITH_${var}) && ${WITH_${var}} == "no" +.warning "Use WITHOUT_${var}=1 instead of WITH_${var}=no" +.endif +.if defined(WITH_${var}) && !defined(WITHOUT_${var}) # WITHOUT always wins +MK_${var}:= yes +.else +MK_${var}:= no +.endif +.else +.if ${MK_${var}} != "yes" && ${MK_${var}} != "no" +.error "Illegal value for MK_${var}: ${MK_${var}}" +.endif +.endif # !defined(MK_${var}) +.endfor +.undef __DEFAULT_NO_OPTIONS + +# +# MK_* options which are always no, usually because they are +# unsupported/badly broken on this architecture. +# +.for var in ${BROKEN_OPTIONS} +MK_${var}:= no +.endfor + +.for vv in ${__DEFAULT_DEPENDENT_OPTIONS} +.if defined(WITH_${vv:H}) && defined(WITHOUT_${vv:H}) +MK_${vv:H}?= no +.elif defined(WITH_${vv:H}) +MK_${vv:H}?= yes +.elif defined(WITHOUT_${vv:H}) +MK_${vv:H}?= no +.else +MK_${vv:H}?= ${MK_${vv:T}} +.endif +MK_${vv:H}:= ${MK_${vv:H}} +.endfor +.undef __DEFAULT_DEPENDENT_OPTIONS diff --git a/mk/mu.opts.mk b/mk/mu.opts.mk new file mode 100644 index 0000000..2ff56c0 --- /dev/null +++ b/mk/mu.opts.mk @@ -0,0 +1,15 @@ +# This file sets up the various options used for compiling +# code. +# +# See bsd.mkopt.mk for more information. + +__DEFAULT_YES_OPTIONS = STROBE + +__DEFAULT_NO_OPTIONS = \ + NODE151 \ + SX1276 \ + USB_CDC + +__DEFAULT_DEPENDENT_OPTIONS = + +.include