Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
MEMORY - MPU - Memory Protection Unit

MPU driver that allows the user to divide the memory space into different protection regions.

Data Structures

struct  mpu_entry_t
 

Macros

#define CAST(to, from)
 

Enumerations

enum  eRegionSize {
  MPU_REGION_SIZE_LOWLIMIT_FORBIDDEN = 10,
  MPU_REGION_SIZE_4KB,
  MPU_REGION_SIZE_8KB,
  MPU_REGION_SIZE_16KB,
  MPU_REGION_SIZE_32KB,
  MPU_REGION_SIZE_64KB,
  MPU_REGION_SIZE_128KB,
  MPU_REGION_SIZE_256KB,
  MPU_REGION_SIZE_512KB,
  MPU_REGION_SIZE_1MB,
  MPU_REGION_SIZE_2MB,
  MPU_REGION_SIZE_4MB,
  MPU_REGION_SIZE_8MB,
  MPU_REGION_SIZE_16MB,
  MPU_REGION_SIZE_32MB,
  MPU_REGION_SIZE_64MB,
  MPU_REGION_SIZE_128MB,
  MPU_REGION_SIZE_256MB,
  MPU_REGION_SIZE_512MB,
  MPU_REGION_SIZE_1GB,
  MPU_REGION_SIZE_2GB,
  MPU_REGION_SIZE_4GB,
  MPU_REGION_SIZE_HIGHLIMIT_FORBIDDEN
}
 

Functions

void disable_mpu (void)
 Disable the memory protection unit. MPU address checking is disabled, no exceptions will be generated by the MPU. More...
 
void disable_mpu_entry (unsigned int region_number, unsigned int register_select)
 
void enable_mpu (void)
 Enable the memory protection unit. MPU address checking is enabled. More...
 
bool mpu_convert_kbsize_to_eregionsize (eRegionSize *peRegionSizeValue, U32 kBSizeValue)
 Converts an input region size expressed in kBytes to the corresponding eRegionSize type value. More...
 
void select_subregion (unsigned int region_number, unsigned int pattern_select)
 
void set_access_permissions (unsigned int region_number, unsigned int register_select, unsigned int right_access)
 
char set_mpu_entry (const mpu_entry_t *mpu_entry, unsigned int region_number)
 
#define MPU_APRA_ID   0
 MPU Access Permission Register A & B identifiers. More...
 
#define MPU_APRB_ID   1
 
#define MPU_PRIVR_UNPRIVNONE   AVR32_MPUAPRA_AP0_PRIV_R_UNPRIV_NONE
 MPU Access Permissions. More...
 
#define MPU_PRIVRX_UNPRIVNONE   AVR32_MPUAPRA_AP0_PRIV_RX_UNPRIV_NONE
 
#define MPU_PRIVRW_UNPRIVNONE   AVR32_MPUAPRA_AP0_PRIV_RW_UNPRIV_NONE
 
#define MPU_PRIVRWX_UNPRIVNONE   AVR32_MPUAPRA_AP0_PRIV_RWX_UNPRIV_NONE
 
#define MPU_PRIVR_UNPRIVR   AVR32_MPUAPRA_AP0_PRIV_R_UNPRIV_R
 
#define MPU_PRIVRX_UNPRIVRX   AVR32_MPUAPRA_AP0_PRIV_RX_UNPRIV_RX
 
#define MPU_PRIVRW_UNPRIVRW   AVR32_MPUAPRA_AP0_PRIV_RW_UNPRIV_RW
 
#define MPU_PRIVRWX_UNPRIVRWX   AVR32_MPUAPRA_AP0_PRIV_RWX_UNPRIV_RWX
 
#define MPU_PRIVRW_UNPRIVR   AVR32_MPUAPRA_AP0_PRIV_RW_UNPRIV_R
 
#define MPU_PRIVRW_UNPRIVRX   AVR32_MPUAPRA_AP0_PRIV_RW_UNPRIV_RX
 
#define MPU_PRIVNONE_UNPRIVNONE   AVR32_MPUAPRA_AP0_PRIV_NONE_UNPRIV_NONE
 
#define MPU_SETUP_ENTRY_OK   0
 MPU entry set up function (set_mpu_entry) return codes. More...
 
#define MPU_SETUP_ENTRY_INVALIDBASEADDR   1
 
#define MPU_SETUP_ENTRY_INVALIDSIZE   2
 

#define CAST (   to,
  from 
)
Value:
({ \
typeof(from) __temp__ = from; \
to = *(typeof(to) *)&__temp__; \
})
#define MPU_APRA_ID   0

MPU Access Permission Register A & B identifiers.

Referenced by configure_memory_area().

#define MPU_APRB_ID   1

Referenced by configure_memory_area().

#define MPU_PRIVNONE_UNPRIVNONE   AVR32_MPUAPRA_AP0_PRIV_NONE_UNPRIV_NONE
#define MPU_PRIVR_UNPRIVNONE   AVR32_MPUAPRA_AP0_PRIV_R_UNPRIV_NONE

MPU Access Permissions.

Referenced by configure_memory_area().

#define MPU_PRIVR_UNPRIVR   AVR32_MPUAPRA_AP0_PRIV_R_UNPRIV_R
#define MPU_PRIVRW_UNPRIVNONE   AVR32_MPUAPRA_AP0_PRIV_RW_UNPRIV_NONE

Referenced by configure_memory_area().

#define MPU_PRIVRW_UNPRIVR   AVR32_MPUAPRA_AP0_PRIV_RW_UNPRIV_R
#define MPU_PRIVRW_UNPRIVRW   AVR32_MPUAPRA_AP0_PRIV_RW_UNPRIV_RW
#define MPU_PRIVRW_UNPRIVRX   AVR32_MPUAPRA_AP0_PRIV_RW_UNPRIV_RX
#define MPU_PRIVRWX_UNPRIVNONE   AVR32_MPUAPRA_AP0_PRIV_RWX_UNPRIV_NONE
#define MPU_PRIVRWX_UNPRIVRWX   AVR32_MPUAPRA_AP0_PRIV_RWX_UNPRIV_RWX
#define MPU_PRIVRX_UNPRIVNONE   AVR32_MPUAPRA_AP0_PRIV_RX_UNPRIV_NONE
#define MPU_PRIVRX_UNPRIVRX   AVR32_MPUAPRA_AP0_PRIV_RX_UNPRIV_RX

Referenced by configure_memory_area().

#define MPU_SETUP_ENTRY_INVALIDBASEADDR   1

Referenced by set_mpu_entry().

#define MPU_SETUP_ENTRY_INVALIDSIZE   2

Referenced by set_mpu_entry().

#define MPU_SETUP_ENTRY_OK   0

MPU entry set up function (set_mpu_entry) return codes.

Referenced by set_mpu_entry().

Possible protected region sizes. Based on Table 5.1 in doc32002 "AVR32UC Technical Reference Manual Complete".

Enumerator
MPU_REGION_SIZE_LOWLIMIT_FORBIDDEN 
MPU_REGION_SIZE_4KB 
MPU_REGION_SIZE_8KB 
MPU_REGION_SIZE_16KB 
MPU_REGION_SIZE_32KB 
MPU_REGION_SIZE_64KB 
MPU_REGION_SIZE_128KB 
MPU_REGION_SIZE_256KB 
MPU_REGION_SIZE_512KB 
MPU_REGION_SIZE_1MB 
MPU_REGION_SIZE_2MB 
MPU_REGION_SIZE_4MB 
MPU_REGION_SIZE_8MB 
MPU_REGION_SIZE_16MB 
MPU_REGION_SIZE_32MB 
MPU_REGION_SIZE_64MB 
MPU_REGION_SIZE_128MB 
MPU_REGION_SIZE_256MB 
MPU_REGION_SIZE_512MB 
MPU_REGION_SIZE_1GB 
MPU_REGION_SIZE_2GB 
MPU_REGION_SIZE_4GB 
MPU_REGION_SIZE_HIGHLIMIT_FORBIDDEN 

void disable_mpu ( void  )

Disable the memory protection unit. MPU address checking is disabled, no exceptions will be generated by the MPU.

Control of the MPU control register MPUCR: disable MPUCR

References Set_system_register.

Referenced by handle_exception().

void disable_mpu_entry ( unsigned int  region_number,
unsigned int  register_select 
)

Disable a MPU entry

Parameters
region_number,:MPU entry region number (0..7).
register_select,:register A: '0' – B: '1'

References Set_system_register.

void enable_mpu ( void  )

Enable the memory protection unit. MPU address checking is enabled.

Control of the MPU control register MPUCR: enable MPUCR

References Set_system_register.

Referenced by configure_memory_area().

bool mpu_convert_kbsize_to_eregionsize ( eRegionSize peRegionSizeValue,
U32  kBSizeValue 
)

Converts an input region size expressed in kBytes to the corresponding eRegionSize type value.

Parameters
kBSizeValue,:input region size expressed in kBytes
peRegionSizeValue,:output region size in the eRegionSize type
Returns
bool true if the conversion succeeded false if the conversion failed (the input is not a possible protected region size).

References clz, MPU_REGION_SIZE_HIGHLIMIT_FORBIDDEN, and MPU_REGION_SIZE_LOWLIMIT_FORBIDDEN.

Referenced by configure_memory_area().

void select_subregion ( unsigned int  region_number,
unsigned int  pattern_select 
)

Setup a Subregion

Parameters
region_number,:MPU entry region number (0..7).
pattern_select,:bit-field for the 16 subregions: register A: '0' – B: '1'

References Set_system_register.

Referenced by configure_memory_area().

void set_access_permissions ( unsigned int  region_number,
unsigned int  register_select,
unsigned int  right_access 
)

Setup a register A and B

Parameters
region_number,:MPU entry region number (0..7).
register_select,:register A: '0' – B: '1'
right_access,:R/W/X see doc32002.pdf (Table 5-3. Access permissions implied by the APn bits)

References Get_system_register, and Set_system_register.

Referenced by configure_memory_area().

char set_mpu_entry ( const mpu_entry_t mpu_entry,
unsigned int  region_number 
)

Setup a MPU entry

Parameters
mpu_entry,:pointer to mpu_entry_t with the MPU settings (base address, size, validity, access permission) .
region_number,:MPU entry region number (0..7).
Returns
int MPU_SETUP_ENTRY_OK if the setup succeeded MPU_SETUP_ENTRY_INVALIDBASEADDR if the setup failed because the input base address is not aligned to the size of the region. MPU_SETUP_ENTRY_INVALIDSIZE if the setup failed because the input size is not a power of 2 or is less than 4kB or is bigger than 4GB.

Setup a MPU entry

Parameters
mpu_entry,:pointer to mpu_entry_t with the MPU settings (base address, size, validity).
region_number,:MPU entry region number (0..7).
Returns
int MPU_SETUP_ENTRY_OK if the setup succeeded MPU_SETUP_ENTRY_INVALIDBASEADDR if the setup failed because the input base address is not aligned to the size of the region. MPU_SETUP_ENTRY_INVALIDSIZE if the setup failed because the input size is not one of the type eRegionSize.

References mpu_entry_t::addr, MPU_REGION_SIZE_HIGHLIMIT_FORBIDDEN, MPU_REGION_SIZE_LOWLIMIT_FORBIDDEN, MPU_SETUP_ENTRY_INVALIDBASEADDR, MPU_SETUP_ENTRY_INVALIDSIZE, MPU_SETUP_ENTRY_OK, Set_system_register, mpu_entry_t::size, Test_align, and mpu_entry_t::valid.

Referenced by configure_memory_area().