Mercurial > nand-ecoscentric
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 |
| rev | line source |
|---|---|
| 2493 | 1 //========================================================================== |
| 2 // | |
| 3 // usb_serial_echo.c | |
| 4 // | |
| 5 // Example application for the USB serial layer in eCos. | |
| 6 // | |
| 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 | 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 | 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 | 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 | 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 | 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 | 39 //=========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 42 // Author(s): Frank M. Pagliughi (fmp), SoRo Systems, Inc. | |
| 43 // Contributors: | |
| 44 // Date: 2008-06-02 | |
| 45 // Description: USB serial example application. | |
| 46 // | |
| 47 //####DESCRIPTIONEND#### | |
| 48 //=========================================================================== | |
| 49 | |
| 50 #include <cyg/kernel/kapi.h> | |
| 51 #include <cyg/hal/hal_arch.h> | |
| 52 #include <cyg/infra/diag.h> | |
| 53 #include <pkgconf/kernel.h> | |
| 54 #include <cyg/io/usb/usbs_serial.h> | |
| 55 | |
| 56 #include <stdio.h> | |
| 57 #include <stdlib.h> | |
| 58 | |
| 59 #define DEBUG_OUTPUT | |
| 60 | |
| 61 #if defined(DEBUG_OUTPUT) | |
| 62 #define DBG diag_printf | |
| 63 #else | |
| 64 #define DBG (1) ? (void)0 : diag_printf | |
| 65 #endif | |
| 66 | |
| 67 typedef unsigned char byte; | |
| 68 | |
| 69 // -------------------------------------------------------------------------- | |
| 70 // Data & Callback(s) | |
| 71 // -------------------------------------------------------------------------- | |
| 72 | |
| 73 #define BUF_SIZE 4096 | |
| 74 | |
| 75 static byte rx_buf[2][BUF_SIZE+1], tx_buf[BUF_SIZE+1]; | |
| 76 | |
| 77 // -------------------------------------------------------------------------- | |
| 78 // Main Routine | |
| 79 // -------------------------------------------------------------------------- | |
| 80 | |
| 81 int main(void) | |
| 82 { | |
| 83 int n; | |
| 84 unsigned ibuf, next_buf; | |
| 85 | |
| 86 // ----- Start USB subsystem ----- | |
| 87 | |
| 88 usbs_serial_start(); | |
| 89 | |
| 90 // ----- Get data from host and send it back ----- | |
| 91 | |
| 92 while (1) { | |
| 93 ibuf = 0; | |
| 94 | |
| 95 // ----- Wait for the host to configure ----- | |
| 96 | |
| 97 usbs_serial_wait_until_configured(); | |
| 98 cyg_thread_delay((cyg_tick_count_t) 10); | |
| 99 | |
| 100 // ----- While configured read data & print to screen ----- | |
| 101 | |
| 102 usbs_serial_start_rx(&usbs_ser0, rx_buf[ibuf], BUF_SIZE); | |
| 103 | |
| 104 while (usbs_serial_is_configured()) { | |
| 105 | |
| 106 n = usbs_serial_wait_for_rx(&usbs_ser0); | |
| 107 next_buf = ibuf ^ 1; | |
| 108 | |
| 109 usbs_serial_start_rx(&usbs_ser0, rx_buf[next_buf], BUF_SIZE); | |
| 110 | |
| 111 if (n < 0) { | |
| 112 DBG("*** I/O Error: %d ***\n", n); | |
| 113 } | |
| 114 else { | |
| 115 memcpy(tx_buf, rx_buf[ibuf], n); | |
| 116 usbs_serial_tx(&usbs_ser0, tx_buf, n); | |
| 117 rx_buf[ibuf][n] = '\0'; | |
| 118 DBG("%s", rx_buf[ibuf]); | |
| 119 } | |
| 120 | |
| 121 ibuf = next_buf; | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 return 0; | |
| 126 } | |
| 127 |
