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 example3b.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
pspatel321 31:7eaa5e881b56 49 #ifdef COMPILE_EXAMPLE3_CODE_MODSERIAL
pspatel321 31:7eaa5e881b56 50
pspatel321 31:7eaa5e881b56 51 #include "mbed.h"
pspatel321 31:7eaa5e881b56 52 #include "MODSERIAL.h"
pspatel321 31:7eaa5e881b56 53
pspatel321 31:7eaa5e881b56 54 void rxCallback(MODSERIAL_IRQ_INFO *info) {
pspatel321 31:7eaa5e881b56 55
pspatel321 31:7eaa5e881b56 56 // Get the pointer to our MODSERIAL object that invoked this callback.
pspatel321 31:7eaa5e881b56 57 MODSERIAL *pc = info->serial;
pspatel321 31:7eaa5e881b56 58
pspatel321 31:7eaa5e881b56 59 // info->serial points at the MODSERIAL instance so we can use it to call
pspatel321 31:7eaa5e881b56 60 // any of the public MODSERIAL functions that are normally available. So
pspatel321 31:7eaa5e881b56 61 // there's now no need to use the global version (pc in our case) inside
pspatel321 31:7eaa5e881b56 62 // callback functions.
pspatel321 31:7eaa5e881b56 63 char c = pc->rxGetLastChar(); // Where local pc variable is a pointer to the global MODSERIAL pc object.
pspatel321 31:7eaa5e881b56 64
pspatel321 31:7eaa5e881b56 65 // The following is rather daft but demos the point.
pspatel321 31:7eaa5e881b56 66 // Don't allow the letter "A" go into the RX buffer.
pspatel321 31:7eaa5e881b56 67 // Basically acts as a filter to remove the letter "A"
pspatel321 31:7eaa5e881b56 68 // if it goes into the RX buffer.
pspatel321 31:7eaa5e881b56 69 if (c == 'A') {
pspatel321 31:7eaa5e881b56 70 // Note, we call the MODSERIAL_IRQ_INFO::rxDiscardLastChar() public function which
pspatel321 31:7eaa5e881b56 71 // is permitted access to the protected version of MODSERIAL::rxDiscardLastChar()
pspatel321 31:7eaa5e881b56 72 // within MODSERIAL (because they are friends). This ensures rxDiscardLastChar()
pspatel321 31:7eaa5e881b56 73 // can only be called within an rxCallback function.
pspatel321 31:7eaa5e881b56 74 info->rxDiscardLastChar();
pspatel321 31:7eaa5e881b56 75 }
pspatel321 31:7eaa5e881b56 76 }
pspatel321 31:7eaa5e881b56 77
pspatel321 31:7eaa5e881b56 78 #endif