max4146x_comp

Dependencies:   MAX14690

Committer:
sdivarci
Date:
Sun Oct 25 20:10:02 2020 +0000
Revision:
0:0061165683ee
sdivarci

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sdivarci 0:0061165683ee 1 /*******************************************************************************
sdivarci 0:0061165683ee 2 * DISCLAIMER
sdivarci 0:0061165683ee 3 * This software is supplied by Renesas Electronics Corporation and is only
sdivarci 0:0061165683ee 4 * intended for use with Renesas products. No other uses are authorized. This
sdivarci 0:0061165683ee 5 * software is owned by Renesas Electronics Corporation and is protected under
sdivarci 0:0061165683ee 6 * all applicable laws, including copyright laws.
sdivarci 0:0061165683ee 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
sdivarci 0:0061165683ee 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
sdivarci 0:0061165683ee 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
sdivarci 0:0061165683ee 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
sdivarci 0:0061165683ee 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
sdivarci 0:0061165683ee 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
sdivarci 0:0061165683ee 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
sdivarci 0:0061165683ee 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
sdivarci 0:0061165683ee 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
sdivarci 0:0061165683ee 16 * Renesas reserves the right, without notice, to make changes to this software
sdivarci 0:0061165683ee 17 * and to discontinue the availability of this software. By using this software,
sdivarci 0:0061165683ee 18 * you agree to the additional terms and conditions found by accessing the
sdivarci 0:0061165683ee 19 * following link:
sdivarci 0:0061165683ee 20 * http://www.renesas.com/disclaimer
sdivarci 0:0061165683ee 21 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
sdivarci 0:0061165683ee 22 *******************************************************************************/
sdivarci 0:0061165683ee 23 /*******************************************************************************
sdivarci 0:0061165683ee 24 * File Name : usb0_function_controlrw.c
sdivarci 0:0061165683ee 25 * $Rev: 1116 $
sdivarci 0:0061165683ee 26 * $Date:: 2014-07-09 16:29:19 +0900#$
sdivarci 0:0061165683ee 27 * Device(s) : RZ/A1H
sdivarci 0:0061165683ee 28 * Tool-Chain :
sdivarci 0:0061165683ee 29 * OS : None
sdivarci 0:0061165683ee 30 * H/W Platform :
sdivarci 0:0061165683ee 31 * Description : RZ/A1H R7S72100 USB Sample Program
sdivarci 0:0061165683ee 32 * Operation :
sdivarci 0:0061165683ee 33 * Limitations :
sdivarci 0:0061165683ee 34 *******************************************************************************/
sdivarci 0:0061165683ee 35
sdivarci 0:0061165683ee 36
sdivarci 0:0061165683ee 37 /*******************************************************************************
sdivarci 0:0061165683ee 38 Includes <System Includes> , "Project Includes"
sdivarci 0:0061165683ee 39 *******************************************************************************/
sdivarci 0:0061165683ee 40 #include "usb0_function.h"
sdivarci 0:0061165683ee 41
sdivarci 0:0061165683ee 42
sdivarci 0:0061165683ee 43 /*******************************************************************************
sdivarci 0:0061165683ee 44 Typedef definitions
sdivarci 0:0061165683ee 45 *******************************************************************************/
sdivarci 0:0061165683ee 46
sdivarci 0:0061165683ee 47
sdivarci 0:0061165683ee 48 /*******************************************************************************
sdivarci 0:0061165683ee 49 Macro definitions
sdivarci 0:0061165683ee 50 *******************************************************************************/
sdivarci 0:0061165683ee 51
sdivarci 0:0061165683ee 52
sdivarci 0:0061165683ee 53 /*******************************************************************************
sdivarci 0:0061165683ee 54 Imported global variables and functions (from other files)
sdivarci 0:0061165683ee 55 *******************************************************************************/
sdivarci 0:0061165683ee 56
sdivarci 0:0061165683ee 57
sdivarci 0:0061165683ee 58 /*******************************************************************************
sdivarci 0:0061165683ee 59 Exported global variables and functions (to be accessed by other files)
sdivarci 0:0061165683ee 60 *******************************************************************************/
sdivarci 0:0061165683ee 61
sdivarci 0:0061165683ee 62
sdivarci 0:0061165683ee 63 /*******************************************************************************
sdivarci 0:0061165683ee 64 Private global variables and functions
sdivarci 0:0061165683ee 65 *******************************************************************************/
sdivarci 0:0061165683ee 66
sdivarci 0:0061165683ee 67
sdivarci 0:0061165683ee 68 /*******************************************************************************
sdivarci 0:0061165683ee 69 * Function Name: usb0_api_function_CtrlReadStart
sdivarci 0:0061165683ee 70 * Description : Executes the USB control read transfer.
sdivarci 0:0061165683ee 71 * : USB host controller <- USB device
sdivarci 0:0061165683ee 72 * Arguments : uint16_t size ; Data Size
sdivarci 0:0061165683ee 73 * : uint8_t *data ; Data Address
sdivarci 0:0061165683ee 74 * Return Value : DEVDRV_USBF_WRITEEND ; End of data write
sdivarci 0:0061165683ee 75 * : DEVDRV_USBF_WRITESHRT ; End of short data write
sdivarci 0:0061165683ee 76 * : DEVDRV_USBF_WRITING ; Continue of data write
sdivarci 0:0061165683ee 77 * : DEVDRV_USBF_FIFOERROR ; FIFO access error
sdivarci 0:0061165683ee 78 *******************************************************************************/
sdivarci 0:0061165683ee 79 uint16_t usb0_api_function_CtrlReadStart (uint32_t size, uint8_t * data)
sdivarci 0:0061165683ee 80 {
sdivarci 0:0061165683ee 81 uint16_t status;
sdivarci 0:0061165683ee 82 uint16_t mbw;
sdivarci 0:0061165683ee 83
sdivarci 0:0061165683ee 84 usb0_function_set_pid_nak(USB_FUNCTION_PIPE0);
sdivarci 0:0061165683ee 85
sdivarci 0:0061165683ee 86 g_usb0_function_data_count[USB_FUNCTION_PIPE0] = size;
sdivarci 0:0061165683ee 87 g_usb0_function_data_pointer[USB_FUNCTION_PIPE0] = data;
sdivarci 0:0061165683ee 88
sdivarci 0:0061165683ee 89 mbw = usb0_function_get_mbw(g_usb0_function_data_count[USB_FUNCTION_PIPE0],
sdivarci 0:0061165683ee 90 (uint32_t)g_usb0_function_data_pointer[USB_FUNCTION_PIPE0]);
sdivarci 0:0061165683ee 91 usb0_function_set_curpipe(USB_FUNCTION_PIPE0, USB_FUNCTION_CUSE, USB_FUNCTION_CFIFO_WRITE, mbw);
sdivarci 0:0061165683ee 92 USB200.CFIFOCTR = USB_FUNCTION_BITBCLR;
sdivarci 0:0061165683ee 93
sdivarci 0:0061165683ee 94 status = usb0_function_write_buffer_c(USB_FUNCTION_PIPE0);
sdivarci 0:0061165683ee 95
sdivarci 0:0061165683ee 96 /* Peripheral Control sequence */
sdivarci 0:0061165683ee 97 switch (status)
sdivarci 0:0061165683ee 98 {
sdivarci 0:0061165683ee 99 case DEVDRV_USBF_WRITESHRT: /* End of data write */
sdivarci 0:0061165683ee 100 case DEVDRV_USBF_WRITEEND: /* End of data write (not null) */
sdivarci 0:0061165683ee 101 case DEVDRV_USBF_WRITING: /* Continue of data write */
sdivarci 0:0061165683ee 102 usb0_function_enable_bemp_int(USB_FUNCTION_PIPE0); /* Enable Empty Interrupt */
sdivarci 0:0061165683ee 103 usb0_function_set_pid_buf(USB_FUNCTION_PIPE0); /* Set BUF */
sdivarci 0:0061165683ee 104 break;
sdivarci 0:0061165683ee 105
sdivarci 0:0061165683ee 106 case DEVDRV_USBF_FIFOERROR: /* FIFO access error */
sdivarci 0:0061165683ee 107 break;
sdivarci 0:0061165683ee 108
sdivarci 0:0061165683ee 109 default:
sdivarci 0:0061165683ee 110 break;
sdivarci 0:0061165683ee 111 }
sdivarci 0:0061165683ee 112
sdivarci 0:0061165683ee 113 return status; /* End or Err or Continue */
sdivarci 0:0061165683ee 114 }
sdivarci 0:0061165683ee 115
sdivarci 0:0061165683ee 116 /*******************************************************************************
sdivarci 0:0061165683ee 117 * Function Name: usb0_api_function_CtrlWriteStart
sdivarci 0:0061165683ee 118 * Description : Executes the USB control write transfer.
sdivarci 0:0061165683ee 119 * : USB host controller -> USB device
sdivarci 0:0061165683ee 120 * Arguments : uint16_t size ; Data Size
sdivarci 0:0061165683ee 121 * : uint8_t *data ; Data Address
sdivarci 0:0061165683ee 122 * Return Value : none
sdivarci 0:0061165683ee 123 *******************************************************************************/
sdivarci 0:0061165683ee 124 void usb0_api_function_CtrlWriteStart (uint32_t size, uint8_t * data)
sdivarci 0:0061165683ee 125 {
sdivarci 0:0061165683ee 126 uint16_t mbw;
sdivarci 0:0061165683ee 127
sdivarci 0:0061165683ee 128 usb0_function_set_pid_nak(USB_FUNCTION_PIPE0);
sdivarci 0:0061165683ee 129
sdivarci 0:0061165683ee 130 g_usb0_function_data_count[USB_FUNCTION_PIPE0] = size;
sdivarci 0:0061165683ee 131 g_usb0_function_data_pointer[USB_FUNCTION_PIPE0] = data;
sdivarci 0:0061165683ee 132
sdivarci 0:0061165683ee 133 mbw = usb0_function_get_mbw(g_usb0_function_data_count[USB_FUNCTION_PIPE0],
sdivarci 0:0061165683ee 134 (uint32_t)g_usb0_function_data_pointer[USB_FUNCTION_PIPE0]);
sdivarci 0:0061165683ee 135 usb0_function_set_curpipe(USB_FUNCTION_PIPE0, USB_FUNCTION_CUSE, USB_FUNCTION_CFIFO_WRITE, mbw);
sdivarci 0:0061165683ee 136 USB200.CFIFOCTR = USB_FUNCTION_BITBCLR;
sdivarci 0:0061165683ee 137
sdivarci 0:0061165683ee 138 usb0_function_enable_brdy_int(USB_FUNCTION_PIPE0);
sdivarci 0:0061165683ee 139 usb0_function_set_pid_buf(USB_FUNCTION_PIPE0);
sdivarci 0:0061165683ee 140 }
sdivarci 0:0061165683ee 141
sdivarci 0:0061165683ee 142 /* End of File */