Small Testprogram to have WebAccess via Webserver to a 433Mhz tranmitter to control remotly some devices from remote, with TFTP, NTP and RMF. This could be a base to develop applications.

Dependencies:   ChaNFSSD TFTPServer RMFWeb

Dependents:   RMFWeb

Committer:
ED7418
Date:
Mon Jun 16 07:40:08 2014 +0000
Revision:
1:809b59c7a800
Parent:
0:51f1ef89ec7b
mbed-lib and other libs are a based on a project, published in a Elektor-book "ARM-microkontroller Part II".

Who changed what in which revision?

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