2018.07.26

Dependencies:   FATFileSystem3 mbed-rtos

Fork of USBHost by mbed official

Committer:
sayzyas
Date:
Thu Jul 26 00:20:32 2018 +0000
Revision:
43:1675750cca08
2018.07.26

Who changed what in which revision?

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