3 * Copyright 2003 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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 3, or (at your option)
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.
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.
25 #ifndef _FUSB_LINUX_H_
26 #define _FUSB_LINUX_H_
32 class fusb_ephandle_linux;
35 * \brief linux specific implementation of fusb_devhandle using usbdevice_fs
37 class fusb_devhandle_linux : public fusb_devhandle {
39 std::list<usbdevfs_urb*> d_pending_rqsts;
41 void pending_add (usbdevfs_urb *urb);
42 bool pending_remove (usbdevfs_urb *urb);
43 usbdevfs_urb * pending_get ();
48 fusb_devhandle_linux (usb_dev_handle *udh);
49 virtual ~fusb_devhandle_linux ();
52 virtual fusb_ephandle *make_ephandle (int endpoint, bool input_p,
53 int block_size = 0, int nblocks = 0);
56 bool _submit_urb (usbdevfs_urb *urb);
57 bool _cancel_urb (usbdevfs_urb *urb);
58 void _cancel_pending_rqsts (fusb_ephandle_linux *eph);
59 bool _reap (bool ok_to_block_p);
60 void _wait_for_completion ();
64 * \brief linux specific implementation of fusb_ephandle using usbdevice_fs
67 class fusb_ephandle_linux : public fusb_ephandle {
69 fusb_devhandle_linux *d_devhandle;
70 std::list<usbdevfs_urb*> d_free_list;
71 std::list<usbdevfs_urb*> d_completed_list;
72 usbdevfs_urb *d_write_work_in_progress;
73 unsigned char *d_write_buffer;
74 usbdevfs_urb *d_read_work_in_progress;
75 unsigned char *d_read_buffer;
76 unsigned char *d_read_buffer_end;
78 usbdevfs_urb *get_write_work_in_progress ();
79 void reap_complete_writes ();
80 bool reload_read_buffer ();
81 bool submit_urb (usbdevfs_urb *urb);
84 fusb_ephandle_linux (fusb_devhandle_linux *dh, int endpoint, bool input_p,
85 int block_size = 0, int nblocks = 0);
86 virtual ~fusb_ephandle_linux ();
88 virtual bool start (); //!< begin streaming i/o
89 virtual bool stop (); //!< stop streaming i/o
92 * \returns \p nbytes if write was successfully enqueued, else -1.
93 * Will block if no free buffers available.
95 virtual int write (const void *buffer, int nbytes);
98 * \returns number of bytes read or -1 if error.
99 * number of bytes read will be <= nbytes.
100 * Will block if no input available.
102 virtual int read (void *buffer, int nbytes);
105 * block until all outstanding writes have completed
107 virtual void wait_for_completion ();
110 void free_list_add (usbdevfs_urb *urb);
111 void completed_list_add (usbdevfs_urb *urb);
112 usbdevfs_urb *free_list_get (); // pop and return head of list or 0
113 usbdevfs_urb *completed_list_get (); // pop and return head of list or 0
116 #endif /* _FUSB_LINUX_H_ */