SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lorcansmith 0:2a53a4c3238c 1
lorcansmith 0:2a53a4c3238c 2 /*
lorcansmith 0:2a53a4c3238c 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
lorcansmith 0:2a53a4c3238c 4
lorcansmith 0:2a53a4c3238c 5 Permission is hereby granted, free of charge, to any person obtaining a copy
lorcansmith 0:2a53a4c3238c 6 of this software and associated documentation files (the "Software"), to deal
lorcansmith 0:2a53a4c3238c 7 in the Software without restriction, including without limitation the rights
lorcansmith 0:2a53a4c3238c 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
lorcansmith 0:2a53a4c3238c 9 copies of the Software, and to permit persons to whom the Software is
lorcansmith 0:2a53a4c3238c 10 furnished to do so, subject to the following conditions:
lorcansmith 0:2a53a4c3238c 11
lorcansmith 0:2a53a4c3238c 12 The above copyright notice and this permission notice shall be included in
lorcansmith 0:2a53a4c3238c 13 all copies or substantial portions of the Software.
lorcansmith 0:2a53a4c3238c 14
lorcansmith 0:2a53a4c3238c 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
lorcansmith 0:2a53a4c3238c 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
lorcansmith 0:2a53a4c3238c 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
lorcansmith 0:2a53a4c3238c 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
lorcansmith 0:2a53a4c3238c 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
lorcansmith 0:2a53a4c3238c 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
lorcansmith 0:2a53a4c3238c 21 THE SOFTWARE.
lorcansmith 0:2a53a4c3238c 22 */
lorcansmith 0:2a53a4c3238c 23
lorcansmith 0:2a53a4c3238c 24 #ifndef USB_SERIAL_H
lorcansmith 0:2a53a4c3238c 25 #define USB_SERIAL_H
lorcansmith 0:2a53a4c3238c 26
lorcansmith 0:2a53a4c3238c 27 //DG 2010
lorcansmith 0:2a53a4c3238c 28 //Essentially a clone of Serial if
lorcansmith 0:2a53a4c3238c 29 #include "Stream.h"
lorcansmith 0:2a53a4c3238c 30 #include "mbed.h"
lorcansmith 0:2a53a4c3238c 31
lorcansmith 0:2a53a4c3238c 32 #include "drv/usb/UsbDevice.h"
lorcansmith 0:2a53a4c3238c 33 #include "drv/usb/UsbEndpoint.h"
lorcansmith 0:2a53a4c3238c 34
lorcansmith 0:2a53a4c3238c 35 namespace mbed {
lorcansmith 0:2a53a4c3238c 36
lorcansmith 0:2a53a4c3238c 37 class UsbSerial : public Stream {
lorcansmith 0:2a53a4c3238c 38
lorcansmith 0:2a53a4c3238c 39 public:
lorcansmith 0:2a53a4c3238c 40
lorcansmith 0:2a53a4c3238c 41 UsbSerial(UsbDevice* pDevice, int epIn, int epOut, const char* name = NULL);
lorcansmith 0:2a53a4c3238c 42 virtual ~UsbSerial();
lorcansmith 0:2a53a4c3238c 43 //Apart from the ctor/dtor, exactly the same protos as Serial
lorcansmith 0:2a53a4c3238c 44
lorcansmith 0:2a53a4c3238c 45 void baud(int baudrate);
lorcansmith 0:2a53a4c3238c 46
lorcansmith 0:2a53a4c3238c 47 enum Parity {
lorcansmith 0:2a53a4c3238c 48 None = 0,
lorcansmith 0:2a53a4c3238c 49 Odd = 1,
lorcansmith 0:2a53a4c3238c 50 Even = 2,
lorcansmith 0:2a53a4c3238c 51 Forced1 = 3,
lorcansmith 0:2a53a4c3238c 52 Forced0 = 4
lorcansmith 0:2a53a4c3238c 53 };
lorcansmith 0:2a53a4c3238c 54
lorcansmith 0:2a53a4c3238c 55 enum IrqType {
lorcansmith 0:2a53a4c3238c 56 RxIrq = 0
lorcansmith 0:2a53a4c3238c 57 , TxIrq
lorcansmith 0:2a53a4c3238c 58 };
lorcansmith 0:2a53a4c3238c 59
lorcansmith 0:2a53a4c3238c 60 void format(int bits, int parity, int stop);
lorcansmith 0:2a53a4c3238c 61
lorcansmith 0:2a53a4c3238c 62 class CDummy;
lorcansmith 0:2a53a4c3238c 63 template <class T>
lorcansmith 0:2a53a4c3238c 64 void attach(T* pCbItem, void (T::*pCbMeth)(), IrqType type = RxIrq)
lorcansmith 0:2a53a4c3238c 65 {
lorcansmith 0:2a53a4c3238c 66 if(type == RxIrq)
lorcansmith 0:2a53a4c3238c 67 {
lorcansmith 0:2a53a4c3238c 68 m_pInCbItem = (CDummy*) pCbItem;
lorcansmith 0:2a53a4c3238c 69 m_pInCbMeth = (void (CDummy::*)()) pCbMeth;
lorcansmith 0:2a53a4c3238c 70 }
lorcansmith 0:2a53a4c3238c 71 else
lorcansmith 0:2a53a4c3238c 72 {
lorcansmith 0:2a53a4c3238c 73 m_pOutCbItem = (CDummy*) pCbItem;
lorcansmith 0:2a53a4c3238c 74 m_pOutCbMeth = (void (CDummy::*)()) pCbMeth;
lorcansmith 0:2a53a4c3238c 75 }
lorcansmith 0:2a53a4c3238c 76 }
lorcansmith 0:2a53a4c3238c 77
lorcansmith 0:2a53a4c3238c 78 #if 0 // Inhereted from Stream, for documentation only
lorcansmith 0:2a53a4c3238c 79
lorcansmith 0:2a53a4c3238c 80 /* Function: putc
lorcansmith 0:2a53a4c3238c 81 * Write a character
lorcansmith 0:2a53a4c3238c 82 *
lorcansmith 0:2a53a4c3238c 83 * Variables:
lorcansmith 0:2a53a4c3238c 84 * c - The character to write to the serial port
lorcansmith 0:2a53a4c3238c 85 */
lorcansmith 0:2a53a4c3238c 86 int putc(int c);
lorcansmith 0:2a53a4c3238c 87
lorcansmith 0:2a53a4c3238c 88 /* Function: getc
lorcansmith 0:2a53a4c3238c 89 * Read a character
lorcansmith 0:2a53a4c3238c 90 *
lorcansmith 0:2a53a4c3238c 91 * Variables:
lorcansmith 0:2a53a4c3238c 92 * returns - The character read from the serial port
lorcansmith 0:2a53a4c3238c 93 */
lorcansmith 0:2a53a4c3238c 94 int getc();
lorcansmith 0:2a53a4c3238c 95
lorcansmith 0:2a53a4c3238c 96 /* Function: printf
lorcansmith 0:2a53a4c3238c 97 * Write a formated string
lorcansmith 0:2a53a4c3238c 98 *
lorcansmith 0:2a53a4c3238c 99 * Variables:
lorcansmith 0:2a53a4c3238c 100 * format - A printf-style format string, followed by the
lorcansmith 0:2a53a4c3238c 101 * variables to use in formating the string.
lorcansmith 0:2a53a4c3238c 102 */
lorcansmith 0:2a53a4c3238c 103 int printf(const char* format, ...);
lorcansmith 0:2a53a4c3238c 104
lorcansmith 0:2a53a4c3238c 105 /* Function: scanf
lorcansmith 0:2a53a4c3238c 106 * Read a formated string
lorcansmith 0:2a53a4c3238c 107 *
lorcansmith 0:2a53a4c3238c 108 * Variables:
lorcansmith 0:2a53a4c3238c 109 * format - A scanf-style format string,
lorcansmith 0:2a53a4c3238c 110 * followed by the pointers to variables to store the results.
lorcansmith 0:2a53a4c3238c 111 */
lorcansmith 0:2a53a4c3238c 112 int scanf(const char* format, ...);
lorcansmith 0:2a53a4c3238c 113
lorcansmith 0:2a53a4c3238c 114 #endif
lorcansmith 0:2a53a4c3238c 115
lorcansmith 0:2a53a4c3238c 116 /* Function: readable
lorcansmith 0:2a53a4c3238c 117 * Determine if there is a character available to read
lorcansmith 0:2a53a4c3238c 118 *
lorcansmith 0:2a53a4c3238c 119 * Variables:
lorcansmith 0:2a53a4c3238c 120 * returns - 1 if there is a character available to read, else 0
lorcansmith 0:2a53a4c3238c 121 */
lorcansmith 0:2a53a4c3238c 122 int readable();
lorcansmith 0:2a53a4c3238c 123
lorcansmith 0:2a53a4c3238c 124 /* Function: writeable
lorcansmith 0:2a53a4c3238c 125 * Determine if there is space available to write a character
lorcansmith 0:2a53a4c3238c 126 *
lorcansmith 0:2a53a4c3238c 127 * Variables:
lorcansmith 0:2a53a4c3238c 128 * returns - 1 if there is space to write a character, else 0
lorcansmith 0:2a53a4c3238c 129 */
lorcansmith 0:2a53a4c3238c 130 int writeable();
lorcansmith 0:2a53a4c3238c 131
lorcansmith 0:2a53a4c3238c 132 #ifdef MBED_RPC
lorcansmith 0:2a53a4c3238c 133 virtual const struct rpc_method *get_rpc_methods();
lorcansmith 0:2a53a4c3238c 134 static struct rpc_class *get_rpc_class();
lorcansmith 0:2a53a4c3238c 135 #endif
lorcansmith 0:2a53a4c3238c 136
lorcansmith 0:2a53a4c3238c 137 protected:
lorcansmith 0:2a53a4c3238c 138
lorcansmith 0:2a53a4c3238c 139 virtual int _getc();
lorcansmith 0:2a53a4c3238c 140 virtual int _putc(int c);
lorcansmith 0:2a53a4c3238c 141
lorcansmith 0:2a53a4c3238c 142 void onReadable();
lorcansmith 0:2a53a4c3238c 143 void onWriteable();
lorcansmith 0:2a53a4c3238c 144
lorcansmith 0:2a53a4c3238c 145 void onEpInTransfer();
lorcansmith 0:2a53a4c3238c 146 void onEpOutTransfer();
lorcansmith 0:2a53a4c3238c 147
lorcansmith 0:2a53a4c3238c 148 private:
lorcansmith 0:2a53a4c3238c 149
lorcansmith 0:2a53a4c3238c 150 UsbEndpoint m_epIn;
lorcansmith 0:2a53a4c3238c 151 UsbEndpoint m_epOut;
lorcansmith 0:2a53a4c3238c 152
lorcansmith 0:2a53a4c3238c 153 CDummy* m_pInCbItem;
lorcansmith 0:2a53a4c3238c 154 void (CDummy::*m_pInCbMeth)();
lorcansmith 0:2a53a4c3238c 155
lorcansmith 0:2a53a4c3238c 156 CDummy* m_pOutCbItem;
lorcansmith 0:2a53a4c3238c 157 void (CDummy::*m_pOutCbMeth)();
lorcansmith 0:2a53a4c3238c 158
lorcansmith 0:2a53a4c3238c 159 void startTx();
lorcansmith 0:2a53a4c3238c 160 void startRx();
lorcansmith 0:2a53a4c3238c 161
lorcansmith 0:2a53a4c3238c 162 Timeout m_txTimeout;
lorcansmith 0:2a53a4c3238c 163 volatile bool m_timeout;
lorcansmith 0:2a53a4c3238c 164
lorcansmith 0:2a53a4c3238c 165 volatile char* m_inBufEven;
lorcansmith 0:2a53a4c3238c 166 volatile char* m_inBufOdd;
lorcansmith 0:2a53a4c3238c 167 volatile char* m_inBufUsr;
lorcansmith 0:2a53a4c3238c 168 volatile char* m_inBufTrmt;
lorcansmith 0:2a53a4c3238c 169
lorcansmith 0:2a53a4c3238c 170 volatile char* m_outBufEven;
lorcansmith 0:2a53a4c3238c 171 volatile char* m_outBufOdd;
lorcansmith 0:2a53a4c3238c 172 volatile char* m_outBufUsr;
lorcansmith 0:2a53a4c3238c 173 volatile char* m_outBufTrmt;
lorcansmith 0:2a53a4c3238c 174
lorcansmith 0:2a53a4c3238c 175 volatile int m_inBufLen;
lorcansmith 0:2a53a4c3238c 176 volatile int m_outBufLen;
lorcansmith 0:2a53a4c3238c 177
lorcansmith 0:2a53a4c3238c 178 volatile char* m_pInBufPos;
lorcansmith 0:2a53a4c3238c 179 volatile char* m_pOutBufPos;
lorcansmith 0:2a53a4c3238c 180
lorcansmith 0:2a53a4c3238c 181
lorcansmith 0:2a53a4c3238c 182
lorcansmith 0:2a53a4c3238c 183 };
lorcansmith 0:2a53a4c3238c 184
lorcansmith 0:2a53a4c3238c 185 }
lorcansmith 0:2a53a4c3238c 186
lorcansmith 0:2a53a4c3238c 187
lorcansmith 0:2a53a4c3238c 188
lorcansmith 0:2a53a4c3238c 189 #endif