Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define TX_SOURCE_CODE
#include "tx_api.h"
#include "tx_mutex.h"
#include "tx_queue.h"
#include "tx_thread.h"
#include "txm_module.h"
...
_txm_module_manager_external_memory_enable(TXM_MODULE_INSTANCE *, void *, ULONG, UINT)
Files
loading...
CodeScopeSTM32 Libraries and Samplesthreadxports_module/cortex_m4/gnu/module_manager/src/txm_module_manager_external_memory_enable.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** ThreadX Component */ /** */ /** Module Manager */ /** */... /**************************************************************************/ /**************************************************************************/ #define TX_SOURCE_CODE #include "tx_api.h" #include "tx_mutex.h" #include "tx_queue.h" #include "tx_thread.h" #include "txm_module.h" 5 includes ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _txm_module_manager_external_memory_enable Cortex-M4 */ /* 6.1.9 */ /* AUTHOR */ /* */ /* Scott Larson, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function creates an entry in the MPU table for a shared */ /* memory space. */ /* */ /* INPUT */ /* */ /* module_instance Module instance pointer */ /* start_address Start address of memory */ /* length Length of external memory */ /* attributes Memory attributes (r/w) */ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* _tx_mutex_get Get protection mutex */ /* _tx_mutex_put Release protection mutex */ /* _txm_power_of_two_block_size Round length to power of two */ /* _txm_module_manager_mm_register_setup Reconfigure MPU registers */ /* */ /* CALLED BY */ /* */ /* Application code */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 10-15-2021 Scott Larson Initial Version 6.1.9 */ /* */... /**************************************************************************/ UINT _txm_module_manager_external_memory_enable(TXM_MODULE_INSTANCE *module_instance, VOID *start_address, ULONG length, UINT attributes) { #ifdef TXM_MODULE_MANAGER_16_MPU ULONG block_size; ULONG region_size; ULONG srd_bits; ULONG size_register; ULONG address; ULONG shared_index; ULONG attributes_check = 0; /* Determine if the module manager has not been initialized yet. */ if (_txm_module_manager_ready != TX_TRUE) { /* Module manager has not been initialized. */ return(TX_NOT_AVAILABLE); }if (_txm_module_manager_ready != TX_TRUE) { ... } /* Determine if the module is valid. */ if (module_instance == TX_NULL) { /* Invalid module pointer. */ return(TX_PTR_ERROR); }if (module_instance == TX_NULL) { ... } /* Get module manager protection mutex. */ _tx_mutex_get(&_txm_module_manager_mutex, TX_WAIT_FOREVER); /* Determine if the module instance is valid. */ if (module_instance -> txm_module_instance_id != TXM_MODULE_ID) { /* Release the protection mutex. */ _tx_mutex_put(&_txm_module_manager_mutex); /* Invalid module pointer. */ return(TX_PTR_ERROR); }if (module_instance -> txm_module_instance_id != TXM_MODULE_ID) { ... } /* Determine if the module instance is in the loaded state. */ if (module_instance -> txm_module_instance_state != TXM_MODULE_LOADED) { /* Release the protection mutex. */ _tx_mutex_put(&_txm_module_manager_mutex); /* Return error if the module is not ready. */ return(TX_START_ERROR); }if (module_instance -> txm_module_instance_state != TXM_MODULE_LOADED) { ... } /* Determine if there are shared memory entries available. */ if(module_instance -> txm_module_instance_shared_memory_count >= TXM_MODULE_MPU_SHARED_ENTRIES) { /* Release the protection mutex. */ _tx_mutex_put(&_txm_module_manager_mutex); /* No more entries available. */ return(TX_NO_MEMORY); }if (module_instance -> txm_module_instance_shared_memory_count >= TXM_MODULE_MPU_SHARED_ENTRIES) { ... } /* Start address and length must adhere to Cortex-M7 MPU. The address must align with the block size. *//* ... */ block_size = _txm_power_of_two_block_size(length); address = (ULONG) start_address; if(address != (address & ~(block_size - 1))) { /* Release the protection mutex. */ _tx_mutex_put(&_txm_module_manager_mutex); /* Return alignment error. */ return(TXM_MODULE_ALIGNMENT_ERROR); }if (address != (address & ~(block_size - 1))) { ... } /* At this point, we have a valid address and block size. Set up MPU registers. *//* ... */ /* Pick up index into shared memory entries. */ shared_index = TXM_MODULE_MPU_SHARED_INDEX + module_instance -> txm_module_instance_shared_memory_count; /* Save address register with address, MPU region, set Valid bit. */ module_instance -> txm_module_instance_mpu_registers[shared_index].txm_module_mpu_region_address = address | shared_index | 0x10; /* Calculate the region size. */ region_size = (_txm_module_manager_region_size_get(block_size) << 1); /* Calculate the subregion bits. */ srd_bits = _txm_module_manager_calculate_srd_bits(block_size, length); /* Generate SRD, size, and enable attributes. */ size_register = srd_bits | region_size | TXM_ENABLE_REGION | TXM_MODULE_MPU_SHARED_ACCESS_CONTROL; /* Check for optional write attribute. */ if(attributes & TXM_MODULE_MANAGER_SHARED_ATTRIBUTE_WRITE) { attributes_check = TXM_MODULE_MANAGER_ATTRIBUTE_WRITE_MPU_BIT; }if (attributes & TXM_MODULE_MANAGER_SHARED_ATTRIBUTE_WRITE) { ... } /* Save attribute-size register. */ module_instance -> txm_module_instance_mpu_registers[shared_index].txm_module_mpu_region_attribute_size = attributes_check | size_register; /* Keep track of shared memory address and length in module instance. */ module_instance -> txm_module_instance_shared_memory_address[module_instance -> txm_module_instance_shared_memory_count] = address; module_instance -> txm_module_instance_shared_memory_length[module_instance -> txm_module_instance_shared_memory_count] = length; /* Increment counter. */ module_instance -> txm_module_instance_shared_memory_count++; /* Release the protection mutex. */ _tx_mutex_put(&_txm_module_manager_mutex); /* Return success. */ return(TX_SUCCESS); /* ... */ #else ULONG block_size; ULONG region_size; ULONG subregion_bits; ULONG address; UINT attributes_check = 0; TXM_MODULE_PREAMBLE *module_preamble; /* Determine if the module manager has not been initialized yet. */ if (_txm_module_manager_ready != TX_TRUE) { /* Module manager has not been initialized. */ return(TX_NOT_AVAILABLE); }if (_txm_module_manager_ready != TX_TRUE) { ... } /* Determine if the module is valid. */ if (module_instance == TX_NULL) { /* Invalid module pointer. */ return(TX_PTR_ERROR); }if (module_instance == TX_NULL) { ... } /* Get module manager protection mutex. */ _tx_mutex_get(&_txm_module_manager_mutex, TX_WAIT_FOREVER); /* Determine if the module instance is valid. */ if (module_instance -> txm_module_instance_id != TXM_MODULE_ID) { /* Release the protection mutex. */ _tx_mutex_put(&_txm_module_manager_mutex); /* Invalid module pointer. */ return(TX_PTR_ERROR); }if (module_instance -> txm_module_instance_id != TXM_MODULE_ID) { ... } /* Determine if the module instance is in the loaded state. */ if (module_instance -> txm_module_instance_state != TXM_MODULE_LOADED) { /* Release the protection mutex. */ _tx_mutex_put(&_txm_module_manager_mutex); /* Return error if the module is not ready. */ return(TX_START_ERROR); }if (module_instance -> txm_module_instance_state != TXM_MODULE_LOADED) { ... } /* Check if preamble shared mem and mem protection property bits are set. */ module_preamble = module_instance -> txm_module_instance_preamble_ptr; if((module_preamble -> txm_module_preamble_property_flags & (TXM_MODULE_MEMORY_PROTECTION | TXM_MODULE_SHARED_EXTERNAL_MEMORY_ACCESS)) != (TXM_MODULE_MEMORY_PROTECTION | TXM_MODULE_SHARED_EXTERNAL_MEMORY_ACCESS)) { /* Release the protection mutex. */ _tx_mutex_put(&_txm_module_manager_mutex); /* Return error if bit not set. */ return(TXM_MODULE_INVALID_PROPERTIES); }if ((module_preamble -> txm_module_preamble_property_flags & (TXM_MODULE_MEMORY_PROTECTION | TXM_MODULE_SHARED_EXTERNAL_MEMORY_ACCESS)) != (TXM_MODULE_MEMORY_PROTECTION | TXM_MODULE_SHARED_EXTERNAL_MEMORY_ACCESS)) { ... } /* Start address and length must adhere to Cortex-M MPU. The address must align with the block size. *//* ... */ block_size = _txm_power_of_two_block_size(length); address = (ULONG) start_address; if(address != (address & ~(block_size - 1))) { /* Release the protection mutex. */ _tx_mutex_put(&_txm_module_manager_mutex); /* Return alignment error. */ return(TXM_MODULE_ALIGNMENT_ERROR); }if (address != (address & ~(block_size - 1))) { ... } /* At this point, we have a valid address and block size. Set up MPU registers. *//* ... */ module_instance -> txm_module_instance_mpu_registers[TXM_MODULE_MANAGER_SHARED_MPU_INDEX] = address | TXM_MODULE_MANAGER_SHARED_MPU_REGION | 0x10; /* Calculate the region size. */ region_size = (_txm_module_manager_region_size_get(block_size) << 1); /* Calculate the subregion bits. */ subregion_bits = _txm_module_manager_calculate_srd_bits(block_size, length); /* Check for valid attributes. */ if(attributes & TXM_MODULE_MANAGER_SHARED_ATTRIBUTE_WRITE) { attributes_check = TXM_MODULE_MANAGER_ATTRIBUTE_WRITE_MPU_BIT; }if (attributes & TXM_MODULE_MANAGER_SHARED_ATTRIBUTE_WRITE) { ... } /* Build register with attributes. */ module_instance -> txm_module_instance_mpu_registers[TXM_MODULE_MANAGER_SHARED_MPU_INDEX+1] = region_size | subregion_bits | attributes_check | 0x12070001; /* Keep track of shared memory address and length in module instance. */ module_instance -> txm_module_instance_shared_memory_address = address; module_instance -> txm_module_instance_shared_memory_length = length; /* Recalculate MPU settings. */ _txm_module_manager_mm_register_setup(module_instance); /* Release the protection mutex. */ _tx_mutex_put(&_txm_module_manager_mutex); /* Return success. */ return(TX_SUCCESS); /* ... */ #endif }{ ... }