FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1-RevB_FreedomStudio/freedom-metal/src/pmp.c
/* This function calculates the minimum granularity from the address
 * that pmpaddr takes on after writing all ones to pmpaddr when pmpcfg = 0.
 *
 * Detect the address granularity based on the position of the
 * least-significant 1 set in the address.
 *
 * For example, if the value read from pmpaddr is 0x3ffffc00, the
 * least-significant set bit is in bit 10 (counting from 0), resulting
 * in a detected granularity of 2^(10 + 2) = 4096.
 */
This function calculates the minimum granularity from the address
that pmpaddr takes on after writing all ones to pmpaddr when pmpcfg = 0.

Detect the address granularity based on the position of the
least-significant 1 set in the address.

For example, if the value read from pmpaddr is 0x3ffffc00, the
least-significant set bit is in bit 10 (counting from 0), resulting
in a detected granularity of 2^(10 + 2) = 4096.
This function calculates the minimum granularity from the address that pmpaddr takes on after writing all ones to pmpaddr when pmpcfg = 0 . Detect the address granularity based on the position of the least - significant 1 set in the address . For example if the value read from pmpaddr is 0x3ffffc00 the least - significant set bit is in bit 10 ( counting from 0 ) resulting in a detected granularity of 2^ ( 10 + 2 ) = 4096 .
static uintptr_t _get_detected_granularity(uintptr_t address) {
    if (address == 0) {
        return (uintptr_t)-1;
    }
    int index = 0;
    while (((address >> index) & 0x1) == 0) {
        index += 1;
    }
    return (1 << (index + 2));
}
static uintptr_t _get_detected_granularity ( uintptr_t address ) { if ( address == 0 ) { return ( uintptr_t ) -1 ; } int index = 0 ; while ( ( ( address >> index ) & 0x1 ) == 0 ) { index += 1 ; } return ( 1 << ( index + 2 ) ) ; }
This function calculates the minimum granularity from the address
 that pmpaddr takes on after writing all ones to pmpaddr when pmpcfg = 0.
This function calculates the minimum granularity from the address that pmpaddr takes on after writing all ones to pmpaddr when pmpcfg = 0 .
/* Get the index of the least significant set bit */ /* The granularity is equal to 2^(index + 2) bytes */