On April 1st, 2010, NEC Electronics Corporation merged with Renesas Technology
Corporation, and Renesas Electronics Corporation took over all the business of both
companies. Therefore, although the old company name remains in this document, it is a valid
Renesas Electronics document. We appreciate your understanding.
Send any inquiries to http://www.renesas.com/inquiry
.
Notice
1. All information included in this document is current as of the date this document is issued. Such information, however, is
subject to change without any prior notice. Before purchasing or using any Renesas Electronics products listed herein, please
confirm the latest product information with a Renesas Electronics sales office. Also, please pay regular and careful attention to
additional and different information to be disclosed by Renesas Electronics such as that disclosed through our website.
2. Renesas Electronics does not assume any liability for infringement of patents, copyrights, or other intellectual property rights
of third parties by or arising from the use of Renesas Electronics products or technical information described in this document.
No license, express, implied or otherwise, is granted hereby under any patents, copyrights or other intellectual property rights
of Renesas Electronics or others.
3. You should not alter, modify, copy, or otherwise misappropriate any Renesas Electronics product, whether in whole or in part.
4. Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of
semiconductor products and application examples. You are fully responsible for the incorporation of these circuits, software,
and information in the design of your equipment. Renesas Electronics assumes no responsibility for any losses incurred by
you or third parties arising from the use of these circuits, software, or information.
5. When exporting the products or technology described in this document, you should comply with the applicable export control
laws and regulations and follow the procedures required by such laws and regulations. You should not use Renesas
Electronics products or the technology described in this document for any purpose relating to military applications or use by
the military, including but not limited to the development of weapons of mass destruction. Renesas Electronics products and
technology may not be used for or incorporated into any products or systems whose manufacture, use, or sale is prohibited
under any applicable domestic or foreign laws or regulations.
6. Renesas Electronics has used reasonable care in preparing the information included in this document, but Renesas Electronics
does not warrant that such informatio n is error free. Renesas Electronics assumes no liability whatsoever for any damages
incurred by you resulting from errors in or omissions from the information included herein.
7. Renesas Electronics products are classified according to the following three quality grades: “Standard”, “High Quality”, and
“Specific”. The recommended applications for each Renesas Electronics product depends on the product’s quality grade, as
indicated below. You must check the quality grade of each Renesas Electronics product before using it in a particular
application. You may not use any Renesas Electronics product for any application categorized as “Specific” without the prior
written consent of Renesas Electronics. Further, you may not use any Renesas Electronics product for any application for
which it is not intended without the prior written consent of Renesas Electronics. Renesas Electronics shall not be in any way
liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for an
application categorized as “Specific” or for which the product is not intended where you have failed to obtain the prior written
consent of Renesas Electronics. The quality grade of each Renesas Electronics product is “Standard” unless otherwise
expressly specified in a Ren esas E lectronics data sheets or dat a books, etc.
“Standard”: Computers; office equipment; communications equipment; test and measurement equipment; audio and visual
equipment; home electron ic appliances; machine tools; personal electronic equipment; and industrial robots.
crime systems; safety equipment; and medical equipment not specifically designed for life support.
“Specific”: Aircraft; aerospace equipment; submersible repeaters; nuclear reactor control systems; medical equipment or
systems for life support (e.g. artificial life support devices or systems), surgical implantations, or healthcare
intervention (e.g. excision, etc.), and any other appl i cations or purposes that pose a d irect threat to human life.
8. You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics,
especially with respect to the maximum rating, operating supply voltage range, movement power voltage range, heat radiation
characteristics, installation and other product characteristics. Renesas Electronics shall have no liability for malfunctions or
damages arising out of the use of Renesas Electronics products beyond such specified ranges.
9. Although Renesas Electronics endeavors to improve the quality and reliability of its products, semiconductor products have
specific characteristics such as t he occu rrence o f failure at a certai n rate an d malfunct io ns under cert ain u se con dition s. Further,
Renesas Electronics prod ucts are not subject to radiation resistance design. Please be sure to implement safety measures to
guard them against the possibility of physical injury, and injury or damage caused by fire in the event of the failure of a
Renesas Electronics product, such as safety design for hardware and software including but not limited to redundancy, fire
control and malfunction prevention, appropriate treatment for aging degradation or any other appropriate measures. Because
the evaluation of microcomputer software alone is very difficult, please evaluate the safety of the final products or system
manufactured by you.
10. Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental
compatibility of each Renesas Electronics product. Please use Renesas Electronics products in compliance with all applicable
laws and regulations that regulate the inclusion or use of controlled substances, including without limitation, the EU RoHS
Directive. Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with
applicable laws and regulations.
11. This document may not be reproduced or duplicated, in any form, in whole or in part, without prior written consent of Renesas
Electronics.
12. Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this
document or Renesas Electronics products, or if you have any other inquiries.
(Note 1) “Renesas Electronics” as used in this document means Renesas Electronics Corporation an d also includes its majority-
owned subsidiaries.
(Note 2) “Renesas Electronics product(s)” means any product developed or manufactured by or for Renesas Electronics.
User’s Manual
User’s Manual
M16C/62P Group Renesas Embedded
Application Programming Interface
Reference Manual
Rev.1.00 2007.11
Renesas Embedded
Application Programming Interface
Reference Manual
<M16C/62P Group>
Rev.1.00 2007.11.1
REC10B0002-0100
2
Table of Contents
Table of Contents ............................................................... 3
The Renesas Embedded Application Programming Interface (API) is a unified API for
the microcomputers made by Renesas Technology Corporation.
Rev.1.00 2007.11.1
REC10B0002-0100
5
2. Driver
2.1 Overview
The library described herein provides a peripheral facility control program (peripheral
driver) for microcomputers. Use of the Renesas API permits the peripheral driver to be
built into a user program.
2.2 Driver Features
The library described herein has the following features available as a peripheral driver.
(1) Serial I/O control feature
It comprises a serial interface driver, which sets or clears the conditions of serial
communication, as well as controls and manages the transmission/reception of
communication data.
(2) Timer control feature
It comprises a timer driver, which sets or clears the operating conditions of timers,
as well as controls the timer operation.
(3) I/O port control feature
It comprises an I/O port driver, which sets or clears the usage conditions of I/O ports, as
well as control data read/write operation.
(4) External interrupt control feature
It comprises an external interrupt driver, which sets or clears the usage conditions of
external interrupts, as well as controls interrupt operation.
(5) A/D converter control feature
It comprises an A/D converter driver, which sets or clears the usage conditions of A/D
converters, as well as controls A/D converter operation.
Rev.1.00 2007.11.1
REC10B0002-0100
6
2.3 Serial Interface Driver
The serial interface driver sets serial communication, clears settings, transmit/receives
data, and controls the status of serial communication.
There are two kinds of serial interface driver: a single-data transmission/reception API
and a multi-data transmission/reception API.
Rev.1.00 2007.11.1
REC10B0002-0100
7
2.4 Timer Driver
The timer driver sets the timer, clears timer settings, controls timer operation, and
acquires a counter value with respect to the following modes:
• Timer mode
• Event counter mode
• Pulse width modulation mode (PWM mode)
• Pulse period measurement mode
• Pulse width measurement mode
2.4.1 Timer Mode
In this mode, the timer counts the internally generated count source. When an
underflow or an overflow interrupt occurs, it calls a preset callback function.
2.4.2 Event Counter Mode
In this mode, the timer counts the external signal fed in from an input pin or an
overflow or underflow from other timer. When an underflow or an overflow interrupt
occurs, it calls a preset callback function.
2.4.3 Pulse Width Modulation Mode (PWM Mode)
In this mode, the timer outputs pulses in a given width successively. When an
underflow or an overflow interrupt occurs, it calls a preset callback function.
2.4.4 Pulse Period Measurement Mode
In this mode, the timer measures the pulse period of an external signal fed in from an
input pin. When an underflow or an overflow interrupt occurs, it calls a preset callback
function.
2.4.5 Pulse Width Measurement Mode
In this mode, the timer measures the pulse width of an external signal fed in from an
input pin. When an underflow or an overflow interrupt occurs, it calls a preset callback
function.
Rev.1.00 2007.11.1
REC10B0002-0100
8
2.5 I/O Port Driver
The I/O port driver sets the I/O port for input or output, writes data to the I/O port, and
reads data from the I/O port.
Rev.1.00 2007.11.1
REC10B0002-0100
9
2.6 External Interrupt Driver
The external interrupt driver sets external interrupts, controls external interrupts,
acquires the status of external interrupt flags, and clears external interrupt flags.
Rev.1.00 2007.11.1
REC10B0002-0100
10
2.7 A/D Converter Driver
The A/D converter driver sets the A/D converter, controls the A/D converter, clears
settings of the A/D converter, acquires the A/D converter value, acquires the status of the
A/D converter, and clears the status of the A/D converter.
Rev.1.00 2007.11.1
REC10B0002-0100
11
3. Standard Types
This section describes the standard types defined in the library. For details about the
set values, refer to the description of each API.
Standard type Description
Boolean
Voi dF unc No ti fy
The Boolean type represents the enum-type data that indicates
whether successful (RAPI_TRUE (= 1)) or failed (RAPI_FALSE (=
0)).
The VoidFuncNotify type represents the type of the notification
function to be registered.
Rev.1.00 2007.11.1
REC10B0002-0100
12
4. Library Reference
4.1 API List by Peripheral Facility
The table below lists the Renesas Embedded APIs classified by peripheral facility.
Opens serial port
Closes serial port
Sets serial communication
Receives 1 data
Transmits 1 data
Reads receive status
Reads transmit status
Stops reception
Stops transmission
Opens serial port
Closes serial port
Registers notification function
Sets serial communication
Sets transmit/receive interrupt
Starts reception
Starts transmission
Stops reception
Stops transmission
Receives by polling
Transmits by polling
Sets timer mode
Controls timer mode operation
Clears timer mode setting
Sets event counter mode
Controls operation of event counter
mode
Clears setting of event counter
mode
Gets event counter mode counter
value
Sets pulse width modulation mode
Controls operation of pulse width
modulation mode
Clears setting of pulse width
modulation mode
Sets pulse period measurement
mode
Controls operation of pulse period
measurement mode
Clears setting of pulse width
measurement mode
Acquires measured value of pulse
period measurement mode
Sets pulse width measurement
mode
Controls operation of pulse width
measurement mode
Clears setting of pulse width
measurement mode
Acquires measured value of pulse
width measurement mode
Sets timer register
Controls operation of timer register
Clears timer register
Gets timer register value
Sets I/O port
Reads from I/O port
Writes to I/O port
Sets I/O port register
Reads from I/O port register
Writes to I/O port register
Sets external interrupt
Controls external interrupt
Gets flag status of external interrupt
Clears flag of external interrupt
Sets A/D converter
Controls operation of A/D converter
Discards settings of A/D converter
Gets A/D conversion value (register
specified)
Gets A/D conversion value (all
registers)
Rev.1.00 2007.11.1
REC10B0002-0100
14
4.2 Description of Each API
This section describes each API and explains how to use them, showing a program
example for each.
The description of each API is divided into the following items.
• Synopsis
• Description
• Return value
• Functionality
• Reference
• Remark
• Program example
: Outlines the content of processing performed by the function. It
also shows the syntax of the function, followed by a brief
explanation of arguments.
: Describes the function and how to use it in detail.
: Explains the returned value of the function.
: Indicates the functional classification of the function.
: Indicates the related functions.
: Describes the precautions to be taken when using the API.
: Presents a program showing how to use the function.
Rev.1.00 2007.11.1
REC10B0002-0100
15
4.2.1 Serial I/O
__BasicOpenSerialDriver
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
Program example
<Open a serial port>
Boolean __BasicOpenSerialDriver(unsigned long data)
For serial communication mode, the following values can be set.
(UART0, UART1, UART2)
RAPI_SM_SYNC
RAPI_SM_ASYNC
(SI/O3, SI/O4)
RAPI_SIO_SM_SYNC
For the data length format of clock asynchronous serial communication, the following
values can be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(UART0, UART1, UART2)
RAPI_BIT_7 Transfer data length 7 bitsRAPI_BIT_8 Transfer data length 8 bits
RAPI_BIT_9 Transfer data length 9 bits
For the clock source of serial communication, the following values can be set.
(UART0, UART1, UART2)
RAPI_CKDIR_INT Internal clock is used as the clock source of serial communication.
RAPI_CKDIR_EXT External clock is used as the clock source of serial communication.
(SI/O3, SI/O4)
RAPI_SIO_CKDIR_INTInternal clock is used as the clock source of serial communication.
RAPI_SIO_CKDIR_EXTExternal clock is used as the clock source of serial communication.
For the stop bit length of clock asynchronous serial communication, the following
values can be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(UART0, UART1, UART2)
RAPI_STPB_1 1 stop bit RAPI_STPB_2 2 stop bits
For the parity bit of clock asynchronous serial communication, the following values can
be set.
Clock synchronous serial communication mode
Clock asynchronous serial communication mode
Clock synchronous serial communication mode
Rev.1.00 2007.11.1
REC10B0002-0100
18
If the API is used in clock synchronous serial communication mode, do not set these
values.
(UART0, UART1, UART2)
RAPI_PARITY_NONNo parity bit RAPI_PARITY_EVEN Even parity bit
RAPI_PARITY_ODDOdd parity bit
For the clock polarity of serial communication, the following values can be set.
If the API is used in clock asynchronous serial communication mode, do not set these
values.
(UART0, UART1, UART2)
RAPI_DPOL_NON Polarity not invertedRAPI_DPOL_INV Polarity inverted
(SI/O3, SI/O4)
RAPI_SIO_DPOL_NONPolarity not invertedRAPI_SIO_DPOL_INV Polarity inverted
For the count source of the built-in baud rate generator, the following values can be set.
(UART0, UART1, UART2)
For the _CTS/_RTS function, the following values can be set.
If the internal clock is selected for use in clock synchronous serial communication
mode, the _RTS function has no effect.
(UART0, UART1, UART2)
RAPI_CTSRTS_DIS _CTS/_RTS functions are not used.
RAPI_CTS_SEL _CTS function is selected.
RAPI_RTS_SEL _RTS function is selected.
For the transfer format, the following values can be set.
If the data length selected for use in clock asynchronous serial communication mode is
7 or 9 bits long, do not set these values.
(UART0, UART1, UART2)
RAPI_LSB_SEL LSB first RAPI_MSB_SEL MSB first
(SI/O3, SI/O4)
RAPI_SIO_LSB_SEL LSB first RAPI_SIO_MSB_SEL MSB first
For serial data logic switchover, the following values can be set.
(UART0, UART1, UART2)
RAPI_LOGIC_NO_REV
RAPI_LOGIC_REV The value written in the transmit buffer register is inverted before
Return value
[data2]
Sets the divide-by-N value of a communication speed.
The value written in the transmit buffer register does not have its
logic inverted.
being transmitted.
Rev.1.00 2007.11.1
REC10B0002-0100
19
Functionality
Reference
Remark
If serial communication was successfully set, RAPI_TRUE is returned; if settings failed,
RAPI_FALSE is returned.
Serial I/O
If an undefined value is specified in the first argument, operation of the API cannot
•
be guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
Boolean func( void )
{
/* Set the data of RAPI_COM1 to serial driver */
Return _BasicSetSerialFormat(RAPI_COM1 | RAPI_SM_SYNC | RAPI_CKDIR_INT