1 /******************************************************************************
3 * @brief Virtual I/O implementation using memory only
6 ******************************************************************************/
8 * Copyright (c) 2019-2020 Arm Limited. All rights reserved.
10 * SPDX-License-Identifier: Apache-2.0
12 * Licensed under the Apache License, Version 2.0 (the License); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
28 #include "cmsis_vio.h"
30 #include "RTE_Components.h" // Component selection
31 #include CMSIS_device_header
33 // VIO input, output definitions
34 #define VIO_PRINT_MAX_SIZE 64U // maximum size of print memory
35 #define VIO_PRINTMEM_NUM 4U // number of print memories
37 #define VIO_VALUE_NUM 3U // number of values
39 #ifndef VIO_VALUEXYZ_NUM
40 #define VIO_VALUEXYZ_NUM 3U // number of XYZ values
42 #ifndef VIO_IPV4_ADDRESS_NUM
43 #define VIO_IPV4_ADDRESS_NUM 2U // number of IPv4 addresses
45 #ifndef VIO_IPV6_ADDRESS_NUM
46 #define VIO_IPV6_ADDRESS_NUM 2U // number of IPv6 addresses
49 // VIO input, output variables
50 __USED uint32_t vioSignalIn;
51 __USED uint32_t vioSignalOut;
52 __USED char vioPrintMem[VIO_PRINTMEM_NUM][VIO_PRINT_MAX_SIZE];
53 __USED int32_t vioValue [VIO_VALUE_NUM];
54 __USED vioValueXYZ_t vioValueXYZ[VIO_VALUEXYZ_NUM];
55 __USED vioAddrIPv4_t vioAddrIPv4[VIO_IPV4_ADDRESS_NUM];
56 __USED vioAddrIPv6_t vioAddrIPv6[VIO_IPV6_ADDRESS_NUM];
58 // Initialize test input, output.
64 memset (vioPrintMem, 0, sizeof(vioPrintMem));
65 memset (vioValue, 0, sizeof(vioValue));
66 memset (vioValueXYZ, 0, sizeof(vioValueXYZ));
67 memset (vioAddrIPv4, 0, sizeof(vioAddrIPv4));
68 memset (vioAddrIPv6, 0, sizeof(vioAddrIPv6));
71 // Print formated string to test terminal.
72 int32_t vioPrint (uint32_t level, const char *format, ...) {
76 if (level > vioLevelError) {
80 if (level > VIO_PRINTMEM_NUM) {
84 va_start(args, format);
86 ret = vsnprintf((char *)vioPrintMem[level], sizeof(vioPrintMem[level]), format, args);
94 void vioSetSignal (uint32_t mask, uint32_t signal) {
96 vioSignalOut &= ~mask;
97 vioSignalOut |= mask & signal;
101 uint32_t vioGetSignal (uint32_t mask) {
104 signal = vioSignalIn;
106 return (signal & mask);
110 void vioSetValue (uint32_t id, int32_t value) {
113 if (index >= VIO_VALUE_NUM) {
114 return; /* return in case of out-of-range index */
117 vioValue[index] = value;
121 int32_t vioGetValue (uint32_t id) {
125 if (index >= VIO_VALUE_NUM) {
126 return value; /* return default in case of out-of-range index */
129 value = vioValue[index];
134 // Set XYZ value output.
135 void vioSetXYZ (uint32_t id, vioValueXYZ_t valueXYZ) {
138 if (index >= VIO_VALUEXYZ_NUM) {
139 return; /* return in case of out-of-range index */
142 vioValueXYZ[index] = valueXYZ;
145 // Get XYZ value input.
146 vioValueXYZ_t vioGetXYZ (uint32_t id) {
148 vioValueXYZ_t valueXYZ = {0, 0, 0};
150 if (index >= VIO_VALUEXYZ_NUM) {
151 return valueXYZ; /* return default in case of out-of-range index */
154 valueXYZ = vioValueXYZ[index];
159 // Set IPv4 address output.
160 void vioSetIPv4 (uint32_t id, vioAddrIPv4_t addrIPv4) {
163 if (index >= VIO_IPV4_ADDRESS_NUM) {
164 return; /* return in case of out-of-range index */
167 vioAddrIPv4[index] = addrIPv4;
170 // Get IPv4 address input.
171 vioAddrIPv4_t vioGetIPv4 (uint32_t id) {
173 vioAddrIPv4_t addrIPv4 = {0U, 0U, 0U, 0U};
175 if (index >= VIO_IPV4_ADDRESS_NUM) {
176 return addrIPv4; /* return default in case of out-of-range index */
179 addrIPv4 = vioAddrIPv4[index];
184 // Set IPv6 address output.
185 void vioSetIPv6 (uint32_t id, vioAddrIPv6_t addrIPv6) {
188 if (index >= VIO_IPV6_ADDRESS_NUM) {
189 return; /* return in case of out-of-range index */
192 vioAddrIPv6[index] = addrIPv6;
195 // Get IPv6 address input.
196 vioAddrIPv6_t vioGetIPv6 (uint32_t id) {
198 vioAddrIPv6_t addrIPv6 = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U,
199 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U};
201 if (index >= VIO_IPV6_ADDRESS_NUM) {
202 return addrIPv6; /* return default in case of out-of-range index */
205 addrIPv6 = vioAddrIPv6[index];