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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [usb/] [serial/] [slave/] [current/] [include/] [usbs_serial.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_USBS_SERIAL_H
2
#define CYGONCE_USBS_SERIAL_H
3
//==========================================================================
4
//
5
//      include/usbs_serial.h
6
//
7
//      Description of the USB slave-side serial device support
8
//
9
//==========================================================================
10
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
11
// -------------------------------------------                              
12
// This file is part of eCos, the Embedded Configurable Operating System.   
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under    
16
// the terms of the GNU General Public License as published by the Free     
17
// Software Foundation; either version 2 or (at your option) any later      
18
// version.                                                                 
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT      
21
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
23
// for more details.                                                        
24
//
25
// You should have received a copy of the GNU General Public License        
26
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
27
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
28
//
29
// As a special exception, if other files instantiate templates or use      
30
// macros or inline functions from this file, or you compile this file      
31
// and link it with other works to produce a work based on this file,       
32
// this file does not by itself cause the resulting work to be covered by   
33
// the GNU General Public License. However the source code for this file    
34
// must still be made available in accordance with section (3) of the GNU   
35
// General Public License v2.                                               
36
//
37
// This exception does not invalidate any other reasons why a work based    
38
// on this file might be covered by the GNU General Public License.         
39
// -------------------------------------------                              
40
// ####ECOSGPLCOPYRIGHTEND####                                              
41
//==========================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):    Frank M. Pagliughi (fmp), SoRo Systems, Inc.
45
// Contributors: 
46
// Date:         2008-06-02
47
// Purpose:
48
// Description:  USB slave-side serial support
49
//
50
//
51
//####DESCRIPTIONEND####
52
//==========================================================================
53
 
54
#ifdef __cplusplus
55
extern "C" {
56
#endif
57
 
58
//
59
// The primary purpose of the USB slave-side serial code is to provide a 
60
// simple USB connection to the host, especially for embedded systems that
61
// are upgrading from RS-232 serial connections. The host would see the 
62
// device as if through a serial port, and thus the host software would
63
// remain unchanged. It would also eliminate the need for a new device
64
// driver on the host.
65
// 
66
// On this side (the eCos USB slave side), the application sees the host
67
// through a normal USB slave connection with two Bulk endpoints - one in 
68
// the IN direction and one in the OUT direction. This module provides the
69
// necessary USB descriptors to enumerate the device for a single serial
70
// port, but then the application is free to communicate with the host
71
// using any desired API:
72
//  - The standard eCos USB slave API
73
//  - The low-level File I/O layer (if USB devtab entries configured)
74
//  - The C stdio functions (again, if USB devtab entries configured)
75
//  - The USB serial API defined here.
76
// 
77
// The USB serial API is a thin layer over the standard eCos USB functions
78
// to provide common synchronous and asynchronous transfers over the assigned
79
// Bulk endpoints.
80
//
81
 
82
#include <cyg/infra/cyg_type.h>
83
#include <cyg/io/usb/usbs.h>
84
 
85
// ----------------------------------------------------------------------------
86
// The ACM class requests
87
// 
88
 
89
#define USBS_SERIAL_SEND_ENCAPSULATED_COMMAND   0x00
90
#define USBS_SERIAL_GET_ENCAPSULATED_RESPONSE   0x01
91
#define USBS_SERIAL_SET_COMM_FEATURE            0x02
92
#define USBS_SERIAL_GET_COMM_FEATURE            0x03
93
#define USBS_SERIAL_CLEAR_COMM_FEATURE          0x04
94
 
95
#define USBS_SERIAL_SET_LINE_CODING             0x20
96
#define USBS_SERIAL_GET_LINE_CODING             0x21
97
#define USBS_SERIAL_SET_CONTROL_LINE_STATE      0x22
98
#define USBS_SERIAL_SEND_BREAK                  0x23
99
 
100
// ----------------------------------------------------------------------------
101
// Data structure to manage the pair of USB endpoints that comprise a single
102
// serial port connection. Each "port" requires one Bulk IN endpoint and one
103
// Bulk OUT endpoint.
104
 
105
typedef struct usbs_serial {
106
    // The communication endpoints. For the first (default) channel, these
107
    // are normally set by the configuration, but can be changed by the
108
    // application, if desired.
109
    usbs_tx_endpoint*   tx_ep;
110
    usbs_rx_endpoint*   rx_ep;
111
 
112
    // The signal that a transmit operation is complete, and it's result.
113
    cyg_sem_t   tx_ready;
114
    int         tx_result;
115
 
116
    // The signal that a receive operation is complete, and it's result.
117
    cyg_sem_t   rx_ready;
118
    int         rx_result;
119
 
120
} usbs_serial;
121
 
122
// The package contains one USB serial device.
123
extern usbs_serial usbs_ser0;
124
 
125
// It's assumed that there's a single USB slave chip in the system, with a
126
// single control endpoint 0. The actual variable is contained in the device
127
// driver, but the USB serial code keeps a pointer to it for driver 
128
// independence. The application might find it useful for overriding low-level
129
// code or callbacks.
130
extern usbs_control_endpoint* usbs_serial_ep0;
131
 
132
// ----------------------------------------------------------------------------
133
// A C interface to the serial USB code.
134
// The application can use this interface, the standard (low-level) USB slave
135
// API, the standard Unix-like I/O API, or C stdio API.
136
 
137
// Initialize support for a particular USB serial "port"
138
// This associates a usbs_serial structure with specific endpoints and 
139
// initializes the structure for communications.
140
void usbs_serial_init(usbs_serial*, usbs_tx_endpoint*, usbs_rx_endpoint*);
141
 
142
// Block the calling thread until the host configures the USB device.
143
void usbs_serial_wait_until_configured(void);
144
 
145
// Determines if the USB subsystem is configured
146
cyg_bool usbs_serial_is_configured(void);
147
 
148
// Start an asynchronous transmit of a single buffer.
149
void usbs_serial_start_tx(usbs_serial*, const void* buf, int n);
150
 
151
// Block the calling thread until the transmit completes.
152
// Returns the result code for the transfer
153
int usbs_serial_wait_for_tx(usbs_serial*);
154
 
155
// Blocking, synchronous transmit of a single buffer.
156
int usbs_serial_tx(usbs_serial*, const void* buf, int n);
157
 
158
// Start an asynchronous receive of a buffer.
159
void usbs_serial_start_rx(usbs_serial*, void* buf, int n);
160
 
161
// Block the calling thread until the receive completes.
162
// Returns the result code for the transfer
163
int usbs_serial_wait_for_rx(usbs_serial*);
164
 
165
// Blocking, synchronous receive of a single buffer.
166
int usbs_serial_rx(usbs_serial*, void* buf, int n);
167
 
168
// The default USB-serial state change handler paces the functions
169
// usbs_serial_wait_until_configured() and usbs_serial_is_configured().
170
// The application can override the state chain handler, but chain to 
171
// this function to keep the full USB-serial system working.
172
void usbs_serial_state_change_handler(usbs_control_endpoint*, void*,
173
                                      usbs_state_change, int);
174
 
175
// Starts the USB subsystem
176
void usbs_serial_start(void);
177
 
178
#ifdef __cplusplus
179
} // extern "C"
180
#endif
181
 
182
#endif // CYGONCE_USBS_SERIAL_H
183
 

powered by: WebSVN 2.1.0

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