1 /******************************************************************************
2  * @file     vio_memory.c
3  * @brief    Virtual I/O implementation using memory only
4  * @version  V1.0.0
5  * @date     24. May 2023
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2019-2023 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 <string.h>
26 #include "cmsis_vio.h"
27 
28 #include "RTE_Components.h"                 // Component selection
29 #include CMSIS_device_header
30 
31 // VIO input, output definitions
32 #ifndef VIO_VALUE_NUM
33 #define VIO_VALUE_NUM           5U          // Number of values
34 #endif
35 
36 // VIO input, output variables
37 __USED uint32_t vioSignalIn;                // Memory for incoming signal
38 __USED uint32_t vioSignalOut;               // Memory for outgoing signal
39 __USED int32_t  vioValue[VIO_VALUE_NUM];    // Memory for value used in vioGetValue/vioSetValue
40 
41 // Initialize test input, output.
vioInit(void)42 void vioInit (void) {
43 
44   vioSignalIn  = 0U;
45   vioSignalOut = 0U;
46 
47   memset(vioValue, 0, sizeof(vioValue));
48 }
49 
50 // Set signal output.
vioSetSignal(uint32_t mask,uint32_t signal)51 void vioSetSignal (uint32_t mask, uint32_t signal) {
52 
53   vioSignalOut &= ~mask;
54   vioSignalOut |=  mask & signal;
55 }
56 
57 // Get signal input.
vioGetSignal(uint32_t mask)58 uint32_t vioGetSignal (uint32_t mask) {
59   uint32_t signal;
60 
61   signal = vioSignalIn & mask;
62 
63   return signal;
64 }
65 
66 // Set value output.
vioSetValue(uint32_t id,int32_t value)67 void vioSetValue (uint32_t id, int32_t value) {
68   uint32_t index = id;
69 
70   if (index >= VIO_VALUE_NUM) {
71     return;                             /* return in case of out-of-range index */
72   }
73 
74   vioValue[index] = value;
75 }
76 
77 // Get value input.
vioGetValue(uint32_t id)78 int32_t vioGetValue (uint32_t id) {
79   uint32_t index = id;
80   int32_t  value = 0;
81 
82   if (index >= VIO_VALUE_NUM) {
83     return value;                       /* return default in case of out-of-range index */
84   }
85 
86   value = vioValue[index];
87 
88   return value;
89 }
90