]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/USBDevice/USBDevice/TARGET_RENESAS/TARGET_RZ_A1H/usb0/src/function/usb0_function_api.c
Merge commit '28203e909e83b1ac6becb45a3eadae23b190df32' into master-core-pull
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / USBDevice / USBDevice / TARGET_RENESAS / TARGET_RZ_A1H / usb0 / src / function / usb0_function_api.c
1 /*******************************************************************************
2 * DISCLAIMER
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
19 * following link:
20 * http://www.renesas.com/disclaimer
21 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
22 *******************************************************************************/
23 /*******************************************************************************
24 * File Name : usb0_function_api.c
25 * $Rev: 1116 $
26 * $Date:: 2014-07-09 16:29:19 +0900#$
27 * Device(s) : RZ/A1H
28 * Tool-Chain :
29 * OS : None
30 * H/W Platform :
31 * Description : RZ/A1H R7S72100 USB Sample Program
32 * Operation :
33 * Limitations :
34 *******************************************************************************/
35
36
37 /*******************************************************************************
38 Includes <System Includes> , "Project Includes"
39 *******************************************************************************/
40 #include "usb0_function.h"
41 #include "dev_drv.h"
42
43
44 /*******************************************************************************
45 Typedef definitions
46 *******************************************************************************/
47
48
49 /*******************************************************************************
50 Macro definitions
51 *******************************************************************************/
52
53
54 /*******************************************************************************
55 Imported global variables and functions (from other files)
56 *******************************************************************************/
57
58
59 /*******************************************************************************
60 Exported global variables and functions (to be accessed by other files)
61 *******************************************************************************/
62
63
64 /*******************************************************************************
65 Private global variables and functions
66 *******************************************************************************/
67
68
69 /*******************************************************************************
70 * Function Name: usb0_api_function_init
71 * Description : Initializes the USB module in the USB function mode.
72 * Arguments : uint8_t int_level ; interruput level
73 * : uint16_t mode : Speed modes
74 * : : USB_FUCNTION_HIGH_SPEED: High-speed device
75 * : : USB_FUCNTION_FULL_SPEED: Full-speed device
76 * : uint16_t clockmode ; 48MHz ; USBFCLOCK_X1_48MHZ
77 * : ; 12MHz ; USBFCLOCK_EXTAL_12MHZ
78 * Return Value : none
79 *******************************************************************************/
80 #if 0
81 void usb0_api_function_init (uint8_t int_level, uint16_t mode, uint16_t clockmode)
82 {
83 volatile uint8_t dummy_buf;
84
85 CPG.STBCR7 &= 0xfd; /* The clock of USB0 modules is permitted */
86 dummy_buf = CPG.STBCR7; /* (Dummy read) */
87
88 usb0_function_setting_interrupt(int_level);
89
90 usb0_function_reset_module(clockmode); /* reset USB module with setting tranciever */
91 /* and HSE=1 */
92
93 usb0_function_init_status(); /* clear variables */
94
95 usb0_function_InitModule(mode); /* select USB Function and Interrupt Enable */
96 /* Detect USB Device to attach or detach */
97 }
98 #endif
99
100 /*******************************************************************************
101 * Function Name: usb0_api_function_IsConfigured
102 * Description : Checks if the USB device is configured to return the result as
103 * : the return value.
104 * Arguments : none
105 * Return Value : DEVDRV_USBF_YES : Configured & Configured Suspend
106 * : DEVDRV_USBF_NO : not Configured
107 *******************************************************************************/
108 uint16_t usb0_api_function_IsConfigured (void)
109 {
110 uint16_t dvst;
111
112 dvst = usb0_function_GetDeviceState();
113
114 if ((dvst == USB_FUNCTION_DVST_CONFIGURED) ||
115 (dvst == USB_FUNCTION_DVST_CONFIGURED_SUSPEND))
116 {
117 return DEVDRV_USBF_YES;
118 }
119
120 return DEVDRV_USBF_NO;
121 }
122
123 /*******************************************************************************
124 * Function Name: usb0_function_GetDeviceState
125 * Description : Returns the state of USB device.
126 * Arguments : none
127 * Return Value : Device States
128 *******************************************************************************/
129 uint16_t usb0_function_GetDeviceState (void)
130 {
131 uint16_t dvsq;
132 uint16_t dvst;
133
134 dvsq = USB200.INTSTS0;
135 switch(dvsq & USB_FUNCTION_BITDVSQ)
136 {
137 case USB_FUNCTION_DS_POWR: /* Power state *//* power-on */
138 dvst = USB_FUNCTION_DVST_POWERED;
139 break;
140
141 case USB_FUNCTION_DS_DFLT: /* Default state *//* bus-reset */
142 dvst = USB_FUNCTION_DVST_DEFAULT;
143 break;
144
145 case USB_FUNCTION_DS_ADDS: /* Address state */
146 dvst = USB_FUNCTION_DVST_ADDRESS;
147 break;
148
149 case USB_FUNCTION_DS_CNFG: /* Configured state */
150 dvst = USB_FUNCTION_DVST_CONFIGURED;
151 break;
152
153 case USB_FUNCTION_DS_SPD_CNFG: /* Configured Suspend state */
154 dvst = USB_FUNCTION_DVST_CONFIGURED_SUSPEND;
155 break;
156
157 case USB_FUNCTION_DS_SPD_POWR: /* Power Suspend state */
158 case USB_FUNCTION_DS_SPD_DFLT: /* Default Suspend state */
159 case USB_FUNCTION_DS_SPD_ADDR: /* Address Suspend state */
160 dvst = USB_FUNCTION_DVST_SUSPEND;
161 break;
162
163 default: /* error */
164 dvst = USB_FUNCTION_DVST_SUSPEND;
165 break;
166 }
167
168 return dvst;
169 }
170
171 /*******************************************************************************
172 * Function Name: usb0_api_function_start_receive_transfer
173 * Description : Starts USB data reception using the pipe specified in the argument.
174 * : The FIFO for using is set in the pipe definition table.
175 * Arguments : uint16_t pipe ; Pipe Number
176 * : uint32_t size ; Data Size
177 * : uint8_t *data ; Data data Address
178 * Return Value : none
179 *******************************************************************************/
180 void usb0_api_function_start_receive_transfer (uint16_t pipe, uint32_t size, uint8_t * data)
181 {
182 usb0_function_start_receive_transfer(pipe, size, data);
183 }
184
185 /*******************************************************************************
186 * Function Name: usb0_api_function_start_send_transfer
187 * Description : Starts the USB data communication using pipe specified by the argument.
188 * Arguments : uint16_t pipe ; Pipe Number
189 * : uint32_t size ; Data Size
190 * : uint8_t *data ; Data data Address
191 * Return Value : DEVDRV_USBF_WRITEEND ; Write end
192 * : DEVDRV_USBF_WRITESHRT ; short data
193 * : DEVDRV_USBF_WRITING ; Continue of data write
194 * : DEVDRV_USBF_WRITEDMA ; Write DMA
195 * : DEVDRV_USBF_FIFOERROR ; FIFO status
196 *******************************************************************************/
197 uint16_t usb0_api_function_start_send_transfer (uint16_t pipe, uint32_t size, uint8_t * data)
198 {
199 uint16_t status;
200
201 status = usb0_function_start_send_transfer(pipe, size, data);
202
203 return status;
204 }
205
206 /*******************************************************************************
207 * Function Name: usb0_api_function_check_pipe_status
208 * Description : Starts USB data reception using the pipe specified in the argument.
209 * : The FIFO for using is set in the pipe definition table.
210 * Arguments : uint16_t pipe ; Pipe Number
211 * : uint32_t *size ; Data Size
212 * Return Value : Pipe Status
213 *******************************************************************************/
214 uint16_t usb0_api_function_check_pipe_status (uint16_t pipe, uint32_t * size)
215 {
216 if (g_usb0_function_pipe_status[pipe] == DEVDRV_USBF_PIPE_DONE)
217 {
218 *size = g_usb0_function_PipeDataSize[pipe];
219 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_IDLE;
220
221 return DEVDRV_USBF_PIPE_DONE;
222 }
223 else if (g_usb0_function_pipe_status[pipe] == DEVDRV_USBF_PIPE_NORES)
224 {
225 *size = 0;
226 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_IDLE;
227
228 return DEVDRV_USBF_PIPE_NORES;
229 }
230 else if (g_usb0_function_pipe_status[pipe] == DEVDRV_USBF_PIPE_STALL)
231 {
232 *size = 0;
233 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_IDLE;
234
235 return DEVDRV_USBF_PIPE_STALL;
236 }
237 else if (g_usb0_function_pipe_status[pipe] == DEVDRV_USBF_FIFOERROR)
238 {
239 *size = 0;
240 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_IDLE;
241
242 return DEVDRV_USBF_FIFOERROR;
243 }
244 else
245 {
246 /* Do Nothing */
247 }
248
249 return g_usb0_function_pipe_status[pipe];
250 }
251
252 /*******************************************************************************
253 * Function Name: usb0_api_function_clear_pipe_status
254 * Description : Starts USB data reception using the pipe specified in the argument.
255 * : The FIFO for using is set in the pipe definition table.
256 * Arguments : uint16_t pipe ; Pipe Number
257 * Return Value : Pipe Status
258 *******************************************************************************/
259 void usb0_api_function_clear_pipe_status (uint16_t pipe)
260 {
261 g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_IDLE;
262 g_usb0_function_PipeDataSize[pipe] = 0;
263 }
264
265 /*******************************************************************************
266 * Function Name: usb0_api_function_set_pid_buf
267 * Description : Enables communicaqtion in the pipe specified by the argument
268 * : (BUF).
269 * Arguments : uint16_t pipe ; pipe Number
270 * Return Value : none
271 *******************************************************************************/
272 void usb0_api_function_set_pid_buf (uint16_t pipe)
273 {
274 usb0_function_set_pid_buf(pipe);
275 }
276
277 /*******************************************************************************
278 * Function Name: usb0_api_function_set_pid_nak
279 * Description : Disables communication (NAK) in the pipe specified by the argument.
280 * : When the pipe status was enabling communication (BUF) before
281 * : executing before executing this function, waits in the software
282 * : until the pipe becomes ready after setting disabled.
283 * Arguments : uint16_t pipe ; pipe Number
284 * Return Value : none
285 *******************************************************************************/
286 void usb0_api_function_set_pid_nak (uint16_t pipe)
287 {
288 usb0_function_set_pid_nak(pipe);
289 }
290
291 /*******************************************************************************
292 * Function Name: usb0_api_function_set_pid_stall
293 * Description : Disables communication (STALL) in the pipe specified by the
294 * : argument.
295 * Arguments : uint16_t pipe ; pipe Number
296 * Return Value : none
297 *******************************************************************************/
298 void usb0_api_function_set_pid_stall (uint16_t pipe)
299 {
300 usb0_function_set_pid_stall(pipe);
301 }
302
303 /*******************************************************************************
304 * Function Name: usb0_api_function_clear_pid_stall
305 * Description : Disables communication (NAK) in the pipe specified by the argument.
306 * Arguments : uint16_t pipe ; pipe Number
307 * Return Value : none
308 *******************************************************************************/
309 void usb0_api_function_clear_pid_stall (uint16_t pipe)
310 {
311 usb0_function_clear_pid_stall(pipe);
312 }
313
314 /*******************************************************************************
315 * Function Name: usb0_api_function_get_pid
316 * Description : Returns the pipe state specified by the argument.
317 * Arguments : uint16_t pipe ; Pipe Number
318 * Return Value : PID
319 *******************************************************************************/
320 uint16_t usb0_api_function_get_pid (uint16_t pipe)
321 {
322 uint16_t pid;
323
324 pid = usb0_function_get_pid(pipe);
325
326 return pid;
327 }
328
329 /*******************************************************************************
330 * Function Name: usb0_api_function_check_stall
331 * Description :
332 * Arguments : uint16_t pipe ; Pipe Number
333 * Return Value : PID
334 *******************************************************************************/
335 int32_t usb0_api_function_check_stall (uint16_t pipe)
336 {
337 uint16_t pid;
338
339 pid = usb0_function_get_pid(pipe);
340
341 if ((pid & DEVDRV_USBF_PID_STALL) == DEVDRV_USBF_PID_STALL)
342 {
343 return DEVDRV_USBF_STALL;
344 }
345
346 return DEVDRV_SUCCESS;
347 }
348
349 /*******************************************************************************
350 * Function Name: usb0_api_function_set_sqclr
351 * Description : Sets the sequence bit of the pipe specified by the argument to
352 * : DATA0.
353 * Arguments : uint16_t pipe ; Pipe Number
354 * Return Value : none
355 *******************************************************************************/
356 void usb0_api_function_set_sqclr (uint16_t pipe)
357 {
358 usb0_function_set_sqclr(pipe);
359 }
360
361 /*******************************************************************************
362 * Function Name: usb0_api_function_set_sqset
363 * Description : Sets the sequence bit of the pipe specified by the argument to
364 * : DATA1.
365 * Arguments : uint16_t pipe ; Pipe number
366 * Return Value : none
367 *******************************************************************************/
368 void usb0_api_function_set_sqset (uint16_t pipe)
369 {
370 usb0_function_set_sqset(pipe);
371 }
372
373 /*******************************************************************************
374 * Function Name: usb0_api_function_set_csclr
375 * Description : CSPLIT status clear setting of sprit transaction in specified
376 * : pipe is performed.
377 * : When SQSET bit or SQCLR bit, and SQSET bit or SQCLR bit
378 * : in DCPCTR register are continuously changed (when the sequence
379 * : toggle bit of data PID is continuously changed over two or more pipes),
380 * : the access cycle with 120 ns and more than 5 cycle bus clock is necessary.
381 * : Do not set both SQCLR bit and SQSET bit to 1 at the same time.
382 * : In addition, both bits should be operated after PID is set to NAK.
383 * : However, when it is set to the isochronous transfer as the transfer type
384 * : (TYPE=11), writing in SQSET bit is disabled.
385 * Arguments : uint16_t pipe ; Pipe number
386 * Return Value : none
387 *******************************************************************************/
388 void usb0_api_function_set_csclr (uint16_t pipe)
389 {
390 usb0_function_set_csclr(pipe);
391 }
392
393 /*******************************************************************************
394 * Function Name: usb0_api_function_set_curpipe
395 * Description : Allocates FIF0 specifed by the argument in the pipe assigned
396 * : by the argument.
397 * Arguments : uint16_t pipe ; Pipe Number
398 * : uint16_t fifosel ; Select FIFO
399 * : uint16_t isel ; FIFO Access Direction
400 * : uint16_t mbw ; FIFO Port Access Bit Width
401 * Return Value : none
402 *******************************************************************************/
403 void usb0_api_function_set_curpipe (uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw)
404 {
405 usb0_function_set_curpipe(pipe, fifosel, isel, mbw);
406 }
407
408 /*******************************************************************************
409 * Function Name: usb0_api_function_clear_brdy_sts
410 * Description : Clear BRDY interrupt status in the pipe spceified by the argument.
411 * Arguments : uint16_t pipe ; pipe Number
412 * Return Value : none
413 *******************************************************************************/
414 void usb0_api_function_clear_brdy_sts (uint16_t pipe)
415 {
416 usb0_function_clear_brdy_sts(pipe);
417 }
418
419 /*******************************************************************************
420 * Function Name: usb0_api_function_clear_bemp_sts
421 * Description : Clear BEMP interrupt status in the pipe spceified by the argument.
422 * Arguments : uint16_t pipe ; pipe Number
423 * Return Value : none
424 *******************************************************************************/
425 void usb0_api_function_clear_bemp_sts (uint16_t pipe)
426 {
427 usb0_function_clear_bemp_sts(pipe);
428 }
429
430 /*******************************************************************************
431 * Function Name: usb0_api_function_clear_nrdy_sts
432 * Description : Clear NRDY interrupt status in the pipe spceified by the argument.
433 * Arguments : uint16_t pipe ; pipe Number
434 * Return Value : none
435 *******************************************************************************/
436 void usb0_api_function_clear_nrdy_sts (uint16_t pipe)
437 {
438 usb0_function_clear_nrdy_sts(pipe);
439 }
440
441 /* End of File */
Imprint / Impressum