CMSIS-Driver  Version 2.8.0
Peripheral Interface for Middleware and Application Code
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
VIO

API for Virtual I/O (VIO) (cmsis_vio.h) More...

Content

 Defines and Structs
 Documents the defines and structs of the VIO API.
 

Functions

void vioInit (void)
 Initialize test input, output. More...
 
int32_t vioPrint (uint32_t level, const char *format,...)
 Print formated string to test terminal. More...
 
void vioSetSignal (uint32_t mask, uint32_t signal)
 Set signal output. More...
 
uint32_t vioGetSignal (uint32_t mask)
 Get signal input. More...
 
void vioSetValue (uint32_t id, int32_t value)
 Set value output. More...
 
int32_t vioGetValue (uint32_t id)
 Get value input. More...
 
void vioSetXYZ (uint32_t id, vioValueXYZ_t valueXYZ)
 Set XYZ value output. More...
 
vioValueXYZ_t vioGetXYZ (uint32_t id)
 Get XYZ value input. More...
 
void vioSetIPv4 (uint32_t id, vioAddrIPv4_t addrIPv4)
 Set IPv4 address output. More...
 
vioAddrIPv4_t vioGetIPv4 (uint32_t id)
 Get IPv4 address input. More...
 
void vioSetIPv6 (uint32_t id, vioAddrIPv6_t addrIPv6)
 Set IPv6 address output. More...
 
vioAddrIPv6_t vioGetIPv6 (uint32_t id)
 Get IPv6 address from peripheral. More...
 

Description

API for Virtual I/O (VIO) (cmsis_vio.h)

The VIO software component is a virtual I/O abstraction for peripherals that are typically used in example projects. It enables developers to move from an evaluation kit to custom hardware and helps to scale project examples at large to many development boards:

vioRationale.png
Virtual I/O provides a generic API for examples and testing

VIO API

The following header file defines the Application Programming Interface (API) for VIO:

VIO User Code Templates

The VIO software component contains two user code templates with different purposes:

VIO Memory Location Structure

For testing purposes, it is required to have fixed memory locations that are used to read/store values. In the VIO:Virtual template file (vio.c), an exemplary implementation is shown:

// Input, output variables
__USED uint32_t vioSignalIn; // Memory for incoming signal
__USED uint32_t vioSignalOut; // Memory for outgoing signal
__USED char vioPrintMem[VIO_PRINTMEM_NUM][VIO_PRINT_MAX_SIZE]; // Memory for the last value for each level
__USED int32_t vioValue [VIO_VALUE_NUM]; // Memory for value used in vioGetValue/vioSetValue
__USED vioValueXYZ_t vioValueXYZ[VIO_VALUEXYZ_NUM]; // Memory for XYZ value for 3-D vector
__USED vioAddrIPv4_t vioAddrIPv4[VIO_IPV4_ADDRESS_NUM]; // Memory for IPv4 address value used in vioSetIPv4/vioGetIPv4
__USED vioAddrIPv6_t vioAddrIPv6[VIO_IPV6_ADDRESS_NUM]; // Memory for IPv6 address value used in vioSetIPv6/vioGetIPv6

Use these memory locations to monitor or set the variables as required in the application.

Two defines are available that help to disconnect the actual peripherals and enable virtual I/Os: CMSIS_VIN and CMSIS_VOUT. They help to write code that can be used in testing environments without real hardware access. The following implementation example shows such code:

Code Example (VIO Implementation)

// Initialize test input, output.
void vioInit (void) {
uint32_t i;
#if !defined CMSIS_VIN
// Add user variables here:
#endif
#if !defined CMSIS_VOUT
// Add user variables here:
#endif
vioSignalIn = 0U;
vioSignalOut = 0U;
memset (vioPrintMem, 0, sizeof(vioPrintMem));
memset (vioValue, 0, sizeof(vioValue));
memset (vioValueXYZ, 0, sizeof(vioValueXYZ));
memset (vioAddrIPv4, 0, sizeof(vioAddrIPv4));
memset (vioAddrIPv6, 0, sizeof(vioAddrIPv6));
#if !defined CMSIS_VOUT
// Add user code here:
// <code vioInit output>
BSP_LED_Init(LED_BLUE);
BSP_LED_Init(LED_RED);
BSP_LED_Init(LED_GREEN);
// </code>
#endif
#if !defined CMSIS_VIN
// Add user code here:
// <code vioInit input>
BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);
// </code>
#endif
return;
}

Memory display in IDEs

Arm Keil MDK uses the provided SCVD file to display the VIO signals in Component Viewer:

vioComponentViewer.png

Function Documentation

void vioInit ( void  )

Initialize test input, output.

Returns
none.

The function vioInit initializes the VIO interface. Use it to initialize any connected hardware that is used to map VIO signals.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
// System Initialization
SystemCoreClockUpdate();
// ...
}
int32_t vioPrint ( uint32_t  level,
const char *  format,
  ... 
)

Print formated string to test terminal.

Parameters
[in]levellevel (vioLevel...).
[in]formatformated string to print.
[in]...optional arguments (depending on format string).
Returns
number of characters written or -1 in case of error.

The function vioPrint prints a formatted string to a test terminal. Formatting of the output follows the rules of standard C language printf().

Refer to Print Levels for information about the possible levels.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
int x = 3;
vioPrint(vioLevelNone, "Test [None]");
vioPrint(vioLevelHeading, "Test [Heading] = Network Connector Message");
vioPrint(vioLevelMessage, "Test [Message] = Connection failed");
vioPrint(vioLevelError, "Test [Error] = %d", x);
}
void vioSetSignal ( uint32_t  mask,
uint32_t  signal 
)

Set signal output.

Parameters
[in]maskbit mask of signals to set.
[in]signalsignal value to set.
Returns
none.

The function vioSetSignal set a signal to an output specified by mask. Use this function to map VIOs to actual hardware for displaying signals on a target board.

Refer to Signals for information about the possible mask and signal values.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
// ...
}
uint32_t vioGetSignal ( uint32_t  mask)

Get signal input.

Parameters
[in]maskbit mask of signals to read.
Returns
signal value.

The function vioGetSignal retrieves a signal from an input identified by mask. Use this function to read data from any input that is provided.

Refer to Signals for information about the possible mask values.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
uint32_t state;
uint32_t last = 0U;
for (;;) {
state = (vioGetSignal (vioBUTTON0)); // Get pressed button state
if (state != last){
if (state == vioBUTTON0){
// do something
}
}
last = state;
}
}
void vioSetValue ( uint32_t  id,
int32_t  value 
)

Set value output.

Parameters
[in]idoutput identifier.
[in]valuevalue to set.
Returns
none.

The function vioSetValue set the value to the output identified by id. Use this function to set states of I/Os for example.

Refer to Values for information about value and IDs for id.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
}
int32_t vioGetValue ( uint32_t  id)

Get value input.

Parameters
[in]idinput identifier.
Returns
value retrieved from input.

The function vioGetValue retrieves a value from the input identified by id. Use this function to read data from inputs.

Refer to IDs for information about id.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
uint32_t button;
}
void vioSetXYZ ( uint32_t  id,
vioValueXYZ_t  valueXYZ 
)

Set XYZ value output.

Parameters
[in]idoutput identifier.
[in]valueXYZXYZ data to set.
Returns
none.

The function vioSetXYZ sets a three-dimensional value valueXYZ to the output identified by id. Use this function to apply a 3d value to an output.

Refer to Values for information about the valueXYZ and IDs for id.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
vioValueXYZ_t xyz = {123, 456, 789};
vioSetXYZ(0, xyz);
}
vioValueXYZ_t vioGetXYZ ( uint32_t  id)

Get XYZ value input.

Parameters
[in]idinput identifier.
Returns
XYZ data retrieved from XYZ peripheral.

The function vioGetXYZ retrieves a three-dimensional value from the input identified by id. Use this function to get a 3d value.

Refer to IDs for information about id.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
volatile vioValueXYZ_t xyz;
}
void vioSetIPv4 ( uint32_t  id,
vioAddrIPv4_t  addrIPv4 
)

Set IPv4 address output.

Parameters
[in]idoutput identifier.
[in]addrIPv4pointer to IPv4 address.
Returns
none.

The function vioSetIPv4 sets an IPv4 address specified by addrIPv4 to an interface identified by id. Use this function to assign an IPv4 address to an interface.

Refer to IDs for information about id and IP Addresses for addrIPv4.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
vioAddrIPv4_t addrIPv4 = {192U, 168U, 111U, 123U};
vioSetIPv4 (0, addrIPv4);
}
vioAddrIPv4_t vioGetIPv4 ( uint32_t  id)

Get IPv4 address input.

Parameters
[in]idinput identifier.
Returns
IPv4 address retrieved from peripheral.

The function vioGetIPv4 retrieves the IPv4 addrIPv4 from an interface identified by id. Use this function to read an IPv4 address.

Refer to IDs for information about id.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
vioAddrIPv4_t addrIPv4;
addrIPv4 = vioGetIPv4(0);
}
void vioSetIPv6 ( uint32_t  id,
vioAddrIPv6_t  addrIPv6 
)

Set IPv6 address output.

Parameters
[in]idoutput identifier.
[in]addrIPv6pointer to IPv6 address.
Returns
none.

The function vioSetIPv6 sets an IPv6 address specified by addrIPv6 to an interface identified by id. Use this function to assign an IPv6 address to an interface.

Refer to IDs for information about id and IP Addresses for addrIPv6.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
vioAddrIPv6_t addrIPv6 = {1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U,
9U, 10U, 11U, 12U, 13U, 14U, 15U, 16U};
vioSetIPv6 (0, addrIPv6);
}
vioAddrIPv6_t vioGetIPv6 ( uint32_t  id)

Get IPv6 address from peripheral.

Parameters
[in]idinput identifier.
Returns
IPv6 address retrieved from peripheral.

The function vioGetIPv6 retrieves the IPv6 addrIPv6 from an interface identified by id. Use this function to read an IPv6 address.

Refer to IDs for information about id.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
vioAddrIPv6_t addrIPv6;
addrIPv6 = vioGetIPv6(0);
}