MODSERIAL with support for more devices. Added support for LPC4330

Dependents:   HC05_AT_mode GPS_U-blox_NEO-6M_Test_Code GPS_U-blox_NEO-6M_Code UbloxGPSWithThread ... more

Fork of MODSERIAL by Erik -

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers example3a.cpp Source File

example3a.cpp

00001 /*
00002     Copyright (c) 2011 Andy Kirkham
00003  
00004     Permission is hereby granted, free of charge, to any person obtaining a copy
00005     of this software and associated documentation files (the "Software"), to deal
00006     in the Software without restriction, including without limitation the rights
00007     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008     copies of the Software, and to permit persons to whom the Software is
00009     furnished to do so, subject to the following conditions:
00010  
00011     The above copyright notice and this permission notice shall be included in
00012     all copies or substantial portions of the Software.
00013  
00014     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020     THE SOFTWARE.
00021     
00022     @file          example3.cpp 
00023     @purpose       Demos a simple filter.
00024     @version       see ChangeLog.c
00025     @author        Andy Kirkham
00026 */
00027 
00028 /*
00029     This example shows how to use the new callback system. In the old system
00030     Mbed's FunctionPointer[1] type was used to store abd make calls to callbacks.
00031     However, that limits the callback function prototype to void func(void);
00032     which means we cannot pass parameters.
00033     
00034     This latest version of MODSERIAL now uses its own callback object. This allows
00035     the passing of a pointer to a class that holds information about the MODSERIAL
00036     object making the callback. As of version 1.18 one critcal piece of information
00037     is passed, a pointer to the MODSERIAL object. This allows callbacks to use the
00038     MODSERIAL functions and data.
00039         
00040     Additionally, since MODSERIAL and the callback parameter class MODSERIAL_IRQ_INFO
00041     are friends, MODSERIAL_IRQ_INFO can access the protected functions of MODSERIAL.
00042     This is used to ensure functions that can only be called during a callback
00043     can be invoked from a callback. 
00044     
00045     [1] http://mbed.org/projects/libraries/svn/mbed/trunk/FunctionPointer.h    
00046 */
00047 
00048 #ifdef COMPILE_EXAMPLE3_CODE_MODSERIAL
00049 
00050 #include "mbed.h"
00051 #include "MODSERIAL.h"
00052 
00053 DigitalOut led1(LED1);
00054 
00055 MODSERIAL pc(USBTX, USBRX);
00056 
00057 // The following callback is defined in example3b.cpp
00058 //! @see example3b.cpp
00059 void rxCallback(MODSERIAL_IRQ_INFO *info);
00060 
00061 int main() {
00062     
00063     int life_counter = 0;
00064     
00065     pc.baud(115200);
00066     
00067     pc.attach(&rxCallback, MODSERIAL::RxIrq);
00068 
00069     while(1) {
00070         // Echo back any chars we get except 'A' which is filtered by the rxCallback.
00071         if (pc.readable()) {
00072             pc.putc(pc.getc());
00073         }
00074         
00075         // Toggle LED1 every so often to show we are alive.
00076         if (life_counter++ == 1000000) {
00077             life_counter = 0;
00078             led1 = !led1;
00079         }
00080     }
00081 }
00082 
00083 #endif