SMPU Functions

group group_prot_functions_smpu

Functions

__STATIC_INLINE cy_en_prot_status_t Cy_Prot_DisableSmpuStruct (PROT_SMPU_SMPU_STRUCT_Type *base)

This function disables both the master and slave parts of a protection unit.

Status

Description

CY_PROT_SUCCESS

The Master and Slave SMPU struct was disabled

CY_PROT_FAILURE

The Master and/or slave SMPU struct was not disabled

CY_PROT_INVALID_STATE

Function was called on the unsupported PERI IP version

Return

Status of the function call.

Function Usage

    
    /* Scenario: The struct of PROT_SMPU_SMPU_STRUCT0 needs to be disabled.
                 Or it needs to be reconfigured and hence must first be disabled. 
                 Both Slave and Master structures will be disabled. */
    
    if(CY_PROT_SUCCESS != Cy_Prot_DisableSmpuStruct(PROT_SMPU_SMPU_STRUCT0))
    {
        /* Insert error handling */
    }

Parameters
  • base: The base address for the SMPU structure to be disabled.

cy_en_prot_status_t Cy_Prot_GetSmpuStruct(PROT_SMPU_SMPU_STRUCT_Type **base, cy_en_prot_req_mode_t reqMode, uint32_t smpuIndex)

Functions returns a pointer of the requested unused SMPU structure.

It searches the SMPU structures until it finds one that both the slave and master sections are disabled. After an available structure is located, function enables the slave structure and set the ATT0[7:0] bits to 0xFF, to make sure that a subsequent call will not see this as an available (unused) SMPU.

It is up to the user to implement, if needed, a system in which a semaphore will lock-out all but one CPU from calling this function at once.

note

This function is applicable for both CPUSS ver_1 and ver_2.

reqMode

Description

CY_PROT_REQMODE_HIGHPRIOR

Return the SMPU structure with the highest priority.

CY_PROT_REQMODE_LOWPRIOR

Return the SMPU structure with the lowest priority.

CY_PROT_REQMODE_INDEX

Return the SMPU structure with the specific index.

Status

Description

CY_PROT_SUCCESS

The Slave PU struct was disabled.

CY_PROT_FAILURE

The Master or Slave SMPU struct is disabled and possibly locked.

CY_PROT_UNAVAILABLE

The requested structure in use or there were no unused structures.

Return

Status of the function call.

Function Usage


    /* Scenario: Need to find available SMPU structure with highest priority 
    *  and configure it.
    */
    
    PROT_SMPU_SMPU_STRUCT_Type *reqStr;
    
    /* Find required SMPU structure */
    if (CY_PROT_SUCCESS != Cy_Prot_GetSmpuStruct(&reqStr, CY_PROT_REQMODE_HIGHPRIOR, 0U))
    {
       /* Insert error handling */
    }
    else
    {
        cy_stc_smpu_cfg_t smpuCfg_m = {
            /*.address =*/ 0UL,                         /* Not applicable for master struct */
            /*.regionSize =*/ (cy_en_prot_size_t)0UL,   /* Not applicable for master struct */
            /*.subregions =*/ 0UL,                      /* Not applicable for master struct */
            /*.userPermission =*/ CY_PROT_PERM_R,       /* Read access always available for Master */
            /*.privPermission =*/ CY_PROT_PERM_RW,      /* Allow read and write accesses */
            /*.secure =*/ true,                         /* Only allow "secure" bus masters */
            /*.pcMatch =*/ false,                       /* Perform access evaluation */
            /*.pcMask =*/ (uint16_t)0UL                 /* Only allow PC=0 bus masters */
        };
        
        /* Configure the master of the found struct */
        if(CY_PROT_SUCCESS != Cy_Prot_ConfigSmpuMasterStruct(reqStr, &smpuCfg_m))
        {
            /* Insert error handling */
        }
        else
        {
            /* Enable the master of the found struct */
            if(CY_PROT_SUCCESS != Cy_Prot_EnableSmpuMasterStruct(reqStr))
            {
                /* Insert error handling */
            }
        }
    }

Parameters
  • base: The base address for the SMPU structure returned if an unused structure was found. If an empty structure was not found, the returned pointer is NULL.

  • reqMode: This parameter (request mode) selects how the user wants to select a SMPU structure.

Parameters
  • smpuIndex: This is the index of the requested SMPU structure. It is only used if the request mode is reqMode = CY_PROT_REQMODE_INDEX.

cy_en_prot_status_t Cy_Prot_ConfigSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type *base, const cy_stc_smpu_cfg_t *config)

Configures a Shared Memory Protection Unit (SMPU) master protection struct with its protection attributes.

This function configures the master struct governing the corresponding slave struct pair. It is a mechanism to protect the slave SMPU struct. Since the memory location of the slave struct is known, the address, regionSize and subregions of the configuration struct are not applicable.

Note that only the user/privileged write permissions are configurable. The read and execute permissions are read-only and cannot be configured.

note

This function is applicable for both CPUSS ver_1 and ver_2.

Status

Description

CY_PROT_SUCCESS

SMPU master struct was successfully configured.

CY_PROT_FAILURE

The resource is locked.

CY_PROT_BAD_PARAM

An incorrect/invalid parameter was passed.

Return

Status of the function call.

Function Usage


    /* Scenario: A bus master must not be able to access the PROT_SMPU_SMPU_STRUCT0
                 master and slave structs unless operating with PC=0, "secure" and
                 "privileged" access settings. The PROT_SMPU_SMPU_STRUCT0 slave 
                 struct is already configured and enabled. */
    
    cy_stc_smpu_cfg_t smpuCfg_m = {
        /*.address =*/ 0UL,                         /* Not applicable for master struct */
        /*.regionSize =*/ (cy_en_prot_size_t)0UL,   /* Not applicable for master struct */
        /*.subregions =*/ 0UL,                      /* Not applicable for master struct */
        /*.userPermission =*/ CY_PROT_PERM_R,       /* Read access always available for Master */
        /*.privPermission =*/ CY_PROT_PERM_RW,      /* Allow read and write accesses */
        /*.secure =*/ true,                         /* Only allow "secure" bus masters */
        /*.pcMatch =*/ false,                       /* Perform access evaluation */
        /*.pcMask =*/ (uint16_t)0UL                 /* Only allow PC=0 bus masters */
    };
    
    /* Configure the master struct of SMPU #0 */
    if(CY_PROT_SUCCESS != Cy_Prot_ConfigSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT0, &smpuCfg_m))
    {
        /* Insert error handling */
    }
    else
    {
        /* Enable the master struct of SMPU #0 */
        if(CY_PROT_SUCCESS != Cy_Prot_EnableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT0))
        {
            /* Insert error handling */
        }
    }

Parameters
  • base: The register base address of the protection struct being configured.

  • config: Initialization structure with all the protection attributes.

cy_en_prot_status_t Cy_Prot_ConfigSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type *base, const cy_stc_smpu_cfg_t *config)

Configures a Shared Memory Protection Unit (SMPU) slave protection struct with its protection attributes.

This function configures the slave struct of an SMPU pair, which can protect any memory region in a device from invalid bus master accesses.

note

This function is applicable for both CPUSS ver_1 and ver_2.

Status

Description

CY_PROT_SUCCESS

SMPU slave struct was successfully configured.

CY_PROT_FAILURE

The resource is locked.

CY_PROT_BAD_PARAM

An incorrect/invalid parameter was passed.

Return

Status of the function call.

Function Usage


    /* Scenario: A bus master must not be able to access the memory region 
                 0x10000200 ~ 0x10000FFF unless it is operating at PC=0 or PC=2 */
    
    cy_stc_smpu_cfg_t smpuCfg_s = {
        /*.address =*/ (uint32_t *)0x10000000UL,    /* Starting address at start of Flash */
        /*.regionSize =*/ CY_PROT_SIZE_4KB,         /* Protect block of 4 KBytes */
        /*.subregions =*/ CY_PROT_SUBREGION_DIS0,   /* Disable protection for first 512 (4096/8) Bytes */
        /*.userPermission =*/ CY_PROT_PERM_RWX,     /* Allow all user mode accesses */
        /*.privPermission =*/ CY_PROT_PERM_RWX,     /* Allow all privileged mode accesses */
        /*.secure =*/ false,                        /* Allow "non-secure" bus masters */
        /*.pcMatch =*/ false,                       /* Perform access evaluation */
        /*.pcMask =*/ (uint16_t)CY_PROT_PCMASK2     /* Allow PC=0 and PC=2 accesses */
    };
    
    /* Configure the slave struct of SMPU #0 */
    if(CY_PROT_SUCCESS != Cy_Prot_ConfigSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT0, &smpuCfg_s))
    {
        /* Insert error handling */
    }
    else
    {
        /* Enable the slave struct of SMPU #0 */
        if(CY_PROT_SUCCESS != Cy_Prot_EnableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT0))
        {
            /* Insert error handling */
        }
    }

Parameters
  • base: The register base address of the protection structure being configured.

  • config: Initialization structure with all the protection attributes.

cy_en_prot_status_t Cy_Prot_EnableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type *base)

Enables the Master SMPU structure.

This is an SMPU master struct enable function. The SMPU protection settings will take effect after successful completion of this function call.

note

This function is applicable for both CPUSS ver_1 and ver_2.

Status

Description

CY_PROT_SUCCESS

The Master PU struct was enabled.

CY_PROT_FAILURE

The Master PU struct is disabled and possibly locked.

Return

Status of the function call.

Function Usage


    /* Scenario: The master struct of PROT_SMPU_SMPU_STRUCT0 is configured to 
                 protect its slave struct and needs to be enabled. */
    
    if(CY_PROT_SUCCESS != Cy_Prot_EnableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT0))
    {
        /* Insert error handling */
    }

Parameters
  • base: The base address for the protection unit structure being configured.

cy_en_prot_status_t Cy_Prot_DisableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT_Type *base)

Disables the Master SMPU structure.

This is an SMPU master struct disable function. The SMPU protection settings will seize to take effect after successful completion of this function call.

note

This function is applicable for both CPUSS ver_1 and ver_2.

Status

Description

CY_PROT_SUCCESS

The Master PU struct was disabled.

CY_PROT_FAILURE

The Master PU struct is enabled and possibly locked.

Return

Status of the function call.

Function Usage

    
    /* Scenario: The master sturct of PROT_SMPU_SMPU_STRUCT0 needs to be disabled.
                 Or it needs to be reconfigured and hence must first be disabled. */
    
    if(CY_PROT_SUCCESS != Cy_Prot_EnableSmpuMasterStruct(PROT_SMPU_SMPU_STRUCT0))
    {
        /* Insert error handling */
    }

Parameters
  • base: The base address for the protection unit structure being configured.

cy_en_prot_status_t Cy_Prot_EnableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type *base)

Enables the Slave SMPU structure.

This is an SMPU slave struct enable function. The SMPU protection settings will take effect after successful completion of this function call.

note

This function is applicable for both CPUSS ver_1 and ver_2.

Status

Description

CY_PROT_SUCCESS

The Slave PU struct was enabled.

CY_PROT_FAILURE

The Slave PU struct is disabled and possibly locked.

Return

Status of the function call.

Function Usage


    /* Scenario: The slave struct of PROT_SMPU_SMPU_STRUCT0 is configured to 
                 protect a resource and needs to be enabled. */
    
    if(CY_PROT_SUCCESS != Cy_Prot_EnableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT0))
    {
        /* Insert error handling */
    }

Parameters
  • base: The base address for the protection unit structure being configured.

cy_en_prot_status_t Cy_Prot_DisableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT_Type *base)

Disables the Slave SMPU structure.

This is an SMPU slave struct disable function. The SMPU protection settings will seize to take effect after successful completion of this function call.

note

This function is applicable for both CPUSS ver_1 and ver_2.

Status

Description

CY_PROT_SUCCESS

The Slave PU struct was disabled.

CY_PROT_FAILURE

The Slave PU struct is enabled and possibly locked.

Return

Status of the function call.

Function Usage

    
    /* Scenario: The slave struct of PROT_SMPU_SMPU_STRUCT0 needs to be disabled.
                 Or it needs to be reconfigured and hence must first be disabled. */
    
    if(CY_PROT_SUCCESS != Cy_Prot_DisableSmpuSlaveStruct(PROT_SMPU_SMPU_STRUCT0))
    {
        /* Insert error handling */
    }

Parameters
  • base: The base address for the protection unit structure being configured.