1 //==========================================================================
5 // Example application for the USB serial layer in eCos.
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
12 // eCos is free software; you can redistribute it and/or modify it under
13 // the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 2 or (at your option) any later version.
16 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 // You should have received a copy of the GNU General Public License along
22 // with eCos; if not, write to the Free Software Foundation, Inc.,
23 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 // As a special exception, if other files instantiate templates or use macros
26 // or inline functions from this file, or you compile this file and link it
27 // with other works to produce a work based on this file, this file does not
28 // by itself cause the resulting work to be covered by the GNU General Public
29 // License. However the source code for this file must still be made available
30 // in accordance with section (3) of the GNU General Public License.
32 // This exception does not invalidate any other reasons why a work based on
33 // this file might be covered by the GNU General Public License.
35 // -------------------------------------------
36 //####ECOSGPLCOPYRIGHTEND####
37 //===========================================================================
38 //#####DESCRIPTIONBEGIN####
40 // Author(s): Frank M. Pagliughi (fmp), SoRo Systems, Inc.
43 // Description: USB serial example application.
45 //####DESCRIPTIONEND####
46 //===========================================================================
48 #include <cyg/kernel/kapi.h>
49 #include <cyg/hal/hal_arch.h>
50 #include <cyg/infra/diag.h>
51 #include <pkgconf/kernel.h>
52 #include <cyg/io/usb/usbs_at91.h>
53 #include <cyg/io/usb/usbs_serial.h>
60 #if defined(DEBUG_OUTPUT)
61 #define DBG diag_printf
63 #define DBG (1) ? (void)0 : diag_printf
66 typedef unsigned char byte;
68 // --------------------------------------------------------------------------
70 // --------------------------------------------------------------------------
74 static byte rx_buf[2][BUF_SIZE+1], tx_buf[BUF_SIZE+1];
76 // --------------------------------------------------------------------------
78 // --------------------------------------------------------------------------
83 unsigned ibuf, next_buf;
85 // ----- Start USB subsystem -----
89 // ----- Get data from host and send it back -----
94 // ----- Wait for the host to configure -----
96 usbs_serial_wait_until_configured();
97 cyg_thread_delay((cyg_tick_count_t) 10);
99 // ----- While configured read data & print to screen -----
101 usbs_serial_start_rx(&usbs_ser0, rx_buf[ibuf], BUF_SIZE);
103 while (usbs_serial_is_configured()) {
105 n = usbs_serial_wait_for_rx(&usbs_ser0);
108 usbs_serial_start_rx(&usbs_ser0, rx_buf[next_buf], BUF_SIZE);
111 DBG("*** I/O Error: %d ***\n", n);
114 memcpy(tx_buf, rx_buf[ibuf], n);
115 usbs_serial_tx(&usbs_ser0, tx_buf, n);
116 rx_buf[ibuf][n] = '\0';
117 DBG("%s", rx_buf[ibuf]);