annotate packages/io/usb/serial/slave/current/tests/usbserial_echo.c @ 3048:ea354217b697

* cdl/usb_serial.cdl: Place static endpoint struct options in a CDL component. * src/usbs_serial.c: Use usbs_get_[tr]x_endpoint() when static endpoint structs are disabled. [ Bugzilla 1001024 ] * tests/usbserial_echo.c, tests/usb2serial.c: Eliminate inclusion of the AT91 USB slave driver header file. * doc/usbs_serial.sgml: Mention the new static endpoint struct CDL component.
author jld
date Wed, 27 Oct 2010 10:22:51 +0000
parents 74dbf4c3f2e1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2493
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
1 //==========================================================================
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
2 //
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
3 // usb_serial_echo.c
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
4 //
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
5 // Example application for the USB serial layer in eCos.
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
6 //
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
7 //==========================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
8 // ####ECOSGPLCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
9 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
3048
ea354217b697 * cdl/usb_serial.cdl: Place static endpoint struct options in a CDL
jld
parents: 2729
diff changeset
11 // Copyright (C) 2008, 2010 Free Software Foundation, Inc.
2493
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
12 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
14 // the terms of the GNU General Public License as published by the Free
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
16 // version.
2493
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
17 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
18 // eCos is distributed in the hope that it will be useful, but WITHOUT
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
21 // for more details.
2493
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
22 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
23 // You should have received a copy of the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
24 // along with eCos; if not, write to the Free Software Foundation, Inc.,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2493
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
26 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
27 // As a special exception, if other files instantiate templates or use
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
28 // macros or inline functions from this file, or you compile this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
29 // and link it with other works to produce a work based on this file,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
30 // this file does not by itself cause the resulting work to be covered by
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
31 // the GNU General Public License. However the source code for this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
32 // must still be made available in accordance with section (3) of the GNU
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
33 // General Public License v2.
2493
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
34 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
35 // This exception does not invalidate any other reasons why a work based
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
36 // on this file might be covered by the GNU General Public License.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
37 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2493
diff changeset
38 // ####ECOSGPLCOPYRIGHTEND####
2493
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
39 //===========================================================================
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
40 //#####DESCRIPTIONBEGIN####
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
41 //
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
42 // Author(s): Frank M. Pagliughi (fmp), SoRo Systems, Inc.
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
43 // Contributors:
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
44 // Date: 2008-06-02
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
45 // Description: USB serial example application.
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
46 //
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
47 //####DESCRIPTIONEND####
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
48 //===========================================================================
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
49
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
50 #include <cyg/kernel/kapi.h>
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
51 #include <cyg/hal/hal_arch.h>
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
52 #include <cyg/infra/diag.h>
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
53 #include <pkgconf/kernel.h>
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
54 #include <cyg/io/usb/usbs_serial.h>
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
55
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
56 #include <stdio.h>
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
57 #include <stdlib.h>
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
58
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
59 #define DEBUG_OUTPUT
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
60
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
61 #if defined(DEBUG_OUTPUT)
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
62 #define DBG diag_printf
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
63 #else
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
64 #define DBG (1) ? (void)0 : diag_printf
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
65 #endif
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
66
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
67 typedef unsigned char byte;
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
68
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
69 // --------------------------------------------------------------------------
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
70 // Data & Callback(s)
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
71 // --------------------------------------------------------------------------
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
72
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
73 #define BUF_SIZE 4096
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
74
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
75 static byte rx_buf[2][BUF_SIZE+1], tx_buf[BUF_SIZE+1];
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
76
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
77 // --------------------------------------------------------------------------
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
78 // Main Routine
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
79 // --------------------------------------------------------------------------
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
80
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
81 int main(void)
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
82 {
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
83 int n;
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
84 unsigned ibuf, next_buf;
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
85
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
86 // ----- Start USB subsystem -----
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
87
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
88 usbs_serial_start();
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
89
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
90 // ----- Get data from host and send it back -----
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
91
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
92 while (1) {
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
93 ibuf = 0;
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
94
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
95 // ----- Wait for the host to configure -----
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
96
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
97 usbs_serial_wait_until_configured();
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
98 cyg_thread_delay((cyg_tick_count_t) 10);
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
99
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
100 // ----- While configured read data & print to screen -----
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
101
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
102 usbs_serial_start_rx(&usbs_ser0, rx_buf[ibuf], BUF_SIZE);
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
103
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
104 while (usbs_serial_is_configured()) {
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
105
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
106 n = usbs_serial_wait_for_rx(&usbs_ser0);
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
107 next_buf = ibuf ^ 1;
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
108
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
109 usbs_serial_start_rx(&usbs_ser0, rx_buf[next_buf], BUF_SIZE);
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
110
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
111 if (n < 0) {
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
112 DBG("*** I/O Error: %d ***\n", n);
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
113 }
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
114 else {
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
115 memcpy(tx_buf, rx_buf[ibuf], n);
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
116 usbs_serial_tx(&usbs_ser0, tx_buf, n);
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
117 rx_buf[ibuf][n] = '\0';
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
118 DBG("%s", rx_buf[ibuf]);
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
119 }
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
120
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
121 ibuf = next_buf;
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
122 }
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
123 }
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
124
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
125 return 0;
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
126 }
3adca3f92ff7 * Generic USB Serial package created.
asl
parents:
diff changeset
127