]> begriffs open source - cmsis/blob - CMSIS/CoreValidation/Source/CV_MPU_ARMv8.c
CoreValidation: Test projects for Cortex-M4.
[cmsis] / CMSIS / CoreValidation / Source / CV_MPU_ARMv8.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() {
16   for(uint32_t i = 0U; i < 8U; ++i) {
17     MPU->RNR = i;
18     MPU->RBAR = 0U;
19     MPU->RLAR = 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, .RLAR = 0U },
37     { .RBAR = ARM_MPU_RBAR(0x30000000U, 0U, 1U, 1U, 1U), .RLAR = ARM_MPU_RLAR(0x38000000U, 0U) }
38   };
39   
40   #define ASSERT_MPU_REGION(rnr, region) \
41     MPU->RNR = rnr; \
42     ASSERT_TRUE(MPU->RBAR == region.RBAR); \
43     ASSERT_TRUE(MPU->RLAR == region.RLAR)
44   
45   ClearMpu();
46     
47   ARM_MPU_SetRegion(2U, table[1].RBAR, table[1].RLAR);
48   
49   ASSERT_MPU_REGION(1U, table[0]);
50   ASSERT_MPU_REGION(2U, table[1]);
51   ASSERT_MPU_REGION(3U, table[0]);
52   
53   ARM_MPU_ClrRegion(2U);
54   
55   MPU->RNR = 2U;
56   ASSERT_TRUE((MPU->RLAR & MPU_RLAR_EN_Msk) == 0U);
57   
58   #undef ASSERT_MPU_REGION
59 }
60   
61 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
62 /**
63 \brief Test case: TC_MPU_Load
64 \details
65 - Check if ARM_MPU_Load correctly loads MPU table to registers.
66 */
67 void TC_MPU_Load(void)
68 {
69   static const ARM_MPU_Region_t table[] = {
70     { .RBAR = ARM_MPU_RBAR(0x10000000U, 0U, 1U, 1U, 1U), .RLAR = ARM_MPU_RLAR(0x18000000U, 0U) },
71     { .RBAR = ARM_MPU_RBAR(0x20000000U, 0U, 1U, 1U, 1U), .RLAR = ARM_MPU_RLAR(0x27000000U, 0U) },
72     { .RBAR = ARM_MPU_RBAR(0x30000000U, 0U, 1U, 1U, 1U), .RLAR = ARM_MPU_RLAR(0x36000000U, 0U) },
73     { .RBAR = ARM_MPU_RBAR(0x40000000U, 0U, 1U, 1U, 1U), .RLAR = ARM_MPU_RLAR(0x45000000U, 0U) },
74     { .RBAR = ARM_MPU_RBAR(0x50000000U, 0U, 1U, 1U, 1U), .RLAR = ARM_MPU_RLAR(0x54000000U, 0U) },
75     { .RBAR = ARM_MPU_RBAR(0x60000000U, 0U, 1U, 1U, 1U), .RLAR = ARM_MPU_RLAR(0x63000000U, 0U) },
76     { .RBAR = ARM_MPU_RBAR(0x70000000U, 0U, 1U, 1U, 1U), .RLAR = ARM_MPU_RLAR(0x72000000U, 0U) },
77     { .RBAR = ARM_MPU_RBAR(0x80000000U, 0U, 1U, 1U, 1U), .RLAR = ARM_MPU_RLAR(0x31000000U, 0U) }
78   };
79   
80   #define ASSERT_MPU_REGION(rnr, table) \
81     MPU->RNR = rnr; \
82     ASSERT_TRUE(MPU->RBAR == table[rnr].RBAR); \
83     ASSERT_TRUE(MPU->RLAR == table[rnr].RLAR)
84
85   ClearMpu();
86   
87   ARM_MPU_Load(0U, &(table[0]), 1U);
88   
89   ASSERT_MPU_REGION(0U, table);
90   
91   ARM_MPU_Load(1U, &(table[1]), 5U);
92
93   ASSERT_MPU_REGION(0U, table);
94   ASSERT_MPU_REGION(1U, table);
95   ASSERT_MPU_REGION(2U, table);
96   ASSERT_MPU_REGION(3U, table);
97   ASSERT_MPU_REGION(4U, table);
98   ASSERT_MPU_REGION(5U, table);
99
100   ARM_MPU_Load(6U, &(table[6]), 2U);
101
102   ASSERT_MPU_REGION(5U, table);
103   ASSERT_MPU_REGION(6U, table);
104   ASSERT_MPU_REGION(7U, table);
105
106   #undef ASSERT_MPU_REGION
107 }