]> begriffs open source - cmsis/blob - CMSIS/CoreValidation/Source/CV_MPU_ARMv7.c
CoreValidation: Fixed test projects for Cortex-M0+
[cmsis] / CMSIS / CoreValidation / Source / CV_MPU_ARMv7.c
1 /*-----------------------------------------------------------------------------
2  *      Name:         CV_MPU_ARMv7.c 
3  *      Purpose:      CMSIS CORE validation tests implementation
4  *-----------------------------------------------------------------------------
5  *      Copyright (c) 2017 ARM Limited. All rights reserved.
6  *----------------------------------------------------------------------------*/
7
8 #include "CV_Framework.h"
9 #include "cmsis_cv.h"
10
11 /*-----------------------------------------------------------------------------
12  *      Test implementation
13  *----------------------------------------------------------------------------*/
14
15 static void ClearMpu(void) {
16   for(uint32_t i = 0U; i < 8U; ++i) {
17     MPU->RNR = i;
18     MPU->RBAR = 0U;
19     MPU->RASR = 0U;
20   }
21 }
22
23 /*-----------------------------------------------------------------------------
24  *      Test cases
25  *----------------------------------------------------------------------------*/
26
27 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
28 /**
29 \brief Test case: TC_MPU_SetClear
30 \details
31 - Check if ARM_MPU_Load correctly loads MPU table to registers.
32 */
33 void TC_MPU_SetClear(void)
34 {
35   static const ARM_MPU_Region_t table[] = {
36     { .RBAR = 0U, .RASR = 0U },
37     { .RBAR = ARM_MPU_RBAR(2U, 0x30000000U), .RASR = ARM_MPU_RASR(1U, ARM_MPU_AP_FULL, 0U, 0U, 0U, 0U, 0U, ARM_MPU_REGION_SIZE_128MB) },
38     { .RBAR = 0x50000000U, .RASR = ARM_MPU_RASR(0U, ARM_MPU_AP_FULL, 0U, 0U, 0U, 0U, 0U, ARM_MPU_REGION_SIZE_64MB) }
39   };
40   
41   #define ASSERT_MPU_REGION(rnr, region) \
42     MPU->RNR = rnr; \
43     ASSERT_TRUE((MPU->RBAR & MPU_RBAR_ADDR_Msk) == (region.RBAR & MPU_RBAR_ADDR_Msk)); \
44     ASSERT_TRUE(MPU->RASR == region.RASR)
45   
46   ClearMpu();
47     
48   ARM_MPU_SetRegion(table[1].RBAR, table[1].RASR);
49   
50   ASSERT_MPU_REGION(1U, table[0]);
51   ASSERT_MPU_REGION(2U, table[1]);
52   ASSERT_MPU_REGION(3U, table[0]);
53   
54   ARM_MPU_SetRegionEx(5U, table[2].RBAR, table[2].RASR);
55   
56   ASSERT_MPU_REGION(4U, table[0]);
57   ASSERT_MPU_REGION(5U, table[2]);
58   ASSERT_MPU_REGION(6U, table[0]);
59   
60   ARM_MPU_ClrRegion(5U);
61   
62   MPU->RNR = 5U;
63   ASSERT_TRUE((MPU->RASR & MPU_RASR_ENABLE_Msk) == 0U);
64   
65   #undef ASSERT_MPU_REGION
66 }
67   
68 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
69 /**
70 \brief Test case: TC_MPU_Load
71 \details
72 - Check if ARM_MPU_Load correctly loads MPU table to registers.
73 */
74 void TC_MPU_Load(void)
75 {
76   static const ARM_MPU_Region_t table[] = {
77     { .RBAR = ARM_MPU_RBAR(0U, 0x10000000U), .RASR = ARM_MPU_RASR(1U, ARM_MPU_AP_FULL, 0U, 0U, 0U, 0U, 0U, ARM_MPU_REGION_SIZE_32MB)  },
78     { .RBAR = ARM_MPU_RBAR(1U, 0x20000000U), .RASR = ARM_MPU_RASR(1U, ARM_MPU_AP_FULL, 0U, 0U, 0U, 0U, 0U, ARM_MPU_REGION_SIZE_64MB)  },
79     { .RBAR = ARM_MPU_RBAR(2U, 0x30000000U), .RASR = ARM_MPU_RASR(1U, ARM_MPU_AP_FULL, 0U, 0U, 0U, 0U, 0U, ARM_MPU_REGION_SIZE_128MB) },
80     { .RBAR = ARM_MPU_RBAR(3U, 0x40000000U), .RASR = ARM_MPU_RASR(1U, ARM_MPU_AP_FULL, 0U, 0U, 0U, 0U, 0U, ARM_MPU_REGION_SIZE_256MB) },
81     { .RBAR = ARM_MPU_RBAR(4U, 0x50000000U), .RASR = ARM_MPU_RASR(1U, ARM_MPU_AP_FULL, 0U, 0U, 0U, 0U, 0U, ARM_MPU_REGION_SIZE_512MB) },
82     { .RBAR = ARM_MPU_RBAR(5U, 0x60000000U), .RASR = ARM_MPU_RASR(1U, ARM_MPU_AP_FULL, 0U, 0U, 0U, 0U, 0U, ARM_MPU_REGION_SIZE_16MB)  },
83     { .RBAR = ARM_MPU_RBAR(6U, 0x70000000U), .RASR = ARM_MPU_RASR(1U, ARM_MPU_AP_FULL, 0U, 0U, 0U, 0U, 0U, ARM_MPU_REGION_SIZE_8MB)   },
84     { .RBAR = ARM_MPU_RBAR(7U, 0x80000000U), .RASR = ARM_MPU_RASR(1U, ARM_MPU_AP_FULL, 0U, 0U, 0U, 0U, 0U, ARM_MPU_REGION_SIZE_4MB)   }
85   };
86   
87   #define ASSERT_MPU_REGION(rnr, table) \
88     MPU->RNR = rnr; \
89     ASSERT_TRUE((MPU->RBAR & MPU_RBAR_ADDR_Msk) == (table[rnr].RBAR & MPU_RBAR_ADDR_Msk)); \
90     ASSERT_TRUE(MPU->RASR == table[rnr].RASR)
91
92   ClearMpu();
93   
94   ARM_MPU_Load(&(table[0]), 1U);
95   
96   ASSERT_MPU_REGION(0U, table);
97   
98   ARM_MPU_Load(&(table[1]), 5U);
99
100   ASSERT_MPU_REGION(0U, table);
101   ASSERT_MPU_REGION(1U, table);
102   ASSERT_MPU_REGION(2U, table);
103   ASSERT_MPU_REGION(3U, table);
104   ASSERT_MPU_REGION(4U, table);
105   ASSERT_MPU_REGION(5U, table);
106
107   ARM_MPU_Load(&(table[6]), 2U);
108
109   ASSERT_MPU_REGION(5U, table);
110   ASSERT_MPU_REGION(6U, table);
111   ASSERT_MPU_REGION(7U, table);
112
113   #undef ASSERT_MPU_REGION
114 }
115