OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [usb/] [serial/] [slave/] [current/] [tests/] [usbserial_echo.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      usb_serial_echo.c
4
//
5
//      Example application for the USB serial layer in eCos.
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2008, 2010 Free Software Foundation, Inc.                        
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
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
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.