]> Pileus Git - ~andy/csm213a-hw/commitdiff
Import testing code and update makefiles
authorAndy Spencer <andy753421@gmail.com>
Fri, 14 Mar 2014 03:17:45 +0000 (03:17 +0000)
committerAndy Spencer <andy753421@gmail.com>
Fri, 14 Mar 2014 03:28:41 +0000 (03:28 +0000)
This supports building and install both the primary build (mbed.bin) and
the secondary testing build (tester.bin).

common.mk
hw2/install.sh
hw2/makefile
hw2/tester.cpp [new file with mode: 0644]

index a0f65a8959b1c5606dbd6303169c391d49a7ccb1..1a1adf22cfb2462bd8ff0937eb4df7a744f61984 100644 (file)
--- 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 $< $@
index f00994e4831e168b35bbc507b34a3a96274216f0..8d16c2e9131b71dcbcaf2ea69772ac8c8d281f52 100755 (executable)
@@ -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
index 80fdcb8140ea34552a1dc37a50d92422d7145a20..e7c5b4006ffe77909e783aeed7958813a3f0dbb4 100644 (file)
@@ -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 (file)
index 0000000..3a55bd8
--- /dev/null
@@ -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);
+       }
+}