L2 Banks Management

Requirements

No specific requirement.

Description

GAP9’s shared L2 memory is consisted with 24 shared banks (65536 Bytes each). Each bank can be powered on/off dynamically in your application, which is controlled by malloc and free.

Code

/* PMSIS includes */
#include "pmsis.h"

#define L2_SHARED_BANK_SIZE     (1<<17)
#define NB_SHARED_BANK          (12)

static int InitGPIOProbing(unsigned int Gpio)

{
#ifndef __PLATFORM_GVSOC__
        pi_pad_function_set(Gpio, 1);
        pi_gpio_pin_configure(Gpio, PI_GPIO_OUTPUT);
        pi_gpio_pin_write(Gpio, 0);
#endif
        return 0;
}



int main(void)
{
    printf("\n\n\t *** PMSIS Malloc Test ***\n\n");
    printf("Entering main controller\n");

    /* Init a GPIO for power measurement */
#ifndef __PLATFORM_GVSOC__
    unsigned int GPIO = 89, V=1, Vdd = 650;
    pi_pmu_voltage_set(PI_PMU_VOLTAGE_DOMAIN_CHIP, Vdd);

    if (InitGPIOProbing(GPIO)) pmsis_exit(-1);
#endif

    uint8_t *p[NB_SHARED_BANK];

    printf("In the beginning, all the banks unused should be off\n");
    printf("Dump the L2 free block:\n");
    pi_l2_malloc_dump();
    pi_time_wait_us(10 * 1000);

    printf("Test shared banks\n");
    for(int i=0; i<NB_SHARED_BANK; i++)
    {
        // Allocate 1 shared bank size, this should turn the next bank on
        printf("Allocate bank %d:\n", i);
        p[i] = pi_l2_malloc(L2_SHARED_BANK_SIZE);
        if (p[i] == NULL)
        {
            printf("Allocation failed, last free chunk is smaller than 128KB. All the banks are powered on\n");
            pi_l2_malloc_dump();
            break;
        }
        printf("allocated %d at 0x%p\n", L2_SHARED_BANK_SIZE, p[i]);

        printf("Dump the L2 free block:\n");
        pi_l2_malloc_dump();
#ifndef __PLATFORM_GVSOC__
        pi_gpio_pin_write(GPIO, V);
        V = V^1;
#endif
        pi_time_wait_us(10 * 1000);
    }

    printf("Test success !\n");
    pmsis_exit(0);
}