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);
}
# Copyright (c) 2022 GreenWaves Technologies SAS
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of GreenWaves Technologies SAS nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required(VERSION 3.19)
###############################################################################
# Panel Control
###############################################################################
set(TARGET_NAME "l2_banks_management")
set(TARGET_SRCS l2_banks_management.c)
###############################################################################
# CMake pre initialization
###############################################################################
set(CONFIG_GAP_SDK_HOME $ENV{GAP_SDK_HOME})
include($ENV{GAP_SDK_HOME}/utils/cmake/setup.cmake)
project(${TARGET_NAME} C ASM)
add_executable(${TARGET_NAME} ${TARGET_SRCS})
###############################################################################
# CMake post initialization
###############################################################################
setupos(${TARGET_NAME})