Instruction manual
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware
R01AN0512EJ0210 Rev.2.10 Page 71 of 157
Apr 1, 2013
5.3 API (Application Programming Interface)
5.3.1 ANSI API
The ANSI API provides an ANSI-type interface for applications enabling the use of the same API for applications of
different classes.
This ANSI interface is made up of its API functions. USB-BASIC-F/W provides 5 API functions: open(), close(), read(),
write(), and control().
The user is discouraged from changing these functions. A list of ANSI API Functions are shown in
Table 5.1.
Table 5.1 List of ANSI API Functions
Function Name Description
open() Establish connection with USB device.
close() End connection with USB device.
read() Execute USB receive process *
write() Execute USB send process *
control() Execute process according to control code
*Transmission and reception of data are requested by user. When done, the user is notified when the API calls
the user-registered call-back function.
[Note]
HDCD cannot be registered using the ANSI IO API. Use the driver registration API
(R_usb_hstd_DriverRegistration()) to register the HDCD.
5.3.2 General operation using ANSI API
To use the ANSI API, here is the general order of how to set up USB transfers.
1. Call open, with the relevant class number for your system.
2. After a successful open, call control to register the call-back functions that will be called by the Basic FW when
the application later uses the read and write APIs.
3. These application read and write calls will each cause the Basic FW to trigger the respective callbacks for the
transfer types registered by the control call(s), that is, there will be one call for each transfer type and direction.
4. Later, when for example a bulk OUT transfer has been completed, the registered user callback will trigger.
5. When your callback is triggered, take care of the incoming data - or for outgoing data do relevant processing for
successfully sent user data.
6. It is important to determine how many bytes have been sent or received in the user application data arrays. For
the Basic FW’s “vendor class” this application data is in the data arrays usb_gvendor_smpl_bi_data[][],
usb_gvendor_smpl_bo_data[][], usb_gvendor_smpl_ii_data[][], and usb_gvendor_smpl_io_data[][], depending
on which transfer type was used for the pipe (endpoint). Use the control API with the
USB_CTL_RD_LENGTH_GET or USB_CTL_WR_LENGTH_GET parameter. The user data in these data
transfer arrays beyond the length returned by the control call is not to be used . Such data is old (from previous
transfer).