root / usrp / host / lib / legacy / fusb.h @ b06cd32d
History | View | Annotate | Download (3.3 kB)
| 1 | /* -*- c++ -*- */
|
|---|---|
| 2 | /*
|
| 3 | * Copyright 2003 Free Software Foundation, Inc. |
| 4 | * |
| 5 | * This file is part of GNU Radio |
| 6 | * |
| 7 | * GNU Radio is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * GNU Radio is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Radio; see the file COPYING. If not, write to |
| 19 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | */ |
| 22 | |
| 23 | // Fast USB interface
|
| 24 | |
| 25 | #ifndef _FUSB_H_
|
| 26 | #define _FUSB_H_
|
| 27 | |
| 28 | |
| 29 | struct usb_dev_handle;
|
| 30 | class fusb_ephandle; |
| 31 | |
| 32 | /*!
|
| 33 | * \brief abstract usb device handle |
| 34 | */ |
| 35 | class fusb_devhandle {
|
| 36 | private:
|
| 37 | // NOT IMPLEMENTED
|
| 38 | fusb_devhandle (const fusb_devhandle &rhs); // no copy constructor |
| 39 | fusb_devhandle &operator= (const fusb_devhandle &rhs); // no assignment operator |
| 40 | |
| 41 | protected:
|
| 42 | usb_dev_handle *d_udh; |
| 43 | |
| 44 | public:
|
| 45 | // CREATORS
|
| 46 | fusb_devhandle (usb_dev_handle *udh); |
| 47 | virtual ~fusb_devhandle (); |
| 48 | |
| 49 | // MANIPULATORS
|
| 50 | |
| 51 | /*!
|
| 52 | * \brief return an ephandle of the correct subtype |
| 53 | */ |
| 54 | virtual fusb_ephandle *make_ephandle (int endpoint, bool input_p, |
| 55 | int block_size = 0, int nblocks = 0) = 0; |
| 56 | |
| 57 | // ACCESSORS
|
| 58 | usb_dev_handle *get_usb_dev_handle () const { return d_udh; } |
| 59 | }; |
| 60 | |
| 61 | |
| 62 | /*!
|
| 63 | * \brief abstract usb end point handle |
| 64 | */ |
| 65 | class fusb_ephandle {
|
| 66 | private:
|
| 67 | // NOT IMPLEMENTED
|
| 68 | fusb_ephandle (const fusb_ephandle &rhs); // no copy constructor |
| 69 | fusb_ephandle &operator= (const fusb_ephandle &rhs); // no assignment operator |
| 70 | |
| 71 | protected:
|
| 72 | int d_endpoint;
|
| 73 | bool d_input_p;
|
| 74 | int d_block_size;
|
| 75 | int d_nblocks;
|
| 76 | bool d_started;
|
| 77 | |
| 78 | public:
|
| 79 | fusb_ephandle (int endpoint, bool input_p, |
| 80 | int block_size = 0, int nblocks = 0); |
| 81 | virtual ~fusb_ephandle (); |
| 82 | |
| 83 | virtual bool start () = 0; //!< begin streaming i/o |
| 84 | virtual bool stop () = 0; //!< stop streaming i/o |
| 85 | |
| 86 | /*!
|
| 87 | * \returns \p nbytes if write was successfully enqueued, else -1. |
| 88 | * Will block if no free buffers available. |
| 89 | */ |
| 90 | virtual int write (const void *buffer, int nbytes) = 0; |
| 91 | |
| 92 | /*!
|
| 93 | * \returns number of bytes read or -1 if error. |
| 94 | * number of bytes read will be <= nbytes. |
| 95 | * Will block if no input available. |
| 96 | */ |
| 97 | virtual int read (void *buffer, int nbytes) = 0; |
| 98 | |
| 99 | /*
|
| 100 | * block until all outstanding writes have completed |
| 101 | */ |
| 102 | virtual void wait_for_completion () = 0; |
| 103 | |
| 104 | /*!
|
| 105 | * \brief returns current block size. |
| 106 | */ |
| 107 | int block_size () { return d_block_size; }; |
| 108 | }; |
| 109 | |
| 110 | |
| 111 | /*!
|
| 112 | * \brief factory for creating concrete instances of the appropriate subtype. |
| 113 | */ |
| 114 | class fusb_sysconfig {
|
| 115 | public:
|
| 116 | /*!
|
| 117 | * \brief returns fusb_devhandle or throws if trouble |
| 118 | */ |
| 119 | static fusb_devhandle *make_devhandle (usb_dev_handle *udh);
|
| 120 | |
| 121 | /*!
|
| 122 | * \brief Returns max block size in bytes (hard limit). |
| 123 | */ |
| 124 | static int max_block_size (); |
| 125 | |
| 126 | /*!
|
| 127 | * \brief Returns default block size in bytes. |
| 128 | */ |
| 129 | static int default_block_size (); |
| 130 | |
| 131 | /*!
|
| 132 | * \brief Returns the default buffer size in bytes. |
| 133 | */ |
| 134 | static int default_buffer_size (); |
| 135 | |
| 136 | }; |
| 137 | |
| 138 | #endif /* _FUSB_H_ */ |