2018.07.26

Dependencies:   FATFileSystem mbed-rtos

Fork of USBHost by mbed official

Committer:
sayzyas
Date:
Thu Jul 26 00:18:29 2018 +0000
Revision:
43:52b15824a019
2018.07.26

Who changed what in which revision?

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