RTOS Support.

Dependents:   SerialRPC_rtos_example

Fork of RPCInterface by Michael Walker

Committer:
ban4jp
Date:
Thu Apr 09 18:02:10 2015 +0000
Revision:
9:2aa76667c340
Parent:
5:56fd0b265aba
Change to work with RTOS.

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 over serial.
MichaelW 5:56fd0b265aba 27 */
MichaelW 5:56fd0b265aba 28 #ifndef INTERFACE
MichaelW 5:56fd0b265aba 29 #define INTERFACE
MichaelW 5:56fd0b265aba 30
MichaelW 5:56fd0b265aba 31 /**
MichaelW 5:56fd0b265aba 32 *Includes
MichaelW 5:56fd0b265aba 33 */
MichaelW 5:56fd0b265aba 34 #include "mbed.h"
ban4jp 9:2aa76667c340 35 #include "rtos.h"
MichaelW 5:56fd0b265aba 36 #include "platform.h"
MichaelW 5:56fd0b265aba 37 #include "rpc.h"
MichaelW 5:56fd0b265aba 38 #include "RPCFunction.h"
MichaelW 5:56fd0b265aba 39 #include "RPCVariable.h"
ban4jp 9:2aa76667c340 40 #include "RpcClasses.h"
ban4jp 9:2aa76667c340 41
ban4jp 9:2aa76667c340 42 #define PROCESS_THREAD 1
MichaelW 5:56fd0b265aba 43
MichaelW 5:56fd0b265aba 44
MichaelW 5:56fd0b265aba 45 namespace mbed{
MichaelW 5:56fd0b265aba 46 /**
MichaelW 5:56fd0b265aba 47 *Provides an Interface to mbed over RPC.
MichaelW 5:56fd0b265aba 48 *
MichaelW 5:56fd0b265aba 49 *For the chosen communication type this class sets up the necessary interrupts to receive RPC messages. Receives the messages, passes them to the rpc function and then returns the result.
MichaelW 5:56fd0b265aba 50 */
MichaelW 5:56fd0b265aba 51 class SerialRPCInterface{
MichaelW 5:56fd0b265aba 52 public:
MichaelW 5:56fd0b265aba 53 /**
MichaelW 5:56fd0b265aba 54 *Constructor
MichaelW 5:56fd0b265aba 55 *
MichaelW 5:56fd0b265aba 56 *Sets up RPC communication using serial communication.
MichaelW 5:56fd0b265aba 57 *
MichaelW 5:56fd0b265aba 58 *@param tx The transmit pin of the serial port.
MichaelW 5:56fd0b265aba 59 *@param rx The receive pin of the serial port.
MichaelW 5:56fd0b265aba 60 *@param baud Set the baud rate, default is 9600.
MichaelW 5:56fd0b265aba 61 */
MichaelW 5:56fd0b265aba 62 SerialRPCInterface(PinName tx, PinName rx, int baud = 9600);
MichaelW 5:56fd0b265aba 63
MichaelW 5:56fd0b265aba 64 /**
MichaelW 5:56fd0b265aba 65 *Disable the RPC.
MichaelW 5:56fd0b265aba 66 *
MichaelW 5:56fd0b265aba 67 *This will stop RPC messages being recevied and interpreted by this library. This might be used to prevent RPC commands interrupting an important piece of code on mbed.
MichaelW 5:56fd0b265aba 68 */
MichaelW 5:56fd0b265aba 69 void Disable(void);
MichaelW 5:56fd0b265aba 70
MichaelW 5:56fd0b265aba 71 /**
MichaelW 5:56fd0b265aba 72 *Enable the RPC
MichaelW 5:56fd0b265aba 73 *
MichaelW 5:56fd0b265aba 74 *This will set this class to receiving and executing RPC commands. The class starts in this mode so this function only needs to be called if you have previosuly disabled the RPC.
MichaelW 5:56fd0b265aba 75 *
MichaelW 5:56fd0b265aba 76 */
MichaelW 5:56fd0b265aba 77 void Enable(void);
MichaelW 5:56fd0b265aba 78
MichaelW 5:56fd0b265aba 79 //The Serial Port
ban4jp 9:2aa76667c340 80 RawSerial pc;
MichaelW 5:56fd0b265aba 81
MichaelW 5:56fd0b265aba 82
MichaelW 5:56fd0b265aba 83 private:
ban4jp 9:2aa76667c340 84 typedef struct {
ban4jp 9:2aa76667c340 85 char command[256];
ban4jp 9:2aa76667c340 86 } mail_t;
ban4jp 9:2aa76667c340 87
MichaelW 5:56fd0b265aba 88 //Handle messgaes and take appropriate action
ban4jp 9:2aa76667c340 89 static void _MsgProcessStarter(const void *args);
MichaelW 5:56fd0b265aba 90 void _MsgProcess(void);
MichaelW 5:56fd0b265aba 91 void _RegClasses(void);
MichaelW 5:56fd0b265aba 92 void _RPCSerial();
MichaelW 5:56fd0b265aba 93 bool _enabled;
MichaelW 5:56fd0b265aba 94 char _command[256];
ban4jp 9:2aa76667c340 95 char* _command_ptr;
MichaelW 5:56fd0b265aba 96 char _response[256];
MichaelW 5:56fd0b265aba 97 bool _RPCflag;
ban4jp 9:2aa76667c340 98 Thread _thread;
ban4jp 9:2aa76667c340 99 Mail<mail_t, 8> _commandMail;
MichaelW 5:56fd0b265aba 100 };
MichaelW 5:56fd0b265aba 101 }
MichaelW 0:9232f9e1178d 102 #endif