Hello World
Requirements
No specific requirement. This example should run without issue on all chips/boards/OSes.
Description
This example is a classic Hello World. It prints an hello world string on all available cores.
How to run
cmake -B build
cmake --build build --target menuconfig # Select your board in the menu
cmake --build build --target run
Or use the gap command:
gap init
gap menuconfig
gap run
cmake -B build
cmake --build build --target menuconfig # Select GVSoC in the menu
cmake --build build --target run
Or use the gap command:
gap init
gap menuconfig
gap run
Results
You should have an output looking like this (order may vary):
*** PMSIS HelloWorld ***
Entering main controller
[32 0] Hello World!
Cluster master core entry
[0 2] Hello World!
[0 0] Hello World!
[0 1] Hello World!
[0 3] Hello World!
[0 4] Hello World!
[0 5] Hello World!
[0 6] Hello World!
[0 7] Hello World!
Cluster master core exit
Bye !
Code
/* PMSIS includes */
#include <pmsis.h>
/* Task executed by cluster cores. */
void cluster_helloworld(void *arg)
{
uint32_t core_id = pi_core_id(), cluster_id = pi_cluster_id();
printf("[%d %d] Hello World!\n", cluster_id, core_id);
}
/* Cluster main entry, executed by core 0. */
void cluster_delegate(void *arg)
{
printf("Cluster master core entry\n");
/* Task dispatch to cluster cores. */
pi_cl_team_fork(pi_cl_cluster_nb_cores(), cluster_helloworld, arg);
printf("Cluster master core exit\n");
}
/* Program Entry. */
int main(void)
{
printf("\n\n\t *** PMSIS HelloWorld ***\n\n");
printf("Entering main controller\n");
uint32_t errors = 0;
uint32_t core_id = pi_core_id(), cluster_id = pi_cluster_id();
printf("[%d %d] Hello World!\n", cluster_id, core_id);
pi_device_t* cluster_dev;
if(pi_open(PI_CORE_CLUSTER, &cluster_dev))
{
printf("Cluster open failed !\n");
pmsis_exit(-1);
}
/* Prepare cluster task and send it to cluster. */
struct pi_cluster_task cl_task;
pi_cluster_send_task_to_cl(cluster_dev, pi_cluster_task(&cl_task, cluster_delegate, NULL));
pi_cluster_close(cluster_dev);
printf("Bye !\n");
return errors;
}
# 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 "helloworld")
set(TARGET_SRCS helloworld.c)
###############################################################################
# CMake pre initialization
###############################################################################
include($ENV{GAP_SDK_HOME}/utils/cmake/setup.cmake)
project(${TARGET_NAME} C ASM)
add_executable(${TARGET_NAME} ${TARGET_SRCS})
# For validation purposes
if (DEFINED USE_CUSTOM_XIP)
if (${USE_CUSTOM_XIP} EQUAL 1)
set(CONFIG_XIP y)
set(CONFIG_XIP_VIRTUAL_ADDRESS 0x20000000)
set(CONFIG_XIP_PAGE_SIZE 2)
set(CONFIG_XIP_PAGE_NUMBER 12)
endif()
endif()
###############################################################################
# CMake post initialization
###############################################################################
setupos(${TARGET_NAME})
source "$(GAP_SDK_HOME)/utils/kconfig/Kconfig"