| CMSIS-Driver Peripheral Interface for Middleware and Application Code |

Loading...
Searching...
No Matches
Content | Functions
VIO

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

## Content
| Signals
| Signal related defines.
| Value IDs
| Value Identifier related defines.

## Functions
void | vioInit (void)
| Initialize test input, output.
void | vioSetSignal (uint32_t mask, uint32_t signal)
| Set signal output.
uint32_t | vioGetSignal (uint32_t mask)
| Get signal input.
void | vioSetValue (uint32_t id, int32_t value)
| Set value output.
int32_t | vioGetValue (uint32_t id)
| Get value input.

## 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:

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:

- cmsis_vio.h : API for VIO

VIO User Code Templates

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

- VIO:Custom: This file is an empty stub with all functions that are defined in the header file that can be used to implement the VIO layer for the hardware that is used in the application.
- VIO:Virtual: This file uses a fixed memory location to emulate the VIO functionality and can be used off-the-shelf.

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 int32_t vioValue[VIO_VALUE_NUM]; // Memory for value used in vioGetValue/vioSetValue

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) {
#if !defined CMSIS_VIN
// Add user variables here:
#endif
#if !defined CMSIS_VOUT
// Add user variables here:
#endif
vioSignalIn = 0U;
vioSignalOut = 0U;
memset(vioValue, 0, sizeof(vioValue));
#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;
}
vioInit
void vioInit(void)
Initialize test input, output.
Definition: VIO.txt:135

Memory display in IDEs

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

## Function Documentation

## ◆ vioInit()

void vioInit | ( | void |  | ) |

Initialize test input, output.

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();
vioInit();
// ...
}
cmsis_vio.h

## ◆ vioSetSignal()

void vioSetSignal | ( | uint32_t | mask,
|  | uint32_t | signal
| ) |  |

Set signal output.

Parameters

  [in] | mask | bit mask of signals to set.
  [in] | signal | signal value to set.

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) {
vioInit();
vioSetSignal(vioLED0, vioLEDon);
// ...
vioSetSignal(vioLED0, vioLEDoff);
}
vioLED0
#define vioLED0
vioSetSignal mask parameter: LED 0 (for 3-color: red)
vioLEDoff
#define vioLEDoff
vioSetSignal signal parameter: pattern to turn any LED off
vioLEDon
#define vioLEDon
vioSetSignal signal parameter: pattern to turn any LED on
vioSetSignal
void vioSetSignal(uint32_t mask, uint32_t signal)
Set signal output.
Definition: VIO.txt:157

## ◆ vioGetSignal()

uint32_t vioGetSignal | ( | uint32_t | mask | ) |

Get signal input.

Parameters

  [in] | mask | bit 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;
vioInit();
for (;;) {
state = (vioGetSignal (vioBUTTON0)); // Get pressed button state
if (state != last){
if (state == vioBUTTON0){
// do something
}
}
last = state;
}
}
vioBUTTON0
#define vioBUTTON0
vioGetSignal mask parameter: Push button 0
vioGetSignal
uint32_t vioGetSignal(uint32_t mask)
Get signal input.
Definition: VIO.txt:180

## ◆ vioSetValue()

void vioSetValue | ( | uint32_t | id,
|  | int32_t | value
| ) |  |

Set value output.

Parameters

  [in] | id | output identifier.
  [in] | value | value to set.

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 Value IDs for information about id.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
vioInit();
vioSetValue(vioAOUT0, 1024);
}
vioAOUT0
#define vioAOUT0
vioSetValue / vioGetValue id parameter: Analog output value 0
vioSetValue
void vioSetValue(uint32_t id, int32_t value)
Set value output.
Definition: VIO.txt:213

## ◆ vioGetValue()

int32_t vioGetValue | ( | uint32_t | id | ) |

Get value input.

Parameters

  [in] | id | input 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 Value IDs for information about id.

Code Example:

#include "cmsis_vio.h" // ::CMSIS Driver:VIO
int main (void) {
uint32_t button;
vioInit();
button = vioGetValue(vioBUTTON0);
}
vioGetValue
int32_t vioGetValue(uint32_t id)
Get value input.
Definition: VIO.txt:234