Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
WANDongle.h
00001 /* Copyright (c) 2010-2011 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef WANDONGLE_H 00020 #define WANDONGLE_H 00021 00022 #include "USBHost.h" 00023 #include "IUSBHostSerial.h" 00024 00025 #include "rtos.h" 00026 00027 00028 #define WANDONGLE_MAX_OUTEP_SIZE 64 00029 #define WANDONGLE_MAX_INEP_SIZE 64 00030 00031 /** A class to use a WAN (3G/LTE) access dongle 00032 * 00033 */ 00034 class WANDongle : public IUSBHostSerial { 00035 public: 00036 /* 00037 * Constructor 00038 * 00039 * @param rootdir mount name 00040 */ 00041 WANDongle(); 00042 00043 /* 00044 * Check if a serial port device is connected 00045 * 00046 * @return true if a serial device is connected 00047 */ 00048 bool connected(); 00049 00050 /* 00051 * Try to connect device 00052 * 00053 * * @return true if connection was successful 00054 */ 00055 bool tryConnect(); 00056 00057 /* 00058 * Get a char from the dongle's serial interface 00059 */ 00060 virtual int getc(); 00061 00062 /* 00063 * Put a char to the dongle's serial interface 00064 */ 00065 virtual int putc(int c); 00066 00067 //void test(); 00068 00069 /* 00070 * Read a packet from the dongle's serial interface, to be called after multiple getc() calls 00071 */ 00072 virtual int readPacket(); 00073 00074 /* 00075 * Write a packet to the dongle's serial interface, to be called after multiple putc() calls 00076 */ 00077 virtual int writePacket(); 00078 00079 /** 00080 * Check the number of bytes available. 00081 * 00082 * @returns the number of bytes available 00083 */ 00084 virtual int readable(); 00085 00086 /** 00087 * Check the free space in output. 00088 * 00089 * @returns the number of bytes available 00090 */ 00091 virtual int writeable(); 00092 00093 /** 00094 * Attach a handler to call when a packet is received / when a packet has been transmitted. 00095 * 00096 * @param pListener instance of the listener deriving from the IUSBHostSerialListener 00097 */ 00098 virtual void attach(IUSBHostSerialListener* pListener); 00099 00100 /** 00101 * Enable or disable readable/writeable callbacks 00102 */ 00103 virtual void setupIrq(bool en, IrqType irq = RxIrq); 00104 00105 00106 protected: 00107 Endpoint * bulk_in; 00108 Endpoint * bulk_out; 00109 USBHost * host; 00110 USBDeviceConnected * dev; 00111 bool dev_connected; 00112 00113 uint8_t buf_out[WANDONGLE_MAX_OUTEP_SIZE]; 00114 volatile uint32_t buf_out_len; 00115 uint32_t max_out_size; 00116 volatile bool lock_tx; 00117 //Mutex lock_tx; 00118 volatile bool cb_tx_en; 00119 volatile bool cb_tx_pending; 00120 Mutex tx_mtx; 00121 00122 uint8_t buf_in[WANDONGLE_MAX_INEP_SIZE]; 00123 volatile uint32_t buf_in_len; 00124 volatile uint32_t buf_in_read_pos; 00125 volatile bool lock_rx; 00126 //Mutex lock_rx; 00127 volatile bool cb_rx_en; 00128 volatile bool cb_rx_pending; 00129 Mutex rx_mtx; 00130 00131 IUSBHostSerialListener* listener; 00132 00133 void init(); 00134 void rxHandler(); 00135 void txHandler(); 00136 bool fetchEndpoints(); 00137 00138 }; 00139 00140 #endif
Generated on Tue Jul 12 2022 17:50:57 by
