From: Andy Spencer Date: Fri, 14 Mar 2014 03:17:45 +0000 (+0000) Subject: Import testing code and update makefiles X-Git-Url: http://pileus.org/git/?p=~andy%2Fcsm213a-hw;a=commitdiff_plain;h=a9299548b2cae6dfe9050dd7d054c5496e5c07c3 Import testing code and update makefiles This supports building and install both the primary build (mbed.bin) and the secondary testing build (tester.bin). --- diff --git a/common.mk b/common.mk index a0f65a8..1a1adf2 100644 --- a/common.mk +++ b/common.mk @@ -25,7 +25,7 @@ LDFLAGS += --specs=nano.specs -Wl,-u_printf_float -Wl,--gc-sections \ -Wl,--start-group -lmbed -lc_s -lstdc++_s -Wl,--end-group # Targets -all: $(PROG).bin +all: $(addsuffix .bin,$(PROG)) info: all @echo "LS $(PROG).bin $(PROG).elf" @@ -51,8 +51,11 @@ openocd: all -f board/frdm-kl46z.cfg clean: - @echo "RM $(PROG).bin $(PROG).elf $(OBJS)" - @rm -f $(PROG).bin $(PROG).elf $(OBJS) + @echo "RM *.bin *.elf *.o $(CLEAN)" + @rm -f *.bin *.elf *.o $(CLEAN) + +# Defaults +$(PROG).elf: $(OJBS) # Rules %.o: %.c $(wildcard *.h) makefile ../common.mk ../config.mk @@ -67,10 +70,10 @@ clean: @echo "CXX $<" @$(GXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< -$(PROG).elf: $(OBJS) +%.elf: @echo "LD $+" @$(GLD) $(CFLAGS) -o $@ $^ $(LDFLAGS) -$(PROG).bin: $(PROG).elf +%.bin: %.elf @echo "BIN $+" @$(OBJCOPY) -O binary $< $@ diff --git a/hw2/install.sh b/hw2/install.sh index f00994e..8d16c2e 100755 --- a/hw2/install.sh +++ b/hw2/install.sh @@ -21,7 +21,11 @@ if [ -z "$1" ] || [ "$1" = "-h" ]; then exit 0 fi -install "$1" /dev/sdb /mnt/mbed1 & -install "$1" /dev/sdc /mnt/mbed2 & +if [ "$2" ]; then + install "$1" "$2" "$3" & +else + install "$1" /dev/sdb /mnt/mbed1 & + install "$1" /dev/sdc /mnt/mbed2 & +fi wait diff --git a/hw2/makefile b/hw2/makefile index 80fdcb8..e7c5b40 100644 --- a/hw2/makefile +++ b/hw2/makefile @@ -1,27 +1,40 @@ -PROG = mbed -UART0 = /dev/ttyACM0 -UART1 = /dev/ttyACM1 -OBJS = main.o serial_irq.o serial_dma.o timer_dma.o +# Common settings +UART0 = /dev/ttyACM0 +UART1 = /dev/ttyACM1 +CLEAN = control tags CPPFLAGS = LDFLAGS = -lm -default: info run +# Common rules +default: all -control: control.c messages.h - gcc -Wall -o $@ $< - -run: all control install.sh - @./install.sh $(PROG).bin - @./control $(UART0) 1 - @./control $(UART1) 2 sync +all: mbed.elf tester.elf control terms: - term /dev/ttyACM0 & - term /dev/ttyACM1 & + test -c $(UART0) && term $(UART0) & + test -c $(UART1) && term $(UART1) & dist: zip mbed.zip makefile ../common.mk *.{c,cpp,h} */*.{cpp,.h} +# Primary mbed (mbed1/mbed2) +mbed.elf: main.o serial_irq.o serial_dma.o timer_dma.o + +mbed-run: mbed.bin control install.sh + @./install.sh $< + @./control $(UART0) 1 + @./control $(UART1) 2 sync + +# Testing mbed (mbed3) +tester.elf: tester.o + +tester-run: tester.bin install.sh + @./install.sh $< /dev/sdb /mnt/usb + +# Controls programs +control: control.c messages.h + gcc -Wall -o $@ $< + -include ../config.mk -include ../common.mk diff --git a/hw2/tester.cpp b/hw2/tester.cpp new file mode 100644 index 0000000..3a55bd8 --- /dev/null +++ b/hw2/tester.cpp @@ -0,0 +1,54 @@ +/* main.cpp + * mbed project: Simple_Square_Wave + * mbed board: FRDM-KL46Z + * Generate square waves using DigitalOut. + */ + +#include "mbed.h" + +DigitalOut Square_Wave(PTD3); // Used PWM output is PTD3 +InterruptIn Control_Testing(PTC12); // SW3 + +void Control_T(void); + +int START_STOP_FLAG = 0; +float period_s = 0.0001; + +extern serial_t stdio_uart; + +int main(int arc, char **argv) +{ + serial_init(&stdio_uart, USBTX, USBRX); + serial_baud(&stdio_uart, 115200); + printf("starting\r\n"); + + Control_Testing.rise(&Control_T); // Enable getMode interrupt handler + __enable_irq(); + + while(1) + { + if(START_STOP_FLAG == 1) + { + Square_Wave.write(0); + wait(period_s/2); + Square_Wave.write(1); + wait(period_s/2); + } + else + Square_Wave.write(0); + } +} + +void Control_T(void) +{ + if(START_STOP_FLAG == 0) + { + period_s = 1; + START_STOP_FLAG = 1; + } + else + { + START_STOP_FLAG = 0; + Square_Wave.write(0); + } +}