Reduce dynamic MPU code size with a loop

pull/9208/head
Kevin Bracey 2018-12-11 18:21:04 +02:00 committed by Cruz Monrreal II
parent 4f9b258a03
commit 60451368a8
2 changed files with 20 additions and 20 deletions

View File

@ -195,13 +195,18 @@ void mbed_mpu_free()
__ISB();
}
static void enable_region(bool enable, uint32_t region)
{
MPU->RNR = region;
MPU->RASR = (MPU->RASR & ~MPU_RASR_ENABLE_Msk) | (enable << MPU_RASR_ENABLE_Pos);
}
void mbed_mpu_enable_rom_wn(bool enable)
{
// Flush memory writes before configuring the MPU.
__DMB();
MPU->RNR = 0;
MPU->RASR = (MPU->RASR & ~MPU_RASR_ENABLE_Msk) | (enable ? MPU_RASR_ENABLE_Msk : 0);
enable_region(enable, 0);
// Ensure changes take effect
__DSB();
@ -213,14 +218,9 @@ void mbed_mpu_enable_ram_xn(bool enable)
// Flush memory writes before configuring the MPU.
__DMB();
MPU->RNR = 1;
MPU->RASR = (MPU->RASR & ~MPU_RASR_ENABLE_Msk) | (enable ? MPU_RASR_ENABLE_Msk : 0);
MPU->RNR = 2;
MPU->RASR = (MPU->RASR & ~MPU_RASR_ENABLE_Msk) | (enable ? MPU_RASR_ENABLE_Msk : 0);
MPU->RNR = 3;
MPU->RASR = (MPU->RASR & ~MPU_RASR_ENABLE_Msk) | (enable ? MPU_RASR_ENABLE_Msk : 0);
for (uint32_t region = 1; region <= 3; region++) {
enable_region(enable, region);
}
// Ensure changes take effect
__DSB();

View File

@ -144,13 +144,18 @@ void mbed_mpu_free()
__ISB();
}
static void enable_region(bool enable, uint32_t region)
{
MPU->RNR = region;
MPU->RLAR = (MPU->RLAR & ~MPU_RLAR_EN_Msk) | (enable << MPU_RLAR_EN_Pos);
}
void mbed_mpu_enable_rom_wn(bool enable)
{
// Flush memory writes before configuring the MPU.
__DMB();
MPU->RNR = 0;
MPU->RLAR = (MPU->RLAR & ~MPU_RLAR_EN_Msk) | (enable ? MPU_RLAR_EN_Msk : 0);
enable_region(enable, 0);
// Ensure changes take effect
__DSB();
@ -162,14 +167,9 @@ void mbed_mpu_enable_ram_xn(bool enable)
// Flush memory writes before configuring the MPU.
__DMB();
MPU->RNR = 1;
MPU->RLAR = (MPU->RLAR & ~MPU_RLAR_EN_Msk) | (enable ? MPU_RLAR_EN_Msk : 0);
MPU->RNR = 2;
MPU->RLAR = (MPU->RLAR & ~MPU_RLAR_EN_Msk) | (enable ? MPU_RLAR_EN_Msk : 0);
MPU->RNR = 3;
MPU->RLAR = (MPU->RLAR & ~MPU_RLAR_EN_Msk) | (enable ? MPU_RLAR_EN_Msk : 0);
for (uint32_t region = 1; region <= 3; region++) {
enable_region(enable, region);
}
// Ensure changes take effect
__DSB();