From bdda7dcfdce84ad3900853d6a2fb678d15763bef Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Fri, 14 Mar 2014 05:52:06 +0000 Subject: [PATCH] Bring in utilities to tester --- hw2/makefile | 4 +- hw2/tester.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 93 insertions(+), 15 deletions(-) diff --git a/hw2/makefile b/hw2/makefile index 11824a8..aba2af8 100644 --- a/hw2/makefile +++ b/hw2/makefile @@ -7,7 +7,7 @@ CPPFLAGS = LDFLAGS = -lm # Common rules -default: all +default: mbed-run all: mbed.elf tester.elf control @@ -27,7 +27,7 @@ mbed-run: mbed.bin control install.sh @./control $(UART1) 2 sync # Testing mbed (mbed3) -tester.elf: tester.o +tester.elf: tester.o serial_irq.o timer_dma.o messages.o tester-run: tester.bin install.sh @./install.sh $< /dev/sdb /mnt/usb diff --git a/hw2/tester.cpp b/hw2/tester.cpp index 3a55bd8..7e766fc 100644 --- a/hw2/tester.cpp +++ b/hw2/tester.cpp @@ -5,40 +5,115 @@ */ #include "mbed.h" +#include "timer_dma.h" +#include "serial_irq.h" +#include "messages.h" -DigitalOut Square_Wave(PTD3); // Used PWM output is PTD3 -InterruptIn Control_Testing(PTC12); // SW3 +#define N_ELEM(x) (sizeof(x)/sizeof((x)[0])) +// Push-button IRQ handler void Control_T(void); +// Task modes +void Empty_Task(void); +void Receive_Event(void); +void Generate_Event(void); + +// Local variables int START_STOP_FLAG = 0; float period_s = 0.0001; +DigitalOut Square_Wave(PTD3); // Used PWM output is PTD3 +InterruptIn Control_Testing(PTC12); // SW3 + +tdma_t *Tdma_Mbed1; +tdma_t *Tdma_Mbed2; + +sirq_t *Sirq_Bbb; + +parser_t Parser_Bbb; +// Extern stuff... extern serial_t stdio_uart; +// Taks tables +static struct { + const char *mode; + void (*func)(void); +} task_table[] = { + { "null", Empty_Task }, + { "generate", Generate_Event }, + { "receive", Receive_Event }, +}; + +int task_index = 0; + +// Main int main(int arc, char **argv) { + // Set debug baud rate serial_init(&stdio_uart, USBTX, USBRX); serial_baud(&stdio_uart, 115200); - printf("starting\r\n"); + // Setup BBB uart port + Sirq_Bbb = sirq_open(SIRQ_UART1, PTE0, PTE1, 115200); + + // Setup time tags + Tdma_Mbed1 = tdma_open(TDMA_CHAN2, 3, PTD2, PullUp); // TODO -- Should be on PTC + Tdma_Mbed2 = tdma_open(TDMA_CHAN3, 3, PTD3, PullUp); // TODO -- Should be on PTD + + // Register messages + //msg_register(&parser_bbb, MSG_ID_INIT, (handler_t)serial_handle_init); + + // Start timers + tdma_start(Tdma_Mbed1); + tdma_start(Tdma_Mbed2); + + // Enable push-button controlling Control_Testing.rise(&Control_T); // Enable getMode interrupt handler + + // Main loop __enable_irq(); + while (1) { + // Recieve serial data + while (sirq_ready(Sirq_Bbb)) { + int byte = sirq_getc(Sirq_Bbb); + msg_receive(&Parser_Bbb, byte); + } - while(1) + // Run task function + task_table[task_index].func(); + } +} + +// Task functions +void Empty_Task(void) +{ + // do nothing +} + +void Receive_Event(void) +{ + uint64_t event; + if (tdma_stamp(Tdma_Mbed1, &event)) + printf("event received - rcv\r\n"); + if (tdma_stamp(Tdma_Mbed2, &event)) + printf("event received - xmt\r\n"); +} + +void Generate_Event(void) +{ + if (START_STOP_FLAG == 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); + Square_Wave.write(0); + wait(period_s/2); + Square_Wave.write(1); + wait(period_s/2); } + else + Square_Wave.write(0); } +// Interrupt handlers void Control_T(void) { if(START_STOP_FLAG == 0) @@ -51,4 +126,7 @@ void Control_T(void) START_STOP_FLAG = 0; Square_Wave.write(0); } + + // Implement task cycling + // task_index = (task_index + 1) % N_ELEM(task_table); } -- 2.43.2