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 system call can be used.

TK_SUPPORT_IOPORT I/O port access support functions

Description

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

Difference from μT-Kernel 1.0

This API was not in the older μT-Kernel specification, but, with the introduction of service profile mechanism, this API can now be used when the profile permits it.

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 system call can be used.

TK_SUPPORT_IOPORT I/O port access support functions

Description

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

Difference from μT-Kernel 1.0

This API was not in the older μT-Kernel specification, but, with the introduction of service profile mechanism, this API can now be used when the profile permits it.

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 system call can be used.

TK_SUPPORT_IOPORT I/O port access support functions

Description

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

Difference from μT-Kernel 1.0

This API was not in the older μT-Kernel specification, but, with the introduction of service profile mechanism, this API can now be used when the profile permits it.

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 system call can be used.

TK_SUPPORT_IOPORT I/O port access support functions
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.

Difference from μT-Kernel 1.0

New API introduced based on T-Kernel 2.0 specification

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 system call can be used.

TK_SUPPORT_IOPORT I/O port access support functions

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.

Difference from μT-Kernel 1.0

This API was not in the older μT-Kernel specification, but, with the introduction of service profile mechanism, this API can now be used when the profile permits it.

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 system call can be used.

TK_SUPPORT_IOPORT I/O port access support functions

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.

Difference from μT-Kernel 1.0

This API was not in the older μT-Kernel specification, but, with the introduction of service profile mechanism, this API can now be used when the profile permits it.

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 system call can be used.

TK_SUPPORT_IOPORT I/O port access support functions

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.

Difference from μT-Kernel 1.0

This API was not in the older μT-Kernel specification, but, with the introduction of service profile mechanism, this API can now be used when the profile permits it.

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 system call can be used.

TK_SUPPORT_IOPORT I/O port access support functions
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.

Difference from μT-Kernel 1.0

New API introduced based on T-Kernel 2.0 specification

Micro Wait

WaitUsec - Micro Wait (in Microseconds)

C Language Interface

#include <tk/tkernel.h>

void WaitUsec (UW usec );

Parameter

UW usec Micro SecondsWait time (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 system call 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.

Difference from T-Kernel 2.0

The data type of usec has been changed from UINT to UW.

Difference from μT-Kernel 1.0

This API was not in the older μT-Kernel specification, but, with the introduction of service profile mechanism, this API can now be used when the profile permits it.

WaitNsec - Micro Wait (in Nanoseconds)

C Language Interface

#include <tk/tkernel.h>

void WaitNsec (UW nsec );

Parameter

UW nsec NanosecondsWait time (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 system call 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.

Difference from T-Kernel 2.0

The data type of nsec has been changed from UINT to UW.

Difference from μT-Kernel 1.0

This API was not in the older μT-Kernel specification, but, with the introduction of service profile mechanism, this API can now be used when the profile permits it.