]> begriffs open source - cmsis/blob - CMSIS/Driver/VIO/Source/vio.c
Possible bugs in MMU_MemorySection(), MMU_MemoryPage() (#219)
[cmsis] / CMSIS / Driver / VIO / Source / vio.c
1 /******************************************************************************
2  * @file     vio.c
3  * @brief    Virtual I/O implementation template
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 #if !defined CMSIS_VOUT || !defined CMSIS_VIN
32 // Add user includes here:
33
34 #endif
35
36 // VIO input, output definitions
37 #define VIO_VALUE_NUM           5U          // Number of values
38
39 // VIO input, output variables
40 __USED uint32_t vioSignalIn;                // Memory for incoming signal
41 __USED uint32_t vioSignalOut;               // Memory for outgoing signal
42 __USED int32_t  vioValue[VIO_VALUE_NUM];    // Memory for value used in vioGetValue/vioSetValue
43
44 #if !defined CMSIS_VOUT
45 // Add global user types, variables, functions here:
46
47 #endif
48
49 #if !defined CMSIS_VIN
50 // Add global user types, variables, functions here:
51
52 #endif
53
54 // Initialize test input, output.
55 void vioInit (void) {
56 #if !defined CMSIS_VOUT
57 // Add user variables here:
58
59 #endif
60 #if !defined CMSIS_VIN
61 // Add user variables here:
62
63 #endif
64
65   vioSignalIn  = 0U;
66   vioSignalOut = 0U;
67
68   memset(vioValue, 0, sizeof(vioValue));
69
70 #if !defined CMSIS_VOUT
71 // Add user code here:
72
73 #endif
74
75 #if !defined CMSIS_VIN
76 // Add user code here:
77
78 #endif
79 }
80
81 // Set signal output.
82 void vioSetSignal (uint32_t mask, uint32_t signal) {
83 #if !defined CMSIS_VOUT
84 // Add user variables here:
85
86 #endif
87
88   vioSignalOut &= ~mask;
89   vioSignalOut |=  mask & signal;
90
91 #if !defined CMSIS_VOUT
92 // Add user code here:
93
94 #endif
95 }
96
97 // Get signal input.
98 uint32_t vioGetSignal (uint32_t mask) {
99   uint32_t signal;
100 #if !defined CMSIS_VIN
101 // Add user variables here:
102
103 #endif
104
105 #if !defined CMSIS_VIN
106 // Add user code here:
107
108 //   vioSignalIn = ...;
109 #endif
110
111   signal = vioSignalIn & mask;
112
113   return signal;
114 }
115
116 // Set value output.
117 void vioSetValue (uint32_t id, int32_t value) {
118   uint32_t index = id;
119 #if !defined CMSIS_VOUT
120 // Add user variables here:
121
122 #endif
123
124   if (index >= VIO_VALUE_NUM) {
125     return;                             /* return in case of out-of-range index */
126   }
127
128   vioValue[index] = value;
129
130 #if !defined CMSIS_VOUT
131 // Add user code here:
132
133 #endif
134 }
135
136 // Get value input.
137 int32_t vioGetValue (uint32_t id) {
138   uint32_t index = id;
139   int32_t  value = 0;
140 #if !defined CMSIS_VIN
141 // Add user variables here:
142
143 #endif
144
145   if (index >= VIO_VALUE_NUM) {
146     return value;                       /* return default in case of out-of-range index */
147   }
148
149 #if !defined CMSIS_VIN
150 // Add user code here:
151
152 //   vioValue[index] = ...;
153 #endif
154
155   value = vioValue[index];
156
157   return value;
158 }