FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1-RevB_FreedomStudio/freedom-metal/src/pmp.c
/* This function calculates the granularity requested by the user's provided
 * value for pmpaddr.
 *
 * Calculate the requested granularity based on the position of the
 * least-significant unset bit.
 *
 * For example, if the requested address is 0x20009ff, the least-significant
 * unset bit is at index 9 (counting from 0), resulting in a requested
 * granularity of 2^(9 + 3) = 4096.
 */
This function calculates the granularity requested by the user's provided
value for pmpaddr.

Calculate the requested granularity based on the position of the
least-significant unset bit.

For example, if the requested address is 0x20009ff, the least-significant
unset bit is at index 9 (counting from 0), resulting in a requested
granularity of 2^(9 + 3) = 4096.
This function calculates the granularity requested by the user ' s provided value for pmpaddr . Calculate the requested granularity based on the position of the least - significant unset bit . For example if the requested address is 0x20009ff the least - significant unset bit is at index 9 ( counting from 0 ) resulting in a requested granularity of 2^ ( 9 + 3 ) = 4096 .
static uintptr_t _get_pmpaddr_granularity(uintptr_t address) {
    int index = 0;
    while (((address >> index) & 0x1) == 1) {
        index += 1;
    }
    return (1 << (index + 3));
}
static uintptr_t _get_pmpaddr_granularity ( uintptr_t address ) { int index = 0 ; while ( ( ( address >> index ) & 0x1 ) == 1 ) { index += 1 ; } return ( 1 << ( index + 3 ) ) ; }
This function calculates the granularity requested by the user's provided
 value for pmpaddr.
This function calculates the granularity requested by the user ' s provided value for pmpaddr .
/* Get the index of the least significant unset bit */ /* The granularity is equal to 2^(index + 3) bytes */