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 un cNo 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
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
Serial I/O
__OpenSerialDriver
If an undefined value is specified in the argument, operation of the API cannot be
•
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
void func( void )
{
/* Close serial driver */
return __CloseSerialDriver( RAPI_COM1 );
}
Rev.1.00 2007.11.1
REC10B0002-0100
28
0
__ConfigSerialDriverNotify
Synopsis
Description
The function to be registered in func must be supplied to the serial I/O driver by the
The serial I/O driver calls the function registered in func.
The serial I/O driver notifies the user of the transmit/receive status by an argument.
The type of the function to be registered is shown below.
void “any function name” (unsigned char notify);
The argument is detailed below.
(UART0, UART1, UART2)
<Register a notification function>
Boolean __ConfigSerialDriverNotify(unsigned long data, VoidFuncNotify *func)
data Setup data
func Function pointer to be registered
Registers the notification function necessary to get various transmit/receive information