]> begriffs open source - cmsis/blob - CMSIS/CoreValidation/Source/CV_MPU_ARMv7.c
CoreValidation: Initial contribution of a test suite for validating CMSIS-Core.
[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 #if defined(__MPU_PRESENT) && (__MPU_PRESENT != 0)
12
13 /*-----------------------------------------------------------------------------
14  *      Test implementation
15  *----------------------------------------------------------------------------*/
16
17 static void ClearMpu(void) {
18   for(uint32_t i = 0U; i < 8U; ++i) {
19     MPU->RNR = i;
20     MPU->RBAR = 0U;
21     MPU->RASR = 0U;
22   }
23 }
24
25 /*-----------------------------------------------------------------------------
26  *      Test cases
27  *----------------------------------------------------------------------------*/
28
29 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
30 /**
31 \brief Test case: TC_MPU_SetClear
32 \details
33 - Check if ARM_MPU_Load correctly loads MPU table to registers.
34 */
35 void TC_MPU_SetClear(void)
36 {
37   static const ARM_MPU_Region_t table[] = {
38     { .RBAR = 0U, .RASR = 0U },
39     { .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) },
40     { .RBAR = 0x50000000U, .RASR = ARM_MPU_RASR(0U, ARM_MPU_AP_FULL, 0U, 0U, 0U, 0U, 0U, ARM_MPU_REGION_SIZE_64MB) }
41   };
42   
43   #define ASSERT_MPU_REGION(rnr, region) \
44     MPU->RNR = rnr; \
45     ASSERT_TRUE((MPU->RBAR & MPU_RBAR_ADDR_Msk) == (region.RBAR & MPU_RBAR_ADDR_Msk)); \
46     ASSERT_TRUE(MPU->RASR == region.RASR)
47   
48   ClearMpu();
49     
50   ARM_MPU_SetRegion(table[1].RBAR, table[1].RASR);
51   
52   ASSERT_MPU_REGION(1U, table[0]);
53   ASSERT_MPU_REGION(2U, table[1]);
54   ASSERT_MPU_REGION(3U, table[0]);
55   
56   ARM_MPU_SetRegionEx(5U, table[2].RBAR, table[2].RASR);
57   
58   ASSERT_MPU_REGION(4U, table[0]);
59   ASSERT_MPU_REGION(5U, table[2]);
60   ASSERT_MPU_REGION(6U, table[0]);
61   
62   ARM_MPU_ClrRegion(5U);
63   
64   MPU->RNR = 5U;
65   ASSERT_TRUE((MPU->RASR & MPU_RASR_ENABLE_Msk) == 0U);
66   
67   #undef ASSERT_MPU_REGION
68 }
69   
70 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
71 /**
72 \brief Test case: TC_MPU_Load
73 \details
74 - Check if ARM_MPU_Load correctly loads MPU table to registers.
75 */
76 void TC_MPU_Load(void)
77 {
78   static const ARM_MPU_Region_t table[] = {
79     { .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)  },
80     { .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)  },
81     { .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) },
82     { .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) },
83     { .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) },
84     { .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)  },
85     { .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)   },
86     { .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)   }
87   };
88   
89   #define ASSERT_MPU_REGION(rnr, table) \
90     MPU->RNR = rnr; \
91     ASSERT_TRUE((MPU->RBAR & MPU_RBAR_ADDR_Msk) == (table[rnr].RBAR & MPU_RBAR_ADDR_Msk)); \
92     ASSERT_TRUE(MPU->RASR == table[rnr].RASR)
93
94   ClearMpu();
95   
96   ARM_MPU_Load(&(table[0]), 1U);
97   
98   ASSERT_MPU_REGION(0U, table);
99   
100   ARM_MPU_Load(&(table[1]), 5U);
101
102   ASSERT_MPU_REGION(0U, table);
103   ASSERT_MPU_REGION(1U, table);
104   ASSERT_MPU_REGION(2U, table);
105   ASSERT_MPU_REGION(3U, table);
106   ASSERT_MPU_REGION(4U, table);
107   ASSERT_MPU_REGION(5U, table);
108
109   ARM_MPU_Load(&(table[6]), 2U);
110
111   ASSERT_MPU_REGION(5U, table);
112   ASSERT_MPU_REGION(6U, table);
113   ASSERT_MPU_REGION(7U, table);
114
115   #undef ASSERT_MPU_REGION
116 }
117
118 #endif