1 /*******************************************************************************
3 * This software is supplied by Renesas Electronics Corporation and is only
4 * intended for use with Renesas products. No other uses are authorized. This
5 * software is owned by Renesas Electronics Corporation and is protected under
6 * all applicable laws, including copyright laws.
7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
16 * Renesas reserves the right, without notice, to make changes to this software
17 * and to discontinue the availability of this software. By using this software,
18 * you agree to the additional terms and conditions found by accessing the
20 * http://www.renesas.com/disclaimer
21 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
22 *******************************************************************************/
23 /*******************************************************************************
24 * File Name : usb1_host_intrn.c
26 * $Date:: 2014-07-09 16:29:19 +0900#$
31 * Description : RZ/A1H R7S72100 USB Sample Program
34 *******************************************************************************/
37 /*******************************************************************************
38 Includes <System Includes> , "Project Includes"
39 *******************************************************************************/
40 #include "usb1_host.h"
41 #if(1) /* ohci_wrapp */
42 #include "ohci_wrapp_RZ_A1_local.h"
46 /*******************************************************************************
48 *******************************************************************************/
51 /*******************************************************************************
53 *******************************************************************************/
56 /*******************************************************************************
57 Imported global variables and functions (from other files)
58 *******************************************************************************/
61 /*******************************************************************************
62 Exported global variables and functions (to be accessed by other files)
63 *******************************************************************************/
66 /*******************************************************************************
67 Private global variables and functions
68 *******************************************************************************/
71 /*******************************************************************************
72 * Function Name: usb1_host_brdy_int
73 * Description : Executes BRDY interrupt(USB_HOST_PIPE1-9).
74 * : According to the pipe that interrupt is generated in,
75 * : reads/writes buffer allocated in the pipe.
76 * : This function is executed in the BRDY interrupt handler.
77 * : This function clears BRDY interrupt status and BEMP interrupt
79 * Arguments : uint16_t status ; BRDYSTS Register Value
80 * : uint16_t int_enb ; BRDYENB Register Value
82 *******************************************************************************/
83 void usb1_host_brdy_int (uint16_t status
, uint16_t int_enb
)
85 uint32_t int_sense
= 0;
89 for (pipe
= USB_HOST_PIPE1
; pipe
<= USB_HOST_MAX_PIPE_NO
; pipe
++)
91 pipebit
= g_usb1_host_bit_set
[pipe
];
93 if ((status
& pipebit
) && (int_enb
& pipebit
))
95 USB201
.BRDYSTS
= (uint16_t)~pipebit
;
96 USB201
.BEMPSTS
= (uint16_t)~pipebit
;
98 if ((g_usb1_host_PipeTbl
[pipe
] & USB_HOST_FIFO_USE
) == USB_HOST_D0FIFO_DMA
)
100 if (g_usb1_host_DmaStatus
[USB_HOST_D0FIFO
] != USB_HOST_DMA_READY
)
102 usb1_host_dma_interrupt_d0fifo(int_sense
);
105 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg
[pipe
], USB_PIPECFG_BFRE_SHIFT
, USB_PIPECFG_BFRE
) == 0)
107 usb1_host_read_dma(pipe
);
108 usb1_host_disable_brdy_int(pipe
);
112 USB201
.D0FIFOCTR
= USB_HOST_BITBCLR
;
113 g_usb1_host_pipe_status
[pipe
] = USB_HOST_PIPE_DONE
;
116 else if ((g_usb1_host_PipeTbl
[pipe
] & USB_HOST_FIFO_USE
) == USB_HOST_D1FIFO_DMA
)
118 if (g_usb1_host_DmaStatus
[USB_HOST_D1FIFO
] != USB_HOST_DMA_READY
)
120 usb1_host_dma_interrupt_d1fifo(int_sense
);
123 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg
[pipe
], USB_PIPECFG_BFRE_SHIFT
, USB_PIPECFG_BFRE
) == 0)
125 usb1_host_read_dma(pipe
);
126 usb1_host_disable_brdy_int(pipe
);
130 USB201
.D1FIFOCTR
= USB_HOST_BITBCLR
;
131 g_usb1_host_pipe_status
[pipe
] = USB_HOST_PIPE_DONE
;
136 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg
[pipe
], USB_PIPECFG_DIR_SHIFT
, USB_PIPECFG_DIR
) == 0)
138 usb1_host_read_buffer(pipe
);
142 usb1_host_write_buffer(pipe
);
145 #if(1) /* ohci_wrapp */
146 switch (g_usb1_host_pipe_status
[pipe
])
148 case USB_HOST_PIPE_DONE
:
149 ohciwrapp_loc_TransEnd(pipe
, TD_CC_NOERROR
);
151 case USB_HOST_PIPE_NORES
:
152 case USB_HOST_PIPE_STALL
:
153 case USB_HOST_PIPE_ERROR
:
154 ohciwrapp_loc_TransEnd(pipe
, TD_CC_STALL
);
165 /*******************************************************************************
166 * Function Name: usb1_host_nrdy_int
167 * Description : Executes NRDY interrupt(USB_HOST_PIPE1-9).
168 * : Checks NRDY interrupt cause by PID. When the cause if STALL,
169 * : regards the pipe state as STALL and ends the processing.
170 * : Then the cause is not STALL, increments the error count to
171 * : communicate again. When the error count is 3, determines
172 * : the pipe state as USB_HOST_PIPE_NORES and ends the processing.
173 * : This function is executed in the NRDY interrupt handler.
174 * : This function clears NRDY interrupt status.
175 * Arguments : uint16_t status ; NRDYSTS Register Value
176 * : uint16_t int_enb ; NRDYENB Register Value
177 * Return Value : none
178 *******************************************************************************/
179 void usb1_host_nrdy_int (uint16_t status
, uint16_t int_enb
)
185 bitcheck
= (uint16_t)(status
& int_enb
);
187 USB201
.NRDYSTS
= (uint16_t)~status
;
189 for (pipe
= USB_HOST_PIPE1
; pipe
<= USB_HOST_MAX_PIPE_NO
; pipe
++)
191 if ((bitcheck
&g_usb1_host_bit_set
[pipe
]) == g_usb1_host_bit_set
[pipe
])
193 if (RZA_IO_RegRead_16(&USB201
.SYSCFG0
,
194 USB_SYSCFG_DCFM_SHIFT
,
195 USB_SYSCFG_DCFM
) == 1)
197 if (g_usb1_host_pipe_status
[pipe
] == USB_HOST_PIPE_WAIT
)
199 pid
= usb1_host_get_pid(pipe
);
201 if ((pid
== USB_HOST_PID_STALL
) || (pid
== USB_HOST_PID_STALL2
))
203 g_usb1_host_pipe_status
[pipe
] = USB_HOST_PIPE_STALL
;
204 #if(1) /* ohci_wrapp */
205 ohciwrapp_loc_TransEnd(pipe
, TD_CC_STALL
);
210 #if(1) /* ohci_wrapp */
211 g_usb1_host_pipe_status
[pipe
] = USB_HOST_PIPE_NORES
;
212 ohciwrapp_loc_TransEnd(pipe
, TD_CC_DEVICENOTRESPONDING
);
214 g_usb1_host_PipeIgnore
[pipe
]++;
216 if (g_usb1_host_PipeIgnore
[pipe
] == 3)
218 g_usb1_host_pipe_status
[pipe
] = USB_HOST_PIPE_NORES
;
222 usb1_host_set_pid_buf(pipe
);
236 /*******************************************************************************
237 * Function Name: usb1_host_bemp_int
238 * Description : Executes BEMP interrupt(USB_HOST_PIPE1-9).
239 * Arguments : uint16_t status ; BEMPSTS Register Value
240 * : uint16_t int_enb ; BEMPENB Register Value
241 * Return Value : none
242 *******************************************************************************/
243 void usb1_host_bemp_int (uint16_t status
, uint16_t int_enb
)
250 bitcheck
= (uint16_t)(status
& int_enb
);
252 USB201
.BEMPSTS
= (uint16_t)~status
;
254 for (pipe
= USB_HOST_PIPE1
; pipe
<= USB_HOST_MAX_PIPE_NO
; pipe
++)
256 if ((bitcheck
&g_usb1_host_bit_set
[pipe
]) == g_usb1_host_bit_set
[pipe
])
258 pid
= usb1_host_get_pid(pipe
);
260 if ((pid
== USB_HOST_PID_STALL
) || (pid
== USB_HOST_PID_STALL2
))
262 g_usb1_host_pipe_status
[pipe
] = USB_HOST_PIPE_STALL
;
263 #if(1) /* ohci_wrapp */
264 ohciwrapp_loc_TransEnd(pipe
, TD_CC_STALL
);
269 inbuf
= usb1_host_get_inbuf(pipe
);
273 usb1_host_disable_bemp_int(pipe
);
274 usb1_host_set_pid_nak(pipe
);
275 g_usb1_host_pipe_status
[pipe
] = USB_HOST_PIPE_DONE
;
276 #if(1) /* ohci_wrapp */
277 ohciwrapp_loc_TransEnd(pipe
, TD_CC_NOERROR
);