Renesas M16C, М62P User Manual

REC10B0002-0100
M16C/62P Group Renesas Embedded Application Programming Interface
Reference Manual
Reference Manual
Rev.1.00 Revision Date: Nov.1, 2007
www.renesas.com
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
1. Introduction................................................................... 5
2. Driver ....................................................................... 6
2.1 Overview.................................................................. 6
2.2 Driver Features ............................................................. 6
2.3 Serial Interface Driver........................................................ 7
2.4 Timer Driver ............................................................... 8
2.4.1 Timer Mode ............................................................ 8
2.4.2 Event Counter Mode ..................................................... 8
2.4.3 Pulse Width Modulation Mode (PWM Mode).................................. 8
2.4.4 Pulse Period Measurement Mode ........................................... 8
2.4.5 Pulse Width Measurement Mode............................................ 8
2.5 I/O Port Driver ............................................................. 9
2.6 External Interrupt Driver..................................................... 10
2.7 A/D Converter Driver ....................................................... 11
3. Standard Types ............................................................... 12
4. Library Reference............................................................. 13
4.1 API List by Peripheral Facility ................................................ 13
4.2 Description of Each API ..................................................... 15
4.2.1 Serial I/O ........................................................... 16
__BasicOpenSerialDriver................................................... 16
__BasicCloseSerialDriver................................................... 17
__BasicSetSerialFormat .................................................... 18
__BasicStartSerialReceiving................................................. 21
__BasicStartSerialSending .................................................. 22
__BasicReceivingStatusRead ................................................ 23
__BasicSendingStatusRead.................................................. 24
__BasicStopSerialReceiving................................................. 25
__BasicStopSerialSending .................................................. 26
__OpenSerialDriver ....................................................... 27
__CloseSerialDriver ....................................................... 28
__ConfigSerialDriverNotify................................................. 29
__SetSerialFormat......................................................... 31
__SetSerialInterrupt ....................................................... 32
__StartSerialReceiving ..................................................... 34
__StartSerialSending....................................................... 35
__StopSerialReceiving ..................................................... 36
__StopSerialSending....................................................... 37
__PollingSerialReceiving ................................................... 38
__PollingSerialSending..................................................... 39
4.2.2 Timer ................................................................ 40
__CreateTimer ........................................................... 40
__EnableTimer ........................................................... 42
Rev.1.00 2007.11.1 REC10B0002-0100
3
__DestroyTimer .......................................................... 43
__CreateEventCounter ..................................................... 44
__EnableEventCounter..................................................... 47
__DestroyEventCounter .................................................... 48
__GetEventCounter........................................................ 49
__CreatePulseWidthModulationMode ......................................... 50
__EnablePulseWidthModulationMode......................................... 53
__DestroyPulseWidthModulationMode ........................................ 54
__CreatePulsePeriodMeasurementMode ....................................... 55
__EnablePulsePeriodMeasurementMode ....................................... 57
__DestroyPulsePeriodMeasurementMode ...................................... 58
__GetPulsePeriodMeasurementMode.......................................... 59
__CreatePulseWidthMeasurementMode........................................ 60
__EnablePulseWidthMeasurementMode ....................................... 62
__DestroyPulseWidthMeasurementMode ...................................... 63
__GetPulseWidthMeasurementMode .......................................... 64
__SetTimerRegister ....................................................... 65
__EnableTimerRegister..................................................... 67
__ClearTimerRegister...................................................... 68
__GetTimerRegister ....................................................... 69
4.2.3 I/O Port ............................................................ 71
__SetIOPort ............................................................. 71
__ReadIOPort ............................................................ 74
__WriteIOPort............................................................ 76
__SetIOPortRegister....................................................... 78
__ReadIOPortRegister ..................................................... 80
__WriteIOPortRegister..................................................... 81
4.2.4 External interrupt..................................................... 82
__SetInterrupt ............................................................ 82
__EnableInterrupt ......................................................... 84
__GetInterruptFlag ........................................................ 85
__ClearInterruptFlag....................................................... 86
4.2.5 A/D converter........................................................ 87
__CreateADC ............................................................ 87
__EnableADC............................................................ 92
__DestroyADC ........................................................... 95
__GetADC .............................................................. 96
__GetADCAll............................................................ 97
Rev.1.00 2007.11.1 REC10B0002-0100
4
1. Introduction
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.
NO Facility
classification
Single-data
1 __BasicOpenSerialDriver
serial I/O
2 __BasicCloseSerialDriver 3 __BasicSetSerialFormat 4 __BasicStartSerialReceiving 5 __BasicStartSerialSending 6 __BasicReceivingStatusRead 7 __BasicSendingStatusRead 8 __BasicStopSerialReceiving 9
Multi-data
10 __OpenSerialDriver
serial I/O
11 __CloseSerialDriver 12 __ConfigSerialDriverNotify 13 __SetSerialFormat 14 __SetSerialInterrupt 15 __StartSerialReceiving 16 __StartSerialSending 17 __StopSerialReceiving 18 __StopSerialSending 19 __PollingSerialReceiving 20
Timer
21 __CreateTimer 22 __EnableTimer 23 __DestroyTimer 24 __CreateEventCounter 25 __EnableEventCounter
26 __DestroyEventCounter 27 __GetEventCounter 28 __CreatePulseWidthModulationMode
29 __EnablePulseWidthModulationMode 30 __DestroyPulseWidthModulationMode 31 __CreatePulsePeriodMeasurementMode 32 __EnablePulsePeriodMeasurementMode 33 __DestroyPulsePeriodMeasurementMode 34
__BasicStopSerialSending
__PollingSerialSending
__GetPulsePeriodMeasurementMode
API API operation
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
Rev.1.00 2007.11.1 REC10B0002-0100
13
35 __CreatePulseWidthMeasurementMode 36
Timer
37 __DestroyPulseWidthMeasurementMode 38 __GetPulseWidthMeasurementMode 39 __SetTimerRegister
40 __EnableTimerRegister 41 __ClearTimerRegister 42
I/O port
43 __SetIOPort 44 __ReadIOPort 45 __WriteIOPort 46 __SetIOPortRegister 47 __ReadIOPortRegister 48
External
49 __SetInterrupt
interrupt
50 __EnableInterrupt 51 __GetInterruptFlag 52
A/D converter
53 __CreateADC 54 __EnableADC 55 __DestroyADC 56 __GetADC
67
__EnablePulseWidthMeasurementMode
__GetTimerRegister
__WriteIOPortRegister
__ClearInterruptFlag
__GetADCAll
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)
data Setup data
Opens and initializes a specified serial port.
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Serial I/O
__BasicCloseSerialDriver
If an undefined value is specified in the argument, oper ation of the API cannot be
guaranteed.
#include ”rapi_sif_m16c_62p”
void func( void ) { /* Open serial driver */ return __BasicOpenSerialDriver( RAPI_COM1 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
16
__BasicCloseSerialDriver
Synopsis
Description
<Close a serial port>
Boolean __BasicCloseSerialDriver(unsigned long data)
data Setup data
Closes a specified serial port. For data, the following values can be set.
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
Return value
Functionality
Reference
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Serial I/O
__BasicOpenSerialDriver
If an undefined value is specified in the argument, operation of the API cannot be
Remark
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
void func( void ) { /* Close serial driver */ return __BasicCloseSerialDriver( RAPI_COM1 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
17
__BasicSetSerialFormat
Synopsis
Description
<Set serial communication>
Boolean __BasicSetSerialFormat(unsigned long data1, unsigned char data2)
data1 Setup data 1 data2 Setup data 2
Sets serial communication according to specified parameters.
[data1]
For data1, the following values can be set. To set multiple definition values at the same time, use the symbol “|” to separate each specified value.
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
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 bits RAPI_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_INT Internal clock is used as the clock source of serial communication. RAPI_SIO_CKDIR_EXT External 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_NON No parity bit RAPI_PARITY_EVEN Even parity bit RAPI_PARITY_ODD Odd 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 inverted RAPI_DPOL_INV Polarity inverted
(SI/O3, SI/O4)
RAPI_SIO_DPOL_NON Polarity not inverted RAPI_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)
RAPI_BCSS_F1 f1SIO RAPI_BCSS_F2 f2SIO RAPI_BCSS_F8 f8SIO RAPI_BCSS_F32 f32SIO
(SI/O3, SI/O4)
RAPI_SIO_BCSS_F1 f1SIO RAPI_SIO_BCSS_F2 f2SIO RAPI_SIO_BCSS_F8 f8SIO RAPI_SIO_BCSS_F32 f32SIO
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
| RAPI_BCSS_F1 | RAPI_DPOL_NON | RAPI_LSB_SEL, 20);
}
Rev.1.00 2007.11.1 REC10B0002-0100
20
__BasicStartSerialReceiving
Synopsis
Description
Return value
Functionality
Reference
Remark
<Receive 1 data>
Boolean __BasicStartSerialReceiving(unsigned long data)
data Setup data
Starts receiving 1 data of serial communication.
[data]
For data, the following values can be set.
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
If data reception in serial communication was successfully started, RAPI_TRUE is returned; if failed, RAPI_FALSE is returned.
Serial I/O
__BasicReceivingStatusRead, __BasicStopSerialReceiving
If an undefined value is specified in the argument, oper ation of the API cannot be
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
void func( void ) {
..........
__BasicStartSerialReceiving( RAPI_COM1 );
..........
}
Rev.1.00 2007.11.1 REC10B0002-0100
21
__BasicStartSerialSending
Synopsis
Description
For data1, the following values can be set.
Return value
Functionality
Reference
Remark
<Transmit 1 data>
Boolean _BasicStartSerialSending(unsigned long data1, unsigned int data2)
data Setup data data Transmit data
Starts sending 1 data of serial communication.
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
If data transmission in serial communication was successfully started, RAPI_TRUE is returned; if failed, RAPI_FALSE is returned.
Serial I/O
__BasicSendingStatusRead, __BasicStopSerialSending
If an undefined value is specified in the argument, oper ation of the API cannot be
guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
Void func( void ) {
..........
__BasicStartSerialSending( RAPI_COM1, 0x00AA );
..........
}
Rev.1.00 2007.11.1 REC10B0002-0100
22
__BasicReceivingStatusRead
Synopsis
Description
For data, the following values can be set.
Return value
(UART0, UART1, UART2)
(SI/O3, SI/O4)
Functionality
Reference
Remark
<Read receive status>
unsigned int __BasicReceivingStatusRead(unsigned long data)
data Setup data
Returns the receive status of serial communication.
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
The receive status of serial communication is returned. The returned value is one of the following.
RAPI_RX_INCOMPLETE Reception not complete yet. Other than above Reception complete. The value read from the UARTi receive
buffer register (i = 0 to 2).
RAPI_RX_INCOMPLETE Reception not complete yet. Other than above Reception complete. Low-order 8 bits: The value read from the
SI/Oi transmit/receive register (i = 3, 4).
Serial I/O
__BasicStartSerialReceiving, __BasicS topSerialReceiving
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 ) { unsigned int rcv_data;
..........
rcv_data = __BasicReceivingStatusRead( RAPI_COM1 );
..........
}
Rev.1.00 2007.11.1 REC10B0002-0100
23
__BasicSendingStatusRead
Synopsis
Description
Return value
Functionality
Reference
Remark
<Read transmit status>
Boolean __BasicSendingStatusRead(unsigned long data)
data Setup data
Returns the transmit status of serial communication. For data, the following values can be set.
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
If no data exists in the transmit buffer, RAPI_TRUE is returned; if data exists, RAPI_FALSE is returned.
Serial I/O
__BasicStartSerialSending, __BasicStopSerialSending
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 ) {
..........
if (__BasicSendingStatusRead( RAPI_COM1 ) == RAPI_TRUE) { /* Transmission completion */ }
..........
}
Rev.1.00 2007.11.1 REC10B0002-0100
24
__BasicStopSerialReceiving
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Stop reception>
Boolean Rapi_BasicStopSerialReceiving(unsigned long data)
data Setup data
Stops receiving data in serial communication
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2
If data reception in serial communication was successfully stopped, RAPI_TRUE is
returned; if failed, RAPI_FALSE is returned.
Serial I/O
__BasicStartSerialReceiving
For the M16C SI/03 and SI/04, this API cannot be used.
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 ) { /* Stop receiving data in serial communication */ __BasicStopSerialReceiving ( RAPI_COM1 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
25
__BasicStopSerialSending
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Stop transmission>
Boolean __BasicStopSerialSending(unsigned long data)
data Setup data
Stops transmitting data in serial communication.
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2
If data transmission in serial communication was successfully stopped, RAPI_TRUE is
returned; if failed, RAPI_FALSE is returned.
Serial I/O
__BasicStartSerialSending
For the M16C SI/03 and SI/04, this API cannot be used.
When operating in clock synchronous serial communication mode, data reception is
stopped at the same time by this API. 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 ) { /* Stop sending data in serial communication */ __BasicStopSerialSending ( RAPI_COM1 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
26
__OpenSerialDriver
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Open a serial port>
Boolean __OpenSerialDriver(unsigned long data)
data Setup data
Opens and initializes a specified serial port.
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise, RAPI_TRUE is returned.
Serial I/O
__CloseSerialDriver
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 ) { /* Open serial driver */ return __OpenSerialDriver( RAPI_COM1 ); }
Rev.1.00 2007.11.1 REC10B0002-0100
27
__CloseSerialDriver
Synopsis
Description
For data, the following values can be set.
Return value
Functionality
Reference
Remark
<Close a serial port>
Boolean __CloseSerialDriver(unsigned long data)
data Setup data
Closes a specified serial port.
[data]
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
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
of serial communication.
[data]
For data, the following values can be set.
RAPI_COM1 UART0 RAPI_COM2 UART1 RAPI_COM3 UART2 RAPI_COM4 SI/O3 RAPI_COM5 SI/O4
[func]
user.
b7 b6 b5 b4 b3 b2 b1 b0
0 0XX 0XXX
(SI/O3,SI/O4)
b7b6b5b4b3b2b1 b
00XX 0000
Rev.1.00 2007.11.1 REC10B0002-0100
Overrun error
Framing error
Parity error
Transmission completed
Reception completed
Transmission co mp leted
Reception completed
29
0 No error 1 Error occurred
0 No error 1 Error occurred
0 No error 1 Error occurred
0 Not completed 1 Completed
0 Not completed 1 Completed
0Not completed 1 Completed
0Not completed 1 Completed
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise,
Return value
RAPI_TRUE is returned.
Functionality
Serial I/O
__StartSerialReceiving, __StartSerialSending
Reference
If an undefined value is specified in the first argument, operation of the API cannot
Remark
be guaranteed.
Program example
#include ”rapi_sif_m16c_62p”
void Notify(unsigned char result) { if ((result&RAPI_OVER_ERR) == RAPI_OVER_ERR) { /* Overrun error */ } if ((result&RAPI_FRAMING_ERR) == RAPI_FRAMING_ERR) { /* Framing error */ } if ((result&RAPI_PARITY_ERR) == RAPI_PARITY_ERR) { /* Parity error */ } if ((result&RAPI_TX_END) == RAPI_TX_END) { /* Transmission completion */ } if ((result&RAPI_RX_END) == RAPI_RX_END) { /* Reception completion */ } }
Boolean func( void ) { /* Set callback functions of RAPI_COM1 to serial driver */ return __ConfigSerialDriverNotify( RAPI_COM1, Notify ); }
Rev.1.00 2007.11.1 REC10B0002-0100
30
Loading...
+ 68 hidden pages