summaryrefslogtreecommitdiff
path: root/tool/mbed/mbed-sdk/libraries/USBDevice/USBDevice/TARGET_RENESAS/TARGET_RZ_A1H/usb1/src/function/usb1_function_controlrw.c
blob: 45f8fa4858f675838c5724d074875465ef11b3de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*******************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only
* intended for use with Renesas products. No other uses are authorized. This
* software is owned by Renesas Electronics Corporation and is protected under
* all applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software
* and to discontinue the availability of this software. By using this software,
* you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
* Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
*******************************************************************************/
/*******************************************************************************
* File Name    : usb1_function_controlrw.c
* $Rev: 1116 $
* $Date:: 2014-07-09 16:29:19 +0900#$
* Device(s)    : RZ/A1H
* Tool-Chain   :
* OS           : None
* H/W Platform :
* Description  : RZ/A1H R7S72100 USB Sample Program
* Operation    :
* Limitations  :
*******************************************************************************/


/*******************************************************************************
Includes   <System Includes> , "Project Includes"
*******************************************************************************/
#include "usb1_function.h"


/*******************************************************************************
Typedef definitions
*******************************************************************************/


/*******************************************************************************
Macro definitions
*******************************************************************************/


/*******************************************************************************
Imported global variables and functions (from other files)
*******************************************************************************/


/*******************************************************************************
Exported global variables and functions (to be accessed by other files)
*******************************************************************************/


/*******************************************************************************
Private global variables and functions
*******************************************************************************/


/*******************************************************************************
* Function Name: usb1_api_function_CtrlReadStart
* Description  : Executes the USB control read transfer.
*              : USB host controller <- USB device
* Arguments    : uint16_t size     ; Data Size
*              : uint8_t  *data    ; Data Address
* Return Value : DEVDRV_USBF_WRITEEND          ; End of data write
*              : DEVDRV_USBF_WRITESHRT         ; End of short data write
*              : DEVDRV_USBF_WRITING           ; Continue of data write
*              : DEVDRV_USBF_FIFOERROR         ; FIFO access error
*******************************************************************************/
uint16_t usb1_api_function_CtrlReadStart (uint32_t size, uint8_t * data)
{
    uint16_t status;
    uint16_t mbw;

    usb1_function_set_pid_nak(USB_FUNCTION_PIPE0);

    g_usb1_function_data_count[USB_FUNCTION_PIPE0]   = size;
    g_usb1_function_data_pointer[USB_FUNCTION_PIPE0] = data;

    mbw = usb1_function_get_mbw(g_usb1_function_data_count[USB_FUNCTION_PIPE0],
                                    (uint32_t)g_usb1_function_data_pointer[USB_FUNCTION_PIPE0]);
    usb1_function_set_curpipe(USB_FUNCTION_PIPE0, USB_FUNCTION_CUSE, USB_FUNCTION_CFIFO_WRITE, mbw);
    USB201.CFIFOCTR = USB_FUNCTION_BITBCLR;

    status = usb1_function_write_buffer_c(USB_FUNCTION_PIPE0);

    /* Peripheral Control sequence */
    switch (status)
    {
        case DEVDRV_USBF_WRITESHRT:                                     /* End of data write */
        case DEVDRV_USBF_WRITEEND:                                      /* End of data write (not null) */
        case DEVDRV_USBF_WRITING:                                       /* Continue of data write */
            usb1_function_enable_bemp_int(USB_FUNCTION_PIPE0);          /* Enable Empty Interrupt */
            usb1_function_set_pid_buf(USB_FUNCTION_PIPE0);              /* Set BUF */
        break;

        case DEVDRV_USBF_FIFOERROR:                                     /* FIFO access error */
        break;

        default:
        break;
    }

    return status;                                                      /* End or Err or Continue */
}

/*******************************************************************************
* Function Name: usb1_api_function_CtrlWriteStart
* Description  : Executes the USB control write transfer.
*              : USB host controller -> USB device
* Arguments    : uint16_t  size         ; Data Size
*              : uint8_t  *data         ; Data Address
* Return Value : none
*******************************************************************************/
void usb1_api_function_CtrlWriteStart (uint32_t size, uint8_t * data)
{
    uint16_t mbw;

    usb1_function_set_pid_nak(USB_FUNCTION_PIPE0);

    g_usb1_function_data_count[USB_FUNCTION_PIPE0]   = size;
    g_usb1_function_data_pointer[USB_FUNCTION_PIPE0] = data;

    mbw = usb1_function_get_mbw(g_usb1_function_data_count[USB_FUNCTION_PIPE0],
                                    (uint32_t)g_usb1_function_data_pointer[USB_FUNCTION_PIPE0]);
    usb1_function_set_curpipe(USB_FUNCTION_PIPE0, USB_FUNCTION_CUSE, USB_FUNCTION_CFIFO_WRITE, mbw);
    USB201.CFIFOCTR = USB_FUNCTION_BITBCLR;

    usb1_function_enable_brdy_int(USB_FUNCTION_PIPE0);
    usb1_function_set_pid_buf(USB_FUNCTION_PIPE0);
}

/* End of File */