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_EXAMPLE1_CODE_MODSERIAL
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 #include "MODSERIAL.h"
dannyman939 0:c746ee34feae 10
dannyman939 0:c746ee34feae 11 DigitalOut led1(LED1);
dannyman939 0:c746ee34feae 12 DigitalOut led2(LED2);
dannyman939 0:c746ee34feae 13 DigitalOut led3(LED3);
dannyman939 0:c746ee34feae 14 DigitalOut led4(LED4);
dannyman939 0:c746ee34feae 15
dannyman939 0:c746ee34feae 16 MODSERIAL pc(USBTX, USBRX);
dannyman939 0:c746ee34feae 17
dannyman939 0:c746ee34feae 18 /*
dannyman939 0:c746ee34feae 19 * As experiement, you can define MODSERIAL as show here and see what
dannyman939 0:c746ee34feae 20 * effects it has on the LEDs.
dannyman939 0:c746ee34feae 21 *
dannyman939 0:c746ee34feae 22 * MODSERIAL uart(TX_PIN, RX_PIN, 512);
dannyman939 0:c746ee34feae 23 * With this, the 512 characters sent can straight into the buffer
dannyman939 0:c746ee34feae 24 * vary quickly. This means LED1 is only on briefly as the TX buffer
dannyman939 0:c746ee34feae 25 * fills.
dannyman939 0:c746ee34feae 26 *
dannyman939 0:c746ee34feae 27 * MODSERIAL uart(TX_PIN, RX_PIN, 32);
dannyman939 0:c746ee34feae 28 * With this, the buffer is smaller than the default 256 bytes and
dannyman939 0:c746ee34feae 29 * therefore LED1 stays on much longer while the system waits for
dannyman939 0:c746ee34feae 30 * room in the TX buffer.
dannyman939 0:c746ee34feae 31 */
dannyman939 0:c746ee34feae 32 MODSERIAL uart(TX_PIN, RX_PIN);
dannyman939 0:c746ee34feae 33
dannyman939 0:c746ee34feae 34 // This function is called when a character goes from the TX buffer
dannyman939 0:c746ee34feae 35 // to the Uart THR FIFO register.
dannyman939 0:c746ee34feae 36 void txCallback(MODSERIAL_IRQ_INFO *q) {
dannyman939 0:c746ee34feae 37 led2 = !led2;
dannyman939 0:c746ee34feae 38 }
dannyman939 0:c746ee34feae 39
dannyman939 0:c746ee34feae 40 // This function is called when TX buffer goes empty
dannyman939 0:c746ee34feae 41 void txEmpty(MODSERIAL_IRQ_INFO *q) {
dannyman939 0:c746ee34feae 42 led2 = 0;
dannyman939 0:c746ee34feae 43 pc.puts(" Done. ");
dannyman939 0:c746ee34feae 44 }
dannyman939 0:c746ee34feae 45
dannyman939 0:c746ee34feae 46 // This function is called when a character goes into the RX buffer.
dannyman939 0:c746ee34feae 47 void rxCallback(MODSERIAL_IRQ_INFO *q) {
dannyman939 0:c746ee34feae 48 led3 = !led3;
dannyman939 0:c746ee34feae 49 pc.putc(uart.getc());
dannyman939 0:c746ee34feae 50 }
dannyman939 0:c746ee34feae 51
dannyman939 0:c746ee34feae 52 int main() {
dannyman939 0:c746ee34feae 53 int c = 'A';
dannyman939 0:c746ee34feae 54
dannyman939 0:c746ee34feae 55 // Ensure the baud rate for the PC "USB" serial is much
dannyman939 0:c746ee34feae 56 // higher than "uart" baud rate below.
dannyman939 0:c746ee34feae 57 pc.baud(PC_BAUD);
dannyman939 0:c746ee34feae 58
dannyman939 0:c746ee34feae 59 // Use a deliberatly slow baud to fill up the TX buffer
dannyman939 0:c746ee34feae 60 uart.baud(1200);
dannyman939 0:c746ee34feae 61
dannyman939 0:c746ee34feae 62 uart.attach(&txCallback, MODSERIAL::TxIrq);
dannyman939 0:c746ee34feae 63 uart.attach(&rxCallback, MODSERIAL::RxIrq);
dannyman939 0:c746ee34feae 64 uart.attach(&txEmpty, MODSERIAL::TxEmpty);
dannyman939 0:c746ee34feae 65
dannyman939 0:c746ee34feae 66 // Loop sending characters. We send 512
dannyman939 0:c746ee34feae 67 // which is twice the default TX/RX buffer size.
dannyman939 0:c746ee34feae 68
dannyman939 0:c746ee34feae 69 led1 = 1; // Show start of sending with LED1.
dannyman939 0:c746ee34feae 70
dannyman939 0:c746ee34feae 71 for (int loop = 0; loop < 512; loop++) {
dannyman939 0:c746ee34feae 72 uart.printf("%c", c);
dannyman939 0:c746ee34feae 73 c++;
dannyman939 0:c746ee34feae 74 if (c > 'Z') c = 'A';
dannyman939 0:c746ee34feae 75 }
dannyman939 0:c746ee34feae 76
dannyman939 0:c746ee34feae 77 led1 = 0; // Show the end of sending by switching off LED1.
dannyman939 0:c746ee34feae 78
dannyman939 0:c746ee34feae 79 // End program. Flash LED4. Notice how LED 2 and 3 continue
dannyman939 0:c746ee34feae 80 // to flash for a short period while the interrupt system
dannyman939 0:c746ee34feae 81 // continues to send the characters left in the TX buffer.
dannyman939 0:c746ee34feae 82
dannyman939 0:c746ee34feae 83 while(1) {
dannyman939 0:c746ee34feae 84 led4 = !led4;
dannyman939 0:c746ee34feae 85 wait(0.25);
dannyman939 0:c746ee34feae 86 }
dannyman939 0:c746ee34feae 87 }
dannyman939 0:c746ee34feae 88
dannyman939 0:c746ee34feae 89 /*
dannyman939 0:c746ee34feae 90 * Notes. Here is the sort of output you can expect on your PC/Mac/Linux host
dannyman939 0:c746ee34feae 91 * machine that is connected to the "pc" USB serial port.
dannyman939 0:c746ee34feae 92 *
dannyman939 0:c746ee34feae 93 * ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUV
dannyman939 0:c746ee34feae 94 * WXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQR
dannyman939 0:c746ee34feae 95 * STUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN
dannyman939 0:c746ee34feae 96 * OPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ
dannyman939 0:c746ee34feae 97 * KLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF
dannyman939 0:c746ee34feae 98 * GHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZAB
dannyman939 0:c746ee34feae 99 * CDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQ Done. R
dannyman939 0:c746ee34feae 100 *
dannyman939 0:c746ee34feae 101 * Of interest is that last "R" character after the system has said "Done."
dannyman939 0:c746ee34feae 102 * This comes from the fact that the TxEmpty callback is made when the TX buffer
dannyman939 0:c746ee34feae 103 * becomes empty. MODSERIAL makes use of the fact that the Uarts built into the
dannyman939 0:c746ee34feae 104 * LPC17xx device use a 16 byte FIFO on both RX and TX channels. This means that
dannyman939 0:c746ee34feae 105 * when the TxEmpty callback is made, the TX buffer is empty, but that just means
dannyman939 0:c746ee34feae 106 * the "last few characters" were written to the TX FIFO. So although the TX
dannyman939 0:c746ee34feae 107 * buffer has gone empty, the Uart's transmit system is still sending any remaining
dannyman939 0:c746ee34feae 108 * characters from it's TX FIFO. If you want to be truely sure all the characters
dannyman939 0:c746ee34feae 109 * you have sent have left the Mbed then call txIsBusy(); This function will
dannyman939 0:c746ee34feae 110 * return true if characters are still being sent. If it returns false after
dannyman939 0:c746ee34feae 111 * the Tx buffer is empty then all your characters have been sent.
dannyman939 0:c746ee34feae 112 *
dannyman939 0:c746ee34feae 113 * In a similar way, when characters are received into the RX FIFO, the entire
dannyman939 0:c746ee34feae 114 * FIFO contents is moved to the RX buffer, assuming there is room left in the
dannyman939 0:c746ee34feae 115 * RX buffer. If there is not, any remaining characters are left in the RX FIFO
dannyman939 0:c746ee34feae 116 * and will be moved to the RX buffer on the next interrupt or when the running
dannyman939 0:c746ee34feae 117 * program removes a character(s) from the RX buffer with the getc() method.
dannyman939 0:c746ee34feae 118 */
dannyman939 0:c746ee34feae 119
dannyman939 0:c746ee34feae 120 #endif