]> begriffs open source - cmsis/blob - CMSIS/Driver/VIO/Source/vio_memory.c
CoreValidation: Fix Arm Compiler 6 linker warnings.
[cmsis] / CMSIS / Driver / VIO / Source / vio_memory.c
1 /******************************************************************************
2  * @file     vio_memory.c
3  * @brief    Virtual I/O implementation using memory only
4  * @version  V1.0.0
5  * @date     23. March 2020
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2019-2020 Arm Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
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
15  *
16  * www.apache.org/licenses/LICENSE-2.0
17  *
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.
23  */
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include "cmsis_vio.h"
29
30 #include "RTE_Components.h"             // Component selection
31 #include CMSIS_device_header
32
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
36 #ifndef VIO_VALUE_NUM
37 #define VIO_VALUE_NUM            3U     // number of values
38 #endif
39 #ifndef VIO_VALUEXYZ_NUM
40 #define VIO_VALUEXYZ_NUM         3U     // number of XYZ values
41 #endif
42 #ifndef VIO_IPV4_ADDRESS_NUM
43 #define VIO_IPV4_ADDRESS_NUM     2U     // number of IPv4 addresses
44 #endif
45 #ifndef VIO_IPV6_ADDRESS_NUM
46 #define VIO_IPV6_ADDRESS_NUM     2U     // number of IPv6 addresses
47 #endif
48
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];
57
58 // Initialize test input, output.
59 void vioInit (void) {
60
61   vioSignalIn  = 0U;
62   vioSignalOut = 0U;
63
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));
69 }
70
71 // Print formated string to test terminal.
72 int32_t vioPrint (uint32_t level, const char *format, ...) {
73   va_list args;
74   int32_t ret;
75
76   if (level > vioLevelError) {
77     return (-1);
78   }
79
80   if (level > VIO_PRINTMEM_NUM) {
81     return (-1);
82   }
83
84   va_start(args, format);
85
86   ret = vsnprintf((char *)vioPrintMem[level], sizeof(vioPrintMem[level]), format, args);
87
88   va_end(args);
89
90   return (ret);
91 }
92
93 // Set signal output.
94 void vioSetSignal (uint32_t mask, uint32_t signal) {
95
96   vioSignalOut &= ~mask;
97   vioSignalOut |=  mask & signal;
98 }
99
100 // Get signal input.
101 uint32_t vioGetSignal (uint32_t mask) {
102   uint32_t signal;
103
104   signal = vioSignalIn;
105
106   return (signal & mask);
107 }
108
109 // Set value output.
110 void vioSetValue (uint32_t id, int32_t value) {
111   uint32_t index = id;
112
113   if (index >= VIO_VALUE_NUM) {
114     return;                             /* return in case of out-of-range index */
115   }
116
117   vioValue[index] = value;
118 }
119
120 // Get value input.
121 int32_t vioGetValue (uint32_t id) {
122   uint32_t index = id;
123   int32_t  value = 0;
124
125   if (index >= VIO_VALUE_NUM) {
126     return value;                       /* return default in case of out-of-range index */
127   }
128
129   value = vioValue[index];
130
131   return value;
132 }
133
134 // Set XYZ value output.
135 void vioSetXYZ (uint32_t id, vioValueXYZ_t valueXYZ) {
136   uint32_t index = id;
137
138   if (index >= VIO_VALUEXYZ_NUM) {
139     return;                             /* return in case of out-of-range index */
140   }
141
142   vioValueXYZ[index] = valueXYZ;
143 }
144
145 // Get XYZ value input.
146 vioValueXYZ_t vioGetXYZ (uint32_t id) {
147   uint32_t index = id;
148   vioValueXYZ_t valueXYZ = {0, 0, 0};
149
150   if (index >= VIO_VALUEXYZ_NUM) {
151     return valueXYZ;                    /* return default in case of out-of-range index */
152   }
153
154   valueXYZ = vioValueXYZ[index];
155
156   return valueXYZ;
157 }
158
159 // Set IPv4 address output.
160 void vioSetIPv4 (uint32_t id, vioAddrIPv4_t addrIPv4) {
161   uint32_t index = id;
162
163   if (index >= VIO_IPV4_ADDRESS_NUM) {
164     return;                             /* return in case of out-of-range index */
165   }
166
167   vioAddrIPv4[index] = addrIPv4;
168 }
169
170 // Get IPv4 address input.
171 vioAddrIPv4_t vioGetIPv4 (uint32_t id) {
172   uint32_t index = id;
173   vioAddrIPv4_t addrIPv4 = {0U, 0U, 0U, 0U};
174
175   if (index >= VIO_IPV4_ADDRESS_NUM) {
176     return addrIPv4;                    /* return default in case of out-of-range index */
177   }
178
179   addrIPv4 = vioAddrIPv4[index];
180
181   return addrIPv4;
182 }
183
184 // Set IPv6 address output.
185 void vioSetIPv6 (uint32_t id, vioAddrIPv6_t addrIPv6) {
186   uint32_t index = id;
187
188   if (index >= VIO_IPV6_ADDRESS_NUM) {
189     return;                             /* return in case of out-of-range index */
190   }
191
192   vioAddrIPv6[index] = addrIPv6;
193 }
194
195 // Get IPv6 address input.
196 vioAddrIPv6_t vioGetIPv6 (uint32_t id) {
197   uint32_t index = id;
198   vioAddrIPv6_t addrIPv6 = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U,
199                             0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U};
200
201   if (index >= VIO_IPV6_ADDRESS_NUM) {
202     return addrIPv6;                    /* return default in case of out-of-range index */
203   }
204
205   addrIPv6 = vioAddrIPv6[index];
206
207   return addrIPv6;
208 }