RTOS Support.

Dependents:   SerialRPC_rtos_example

Fork of RPCInterface by Michael Walker

Committer:
MichaelW
Date:
Sat Jan 28 19:12:00 2012 +0000
Revision:
8:682c65afe534
Parent:
5:56fd0b265aba
Child:
9:2aa76667c340
Updated to not register AnalogOut class if the LPC11U24 as it doesn\t have AnalogOut

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MichaelW 5:56fd0b265aba 1 /**
MichaelW 5:56fd0b265aba 2 * @section LICENSE
MichaelW 5:56fd0b265aba 3 *Copyright (c) 2010 ARM Ltd.
MichaelW 5:56fd0b265aba 4 *
MichaelW 5:56fd0b265aba 5 *Permission is hereby granted, free of charge, to any person obtaining a copy
MichaelW 5:56fd0b265aba 6 *of this software and associated documentation files (the "Software"), to deal
MichaelW 5:56fd0b265aba 7 *in the Software without restriction, including without limitation the rights
MichaelW 5:56fd0b265aba 8 *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
MichaelW 5:56fd0b265aba 9 *copies of the Software, and to permit persons to whom the Software is
MichaelW 5:56fd0b265aba 10 *furnished to do so, subject to the following conditions:
MichaelW 5:56fd0b265aba 11 *
MichaelW 5:56fd0b265aba 12 *The above copyright notice and this permission notice shall be included in
MichaelW 5:56fd0b265aba 13 *all copies or substantial portions of the Software.
MichaelW 5:56fd0b265aba 14 *
MichaelW 5:56fd0b265aba 15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
MichaelW 5:56fd0b265aba 16 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
MichaelW 5:56fd0b265aba 17 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
MichaelW 5:56fd0b265aba 18 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
MichaelW 5:56fd0b265aba 19 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
MichaelW 5:56fd0b265aba 20 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
MichaelW 5:56fd0b265aba 21 *THE SOFTWARE.
MichaelW 5:56fd0b265aba 22 *
MichaelW 5:56fd0b265aba 23 *
MichaelW 5:56fd0b265aba 24 * @section DESCRIPTION
MichaelW 5:56fd0b265aba 25 *
MichaelW 5:56fd0b265aba 26 *This class sets up RPC communication. This allows objects on mbed to be controlled. Objects can be created or existing objects can be used
MichaelW 5:56fd0b265aba 27 */
MichaelW 5:56fd0b265aba 28 #include "SerialRPCInterface.h"
MichaelW 5:56fd0b265aba 29
MichaelW 5:56fd0b265aba 30 using namespace mbed;
MichaelW 5:56fd0b265aba 31
MichaelW 5:56fd0b265aba 32 //Requires multiple contstructors for each type, serial to set different pin numbers, TCP for port.
MichaelW 5:56fd0b265aba 33 SerialRPCInterface::SerialRPCInterface(PinName tx, PinName rx, int baud):pc(tx, rx) {
MichaelW 5:56fd0b265aba 34 _RegClasses();
MichaelW 5:56fd0b265aba 35 _enabled = true;
MichaelW 5:56fd0b265aba 36 pc.attach(this, &SerialRPCInterface::_RPCSerial, Serial::RxIrq);
MichaelW 5:56fd0b265aba 37 if(baud != 9600)pc.baud(baud);
MichaelW 5:56fd0b265aba 38 }
MichaelW 5:56fd0b265aba 39
MichaelW 5:56fd0b265aba 40 void SerialRPCInterface::_RegClasses(void){
MichaelW 5:56fd0b265aba 41 //Register classes with base
MichaelW 5:56fd0b265aba 42 Base::add_rpc_class<AnalogIn>();
MichaelW 5:56fd0b265aba 43 Base::add_rpc_class<DigitalIn>();
MichaelW 5:56fd0b265aba 44 Base::add_rpc_class<DigitalOut>();
MichaelW 5:56fd0b265aba 45 Base::add_rpc_class<DigitalInOut>();
MichaelW 5:56fd0b265aba 46 Base::add_rpc_class<PwmOut>();
MichaelW 5:56fd0b265aba 47 Base::add_rpc_class<Timer>();
MichaelW 5:56fd0b265aba 48 Base::add_rpc_class<BusOut>();
MichaelW 5:56fd0b265aba 49 Base::add_rpc_class<BusIn>();
MichaelW 5:56fd0b265aba 50 Base::add_rpc_class<BusInOut>();
MichaelW 5:56fd0b265aba 51 Base::add_rpc_class<Serial>();
MichaelW 8:682c65afe534 52
MichaelW 8:682c65afe534 53 //AnalogOut not avaliable on mbed LPC11U24 so only compile for other devices
MichaelW 8:682c65afe534 54 #if !defined(TARGET_LPC11U24)
MichaelW 8:682c65afe534 55 Base::add_rpc_class<AnalogOut>();
MichaelW 8:682c65afe534 56 #endif
MichaelW 5:56fd0b265aba 57 }
MichaelW 5:56fd0b265aba 58
MichaelW 5:56fd0b265aba 59 void SerialRPCInterface::Disable(void){
MichaelW 5:56fd0b265aba 60 _enabled = false;
MichaelW 5:56fd0b265aba 61 }
MichaelW 5:56fd0b265aba 62 void SerialRPCInterface::Enable(void){
MichaelW 5:56fd0b265aba 63 _enabled = true;
MichaelW 5:56fd0b265aba 64 }
MichaelW 5:56fd0b265aba 65 void SerialRPCInterface::_MsgProcess(void) {
MichaelW 5:56fd0b265aba 66 if(_enabled == true){
MichaelW 5:56fd0b265aba 67 rpc(_command, _response);
MichaelW 5:56fd0b265aba 68 }
MichaelW 5:56fd0b265aba 69 }
MichaelW 5:56fd0b265aba 70
MichaelW 5:56fd0b265aba 71 void SerialRPCInterface::_RPCSerial() {
MichaelW 5:56fd0b265aba 72 _RPCflag = true;
MichaelW 5:56fd0b265aba 73 if(_enabled == true){
MichaelW 5:56fd0b265aba 74 pc.gets(_command, 256);
MichaelW 5:56fd0b265aba 75 _MsgProcess();
MichaelW 5:56fd0b265aba 76 pc.printf("%s\n", _response);
MichaelW 5:56fd0b265aba 77 }
MichaelW 5:56fd0b265aba 78 _RPCflag = false;
MichaelW 5:56fd0b265aba 79 }