1 /***************************************************************************//**
2 * \file cy_prot.c
3 * \version 1.60
4 *
5 * \brief
6 * Provides an API implementation of the Protection Unit driver
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2016-2020 Cypress Semiconductor Corporation
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25
26 #include "cy_device.h"
27
28 #if defined (CY_IP_M4CPUSS)
29
30 #include "cy_prot.h"
31
32 #if defined(CY_DEVICE_SECURE) && defined(CY_DEVICE_PSOC6ABLE2)
33 #include "cy_pra.h"
34 #endif /* defined(CY_DEVICE_SECURE) && defined(CY_DEVICE_PSOC6ABLE2) */
35
36 #if defined(__cplusplus)
37 extern "C" {
38 #endif
39
40 static bool Prot_IsSmpuStructDisabled(uint32_t smpuStcIndex);
41 static bool Prot_IsPpuProgStructDisabled(uint32_t ppuStcIndex);
42 static cy_en_prot_status_t Prot_ConfigPpuAtt(volatile uint32_t * reg, uint16_t pcMask,
43 cy_en_prot_perm_t userPermission, cy_en_prot_perm_t privPermission, bool secure);
44
45 /* Define to enable all attributes for SMPU slave structure */
46 #define PROT_SMPU_STRUCT_ATT0_ENABLE_ALL_MASK (PROT_SMPU_SMPU_STRUCT_ATT0_UR_Msk | \
47 PROT_SMPU_SMPU_STRUCT_ATT0_UW_Msk | \
48 PROT_SMPU_SMPU_STRUCT_ATT0_UX_Msk | \
49 PROT_SMPU_SMPU_STRUCT_ATT0_PR_Msk | \
50 PROT_SMPU_SMPU_STRUCT_ATT0_PW_Msk | \
51 PROT_SMPU_SMPU_STRUCT_ATT0_PX_Msk | \
52 PROT_SMPU_SMPU_STRUCT_ATT0_NS_Msk)
53
54 /* Define to enable all attributes for programmable PPU slave structure */
55 #define PROT_PERI_PPU_PR_ATT0_ENABLE_ALL_MASK (PERI_PPU_PR_ATT0_UR_Msk | \
56 PERI_PPU_PR_ATT0_UW_Msk | \
57 PERI_PPU_PR_ATT0_UX_Msk | \
58 PERI_PPU_PR_ATT0_PR_Msk | \
59 PERI_PPU_PR_ATT0_PW_Msk | \
60 PERI_PPU_PR_ATT0_PX_Msk | \
61 PERI_PPU_PR_ATT0_NS_Msk)
62
63 #define PROT_PERI_PPU_PROG_PC1_PC3_MASK (0xffffffe0UL) /* PC1 - PC3 bits mask */
64
65 /*******************************************************************************
66 * Function Name: Cy_Prot_ConfigBusMaster
67 ****************************************************************************//**
68 *
69 * Configures the allowed protection contexts, security (secure/non-secure)
70 * and privilege level of the bus transaction created by the specified master.
71 *
72 * \note This function is applicable for both CPUSS ver_1 and ver_2.
73 *
74 * \param busMaster
75 * Indicates which master needs to be configured. Refer to the CPUSS_MS_ID_X
76 * defines in the device config header file.
77 *
78 * \param privileged
79 * Boolean to define the privilege level of all subsequent bus transfers.
80 * True - privileged, False - not privileged.
81 * Note that this is an inherited value. If not inherited, then this bit will
82 * be used.
83 *
84 * \param secure
85 * Security setting for the master. True - Secure, False - Not secure.
86 *
87 * \param pcMask
88 * This is a 16 bit value of the allowed contexts, it is an OR'ed (|) field of the
89 * provided defines in cy_prot.h. For example: (CY_PROT_PCMASK1 | CY_PROT_PCMASK3 | CY_PROT_PCMASK4)
90 * \note The function accepts pcMask values from CY_PROT_PCMASK1 to CY_PROT_PCMASK15.
91 * But each device has its own number of available protection contexts.
92 * That number is defined by PERI_PC_NR in the config file.
93 *
94 * \return
95 * Status of the function call.
96 *
97 * Status | Description
98 * ------------ | -----------
99 * CY_PROT_SUCCESS | The function completed successfully.
100 * CY_PROT_FAILURE | The resource is locked.
101 *
102 * \funcusage
103 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigBusMaster
104 *
105 *******************************************************************************/
Cy_Prot_ConfigBusMaster(en_prot_master_t busMaster,bool privileged,bool secure,uint32_t pcMask)106 cy_en_prot_status_t Cy_Prot_ConfigBusMaster(en_prot_master_t busMaster, bool privileged, bool secure, uint32_t pcMask)
107 {
108 cy_en_prot_status_t status = CY_PROT_SUCCESS;
109 uint32_t regVal;
110 volatile uint32_t *addrMsCtl; /* addrMsCtl is pointer to a register that is volatile by
111 * nature as can be changed outside of firmware control.
112 */
113
114 CY_ASSERT_L1(CY_PROT_IS_BUS_MASTER_VALID(busMaster));
115 CY_ASSERT_L2(CY_PROT_IS_PC_MASK_VALID(pcMask));
116
117 /* Get the address of Master x protection context control register (MSx_CTL) */
118 addrMsCtl = (uint32_t *)(CY_PROT_BASE + (uint32_t)((uint32_t)busMaster << CY_PROT_MSX_CTL_SHIFT));
119
120 /* Get bitfields for MSx_CTL */
121 regVal = _VAL2FLD(PROT_SMPU_MS0_CTL_NS, !secure) /* Security setting */
122 | _VAL2FLD(PROT_SMPU_MS0_CTL_P, privileged) /* Privileged setting */
123 | _VAL2FLD(PROT_SMPU_MS0_CTL_PC_MASK_15_TO_1, pcMask); /* Protection context mask */
124
125 /* Set the value of MSx_CTL */
126 *addrMsCtl = regVal;
127
128 /* Check if the MSx_CTL register is successfully updated with the new register value.
129 * The register will not be updated for the invalid master-protection context.
130 */
131 status = (*addrMsCtl != regVal) ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
132
133 return status;
134 }
135
136
137 /*******************************************************************************
138 * Function Name: Cy_Prot_SetActivePC
139 ****************************************************************************//**
140 *
141 * Sets the current/active protection context of the specified bus master.
142 *
143 * Allowed PC values are 1-15. If this value is not inherited from another bus
144 * master, the value set through this function is used.
145 *
146 * \note This function is applicable for both CPUSS ver_1 and ver_2.
147 *
148 * \note The function does not have access and returns an error for the secure
149 * CYB06xx7 devices.
150 *
151 * \param busMaster
152 * The bus master to configure. Refer to the CPUSS_MS_ID_X defines in the device
153 * config header file.
154 *
155 * \param pc
156 * Active protection context of the specified master \ref cy_en_prot_pc_t.
157 * \note that only those protection contexts allowed by the pcMask (which was
158 * configured in \ref Cy_Prot_ConfigBusMaster) will take effect.
159 * \note The function accepts pcMask values from CY_PROT_PC1 to CY_PROT_PC15.
160 * But each device has its own number of available protection contexts.
161 * That number is defined by PERI_PC_NR in the config file.
162 *
163 * \return
164 * Status of the function call.
165 *
166 * Status | Description
167 * ------------ | -----------
168 * CY_PROT_SUCCESS | The function completed successfully.
169 * CY_PROT_FAILURE | The resource is locked.
170 *
171 * \funcusage
172 * \snippet prot/snippet/main.c snippet_Cy_Prot_SetActivePC
173 *
174 *******************************************************************************/
Cy_Prot_SetActivePC(en_prot_master_t busMaster,uint32_t pc)175 cy_en_prot_status_t Cy_Prot_SetActivePC(en_prot_master_t busMaster, uint32_t pc)
176 {
177 cy_en_prot_status_t status;
178
179 CY_ASSERT_L1(CY_PROT_IS_BUS_MASTER_VALID(busMaster));
180 CY_ASSERT_L2(CY_PROT_IS_PC_VALID(pc));
181
182 #if CY_CPU_CORTEX_M4 && defined(CY_DEVICE_SECURE) && defined(CY_DEVICE_PSOC6ABLE2)
183 status = CY_PROT_UNAVAILABLE;
184 CY_UNUSED_PARAMETER(busMaster);
185 CY_UNUSED_PARAMETER(pc);
186 #else
187 PROT_MPU_MS_CTL(busMaster) = _VAL2FLD(PROT_MPU_MS_CTL_PC, pc) | _VAL2FLD(PROT_MPU_MS_CTL_PC_SAVED, pc);
188 status = (_FLD2VAL(PROT_MPU_MS_CTL_PC, PROT_MPU_MS_CTL(busMaster)) != pc) ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
189 #endif
190
191 return status;
192 }
193
194
195 /*******************************************************************************
196 * Function Name: Cy_Prot_GetActivePC
197 ****************************************************************************//**
198 *
199 * \note This function is applicable for both CPUSS ver_1 and ver_2.
200 *
201 * Returns the active protection context of a master.
202 *
203 * \param busMaster
204 * The bus master, whose protection context is being read. Refer to the
205 * CPUSS_MS_ID_X defines in the device config header file.
206 *
207 * \return
208 * Active protection context of the master \ref cy_en_prot_pc_t.
209 *
210 * \funcusage
211 * \snippet prot/snippet/main.c snippet_Cy_Prot_SetActivePC
212 *
213 *******************************************************************************/
Cy_Prot_GetActivePC(en_prot_master_t busMaster)214 uint32_t Cy_Prot_GetActivePC(en_prot_master_t busMaster)
215 {
216 CY_ASSERT_L1(CY_PROT_IS_BUS_MASTER_VALID(busMaster));
217
218 #if CY_CPU_CORTEX_M4 && defined(CY_DEVICE_SECURE) && defined(CY_DEVICE_PSOC6ABLE2)
219 return ((uint32_t)_FLD2VAL(PROT_MPU_MS_CTL_PC, CY_PRA_REG32_GET((CY_PRA_INDX_PROT_MPU_MS_CTL + (uint16_t) busMaster))));
220 #else
221 return ((uint32_t)_FLD2VAL(PROT_MPU_MS_CTL_PC, PROT_MPU_MS_CTL(busMaster)));
222 #endif
223 }
224
225
226 /*******************************************************************************
227 * Function Name: Cy_Prot_ConfigMpuStruct
228 ****************************************************************************//**
229 *
230 * This function configures a memory protection unit (MPU) struct with its
231 * protection attributes.
232 *
233 * The protection structs act like the gatekeepers for a master's accesses to
234 * memory, allowing only the permitted transactions to go through.
235 *
236 * \note This function is applicable for both CPUSS ver_1 and ver_2.
237 *
238 * \param base
239 * The base address for the MPU struct being configured.
240 *
241 * \param config
242 * Initialization structure containing all the protection attributes.
243 *
244 * \return
245 * Status of the function call.
246 *
247 * Status | Description
248 * ------------ | -----------
249 * CY_PROT_SUCCESS | The MPU struct was configured.
250 * CY_PROT_FAILURE | Configuration failed due to a protection violation.
251 *
252 * \funcusage
253 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigMpuStruct
254 *
255 *******************************************************************************/
Cy_Prot_ConfigMpuStruct(PROT_MPU_MPU_STRUCT_Type * base,const cy_stc_mpu_cfg_t * config)256 cy_en_prot_status_t Cy_Prot_ConfigMpuStruct(PROT_MPU_MPU_STRUCT_Type* base, const cy_stc_mpu_cfg_t* config)
257 {
258 cy_en_prot_status_t status;
259 uint32_t addrReg;
260 uint32_t attReg;
261
262 CY_ASSERT_L1(NULL != base);
263 CY_ASSERT_L3(CY_PROT_IS_MPU_PERM_VALID(config->userPermission));
264 CY_ASSERT_L3(CY_PROT_IS_MPU_PERM_VALID(config->privPermission));
265 CY_ASSERT_L3(CY_PROT_IS_REGION_SIZE_VALID(config->regionSize));
266
267 addrReg = _VAL2FLD(PROT_MPU_MPU_STRUCT_ADDR_SUBREGION_DISABLE, config->subregions)
268 | _VAL2FLD(PROT_MPU_MPU_STRUCT_ADDR_ADDR24, (uint32_t)((uint32_t)config->address >> CY_PROT_ADDR_SHIFT));
269 attReg = ((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK)
270 | (((uint32_t)config->privPermission & CY_PROT_ATT_PERMISSION_MASK) << CY_PROT_ATT_PRIV_PERMISSION_SHIFT)
271 | _VAL2FLD(PROT_MPU_MPU_STRUCT_ATT_NS, !(config->secure))
272 | _VAL2FLD(PROT_MPU_MPU_STRUCT_ATT_REGION_SIZE, config->regionSize);
273 PROT_MPU_MPU_STRUCT_ATT(base) = attReg;
274 PROT_MPU_MPU_STRUCT_ADDR(base) = addrReg;
275 status = ((PROT_MPU_MPU_STRUCT_ADDR(base) != addrReg) || (PROT_MPU_MPU_STRUCT_ATT(base) != attReg)) ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
276
277 return status;
278 }
279
280
281 /*******************************************************************************
282 * Function Name: Cy_Prot_EnableMpuStruct
283 ****************************************************************************//**
284 *
285 * Enables the MPU struct, which allows the MPU protection attributes to
286 * take effect.
287 *
288 * \note This function is applicable for both CPUSS ver_1 and ver_2.
289 *
290 * \param base
291 * The base address of the MPU struct being configured.
292 *
293 * \return
294 * Status of the function call.
295 *
296 * Status | Description
297 * ------------ | -----------
298 * CY_PROT_SUCCESS | The MPU struct was enabled.
299 * CY_PROT_FAILURE | The MPU struct is disabled and possibly locked.
300 *
301 * \funcusage
302 * \snippet prot/snippet/main.c snippet_Cy_Prot_EnableMpuStruct
303 *
304 *******************************************************************************/
Cy_Prot_EnableMpuStruct(PROT_MPU_MPU_STRUCT_Type * base)305 cy_en_prot_status_t Cy_Prot_EnableMpuStruct(PROT_MPU_MPU_STRUCT_Type* base)
306 {
307 cy_en_prot_status_t status;
308
309 CY_ASSERT_L1(NULL != base);
310
311 PROT_MPU_MPU_STRUCT_ATT(base) |= _VAL2FLD(PROT_MPU_MPU_STRUCT_ATT_ENABLED, CY_PROT_STRUCT_ENABLE);
312 status = (_FLD2VAL(PROT_MPU_MPU_STRUCT_ATT_ENABLED, PROT_MPU_MPU_STRUCT_ATT(base)) != CY_PROT_STRUCT_ENABLE) ?
313 CY_PROT_FAILURE : CY_PROT_SUCCESS;
314
315 return status;
316 }
317
318
319 /*******************************************************************************
320 * Function Name: Cy_Prot_DisableMpuStruct
321 ****************************************************************************//**
322 *
323 * Disables the MPU struct, which prevents the MPU protection attributes
324 * from taking effect.
325 *
326 * \note This function is applicable for both CPUSS ver_1 and ver_2.
327 *
328 * \param base
329 * The base address of the MPU struct being configured.
330 *
331 * \return
332 * Status of the function call.
333 *
334 * Status | Description
335 * ------------ | -----------
336 * CY_PROT_SUCCESS | The MPU struct was disabled.
337 * CY_PROT_FAILURE | The MPU struct is enabled and possibly locked.
338 *
339 * \funcusage
340 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisableMpuStruct
341 *
342 *******************************************************************************/
Cy_Prot_DisableMpuStruct(PROT_MPU_MPU_STRUCT_Type * base)343 cy_en_prot_status_t Cy_Prot_DisableMpuStruct(PROT_MPU_MPU_STRUCT_Type* base)
344 {
345 cy_en_prot_status_t status;
346
347 CY_ASSERT_L1(NULL != base);
348
349 PROT_MPU_MPU_STRUCT_ATT(base) &= ~_VAL2FLD(PROT_MPU_MPU_STRUCT_ATT_ENABLED, CY_PROT_STRUCT_ENABLE);
350 status = (_FLD2VAL(PROT_MPU_MPU_STRUCT_ATT_ENABLED, PROT_MPU_MPU_STRUCT_ATT(base)) == CY_PROT_STRUCT_ENABLE) ?
351 CY_PROT_FAILURE : CY_PROT_SUCCESS;
352
353 return status;
354 }
355
356
357 /*******************************************************************************
358 * Function Name: Cy_Prot_ConfigSmpuMasterStruct
359 ****************************************************************************//**
360 *
361 * Configures a Shared Memory Protection Unit (SMPU) master protection
362 * struct with its protection attributes.
363 *
364 * This function configures the master struct governing the corresponding slave
365 * struct pair. It is a mechanism to protect the slave SMPU struct. Since the
366 * memory location of the slave struct is known, the address, regionSize and
367 * subregions of the configuration struct are not applicable.
368 *
369 * Note that only the user/privileged write permissions are configurable. The
370 * read and execute permissions are read-only and cannot be configured.
371 *
372 * \note This function is applicable for both CPUSS ver_1 and ver_2.
373 *
374 * \param base
375 * The register base address of the protection struct being configured.
376 *
377 * \param config
378 * Initialization structure with all the protection attributes.
379 *
380 * \return
381 * Status of the function call.
382 *
383 * Status | Description
384 * ------------ | -----------
385 * CY_PROT_SUCCESS | SMPU master struct was successfully configured.
386 * CY_PROT_FAILURE | The resource is locked.
387 * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed.
388 *
389 * \funcusage
390 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigSmpuMasterStruct
391 *
392 *******************************************************************************/
Cy_Prot_ConfigSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type * base,const cy_stc_smpu_cfg_t * config)393 cy_en_prot_status_t Cy_Prot_ConfigSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base, const cy_stc_smpu_cfg_t* config)
394 {
395 cy_en_prot_status_t status;
396 uint32_t attReg;
397
398 CY_ASSERT_L1(NULL != base);
399 CY_ASSERT_L2(CY_PROT_IS_PC_MASK_VALID(config->pcMask));
400 CY_ASSERT_L3(CY_PROT_IS_SMPU_MS_PERM_VALID(config->userPermission));
401 CY_ASSERT_L3(CY_PROT_IS_SMPU_MS_PERM_VALID(config->privPermission));
402
403 if(((uint32_t)config->pcMask & CY_PROT_SMPU_PC_LIMIT_MASK) != 0UL)
404 {
405 /* PC mask out of range - not supported in device */
406 status = CY_PROT_BAD_PARAM;
407 }
408 else
409 {
410 /* ADDR1 is read only. Only configure ATT1 */
411 attReg = ((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK)
412 | (uint32_t)(((uint32_t)config->privPermission & CY_PROT_ATT_PERMISSION_MASK) << CY_PROT_ATT_PRIV_PERMISSION_SHIFT)
413 | _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT1_NS, !(config->secure))
414 | _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT1_PC_MASK_15_TO_1, config->pcMask)
415 /* No region size - read only for master structs */
416 | _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT1_PC_MATCH, config->pcMatch);
417 if ((attReg & CY_PROT_SMPU_ATT1_MASK) != attReg)
418 {
419 /* Invalid parameter was passed */
420 status = CY_PROT_BAD_PARAM;
421 }
422 else
423 {
424 PROT_SMPU_SMPU_STRUCT_ATT1(base) = attReg;
425 status = ((PROT_SMPU_SMPU_STRUCT_ATT1(base) & CY_PROT_SMPU_ATT1_MASK) != attReg) ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
426 }
427 }
428
429 return status;
430 }
431
432
433 /*******************************************************************************
434 * Function Name: Cy_Prot_ConfigSmpuSlaveStruct
435 ****************************************************************************//**
436 *
437 * Configures a Shared Memory Protection Unit (SMPU) slave protection
438 * struct with its protection attributes.
439 *
440 * This function configures the slave struct of an SMPU pair, which can protect
441 * any memory region in a device from invalid bus master accesses.
442 *
443 * \note This function is applicable for both CPUSS ver_1 and ver_2.
444 *
445 * \param base
446 * The register base address of the protection structure being configured.
447 *
448 * \param config
449 * Initialization structure with all the protection attributes.
450 *
451 * \return
452 * Status of the function call.
453 *
454 * Status | Description
455 * ------------ | -----------
456 * CY_PROT_SUCCESS | SMPU slave struct was successfully configured.
457 * CY_PROT_FAILURE | The resource is locked.
458 * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed.
459 *
460 * \funcusage
461 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigSmpuSlaveStruct
462 *
463 *******************************************************************************/
Cy_Prot_ConfigSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type * base,const cy_stc_smpu_cfg_t * config)464 cy_en_prot_status_t Cy_Prot_ConfigSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base, const cy_stc_smpu_cfg_t* config)
465 {
466 cy_en_prot_status_t status = CY_PROT_SUCCESS;
467 uint32_t addrReg;
468 uint32_t attReg;
469
470 CY_ASSERT_L1(NULL != base);
471 CY_ASSERT_L2(CY_PROT_IS_PC_MASK_VALID(config->pcMask));
472 CY_ASSERT_L3(CY_PROT_IS_SMPU_SL_PERM_VALID(config->userPermission));
473 CY_ASSERT_L3(CY_PROT_IS_SMPU_SL_PERM_VALID(config->privPermission));
474 CY_ASSERT_L3(CY_PROT_IS_REGION_SIZE_VALID(config->regionSize));
475
476 if(((uint32_t)config->pcMask & CY_PROT_SMPU_PC_LIMIT_MASK) != 0UL)
477 {
478 /* PC mask out of range - not supported in device */
479 status = CY_PROT_BAD_PARAM;
480 }
481 else
482 {
483 addrReg= _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ADDR0_SUBREGION_DISABLE, config->subregions)
484 | _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ADDR0_ADDR24, (uint32_t)((uint32_t)config->address >> CY_PROT_ADDR_SHIFT));
485 attReg= ((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK)
486 | (uint32_t)(((uint32_t)config->privPermission & CY_PROT_ATT_PERMISSION_MASK) << CY_PROT_ATT_PRIV_PERMISSION_SHIFT)
487 | _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT0_NS, !(config->secure))
488 | _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT0_PC_MASK_15_TO_1, config->pcMask)
489 | _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT0_REGION_SIZE, config->regionSize)
490 | _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT0_PC_MATCH, config->pcMatch);
491 PROT_SMPU_SMPU_STRUCT_ATT0(base) = attReg;
492 PROT_SMPU_SMPU_STRUCT_ADDR0(base) = addrReg;
493 status = ((PROT_SMPU_SMPU_STRUCT_ADDR0(base) != addrReg) || ((PROT_SMPU_SMPU_STRUCT_ATT0(base) & CY_PROT_SMPU_ATT0_MASK) != attReg))
494 ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
495 }
496
497 return status;
498 }
499
500
501 /*******************************************************************************
502 * Function Name: Cy_Prot_EnableSmpuMasterStruct
503 ****************************************************************************//**
504 *
505 * Enables the Master SMPU structure.
506 *
507 * This is an SMPU master struct enable function. The SMPU protection settings
508 * will take effect after successful completion of this function call.
509 *
510 * \note This function is applicable for both CPUSS ver_1 and ver_2.
511 *
512 * \param base
513 * The base address for the protection unit structure being configured.
514 *
515 * \return
516 * Status of the function call.
517 *
518 * Status | Description
519 * ------------ | -----------
520 * CY_PROT_SUCCESS | The Master PU struct was enabled.
521 * CY_PROT_FAILURE | The Master PU struct is disabled and possibly locked.
522 *
523 * \funcusage
524 * \snippet prot/snippet/main.c snippet_Cy_Prot_EnableSmpuMasterStruct
525 *
526 *******************************************************************************/
Cy_Prot_EnableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type * base)527 cy_en_prot_status_t Cy_Prot_EnableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base)
528 {
529 cy_en_prot_status_t status;
530
531 CY_ASSERT_L1(NULL != base);
532
533 PROT_SMPU_SMPU_STRUCT_ATT1(base) |= _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE);
534 status = (_FLD2VAL(PROT_SMPU_SMPU_STRUCT_ATT1_ENABLED, PROT_SMPU_SMPU_STRUCT_ATT1(base)) != CY_PROT_STRUCT_ENABLE) ?
535 CY_PROT_FAILURE : CY_PROT_SUCCESS;
536
537 return status;
538 }
539
540
541 /*******************************************************************************
542 * Function Name: Cy_Prot_DisableSmpuMasterStruct
543 ****************************************************************************//**
544 *
545 * Disables the Master SMPU structure.
546 *
547 * This is an SMPU master struct disable function. The SMPU protection settings
548 * will seize to take effect after successful completion of this function call.
549 *
550 * \note This function is applicable for both CPUSS ver_1 and ver_2.
551 *
552 * \param base
553 * The base address for the protection unit structure being configured.
554 *
555 * \return
556 * Status of the function call.
557 *
558 * Status | Description
559 * ------------ | -----------
560 * CY_PROT_SUCCESS | The Master PU struct was disabled.
561 * CY_PROT_FAILURE | The Master PU struct is enabled and possibly locked.
562 *
563 * \funcusage
564 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisableSmpuMasterStruct
565 *
566 *******************************************************************************/
Cy_Prot_DisableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type * base)567 cy_en_prot_status_t Cy_Prot_DisableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type* base)
568 {
569 cy_en_prot_status_t status;
570
571 CY_ASSERT_L1(NULL != base);
572
573 PROT_SMPU_SMPU_STRUCT_ATT1(base) &= ~_VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE);
574 status = (_FLD2VAL(PROT_SMPU_SMPU_STRUCT_ATT1_ENABLED, PROT_SMPU_SMPU_STRUCT_ATT1(base)) == CY_PROT_STRUCT_ENABLE) ?
575 CY_PROT_FAILURE : CY_PROT_SUCCESS;
576
577 return status;
578 }
579
580
581 /*******************************************************************************
582 * Function Name: Cy_Prot_EnableSmpuSlaveStruct
583 ****************************************************************************//**
584 *
585 * Enables the Slave SMPU structure.
586 *
587 * This is an SMPU slave struct enable function. The SMPU protection settings
588 * will take effect after successful completion of this function call.
589 *
590 * \note This function is applicable for both CPUSS ver_1 and ver_2.
591 *
592 * \param base
593 * The base address for the protection unit structure being configured.
594 *
595 * \return
596 * Status of the function call.
597 *
598 * Status | Description
599 * ------------ | -----------
600 * CY_PROT_SUCCESS | The Slave PU struct was enabled.
601 * CY_PROT_FAILURE | The Slave PU struct is disabled and possibly locked.
602 *
603 * \funcusage
604 * \snippet prot/snippet/main.c snippet_Cy_Prot_EnableSmpuSlaveStruct
605 *
606 *******************************************************************************/
Cy_Prot_EnableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type * base)607 cy_en_prot_status_t Cy_Prot_EnableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base)
608 {
609 cy_en_prot_status_t status;
610
611 CY_ASSERT_L1(NULL != base);
612
613 PROT_SMPU_SMPU_STRUCT_ATT0(base) |= _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
614 status = (_FLD2VAL(PROT_SMPU_SMPU_STRUCT_ATT0_ENABLED, PROT_SMPU_SMPU_STRUCT_ATT0(base)) != CY_PROT_STRUCT_ENABLE) ?
615 CY_PROT_FAILURE : CY_PROT_SUCCESS;
616
617 return status;
618 }
619
620
621 /*******************************************************************************
622 * Function Name: Cy_Prot_DisableSmpuSlaveStruct
623 ****************************************************************************//**
624 *
625 * Disables the Slave SMPU structure.
626 *
627 * This is an SMPU slave struct disable function. The SMPU protection settings
628 * will seize to take effect after successful completion of this function call.
629 *
630 * \note This function is applicable for both CPUSS ver_1 and ver_2.
631 *
632 * \param base
633 * The base address for the protection unit structure being configured.
634 *
635 * \return
636 * Status of the function call.
637 *
638 * Status | Description
639 * ------------ | -----------
640 * CY_PROT_SUCCESS | The Slave PU struct was disabled.
641 * CY_PROT_FAILURE | The Slave PU struct is enabled and possibly locked.
642 *
643 * \funcusage
644 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisableSmpuSlaveStruct
645 *
646 *******************************************************************************/
Cy_Prot_DisableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type * base)647 cy_en_prot_status_t Cy_Prot_DisableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type* base)
648 {
649 cy_en_prot_status_t status;
650
651 CY_ASSERT_L1(NULL != base);
652
653 PROT_SMPU_SMPU_STRUCT_ATT0(base) &= ~_VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
654 status = (_FLD2VAL(PROT_SMPU_SMPU_STRUCT_ATT0_ENABLED, PROT_SMPU_SMPU_STRUCT_ATT0(base)) == CY_PROT_STRUCT_ENABLE) ?
655 CY_PROT_FAILURE : CY_PROT_SUCCESS;
656
657 return status;
658 }
659
660
661 /*******************************************************************************
662 * Function Name: Cy_Prot_GetSmpuStruct
663 ****************************************************************************//**
664 *
665 * Functions returns a pointer of the requested unused SMPU structure. It
666 * searches the SMPU structures until it finds one that both the slave and master
667 * sections are disabled. After an available structure is located, function
668 * enables the slave structure and set the ATT0[7:0] bits to 0xFF, to make sure
669 * that a subsequent call will not see this as an available (unused) SMPU.
670 *
671 * It is up to the user to implement, if needed, a system in which a semaphore
672 * will lock-out all but one CPU from calling this function at once.
673 *
674 * \note This function is applicable for both CPUSS ver_1 and ver_2.
675 *
676 * \param base
677 * The base address for the SMPU structure returned if an unused structure was
678 * found. If an empty structure was not found, the returned pointer is NULL.
679 *
680 * \param reqMode
681 * This parameter (request mode) selects how the user wants to select a SMPU
682 * structure.
683 *
684 * reqMode | Description
685 * --------------------------| -----------------------------
686 * CY_PROT_REQMODE_HIGHPRIOR | Return the SMPU structure with the highest priority.
687 * CY_PROT_REQMODE_LOWPRIOR | Return the SMPU structure with the lowest priority.
688 * CY_PROT_REQMODE_INDEX | Return the SMPU structure with the specific index.
689 *
690 * \param smpuIndex
691 * This is the index of the requested SMPU structure. It is only used if the
692 * request mode is reqMode = CY_PROT_REQMODE_INDEX.
693 *
694 * \return
695 * Status of the function call.
696 *
697 * Status | Description
698 * ----------------------| ---------------------------------------
699 * CY_PROT_SUCCESS | The Slave PU struct was disabled.
700 * CY_PROT_FAILURE | The Master or Slave SMPU struct is disabled and possibly locked.
701 * CY_PROT_UNAVAILABLE | The requested structure in use or there were no unused structures.
702 *
703 * \funcusage
704 * \snippet prot/snippet/main.c snippet_Cy_Prot_GetSmpuStruct
705 *
706 *******************************************************************************/
Cy_Prot_GetSmpuStruct(PROT_SMPU_SMPU_STRUCT_Type ** base,cy_en_prot_req_mode_t reqMode,uint32_t smpuIndex)707 cy_en_prot_status_t Cy_Prot_GetSmpuStruct(PROT_SMPU_SMPU_STRUCT_Type** base,
708 cy_en_prot_req_mode_t reqMode, uint32_t smpuIndex)
709 {
710 CY_ASSERT_L3(CY_PROT_IS_SMPU_REQ_MODE_VALID(reqMode));
711 CY_ASSERT_L2(CY_PROT_IS_SMPU_IDX_VALID(smpuIndex));
712
713 cy_en_prot_status_t status = CY_PROT_UNAVAILABLE;
714 int32_t stcIdx = (int32_t)smpuIndex;
715
716 *base = NULL;
717
718 switch (reqMode)
719 {
720 /* The SMPU priority goes from PROT_SMPU_STRUCT_HIGHEST_PR
721 * (highest priority) to 0 (lowest priority)
722 */
723 case CY_PROT_REQMODE_HIGHPRIOR:
724
725 stcIdx = PROT_SMPU_STRUCT_WTH_HIGHEST_PR;
726 do
727 {
728 if (Prot_IsSmpuStructDisabled((uint32_t)stcIdx))
729 {
730 status = CY_PROT_SUCCESS;
731 }
732 else
733 {
734 --stcIdx;
735 }
736 } while ((stcIdx >= 0) && (CY_PROT_SUCCESS != status));
737 break;
738
739 case CY_PROT_REQMODE_LOWPRIOR:
740 stcIdx = 0;
741 do
742 {
743 if (Prot_IsSmpuStructDisabled((uint32_t)stcIdx))
744 {
745 status = CY_PROT_SUCCESS;
746 }
747 else
748 {
749 ++stcIdx;
750 }
751 } while ((stcIdx <= PROT_SMPU_STRUCT_WTH_HIGHEST_PR) && (CY_PROT_SUCCESS != status));
752 break;
753
754 case CY_PROT_REQMODE_INDEX:
755 if (Prot_IsSmpuStructDisabled((uint32_t)stcIdx))
756 {
757 status = CY_PROT_SUCCESS;
758 }
759 break;
760
761 default:
762 /* Unknown request mode */
763 break;
764 }
765
766 /* Proceed if required structure is found */
767 if (CY_PROT_SUCCESS == status)
768 {
769 /* Enable Slave SMPU struct */
770 PROT_SMPU_SMPU_STRUCT_IDX_ATT0(stcIdx) |= _VAL2FLD(PROT_SMPU_SMPU_STRUCT_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
771
772 status =
773 (_FLD2VAL(PROT_SMPU_SMPU_STRUCT_ATT0_ENABLED, PROT_SMPU_SMPU_STRUCT_IDX_ATT0(stcIdx)) != CY_PROT_STRUCT_ENABLE) ?
774 CY_PROT_FAILURE : CY_PROT_SUCCESS;
775
776 /* Enable all attributes only if Slave struct was enabled */
777 if (CY_PROT_SUCCESS == status)
778 {
779 *base = (PROT_SMPU_SMPU_STRUCT_Type* ) PROT_SMPU_SMPU_STRUCT_IDX(stcIdx);
780 PROT_SMPU_SMPU_STRUCT_IDX_ATT0(stcIdx) |= PROT_SMPU_STRUCT_ATT0_ENABLE_ALL_MASK;
781 }
782 }
783 return status;
784 }
785
786
787 /*******************************************************************************
788 * Function Name: Prot_ConfigPpuAtt
789 ********************************************************************************
790 *
791 * An internal function to hold the common code for
792 * Cy_Prot_ConfigPpu[Prog/Fixed][Master/Slave]Att API functions
793 *
794 * \note This function is applicable for CPUSS ver_2 only.
795 *
796 * \param reg
797 * The register to update attributes in.
798 *
799 * \param pcMask
800 * The protection context mask. It specifies the protection context or a set of
801 * multiple protection contexts to be configured.
802 * It is a value of OR'd (|) items of \ref cy_en_prot_pcmask_t.
803 * For example: (\ref CY_PROT_PCMASK1 | \ref CY_PROT_PCMASK3 | \ref CY_PROT_PCMASK4).
804 * \note The function accepts pcMask values from \ref CY_PROT_PCMASK1 to \ref CY_PROT_PCMASK15.
805 * But each device has its own number of available protection contexts.
806 * That number is defined by PERI_PC_NR in the config file.
807 *
808 * \param userPermission
809 * The user permissions for the region.
810 *
811 * \param privPermission
812 * The privileged permissions for the region.
813 *
814 * \param secure
815 * Non Secure = false, Secure = true
816 *
817 * \return
818 * The status of the function call.
819 *
820 * Status | Description
821 * ----------------------| ---------------------------------------
822 * CY_PROT_SUCCESS | The attributes were set up.
823 * CY_PROT_FAILURE | The attributes were not set up because the structure is possibly locked.
824 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
825 *
826 *******************************************************************************/
Prot_ConfigPpuAtt(volatile uint32_t * reg,uint16_t pcMask,cy_en_prot_perm_t userPermission,cy_en_prot_perm_t privPermission,bool secure)827 static cy_en_prot_status_t Prot_ConfigPpuAtt(volatile uint32_t * reg, uint16_t pcMask,
828 cy_en_prot_perm_t userPermission, cy_en_prot_perm_t privPermission, bool secure)
829 {
830 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
831
832 if (!CY_PERI_V1)
833 {
834 uint32_t tmpMask = (uint32_t)pcMask << CY_PROT_PCMASK_CHECK;
835 uint32_t tmpMask2;
836 uint32_t attReg;
837 int32_t regIdx;
838 uint32_t fldIdx;
839
840 status = CY_PROT_SUCCESS;
841
842 /* Populate the ATT values */
843 /* Note that we have to start with the higher PCs to avoid locking ourselves out */
844 for(regIdx = ((int32_t)CY_PROT_ATT_REGS_MAX - (int32_t)1U); regIdx >= 0; regIdx--)
845 {
846 tmpMask2 = (tmpMask >> (CY_PROT_ATT_PC_MAX * (uint32_t)regIdx)) & 0xFUL;
847
848 /* Get the attributes register value */
849 attReg = reg[regIdx];
850
851 for(fldIdx = 0UL; fldIdx < CY_PROT_ATT_PC_MAX; fldIdx++)
852 {
853 if((tmpMask2 & CY_PROT_PCMASK_CHECK) == CY_PROT_STRUCT_ENABLE)
854 {
855 /* Reset the bitfield for the PCx attributes */
856 attReg &= ~((_VAL2FLD(CY_PROT_ATT_PERI_USER_PERM, CY_PROT_PERM_RW) |
857 _VAL2FLD(CY_PROT_ATT_PERI_PRIV_PERM, CY_PROT_PERM_RW) |
858 PERI_MS_PPU_PR_V2_MS_ATT0_PC0_NS_Msk) <<
859 (PERI_MS_PPU_PR_V2_MS_ATT0_PC1_UR_Pos * fldIdx));
860
861 /* Set the bitfield for the PCx attributes */
862 attReg |= (_VAL2FLD(CY_PROT_ATT_PERI_USER_PERM, userPermission) |
863 _VAL2FLD(CY_PROT_ATT_PERI_PRIV_PERM, privPermission) |
864 _BOOL2FLD(PERI_MS_PPU_PR_V2_MS_ATT0_PC0_NS, !secure)) <<
865 (PERI_MS_PPU_PR_V2_MS_ATT0_PC1_UR_Pos * fldIdx);
866 }
867 tmpMask2 = tmpMask2 >> CY_PROT_PCMASK_CHECK;
868 }
869
870 /* Update the attributes register */
871 reg[regIdx] = attReg;
872
873 /* Check the result */
874 if (0UL == (uint32_t)regIdx)
875 {
876 if ((reg[regIdx] & PROT_PERI_PPU_PROG_PC1_PC3_MASK) != (attReg & PROT_PERI_PPU_PROG_PC1_PC3_MASK))
877 {
878 status = CY_PROT_FAILURE;
879 }
880 }
881 else if (reg[regIdx] != attReg)
882 {
883 status = CY_PROT_FAILURE;
884 }
885 else
886 {
887 /* CY_PROT_SUCCESS */
888 }
889 }
890 }
891
892 return status;
893 }
894
895
896 /*******************************************************************************
897 * Function Name: Cy_Prot_ConfigPpuProgMasterAtt
898 ****************************************************************************//**
899 *
900 * Configures the protection-structure attributes of the
901 * Programmable Peripheral Protection Unit (PPU PROG) master.
902 *
903 * This function configures the master structure governing the corresponding slave
904 * structure pair. It is a mechanism to protect the slave PPU PROG structure.
905 * The memory location of the slave structure is known, so the address, regionSize, and
906 * sub-regions of the configuration structure are not applicable.
907 *
908 * \note This function is applicable for CPUSS ver_2 only.
909 *
910 * \param base
911 * The register base address of the protection structure is being configured.
912 *
913 * \param pcMask
914 * The protection context mask. It specifies the protection context or a set of
915 * multiple protection contexts to be configured.
916 * It is a value of OR'd (|) items of \ref cy_en_prot_pcmask_t.
917 * \note The function accepts pcMask values from \ref CY_PROT_PCMASK1 to
918 * \ref CY_PROT_PCMASK15. But each device has its own number of available protection
919 * contexts. That number is defined by PERI_PC_NR in the config file. If pcMask
920 * is passed beyond the range of available protection context, the bits above PERI_PC_NR
921 * will be ignored.
922 *
923 * \param userPermission
924 * The user permission setting. The CY_PROT_PERM_R or CY_PROT_PERM_RW values
925 * are valid for the master.
926 *
927 * \param privPermission
928 * The privileged permission setting. CY_PROT_PERM_R or CY_PROT_PERM_RW values
929 * are valid for the master.
930 *
931 * \param secure
932 * The secure flag.
933 *
934 * \return
935 * The status of the function call.
936 *
937 * Status | Description
938 * ----------------------| ---------------------------------------
939 * CY_PROT_SUCCESS | The attributes were set up.
940 * CY_PROT_FAILURE | The attributes were not set up because the structure is possibly locked.
941 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
942 *
943 * \note Only the user's/privileged Write permissions are configurable. The
944 * Read permissions are read-only and cannot be configured.
945 *
946 * \note PC0 accesses are read-only and are always enabled.
947 *
948 * \funcusage
949 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuProgMasterAtt
950 *
951 *******************************************************************************/
Cy_Prot_ConfigPpuProgMasterAtt(PERI_MS_PPU_PR_Type * base,uint16_t pcMask,cy_en_prot_perm_t userPermission,cy_en_prot_perm_t privPermission,bool secure)952 cy_en_prot_status_t Cy_Prot_ConfigPpuProgMasterAtt(PERI_MS_PPU_PR_Type* base, uint16_t pcMask,
953 cy_en_prot_perm_t userPermission, cy_en_prot_perm_t privPermission, bool secure)
954 {
955 /* The parameter checks */
956 CY_ASSERT_L1(NULL != base);
957 CY_ASSERT_L3(CY_PROT_IS_PROG_MS_PERM_VALID(userPermission));
958 CY_ASSERT_L3(CY_PROT_IS_PROG_MS_PERM_VALID(privPermission));
959
960 pcMask &= ((uint16_t) CY_PROT_PCMASK_VALID);
961
962 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 18.1','Checked manually, base pointer will not exceed register range.');
963 return (Prot_ConfigPpuAtt(PERI_MS_PPU_PR_MS_ATT(base), pcMask, userPermission, privPermission, secure));
964 }
965
966
967 /*******************************************************************************
968 * Function Name: Cy_Prot_ConfigPpuProgSlaveAddr
969 ****************************************************************************//**
970 *
971 * Configures the protection-structure address settings of the
972 * Programmable Peripheral Protection Unit (PPU PROG) slave.
973 *
974 * This function configures the slave structure of the PPU PROG pair, which can
975 * protect any peripheral memory region in a device from an invalid bus-master
976 * access.
977 *
978 * \note This function is applicable for CPUSS ver_2 only.
979 *
980 * \param base
981 * The register base address of the protection structure is being configured.
982 *
983 * \param address
984 * The address.
985 *
986 * \param regionSize
987 * The region size.
988 *
989 * \return
990 * The status of the function call.
991 *
992 * Status | Description
993 * ----------------------| ---------------------------------------
994 * CY_PROT_SUCCESS | The address settings were set up.
995 * CY_PROT_FAILURE | The address settings were not set up because the structure is possibly locked.
996 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
997 *
998 * \note PC0 accesses are Read-only and are always enabled.
999 *
1000 * \funcusage
1001 * \ref Cy_Prot_ConfigPpuProgSlaveAtt
1002 *
1003 *******************************************************************************/
Cy_Prot_ConfigPpuProgSlaveAddr(PERI_MS_PPU_PR_Type * base,uint32_t address,cy_en_prot_size_t regionSize)1004 cy_en_prot_status_t Cy_Prot_ConfigPpuProgSlaveAddr(PERI_MS_PPU_PR_Type* base, uint32_t address,
1005 cy_en_prot_size_t regionSize)
1006 {
1007 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1008
1009 /* The parameter checks */
1010 CY_ASSERT_L1(NULL != base);
1011 CY_ASSERT_L3(CY_PROT_IS_PPU_V2_SIZE_VALID(regionSize));
1012
1013 if (!CY_PERI_V1)
1014 {
1015 PERI_MS_PPU_PR_SL_ADDR(base) = address & PERI_MS_PPU_PR_V2_SL_ADDR_ADDR30_Msk;
1016 PERI_MS_PPU_PR_SL_SIZE(base) = _CLR_SET_FLD32U((PERI_MS_PPU_PR_SL_SIZE(base)), PERI_MS_PPU_PR_V2_SL_SIZE_REGION_SIZE, regionSize);
1017
1018 status = ((PERI_MS_PPU_PR_SL_ADDR(base) != (address & PERI_MS_PPU_PR_V2_SL_ADDR_ADDR30_Msk)) ||
1019 (_FLD2VAL(PERI_MS_PPU_PR_V2_SL_SIZE_REGION_SIZE, PERI_MS_PPU_PR_SL_SIZE(base)) != (uint32_t)regionSize)) ?
1020 CY_PROT_FAILURE : CY_PROT_SUCCESS;
1021 }
1022
1023 return status;
1024 }
1025
1026
1027 /*******************************************************************************
1028 * Function Name: Cy_Prot_ConfigPpuProgSlaveAtt
1029 ****************************************************************************//**
1030 *
1031 * Configures the protection structure with its protection attributes of the
1032 * Programmable Peripheral Protection Unit (PPU PROG) slave.
1033 *
1034 * This function configures the slave structure of the PPU PROG pair, which can
1035 * protect any peripheral memory region in a device from invalid bus-master
1036 * access.
1037 *
1038 * \note This function is applicable for CPUSS ver_2 only.
1039 *
1040 * \param base
1041 * The register base address of the protection structure is being configured.
1042 *
1043 * \param pcMask
1044 * The protection context mask. It specifies the protection context or a set of
1045 * multiple protection contexts to be configured.
1046 * It is a value of OR'd (|) items of \ref cy_en_prot_pcmask_t.
1047 * For example: (\ref CY_PROT_PCMASK1 | \ref CY_PROT_PCMASK3 | \ref CY_PROT_PCMASK4).
1048 * \note The function accepts pcMask values from \ref CY_PROT_PCMASK1 to \ref CY_PROT_PCMASK15.
1049 * But each device has its own number of available protection contexts.
1050 * That number is defined by PERI_PC_NR in the config file.
1051 *
1052 * \param userPermission
1053 * The user permission setting.
1054 *
1055 * \param privPermission
1056 * The privileged permission setting.
1057 *
1058 * \param secure
1059 * The secure flag.
1060 *
1061 * \return
1062 * The status of the function call.
1063 *
1064 * Status | Description
1065 * ----------------------| ---------------------------------------
1066 * CY_PROT_SUCCESS | The attributes were set up.
1067 * CY_PROT_FAILURE | The attributes were not set up because the structure is possibly locked.
1068 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1069 *
1070 * \note PC0 accesses are read-only and are always enabled.
1071 *
1072 * \funcusage
1073 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuProgSlaveAtt
1074 *
1075 *******************************************************************************/
Cy_Prot_ConfigPpuProgSlaveAtt(PERI_MS_PPU_PR_Type * base,uint16_t pcMask,cy_en_prot_perm_t userPermission,cy_en_prot_perm_t privPermission,bool secure)1076 cy_en_prot_status_t Cy_Prot_ConfigPpuProgSlaveAtt(PERI_MS_PPU_PR_Type* base, uint16_t pcMask,
1077 cy_en_prot_perm_t userPermission, cy_en_prot_perm_t privPermission, bool secure)
1078 {
1079 /* The parameter checks */
1080 CY_ASSERT_L1(NULL != base);
1081 CY_ASSERT_L3(CY_PROT_IS_PROG_SL_PERM_VALID(userPermission));
1082 CY_ASSERT_L3(CY_PROT_IS_PROG_SL_PERM_VALID(privPermission));
1083
1084 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 18.1','Checked manually, base pointer will not exceed register range.');
1085 return (Prot_ConfigPpuAtt(PERI_MS_PPU_PR_SL_ATT(base), pcMask, userPermission, privPermission, secure));
1086 }
1087
1088
1089 /*******************************************************************************
1090 * Function Name: Cy_Prot_EnablePpuProgSlaveRegion
1091 ****************************************************************************//**
1092 *
1093 * Enables the Slave PPU PROG structure.
1094 *
1095 * This is the PPU PROG slave-structure enable function. The PPU PROG protection
1096 * settings will take effect after a successful completion of this function call.
1097 *
1098 * \note This function is applicable for CPUSS ver_2 only.
1099 *
1100 * \param base
1101 * The base address for the protection unit structure is being configured.
1102 *
1103 * \return
1104 * The status of the function call.
1105 *
1106 * Status | Description
1107 * ----------------------| ---------------------------------------
1108 * CY_PROT_SUCCESS | The structure was enabled.
1109 * CY_PROT_FAILURE | The structure is disabled and possibly locked.
1110 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1111 *
1112 * \funcusage
1113 * \ref Cy_Prot_ConfigPpuProgSlaveAtt
1114 *
1115 *******************************************************************************/
Cy_Prot_EnablePpuProgSlaveRegion(PERI_MS_PPU_PR_Type * base)1116 cy_en_prot_status_t Cy_Prot_EnablePpuProgSlaveRegion(PERI_MS_PPU_PR_Type* base)
1117 {
1118 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1119
1120 CY_ASSERT_L1(NULL != base);
1121
1122 if (!CY_PERI_V1)
1123 {
1124 PERI_MS_PPU_PR_SL_SIZE(base) =
1125 _CLR_SET_FLD32U((PERI_MS_PPU_PR_SL_SIZE(base)), PERI_MS_PPU_PR_V2_SL_SIZE_VALID, CY_PROT_STRUCT_ENABLE);
1126
1127 status = (_FLD2VAL(PERI_MS_PPU_PR_V2_SL_SIZE_VALID, PERI_MS_PPU_PR_SL_SIZE(base)) != CY_PROT_STRUCT_ENABLE) ?
1128 CY_PROT_FAILURE : CY_PROT_SUCCESS;
1129 }
1130
1131 return status;
1132 }
1133
1134
1135 /*******************************************************************************
1136 * Function Name: Cy_Prot_DisablePpuProgSlaveRegion
1137 ****************************************************************************//**
1138 *
1139 * Disables the Slave PPU PROG structure.
1140 *
1141 * This is the PPU PROG slave-structure disable function. The PPU PROG protection
1142 * settings will seize to take effect after successful completion of this
1143 * function call.
1144 *
1145 * \note This function is applicable for CPUSS ver_2 only.
1146 *
1147 * \param base
1148 * The base address for the protection unit structure is being configured.
1149 *
1150 * \return
1151 * The status of the function call.
1152 *
1153 * Status | Description
1154 * ----------------------| ---------------------------------------
1155 * CY_PROT_SUCCESS | The slave PPU PROG structure was disabled.
1156 * CY_PROT_FAILURE | The structure is enabled and possibly locked.
1157 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1158 *
1159 * \funcusage
1160 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisablePpuProgSlaveRegion
1161 *
1162 *******************************************************************************/
Cy_Prot_DisablePpuProgSlaveRegion(PERI_MS_PPU_PR_Type * base)1163 cy_en_prot_status_t Cy_Prot_DisablePpuProgSlaveRegion(PERI_MS_PPU_PR_Type* base)
1164 {
1165 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1166
1167 CY_ASSERT_L1(NULL != base);
1168
1169 if (!CY_PERI_V1)
1170 {
1171 PERI_MS_PPU_PR_SL_SIZE(base) =
1172 _CLR_SET_FLD32U((PERI_MS_PPU_PR_SL_SIZE(base)), PERI_MS_PPU_PR_V2_SL_SIZE_VALID, CY_PROT_STRUCT_DISABLE);
1173
1174 status = (_FLD2VAL(PERI_MS_PPU_PR_V2_SL_SIZE_VALID, PERI_MS_PPU_PR_SL_SIZE(base)) != CY_PROT_STRUCT_DISABLE) ?
1175 CY_PROT_FAILURE : CY_PROT_SUCCESS;
1176 }
1177
1178 return status;
1179 }
1180
1181
1182 /*******************************************************************************
1183 * Function Name: Cy_Prot_ConfigPpuFixedMasterAtt
1184 ****************************************************************************//**
1185 *
1186 * Configures the protection structure with its protection attributes of the
1187 * Fixed Peripheral Protection Unit (PPU FIXED) master.
1188 *
1189 * This function configures the master structure governing the corresponding slave
1190 * structure pair. It is a mechanism to protect the slave PPU FIXED structure.
1191 * The memory location of the slave structure is known, so the address, region size
1192 * and sub-regions of the configuration structure are not applicable.
1193 *
1194 * \note This function is applicable for CPUSS ver_2 only.
1195 *
1196 * \param base
1197 * The register base address of the protection structure is being configured.
1198 *
1199 * \param pcMask
1200 * The protection context mask. It specifies the protection context or a set of
1201 * multiple protection contexts to be configured.
1202 * It is a value of OR'd (|) items of \ref cy_en_prot_pcmask_t.
1203 * \note The function accepts pcMask values from \ref CY_PROT_PCMASK1 to
1204 * \ref CY_PROT_PCMASK15. But each device has its own number of available protection
1205 * contexts. That number is defined by PERI_PC_NR in the config file. If pcMask
1206 * is passed beyond the range of available protection context, the bits above PERI_PC_NR
1207 * will be ignored.
1208 *
1209 * \param userPermission
1210 * The user permission setting. The CY_PROT_PERM_R or CY_PROT_PERM_RW values
1211 * are valid for the master.
1212 *
1213 * \param privPermission
1214 * The privileged permission setting. The CY_PROT_PERM_R or CY_PROT_PERM_RW values
1215 * are valid for the master.
1216 *
1217 * \param secure
1218 * The secure flag.
1219 *
1220 * \return
1221 * The status of the function call.
1222 *
1223 * Status | Description
1224 * ----------------------| ---------------------------------------
1225 * CY_PROT_SUCCESS | The attributes were set up.
1226 * CY_PROT_FAILURE | The attributes were not setup and the structure is possibly locked.
1227 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1228 *
1229 * \note Only the user/privileged write permissions are configurable. The
1230 * read permissions are read-only and cannot be configured.
1231 *
1232 * \note PC0 accesses are read-only and are always enabled.
1233 *
1234 * \funcusage
1235 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuFixedMasterAtt
1236 *
1237 *******************************************************************************/
Cy_Prot_ConfigPpuFixedMasterAtt(PERI_MS_PPU_FX_Type * base,uint16_t pcMask,cy_en_prot_perm_t userPermission,cy_en_prot_perm_t privPermission,bool secure)1238 cy_en_prot_status_t Cy_Prot_ConfigPpuFixedMasterAtt(PERI_MS_PPU_FX_Type* base, uint16_t pcMask,
1239 cy_en_prot_perm_t userPermission, cy_en_prot_perm_t privPermission, bool secure)
1240 {
1241 /* The parameter checks */
1242 CY_ASSERT_L1(NULL != base);
1243 CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_MS_PERM_VALID(userPermission));
1244 CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_MS_PERM_VALID(privPermission));
1245
1246 pcMask &= ((uint16_t) CY_PROT_PCMASK_VALID);
1247
1248 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 18.1','Checked manually, base pointer will not exceed register range.');
1249 return (Prot_ConfigPpuAtt(PERI_MS_PPU_FX_MS_ATT(base), pcMask, userPermission, privPermission, secure));
1250 }
1251
1252
1253 /*******************************************************************************
1254 * Function Name: Cy_Prot_ConfigPpuFixedSlaveAtt
1255 ****************************************************************************//**
1256 *
1257 * Configures the protection structure with its protection attributes of
1258 * the Fixed Peripheral Protection Unit (PPU FIXED) slave.
1259 *
1260 * This function configures the slave structure of the PPU FIXED pair, which can
1261 * protect any peripheral memory region in a device from invalid bus-master
1262 * access.
1263 *
1264 * \note This function is applicable for CPUSS ver_2 only.
1265 *
1266 * \param base
1267 * The register base address of the protection structure is being configured.
1268 *
1269 * \param pcMask
1270 * The protection context mask. It specifies the protection context or a set of
1271 * multiple protection contexts to be configured.
1272 * It is a value of OR'd (|) items of \ref cy_en_prot_pcmask_t.
1273 * For example: (\ref CY_PROT_PCMASK1 | \ref CY_PROT_PCMASK3 | \ref CY_PROT_PCMASK4).
1274 * \note The function accepts pcMask values from \ref CY_PROT_PCMASK1 to \ref CY_PROT_PCMASK15.
1275 * But each device has its own number of available protection contexts.
1276 * That number is defined by PERI_PC_NR in the config file.
1277 *
1278 * \param userPermission
1279 * The user permission setting.
1280 *
1281 * \param privPermission
1282 * The privileged permission setting.
1283 *
1284 * \param secure
1285 * The secure flag.
1286 *
1287 * \return
1288 * The status of the function call.
1289 *
1290 * Status | Description
1291 * ----------------------| ---------------------------------------
1292 * CY_PROT_SUCCESS | The attributes were set up.
1293 * CY_PROT_FAILURE | The attributes were not setup and the structure is possibly locked.
1294 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1295 *
1296 * \note PC0 accesses are read-only and are always enabled.
1297 *
1298 * \funcusage
1299 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuFixedSlaveAtt
1300 *
1301 *******************************************************************************/
Cy_Prot_ConfigPpuFixedSlaveAtt(PERI_MS_PPU_FX_Type * base,uint16_t pcMask,cy_en_prot_perm_t userPermission,cy_en_prot_perm_t privPermission,bool secure)1302 cy_en_prot_status_t Cy_Prot_ConfigPpuFixedSlaveAtt(PERI_MS_PPU_FX_Type* base, uint16_t pcMask,
1303 cy_en_prot_perm_t userPermission, cy_en_prot_perm_t privPermission, bool secure)
1304 {
1305 /* The parameter checks */
1306 CY_ASSERT_L1(NULL != base);
1307 CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(userPermission));
1308 CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(privPermission));
1309
1310 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 18.1','Checked manually, base pointer will not exceed register range.');
1311 return (Prot_ConfigPpuAtt(PERI_MS_PPU_FX_SL_ATT(base), pcMask, userPermission, privPermission, secure));
1312 }
1313
1314
1315 /*******************************************************************************
1316 * Function Name: Cy_Prot_ConfigPpuProgMasterStruct
1317 ****************************************************************************//**
1318 *
1319 * Configures a Programmable Peripheral Protection Unit (PPU PROG) master
1320 * protection struct with its protection attributes.
1321 *
1322 * This function configures the master struct governing the corresponding slave
1323 * struct pair. It is a mechanism to protect the slave PPU PROG struct. Since
1324 * the memory location of the slave struct is known, the address, regionSize and
1325 * subregions of the configuration struct are not applicable.
1326 *
1327 * Note that only the user/privileged write permissions are configurable. The
1328 * read and execute permissions are read-only and cannot be configured.
1329 *
1330 * \note This function is applicable for CPUSS ver_1 only.
1331 *
1332 * \param base
1333 * The register base address of the protection struct being configured.
1334 *
1335 * \param config
1336 * Initialization structure with all the protection attributes.
1337 *
1338 * \return
1339 * Status of the function call.
1340 *
1341 * Status | Description
1342 * ------------ | -----------
1343 * CY_PROT_SUCCESS | PPU PROG master struct was successfully configured.
1344 * CY_PROT_FAILURE | The resource is locked.
1345 * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed.
1346 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1347 *
1348 * \funcusage
1349 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuProgMasterStruct
1350 *
1351 *******************************************************************************/
Cy_Prot_ConfigPpuProgMasterStruct(PERI_PPU_PR_Type * base,const cy_stc_ppu_prog_cfg_t * config)1352 cy_en_prot_status_t Cy_Prot_ConfigPpuProgMasterStruct(PERI_PPU_PR_Type* base, const cy_stc_ppu_prog_cfg_t* config)
1353 {
1354 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1355 uint32_t attReg;
1356
1357 CY_ASSERT_L1(NULL != base);
1358 CY_ASSERT_L3(CY_PROT_IS_PROG_MS_PERM_VALID(config->userPermission));
1359 CY_ASSERT_L3(CY_PROT_IS_PROG_MS_PERM_VALID(config->privPermission));
1360
1361 if (CY_PERI_V1)
1362 {
1363 if(((uint32_t)config->pcMask & CY_PROT_PPU_PROG_PC_LIMIT_MASK) != 0UL)
1364 {
1365 /* PC mask out of range - not supported in device */
1366 status = CY_PROT_BAD_PARAM;
1367 }
1368 else
1369 {
1370 /* ADDR1 is read only. Only configure ATT1 */
1371 attReg = ((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK)
1372 | (uint32_t)(((uint32_t)config->privPermission & CY_PROT_ATT_PERMISSION_MASK) << CY_PROT_ATT_PRIV_PERMISSION_SHIFT)
1373 | _VAL2FLD(PERI_PPU_PR_ATT1_NS, !(config->secure))
1374 | _VAL2FLD(PERI_PPU_PR_ATT1_PC_MASK_15_TO_1, config->pcMask)
1375 /* No region size - read only for master structs */
1376 | _VAL2FLD(PERI_PPU_PR_ATT1_PC_MATCH, config->pcMatch);
1377 if ((attReg & CY_PROT_PPU_PROG_ATT1_MASK) != attReg)
1378 {
1379 /* Invalid parameter was passed */
1380 status = CY_PROT_BAD_PARAM;
1381 }
1382 else
1383 {
1384 PERI_PPU_PR_ATT1(base) = attReg;
1385 status = ((PERI_PPU_PR_ATT1(base) & CY_PROT_PPU_PROG_ATT1_MASK) != attReg) ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
1386 }
1387 }
1388 }
1389
1390 return status;
1391 }
1392
1393 /*******************************************************************************
1394 * Function Name: Cy_Prot_ConfigPpuProgSlaveStruct
1395 ****************************************************************************//**
1396 *
1397 * Configures a Programmable Peripheral Protection Unit (PPU PROG) slave
1398 * protection struct with its protection attributes.
1399 *
1400 * This function configures the slave struct of a PPU PROG pair, which can
1401 * protect any peripheral memory region in a device from invalid bus master
1402 * accesses.
1403 *
1404 * Note that the user/privileged execute accesses are read-only and are always
1405 * enabled.
1406 *
1407 * \note This function is applicable for CPUSS ver_1 only.
1408 *
1409 * \param base
1410 * The register base address of the protection structure being configured.
1411 *
1412 * \param config
1413 * Initialization structure with all the protection attributes.
1414 *
1415 * \return
1416 * Status of the function call.
1417 *
1418 * Status | Description
1419 * ------------ | -----------
1420 * CY_PROT_SUCCESS | PPU PROG slave struct was successfully configured.
1421 * CY_PROT_FAILURE | The resource is locked.
1422 * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed.
1423 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1424 *
1425 * \funcusage
1426 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuProgSlaveStruct
1427 *
1428 *******************************************************************************/
Cy_Prot_ConfigPpuProgSlaveStruct(PERI_PPU_PR_Type * base,const cy_stc_ppu_prog_cfg_t * config)1429 cy_en_prot_status_t Cy_Prot_ConfigPpuProgSlaveStruct(PERI_PPU_PR_Type* base, const cy_stc_ppu_prog_cfg_t* config)
1430 {
1431 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1432 uint32_t addrReg;
1433 uint32_t attReg;
1434
1435 CY_ASSERT_L1(NULL != base);
1436 CY_ASSERT_L3(CY_PROT_IS_PROG_SL_PERM_VALID(config->userPermission));
1437 CY_ASSERT_L3(CY_PROT_IS_PROG_SL_PERM_VALID(config->privPermission));
1438 CY_ASSERT_L3(CY_PROT_IS_REGION_SIZE_VALID(config->regionSize));
1439
1440 if (CY_PERI_V1)
1441 {
1442 if(((uint32_t)config->pcMask & CY_PROT_PPU_PROG_PC_LIMIT_MASK) != 0UL)
1443 {
1444 /* PC mask out of range - not supported in device */
1445 status = CY_PROT_BAD_PARAM;
1446 }
1447 else
1448 {
1449 addrReg= _VAL2FLD(PERI_PPU_PR_ADDR0_SUBREGION_DISABLE, config->subregions)
1450 | _VAL2FLD(PERI_PPU_PR_ADDR0_ADDR24, (uint32_t)((uint32_t)config->address >> CY_PROT_ADDR_SHIFT));
1451 attReg= ((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK)
1452 | (uint32_t)(((uint32_t)config->privPermission & CY_PROT_ATT_PERMISSION_MASK) << CY_PROT_ATT_PRIV_PERMISSION_SHIFT)
1453 | _VAL2FLD(PERI_PPU_PR_ATT0_NS, !(config->secure))
1454 | _VAL2FLD(PERI_PPU_PR_ATT0_PC_MASK_15_TO_1, config->pcMask)
1455 | _VAL2FLD(PERI_PPU_PR_ATT0_REGION_SIZE, config->regionSize)
1456 | _VAL2FLD(PERI_PPU_PR_ATT0_PC_MATCH, config->pcMatch);
1457 if ((attReg & CY_PROT_PPU_PROG_ATT0_MASK) != attReg)
1458 {
1459 /* Invalid parameter was passed */
1460 status = CY_PROT_BAD_PARAM;
1461 }
1462 else
1463 {
1464 PERI_PPU_PR_ATT0(base) = attReg;
1465 PERI_PPU_PR_ADDR0(base) = addrReg;
1466 status = ((PERI_PPU_PR_ADDR0(base) != addrReg) || ((PERI_PPU_PR_ATT0(base) & CY_PROT_PPU_PROG_ATT0_MASK) != attReg))
1467 ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
1468 }
1469 }
1470 }
1471
1472 return status;
1473 }
1474
1475
1476 /*******************************************************************************
1477 * Function Name: Cy_Prot_EnablePpuProgMasterStruct
1478 ****************************************************************************//**
1479 *
1480 * Enables the Master PPU PROG structure.
1481 *
1482 * This is a PPU PROG master struct enable function. The PPU PROG protection
1483 * settings will take effect after successful completion of this function call.
1484 *
1485 * \note This function is applicable for CPUSS ver_1 only.
1486 *
1487 * \param base
1488 * The base address for the protection unit structure being configured.
1489 *
1490 * \return
1491 * Status of the function call.
1492 *
1493 * Status | Description
1494 * ------------ | -----------
1495 * CY_PROT_SUCCESS | The Master PU struct was enabled.
1496 * CY_PROT_FAILURE | The Master PU struct is disabled and possibly locked.
1497 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1498 *
1499 * \funcusage
1500 * \snippet prot/snippet/main.c snippet_Cy_Prot_EnablePpuProgMasterStruct
1501 *
1502 *******************************************************************************/
Cy_Prot_EnablePpuProgMasterStruct(PERI_PPU_PR_Type * base)1503 cy_en_prot_status_t Cy_Prot_EnablePpuProgMasterStruct(PERI_PPU_PR_Type* base)
1504 {
1505 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1506
1507 CY_ASSERT_L1(NULL != base);
1508
1509 if (CY_PERI_V1)
1510 {
1511 PERI_PPU_PR_ATT1(base) |= _VAL2FLD(PERI_PPU_PR_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE);
1512 status = (_FLD2VAL(PERI_PPU_PR_ATT1_ENABLED, PERI_PPU_PR_ATT1(base)) != CY_PROT_STRUCT_ENABLE) ?
1513 CY_PROT_FAILURE : CY_PROT_SUCCESS;
1514 }
1515
1516 return status;
1517 }
1518
1519
1520 /*******************************************************************************
1521 * Function Name: Cy_Prot_DisablePpuProgMasterStruct
1522 ****************************************************************************//**
1523 *
1524 * Disables the Master PPU PROG structure.
1525 *
1526 * This is a PPU PROG master struct disable function. The PPU PROG protection
1527 * settings will seize to take effect after successful completion of this
1528 * function call.
1529 *
1530 * \note This function is applicable for CPUSS ver_1 only.
1531 *
1532 * \param base
1533 * The base address for the protection unit structure being configured.
1534 *
1535 * \return
1536 * Status of the function call.
1537 *
1538 * Status | Description
1539 * ------------ | -----------
1540 * CY_PROT_SUCCESS | The Master PU struct was disabled.
1541 * CY_PROT_FAILURE | The Master PU struct is enabled and possibly locked.
1542 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1543 *
1544 * \funcusage
1545 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisablePpuProgMasterStruct
1546 *
1547 *******************************************************************************/
Cy_Prot_DisablePpuProgMasterStruct(PERI_PPU_PR_Type * base)1548 cy_en_prot_status_t Cy_Prot_DisablePpuProgMasterStruct(PERI_PPU_PR_Type* base)
1549 {
1550 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1551
1552 CY_ASSERT_L1(NULL != base);
1553
1554 if (CY_PERI_V1)
1555 {
1556 PERI_PPU_PR_ATT1(base) &= ~_VAL2FLD(PERI_PPU_PR_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE);
1557 status = (_FLD2VAL(PERI_PPU_PR_ATT1_ENABLED, PERI_PPU_PR_ATT1(base)) == CY_PROT_STRUCT_ENABLE) ?
1558 CY_PROT_FAILURE : CY_PROT_SUCCESS;
1559 }
1560
1561 return status;
1562 }
1563
1564
1565 /*******************************************************************************
1566 * Function Name: Cy_Prot_EnablePpuProgSlaveStruct
1567 ****************************************************************************//**
1568 *
1569 * Enables the Slave PPU PROG structure.
1570 *
1571 * This is a PPU PROG slave struct enable function. The PPU PROG protection
1572 * settings will take effect after successful completion of this function call.
1573 *
1574 * \note This function is applicable for CPUSS ver_1 only.
1575 *
1576 * \param base
1577 * The base address for the protection unit structure being configured.
1578 *
1579 * \return
1580 * Status of the function call.
1581 *
1582 * Status | Description
1583 * ------------ | -----------
1584 * CY_PROT_SUCCESS | The Slave PU struct was enabled.
1585 * CY_PROT_FAILURE | The Slave PU struct is disabled and possibly locked.
1586 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1587 *
1588 * \funcusage
1589 * \snippet prot/snippet/main.c snippet_Cy_Prot_EnablePpuProgSlaveStruct
1590 *
1591 *******************************************************************************/
Cy_Prot_EnablePpuProgSlaveStruct(PERI_PPU_PR_Type * base)1592 cy_en_prot_status_t Cy_Prot_EnablePpuProgSlaveStruct(PERI_PPU_PR_Type* base)
1593 {
1594 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1595
1596 CY_ASSERT_L1(NULL != base);
1597
1598 if (CY_PERI_V1)
1599 {
1600 PERI_PPU_PR_ATT0(base) |= _VAL2FLD(PERI_PPU_PR_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
1601 status = (_FLD2VAL(PERI_PPU_PR_ATT0_ENABLED, PERI_PPU_PR_ATT0(base)) != CY_PROT_STRUCT_ENABLE) ?
1602 CY_PROT_FAILURE : CY_PROT_SUCCESS;
1603 }
1604
1605 return status;
1606 }
1607
1608
1609 /*******************************************************************************
1610 * Function Name: Cy_Prot_DisablePpuProgSlaveStruct
1611 ****************************************************************************//**
1612 *
1613 * Disables the Slave PPU PROG structure.
1614 *
1615 * This is a PPU PROG slave struct disable function. The PPU PROG protection
1616 * settings will seize to take effect after successful completion of this
1617 * function call.
1618 *
1619 * \note This function is applicable for CPUSS ver_1 only.
1620 *
1621 * \param base
1622 * The base address for the protection unit structure being configured.
1623 *
1624 * \return
1625 * Status of the function call.
1626 *
1627 * Status | Description
1628 * ------------ | -----------
1629 * CY_PROT_SUCCESS | The Slave PU struct was disabled.
1630 * CY_PROT_FAILURE | The Slave PU struct is enabled and possibly locked.
1631 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1632 *
1633 * \funcusage
1634 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisablePpuProgSlaveStruct
1635 *
1636 *******************************************************************************/
Cy_Prot_DisablePpuProgSlaveStruct(PERI_PPU_PR_Type * base)1637 cy_en_prot_status_t Cy_Prot_DisablePpuProgSlaveStruct(PERI_PPU_PR_Type* base)
1638 {
1639 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1640
1641 CY_ASSERT_L1(NULL != base);
1642
1643 if (CY_PERI_V1)
1644 {
1645 PERI_PPU_PR_ATT0(base) &= ~_VAL2FLD(PERI_PPU_PR_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
1646 status = (_FLD2VAL(PERI_PPU_PR_ATT0_ENABLED, PERI_PPU_PR_ATT0(base)) == CY_PROT_STRUCT_ENABLE) ?
1647 CY_PROT_FAILURE : CY_PROT_SUCCESS;
1648 }
1649
1650 return status;
1651 }
1652
1653
1654 /*******************************************************************************
1655 * Function Name: Cy_Prot_GetPpuProgStruct
1656 ****************************************************************************//**
1657 *
1658 * Functions returns a pointer of the requested unused Programmable PPU
1659 * structure. Function searches the Programmable PPU structure until it finds
1660 * one that both the slave and master sections are disabled. After an available
1661 * structure is located, function enables the slave structure and enables all
1662 * attributes, to make sure that a subsequent call will not see this
1663 * as an available (unused) Programmable PPU.
1664 *
1665 * It is up to the user to implement, if needed, a system in which a semaphore
1666 * will lock-out all but one CPU from calling this function at once.
1667 *
1668 * \note This function is applicable for CPUSS ver_1 only.
1669 *
1670 * \param base
1671 * The base address for the Programmable PPU structure returned if an unused
1672 * structure was found. If an empty structure was not found, the returned
1673 * pointer is NULL.
1674 *
1675 * \param reqMode
1676 * This parameter (request mode) selects how the user wants to select a
1677 * Programmable PPU structure.
1678 *
1679 * reqMode | Description
1680 * --------------------------| -----------------------------
1681 * CY_PROT_REQMODE_HIGHPRIOR | Return the Programmable PPU structure with the highest priority.
1682 * CY_PROT_REQMODE_LOWPRIOR | Return the Programmable PPU structure with the lowest priority.
1683 * CY_PROT_REQMODE_INDEX | Return the Programmable PPU structure with the specific index.
1684 *
1685 * \param ppuProgIndex
1686 * This is the index of the requested Programmable PPU structure. It is only
1687 * used if the request mode is reqMode = CY_PROT_REQMODE_INDEX.
1688 *
1689 * \return
1690 * Status of the function call.
1691 *
1692 * Status | Description
1693 * ----------------------| ---------------------------------------
1694 * CY_PROT_SUCCESS | The Slave PU struct was disabled.
1695 * CY_PROT_FAILURE | The Master or Slave Programmable PPU struct is disabled and possibly locked.
1696 * CY_PROT_UNAVAILABLE | The requested structure in use or there were no unused structures.
1697 * CY_PROT_INVALID_STATE | Function was called on unsupported PERI HW version.
1698 *
1699 * \funcusage
1700 * \snippet prot/snippet/main.c snippet_Cy_Prot_GetPpuProgStruct
1701 *
1702 *******************************************************************************/
Cy_Prot_GetPpuProgStruct(PERI_PPU_PR_Type ** base,cy_en_prot_req_mode_t reqMode,uint32_t ppuProgIndex)1703 cy_en_prot_status_t Cy_Prot_GetPpuProgStruct(PERI_PPU_PR_Type** base, cy_en_prot_req_mode_t reqMode, uint32_t ppuProgIndex)
1704 {
1705 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1706
1707 if (CY_PERI_V1)
1708 {
1709 CY_ASSERT_L3(CY_PROT_IS_PPU_PROG_REQ_MODE_VALID(reqMode));
1710 CY_ASSERT_L2(CY_PROT_IS_PPU_PROG_IDX_VALID(ppuProgIndex));
1711
1712 status = CY_PROT_UNAVAILABLE;
1713 int32_t stcIdx = (int32_t) ppuProgIndex;
1714
1715 *base = NULL;
1716
1717 switch (reqMode)
1718 {
1719 /* Programmed structures priority goes from 0 (highest) to
1720 * PROT_PPU_PROG_STRUCT_WTH_LOWEST_PR (lowest)
1721 */
1722 case CY_PROT_REQMODE_LOWPRIOR:
1723
1724 stcIdx = PROT_PPU_PROG_STRUCT_WTH_LOWEST_PR;
1725 do
1726 {
1727 if (Prot_IsPpuProgStructDisabled((uint32_t)stcIdx))
1728 {
1729 status = CY_PROT_SUCCESS;
1730 }
1731 else
1732 {
1733 --stcIdx;
1734 }
1735 } while ((stcIdx >= 0) && (CY_PROT_SUCCESS != status));
1736 break;
1737
1738 /* Programmed structures priority goes from 0 (highest) to
1739 * PROT_PPU_PROG_STRUCT_WTH_LOWEST_PR (lowest)
1740 */
1741 case CY_PROT_REQMODE_HIGHPRIOR:
1742 stcIdx = 0;
1743 do
1744 {
1745 if (Prot_IsPpuProgStructDisabled((uint32_t)stcIdx))
1746 {
1747 status = CY_PROT_SUCCESS;
1748 }
1749 else
1750 {
1751 ++stcIdx;
1752 }
1753 } while ((stcIdx <= PROT_PPU_PROG_STRUCT_WTH_LOWEST_PR) && (CY_PROT_SUCCESS != status));
1754 break;
1755
1756 case CY_PROT_REQMODE_INDEX:
1757
1758 if (Prot_IsPpuProgStructDisabled((uint32_t)stcIdx))
1759 {
1760 status = CY_PROT_SUCCESS;
1761 }
1762 break;
1763
1764 default:
1765 /* Unknown request mode */
1766 break;
1767 }
1768
1769 /* Enable Programmable PPU struct */
1770 if (CY_PROT_SUCCESS == status)
1771 {
1772 PROT_PERI_PPU_PR_STRUCT_IDX_ATT0(stcIdx) |= _VAL2FLD(PERI_PPU_PR_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
1773
1774 status =
1775 (_FLD2VAL(PERI_PPU_PR_ATT0_ENABLED, PROT_PERI_PPU_PR_STRUCT_IDX_ATT0(stcIdx)) != CY_PROT_STRUCT_ENABLE) ?
1776 CY_PROT_FAILURE : CY_PROT_SUCCESS;
1777
1778 /* Enable all attributes only if Slave struct was enabled */
1779 if (CY_PROT_SUCCESS == status)
1780 {
1781 *base = (PERI_PPU_PR_Type*) PROT_PERI_PPU_PR_STRUCT_IDX(stcIdx);
1782 PROT_PERI_PPU_PR_STRUCT_IDX_ATT0(stcIdx) |= PROT_PERI_PPU_PR_ATT0_ENABLE_ALL_MASK;
1783 }
1784 }
1785 }
1786
1787 return status;
1788 }
1789
1790
1791
1792 /*******************************************************************************
1793 * Function Name: Cy_Prot_ConfigPpuFixedGrMasterStruct
1794 ****************************************************************************//**
1795 *
1796 * Configures a Fixed Peripheral Group Protection Unit (PPU GR) master
1797 * protection struct with its protection attributes.
1798 *
1799 * This function configures the master struct governing the corresponding slave
1800 * struct pair. It is a mechanism to protect the slave PPU GR struct. Since
1801 * the memory location of the slave struct is known, the address, regionSize and
1802 * subregions of the configuration struct are not applicable.
1803 *
1804 * Note that only the user/privileged write permissions are configurable. The
1805 * read and execute permissions are read-only and cannot be configured.
1806 *
1807 * \note This function is applicable for CPUSS ver_1 only.
1808 *
1809 * \param base
1810 * The register base address of the protection struct being configured.
1811 *
1812 * \param config
1813 * Initialization structure with all the protection attributes.
1814 *
1815 * \return
1816 * Status of the function call.
1817 *
1818 * Status | Description
1819 * ------------ | -----------
1820 * CY_PROT_SUCCESS | PPU GR master struct was successfully configured.
1821 * CY_PROT_FAILURE | The resource is locked.
1822 * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed.
1823 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1824 *
1825 * \funcusage
1826 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuFixedGrMasterStruct
1827 *
1828 *******************************************************************************/
Cy_Prot_ConfigPpuFixedGrMasterStruct(PERI_PPU_GR_Type * base,const cy_stc_ppu_gr_cfg_t * config)1829 cy_en_prot_status_t Cy_Prot_ConfigPpuFixedGrMasterStruct(PERI_PPU_GR_Type* base, const cy_stc_ppu_gr_cfg_t* config)
1830 {
1831 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1832 uint32_t attReg;
1833
1834 CY_ASSERT_L1(NULL != base);
1835 CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->userPermission));
1836 CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->privPermission));
1837
1838 if (CY_PERI_V1)
1839 {
1840 if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL)
1841 {
1842 /* PC mask out of range - not supported in device */
1843 status = CY_PROT_BAD_PARAM;
1844 }
1845 else
1846 {
1847 /* ADDR1 is read only. Only configure ATT1 */
1848 attReg = (((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK))
1849 | (uint32_t)(((uint32_t)config->privPermission & CY_PROT_ATT_PERMISSION_MASK) << CY_PROT_ATT_PRIV_PERMISSION_SHIFT)
1850 | _VAL2FLD(PERI_PPU_GR_ATT1_NS, !(config->secure))
1851 | _VAL2FLD(PERI_PPU_GR_ATT1_PC_MASK_15_TO_1, config->pcMask)
1852 /* No region size - read only for master structs */
1853 | _VAL2FLD(PERI_PPU_GR_ATT1_PC_MATCH, config->pcMatch);
1854 if ((attReg & CY_PROT_PPU_GR_ATT1_MASK) != attReg)
1855 {
1856 /* Invalid parameter was passed */
1857 status = CY_PROT_BAD_PARAM;
1858 }
1859 else
1860 {
1861 PERI_PPU_GR_ATT1(base) = attReg;
1862 status = ((PERI_PPU_GR_ATT1(base) & CY_PROT_PPU_GR_ATT1_MASK) != attReg) ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
1863 }
1864 }
1865 }
1866
1867 return status;
1868 }
1869
1870
1871 /*******************************************************************************
1872 * Function Name: Cy_Prot_ConfigPpuFixedGrSlaveStruct
1873 ****************************************************************************//**
1874 *
1875 * Configures a Fixed Peripheral Group Protection Unit (PPU GR) slave
1876 * protection struct with its protection attributes.
1877 *
1878 * This function configures the slave struct of a PPU GR pair, which can
1879 * protect an entire peripheral MMIO group from invalid bus master accesses.
1880 * Refer to the device Technical Reference manual for details on peripheral
1881 * MMIO grouping and which peripherals belong to which groups.
1882 *
1883 * Each fixed PPU GR is devoted to a defined MMIO group. Hence the address,
1884 * regionSize and subregions of the configuration struct are not applicable.
1885 *
1886 * Note that the user/privileged execute accesses are read-only and are always
1887 * enabled.
1888 *
1889 * \note This function is applicable for CPUSS ver_1 only.
1890 *
1891 * \param base
1892 * The register base address of the protection structure being configured.
1893 *
1894 * \param config
1895 * Initialization structure with all the protection attributes.
1896 *
1897 * \return
1898 * Status of the function call.
1899 *
1900 * Status | Description
1901 * ------------ | -----------
1902 * CY_PROT_SUCCESS | PPU GR slave struct was successfully configured.
1903 * CY_PROT_FAILURE | The resource is locked.
1904 * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed.
1905 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1906 *
1907 * \funcusage
1908 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuFixedGrSlaveStruct
1909 *
1910 *******************************************************************************/
Cy_Prot_ConfigPpuFixedGrSlaveStruct(PERI_PPU_GR_Type * base,const cy_stc_ppu_gr_cfg_t * config)1911 cy_en_prot_status_t Cy_Prot_ConfigPpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base, const cy_stc_ppu_gr_cfg_t* config)
1912 {
1913 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1914 uint32_t attReg;
1915
1916 CY_ASSERT_L1(NULL != base);
1917 CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->userPermission));
1918 CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->privPermission));
1919
1920 if (CY_PERI_V1)
1921 {
1922 if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL)
1923 {
1924 /* PC mask out of range - not supported in device */
1925 status = CY_PROT_BAD_PARAM;
1926 }
1927 else
1928 {
1929 /* ADDR0 is read only. Only configure ATT0 */
1930 attReg = (uint32_t)(((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK))
1931 | (uint32_t)(((uint32_t)config->privPermission & CY_PROT_ATT_PERMISSION_MASK) << CY_PROT_ATT_PRIV_PERMISSION_SHIFT)
1932 | _VAL2FLD(PERI_PPU_GR_ATT0_NS, !(config->secure))
1933 | _VAL2FLD(PERI_PPU_GR_ATT0_PC_MASK_15_TO_1, config->pcMask)
1934 /* No region size - read only */
1935 | _VAL2FLD(PERI_PPU_GR_ATT0_PC_MATCH, config->pcMatch);
1936 if ((attReg & CY_PROT_PPU_GR_ATT0_MASK) != attReg)
1937 {
1938 /* Invalid parameter was passed */
1939 status = CY_PROT_BAD_PARAM;
1940 }
1941 else
1942 {
1943 PERI_PPU_GR_ATT0(base) = attReg;
1944 status = ((PERI_PPU_GR_ATT0(base) & CY_PROT_PPU_GR_ATT0_MASK) != attReg) ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
1945 }
1946 }
1947 }
1948
1949 return status;
1950 }
1951
1952
1953 /*******************************************************************************
1954 * Function Name: Cy_Prot_EnablePpuFixedGrMasterStruct
1955 ****************************************************************************//**
1956 *
1957 * Enables the Master PPU GR structure.
1958 *
1959 * This is a PPU GR master struct enable function. The PPU GR protection
1960 * settings will take effect after successful completion of this function call.
1961 *
1962 * \note This function is applicable for CPUSS ver_1 only.
1963 *
1964 * \param base
1965 * The base address for the protection unit structure being configured.
1966 *
1967 * \return
1968 * Status of the function call.
1969 *
1970 * Status | Description
1971 * ------------ | -----------
1972 * CY_PROT_SUCCESS | The Master PU struct was enabled.
1973 * CY_PROT_FAILURE | The Master PU struct is disabled and possibly locked.
1974 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
1975 *
1976 * \funcusage
1977 * \snippet prot/snippet/main.c snippet_Cy_Prot_EnablePpuFixedGrMasterStruct
1978 *
1979 *******************************************************************************/
Cy_Prot_EnablePpuFixedGrMasterStruct(PERI_PPU_GR_Type * base)1980 cy_en_prot_status_t Cy_Prot_EnablePpuFixedGrMasterStruct(PERI_PPU_GR_Type* base)
1981 {
1982 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
1983
1984 CY_ASSERT_L1(NULL != base);
1985
1986 if (CY_PERI_V1)
1987 {
1988 PERI_PPU_GR_ATT1(base) |= _VAL2FLD(PERI_PPU_GR_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE);
1989 status = (_FLD2VAL(PERI_PPU_GR_ATT1_ENABLED, PERI_PPU_GR_ATT1(base)) != CY_PROT_STRUCT_ENABLE) ?
1990 CY_PROT_FAILURE : CY_PROT_SUCCESS;
1991 }
1992
1993 return status;
1994 }
1995
1996
1997 /*******************************************************************************
1998 * Function Name: Cy_Prot_DisablePpuFixedGrMasterStruct
1999 ****************************************************************************//**
2000 *
2001 * Disables the Master PPU GR structure.
2002 *
2003 * This is a PPU GR master struct disable function. The PPU GR protection
2004 * settings will seize to take effect after successful completion of this
2005 * function call.
2006 *
2007 * \note This function is applicable for CPUSS ver_1 only.
2008 *
2009 * \param base
2010 * The base address for the protection unit structure being configured.
2011 *
2012 * \return
2013 * Status of the function call.
2014 *
2015 * Status | Description
2016 * ------------ | -----------
2017 * CY_PROT_SUCCESS | The Master PU struct was disabled.
2018 * CY_PROT_FAILURE | The Master PU struct is enabled and possibly locked.
2019 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2020 *
2021 * \funcusage
2022 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisablePpuFixedGrMasterStruct
2023 *
2024 *******************************************************************************/
Cy_Prot_DisablePpuFixedGrMasterStruct(PERI_PPU_GR_Type * base)2025 cy_en_prot_status_t Cy_Prot_DisablePpuFixedGrMasterStruct(PERI_PPU_GR_Type* base)
2026 {
2027 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2028
2029 CY_ASSERT_L1(NULL != base);
2030
2031 if (CY_PERI_V1)
2032 {
2033 PERI_PPU_GR_ATT1(base) &= ~_VAL2FLD(PERI_PPU_GR_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE);
2034 status = (_FLD2VAL(PERI_PPU_GR_ATT1_ENABLED, PERI_PPU_GR_ATT1(base)) == CY_PROT_STRUCT_ENABLE) ?
2035 CY_PROT_FAILURE : CY_PROT_SUCCESS;
2036 }
2037
2038 return status;
2039 }
2040
2041
2042 /*******************************************************************************
2043 * Function Name: Cy_Prot_EnablePpuFixedGrSlaveStruct
2044 ****************************************************************************//**
2045 *
2046 * Enables the Slave PPU GR structure.
2047 *
2048 * This is a PPU GR slave struct enable function. The PPU GR protection
2049 * settings will take effect after successful completion of this function call.
2050 *
2051 * \note This function is applicable for CPUSS ver_1 only.
2052 *
2053 * \param base
2054 * The base address for the protection unit structure being configured.
2055 *
2056 * \return
2057 * Status of the function call.
2058 *
2059 * Status | Description
2060 * ------------ | -----------
2061 * CY_PROT_SUCCESS | The Slave PU struct was enabled.
2062 * CY_PROT_FAILURE | The Slave PU struct is disabled and possibly locked.
2063 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2064 *
2065 * \funcusage
2066 * \snippet prot/snippet/main.c snippet_Cy_Prot_EnablePpuFixedGrSlaveStruct
2067 *
2068 *******************************************************************************/
Cy_Prot_EnablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type * base)2069 cy_en_prot_status_t Cy_Prot_EnablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base)
2070 {
2071 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2072
2073 CY_ASSERT_L1(NULL != base);
2074
2075 if (CY_PERI_V1)
2076 {
2077 PERI_PPU_GR_ATT0(base) |= _VAL2FLD(PERI_PPU_GR_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
2078 status = (_FLD2VAL(PERI_PPU_GR_ATT0_ENABLED, PERI_PPU_GR_ATT0(base)) != CY_PROT_STRUCT_ENABLE) ?
2079 CY_PROT_FAILURE : CY_PROT_SUCCESS;
2080 }
2081
2082 return status;
2083 }
2084
2085
2086 /*******************************************************************************
2087 * Function Name: Cy_Prot_DisablePpuFixedGrSlaveStruct
2088 ****************************************************************************//**
2089 *
2090 * Disables the Slave PPU GR structure.
2091 *
2092 * This is a PPU GR slave struct disable function. The PPU GR protection
2093 * settings will seize to take effect after successful completion of this
2094 * function call.
2095 *
2096 * \note This function is applicable for CPUSS ver_1 only.
2097 *
2098 * \param base
2099 * The base address for the protection unit structure being configured.
2100 *
2101 * \return
2102 * Status of the function call.
2103 *
2104 * Status | Description
2105 * ------------ | -----------
2106 * CY_PROT_SUCCESS | The Slave PU struct was disabled.
2107 * CY_PROT_FAILURE | The Slave PU struct is enabled and possibly locked.
2108 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2109 *
2110 * \funcusage
2111 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisablePpuFixedGrSlaveStruct
2112 *
2113 *******************************************************************************/
Cy_Prot_DisablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type * base)2114 cy_en_prot_status_t Cy_Prot_DisablePpuFixedGrSlaveStruct(PERI_PPU_GR_Type* base)
2115 {
2116 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2117
2118 CY_ASSERT_L1(NULL != base);
2119
2120 if (CY_PERI_V1)
2121 {
2122 PERI_PPU_GR_ATT0(base) &= ~_VAL2FLD(PERI_PPU_GR_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
2123 status = (_FLD2VAL(PERI_PPU_GR_ATT0_ENABLED, PERI_PPU_GR_ATT0(base)) == CY_PROT_STRUCT_ENABLE) ?
2124 CY_PROT_FAILURE : CY_PROT_SUCCESS;
2125 }
2126
2127 return status;
2128 }
2129
2130
2131 /*******************************************************************************
2132 * Function Name: Cy_Prot_ConfigPpuFixedSlMasterStruct
2133 ****************************************************************************//**
2134 *
2135 * Configures a Fixed Peripheral Slave Protection Unit (PPU SL) master
2136 * protection struct with its protection attributes.
2137 *
2138 * This function configures the master struct governing the corresponding slave
2139 * struct pair. It is a mechanism to protect the slave PPU SL struct. Since
2140 * the memory location of the slave struct is known, the address, regionSize and
2141 * subregions of the configuration struct are not applicable.
2142 *
2143 * Note that only the user/privileged write permissions are configurable. The
2144 * read and execute permissions are read-only and cannot be configured.
2145 *
2146 * \note This function is applicable for CPUSS ver_1 only.
2147 *
2148 * \param base
2149 * The register base address of the protection struct being configured.
2150 *
2151 * \param config
2152 * Initialization structure with all the protection attributes.
2153 *
2154 * \return
2155 * Status of the function call.
2156 *
2157 * Status | Description
2158 * ------------ | -----------
2159 * CY_PROT_SUCCESS | PPU SL master struct was successfully configured.
2160 * CY_PROT_FAILURE | The resource is locked.
2161 * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed.
2162 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2163 *
2164 * \funcusage
2165 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuFixedSlMasterStruct
2166 *
2167 *******************************************************************************/
Cy_Prot_ConfigPpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type * base,const cy_stc_ppu_sl_cfg_t * config)2168 cy_en_prot_status_t Cy_Prot_ConfigPpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base, const cy_stc_ppu_sl_cfg_t* config)
2169 {
2170 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2171 uint32_t attReg;
2172
2173 CY_ASSERT_L1(NULL != base);
2174 CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->userPermission));
2175 CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->privPermission));
2176
2177 if (CY_PERI_V1)
2178 {
2179 if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL)
2180 {
2181 /* PC mask out of range - not supported in device */
2182 status = CY_PROT_BAD_PARAM;
2183 }
2184 else
2185 {
2186 /* ADDR1 is read only. Only configure ATT1 */
2187 attReg = ((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK)
2188 | (uint32_t)(((uint32_t)config->privPermission & CY_PROT_ATT_PERMISSION_MASK) << CY_PROT_ATT_PRIV_PERMISSION_SHIFT)
2189 | _VAL2FLD(PERI_GR_PPU_SL_ATT1_NS, !(config->secure))
2190 | _VAL2FLD(PERI_GR_PPU_SL_ATT1_PC_MASK_15_TO_1, config->pcMask)
2191 /* No region size - read only for master structs */
2192 | _VAL2FLD(PERI_GR_PPU_SL_ATT1_PC_MATCH, config->pcMatch);
2193 if ((attReg & CY_PROT_PPU_SL_ATT1_MASK) != attReg)
2194 {
2195 /* Invalid parameter was passed */
2196 status = CY_PROT_BAD_PARAM;
2197 }
2198 else
2199 {
2200 PERI_GR_PPU_SL_ATT1(base) = attReg;
2201 status = ((PERI_GR_PPU_SL_ATT1(base) & CY_PROT_PPU_SL_ATT1_MASK) != attReg) ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
2202 }
2203 }
2204 }
2205
2206 return status;
2207 }
2208
2209
2210 /*******************************************************************************
2211 * Function Name: Cy_Prot_ConfigPpuFixedSlSlaveStruct
2212 ****************************************************************************//**
2213 *
2214 * Configures a Fixed Peripheral Slave Protection Unit (PPU SL) slave
2215 * protection struct with its protection attributes.
2216 *
2217 * This function configures the slave struct of a PPU SL pair, which can
2218 * protect an entire peripheral slave instance from invalid bus master accesses.
2219 * For example, TCPWM0, TCPWM1, SCB0 and SCB1 etc.
2220 *
2221 * Each fixed PPU SL is devoted to a defined peripheral slave. Hence the address,
2222 * regionSize and subregions of the configuration struct are not applicable.
2223 *
2224 * Note that the user/privileged execute accesses are read-only and are always
2225 * enabled.
2226 *
2227 * \note This function is applicable for CPUSS ver_1 only.
2228 *
2229 * \param base
2230 * The register base address of the protection structure being configured.
2231 *
2232 * \param config
2233 * Initialization structure with all the protection attributes.
2234 *
2235 * \return
2236 * Status of the function call.
2237 *
2238 * Status | Description
2239 * ------------ | -----------
2240 * CY_PROT_SUCCESS | PPU SL slave struct was successfully configured.
2241 * CY_PROT_FAILURE | The resource is locked.
2242 * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed.
2243 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2244 *
2245 * \funcusage
2246 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuFixedSlSlaveStruct
2247 *
2248 *******************************************************************************/
Cy_Prot_ConfigPpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type * base,const cy_stc_ppu_sl_cfg_t * config)2249 cy_en_prot_status_t Cy_Prot_ConfigPpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base, const cy_stc_ppu_sl_cfg_t* config)
2250 {
2251 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2252 uint32_t attReg;
2253
2254 CY_ASSERT_L1(NULL != base);
2255 CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->userPermission));
2256 CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->privPermission));
2257
2258 if (CY_PERI_V1)
2259 {
2260 if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL)
2261 {
2262 /* PC mask out of range - not supported in device */
2263 status = CY_PROT_BAD_PARAM;
2264 }
2265 else
2266 {
2267 /* ADDR0 is read only. Only configure ATT0 */
2268 attReg = ((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK)
2269 | (uint32_t)(((uint32_t)config->privPermission & CY_PROT_ATT_PERMISSION_MASK) << CY_PROT_ATT_PRIV_PERMISSION_SHIFT)
2270 | _VAL2FLD(PERI_GR_PPU_SL_ATT0_NS, !(config->secure))
2271 | _VAL2FLD(PERI_GR_PPU_SL_ATT0_PC_MASK_15_TO_1, config->pcMask)
2272 /* No region size - read only */
2273 | _VAL2FLD(PERI_GR_PPU_SL_ATT0_PC_MATCH, config->pcMatch);
2274 if ((attReg & CY_PROT_PPU_SL_ATT0_MASK) != attReg)
2275 {
2276 /* Invalid parameter was passed */
2277 status = CY_PROT_BAD_PARAM;
2278 }
2279 else
2280 {
2281 PERI_GR_PPU_SL_ATT0(base) = attReg;
2282 status = ((PERI_GR_PPU_SL_ATT0(base) & CY_PROT_PPU_SL_ATT0_MASK) != attReg) ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
2283 }
2284 }
2285 }
2286
2287 return status;
2288 }
2289
2290
2291 /*******************************************************************************
2292 * Function Name: Cy_Prot_EnablePpuFixedSlMasterStruct
2293 ****************************************************************************//**
2294 *
2295 * Enables the Master PPU SL structure.
2296 *
2297 * This is a PPU SL master struct enable function. The PPU SL protection
2298 * settings will take effect after successful completion of this function call.
2299 *
2300 * \note This function is applicable for CPUSS ver_1 only.
2301 *
2302 * \param base
2303 * The base address for the protection unit structure being configured.
2304 *
2305 * \return
2306 * Status of the function call.
2307 *
2308 * Status | Description
2309 * ------------ | -----------
2310 * CY_PROT_SUCCESS | The Master PU struct was enabled.
2311 * CY_PROT_FAILURE | The Master PU struct is disabled and possibly locked.
2312 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2313 *
2314 * \funcusage
2315 * \snippet prot/snippet/main.c snippet_Cy_Prot_EnablePpuFixedSlMasterStruct
2316 *
2317 *******************************************************************************/
Cy_Prot_EnablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type * base)2318 cy_en_prot_status_t Cy_Prot_EnablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base)
2319 {
2320 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2321
2322 CY_ASSERT_L1(NULL != base);
2323
2324 if (CY_PERI_V1)
2325 {
2326 PERI_GR_PPU_SL_ATT1(base) |= _VAL2FLD(PERI_GR_PPU_SL_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE);
2327 status = (_FLD2VAL(PERI_GR_PPU_SL_ATT1_ENABLED, PERI_GR_PPU_SL_ATT1(base)) != CY_PROT_STRUCT_ENABLE) ?
2328 CY_PROT_FAILURE : CY_PROT_SUCCESS;
2329 }
2330
2331 return status;
2332 }
2333
2334
2335 /*******************************************************************************
2336 * Function Name: Cy_Prot_DisablePpuFixedSlMasterStruct
2337 ****************************************************************************//**
2338 *
2339 * Disables the Master PPU SL structure.
2340 *
2341 * This is a PPU SL master struct disable function. The PPU SL protection
2342 * settings will seize to take effect after successful completion of this
2343 * function call.
2344 *
2345 * \note This function is applicable for CPUSS ver_1 only.
2346 *
2347 * \param base
2348 * The base address for the protection unit structure being configured.
2349 *
2350 * \return
2351 * Status of the function call.
2352 *
2353 * Status | Description
2354 * ------------ | -----------
2355 * CY_PROT_SUCCESS | The Master PU struct was disabled.
2356 * CY_PROT_FAILURE | The Master PU struct is enabled and possibly locked.
2357 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2358 *
2359 * \funcusage
2360 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisablePpuFixedSlMasterStruct
2361 *
2362 *******************************************************************************/
Cy_Prot_DisablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type * base)2363 cy_en_prot_status_t Cy_Prot_DisablePpuFixedSlMasterStruct(PERI_GR_PPU_SL_Type* base)
2364 {
2365 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2366
2367 CY_ASSERT_L1(NULL != base);
2368
2369 if (CY_PERI_V1)
2370 {
2371 PERI_GR_PPU_SL_ATT1(base) &= ~_VAL2FLD(PERI_GR_PPU_SL_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE);
2372 status = (_FLD2VAL(PERI_GR_PPU_SL_ATT1_ENABLED, PERI_GR_PPU_SL_ATT1(base)) == CY_PROT_STRUCT_ENABLE) ?
2373 CY_PROT_FAILURE : CY_PROT_SUCCESS;
2374 }
2375
2376 return status;
2377 }
2378
2379
2380 /*******************************************************************************
2381 * Function Name: Cy_Prot_EnablePpuFixedSlSlaveStruct
2382 ****************************************************************************//**
2383 *
2384 * Enables the Slave PPU SL structure.
2385 *
2386 * This is a PPU SL slave struct enable function. The PPU SL protection
2387 * settings will take effect after successful completion of this function call.
2388 *
2389 * \note This function is applicable for CPUSS ver_1 only.
2390 *
2391 * \param base
2392 * The base address for the protection unit structure being configured.
2393 *
2394 * \return
2395 * Status of the function call.
2396 *
2397 * Status | Description
2398 * ------------ | -----------
2399 * CY_PROT_SUCCESS | The Slave PU struct was enabled.
2400 * CY_PROT_FAILURE | The Slave PU struct is disabled and possibly locked.
2401 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2402 *
2403 * \funcusage
2404 * \snippet prot/snippet/main.c snippet_Cy_Prot_EnablePpuFixedSlSlaveStruct
2405 *
2406 *******************************************************************************/
Cy_Prot_EnablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type * base)2407 cy_en_prot_status_t Cy_Prot_EnablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base)
2408 {
2409 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2410
2411 CY_ASSERT_L1(NULL != base);
2412
2413 if (CY_PERI_V1)
2414 {
2415 PERI_GR_PPU_SL_ATT0(base) |= _VAL2FLD(PERI_GR_PPU_SL_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
2416 status = (_FLD2VAL(PERI_GR_PPU_SL_ATT0_ENABLED, PERI_GR_PPU_SL_ATT0(base)) != CY_PROT_STRUCT_ENABLE) ?
2417 CY_PROT_FAILURE : CY_PROT_SUCCESS;
2418 }
2419
2420 return status;
2421 }
2422
2423
2424 /*******************************************************************************
2425 * Function Name: Cy_Prot_DisablePpuFixedSlSlaveStruct
2426 ****************************************************************************//**
2427 *
2428 * Disables the Slave PPU SL structure.
2429 *
2430 * This is a PPU SL slave struct disable function. The PPU SL protection
2431 * settings will seize to take effect after successful completion of this
2432 * function call.
2433 *
2434 * \note This function is applicable for CPUSS ver_1 only.
2435 *
2436 * \param base
2437 * The base address for the protection unit structure being configured.
2438 *
2439 * \return
2440 * Status of the function call.
2441 *
2442 * Status | Description
2443 * ------------ | -----------
2444 * CY_PROT_SUCCESS | The Slave PU struct was enabled.
2445 * CY_PROT_FAILURE | The Slave PU struct is disabled and possibly locked.
2446 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2447 *
2448 * \funcusage
2449 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisablePpuFixedSlSlaveStruct
2450 *
2451 *******************************************************************************/
Cy_Prot_DisablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type * base)2452 cy_en_prot_status_t Cy_Prot_DisablePpuFixedSlSlaveStruct(PERI_GR_PPU_SL_Type* base)
2453 {
2454 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2455
2456 CY_ASSERT_L1(NULL != base);
2457
2458 if (CY_PERI_V1)
2459 {
2460 PERI_GR_PPU_SL_ATT0(base) &= ~_VAL2FLD(PERI_GR_PPU_SL_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
2461 status = (_FLD2VAL(PERI_GR_PPU_SL_ATT0_ENABLED, PERI_GR_PPU_SL_ATT0(base)) == CY_PROT_STRUCT_ENABLE) ?
2462 CY_PROT_FAILURE : CY_PROT_SUCCESS;
2463 }
2464
2465 return status;
2466 }
2467
2468
2469 /*******************************************************************************
2470 * Function Name: Cy_Prot_ConfigPpuFixedRgMasterStruct
2471 ****************************************************************************//**
2472 *
2473 * Configures a Fixed Peripheral Region Protection Unit (PPU RG) master
2474 * protection struct with its protection attributes.
2475 *
2476 * This function configures the master struct governing the corresponding slave
2477 * struct pair. It is a mechanism to protect the slave PPU RG struct. Since
2478 * the memory location of the slave struct is known, the address, regionSize and
2479 * subregions of the configuration struct are not applicable.
2480 *
2481 * Note that only the user/privileged write permissions are configurable. The
2482 * read and execute permissions are read-only and cannot be configured.
2483 *
2484 * \note This function is applicable for CPUSS ver_1 only.
2485 *
2486 * \param base
2487 * The register base address of the protection struct being configured.
2488 *
2489 * \param config
2490 * Initialization structure with all the protection attributes.
2491 *
2492 * \return
2493 * Status of the function call.
2494 *
2495 * Status | Description
2496 * ------------ | -----------
2497 * CY_PROT_SUCCESS | PPU RG master struct was successfully configured.
2498 * CY_PROT_FAILURE | The resource is locked.
2499 * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed.
2500 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2501 *
2502 * \funcusage
2503 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuFixedRgMasterStruct
2504 *
2505 *******************************************************************************/
Cy_Prot_ConfigPpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type * base,const cy_stc_ppu_rg_cfg_t * config)2506 cy_en_prot_status_t Cy_Prot_ConfigPpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base, const cy_stc_ppu_rg_cfg_t* config)
2507 {
2508 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2509 uint32_t attReg;
2510
2511 CY_ASSERT_L1(NULL != base);
2512 CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->userPermission));
2513 CY_ASSERT_L3(CY_PROT_IS_FIXED_MS_PERM_VALID(config->privPermission));
2514
2515 if (CY_PERI_V1)
2516 {
2517 if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL)
2518 {
2519 /* PC mask out of range - not supported in device */
2520 status = CY_PROT_BAD_PARAM;
2521 }
2522 else
2523 {
2524 /* ADDR1 is read only. Only configure ATT1 */
2525 attReg = ((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK)
2526 | (uint32_t)(((uint32_t)config->privPermission & CY_PROT_ATT_PERMISSION_MASK) << CY_PROT_ATT_PRIV_PERMISSION_SHIFT)
2527 | _VAL2FLD(PERI_GR_PPU_RG_ATT1_NS, !(config->secure))
2528 | _VAL2FLD(PERI_GR_PPU_RG_ATT1_PC_MASK_15_TO_1, config->pcMask)
2529 /* No region size - read only for master structs */
2530 | _VAL2FLD(PERI_GR_PPU_RG_ATT1_PC_MATCH, config->pcMatch);
2531 if ((attReg & CY_PROT_PPU_RG_ATT1_MASK) != attReg)
2532 {
2533 /* Invalid parameter was passed */
2534 status = CY_PROT_BAD_PARAM;
2535 }
2536 else
2537 {
2538 PERI_GR_PPU_RG_ATT1(base) = attReg;
2539 status = ((PERI_GR_PPU_RG_ATT1(base) & CY_PROT_PPU_RG_ATT1_MASK) != attReg) ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
2540 }
2541 }
2542 }
2543
2544 return status;
2545 }
2546
2547
2548 /*******************************************************************************
2549 * Function Name: Cy_Prot_ConfigPpuFixedRgSlaveStruct
2550 ****************************************************************************//**
2551 *
2552 * Configures a Fixed Peripheral Region Protection Unit (PPU RG) slave
2553 * protection struct with its protection attributes.
2554 *
2555 * This function configures the slave struct of a PPU RG pair, which can
2556 * protect specified regions of peripheral instances. For example, individual
2557 * DW channel structs, SMPU structs, and IPC structs etc.
2558 *
2559 * Each fixed PPU RG is devoted to a defined peripheral region. Hence the address,
2560 * regionSize and subregions of the configuration struct are not applicable.
2561 *
2562 * Note that the user/privileged execute accesses are read-only and are always
2563 * enabled.
2564 *
2565 * \note This function is applicable for CPUSS ver_1 only.
2566 *
2567 * \param base
2568 * The register base address of the protection structure being configured.
2569 *
2570 * \param config
2571 * Initialization structure with all the protection attributes.
2572 *
2573 * \return
2574 * Status of the function call.
2575 *
2576 * Status | Description
2577 * ------------ | -----------
2578 * CY_PROT_SUCCESS | PPU RG slave struct was successfully configured.
2579 * CY_PROT_FAILURE | The resource is locked.
2580 * CY_PROT_BAD_PARAM | An incorrect/invalid parameter was passed.
2581 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2582 *
2583 * \funcusage
2584 * \snippet prot/snippet/main.c snippet_Cy_Prot_ConfigPpuFixedRgSlaveStruct
2585 *
2586 *******************************************************************************/
Cy_Prot_ConfigPpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type * base,const cy_stc_ppu_rg_cfg_t * config)2587 cy_en_prot_status_t Cy_Prot_ConfigPpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base, const cy_stc_ppu_rg_cfg_t* config)
2588 {
2589 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2590 uint32_t attReg;
2591
2592 CY_ASSERT_L1(NULL != base);
2593 CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->userPermission));
2594 CY_ASSERT_L3(CY_PROT_IS_FIXED_SL_PERM_VALID(config->privPermission));
2595
2596 if (CY_PERI_V1)
2597 {
2598 if(((uint32_t)config->pcMask & CY_PROT_PPU_FIXED_PC_LIMIT_MASK) != 0UL)
2599 {
2600 /* PC mask out of range - not supported in device */
2601 status = CY_PROT_BAD_PARAM;
2602 }
2603 else
2604 {
2605 /* ADDR0 is read only. Only configure ATT0 */
2606 attReg = ((uint32_t)config->userPermission & CY_PROT_ATT_PERMISSION_MASK)
2607 | (uint32_t)(((uint32_t)config->privPermission & CY_PROT_ATT_PERMISSION_MASK) << CY_PROT_ATT_PRIV_PERMISSION_SHIFT)
2608 | _VAL2FLD(PERI_GR_PPU_RG_ATT0_NS, !(config->secure))
2609 | _VAL2FLD(PERI_GR_PPU_RG_ATT0_PC_MASK_15_TO_1, config->pcMask)
2610 /* No region size - read only */
2611 | _VAL2FLD(PERI_GR_PPU_RG_ATT0_PC_MATCH, config->pcMatch);
2612 if ((attReg & CY_PROT_PPU_RG_ATT0_MASK) != attReg)
2613 {
2614 /* Invalid parameter was passed */
2615 status = CY_PROT_BAD_PARAM;
2616 }
2617 else
2618 {
2619 PERI_GR_PPU_RG_ATT0(base) = attReg;
2620 status = ((PERI_GR_PPU_RG_ATT0(base) & CY_PROT_PPU_RG_ATT0_MASK) != attReg) ? CY_PROT_FAILURE : CY_PROT_SUCCESS;
2621 }
2622 }
2623 }
2624
2625 return status;
2626 }
2627
2628
2629 /*******************************************************************************
2630 * Function Name: Cy_Prot_EnablePpuFixedRgMasterStruct
2631 ****************************************************************************//**
2632 *
2633 * Enables the Master PPU RG structure.
2634 *
2635 * This is a PPU RG master struct enable function. The PPU RG protection
2636 * settings will take effect after successful completion of this function call.
2637 *
2638 * \note This function is applicable for CPUSS ver_1 only.
2639 *
2640 * \param base
2641 * The base address for the protection unit structure being configured.
2642 *
2643 * \return
2644 * Status of the function call.
2645 *
2646 * Status | Description
2647 * ------------ | -----------
2648 * CY_PROT_SUCCESS | The Master PU struct was enabled.
2649 * CY_PROT_FAILURE | The Master PU struct is disabled and possibly locked.
2650 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2651 *
2652 * \funcusage
2653 * \snippet prot/snippet/main.c snippet_Cy_Prot_EnablePpuFixedRgMasterStruct
2654 *
2655 *******************************************************************************/
Cy_Prot_EnablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type * base)2656 cy_en_prot_status_t Cy_Prot_EnablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base)
2657 {
2658 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2659
2660 if (CY_PERI_V1)
2661 {
2662 PERI_GR_PPU_RG_ATT1(base) |= _VAL2FLD(PERI_GR_PPU_RG_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE);
2663 status = (_FLD2VAL(PERI_GR_PPU_RG_ATT1_ENABLED, PERI_GR_PPU_RG_ATT1(base)) != CY_PROT_STRUCT_ENABLE) ?
2664 CY_PROT_FAILURE : CY_PROT_SUCCESS;
2665 }
2666
2667 return status;
2668 }
2669
2670
2671 /*******************************************************************************
2672 * Function Name: Cy_Prot_DisablePpuFixedRgMasterStruct
2673 ****************************************************************************//**
2674 *
2675 * Disables the Master PPU RG structure.
2676 *
2677 * This is a PPU RG master struct disable function. The PPU RG protection
2678 * settings will seize to take effect after successful completion of this
2679 * function call.
2680 *
2681 * \note This function is applicable for CPUSS ver_1 only.
2682 *
2683 * \param base
2684 * The base address for the protection unit structure being configured.
2685 *
2686 * \return
2687 * Status of the function call.
2688 *
2689 * Status | Description
2690 * ------------ | -----------
2691 * CY_PROT_SUCCESS | The Master PU struct was disabled.
2692 * CY_PROT_FAILURE | The Master PU struct is enabled and possibly locked.
2693 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2694 *
2695 * \funcusage
2696 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisablePpuFixedRgMasterStruct
2697 *
2698 *******************************************************************************/
Cy_Prot_DisablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type * base)2699 cy_en_prot_status_t Cy_Prot_DisablePpuFixedRgMasterStruct(PERI_GR_PPU_RG_Type* base)
2700 {
2701 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2702
2703 if (CY_PERI_V1)
2704 {
2705 PERI_GR_PPU_RG_ATT1(base) &= ~_VAL2FLD(PERI_GR_PPU_RG_ATT1_ENABLED, CY_PROT_STRUCT_ENABLE);
2706 status = (_FLD2VAL(PERI_GR_PPU_RG_ATT1_ENABLED, PERI_GR_PPU_RG_ATT1(base)) == CY_PROT_STRUCT_ENABLE) ?
2707 CY_PROT_FAILURE : CY_PROT_SUCCESS;
2708 }
2709
2710 return status;
2711 }
2712
2713
2714 /*******************************************************************************
2715 * Function Name: Cy_Prot_EnablePpuFixedRgSlaveStruct
2716 ****************************************************************************//**
2717 *
2718 * Enables the Slave PPU RG structure.
2719 *
2720 * This is a PPU RG slave struct enable function. The PPU RG protection
2721 * settings will take effect after successful completion of this function call.
2722 *
2723 * \note This function is applicable for CPUSS ver_1 only.
2724 *
2725 * \param base
2726 * The base address for the protection unit structure being configured.
2727 *
2728 * \return
2729 * Status of the function call.
2730 *
2731 * Status | Description
2732 * ------------ | -----------
2733 * CY_PROT_SUCCESS | The Slave PU struct was enabled.
2734 * CY_PROT_FAILURE | The Slave PU struct is disabled and possibly locked.
2735 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2736 *
2737 * \funcusage
2738 * \snippet prot/snippet/main.c snippet_Cy_Prot_EnablePpuFixedRgSlaveStruct
2739 *
2740 *******************************************************************************/
Cy_Prot_EnablePpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type * base)2741 cy_en_prot_status_t Cy_Prot_EnablePpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base)
2742 {
2743 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2744
2745 if (CY_PERI_V1)
2746 {
2747 PERI_GR_PPU_RG_ATT0(base) |= _VAL2FLD(PERI_GR_PPU_RG_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
2748 status = (_FLD2VAL(PERI_GR_PPU_RG_ATT0_ENABLED, PERI_GR_PPU_RG_ATT0(base)) != CY_PROT_STRUCT_ENABLE) ?
2749 CY_PROT_FAILURE : CY_PROT_SUCCESS;
2750 }
2751
2752 return status;
2753 }
2754
2755
2756 /*******************************************************************************
2757 * Function Name: Cy_Prot_DisablePpuFixedRgSlaveStruct
2758 ****************************************************************************//**
2759 *
2760 * Disables the Slave PPU RG structure.
2761 *
2762 * This is a PPU RG slave struct disable function. The PPU RG protection
2763 * settings will seize to take effect after successful completion of this
2764 * function call.
2765 *
2766 * \note This function is applicable for CPUSS ver_1 only.
2767 *
2768 * \param base
2769 * The base address for the protection unit structure being configured.
2770 *
2771 * \return
2772 * Status of the function call.
2773 *
2774 * Status | Description
2775 * ------------ | -----------
2776 * CY_PROT_SUCCESS | The Slave PU struct was disabled.
2777 * CY_PROT_FAILURE | The Slave PU struct is enabled and possibly locked.
2778 * CY_PROT_INVALID_STATE | The function was called on the device with an unsupported PERI HW version.
2779 *
2780 * \funcusage
2781 * \snippet prot/snippet/main.c snippet_Cy_Prot_DisablePpuFixedRgSlaveStruct
2782 *
2783 *******************************************************************************/
Cy_Prot_DisablePpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type * base)2784 cy_en_prot_status_t Cy_Prot_DisablePpuFixedRgSlaveStruct(PERI_GR_PPU_RG_Type* base)
2785 {
2786 cy_en_prot_status_t status = CY_PROT_INVALID_STATE;
2787
2788 if (CY_PERI_V1)
2789 {
2790 PERI_GR_PPU_RG_ATT0(base) &= ~_VAL2FLD(PERI_GR_PPU_RG_ATT0_ENABLED, CY_PROT_STRUCT_ENABLE);
2791 status = (_FLD2VAL(PERI_GR_PPU_RG_ATT0_ENABLED, PERI_GR_PPU_RG_ATT0(base)) == CY_PROT_STRUCT_ENABLE) ?
2792 CY_PROT_FAILURE : CY_PROT_SUCCESS;
2793 }
2794
2795 return status;
2796 }
2797
2798
2799 /*******************************************************************************
2800 * Function Name: Prot_IsSmpuStructDisabled
2801 ****************************************************************************//**
2802 *
2803 * This function returns the SMPU disabled status.
2804 *
2805 * \note This function is applicable for both CPUSS ver_1 and ver_2.
2806 *
2807 * \param smpuStcIndex
2808 * index of the SMPU structure.
2809 *
2810 * \return
2811 * true if both Slave and Master structures are disabled.
2812 * false if Master or/and Slave structure is/are enabled.
2813 *
2814 *******************************************************************************/
Prot_IsSmpuStructDisabled(uint32_t smpuStcIndex)2815 static bool Prot_IsSmpuStructDisabled(uint32_t smpuStcIndex)
2816 {
2817 return ((!_FLD2BOOL(PROT_SMPU_SMPU_STRUCT_ATT0_ENABLED, PROT_SMPU_SMPU_STRUCT_IDX_ATT0(smpuStcIndex))) &&
2818 (!_FLD2BOOL(PROT_SMPU_SMPU_STRUCT_ATT1_ENABLED, PROT_SMPU_SMPU_STRUCT_IDX_ATT1(smpuStcIndex))));
2819 }
2820
2821
2822 /*******************************************************************************
2823 * Function Name: Prot_IsPpoProgStructDisabled
2824 ****************************************************************************//**
2825 *
2826 * This function returns the Peripheral PPU disabled status.
2827 *
2828 * \note This function is applicable for both CPUSS ver_1 and ver_2.
2829 *
2830 * \param ppuStcIndex
2831 * index of the Prot_IsPpoProgStructDisabled structure.
2832 *
2833 * \return
2834 * true if both Slave and Master structures are disabled.
2835 * false if Master or/and Slave structure is/are enabled.
2836 *
2837 *******************************************************************************/
Prot_IsPpuProgStructDisabled(uint32_t ppuStcIndex)2838 static bool Prot_IsPpuProgStructDisabled(uint32_t ppuStcIndex)
2839 {
2840 return ((!_FLD2BOOL(PERI_PPU_PR_ATT0_ENABLED, PROT_PERI_PPU_PR_STRUCT_IDX_ATT0(ppuStcIndex))) &&
2841 (!_FLD2BOOL(PERI_PPU_PR_ATT1_ENABLED, PROT_PERI_PPU_PR_STRUCT_IDX_ATT1(ppuStcIndex))));
2842 }
2843
2844
2845 #if defined(__cplusplus)
2846 }
2847 #endif
2848
2849 #endif
2850 /* [] END OF FILE */
2851