JEK changes enabling proper recording of IMU/GPS datastrams - 02-APR-2013

Dependencies:   mbed

Fork of GPS_Incremental by Dan Matthews

Committer:
jekain314
Date:
Fri Apr 19 16:21:27 2013 +0000
Revision:
9:b45feb91ba38
Parent:
0:c746ee34feae
update to allow better imu gps data collection

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dannyman939 0:c746ee34feae 1 #ifdef COMPILE_EXAMPLE_CODE_MODSERIAL_MODDMA
dannyman939 0:c746ee34feae 2
dannyman939 0:c746ee34feae 3 /*
dannyman939 0:c746ee34feae 4 * To run this test program, link p9 to p10 so the Serial loops
dannyman939 0:c746ee34feae 5 * back and receives characters it sends.
dannyman939 0:c746ee34feae 6 */
dannyman939 0:c746ee34feae 7
dannyman939 0:c746ee34feae 8 #include "mbed.h"
dannyman939 0:c746ee34feae 9
dannyman939 0:c746ee34feae 10 /* Note, this example requires that you also import into the Mbed
dannyman939 0:c746ee34feae 11 compiler the MODDMA project as well as MODSERIAL
dannyman939 0:c746ee34feae 12 http://mbed.org/users/AjK/libraries/MODDMA/latest
dannyman939 0:c746ee34feae 13 MODDMA.h MUST come before MODSERIAL.h */
dannyman939 0:c746ee34feae 14 #include "MODDMA.h" // <--- Declare first
dannyman939 0:c746ee34feae 15 #include "MODSERIAL.h" // Flollowed by MODSERIAL
dannyman939 0:c746ee34feae 16
dannyman939 0:c746ee34feae 17 DigitalOut led1(LED1);
dannyman939 0:c746ee34feae 18 DigitalOut led2(LED2);
dannyman939 0:c746ee34feae 19 DigitalOut led3(LED3);
dannyman939 0:c746ee34feae 20 DigitalOut led4(LED4);
dannyman939 0:c746ee34feae 21
dannyman939 0:c746ee34feae 22 MODSERIAL pc(USBTX, USBRX);
dannyman939 0:c746ee34feae 23
dannyman939 0:c746ee34feae 24 /*
dannyman939 0:c746ee34feae 25 * As experiement, you can define MODSERIAL as show here and see what
dannyman939 0:c746ee34feae 26 * effects it has on the LEDs.
dannyman939 0:c746ee34feae 27 *
dannyman939 0:c746ee34feae 28 * MODSERIAL uart(TX_PIN, RX_PIN, 512);
dannyman939 0:c746ee34feae 29 * With this, the 512 characters sent can straight into the buffer
dannyman939 0:c746ee34feae 30 * vary quickly. This means LED1 is only on briefly as the TX buffer
dannyman939 0:c746ee34feae 31 * fills.
dannyman939 0:c746ee34feae 32 *
dannyman939 0:c746ee34feae 33 * MODSERIAL uart(TX_PIN, RX_PIN, 32);
dannyman939 0:c746ee34feae 34 * With this, the buffer is smaller than the default 256 bytes and
dannyman939 0:c746ee34feae 35 * therefore LED1 stays on much longer while the system waits for
dannyman939 0:c746ee34feae 36 * room in the TX buffer.
dannyman939 0:c746ee34feae 37 */
dannyman939 0:c746ee34feae 38 MODSERIAL uart(TX_PIN, RX_PIN);
dannyman939 0:c746ee34feae 39
dannyman939 0:c746ee34feae 40 MODDMA dma;
dannyman939 0:c746ee34feae 41
dannyman939 0:c746ee34feae 42 // This function is called when a character goes from the TX buffer
dannyman939 0:c746ee34feae 43 // to the Uart THR FIFO register.
dannyman939 0:c746ee34feae 44 void txCallback(void) {
dannyman939 0:c746ee34feae 45 led2 = !led2;
dannyman939 0:c746ee34feae 46 }
dannyman939 0:c746ee34feae 47
dannyman939 0:c746ee34feae 48 // This function is called when TX buffer goes empty
dannyman939 0:c746ee34feae 49 void txEmpty(void) {
dannyman939 0:c746ee34feae 50 led2 = 0;
dannyman939 0:c746ee34feae 51 pc.puts(" Done. ");
dannyman939 0:c746ee34feae 52 }
dannyman939 0:c746ee34feae 53
dannyman939 0:c746ee34feae 54 void dmaComplete(void) {
dannyman939 0:c746ee34feae 55 led1 = 1;
dannyman939 0:c746ee34feae 56 }
dannyman939 0:c746ee34feae 57
dannyman939 0:c746ee34feae 58 // This function is called when a character goes into the RX buffer.
dannyman939 0:c746ee34feae 59 void rxCallback(void) {
dannyman939 0:c746ee34feae 60 led3 = !led3;
dannyman939 0:c746ee34feae 61 pc.putc(uart.getc());
dannyman939 0:c746ee34feae 62 }
dannyman939 0:c746ee34feae 63
dannyman939 0:c746ee34feae 64 int main() {
dannyman939 0:c746ee34feae 65 char s1[] = " *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* ";
dannyman939 0:c746ee34feae 66 int c = 'A';
dannyman939 0:c746ee34feae 67
dannyman939 0:c746ee34feae 68 // Tell MODSERIAL where the MODDMA controller is.
dannyman939 0:c746ee34feae 69 pc.MODDMA( &dma );
dannyman939 0:c746ee34feae 70
dannyman939 0:c746ee34feae 71 // Ensure the baud rate for the PC "USB" serial is much
dannyman939 0:c746ee34feae 72 // higher than "uart" baud rate below.
dannyman939 0:c746ee34feae 73 pc.baud( PC_BAUD );
dannyman939 0:c746ee34feae 74
dannyman939 0:c746ee34feae 75 // Use a deliberatly slow baud to fill up the TX buffer
dannyman939 0:c746ee34feae 76 uart.baud(1200);
dannyman939 0:c746ee34feae 77
dannyman939 0:c746ee34feae 78 uart.attach( &txCallback, MODSERIAL::TxIrq );
dannyman939 0:c746ee34feae 79 uart.attach( &rxCallback, MODSERIAL::RxIrq );
dannyman939 0:c746ee34feae 80 uart.attach( &txEmpty, MODSERIAL::TxEmpty );
dannyman939 0:c746ee34feae 81
dannyman939 0:c746ee34feae 82 // Loop sending characters. We send 512
dannyman939 0:c746ee34feae 83 // which is twice the default TX/RX buffer size.
dannyman939 0:c746ee34feae 84
dannyman939 0:c746ee34feae 85 led1 = 0;
dannyman939 0:c746ee34feae 86
dannyman939 0:c746ee34feae 87 // Send the buffer s using DMA channel 7
dannyman939 0:c746ee34feae 88 pc.attach_dmaSendComplete( &dmaComplete );
dannyman939 0:c746ee34feae 89 pc.dmaSend( s1, sizeof(s1), MODDMA::Channel_7 );
dannyman939 0:c746ee34feae 90
dannyman939 0:c746ee34feae 91 for (int loop = 0; loop < 512; loop++) {
dannyman939 0:c746ee34feae 92 uart.printf("%c", c);
dannyman939 0:c746ee34feae 93 c++;
dannyman939 0:c746ee34feae 94 if (c > 'Z') c = 'A';
dannyman939 0:c746ee34feae 95 }
dannyman939 0:c746ee34feae 96
dannyman939 0:c746ee34feae 97 led1 = 0; // Show the end of sending by switching off LED1.
dannyman939 0:c746ee34feae 98
dannyman939 0:c746ee34feae 99 // End program. Flash LED4. Notice how LED 2 and 3 continue
dannyman939 0:c746ee34feae 100 // to flash for a short period while the interrupt system
dannyman939 0:c746ee34feae 101 // continues to send the characters left in the TX buffer.
dannyman939 0:c746ee34feae 102
dannyman939 0:c746ee34feae 103 while(1) {
dannyman939 0:c746ee34feae 104 led4 = !led4;
dannyman939 0:c746ee34feae 105 wait(0.25);
dannyman939 0:c746ee34feae 106 }
dannyman939 0:c746ee34feae 107 }
dannyman939 0:c746ee34feae 108
dannyman939 0:c746ee34feae 109 /*
dannyman939 0:c746ee34feae 110 * Notes. Here is the sort of output you can expect on your PC/Mac/Linux host
dannyman939 0:c746ee34feae 111 * machine that is connected to the "pc" USB serial port.
dannyman939 0:c746ee34feae 112 *
dannyman939 0:c746ee34feae 113 * *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE
dannyman939 0:c746ee34feae 114 * FGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA
dannyman939 0:c746ee34feae 115 * BCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVW
dannyman939 0:c746ee34feae 116 * XYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRS
dannyman939 0:c746ee34feae 117 * TUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNO
dannyman939 0:c746ee34feae 118 * PQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJK
dannyman939 0:c746ee34feae 119 * LMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFG
dannyman939 0:c746ee34feae 120 * HIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQ Done. R
dannyman939 0:c746ee34feae 121 *
dannyman939 0:c746ee34feae 122 * Note how the DMA blocks the TX buffer sending under standard interrupt control.
dannyman939 0:c746ee34feae 123 * Not until the DMA transfer is complete will "normal" buffered TX sending resume.
dannyman939 0:c746ee34feae 124 *
dannyman939 0:c746ee34feae 125 * Of interest is that last "R" character after the system has said "Done."
dannyman939 0:c746ee34feae 126 * This comes from the fact that the TxEmpty callback is made when the TX buffer
dannyman939 0:c746ee34feae 127 * becomes empty. MODSERIAL makes use of the fact that the Uarts built into the
dannyman939 0:c746ee34feae 128 * LPC17xx device use a 16 byte FIFO on both RX and TX channels. This means that
dannyman939 0:c746ee34feae 129 * when the TxEmpty callback is made, the TX buffer is empty, but that just means
dannyman939 0:c746ee34feae 130 * the "last few characters" were written to the TX FIFO. So although the TX
dannyman939 0:c746ee34feae 131 * buffer has gone empty, the Uart's transmit system is still sending any remaining
dannyman939 0:c746ee34feae 132 * characters from it's TX FIFO. If you want to be truely sure all the characters
dannyman939 0:c746ee34feae 133 * you have sent have left the Mbed then call txIsBusy(); This function will
dannyman939 0:c746ee34feae 134 * return true if characters are still being sent. If it returns false after
dannyman939 0:c746ee34feae 135 * the Tx buffer is empty then all your characters have been sent.
dannyman939 0:c746ee34feae 136 *
dannyman939 0:c746ee34feae 137 * In a similar way, when characters are received into the RX FIFO, the entire
dannyman939 0:c746ee34feae 138 * FIFO contents is moved to the RX buffer, assuming there is room left in the
dannyman939 0:c746ee34feae 139 * RX buffer. If there is not, any remaining characters are left in the RX FIFO
dannyman939 0:c746ee34feae 140 * and will be moved to the RX buffer on the next interrupt or when the running
dannyman939 0:c746ee34feae 141 * program removes a character(s) from the RX buffer with the getc() method.
dannyman939 0:c746ee34feae 142 */
dannyman939 0:c746ee34feae 143
dannyman939 0:c746ee34feae 144 #endif