Statistics
| Branch: | Tag: | Revision:

root / LUFA / Drivers / USB / Core / AVR8 / Template / Template_Pipe_RW.c @ 978b99e5

History | View | Annotate | Download (2.41 KB)

1
/*
2
             LUFA Library
3
     Copyright (C) Dean Camera, 2011.
4

5
  dean [at] fourwalledcubicle [dot] com
6
           www.lufa-lib.org
7
*/
8

    
9
/*
10
  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
11

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.
20

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
28
  this software.
29
*/
30

    
31
#if defined(TEMPLATE_FUNC_NAME)
32

    
33
uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE const Buffer,
34
                            uint16_t Length,
35
                            uint16_t* const BytesProcessed)
36
{
37
        uint8_t* DataStream      = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
38
        uint16_t BytesInTransfer = 0;
39
        uint8_t  ErrorCode;
40

    
41
        Pipe_SetPipeToken(TEMPLATE_TOKEN);
42

    
43
        if ((ErrorCode = Pipe_WaitUntilReady()))
44
          return ErrorCode;
45

    
46
        if (BytesProcessed != NULL)
47
        {
48
                Length -= *BytesProcessed;
49
                TEMPLATE_BUFFER_MOVE(DataStream, *BytesProcessed);
50
        }
51
        
52
        while (Length)
53
        {
54
                if (!(Pipe_IsReadWriteAllowed()))
55
                {
56
                        TEMPLATE_CLEAR_PIPE();
57

    
58
                        if (BytesProcessed != NULL)
59
                        {
60
                                *BytesProcessed += BytesInTransfer;
61
                                return PIPE_RWSTREAM_IncompleteTransfer;
62
                        }
63

    
64
                        if ((ErrorCode = Pipe_WaitUntilReady()))
65
                          return ErrorCode;
66
                }
67
                else
68
                {
69
                        TEMPLATE_TRANSFER_BYTE(DataStream);
70
                        TEMPLATE_BUFFER_MOVE(DataStream, 1);
71
                        Length--;
72
                        BytesInTransfer++;
73
                }
74
        }
75

    
76
        return PIPE_RWSTREAM_NoError;
77
}
78

    
79
#undef TEMPLATE_FUNC_NAME
80
#undef TEMPLATE_BUFFER_TYPE
81
#undef TEMPLATE_TOKEN
82
#undef TEMPLATE_TRANSFER_BYTE
83
#undef TEMPLATE_CLEAR_PIPE
84
#undef TEMPLATE_BUFFER_OFFSET
85
#undef TEMPLATE_BUFFER_MOVE
86

    
87
#endif