From 4e6115560cb6ace22dad66cf99cc0eaa0e877cde Mon Sep 17 00:00:00 2001 From: Rihards Skuja Date: Fri, 19 Jan 2018 18:13:16 +0200 Subject: [PATCH] Add initial code for the base station --- Makefile | 223 +----------- base_station/Makefile | 221 ++++++++++++ {include => base_station/include}/common.h | 0 {include => base_station/include}/debug.h | 0 {include => base_station/include}/led.h | 0 base_station/include/main.h | 6 + {include => base_station/include}/nRF24L01.h | 0 {include => base_station/include}/nrf24.h | 0 base_station/obj/led.o | Bin 0 -> 5160 bytes base_station/obj/main.o | Bin 0 -> 5328 bytes base_station/obj/nrf24.o | Bin 0 -> 13376 bytes base_station/obj/radioPinFunctions.o | Bin 0 -> 6556 bytes {src => base_station/src}/led.c | 0 base_station/src/main.c | 23 ++ {src => base_station/src}/nrf24.c | 0 {src => base_station/src}/radioPinFunctions.c | 0 robot/Makefile | 221 ++++++++++++ robot/include/common.h | 12 + robot/include/debug.h | 16 + robot/include/led.h | 11 + {include => robot/include}/main.h | 0 robot/include/nRF24L01.h | 130 +++++++ robot/include/nrf24.h | 116 ++++++ {include => robot/include}/servos.h | 9 +- {include => robot/include}/sonar.h | 0 {include => robot/include}/temperature.h | 0 robot/src/led.c | 9 + {src => robot/src}/main.c | 2 +- robot/src/nrf24.c | 339 ++++++++++++++++++ robot/src/radioPinFunctions.c | 74 ++++ {src => robot/src}/servos.c | 4 +- {src => robot/src}/sonar.c | 10 +- {src => robot/src}/temperature.c | 0 33 files changed, 1196 insertions(+), 230 deletions(-) create mode 100644 base_station/Makefile rename {include => base_station/include}/common.h (100%) rename {include => base_station/include}/debug.h (100%) rename {include => base_station/include}/led.h (100%) create mode 100644 base_station/include/main.h rename {include => base_station/include}/nRF24L01.h (100%) rename {include => base_station/include}/nrf24.h (100%) create mode 100644 base_station/obj/led.o create mode 100644 base_station/obj/main.o create mode 100644 base_station/obj/nrf24.o create mode 100644 base_station/obj/radioPinFunctions.o rename {src => base_station/src}/led.c (100%) create mode 100644 base_station/src/main.c rename {src => base_station/src}/nrf24.c (100%) rename {src => base_station/src}/radioPinFunctions.c (100%) create mode 100644 robot/Makefile create mode 100644 robot/include/common.h create mode 100644 robot/include/debug.h create mode 100644 robot/include/led.h rename {include => robot/include}/main.h (100%) create mode 100644 robot/include/nRF24L01.h create mode 100644 robot/include/nrf24.h rename {include => robot/include}/servos.h (58%) rename {include => robot/include}/sonar.h (100%) rename {include => robot/include}/temperature.h (100%) create mode 100644 robot/src/led.c rename {src => robot/src}/main.c (97%) create mode 100644 robot/src/nrf24.c create mode 100644 robot/src/radioPinFunctions.c rename {src => robot/src}/servos.c (90%) rename {src => robot/src}/sonar.c (85%) rename {src => robot/src}/temperature.c (100%) diff --git a/Makefile b/Makefile index 1ba9a59..dce0aa9 100644 --- a/Makefile +++ b/Makefile @@ -1,221 +1,10 @@ -# AVR-GCC Makefile template, derived from the WinAVR template (which -# is public domain), believed to be neutral to any flavor of "make" -# (GNU make, BSD make, SysV make) +TARGETS = robot base_station -SRC_DIR = src -BUILD_DIR = build -INC_DIR = include -OBJ_DIR = obj +all: + $(foreach var,$(TARGETS),cd $(var) && make && cd ..;) -MCU = atmega328p -FORMAT = ihex -TARGET = main -SRC = $(wildcard $(SRC_DIR)/*.c) -OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) -LST = $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.lst) -OPT = s +debug: $(TARGETS) + $(foreach var,$(TARGETS),cd $(var) && make debug && cd ..;) -# Name of this Makefile (used for "make depend"). -MAKEFILE = Makefile - -# Debugging format. -# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. -# AVR (extended) COFF requires stabs, plus an avr-objcopy run. -DEBUG = stabs - -# Compiler flag to set the C Standard level. -# c89 - "ANSI" C -# gnu89 - c89 plus GCC extensions -# c99 - ISO C99 standard (not yet fully implemented) -# gnu99 - c99 plus GCC extensions -CSTANDARD = -std=gnu99 - -# Place -D or -U options here -CDEFS = -DF_CPU=16000000L -D__AVR__ -D__AVR_ATmega328P__ - -# Place -I options here -CINCS = -I $(INC_DIR) - -CDEBUG = -g$(DEBUG) -CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) -CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CSTANDARD) $(CEXTRA) - -#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs - -ifeq ($(BUILD),debug) - CFLAGS += -DDEBUG - CFLAGS += -Wall -Wextra -Wformat=2 -Wswitch-default \ - -Wcast-align -Wpointer-arith -Wbad-function-cast \ - -Wstrict-prototypes -Winline -Wundef -Wnested-externs \ - -Wcast-qual -Wshadow -Wwrite-strings -Wconversion \ - -Winit-self -Wstrict-aliasing -Wmissing-declarations \ - -Wmissing-include-dirs -Wno-unused-parameter -Wuninitialized \ - -Wold-style-definition -Wmissing-prototypes -Wunreachable-code \ - -Wno-unused-but-set-variable -Wmaybe-uninitialized - CINCS += -I/usr/include/simavr - # -endif - -#Additional libraries. - -# Minimalistic printf version -PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min - -# Floating point printf version (requires MATH_LIB = -lm below) -PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt - -PRINTF_LIB = - -# Minimalistic scanf version -SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min - -# Floating point + %[ scanf version (requires MATH_LIB = -lm below) -SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt - -SCANF_LIB = - -MATH_LIB = -lm - -# External memory options - -# 64 KB of external RAM, starting after internal RAM (ATmega128!), -# used for variables (.data/.bss) and heap (malloc()). -#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff - -# 64 KB of external RAM, starting after internal RAM (ATmega128!), -# only used for heap (malloc()). -#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff - -EXTMEMOPTS = - -#LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref -LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) - -# Programming support using avrdude. Settings and variables. - -AVRDUDE_PROGRAMMER = usbasp -AVRDUDE_PORT = usb - -AVRDUDE_WRITE_FLASH = -U flash:w:$(BUILD_DIR)/$(TARGET).hex -#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep - - -# Uncomment the following if you want avrdude's erase cycle counter. -# Note that this counter needs to be initialized first using -Yn, -# see avrdude manual. -#AVRDUDE_ERASE_COUNTER = -y - -# Uncomment the following if you do /not/ wish a verification to be -# performed after programming the device. -AVRDUDE_NO_VERIFY = -V - -# Increase verbosity level. Please use this when submitting bug -# reports about avrdude. See -# to submit bug reports. -AVRDUDE_VERBOSE = -v -v - -AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) \ - $(AVRDUDE_ERASE_COUNTER) - - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -SIZE = avr-size -NM = avr-nm -AVRDUDE = avrdude -REMOVE = rm -rf -MV = mv -f - -# Combine all necessary flags and optional flags. -# Add target processor to flags. -ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) - - -# Default target. -all: build - -build: elf hex eep lss sym - -elf: $(BUILD_DIR)/$(TARGET).elf -hex: $(BUILD_DIR)/$(TARGET).hex -eep: $(BUILD_DIR)/$(TARGET).eep -lss: $(BUILD_DIR)/$(TARGET).lss -sym: $(BUILD_DIR)/$(TARGET).sym - - -# Program the device. -program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep - $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) - - -debug: - make "BUILD=debug" - - -# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. -COFFCONVERT = $(OBJCOPY) --debugging \ - --change-section-address .data-0x800000 \ - --change-section-address .bss-0x800000 \ - --change-section-address .noinit-0x800000 \ - --change-section-address .eeprom-0x810000 - - -coff: $(BUILD_DIR)/$(TARGET).elf - $(COFFCONVERT) -O coff-avr $< $(TARGET).cof - - -extcoff: $(BUILD_DIR)/$(TARGET).elf - $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof - - -.SUFFIXES: .elf .hex .eep .lss .sym - -%.hex: %.elf - $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ - -%.eep: %.elf - -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ - --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ - -# Create extended listing file from ELF output file. -%.lss: %.elf - $(OBJDUMP) -h -S $< > $@ - -# Create a symbol table from ELF output file. -%.sym: %.elf - $(NM) -n $< > $@ - - - -# Link: create ELF output file from object files. -.SECONDARY: $(OBJ) -$(BUILD_DIR)/%.elf: $(OBJ) - @mkdir -p $(@D) - $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) - - -# Compile: create object files from C source files. -$(OBJ_DIR)/%.o : $(SRC_DIR)/%.c - @mkdir -p $(@D) - $(CC) -c $(ALL_CFLAGS) $< -o $@ - - -# Target: clean project. clean: - $(REMOVE) $(BUILD_DIR)/* $(OBJ_DIR)/* - -depend: - if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ - then \ - sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ - $(MAKEFILE).$$$$ && \ - $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ - fi - echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ - >> $(MAKEFILE); \ - $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) >> $(MAKEFILE) - -.PHONY: all build elf hex eep lss sym program coff extcoff clean depend + $(foreach var,$(TARGETS),cd $(var) && make clean && cd ..;) diff --git a/base_station/Makefile b/base_station/Makefile new file mode 100644 index 0000000..1ba9a59 --- /dev/null +++ b/base_station/Makefile @@ -0,0 +1,221 @@ +# AVR-GCC Makefile template, derived from the WinAVR template (which +# is public domain), believed to be neutral to any flavor of "make" +# (GNU make, BSD make, SysV make) + +SRC_DIR = src +BUILD_DIR = build +INC_DIR = include +OBJ_DIR = obj + +MCU = atmega328p +FORMAT = ihex +TARGET = main +SRC = $(wildcard $(SRC_DIR)/*.c) +OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) +LST = $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.lst) +OPT = s + +# Name of this Makefile (used for "make depend"). +MAKEFILE = Makefile + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = stabs + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 + +# Place -D or -U options here +CDEFS = -DF_CPU=16000000L -D__AVR__ -D__AVR_ATmega328P__ + +# Place -I options here +CINCS = -I $(INC_DIR) + +CDEBUG = -g$(DEBUG) +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) +CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CSTANDARD) $(CEXTRA) + +#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs + +ifeq ($(BUILD),debug) + CFLAGS += -DDEBUG + CFLAGS += -Wall -Wextra -Wformat=2 -Wswitch-default \ + -Wcast-align -Wpointer-arith -Wbad-function-cast \ + -Wstrict-prototypes -Winline -Wundef -Wnested-externs \ + -Wcast-qual -Wshadow -Wwrite-strings -Wconversion \ + -Winit-self -Wstrict-aliasing -Wmissing-declarations \ + -Wmissing-include-dirs -Wno-unused-parameter -Wuninitialized \ + -Wold-style-definition -Wmissing-prototypes -Wunreachable-code \ + -Wno-unused-but-set-variable -Wmaybe-uninitialized + CINCS += -I/usr/include/simavr + # +endif + +#Additional libraries. + +# Minimalistic printf version +PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min + +# Floating point printf version (requires MATH_LIB = -lm below) +PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt + +PRINTF_LIB = + +# Minimalistic scanf version +SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min + +# Floating point + %[ scanf version (requires MATH_LIB = -lm below) +SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt + +SCANF_LIB = + +MATH_LIB = -lm + +# External memory options + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# used for variables (.data/.bss) and heap (malloc()). +#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# only used for heap (malloc()). +#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff + +EXTMEMOPTS = + +#LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref +LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) + +# Programming support using avrdude. Settings and variables. + +AVRDUDE_PROGRAMMER = usbasp +AVRDUDE_PORT = usb + +AVRDUDE_WRITE_FLASH = -U flash:w:$(BUILD_DIR)/$(TARGET).hex +#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep + + +# Uncomment the following if you want avrdude's erase cycle counter. +# Note that this counter needs to be initialized first using -Yn, +# see avrdude manual. +#AVRDUDE_ERASE_COUNTER = -y + +# Uncomment the following if you do /not/ wish a verification to be +# performed after programming the device. +AVRDUDE_NO_VERIFY = -V + +# Increase verbosity level. Please use this when submitting bug +# reports about avrdude. See +# to submit bug reports. +AVRDUDE_VERBOSE = -v -v + +AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) +AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) \ + $(AVRDUDE_ERASE_COUNTER) + + +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -rf +MV = mv -f + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) + + +# Default target. +all: build + +build: elf hex eep lss sym + +elf: $(BUILD_DIR)/$(TARGET).elf +hex: $(BUILD_DIR)/$(TARGET).hex +eep: $(BUILD_DIR)/$(TARGET).eep +lss: $(BUILD_DIR)/$(TARGET).lss +sym: $(BUILD_DIR)/$(TARGET).sym + + +# Program the device. +program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) + + +debug: + make "BUILD=debug" + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT = $(OBJCOPY) --debugging \ + --change-section-address .data-0x800000 \ + --change-section-address .bss-0x800000 \ + --change-section-address .noinit-0x800000 \ + --change-section-address .eeprom-0x810000 + + +coff: $(BUILD_DIR)/$(TARGET).elf + $(COFFCONVERT) -O coff-avr $< $(TARGET).cof + + +extcoff: $(BUILD_DIR)/$(TARGET).elf + $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof + + +.SUFFIXES: .elf .hex .eep .lss .sym + +%.hex: %.elf + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +%.eep: %.elf + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +%.lss: %.elf + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +%.sym: %.elf + $(NM) -n $< > $@ + + + +# Link: create ELF output file from object files. +.SECONDARY: $(OBJ) +$(BUILD_DIR)/%.elf: $(OBJ) + @mkdir -p $(@D) + $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) + + +# Compile: create object files from C source files. +$(OBJ_DIR)/%.o : $(SRC_DIR)/%.c + @mkdir -p $(@D) + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Target: clean project. +clean: + $(REMOVE) $(BUILD_DIR)/* $(OBJ_DIR)/* + +depend: + if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ + then \ + sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ + $(MAKEFILE).$$$$ && \ + $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ + fi + echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ + >> $(MAKEFILE); \ + $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) >> $(MAKEFILE) + +.PHONY: all build elf hex eep lss sym program coff extcoff clean depend diff --git a/include/common.h b/base_station/include/common.h similarity index 100% rename from include/common.h rename to base_station/include/common.h diff --git a/include/debug.h b/base_station/include/debug.h similarity index 100% rename from include/debug.h rename to base_station/include/debug.h diff --git a/include/led.h b/base_station/include/led.h similarity index 100% rename from include/led.h rename to base_station/include/led.h diff --git a/base_station/include/main.h b/base_station/include/main.h new file mode 100644 index 0000000..29f0d59 --- /dev/null +++ b/base_station/include/main.h @@ -0,0 +1,6 @@ +#ifndef MAIN_H +#define MAIN_H + +#include + +#endif diff --git a/include/nRF24L01.h b/base_station/include/nRF24L01.h similarity index 100% rename from include/nRF24L01.h rename to base_station/include/nRF24L01.h diff --git a/include/nrf24.h b/base_station/include/nrf24.h similarity index 100% rename from include/nrf24.h rename to base_station/include/nrf24.h diff --git a/base_station/obj/led.o b/base_station/obj/led.o new file mode 100644 index 0000000000000000000000000000000000000000..eb59e326e2efa7661a5ba93e4e4568c2b0101194 GIT binary patch literal 5160 zcma)AO^6$182+|fYyT8&MW}+VQn8WUY-Tc(WH(l~ba&fA5pmmtA`IDNb`!|Yl9|-D zP`ZkR>cvA9r1l^pBB=D@q0p0{rAIx8hk_{HmBmXvtb!V$4g>=i55&s^XAk!&?kLzSH?!V7SNd#|+`ze3{`J4Buk-XNLb` zc<){p>p6yxG5jXO=NZ1n@J)vAFidUuO!tE0Um52yvu^)C}~_6U3pewglv`6o$o6yUY+nMGT1;_;bNrsqD{z9Yu)l`4yR7Ns&rK zn(>@*%D9uPvSO7DOV%({NJTL!C}cRAqZ*I4k~y_!&Uj6ly?$z~UO|~Lk7%oS8F!xP zg+~sxG+I2{4o~+3GwSs#swdW$mDFb0IO*92CMB@od>PD zG0F0|T?=mP(K2~0`f9V**%(!!(Q?05*MYUnAb1p*o3xrR`DBuTncX*X>YQC)ILSzu zt5(Q~)g_aOZ*@1z7S#%w7XY<}ik@W9FMn#Ga}oYt;AnZ%slF4Xv>ocxYy3(m+FxNf-YES;z6I^xo_#7w@f zD`T=4pSWw1+;XnhYRIz|qA9qWViL21q(56b*Pm^5>+L}!R=AgMj<+Oh{iqSICFAV4 z-K7^cVry%+R%dZLmmbS`KVPshlC%NxI3LymdnKY@`lvuEQ)V(^qcX#3)Q%*T$ySBhS*TGX)jS-}*62~`Ar(ob ztBuY`3WU=o7SUGhkr3f@nQwGP(jz35$mtp{P-$WcrVSaYOwVYA^PSN6y;HN!mrhs zNmYc@#(pE$21$(XOB4~1@k`QK3DO-+itXN8^Eit*5z{!Q)n;qGX|5}{j?brYw-GnY znpeVN6@6+^_Z!LlGM#z+8i*6ekIzpXIq}Nb+?4#vnt#*zjK_F8c8aZSdjT*x^ag{j zcW^VVC*{+@OLlc@`w`%y?D`P!%k27DiwSIP=keF&FdE-HVW>@$?74(iD0)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|-X&W)g z5vSc1k;ik}a@0=cTL0&3H%Qb!(}|#OlIiUp&BH4gIqt^W2QMD)v9r{;8_$E=#3m;3 zeu91`57Lu#8^wq4VSMDk#+U`5R*>EB%D`q#KyecedLL(oS!)Ug!e*T}(FodWW*FXK z82GxgAnk>X)}>u-)|~^UIpg@y_;^4(^3#W3eV4)84kM*VPv{g6CR_o%b$o{l@>$r- Upg1(>I_34YkRQEEG{f-z14pC>N&o-= literal 0 HcmV?d00001 diff --git a/base_station/obj/nrf24.o b/base_station/obj/nrf24.o new file mode 100644 index 0000000000000000000000000000000000000000..45d8b14f0cc51c8722e7b8107408b3042cd61468 GIT binary patch literal 13376 zcmbuF4{+4Sb;tJy#8xooUx-a@Y%3Hy;1N3MbP@sqmhB$`yRsvLOsLEFbm&gf+0vbI zcfzuV5(x_owah;u4|QpW@uV5Xacn204HHvWafr*f6x%6wnU)C`hs4CC0aNUu2_E`= zyKjH{PDdQibZ370efI6!w{PFu-|pQ{_su1Z4W8#ITRgQwxtdZfVWl>rF`^Y_s|o5F zHF1|xeR=xZpPxXyL#dMCvpX;EoHTUH&|5>N%T4Rm`N{c_{6}T~?5T1!GCcg$@c3P0 zF7#biBmLZ)Y#f=SElv4Ri|OSxP5Gj_Fc^Ak$1OW1?YO-C?Dmr3zPuWFYsj?s{mPAh zIAko5cFC~S*mjmQ3foAsJG4F9pZCu7pPVSICZP`IKE_(e#+dMU5W=?$uy{jfoxoPD3cdm9lN`{R#&En+H z;m~^_Gnc{8wr}*UAv@26=x=|X#-Nyz-Wktm_3IheBg(INM?IrQe_KvH73dqy4Zjhs zA3UX_Y+4@8vn`#mmLa7&LK}5^OTPc-+8XR{FqD6i?*n|_$oEb9-j?5_dv>tR*1X9= zYkq^4r%w&A4|OW{3GNlVSMU+R=LKI6cl)#zr78tC3horVMeqxPew9u7WS-xYjV@Gk^k7JS2aH*SsK2LyKs9uQ37ex76g`*;uZ zX9*o&O$%ziqMgAMUtOoL9Ch*4^$Ok8%SCEf#%-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3Y^rZZ;`n8w-#-p6v{ z{enlBpM#u!yGH)+1s`YrHux0tOW@xH}e0)B;gGWa0#bTIv9j(nr*81rm!o|(?2 zGhmtvoi!I(PCO198}%ce%)Agh15En#-6q0v;(BKK-qFZR=h!OdW^kPOA#gWy3wRxK z8+bEwCwLcg2E3Pf9r#7&4d4UJ1K>l1W#tBGk*q{?9=z$ z2+N7{Eu~PzHle>`QJ)Ad?GIH@sErD}OB#o(9v79;TQMI9@c3&TYC}5o@3E*4O^M1e z3#J;_D?=UI;~&(kfsXZoOpv`i;)Y{I7dvhxYSO<0bC636K>pz)fNmrI7UGgF?Z*$2 z==b`z*s+#CKwQBM@85#Yj8=);sGTmPFen$GHv$2+2?aOxxb(S>{3sZArc#fHj&@wQ RQ=m6Ftb*UEp(%*P{{boW%cKAR literal 0 HcmV?d00001 diff --git a/base_station/obj/radioPinFunctions.o b/base_station/obj/radioPinFunctions.o new file mode 100644 index 0000000000000000000000000000000000000000..d9b96dfd3207d07c7b62bb5b624a092d8389e332 GIT binary patch literal 6556 zcma)>O>A6O700jR0H#T3ffOoQ%Ct!n54FcLZ{Cc@o(9r(;xrIdp(!Awpx5V_XM4nW z#+~;jxNH)jprCHLXew${sjUEYfrKixB?}e^ApvS7xS=iYPg zJ@X;qD~;dpopbKF=i|3yuYUTkuZ>zaw~0@a%`Y&#wsnf#4Ux-{C&~Lhzpi|5Nat zGv2-ewtL_Uf}apP5d4hbmju5l_$|SI75u*7TR-gA{jA^>!K;F=2>y}a8-o8RcvtYD zTl`ul1V1SF>w>ohKPUL-g5MJSo?vRjE8Gjo{}MJw5BYecjpPN`*q(lIANDW6=D1k5 zp+4pA8tP8Lckz=+sfPNr!dF6%hPqo}+cAGep;gQ|h0xV&!v7z@ry;vTTace)OvFBl zhPqGqKPi0Xwa<5j&wr2koD)9jDQZST6@<^C@EK^IGkE^m2u^}eW15e%!d@uOs^CT8 zb4mEDYoDR;`S_U6&j~-D7kpayd`S3gXrHn0Ns}7tteE?V;B&5D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d+934%dLWhAY`k!G^}QgPxxQ=UD!d;GZ#*>IO3|>Nm_((|4HZ+~QqkI=A>6 znAV~`D72mY6CW0Q2lH)^A7`c*i_D(@KL92_)bqz#PW*)64)a}*Z!_n>Pcz>OeilrA zj)PxiIq~a)>3osmoQ3>tW~$+znG0Y#cO*Zw$Ns}|;u#c!<`N%ernBxGGu3~Nc^O;- zlONif4VDvM5PXT5zK}4b`bj4)WOz=hLMzTevJ5jhlvy)TB>yvAN9ko z2~;=Xi~gU%4!hPF2#6_18qJT>v&Ik7*$-Oo#y0GVP|)|~2tE|kZTL_ea@|+)rFa`M XJIEJ}kK!ZkI`}`9N43WMv3CCh7cRsp literal 0 HcmV?d00001 diff --git a/src/led.c b/base_station/src/led.c similarity index 100% rename from src/led.c rename to base_station/src/led.c diff --git a/base_station/src/main.c b/base_station/src/main.c new file mode 100644 index 0000000..b1262f4 --- /dev/null +++ b/base_station/src/main.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include "led.h" +#include "nrf24.h" +#include "common.h" +#include "main.h" + +#ifdef DEBUG +#include "debug.h" +#endif /* DEBUG */ + +int main(void) +{ + init_leds(); + + // Use green LED as power LED + SET(LED_PORT, LED_GREEN_BIT); + + while (1) { } + + return 0; +} diff --git a/src/nrf24.c b/base_station/src/nrf24.c similarity index 100% rename from src/nrf24.c rename to base_station/src/nrf24.c diff --git a/src/radioPinFunctions.c b/base_station/src/radioPinFunctions.c similarity index 100% rename from src/radioPinFunctions.c rename to base_station/src/radioPinFunctions.c diff --git a/robot/Makefile b/robot/Makefile new file mode 100644 index 0000000..1ba9a59 --- /dev/null +++ b/robot/Makefile @@ -0,0 +1,221 @@ +# AVR-GCC Makefile template, derived from the WinAVR template (which +# is public domain), believed to be neutral to any flavor of "make" +# (GNU make, BSD make, SysV make) + +SRC_DIR = src +BUILD_DIR = build +INC_DIR = include +OBJ_DIR = obj + +MCU = atmega328p +FORMAT = ihex +TARGET = main +SRC = $(wildcard $(SRC_DIR)/*.c) +OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) +LST = $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.lst) +OPT = s + +# Name of this Makefile (used for "make depend"). +MAKEFILE = Makefile + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = stabs + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 + +# Place -D or -U options here +CDEFS = -DF_CPU=16000000L -D__AVR__ -D__AVR_ATmega328P__ + +# Place -I options here +CINCS = -I $(INC_DIR) + +CDEBUG = -g$(DEBUG) +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) +CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CSTANDARD) $(CEXTRA) + +#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs + +ifeq ($(BUILD),debug) + CFLAGS += -DDEBUG + CFLAGS += -Wall -Wextra -Wformat=2 -Wswitch-default \ + -Wcast-align -Wpointer-arith -Wbad-function-cast \ + -Wstrict-prototypes -Winline -Wundef -Wnested-externs \ + -Wcast-qual -Wshadow -Wwrite-strings -Wconversion \ + -Winit-self -Wstrict-aliasing -Wmissing-declarations \ + -Wmissing-include-dirs -Wno-unused-parameter -Wuninitialized \ + -Wold-style-definition -Wmissing-prototypes -Wunreachable-code \ + -Wno-unused-but-set-variable -Wmaybe-uninitialized + CINCS += -I/usr/include/simavr + # +endif + +#Additional libraries. + +# Minimalistic printf version +PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min + +# Floating point printf version (requires MATH_LIB = -lm below) +PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt + +PRINTF_LIB = + +# Minimalistic scanf version +SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min + +# Floating point + %[ scanf version (requires MATH_LIB = -lm below) +SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt + +SCANF_LIB = + +MATH_LIB = -lm + +# External memory options + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# used for variables (.data/.bss) and heap (malloc()). +#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# only used for heap (malloc()). +#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff + +EXTMEMOPTS = + +#LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref +LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) + +# Programming support using avrdude. Settings and variables. + +AVRDUDE_PROGRAMMER = usbasp +AVRDUDE_PORT = usb + +AVRDUDE_WRITE_FLASH = -U flash:w:$(BUILD_DIR)/$(TARGET).hex +#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep + + +# Uncomment the following if you want avrdude's erase cycle counter. +# Note that this counter needs to be initialized first using -Yn, +# see avrdude manual. +#AVRDUDE_ERASE_COUNTER = -y + +# Uncomment the following if you do /not/ wish a verification to be +# performed after programming the device. +AVRDUDE_NO_VERIFY = -V + +# Increase verbosity level. Please use this when submitting bug +# reports about avrdude. See +# to submit bug reports. +AVRDUDE_VERBOSE = -v -v + +AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) +AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) \ + $(AVRDUDE_ERASE_COUNTER) + + +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -rf +MV = mv -f + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) + + +# Default target. +all: build + +build: elf hex eep lss sym + +elf: $(BUILD_DIR)/$(TARGET).elf +hex: $(BUILD_DIR)/$(TARGET).hex +eep: $(BUILD_DIR)/$(TARGET).eep +lss: $(BUILD_DIR)/$(TARGET).lss +sym: $(BUILD_DIR)/$(TARGET).sym + + +# Program the device. +program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) + + +debug: + make "BUILD=debug" + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT = $(OBJCOPY) --debugging \ + --change-section-address .data-0x800000 \ + --change-section-address .bss-0x800000 \ + --change-section-address .noinit-0x800000 \ + --change-section-address .eeprom-0x810000 + + +coff: $(BUILD_DIR)/$(TARGET).elf + $(COFFCONVERT) -O coff-avr $< $(TARGET).cof + + +extcoff: $(BUILD_DIR)/$(TARGET).elf + $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof + + +.SUFFIXES: .elf .hex .eep .lss .sym + +%.hex: %.elf + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +%.eep: %.elf + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +%.lss: %.elf + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +%.sym: %.elf + $(NM) -n $< > $@ + + + +# Link: create ELF output file from object files. +.SECONDARY: $(OBJ) +$(BUILD_DIR)/%.elf: $(OBJ) + @mkdir -p $(@D) + $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) + + +# Compile: create object files from C source files. +$(OBJ_DIR)/%.o : $(SRC_DIR)/%.c + @mkdir -p $(@D) + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Target: clean project. +clean: + $(REMOVE) $(BUILD_DIR)/* $(OBJ_DIR)/* + +depend: + if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ + then \ + sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ + $(MAKEFILE).$$$$ && \ + $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ + fi + echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ + >> $(MAKEFILE); \ + $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) >> $(MAKEFILE) + +.PHONY: all build elf hex eep lss sym program coff extcoff clean depend diff --git a/robot/include/common.h b/robot/include/common.h new file mode 100644 index 0000000..1d67b43 --- /dev/null +++ b/robot/include/common.h @@ -0,0 +1,12 @@ +#ifndef COMMON_H +#define COMMON_H + +#include + +#define BIT(mask) (1 << (mask)) +#define SET(var, mask) ((var) |= (uint8_t)BIT(mask)) +#define CLR(var, mask) ((var) &= (uint8_t)~(BIT(mask))) +#define CHK(var, mask) ((var) & (uint8_t)BIT(mask)) +#define TOG(var, mask) ((var) ^= (uint8_t)BIT(mask)) + +#endif /* COMMON_H */ diff --git a/robot/include/debug.h b/robot/include/debug.h new file mode 100644 index 0000000..002c485 --- /dev/null +++ b/robot/include/debug.h @@ -0,0 +1,16 @@ +#ifndef DEBUG_H +#define DEBUG_H + +#include +#include + +AVR_MCU(F_CPU, "atmega328p"); +const struct avr_mmcu_vcd_trace_t _mytrace[] _MMCU_ = { + { AVR_MCU_VCD_SYMBOL("DDRD"), .what = (void *) &DDRD, }, + { AVR_MCU_VCD_SYMBOL("TCCR0A"), .what = (void *) &TCCR0A, }, + { AVR_MCU_VCD_SYMBOL("TCCR0B"), .what = (void *) &TCCR0B, }, + { AVR_MCU_VCD_SYMBOL("OCR0A"), .what = (void *) &OCR0A, }, + { AVR_MCU_VCD_SYMBOL("OCR0B"), .what = (void *) &OCR0B, }, +}; + +#endif /* DEBUG_H */ diff --git a/robot/include/led.h b/robot/include/led.h new file mode 100644 index 0000000..d2ad6eb --- /dev/null +++ b/robot/include/led.h @@ -0,0 +1,11 @@ +#ifndef LED_H +#define LED_H + +#define LED_DDR DDRD +#define LED_PORT PORTD +#define LED_GREEN_BIT PD3 +#define LED_BLUE_BIT PD4 + +void init_leds(void); + +#endif /* LED_H */ diff --git a/include/main.h b/robot/include/main.h similarity index 100% rename from include/main.h rename to robot/include/main.h diff --git a/robot/include/nRF24L01.h b/robot/include/nRF24L01.h new file mode 100644 index 0000000..4ec208d --- /dev/null +++ b/robot/include/nRF24L01.h @@ -0,0 +1,130 @@ +/* + Copyright (c) 2007 Stefan Engelke + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + $Id$ +*/ + +/* Memory Map */ +#define CONFIG 0x00 +#define EN_AA 0x01 +#define EN_RXADDR 0x02 +#define SETUP_AW 0x03 +#define SETUP_RETR 0x04 +#define RF_CH 0x05 +#define RF_SETUP 0x06 +#define STATUS 0x07 +#define OBSERVE_TX 0x08 +#define CD 0x09 +#define RX_ADDR_P0 0x0A +#define RX_ADDR_P1 0x0B +#define RX_ADDR_P2 0x0C +#define RX_ADDR_P3 0x0D +#define RX_ADDR_P4 0x0E +#define RX_ADDR_P5 0x0F +#define TX_ADDR 0x10 +#define RX_PW_P0 0x11 +#define RX_PW_P1 0x12 +#define RX_PW_P2 0x13 +#define RX_PW_P3 0x14 +#define RX_PW_P4 0x15 +#define RX_PW_P5 0x16 +#define FIFO_STATUS 0x17 +#define DYNPD 0x1C + +/* Bit Mnemonics */ + +/* configuratio nregister */ +#define MASK_RX_DR 6 +#define MASK_TX_DS 5 +#define MASK_MAX_RT 4 +#define EN_CRC 3 +#define CRCO 2 +#define PWR_UP 1 +#define PRIM_RX 0 + +/* enable auto acknowledgment */ +#define ENAA_P5 5 +#define ENAA_P4 4 +#define ENAA_P3 3 +#define ENAA_P2 2 +#define ENAA_P1 1 +#define ENAA_P0 0 + +/* enable rx addresses */ +#define ERX_P5 5 +#define ERX_P4 4 +#define ERX_P3 3 +#define ERX_P2 2 +#define ERX_P1 1 +#define ERX_P0 0 + +/* setup of address width */ +#define AW 0 /* 2 bits */ + +/* setup of auto re-transmission */ +#define ARD 4 /* 4 bits */ +#define ARC 0 /* 4 bits */ + +/* RF setup register */ +#define PLL_LOCK 4 +#define RF_DR 3 +#define RF_PWR 1 /* 2 bits */ + +/* general status register */ +#define RX_DR 6 +#define TX_DS 5 +#define MAX_RT 4 +#define RX_P_NO 1 /* 3 bits */ +#define TX_FULL 0 + +/* transmit observe register */ +#define PLOS_CNT 4 /* 4 bits */ +#define ARC_CNT 0 /* 4 bits */ + +/* fifo status */ +#define TX_REUSE 6 +#define FIFO_FULL 5 +#define TX_EMPTY 4 +#define RX_FULL 1 +#define RX_EMPTY 0 + +/* dynamic length */ +#define DPL_P0 0 +#define DPL_P1 1 +#define DPL_P2 2 +#define DPL_P3 3 +#define DPL_P4 4 +#define DPL_P5 5 + +/* Instruction Mnemonics */ +#define R_REGISTER 0x00 /* last 4 bits will indicate reg. address */ +#define W_REGISTER 0x20 /* last 4 bits will indicate reg. address */ +#define REGISTER_MASK 0x1F +#define R_RX_PAYLOAD 0x61 +#define W_TX_PAYLOAD 0xA0 +#define FLUSH_TX 0xE1 +#define FLUSH_RX 0xE2 +#define REUSE_TX_PL 0xE3 +#define ACTIVATE 0x50 +#define R_RX_PL_WID 0x60 +#define NOP 0xFF diff --git a/robot/include/nrf24.h b/robot/include/nrf24.h new file mode 100644 index 0000000..7f96cdf --- /dev/null +++ b/robot/include/nrf24.h @@ -0,0 +1,116 @@ +/* +* ---------------------------------------------------------------------------- +* “THE COFFEEWARE LICENSE” (Revision 1): +* wrote this file. As long as you retain this notice you +* can do whatever you want with this stuff. If we meet some day, and you think +* this stuff is worth it, you can buy me a coffee in return. +* ----------------------------------------------------------------------------- +* This library is based on this library: +* https://github.com/aaronds/arduino-nrf24l01 +* Which is based on this library: +* http://www.tinkerer.eu/AVRLib/nRF24L01 +* ----------------------------------------------------------------------------- +*/ +#ifndef NRF24 +#define NRF24 + +#include "nRF24L01.h" +#include + +#define LOW 0 +#define HIGH 1 + +#define nrf24_ADDR_LEN 5 +#define nrf24_CONFIG ((1< Pin HIGH + * - state:0 => Pin LOW */ +/* -------------------------------------------------------------------------- */ +extern void nrf24_ce_digitalWrite(uint8_t state); + +/* -------------------------------------------------------------------------- */ +/* nrf24 CE pin control function + * - state:1 => Pin HIGH + * - state:0 => Pin LOW */ +/* -------------------------------------------------------------------------- */ +extern void nrf24_csn_digitalWrite(uint8_t state); + +/* -------------------------------------------------------------------------- */ +/* nrf24 SCK pin control function + * - state:1 => Pin HIGH + * - state:0 => Pin LOW */ +/* -------------------------------------------------------------------------- */ +extern void nrf24_sck_digitalWrite(uint8_t state); + +/* -------------------------------------------------------------------------- */ +/* nrf24 MOSI pin control function + * - state:1 => Pin HIGH + * - state:0 => Pin LOW */ +/* -------------------------------------------------------------------------- */ +extern void nrf24_mosi_digitalWrite(uint8_t state); + +/* -------------------------------------------------------------------------- */ +/* nrf24 MISO pin read function +* - returns: Non-zero if the pin is high */ +/* -------------------------------------------------------------------------- */ +extern uint8_t nrf24_miso_digitalRead(); + +#endif diff --git a/include/servos.h b/robot/include/servos.h similarity index 58% rename from include/servos.h rename to robot/include/servos.h index fa0b899..de3aad4 100644 --- a/include/servos.h +++ b/robot/include/servos.h @@ -9,10 +9,13 @@ #define SERVO_MIN 930 // (us). Go backwards #define SERVO_MAX 1930 // (us). Go forwards -#define SERVO_MID (SERVO_MIN + SERVO_MAX) / 2 // Stop -#define PWM_PERIOD 16384 // (1000000 / F_CPU) * PRESCALER * 256) / F_CPU (us) +#define SERVO_MID (SERVO_MIN + SERVO_MAX) / 2 // (us). Stop -#define US2TIMER0(us) (255 * (uint32_t)us) / PWM_PERIOD +#define PRESCALER 1024L +#define PWM_CLOCK F_CPU / (256 * PRESCALER) +#define PWM_PERIOD_US 1000000 / PWM_CLOCK + +#define US2TIMER0(us) (255 * (uint32_t)us) / PWM_PERIOD_US void init_servos(void); diff --git a/include/sonar.h b/robot/include/sonar.h similarity index 100% rename from include/sonar.h rename to robot/include/sonar.h diff --git a/include/temperature.h b/robot/include/temperature.h similarity index 100% rename from include/temperature.h rename to robot/include/temperature.h diff --git a/robot/src/led.c b/robot/src/led.c new file mode 100644 index 0000000..1057fd4 --- /dev/null +++ b/robot/src/led.c @@ -0,0 +1,9 @@ +#include +#include "common.h" +#include "led.h" + +void init_leds(void) +{ + SET(LED_DDR, LED_GREEN_BIT); + SET(LED_DDR, LED_BLUE_BIT); +} diff --git a/src/main.c b/robot/src/main.c similarity index 97% rename from src/main.c rename to robot/src/main.c index cd22275..825d74f 100644 --- a/src/main.c +++ b/robot/src/main.c @@ -37,7 +37,7 @@ int main(void) // Use green LED as power LED SET(LED_PORT, LED_GREEN_BIT); - /* run_servos(); */ + run_servos(); /* read_temp(); */ while (1) { uint16_t distance_int_cm = read_sonar(); diff --git a/robot/src/nrf24.c b/robot/src/nrf24.c new file mode 100644 index 0000000..e7dd2e9 --- /dev/null +++ b/robot/src/nrf24.c @@ -0,0 +1,339 @@ +/* +* ---------------------------------------------------------------------------- +* “THE COFFEEWARE LICENSE” (Revision 1): +* wrote this file. As long as you retain this notice you +* can do whatever you want with this stuff. If we meet some day, and you think +* this stuff is worth it, you can buy me a coffee in return. +* ----------------------------------------------------------------------------- +* This library is based on this library: +* https://github.com/aaronds/arduino-nrf24l01 +* Which is based on this library: +* http://www.tinkerer.eu/AVRLib/nRF24L01 +* ----------------------------------------------------------------------------- +*/ +#include "nrf24.h" + +uint8_t payload_len; + +/* init the hardware pins */ +void nrf24_init() +{ + nrf24_setupPins(); + nrf24_ce_digitalWrite(LOW); + nrf24_csn_digitalWrite(HIGH); +} + +/* configure the module */ +void nrf24_config(uint8_t channel, uint8_t pay_length) +{ + /* Use static payload length ... */ + payload_len = pay_length; + + // Set RF channel + nrf24_configRegister(RF_CH, channel); + + // Set length of incoming payload + nrf24_configRegister(RX_PW_P0, 0x00); // Auto-ACK pipe ... + nrf24_configRegister(RX_PW_P1, payload_len); // Data payload pipe + nrf24_configRegister(RX_PW_P2, 0x00); // Pipe not used + nrf24_configRegister(RX_PW_P3, 0x00); // Pipe not used + nrf24_configRegister(RX_PW_P4, 0x00); // Pipe not used + nrf24_configRegister(RX_PW_P5, 0x00); // Pipe not used + + // 1 Mbps, TX gain: 0dbm + nrf24_configRegister(RF_SETUP, (0 << RF_DR) | ((0x03) << RF_PWR)); + + // CRC enable, 1 byte CRC length + nrf24_configRegister(CONFIG, nrf24_CONFIG); + + // Auto Acknowledgment + nrf24_configRegister(EN_AA, (1 << ENAA_P0) | (1 << ENAA_P1) | (0 << ENAA_P2) | (0 << ENAA_P3) | (0 << ENAA_P4) | (0 << ENAA_P5)); + + // Enable RX addresses + nrf24_configRegister(EN_RXADDR, (1 << ERX_P0) | (1 << ERX_P1) | (0 << ERX_P2) | (0 << ERX_P3) | (0 << ERX_P4) | (0 << ERX_P5)); + + // Auto retransmit delay: 1000 us and Up to 15 retransmit trials + nrf24_configRegister(SETUP_RETR, (0x04 << ARD) | (0x0F << ARC)); + + // Dynamic length configurations: No dynamic length + nrf24_configRegister(DYNPD, (0 << DPL_P0) | (0 << DPL_P1) | (0 << DPL_P2) | (0 << DPL_P3) | (0 << DPL_P4) | (0 << DPL_P5)); + + // Start listening + nrf24_powerUpRx(); +} + +/* Set the RX address */ +void nrf24_rx_address(uint8_t *adr) +{ + nrf24_ce_digitalWrite(LOW); + nrf24_writeRegister(RX_ADDR_P1, adr, nrf24_ADDR_LEN); + nrf24_ce_digitalWrite(HIGH); +} + +/* Returns the payload length */ +uint8_t nrf24_payload_length() +{ + return payload_len; +} + +/* Set the TX address */ +void nrf24_tx_address(uint8_t *adr) +{ + /* RX_ADDR_P0 must be set to the sending addr for auto ack to work. */ + nrf24_writeRegister(RX_ADDR_P0, adr, nrf24_ADDR_LEN); + nrf24_writeRegister(TX_ADDR, adr, nrf24_ADDR_LEN); +} + +/* Checks if data is available for reading */ +/* Returns 1 if data is ready ... */ +uint8_t nrf24_dataReady() +{ + // See note in getData() function - just checking RX_DR isn't good enough + uint8_t status = nrf24_getStatus(); + + // We can short circuit on RX_DR, but if it's not set, we still need + // to check the FIFO for any pending packets + if (status & (1 << RX_DR)) { + return 1; + } + + return !nrf24_rxFifoEmpty();; +} + +/* Checks if receive FIFO is empty or not */ +uint8_t nrf24_rxFifoEmpty() +{ + uint8_t fifoStatus; + + nrf24_readRegister(FIFO_STATUS, &fifoStatus, 1); + + return (fifoStatus & (1 << RX_EMPTY)); +} + +/* Returns the length of data waiting in the RX fifo */ +uint8_t nrf24_payloadLength() +{ + uint8_t status; + nrf24_csn_digitalWrite(LOW); + spi_transfer(R_RX_PL_WID); + status = spi_transfer(0x00); + nrf24_csn_digitalWrite(HIGH); + return status; +} + +/* Reads payload bytes into data array */ +void nrf24_getData(uint8_t *data) +{ + /* Pull down chip select */ + nrf24_csn_digitalWrite(LOW); + + /* Send cmd to read rx payload */ + spi_transfer(R_RX_PAYLOAD); + + /* Read payload */ + nrf24_transferSync(data, data, payload_len); + + /* Pull up chip select */ + nrf24_csn_digitalWrite(HIGH); + + /* Reset status register */ + nrf24_configRegister(STATUS, (1 << RX_DR)); +} + +/* Returns the number of retransmissions occured for the last message */ +uint8_t nrf24_retransmissionCount() +{ + uint8_t rv; + nrf24_readRegister(OBSERVE_TX, &rv, 1); + rv = rv & 0x0F; + return rv; +} + +// Sends a data package to the default address. Be sure to send the correct +// amount of bytes as configured as payload on the receiver. +void nrf24_send(uint8_t *value) +{ + /* Go to Standby-I first */ + nrf24_ce_digitalWrite(LOW); + + /* Set to transmitter mode , Power up if needed */ + nrf24_powerUpTx(); + + /* Do we really need to flush TX fifo each time ? */ +#if 1 + /* Pull down chip select */ + nrf24_csn_digitalWrite(LOW); + + /* Write cmd to flush transmit FIFO */ + spi_transfer(FLUSH_TX); + + /* Pull up chip select */ + nrf24_csn_digitalWrite(HIGH); +#endif + + /* Pull down chip select */ + nrf24_csn_digitalWrite(LOW); + + /* Write cmd to write payload */ + spi_transfer(W_TX_PAYLOAD); + + /* Write payload */ + nrf24_transmitSync(value, payload_len); + + /* Pull up chip select */ + nrf24_csn_digitalWrite(HIGH); + + /* Start the transmission */ + nrf24_ce_digitalWrite(HIGH); +} + +uint8_t nrf24_isSending() +{ + uint8_t status; + + /* read the current status */ + status = nrf24_getStatus(); + + /* if sending successful (TX_DS) or max retries exceded (MAX_RT). */ + if ((status & ((1 << TX_DS) | (1 << MAX_RT)))) { + return 0; /* false */ + } + + return 1; /* true */ + +} + +uint8_t nrf24_getStatus() +{ + uint8_t rv; + nrf24_csn_digitalWrite(LOW); + rv = spi_transfer(NOP); + nrf24_csn_digitalWrite(HIGH); + return rv; +} + +uint8_t nrf24_lastMessageStatus() +{ + uint8_t rv; + + rv = nrf24_getStatus(); + + /* Transmission went OK */ + if ((rv & ((1 << TX_DS)))) { + return NRF24_TRANSMISSON_OK; + } + /* Maximum retransmission count is reached */ + /* Last message probably went missing ... */ + else if ((rv & ((1 << MAX_RT)))) { + return NRF24_MESSAGE_LOST; + } + /* Probably still sending ... */ + else { + return 0xFF; + } +} + +void nrf24_powerUpRx() +{ + nrf24_csn_digitalWrite(LOW); + spi_transfer(FLUSH_RX); + nrf24_csn_digitalWrite(HIGH); + + nrf24_configRegister(STATUS, (1 << RX_DR) | (1 << TX_DS) | (1 << MAX_RT)); + + nrf24_ce_digitalWrite(LOW); + nrf24_configRegister(CONFIG, nrf24_CONFIG | ((1 << PWR_UP) | (1 << PRIM_RX))); + nrf24_ce_digitalWrite(HIGH); +} + +void nrf24_powerUpTx() +{ + nrf24_configRegister(STATUS, (1 << RX_DR) | (1 << TX_DS) | (1 << MAX_RT)); + + nrf24_configRegister(CONFIG, nrf24_CONFIG | ((1 << PWR_UP) | (0 << PRIM_RX))); +} + +void nrf24_powerDown() +{ + nrf24_ce_digitalWrite(LOW); + nrf24_configRegister(CONFIG, nrf24_CONFIG); +} + +/* software spi routine */ +uint8_t spi_transfer(uint8_t tx) +{ + uint8_t i = 0; + uint8_t rx = 0; + + nrf24_sck_digitalWrite(LOW); + + for (i = 0; i < 8; i++) { + + if (tx & (1 << (7 - i))) { + nrf24_mosi_digitalWrite(HIGH); + } else { + nrf24_mosi_digitalWrite(LOW); + } + + nrf24_sck_digitalWrite(HIGH); + + rx = rx << 1; + if (nrf24_miso_digitalRead()) { + rx |= 0x01; + } + + nrf24_sck_digitalWrite(LOW); + + } + + return rx; +} + +/* send and receive multiple bytes over SPI */ +void nrf24_transferSync(uint8_t *dataout, uint8_t *datain, uint8_t len) +{ + uint8_t i; + + for (i = 0; i < len; i++) { + datain[i] = spi_transfer(dataout[i]); + } + +} + +/* send multiple bytes over SPI */ +void nrf24_transmitSync(uint8_t *dataout, uint8_t len) +{ + uint8_t i; + + for (i = 0; i < len; i++) { + spi_transfer(dataout[i]); + } + +} + +/* Clocks only one byte into the given nrf24 register */ +void nrf24_configRegister(uint8_t reg, uint8_t value) +{ + nrf24_csn_digitalWrite(LOW); + spi_transfer(W_REGISTER | (REGISTER_MASK & reg)); + spi_transfer(value); + nrf24_csn_digitalWrite(HIGH); +} + +/* Read single register from nrf24 */ +void nrf24_readRegister(uint8_t reg, uint8_t *value, uint8_t len) +{ + nrf24_csn_digitalWrite(LOW); + spi_transfer(R_REGISTER | (REGISTER_MASK & reg)); + nrf24_transferSync(value, value, len); + nrf24_csn_digitalWrite(HIGH); +} + +/* Write to a single register of nrf24 */ +void nrf24_writeRegister(uint8_t reg, uint8_t *value, uint8_t len) +{ + nrf24_csn_digitalWrite(LOW); + spi_transfer(W_REGISTER | (REGISTER_MASK & reg)); + nrf24_transmitSync(value, len); + nrf24_csn_digitalWrite(HIGH); +} diff --git a/robot/src/radioPinFunctions.c b/robot/src/radioPinFunctions.c new file mode 100644 index 0000000..43ca62b --- /dev/null +++ b/robot/src/radioPinFunctions.c @@ -0,0 +1,74 @@ +/* +* ---------------------------------------------------------------------------- +* “THE COFFEEWARE LICENSE” (Revision 1): +* wrote this file. As long as you retain this notice you +* can do whatever you want with this stuff. If we meet some day, and you think +* this stuff is worth it, you can buy me a coffee in return. +* ----------------------------------------------------------------------------- +* Please define your platform spesific functions in this file ... +* ----------------------------------------------------------------------------- +*/ + +#include +#include "common.h" + +#define REG DDRB +#define PORT PORTB +#define PIN PINB +#define PIN_CE PB0 +#define PIN_CSN PB1 +#define PIN_SCK PB5 +#define PIN_MOSI PB3 +#define PIN_MISO PB4 + +/* ------------------------------------------------------------------------- */ +void nrf24_setupPins(void) +{ + SET(REG, PIN_CE); + SET(REG, PIN_CSN); + SET(REG, PIN_SCK); + SET(REG, PIN_MOSI); + CLR(REG, PIN_MISO); +} +/* ------------------------------------------------------------------------- */ +void nrf24_ce_digitalWrite(uint8_t state) +{ + if (state) { + SET(PORT, PIN_CE); + } else { + CLR(PORT, PIN_CE); + } +} +/* ------------------------------------------------------------------------- */ +void nrf24_csn_digitalWrite(uint8_t state) +{ + if (state) { + SET(PORT, PIN_CSN); + } else { + CLR(PORT, PIN_CSN); + } +} +/* ------------------------------------------------------------------------- */ +void nrf24_sck_digitalWrite(uint8_t state) +{ + if (state) { + SET(PORT, PIN_SCK); + } else { + CLR(PORT, PIN_SCK); + } +} +/* ------------------------------------------------------------------------- */ +void nrf24_mosi_digitalWrite(uint8_t state) +{ + if (state) { + SET(PORT, PIN_MOSI); + } else { + CLR(PORT, PIN_MOSI); + } +} +/* ------------------------------------------------------------------------- */ +uint8_t nrf24_miso_digitalRead(void) +{ + return CHK(PIN, PIN_MISO); +} +/* ------------------------------------------------------------------------- */ diff --git a/src/servos.c b/robot/src/servos.c similarity index 90% rename from src/servos.c rename to robot/src/servos.c index 60257e2..df4bd5a 100644 --- a/src/servos.c +++ b/robot/src/servos.c @@ -15,9 +15,9 @@ void init_servos(void) SET(TCCR0A, WGM00); SET(TCCR0A, WGM01); - // Prescaler. clkPWM = clkIO / 64 + // Prescaler = 1024 SET(TCCR0B, CS00); - SET(TCCR0B, CS01); + SET(TCCR0B, CS02); } void run_servos(void) diff --git a/src/sonar.c b/robot/src/sonar.c similarity index 85% rename from src/sonar.c rename to robot/src/sonar.c index f5bd653..801009c 100644 --- a/src/sonar.c +++ b/robot/src/sonar.c @@ -5,7 +5,7 @@ #include "led.h" volatile uint32_t trig_counter; -volatile uint32_t no_of_ticks; +uint32_t no_of_ticks; void init_sonar(void) { @@ -36,19 +36,15 @@ uint16_t read_sonar(void) sei(); // Count cycles until ECHO goes low while (CHK(ECHO_PIN, ECHO_BIT)) { - if (no_of_ticks + TCNT1 > SONAR_TIMEOUT) { + ++no_of_ticks; + if (no_of_ticks > SONAR_TIMEOUT) { return SONAR_ERROR; } } TCCR1B = 0x00; cli(); - no_of_ticks += TCNT1; return (uint16_t)(no_of_ticks / (CYCLES_PER_US * 58)); } -ISR(TIMER1_OVF_vect) -{ - no_of_ticks += TIMER_MAX; -} diff --git a/src/temperature.c b/robot/src/temperature.c similarity index 100% rename from src/temperature.c rename to robot/src/temperature.c