test public

Dependencies:   HttpServer_snapshot_mbed-os

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WANDongleSerialPort.h Source File

WANDongleSerialPort.h

00001 /* Copyright (c) 2010-2012 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 WANDONGLESERIALPORT_H
00020 #define WANDONGLESERIALPORT_H
00021 
00022 #include "USBHostConf.h"
00023 
00024 #ifdef USBHOST_3GMODULE
00025 
00026 #include "USBHost.h"
00027 #include "IUSBHostSerial.h"
00028 
00029 #include "rtos.h"
00030 
00031 
00032 #define WANDONGLE_MAX_OUTEP_SIZE 64
00033 #define WANDONGLE_MAX_INEP_SIZE 64
00034 
00035 /** A class to use a WAN (3G/LTE) access dongle
00036  *
00037  */
00038 class WANDongleSerialPort : public IUSBHostSerial {
00039 public:
00040     /*
00041     * Constructor
00042     *
00043     */
00044     WANDongleSerialPort();
00045 #if defined(TARGET_RZ_A2XX)
00046     virtual ~WANDongleSerialPort();
00047 #endif
00048 
00049     void init( USBHost* pHost );
00050 
00051     void connect( USBDeviceConnected* pDev, USBEndpoint* pInEp, USBEndpoint* pOutEp );
00052 
00053     void disconnect( );
00054 
00055     /*
00056     * Get a char from the dongle's serial interface
00057     */
00058     virtual int getc();
00059 
00060     /*
00061     * Put a char to the dongle's serial interface
00062     */
00063     virtual int putc(int c);
00064 
00065     /*
00066      *  Read a packet from the dongle's serial interface, to be called after multiple getc() calls
00067      */
00068     virtual int readPacket();
00069 
00070     /*
00071      *  Write a packet to the dongle's serial interface, to be called after multiple putc() calls
00072      */
00073     virtual int writePacket();
00074 
00075     /**
00076     * Check the number of bytes available.
00077     *
00078     * @returns the number of bytes available
00079     */
00080     virtual int readable();
00081 
00082     /**
00083     * Check the free space in output.
00084     *
00085     * @returns the number of bytes available
00086     */
00087     virtual int writeable();
00088 
00089     /**
00090      *  Attach a handler to call when a packet is received / when a packet has been transmitted.
00091      *
00092      *  @param pListener instance of the listener deriving from the IUSBHostSerialListener
00093      */
00094     virtual void attach(IUSBHostSerialListener* pListener);
00095 
00096     /**
00097      * Enable or disable readable/writeable callbacks
00098      */
00099     virtual void setupIrq(bool en, IrqType irq = RxIrq);
00100 
00101 
00102 protected:
00103     USBEndpoint * bulk_in;
00104     USBEndpoint * bulk_out;
00105     USBHost * host;
00106     USBDeviceConnected * dev;
00107 
00108 #if defined(TARGET_RZ_A2XX)
00109     uint8_t * buf_out;
00110 #else
00111     uint8_t buf_out[WANDONGLE_MAX_OUTEP_SIZE];
00112 #endif
00113     volatile uint32_t buf_out_len;
00114     uint32_t max_out_size;
00115     volatile bool lock_tx;
00116     volatile bool cb_tx_en;
00117     volatile bool cb_tx_pending;
00118     rtos::Mutex tx_mtx;
00119 
00120 #if defined(TARGET_RZ_A2XX)
00121     uint8_t * buf_in;
00122 #else
00123     uint8_t buf_in[WANDONGLE_MAX_INEP_SIZE];
00124 #endif
00125     volatile uint32_t buf_in_len;
00126     volatile uint32_t buf_in_read_pos;
00127     volatile bool lock_rx;
00128     volatile bool cb_rx_en;
00129     volatile bool cb_rx_pending;
00130     rtos::Mutex rx_mtx;
00131 
00132     IUSBHostSerialListener* listener;
00133 
00134     void reset();
00135 
00136     void rxHandler();
00137     void txHandler();
00138 
00139 };
00140 
00141 #endif /* USBHOST_3GMODULE */
00142 
00143 #endif
00144