123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- /*******************************************************************************
- * 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_sub.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)
- *******************************************************************************/
- #if 0
- extern const uint16_t *g_usb1_function_EndPntPtr[];
- extern uint8_t g_usb1_function_DeviceDescriptor[];
- extern uint8_t *g_usb1_function_ConfigurationPtr[];
- #endif
-
-
- /*******************************************************************************
- Exported global variables and functions (to be accessed by other files)
- *******************************************************************************/
-
-
- /*******************************************************************************
- Private global variables and functions
- *******************************************************************************/
-
-
- /*******************************************************************************
- * Function Name: usb1_function_ResetDCP
- * Description : Initializes the default control pipe(DCP).
- * Outline : Reset default control pipe
- * Arguments : none
- * Return Value : none
- *******************************************************************************/
- void usb1_function_ResetDCP (void)
- {
- USB201.DCPCFG = 0;
- #if 0
- USB201.DCPMAXP = g_usb1_function_DeviceDescriptor[7];
- #else
- USB201.DCPMAXP = 64;
- #endif
-
- USB201.CFIFOSEL = (uint16_t)(USB_FUNCTION_BITMBW_8 | USB_FUNCTION_BITBYTE_LITTLE);
- USB201.D0FIFOSEL = (uint16_t)(USB_FUNCTION_BITMBW_8 | USB_FUNCTION_BITBYTE_LITTLE);
- USB201.D1FIFOSEL = (uint16_t)(USB_FUNCTION_BITMBW_8 | USB_FUNCTION_BITBYTE_LITTLE);
- }
-
- /*******************************************************************************
- * Function Name: usb1_function_ResetEP
- * Description : Initializes the end point.
- * Arguments : uint16_t num ; Configuration Number
- * Return Value : none
- *******************************************************************************/
- #if 0
- void usb1_function_ResetEP (uint16_t num)
- {
- uint16_t pipe;
- uint16_t ep;
- uint16_t index;
- uint16_t buf;
- uint16_t * tbl;
-
- tbl = (uint16_t *)(g_usb1_function_EndPntPtr[num - 1]);
-
- for (ep = 1; ep <= USB_FUNCTION_MAX_EP_NO; ++ep)
- {
- if (g_usb1_function_EPTableIndex[ep] != USB_FUNCTION_EP_ERROR)
- {
- index = (uint16_t)(USB_FUNCTION_EPTABLE_LENGTH * g_usb1_function_EPTableIndex[ep]);
- pipe = (uint16_t)(tbl[index + 0] & USB_FUNCTION_BITCURPIPE);
-
- g_usb1_function_PipeTbl[pipe] = (uint16_t)(((tbl[index + 1] & USB_FUNCTION_DIRFIELD) << 3) |
- ep |
- (tbl[index + 0] & USB_FUNCTION_FIFO_USE));
-
- if ((tbl[index + 1] & USB_FUNCTION_DIRFIELD) == USB_FUNCTION_DIR_P_OUT)
- {
- tbl[index + 1] |= USB_FUNCTION_SHTNAKON;
- #ifdef __USB_DMA_BFRE_ENABLE__
- /* this routine cannnot be perfomred if read operation is executed in buffer size */
- if (((tbl[index + 0] & USB_FUNCTION_FIFO_USE) == USB_FUNCTION_D0FIFO_DMA) ||
- ((tbl[index + 0] & USB_FUNCTION_FIFO_USE) == USB_FUNCTION_D1FIFO_DMA))
- {
- tbl[index + 1] |= USB_FUNCTION_BFREON;
- }
- #endif
- }
-
- /* Interrupt Disable */
- buf = USB201.BRDYENB;
- buf &= (uint16_t)~g_usb1_function_bit_set[pipe];
- USB201.BRDYENB = buf;
- buf = USB201.NRDYENB;
- buf &= (uint16_t)~g_usb1_function_bit_set[pipe];
- USB201.NRDYENB = buf;
- buf = USB201.BEMPENB;
- buf &= (uint16_t)~g_usb1_function_bit_set[pipe];
- USB201.BEMPENB = buf;
-
- usb1_function_set_pid_nak(pipe);
-
- /* CurrentPIPE Clear */
- if (RZA_IO_RegRead_16(&USB201.CFIFOSEL,
- USB_CFIFOSEL_CURPIPE_SHIFT,
- USB_CFIFOSEL_CURPIPE) == pipe)
- {
- RZA_IO_RegWrite_16(&USB201.CFIFOSEL,
- 0,
- USB_CFIFOSEL_CURPIPE_SHIFT,
- USB_CFIFOSEL_CURPIPE);
- }
-
- if (RZA_IO_RegRead_16(&USB201.D0FIFOSEL,
- USB_DnFIFOSEL_CURPIPE_SHIFT,
- USB_DnFIFOSEL_CURPIPE) == pipe)
- {
- RZA_IO_RegWrite_16(&USB201.D0FIFOSEL,
- 0,
- USB_DnFIFOSEL_CURPIPE_SHIFT,
- USB_DnFIFOSEL_CURPIPE);
- }
-
- if (RZA_IO_RegRead_16(&USB201.D1FIFOSEL,
- USB_DnFIFOSEL_CURPIPE_SHIFT,
- USB_DnFIFOSEL_CURPIPE) == pipe)
- {
- RZA_IO_RegWrite_16(&USB201.D1FIFOSEL,
- 0,
- USB_DnFIFOSEL_CURPIPE_SHIFT,
- USB_DnFIFOSEL_CURPIPE);
- }
-
- /* PIPE Configuration */
- USB201.PIPESEL = pipe;
- USB201.PIPECFG = tbl[index + 1];
- USB201.PIPEBUF = tbl[index + 2];
- USB201.PIPEMAXP = tbl[index + 3];
- USB201.PIPEPERI = tbl[index + 4];
-
- g_usb1_function_pipecfg[pipe] = tbl[index + 1];
- g_usb1_function_pipebuf[pipe] = tbl[index + 2];
- g_usb1_function_pipemaxp[pipe] = tbl[index + 3];
- g_usb1_function_pipeperi[pipe] = tbl[index + 4];
-
- /* Buffer Clear */
- usb1_function_set_sqclr(pipe);
- usb1_function_aclrm(pipe);
-
- /* init Global */
- g_usb1_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_IDLE;
- g_usb1_function_PipeDataSize[pipe] = 0;
- }
- }
- }
- #endif
-
- /*******************************************************************************
- * Function Name: usb1_function_EpToPipe
- * Description : Returns the pipe which end point specified by the argument is
- * : allocated to.
- * Arguments : uint16_t ep ; Direction + Endpoint Number
- * Return Value : USB_FUNCTION_EP_ERROR : Error
- * : Others : Pipe Number
- *******************************************************************************/
- uint16_t usb1_function_EpToPipe (uint16_t ep)
- {
- uint16_t pipe;
-
- for (pipe = 1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
- {
- if ((g_usb1_function_PipeTbl[pipe] & 0x00ff) == ep)
- {
- return pipe;
- }
- }
-
- return USB_FUNCTION_EP_ERROR;
- }
-
- /*******************************************************************************
- * Function Name: usb1_function_InitEPTable
- * Description : Sets the end point by the Alternate setting value of the
- * : configuration number and the interface number specified by the
- * : argument.
- * Arguments : uint16_t Con_Num ; Configuration Number
- * : uint16_t Int_Num ; Interface Number
- * : uint16_t Alt_Num ; Alternate Setting
- * Return Value : none
- *******************************************************************************/
- #if 0
- void usb1_function_InitEPTable (uint16_t Con_Num, uint16_t Int_Num, uint16_t Alt_Num)
- {
- uint8_t * ptr;
- uint16_t point_interface;
- uint16_t point_endpoint;
- uint16_t length;
- uint16_t start;
- uint16_t numbers;
- uint16_t endpoint;
-
- ptr = (uint8_t *)g_usb1_function_ConfigurationPtr[Con_Num - 1];
- point_interface = *ptr;
- length = (uint16_t)((uint16_t)*(ptr + 3) << 8 | (uint16_t)*(ptr + 2));
- ptr += *ptr;
- start = 0;
- numbers = 0;
- point_endpoint = 0;
-
- for (; point_interface < length;)
- {
- switch (*(ptr + 1)) /* Descriptor Type ? */
- {
- case USB_FUNCTION_DT_INTERFACE: /* Interface */
- if ((*(ptr + 2) == Int_Num) && (*(ptr + 3) == Alt_Num))
- {
- numbers = *(ptr + 4);
- }
- else
- {
- start += *(ptr + 4);
- }
- point_interface += *ptr;
- ptr += *ptr;
- break;
-
- case USB_FUNCTION_DT_ENDPOINT: /* Endpoint */
- if (point_endpoint < numbers)
- {
- endpoint = (uint16_t)(*(ptr + 2) & 0x0f);
- g_usb1_function_EPTableIndex[endpoint] = (uint16_t)(start + point_endpoint);
- ++point_endpoint;
- }
- point_interface += *ptr;
- ptr += *ptr;
- break;
-
- case USB_FUNCTION_DT_DEVICE: /* Device */
- case USB_FUNCTION_DT_CONFIGURATION: /* Configuration */
- case USB_FUNCTION_DT_STRING: /* String */
- default: /* Class, Vendor, else */
- point_interface += *ptr;
- ptr += *ptr;
- break;
- }
- }
- }
- #endif
-
- /*******************************************************************************
- * Function Name: usb1_function_GetConfigNum
- * Description : Returns the number of configuration referring to the number of
- * : configuration described in the device descriptor.
- * Arguments : none
- * Return Value : Number of possible configurations (bNumConfigurations).
- *******************************************************************************/
- #if 0
- uint16_t usb1_function_GetConfigNum (void)
- {
- return (uint16_t)g_usb1_function_DeviceDescriptor[17];
- }
- #endif
-
- /*******************************************************************************
- * Function Name: usb1_function_GetInterfaceNum
- * Description : Returns the number of interface referring to the number of
- * : interface described in the configuration descriptor.
- * Arguments : uint16_t num ; Configuration Number
- * Return Value : Number of this interface (bNumInterfaces).
- *******************************************************************************/
- #if 0
- uint16_t usb1_function_GetInterfaceNum (uint16_t num)
- {
- return (uint16_t)(*(g_usb1_function_ConfigurationPtr[num - 1] + 4));
- }
- #endif
-
- /*******************************************************************************
- * Function Name: usb1_function_GetAltNum
- * Description : Returns the Alternate setting value of the configuration number
- * : and the interface number specified by the argument.
- * Arguments : uint16_t Con_Num ; Configuration Number
- * : uint16_t Int_Num ; Interface Number
- * Return Value : Value used to select this alternate setting(bAlternateSetting).
- *******************************************************************************/
- #if 0
- uint16_t usb1_function_GetAltNum (uint16_t Con_Num, uint16_t Int_Num)
- {
- uint8_t * ptr;
- uint16_t point;
- uint16_t alt_num = 0;
- uint16_t length;
-
- ptr = (uint8_t *)(g_usb1_function_ConfigurationPtr[Con_Num - 1]);
- point = ptr[0];
- ptr += ptr[0]; /* InterfaceDescriptor[0] */
- length = (uint16_t)(*(g_usb1_function_ConfigurationPtr[Con_Num - 1] + 2));
- length |= (uint16_t)((uint16_t)(*(g_usb1_function_ConfigurationPtr[Con_Num - 1] + 3)) << 8);
-
- for (; point < length;) /* Search Descriptor Table size */
- {
- switch (ptr[1]) /* Descriptor Type ? */
- {
- case USB_FUNCTION_DT_INTERFACE: /* Interface */
- if (Int_Num == ptr[2])
- {
- alt_num = (uint16_t)ptr[3]; /* Alternate Number count */
- }
- point += ptr[0];
- ptr += ptr[0];
- break;
-
- case USB_FUNCTION_DT_DEVICE: /* Device */
- case USB_FUNCTION_DT_CONFIGURATION: /* Configuration */
- case USB_FUNCTION_DT_STRING: /* String */
- case USB_FUNCTION_DT_ENDPOINT: /* Endpoint */
- default: /* Class, Vendor, else */
- point += ptr[0];
- ptr += ptr[0];
- break;
- }
- }
- return alt_num;
- }
- #endif
-
- /*******************************************************************************
- * Function Name: usb1_function_CheckRemoteWakeup
- * Description : Returns the result of the remote wake up function is supported
- * : or not referring to the configuration descriptor.
- * Arguments : none
- * Return Value : DEVDRV_USBF_ON : Support Remote Wakeup
- * : DEVDRV_USBF_OFF : not Support Remote Wakeup
- *******************************************************************************/
- #if 0
- uint16_t usb1_function_CheckRemoteWakeup (void)
- {
- uint8_t atr;
-
- if (g_usb1_function_ConfigNum == 0)
- {
- return DEVDRV_USBF_OFF;
- }
-
- atr = *(g_usb1_function_ConfigurationPtr[g_usb1_function_ConfigNum - 1] + 7);
-
- if (atr & USB_FUNCTION_CF_RWUP)
- {
- return DEVDRV_USBF_ON;
- }
-
- return DEVDRV_USBF_OFF;
- }
- #endif
-
- /*******************************************************************************
- * Function Name: usb1_function_clear_alt
- * Description : Initializes the Alternate setting area.
- * Arguments : none
- * Return Value : none
- *******************************************************************************/
- #if 0
- void usb1_function_clear_alt (void)
- {
- int i;
-
- for (i = 0; i < USB_FUNCTION_ALT_NO; ++i)
- {
- g_usb1_function_Alternate[i] = 0; /* Alternate */
- }
- }
- #endif
-
- /*******************************************************************************
- * Function Name: usb1_function_clear_pipe_tbl
- * Description : Initializes pipe definition table.
- * Arguments : none
- * Return Value : none
- *******************************************************************************/
- void usb1_function_clear_pipe_tbl (void)
- {
- int pipe;
-
- for (pipe = 0; pipe < (USB_FUNCTION_MAX_PIPE_NO + 1); ++pipe)
- {
- g_usb1_function_PipeTbl[pipe] = 0;
- }
- }
-
- /*******************************************************************************
- * Function Name: usb1_function_clear_ep_table_index
- * Description : Initializes the end point table index.
- * Arguments : none
- * Return Value : none
- *******************************************************************************/
- #if 0
- void usb1_function_clear_ep_table_index (void)
- {
- int ep;
-
- for (ep = 0; ep <= USB_FUNCTION_MAX_EP_NO; ++ep)
- {
- g_usb1_function_EPTableIndex[ep] = USB_FUNCTION_EP_ERROR;
- }
- }
- #endif
-
- /* End of File */
|