I/O Port Access Support Functions

I/O port access support functions support accesses or operations to the I/O devices. These include functions that read from or write to the I/O port of the specified address using the unit of byte or word, and a function that realizes a wait for a short time (micro wait) which is used for I/O device operations.

I/O port access support functions are provided as library functions or C language macros. These can be called from a task-independent portion or while task dispatching and interrupts are disabled.

I/O Port Access

In a system with separate I/O space and memory space, I/O port access functions access I/O space. In a system with memory-mapped I/O only, I/O port access functions access memory space. Using these functions will improve software portability and readability even in a memory-mapped I/O system.

out_b - Write to I/O Port (In Unit of Byte)

C Language Interface

#include <tk/tkernel.h>

void out_b(INT port, UB data);

Parameter

INT port I/O Port AddressI/O port address
UB data Write DataData to be written (in unit of byte)

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Related Service Profile Items

Only when all the service profile items below are set to be effective, this API can be used.

TK_SUPPORT_IOPORT Support of I/O port access

Description

Writes data in byte (8-bit) to the I/O port pointed by the address port.

out_h - Write to I/O Port (In Unit of Half-word)

C Language Interface

#include <tk/tkernel.h>

void out_h(INT port, UH data);

Parameter

INT port I/O Port AddressI/O port address
UH data Write DataData to be written (in unit of half-word)

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Related Service Profile Items

Only when all the service profile items below are set to be effective, this API can be used.

TK_SUPPORT_IOPORT Support of I/O port access

Description

Writes data in a half-word (16-bit) to the I/O port pointed by the address port.

out_w - Write to I/O Port (In Unit of Word)

C Language Interface

#include <tk/tkernel.h>

void out_w(INT port, UW data);

Parameter

INT port I/O Port AddressI/O port address
UW data Write DataData to be written (in unit of word)

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Related Service Profile Items

Only when all the service profile items below are set to be effective, this API can be used.

TK_SUPPORT_IOPORT Support of I/O port access

Description

Writes data in a word (32-bit) to the I/O port pointed by the address port.

out_d - Write to I/O Port (In Unit of Double-word)

C Language Interface

#include <tk/tkernel.h>

void out_d(INT port, UD data);

Parameter

INT port I/O Port AddressI/O port address
UD data Write DataData to be written (in unit of double-word)

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Related Service Profile Items

Only when all the service profile items below are set to be effective, this API can be used.

TK_SUPPORT_IOPORT Support of I/O port access
TK_HAS_DOUBLEWORD Support of 64-bit data types (D, UD, VD)

Description

Writes data in a double-word (64-bit) to the I/O port pointed by the address port.

Note that, in a system where I/O port cannot be accessed in double-word (64-bit) due to hardware constraint, data is separated into shorter units than double-word (64-bit) before they are written.

Rationale for the Specification

There are many systems where I/O port cannot be accessed in double-word (64-bit) due to hardware constraint such as 32-bit or less I/O data bus. In such systems, the strict specification of out_d and in_d cannot be implemented; that is, they cannot process data in one chunk of the specified bit width. In terms of the original purpose of this API, it is preferable not to implement the out_d and in_d or return an error at runtime. However, it is not practical to detect an error by determining the bus configuration at runtime, and it is often harmless to separate 64-bit data into 32-bit or narrower units before writing.

This is why the specification of out_d and in_d allow for the case where 64-bit data cannot be processed in one chunk. Therefore, whether out_d and in_d support the block access to 64-bit I/O port or not is implementation-dependent. If the block access to 64-bit I/O port is needed, the system hardware configuration and handling of out_d and in_d should be checked.

in_b - Read from I/O Port (In Unit of Byte)

C Language Interface

#include <tk/tkernel.h>

UB data = in_b(INT port);

Parameter

INT port I/O Port AddressI/O port address

Return Parameter

UB data Read DataData to be read (in unit of byte)

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Related Service Profile Items

Only when all the service profile items below are set to be effective, this API can be used.

TK_SUPPORT_IOPORT Support of I/O port access

Description

Reads data in a byte (8-bit) from the I/O port pointed by the address port and returns it in the return parameter data.

in_h - Read from I/O Port (In Unit of Half-word)

C Language Interface

#include <tk/tkernel.h>

UH data = in_h(INT port);

Parameter

INT port I/O Port AddressI/O port address

Return Parameter

UH data Read DataData to be read (in unit of half-word)

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Related Service Profile Items

Only when all the service profile items below are set to be effective, this API can be used.

TK_SUPPORT_IOPORT Support of I/O port access

Description

Reads data in a half-word (16-bit) from the I/O port pointed by the address port and returns it in the return parameter data.

in_w - Read from I/O Port (In Unit of Word)

C Language Interface

#include <tk/tkernel.h>

UW data = in_w(INT port);

Parameter

INT port I/O Port AddressI/O port address

Return Parameter

UW data Read DataData to be read (in unit of word)

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Related Service Profile Items

Only when all the service profile items below are set to be effective, this API can be used.

TK_SUPPORT_IOPORT Support of I/O port access

Description

Reads data in a word (32-bit) from the I/O port pointed by the address port and returns it in the return parameter data.

in_d - Read from I/O Port (In Unit of Double-word)

C Language Interface

#include <tk/tkernel.h>

UD data = in_d(INT port);

Parameter

INT port I/O Port AddressI/O port address

Return Parameter

UD data Read DataData to be read (in unit of double-word)

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Related Service Profile Items

Only when all the service profile items below are set to be effective, this API can be used.

TK_SUPPORT_IOPORT Support of I/O port access
TK_HAS_DOUBLEWORD Support of 64-bit data types (D, UD, VD)

Description

Reads data in a double-word (64-bit) from the I/O port pointed by the address port and returns it in the return parameter data.

Note that, in a system where I/O port cannot be accessed in one chunk of double-word (64-bit) due to hardware constraint, data is separated into shorter units than double-word (64-bit) before reading.

Micro Wait

WaitUsec - Micro Wait (Microseconds)

C Language Interface

#include <tk/tkernel.h>

void WaitUsec(UW usec);

Parameter

UW usec Micro SecondsWait time (in microseconds)

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Related Service Profile Items

Only when all the service profile items below are set to be effective, this API can be used.

TK_SUPPORT_MICROWAIT Support of micro wait

Description

Performs a micro wait for the specified interval (in microseconds).

This wait is usually implemented as a busy loop. This means that the micro wait occurs in the task RUNNING state rather than WAITING state.

The micro wait is easily influenced by the runtime environment, such as execution in RAM, execution in ROM, memory cache on or off, etc. The wait time is therefore not very accurate.

WaitNsec - Micro Wait (Nanoseconds)

C Language Interface

#include <tk/tkernel.h>

void WaitNsec(UW nsec);

Parameter

UW nsec NanosecondsWait time (in nanoseconds)

Valid Context

Task portionQuasi-task portionTask-independent portion
YESYESYES

Related Service Profile Items

Only when all the service profile items below are set to be effective, this API can be used.

TK_SUPPORT_MICROWAIT Support of micro wait

Description

Performs a micro wait for the specified interval (in nanoseconds).

This wait is usually implemented as a busy loop. This means that the micro wait occurs in the task RUNNING state rather than WAITING state.

The micro wait is easily influenced by the runtime environment, such as execution in RAM, execution in ROM, memory cache on or off, etc. The wait time is therefore not very accurate.