mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 /* Copyright (c) 2010-2012 mbed.org, MIT License
elessair 0:f269e3021894 2 *
elessair 0:f269e3021894 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
elessair 0:f269e3021894 4 * and associated documentation files (the "Software"), to deal in the Software without
elessair 0:f269e3021894 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
elessair 0:f269e3021894 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
elessair 0:f269e3021894 7 * Software is furnished to do so, subject to the following conditions:
elessair 0:f269e3021894 8 *
elessair 0:f269e3021894 9 * The above copyright notice and this permission notice shall be included in all copies or
elessair 0:f269e3021894 10 * substantial portions of the Software.
elessair 0:f269e3021894 11 *
elessair 0:f269e3021894 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
elessair 0:f269e3021894 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
elessair 0:f269e3021894 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
elessair 0:f269e3021894 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
elessair 0:f269e3021894 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
elessair 0:f269e3021894 17 */
elessair 0:f269e3021894 18
elessair 0:f269e3021894 19 #ifndef WANDONGLESERIALPORT_H
elessair 0:f269e3021894 20 #define WANDONGLESERIALPORT_H
elessair 0:f269e3021894 21
elessair 0:f269e3021894 22 #include "USBHostConf.h"
elessair 0:f269e3021894 23
elessair 0:f269e3021894 24 #ifdef USBHOST_3GMODULE
elessair 0:f269e3021894 25
elessair 0:f269e3021894 26 #include "USBHost.h"
elessair 0:f269e3021894 27 #include "IUSBHostSerial.h"
elessair 0:f269e3021894 28
elessair 0:f269e3021894 29 #include "rtos.h"
elessair 0:f269e3021894 30
elessair 0:f269e3021894 31
elessair 0:f269e3021894 32 #define WANDONGLE_MAX_OUTEP_SIZE 64
elessair 0:f269e3021894 33 #define WANDONGLE_MAX_INEP_SIZE 64
elessair 0:f269e3021894 34
elessair 0:f269e3021894 35 /** A class to use a WAN (3G/LTE) access dongle
elessair 0:f269e3021894 36 *
elessair 0:f269e3021894 37 */
elessair 0:f269e3021894 38 class WANDongleSerialPort : public IUSBHostSerial {
elessair 0:f269e3021894 39 public:
elessair 0:f269e3021894 40 /*
elessair 0:f269e3021894 41 * Constructor
elessair 0:f269e3021894 42 *
elessair 0:f269e3021894 43 */
elessair 0:f269e3021894 44 WANDongleSerialPort();
elessair 0:f269e3021894 45
elessair 0:f269e3021894 46 void init( USBHost* pHost );
elessair 0:f269e3021894 47
elessair 0:f269e3021894 48 void connect( USBDeviceConnected* pDev, USBEndpoint* pInEp, USBEndpoint* pOutEp );
elessair 0:f269e3021894 49
elessair 0:f269e3021894 50 void disconnect( );
elessair 0:f269e3021894 51
elessair 0:f269e3021894 52 /*
elessair 0:f269e3021894 53 * Get a char from the dongle's serial interface
elessair 0:f269e3021894 54 */
elessair 0:f269e3021894 55 virtual int getc();
elessair 0:f269e3021894 56
elessair 0:f269e3021894 57 /*
elessair 0:f269e3021894 58 * Put a char to the dongle's serial interface
elessair 0:f269e3021894 59 */
elessair 0:f269e3021894 60 virtual int putc(int c);
elessair 0:f269e3021894 61
elessair 0:f269e3021894 62 /*
elessair 0:f269e3021894 63 * Read a packet from the dongle's serial interface, to be called after multiple getc() calls
elessair 0:f269e3021894 64 */
elessair 0:f269e3021894 65 virtual int readPacket();
elessair 0:f269e3021894 66
elessair 0:f269e3021894 67 /*
elessair 0:f269e3021894 68 * Write a packet to the dongle's serial interface, to be called after multiple putc() calls
elessair 0:f269e3021894 69 */
elessair 0:f269e3021894 70 virtual int writePacket();
elessair 0:f269e3021894 71
elessair 0:f269e3021894 72 /**
elessair 0:f269e3021894 73 * Check the number of bytes available.
elessair 0:f269e3021894 74 *
elessair 0:f269e3021894 75 * @returns the number of bytes available
elessair 0:f269e3021894 76 */
elessair 0:f269e3021894 77 virtual int readable();
elessair 0:f269e3021894 78
elessair 0:f269e3021894 79 /**
elessair 0:f269e3021894 80 * Check the free space in output.
elessair 0:f269e3021894 81 *
elessair 0:f269e3021894 82 * @returns the number of bytes available
elessair 0:f269e3021894 83 */
elessair 0:f269e3021894 84 virtual int writeable();
elessair 0:f269e3021894 85
elessair 0:f269e3021894 86 /**
elessair 0:f269e3021894 87 * Attach a handler to call when a packet is received / when a packet has been transmitted.
elessair 0:f269e3021894 88 *
elessair 0:f269e3021894 89 * @param pListener instance of the listener deriving from the IUSBHostSerialListener
elessair 0:f269e3021894 90 */
elessair 0:f269e3021894 91 virtual void attach(IUSBHostSerialListener* pListener);
elessair 0:f269e3021894 92
elessair 0:f269e3021894 93 /**
elessair 0:f269e3021894 94 * Enable or disable readable/writeable callbacks
elessair 0:f269e3021894 95 */
elessair 0:f269e3021894 96 virtual void setupIrq(bool en, IrqType irq = RxIrq);
elessair 0:f269e3021894 97
elessair 0:f269e3021894 98
elessair 0:f269e3021894 99 protected:
elessair 0:f269e3021894 100 USBEndpoint * bulk_in;
elessair 0:f269e3021894 101 USBEndpoint * bulk_out;
elessair 0:f269e3021894 102 USBHost * host;
elessair 0:f269e3021894 103 USBDeviceConnected * dev;
elessair 0:f269e3021894 104
elessair 0:f269e3021894 105 uint8_t buf_out[WANDONGLE_MAX_OUTEP_SIZE];
elessair 0:f269e3021894 106 volatile uint32_t buf_out_len;
elessair 0:f269e3021894 107 uint32_t max_out_size;
elessair 0:f269e3021894 108 volatile bool lock_tx;
elessair 0:f269e3021894 109 volatile bool cb_tx_en;
elessair 0:f269e3021894 110 volatile bool cb_tx_pending;
elessair 0:f269e3021894 111 Mutex tx_mtx;
elessair 0:f269e3021894 112
elessair 0:f269e3021894 113 uint8_t buf_in[WANDONGLE_MAX_INEP_SIZE];
elessair 0:f269e3021894 114 volatile uint32_t buf_in_len;
elessair 0:f269e3021894 115 volatile uint32_t buf_in_read_pos;
elessair 0:f269e3021894 116 volatile bool lock_rx;
elessair 0:f269e3021894 117 volatile bool cb_rx_en;
elessair 0:f269e3021894 118 volatile bool cb_rx_pending;
elessair 0:f269e3021894 119 Mutex rx_mtx;
elessair 0:f269e3021894 120
elessair 0:f269e3021894 121 IUSBHostSerialListener* listener;
elessair 0:f269e3021894 122
elessair 0:f269e3021894 123 void reset();
elessair 0:f269e3021894 124
elessair 0:f269e3021894 125 void rxHandler();
elessair 0:f269e3021894 126 void txHandler();
elessair 0:f269e3021894 127
elessair 0:f269e3021894 128 };
elessair 0:f269e3021894 129
elessair 0:f269e3021894 130 #endif /* USBHOST_3GMODULE */
elessair 0:f269e3021894 131
elessair 0:f269e3021894 132 #endif
elessair 0:f269e3021894 133