Add more const-ness to the stream endpoint/pipe functions where possible.
[pub/USBasp.git] / LUFA / Drivers / USB / HighLevel / Template / Template_Pipe_RW.c
1 uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE const Buffer,
2 uint16_t Length,
3 uint16_t* const BytesProcessed)
4 {
5 uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
6 uint16_t BytesInTransfer = 0;
7 uint8_t ErrorCode;
8
9 Pipe_SetPipeToken(TEMPLATE_TOKEN);
10
11 if ((ErrorCode = Pipe_WaitUntilReady()))
12 return ErrorCode;
13
14 if (BytesProcessed != NULL)
15 {
16 Length -= *BytesProcessed;
17 TEMPLATE_BUFFER_MOVE(DataStream, *BytesProcessed);
18 }
19
20 while (Length)
21 {
22 if (!(Pipe_IsReadWriteAllowed()))
23 {
24 TEMPLATE_CLEAR_PIPE();
25
26 if (BytesProcessed != NULL)
27 {
28 *BytesProcessed += BytesInTransfer;
29 return PIPE_RWSTREAM_IncompleteTransfer;
30 }
31
32 if ((ErrorCode = Pipe_WaitUntilReady()))
33 return ErrorCode;
34 }
35 else
36 {
37 TEMPLATE_TRANSFER_BYTE(DataStream);
38 TEMPLATE_BUFFER_MOVE(DataStream, 1);
39 Length--;
40 BytesInTransfer++;
41 }
42 }
43
44 return PIPE_RWSTREAM_NoError;
45 }
46
47 #undef TEMPLATE_FUNC_NAME
48 #undef TEMPLATE_BUFFER_TYPE
49 #undef TEMPLATE_TOKEN
50 #undef TEMPLATE_TRANSFER_BYTE
51 #undef TEMPLATE_CLEAR_PIPE
52 #undef TEMPLATE_BUFFER_OFFSET
53 #undef TEMPLATE_BUFFER_MOVE