Penn Electric Racing / Mbed 2 deprecated SystemManagement

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Committer:
pspatel321
Date:
Fri Nov 14 06:05:59 2014 +0000
Revision:
31:7eaa5e881b56
Mostly working.  Wrote CAN in/out code.  Xbee still needs work.  My guess is that MODDMA breaks when used with RTOS.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pspatel321 31:7eaa5e881b56 1 /*
pspatel321 31:7eaa5e881b56 2 Copyright (c) 2011 Andy Kirkham
pspatel321 31:7eaa5e881b56 3
pspatel321 31:7eaa5e881b56 4 Permission is hereby granted, free of charge, to any person obtaining a copy
pspatel321 31:7eaa5e881b56 5 of this software and associated documentation files (the "Software"), to deal
pspatel321 31:7eaa5e881b56 6 in the Software without restriction, including without limitation the rights
pspatel321 31:7eaa5e881b56 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pspatel321 31:7eaa5e881b56 8 copies of the Software, and to permit persons to whom the Software is
pspatel321 31:7eaa5e881b56 9 furnished to do so, subject to the following conditions:
pspatel321 31:7eaa5e881b56 10
pspatel321 31:7eaa5e881b56 11 The above copyright notice and this permission notice shall be included in
pspatel321 31:7eaa5e881b56 12 all copies or substantial portions of the Software.
pspatel321 31:7eaa5e881b56 13
pspatel321 31:7eaa5e881b56 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pspatel321 31:7eaa5e881b56 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pspatel321 31:7eaa5e881b56 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pspatel321 31:7eaa5e881b56 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pspatel321 31:7eaa5e881b56 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pspatel321 31:7eaa5e881b56 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pspatel321 31:7eaa5e881b56 20 THE SOFTWARE.
pspatel321 31:7eaa5e881b56 21
pspatel321 31:7eaa5e881b56 22 @file example3.cpp
pspatel321 31:7eaa5e881b56 23 @purpose Demos a simple filter.
pspatel321 31:7eaa5e881b56 24 @version see ChangeLog.c
pspatel321 31:7eaa5e881b56 25 @author Andy Kirkham
pspatel321 31:7eaa5e881b56 26 */
pspatel321 31:7eaa5e881b56 27
pspatel321 31:7eaa5e881b56 28 /*
pspatel321 31:7eaa5e881b56 29 This example shows how to use the new callback system. In the old system
pspatel321 31:7eaa5e881b56 30 Mbed's FunctionPointer[1] type was used to store abd make calls to callbacks.
pspatel321 31:7eaa5e881b56 31 However, that limits the callback function prototype to void func(void);
pspatel321 31:7eaa5e881b56 32 which means we cannot pass parameters.
pspatel321 31:7eaa5e881b56 33
pspatel321 31:7eaa5e881b56 34 This latest version of MODSERIAL now uses its own callback object. This allows
pspatel321 31:7eaa5e881b56 35 the passing of a pointer to a class that holds information about the MODSERIAL
pspatel321 31:7eaa5e881b56 36 object making the callback. As of version 1.18 one critcal piece of information
pspatel321 31:7eaa5e881b56 37 is passed, a pointer to the MODSERIAL object. This allows callbacks to use the
pspatel321 31:7eaa5e881b56 38 MODSERIAL functions and data.
pspatel321 31:7eaa5e881b56 39
pspatel321 31:7eaa5e881b56 40 Additionally, since MODSERIAL and the callback parameter class MODSERIAL_IRQ_INFO
pspatel321 31:7eaa5e881b56 41 are friends, MODSERIAL_IRQ_INFO can access the protected functions of MODSERIAL.
pspatel321 31:7eaa5e881b56 42 This is used to ensure functions that can only be called during a callback
pspatel321 31:7eaa5e881b56 43 can be invoked from a callback.
pspatel321 31:7eaa5e881b56 44
pspatel321 31:7eaa5e881b56 45 [1] http://mbed.org/projects/libraries/svn/mbed/trunk/FunctionPointer.h
pspatel321 31:7eaa5e881b56 46 */
pspatel321 31:7eaa5e881b56 47
pspatel321 31:7eaa5e881b56 48 #ifdef COMPILE_EXAMPLE3_CODE_MODSERIAL
pspatel321 31:7eaa5e881b56 49
pspatel321 31:7eaa5e881b56 50 #include "mbed.h"
pspatel321 31:7eaa5e881b56 51 #include "MODSERIAL.h"
pspatel321 31:7eaa5e881b56 52
pspatel321 31:7eaa5e881b56 53 DigitalOut led1(LED1);
pspatel321 31:7eaa5e881b56 54
pspatel321 31:7eaa5e881b56 55 MODSERIAL pc(USBTX, USBRX);
pspatel321 31:7eaa5e881b56 56
pspatel321 31:7eaa5e881b56 57 // The following callback is defined in example3b.cpp
pspatel321 31:7eaa5e881b56 58 //! @see example3b.cpp
pspatel321 31:7eaa5e881b56 59 void rxCallback(MODSERIAL_IRQ_INFO *info);
pspatel321 31:7eaa5e881b56 60
pspatel321 31:7eaa5e881b56 61 int main() {
pspatel321 31:7eaa5e881b56 62
pspatel321 31:7eaa5e881b56 63 int life_counter = 0;
pspatel321 31:7eaa5e881b56 64
pspatel321 31:7eaa5e881b56 65 pc.baud(115200);
pspatel321 31:7eaa5e881b56 66
pspatel321 31:7eaa5e881b56 67 pc.attach(&rxCallback, MODSERIAL::RxIrq);
pspatel321 31:7eaa5e881b56 68
pspatel321 31:7eaa5e881b56 69 while(1) {
pspatel321 31:7eaa5e881b56 70 // Echo back any chars we get except 'A' which is filtered by the rxCallback.
pspatel321 31:7eaa5e881b56 71 if (pc.readable()) {
pspatel321 31:7eaa5e881b56 72 pc.putc(pc.getc());
pspatel321 31:7eaa5e881b56 73 }
pspatel321 31:7eaa5e881b56 74
pspatel321 31:7eaa5e881b56 75 // Toggle LED1 every so often to show we are alive.
pspatel321 31:7eaa5e881b56 76 if (life_counter++ == 1000000) {
pspatel321 31:7eaa5e881b56 77 life_counter = 0;
pspatel321 31:7eaa5e881b56 78 led1 = !led1;
pspatel321 31:7eaa5e881b56 79 }
pspatel321 31:7eaa5e881b56 80 }
pspatel321 31:7eaa5e881b56 81 }
pspatel321 31:7eaa5e881b56 82
pspatel321 31:7eaa5e881b56 83 #endif