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_intrn.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_function_brdy_int
sdivarci 0:0061165683ee 70 * Description : Executes BRDY interrupt(USB_FUNCTION_PIPE1-9).
sdivarci 0:0061165683ee 71 * : According to the pipe that interrupt is generated in,
sdivarci 0:0061165683ee 72 * : reads/writes buffer allocated in the pipe.
sdivarci 0:0061165683ee 73 * : This function is executed in the BRDY interrupt handler.
sdivarci 0:0061165683ee 74 * : This function clears BRDY interrupt status and BEMP interrupt
sdivarci 0:0061165683ee 75 * : status.
sdivarci 0:0061165683ee 76 * Arguments : uint16_t Status ; BRDYSTS Register Value
sdivarci 0:0061165683ee 77 * : uint16_t Int_enbl ; BRDYENB Register Value
sdivarci 0:0061165683ee 78 * Return Value : none
sdivarci 0:0061165683ee 79 *******************************************************************************/
sdivarci 0:0061165683ee 80 #if 0
sdivarci 0:0061165683ee 81 void usb0_function_brdy_int (uint16_t status, uint16_t int_enb)
sdivarci 0:0061165683ee 82 {
sdivarci 0:0061165683ee 83 uint32_t int_sense = 0;
sdivarci 0:0061165683ee 84 uint16_t pipe;
sdivarci 0:0061165683ee 85 uint16_t pipebit;
sdivarci 0:0061165683ee 86
sdivarci 0:0061165683ee 87 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
sdivarci 0:0061165683ee 88 {
sdivarci 0:0061165683ee 89 pipebit = g_usb0_function_bit_set[pipe];
sdivarci 0:0061165683ee 90
sdivarci 0:0061165683ee 91 if ((status & pipebit) && (int_enb & pipebit))
sdivarci 0:0061165683ee 92 {
sdivarci 0:0061165683ee 93 USB200.BRDYSTS = (uint16_t)~pipebit;
sdivarci 0:0061165683ee 94 USB200.BEMPSTS = (uint16_t)~pipebit;
sdivarci 0:0061165683ee 95 if ((g_usb0_function_PipeTbl[pipe] & USB_FUNCTION_FIFO_USE) == USB_FUNCTION_D0FIFO_DMA)
sdivarci 0:0061165683ee 96 {
sdivarci 0:0061165683ee 97 if (g_usb0_function_DmaStatus[USB_FUNCTION_D0FIFO] != USB_FUNCTION_DMA_READY)
sdivarci 0:0061165683ee 98 {
sdivarci 0:0061165683ee 99 usb0_function_dma_interrupt_d0fifo(int_sense);
sdivarci 0:0061165683ee 100 }
sdivarci 0:0061165683ee 101
sdivarci 0:0061165683ee 102 if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
sdivarci 0:0061165683ee 103 {
sdivarci 0:0061165683ee 104 usb0_function_read_dma(pipe);
sdivarci 0:0061165683ee 105 usb0_function_disable_brdy_int(pipe);
sdivarci 0:0061165683ee 106 }
sdivarci 0:0061165683ee 107 else
sdivarci 0:0061165683ee 108 {
sdivarci 0:0061165683ee 109 USB200.D0FIFOCTR = USB_FUNCTION_BITBCLR;
sdivarci 0:0061165683ee 110 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
sdivarci 0:0061165683ee 111 }
sdivarci 0:0061165683ee 112 }
sdivarci 0:0061165683ee 113 else if ((g_usb0_function_PipeTbl[pipe] & USB_FUNCTION_FIFO_USE) == USB_FUNCTION_D1FIFO_DMA)
sdivarci 0:0061165683ee 114 {
sdivarci 0:0061165683ee 115 if (g_usb0_function_DmaStatus[USB_FUNCTION_D1FIFO] != USB_FUNCTION_DMA_READY)
sdivarci 0:0061165683ee 116 {
sdivarci 0:0061165683ee 117 usb0_function_dma_interrupt_d1fifo(int_sense);
sdivarci 0:0061165683ee 118 }
sdivarci 0:0061165683ee 119
sdivarci 0:0061165683ee 120 if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
sdivarci 0:0061165683ee 121 {
sdivarci 0:0061165683ee 122 usb0_function_read_dma(pipe);
sdivarci 0:0061165683ee 123 usb0_function_disable_brdy_int(pipe);
sdivarci 0:0061165683ee 124 }
sdivarci 0:0061165683ee 125 else
sdivarci 0:0061165683ee 126 {
sdivarci 0:0061165683ee 127 USB200.D1FIFOCTR = USB_FUNCTION_BITBCLR;
sdivarci 0:0061165683ee 128 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
sdivarci 0:0061165683ee 129 }
sdivarci 0:0061165683ee 130 }
sdivarci 0:0061165683ee 131 else
sdivarci 0:0061165683ee 132 {
sdivarci 0:0061165683ee 133 if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_DIR_SHIFT, USB_PIPECFG_DIR) == 0)
sdivarci 0:0061165683ee 134 {
sdivarci 0:0061165683ee 135 usb0_function_read_buffer(pipe);
sdivarci 0:0061165683ee 136 }
sdivarci 0:0061165683ee 137 else
sdivarci 0:0061165683ee 138 {
sdivarci 0:0061165683ee 139 usb0_function_write_buffer(pipe);
sdivarci 0:0061165683ee 140 }
sdivarci 0:0061165683ee 141 }
sdivarci 0:0061165683ee 142 }
sdivarci 0:0061165683ee 143 }
sdivarci 0:0061165683ee 144 }
sdivarci 0:0061165683ee 145 #endif
sdivarci 0:0061165683ee 146
sdivarci 0:0061165683ee 147 /*******************************************************************************
sdivarci 0:0061165683ee 148 * Function Name: usb0_function_nrdy_int
sdivarci 0:0061165683ee 149 * Description : Executes NRDY interrupt(USB_FUNCTION_PIPE1-9).
sdivarci 0:0061165683ee 150 * : Checks NRDY interrupt cause by PID. When the cause if STALL,
sdivarci 0:0061165683ee 151 * : regards the pipe state as STALL and ends the processing.
sdivarci 0:0061165683ee 152 * : Then the cause is not STALL, increments the error count to
sdivarci 0:0061165683ee 153 * : communicate again. When the error count is 3, determines
sdivarci 0:0061165683ee 154 * : the pipe state as DEVDRV_USBF_PIPE_NORES and ends the processing.
sdivarci 0:0061165683ee 155 * : This function is executed in the NRDY interrupt handler.
sdivarci 0:0061165683ee 156 * : This function clears NRDY interrupt status.
sdivarci 0:0061165683ee 157 * Arguments : uint16_t status ; NRDYSTS Register Value
sdivarci 0:0061165683ee 158 * : uint16_t int_enb ; NRDYENB Register Value
sdivarci 0:0061165683ee 159 * Return Value : none
sdivarci 0:0061165683ee 160 *******************************************************************************/
sdivarci 0:0061165683ee 161 void usb0_function_nrdy_int (uint16_t status, uint16_t int_enb)
sdivarci 0:0061165683ee 162 {
sdivarci 0:0061165683ee 163 uint16_t pid;
sdivarci 0:0061165683ee 164 uint16_t pipe;
sdivarci 0:0061165683ee 165 uint16_t bitcheck;
sdivarci 0:0061165683ee 166
sdivarci 0:0061165683ee 167 bitcheck = (uint16_t)(status & int_enb);
sdivarci 0:0061165683ee 168
sdivarci 0:0061165683ee 169 USB200.NRDYSTS = (uint16_t)~status;
sdivarci 0:0061165683ee 170
sdivarci 0:0061165683ee 171 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
sdivarci 0:0061165683ee 172 {
sdivarci 0:0061165683ee 173 if ((bitcheck&g_usb0_function_bit_set[pipe]) == g_usb0_function_bit_set[pipe])
sdivarci 0:0061165683ee 174 {
sdivarci 0:0061165683ee 175 if (RZA_IO_RegRead_16(&USB200.SYSCFG0, USB_SYSCFG_DCFM_SHIFT, USB_SYSCFG_DCFM) == 1)
sdivarci 0:0061165683ee 176 {
sdivarci 0:0061165683ee 177 if (g_usb0_function_pipe_status[pipe] == DEVDRV_USBF_PIPE_WAIT)
sdivarci 0:0061165683ee 178 {
sdivarci 0:0061165683ee 179 pid = usb0_function_get_pid(pipe);
sdivarci 0:0061165683ee 180 if ((pid == DEVDRV_USBF_PID_STALL) || (pid == DEVDRV_USBF_PID_STALL2))
sdivarci 0:0061165683ee 181 {
sdivarci 0:0061165683ee 182 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_STALL;
sdivarci 0:0061165683ee 183 }
sdivarci 0:0061165683ee 184 else
sdivarci 0:0061165683ee 185 {
sdivarci 0:0061165683ee 186 g_usb0_function_PipeIgnore[pipe]++;
sdivarci 0:0061165683ee 187 if (g_usb0_function_PipeIgnore[pipe] == 3)
sdivarci 0:0061165683ee 188 {
sdivarci 0:0061165683ee 189 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_NORES;
sdivarci 0:0061165683ee 190 }
sdivarci 0:0061165683ee 191 else
sdivarci 0:0061165683ee 192 {
sdivarci 0:0061165683ee 193 usb0_function_set_pid_buf(pipe);
sdivarci 0:0061165683ee 194 }
sdivarci 0:0061165683ee 195 }
sdivarci 0:0061165683ee 196 }
sdivarci 0:0061165683ee 197 }
sdivarci 0:0061165683ee 198 else
sdivarci 0:0061165683ee 199 {
sdivarci 0:0061165683ee 200 /* USB Function */
sdivarci 0:0061165683ee 201 }
sdivarci 0:0061165683ee 202 }
sdivarci 0:0061165683ee 203 }
sdivarci 0:0061165683ee 204 }
sdivarci 0:0061165683ee 205
sdivarci 0:0061165683ee 206 /*******************************************************************************
sdivarci 0:0061165683ee 207 * Function Name: usb0_function_bemp_int
sdivarci 0:0061165683ee 208 * Description : Executes BEMP interrupt(USB_FUNCTION_PIPE1-9).
sdivarci 0:0061165683ee 209 * Arguments : uint16_t status ; BEMPSTS Register Value
sdivarci 0:0061165683ee 210 * : uint16_t int_enb ; BEMPENB Register Value
sdivarci 0:0061165683ee 211 * Return Value : none
sdivarci 0:0061165683ee 212 *******************************************************************************/
sdivarci 0:0061165683ee 213 void usb0_function_bemp_int (uint16_t status, uint16_t int_enb)
sdivarci 0:0061165683ee 214 {
sdivarci 0:0061165683ee 215 uint16_t pid;
sdivarci 0:0061165683ee 216 uint16_t pipe;
sdivarci 0:0061165683ee 217 uint16_t bitcheck;
sdivarci 0:0061165683ee 218 uint16_t inbuf;
sdivarci 0:0061165683ee 219
sdivarci 0:0061165683ee 220 bitcheck = (uint16_t)(status & int_enb);
sdivarci 0:0061165683ee 221
sdivarci 0:0061165683ee 222 USB200.BEMPSTS = (uint16_t)~status;
sdivarci 0:0061165683ee 223
sdivarci 0:0061165683ee 224 for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
sdivarci 0:0061165683ee 225 {
sdivarci 0:0061165683ee 226 if ((bitcheck&g_usb0_function_bit_set[pipe]) == g_usb0_function_bit_set[pipe])
sdivarci 0:0061165683ee 227 {
sdivarci 0:0061165683ee 228 pid = usb0_function_get_pid(pipe);
sdivarci 0:0061165683ee 229
sdivarci 0:0061165683ee 230 if ((pid == DEVDRV_USBF_PID_STALL) || (pid == DEVDRV_USBF_PID_STALL2))
sdivarci 0:0061165683ee 231 {
sdivarci 0:0061165683ee 232 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_STALL;
sdivarci 0:0061165683ee 233 }
sdivarci 0:0061165683ee 234 else
sdivarci 0:0061165683ee 235 {
sdivarci 0:0061165683ee 236 inbuf = usb0_function_get_inbuf(pipe);
sdivarci 0:0061165683ee 237
sdivarci 0:0061165683ee 238 if (inbuf == 0)
sdivarci 0:0061165683ee 239 {
sdivarci 0:0061165683ee 240 usb0_function_disable_bemp_int(pipe);
sdivarci 0:0061165683ee 241 usb0_function_set_pid_nak(pipe);
sdivarci 0:0061165683ee 242 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
sdivarci 0:0061165683ee 243 }
sdivarci 0:0061165683ee 244 }
sdivarci 0:0061165683ee 245 }
sdivarci 0:0061165683ee 246 }
sdivarci 0:0061165683ee 247 }
sdivarci 0:0061165683ee 248
sdivarci 0:0061165683ee 249 /* End of File */