Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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