WANDongleSerialPort.h 3.5 KB

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