LCOV - code coverage report
Current view: top level - arch/arm/core/aarch32/cortex_m - scb.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 15 0.0 %
Date: 2022-08-18 11:36:24 Functions: 0 3 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 6 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2013-2014 Wind River Systems, Inc.
       3                 :            :  *
       4                 :            :  * SPDX-License-Identifier: Apache-2.0
       5                 :            :  */
       6                 :            : 
       7                 :            : /**
       8                 :            :  * @file
       9                 :            :  * @brief ARM Cortex-M System Control Block interface
      10                 :            :  *
      11                 :            :  *
      12                 :            :  * Most of the SCB interface consists of simple bit-flipping methods, and is
      13                 :            :  * implemented as inline functions in scb.h. This module thus contains only data
      14                 :            :  * definitions and more complex routines, if needed.
      15                 :            :  */
      16                 :            : 
      17                 :            : #include <kernel.h>
      18                 :            : #include <arch/cpu.h>
      19                 :            : #include <sys/util.h>
      20                 :            : #include <arch/arm/aarch32/cortex_m/cmsis.h>
      21                 :            : #include <linker/linker-defs.h>
      22                 :            : 
      23                 :            : #if defined(CONFIG_CPU_HAS_NXP_MPU)
      24                 :            : #include <fsl_sysmpu.h>
      25                 :            : #endif
      26                 :            : 
      27                 :            : /**
      28                 :            :  *
      29                 :            :  * @brief Reset the system
      30                 :            :  *
      31                 :            :  * This routine resets the processor.
      32                 :            :  *
      33                 :            :  */
      34                 :            : 
      35                 :          0 : void __weak sys_arch_reboot(int type)
      36                 :            : {
      37                 :            :         ARG_UNUSED(type);
      38                 :            : 
      39                 :          0 :         NVIC_SystemReset();
      40                 :            : }
      41                 :            : 
      42                 :            : #if defined(CONFIG_CPU_HAS_ARM_MPU)
      43                 :            : /**
      44                 :            :  *
      45                 :            :  * @brief Clear all MPU region configuration
      46                 :            :  *
      47                 :            :  * This routine clears all ARM MPU region configuration.
      48                 :            :  *
      49                 :            :  */
      50                 :          0 : void z_arm_clear_arm_mpu_config(void)
      51                 :            : {
      52                 :            :         int i;
      53                 :            : 
      54                 :          0 :         int num_regions =
      55                 :          0 :                 ((MPU->TYPE & MPU_TYPE_DREGION_Msk) >> MPU_TYPE_DREGION_Pos);
      56                 :            : 
      57         [ #  # ]:          0 :         for (i = 0; i < num_regions; i++) {
      58                 :          0 :                 ARM_MPU_ClrRegion(i);
      59                 :            :         }
      60                 :          0 : }
      61                 :            : #elif CONFIG_CPU_HAS_NXP_MPU
      62                 :            : void z_arm_clear_arm_mpu_config(void)
      63                 :            : {
      64                 :            :         int i;
      65                 :            : 
      66                 :            :         int num_regions = FSL_FEATURE_SYSMPU_DESCRIPTOR_COUNT;
      67                 :            : 
      68                 :            :         SYSMPU_Enable(SYSMPU, false);
      69                 :            : 
      70                 :            :         /* NXP MPU region 0 is reserved for the debugger */
      71                 :            :         for (i = 1; i < num_regions; i++) {
      72                 :            :                 SYSMPU_RegionEnable(SYSMPU, i, false);
      73                 :            :         }
      74                 :            : }
      75                 :            : #endif /* CONFIG_CPU_HAS_NXP_MPU */
      76                 :            : 
      77                 :            : #if defined(CONFIG_INIT_ARCH_HW_AT_BOOT)
      78                 :            : /**
      79                 :            :  *
      80                 :            :  * @brief Reset system control blocks and core registers
      81                 :            :  *
      82                 :            :  * This routine resets Cortex-M system control block
      83                 :            :  * components and core registers.
      84                 :            :  *
      85                 :            :  */
      86                 :          0 : void z_arm_init_arch_hw_at_boot(void)
      87                 :            : {
      88                 :            :     /* Disable interrupts */
      89                 :            :         __disable_irq();
      90                 :            : 
      91                 :            : #if defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
      92                 :            :         __set_FAULTMASK(0);
      93                 :            : #endif
      94                 :            : 
      95                 :            :         /* Initialize System Control Block components */
      96                 :            : 
      97                 :            : #if defined(CONFIG_CPU_HAS_ARM_MPU) || defined(CONFIG_CPU_HAS_NXP_MPU)
      98                 :            :         /* Clear MPU region configuration */
      99                 :          0 :         z_arm_clear_arm_mpu_config();
     100                 :            : #endif /* CONFIG_CPU_HAS_ARM_MPU */
     101                 :            : 
     102                 :            :         /* Disable NVIC interrupts */
     103         [ #  # ]:          0 :         for (uint8_t i = 0; i < ARRAY_SIZE(NVIC->ICER); i++) {
     104                 :          0 :                 NVIC->ICER[i] = 0xFFFFFFFF;
     105                 :            :         }
     106                 :            :         /* Clear pending NVIC interrupts */
     107         [ #  # ]:          0 :         for (uint8_t i = 0; i < ARRAY_SIZE(NVIC->ICPR); i++) {
     108                 :          0 :                 NVIC->ICPR[i] = 0xFFFFFFFF;
     109                 :            :         }
     110                 :            : 
     111                 :            : #if defined(CONFIG_CPU_CORTEX_M_HAS_CACHE)
     112                 :            :         /* Reset D-Cache settings. If the D-Cache was enabled,
     113                 :            :          * SCB_DisableDCache() takes care of cleaning and invalidating it.
     114                 :            :          * If it was already disabled, just call SCB_InvalidateDCache() to
     115                 :            :          * reset it to a known clean state.
     116                 :            :          */
     117                 :            :         if (SCB->CCR & SCB_CCR_DC_Msk) {
     118                 :            :                 SCB_DisableDCache();
     119                 :            :         } else {
     120                 :            :                 SCB_InvalidateDCache();
     121                 :            :         }
     122                 :            :         /* Reset I-Cache settings. */
     123                 :            :         SCB_DisableICache();
     124                 :            : #endif /* CONFIG_CPU_CORTEX_M_HAS_CACHE */
     125                 :            : 
     126                 :            :         /* Restore Interrupts */
     127                 :            :         __enable_irq();
     128                 :            : 
     129                 :            :         __DSB();
     130                 :            :         __ISB();
     131                 :          0 : }
     132                 :            : #endif /* CONFIG_INIT_ARCH_HW_AT_BOOT */

Generated by: LCOV version 1.14