3 Copyright (C) Dean Camera, 2010.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
31 #define __INCLUDE_FROM_USB_DRIVER
34 #if defined(USB_CAN_BE_HOST)
36 #include "PipeStream.h"
38 uint8_t Pipe_Discard_Stream(uint16_t Length
43 Pipe_SetPipeToken(PIPE_TOKEN_IN
);
45 if ((ErrorCode
= Pipe_WaitUntilReady()))
48 #if defined(FAST_STREAM_TRANSFERS)
49 uint8_t BytesRemToAlignment
= (Pipe_BytesInPipe() & 0x07);
53 Length
-= BytesRemToAlignment
;
55 switch (BytesRemToAlignment
)
60 if (!(Pipe_IsReadWriteAllowed()))
64 #if !defined(NO_STREAM_CALLBACKS)
65 if ((Callback
!= NULL
) && (Callback() == STREAMCALLBACK_Abort
))
66 return PIPE_RWSTREAM_CallbackAborted
;
69 if ((ErrorCode
= Pipe_WaitUntilReady()))
76 case 7: Pipe_Discard_Byte();
77 case 6: Pipe_Discard_Byte();
78 case 5: Pipe_Discard_Byte();
79 case 4: Pipe_Discard_Byte();
80 case 3: Pipe_Discard_Byte();
81 case 2: Pipe_Discard_Byte();
82 case 1: Pipe_Discard_Byte();
83 } while (Length
>= 8);
90 if (!(Pipe_IsReadWriteAllowed()))
94 #if !defined(NO_STREAM_CALLBACKS)
95 if ((Callback
!= NULL
) && (Callback() == STREAMCALLBACK_Abort
))
96 return PIPE_RWSTREAM_CallbackAborted
;
99 if ((ErrorCode
= Pipe_WaitUntilReady()))
109 return PIPE_RWSTREAM_NoError
;
112 /* The following abuses the C preprocessor in order to copy-past common code with slight alterations,
113 * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
115 #define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE
116 #define TEMPLATE_BUFFER_TYPE const void*
117 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
118 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
119 #define TEMPLATE_BUFFER_OFFSET(Length) 0
120 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*((uint8_t*)BufferPtr++))
121 #include "Template/Template_Pipe_RW.c"
123 #define TEMPLATE_FUNC_NAME Pipe_Write_PStream_LE
124 #define TEMPLATE_BUFFER_TYPE const void*
125 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
126 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
127 #define TEMPLATE_BUFFER_OFFSET(Length) 0
128 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
129 #include "Template/Template_Pipe_RW.c"
131 #define TEMPLATE_FUNC_NAME Pipe_Write_EStream_LE
132 #define TEMPLATE_BUFFER_TYPE const void*
133 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
134 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
135 #define TEMPLATE_BUFFER_OFFSET(Length) 0
136 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
137 #include "Template/Template_Pipe_RW.c"
139 #define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE
140 #define TEMPLATE_BUFFER_TYPE const void*
141 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
142 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
143 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
144 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*((uint8_t*)BufferPtr--))
145 #include "Template/Template_Pipe_RW.c"
147 #define TEMPLATE_FUNC_NAME Pipe_Write_PStream_BE
148 #define TEMPLATE_BUFFER_TYPE const void*
149 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
150 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
151 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
152 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
153 #include "Template/Template_Pipe_RW.c"
155 #define TEMPLATE_FUNC_NAME Pipe_Write_EStream_BE
156 #define TEMPLATE_BUFFER_TYPE const void*
157 #define TEMPLATE_TOKEN PIPE_TOKEN_OUT
158 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
159 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
160 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
161 #include "Template/Template_Pipe_RW.c"
163 #define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE
164 #define TEMPLATE_BUFFER_TYPE void*
165 #define TEMPLATE_TOKEN PIPE_TOKEN_IN
166 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
167 #define TEMPLATE_BUFFER_OFFSET(Length) 0
168 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Pipe_Read_Byte()
169 #include "Template/Template_Pipe_RW.c"
171 #define TEMPLATE_FUNC_NAME Pipe_Read_EStream_LE
172 #define TEMPLATE_BUFFER_TYPE void*
173 #define TEMPLATE_TOKEN PIPE_TOKEN_IN
174 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
175 #define TEMPLATE_BUFFER_OFFSET(Length) 0
176 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr++, Pipe_Read_Byte())
177 #include "Template/Template_Pipe_RW.c"
179 #define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE
180 #define TEMPLATE_BUFFER_TYPE void*
181 #define TEMPLATE_TOKEN PIPE_TOKEN_IN
182 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
183 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
184 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Pipe_Read_Byte()
185 #include "Template/Template_Pipe_RW.c"
187 #define TEMPLATE_FUNC_NAME Pipe_Read_EStream_BE
188 #define TEMPLATE_BUFFER_TYPE void*
189 #define TEMPLATE_TOKEN PIPE_TOKEN_IN
190 #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
191 #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
192 #define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr--, Pipe_Read_Byte())
193 #include "Template/Template_Pipe_RW.c"