diff --git a/examples/legacy_apps/cmake/options.cmake b/examples/legacy_apps/cmake/options.cmake index 5d036bb..d6b6581 100644 --- a/examples/legacy_apps/cmake/options.cmake +++ b/examples/legacy_apps/cmake/options.cmake @@ -21,8 +21,6 @@ if (NOT DEFINED MACHINE) endif (NOT DEFINED MACHINE) message ("-- Machine: ${MACHINE}") -string (TOLOWER ${CMAKE_SYSTEM_NAME} PROJECT_SYSTEM) -string (TOUPPER ${CMAKE_SYSTEM_NAME} PROJECT_SYSTEM_UPPER) string (TOLOWER ${CMAKE_SYSTEM_PROCESSOR} PROJECT_PROCESSOR) string (TOUPPER ${CMAKE_SYSTEM_PROCESSOR} PROJECT_PROCESSOR_UPPER) string (TOLOWER ${MACHINE} PROJECT_MACHINE) diff --git a/examples/legacy_apps/cmake/platforms/cross_freertos_gcc.cmake b/examples/legacy_apps/cmake/platforms/cross_freertos_gcc.cmake new file mode 100644 index 0000000..4db1913 --- /dev/null +++ b/examples/legacy_apps/cmake/platforms/cross_freertos_gcc.cmake @@ -0,0 +1,14 @@ +set (CMAKE_SYSTEM_NAME "Generic" CACHE STRING "") + +string (TOLOWER "freertos" PROJECT_SYSTEM) +string (TOUPPER "freertos" PROJECT_SYSTEM_UPPER) + +set (CMAKE_C_COMPILER "${CROSS_PREFIX}gcc") +set (CMAKE_CXX_COMPILER "${CROSS_PREFIX}g++") +# _exit is in the BSP rather than in libgcc, leaving this out +# causes errors in try_compile on ARM generic. +set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE STRING "") +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER CACHE STRING "") +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER CACHE STRING "") diff --git a/examples/legacy_apps/cmake/platforms/cross_generic_gcc.cmake b/examples/legacy_apps/cmake/platforms/cross_generic_gcc.cmake index 862ec25..f06bb1a 100644 --- a/examples/legacy_apps/cmake/platforms/cross_generic_gcc.cmake +++ b/examples/legacy_apps/cmake/platforms/cross_generic_gcc.cmake @@ -1,5 +1,8 @@ set (CMAKE_SYSTEM_NAME "Generic" CACHE STRING "") +string (TOLOWER "generic" PROJECT_SYSTEM) +string (TOUPPER "generic" PROJECT_SYSTEM_UPPER) + set (CMAKE_C_COMPILER "${CROSS_PREFIX}gcc") set (CMAKE_CXX_COMPILER "${CROSS_PREFIX}g++") # _exit is in the BSP rather than in libgcc, leaving this out diff --git a/examples/legacy_apps/cmake/platforms/cross_linux_gcc.cmake b/examples/legacy_apps/cmake/platforms/cross_linux_gcc.cmake index 4d372d4..3c09dfa 100644 --- a/examples/legacy_apps/cmake/platforms/cross_linux_gcc.cmake +++ b/examples/legacy_apps/cmake/platforms/cross_linux_gcc.cmake @@ -1,4 +1,8 @@ set (CMAKE_SYSTEM_NAME "Linux") + +string (TOLOWER "linux" PROJECT_SYSTEM) +string (TOUPPER "linux" PROJECT_SYSTEM_UPPER) + set (CMAKE_C_COMPILER "${CROSS_PREFIX}gcc") set (CMAKE_CXX_COMPILER "${CROSS_PREFIX}g++") diff --git a/examples/legacy_apps/cmake/platforms/zynqmp_r5_generic.cmake b/examples/legacy_apps/cmake/platforms/zynqmp_r5_generic.cmake index 4b856c6..d98b144 100644 --- a/examples/legacy_apps/cmake/platforms/zynqmp_r5_generic.cmake +++ b/examples/legacy_apps/cmake/platforms/zynqmp_r5_generic.cmake @@ -4,5 +4,3 @@ set (CROSS_PREFIX "armr5-none-eabi-" CACHE STRING "") # Xilinx SDK version earlier than 2017.2 use mfloat-abi=soft by default to generate libxil set (CMAKE_C_FLAGS "-mfloat-abi=hard -mfpu=vfpv3-d16 -mcpu=cortex-r5" CACHE STRING "") - -include (cross_generic_gcc) diff --git a/examples/legacy_apps/examples/echo/freertos/main.c b/examples/legacy_apps/examples/echo/freertos/main.c index c25ee8f..5f34c22 100644 --- a/examples/legacy_apps/examples/echo/freertos/main.c +++ b/examples/legacy_apps/examples/echo/freertos/main.c @@ -51,7 +51,7 @@ static void rpmsg_listen_task(void *unused_arg) if (!rpdev) { LPERROR("Failed to create rpmsg virtio device.\r\n"); } else { - echo_remote_app(rpdev, platform); + rpmsg_echo_app(rpdev, platform); platform_release_rpmsg_vdev(rpdev, platform); } } diff --git a/examples/legacy_apps/machine/zynqmp_r5/CMakeLists.txt b/examples/legacy_apps/machine/zynqmp_r5/CMakeLists.txt index e9fb7ad..9807b27 100644 --- a/examples/legacy_apps/machine/zynqmp_r5/CMakeLists.txt +++ b/examples/legacy_apps/machine/zynqmp_r5/CMakeLists.txt @@ -1,9 +1,12 @@ include(CheckSymbolExists) +if (${PROJECT_SYSTEM} STREQUAL "freertos") + add_definitions(-DFREERTOS_BSP) +endif() + collect (APP_COMMON_SOURCES platform_info.c) collect (APP_COMMON_SOURCES rsc_table.c) collect (APP_COMMON_SOURCES zynqmp_r5_a53_rproc.c) -collect (APP_COMMON_SOURCES helper.c) collect (APP_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_SYSTEM}/gic_init.c") @@ -26,6 +29,7 @@ collect (PROJECT_INC_DIRS "${XIL_INCLUDE_DIR}") find_library(LIBXIL_LIB NAMES xil PATHS ${CMAKE_FIND_ROOT_PATH}) get_filename_component(LIBXIL_LIB_DIR ${LIBXIL_LIB} DIRECTORY) collect(PROJECT_LIB_DIRS ${LIBXIL_LIB_DIR}) +collect(PROJECT_LIB_DIRS ${CMAKE_LIBRARY_PATH}) # check PM API for certain headers and set client version based CHECK_SYMBOL_EXISTS(XPAR_XILPM_ENABLED "xparameters.h" PM_FOUND) @@ -40,6 +44,8 @@ if(PM_FOUND) endif(VERSION_2_PM_CLIENT) endif(PM_FOUND) +collect(PROJECT_LIB_DEPS metal_xlnx_extension) +collect(PROJECT_LIB_DEPS xiltimer) collect(PROJECT_LIB_DEPS xil) collect(PROJECT_LIB_DEPS xilstandalone) collect(PROJECT_LIB_DEPS c) diff --git a/examples/legacy_apps/machine/zynqmp_r5/freertos/gic_init.c b/examples/legacy_apps/machine/zynqmp_r5/freertos/gic_init.c index 4a33a2b..1ac4c3b 100644 --- a/examples/legacy_apps/machine/zynqmp_r5/freertos/gic_init.c +++ b/examples/legacy_apps/machine/zynqmp_r5/freertos/gic_init.c @@ -19,14 +19,17 @@ #include "xscugic.h" /* Interrupt Controller setup */ -int app_gic_initialize(void) +int system_interrupt_register(int int_num, void (*intr_handler)(void *), + void *data) { + long ret; + /* * Register the ISR with the interrupt controller instance * initialized by porting layer. */ - xPortInstallInterruptHandler(IPI_IRQ_VECT_ID, - (Xil_ExceptionHandler)metal_xlnx_irq_isr, - (void *)IPI_IRQ_VECT_ID); - return 0; + ret = xPortInstallInterruptHandler(int_num, + intr_handler, + data); + return (int)ret; } diff --git a/examples/legacy_apps/machine/zynqmp_r5/generic/gic_init.c b/examples/legacy_apps/machine/zynqmp_r5/generic/gic_init.c index 68e07db..0b839fb 100644 --- a/examples/legacy_apps/machine/zynqmp_r5/generic/gic_init.c +++ b/examples/legacy_apps/machine/zynqmp_r5/generic/gic_init.c @@ -8,20 +8,21 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include "xparameters.h" -#include "xil_exception.h" -#include "xil_printf.h" -#include "xscugic.h" #include #include +#include #include "platform_info.h" +#include "xil_exception.h" +#include "xparameters.h" +#include "xscugic.h" + #define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID static XScuGic xInterruptController; -/* Interrupt Controller setup */ -int app_gic_initialize(void) +int system_interrupt_register(int intr_num, void (*intr_handler)(void *), + void *data) { uint32_t status; XScuGic_Config *int_ctrl_config; /* interrupt controller configuration params */ @@ -38,7 +39,7 @@ int app_gic_initialize(void) * Initialize the interrupt controller driver */ int_ctrl_config = XScuGic_LookupConfig(INTC_DEVICE_ID); - if (!int_ctrl_config) + if (int_ctrl_config == NULL) return XST_FAILURE; status = XScuGic_CfgInitialize(&xInterruptController, int_ctrl_config, @@ -47,36 +48,36 @@ int app_gic_initialize(void) return XST_FAILURE; /* Only associate interrupt needed to this CPU */ - for (int_id = 32U; int_id -#include -#include "xparameters.h" -#include "xil_exception.h" -#include "xil_printf.h" -#include "xscugic.h" -#include "xil_cache.h" -#include -#include -#include "platform_info.h" -#include "rsc_table.h" - -/* - * app_gic_initialize - Interrupt Controller setup - */ -extern int app_gic_initialize(void); - -/* Main hw machinery initialization entry point, called from main()*/ -/* return 0 on success */ -int init_system(void) -{ - int ret; - struct metal_init_params metal_param = METAL_INIT_DEFAULTS; - - /* - * Ensure resource table resource is set up before any attempts - * are made to cache the table. - */ - get_resource_table(0, &ret); - - /* Low level abstraction layer for openamp initialization */ - metal_init(&metal_param); - - /* configure the global interrupt controller */ - app_gic_initialize(); - - /* Initialize metal Xilinx IRQ controller */ - ret = metal_xlnx_irq_init(); - if (ret) - metal_err("metal_xlnx_irq_init failed.\r\n"); - - return ret; -} - -void cleanup_system(void) -{ - metal_finish(); - free_resource_table(); - - Xil_DCacheDisable(); - Xil_ICacheDisable(); - Xil_DCacheInvalidate(); - Xil_ICacheInvalidate(); -} diff --git a/examples/legacy_apps/machine/zynqmp_r5/platform_info.c b/examples/legacy_apps/machine/zynqmp_r5/platform_info.c index e39c476..0aab324 100644 --- a/examples/legacy_apps/machine/zynqmp_r5/platform_info.c +++ b/examples/legacy_apps/machine/zynqmp_r5/platform_info.c @@ -18,16 +18,26 @@ * **************************************************************************/ +#include +#include +#include #include #include #include #include +#include +#include #include #include -#include + #include "platform_info.h" #include "rsc_table.h" #include "suspend.h" +#include "xparameters.h" +#include "xscugic.h" +#include "xil_exception.h" +#include "xil_printf.h" +#include "xil_cache.h" #define KICK_DEV_NAME "poll_dev" #define KICK_BUS_NAME "generic" @@ -54,6 +64,8 @@ #define SHARED_BUF_OFFSET 0x8000UL #endif /* !SHARED_BUF_OFFSET */ +#define FREERTOS_IRQ_ID_OFFSET 32 + /* Polling information used by remoteproc operations. */ static metal_phys_addr_t poll_phys_addr = POLL_BASE_ADDR; struct metal_device kick_device = { @@ -74,7 +86,11 @@ struct metal_device kick_device = { .node = {NULL}, #ifndef RPMSG_NO_IPI .irq_num = 1, +#ifdef FREERTOS_BSP + .irq_info = (void *)(IPI_IRQ_VECT_ID - FREERTOS_IRQ_ID_OFFSET), +#else .irq_info = (void *)IPI_IRQ_VECT_ID, +#endif /* FREERTOS_BSP */ #endif /* !RPMSG_NO_IPI */ }; @@ -88,19 +104,38 @@ static struct remoteproc_priv rproc_priv = { static struct remoteproc rproc_inst; -/* External functions */ -extern int init_system(void); -extern void cleanup_system(void); - /* * processor operations from r5 to a53. It defines * notification operation and remote processor management operations. */ extern const struct remoteproc_ops zynqmp_r5_a53_proc_ops; +/** + * Definition of the interrupt controller will be provided by + * libmetal_xlnx_extension.a module + **/ +extern struct metal_irq_controller xlnx_irq_cntr; + +int system_interrupt_register(int int_num, void (*intr_handler)(void *), + void *data); /* RPMsg virtio shared buffer pool */ static struct rpmsg_virtio_shm_pool shpool; +static void xlnx_irq_isr(void *arg) +{ + int vector; + + vector = (int)arg; + + if (vector >= xlnx_irq_cntr.irq_num || vector < 0) { + metal_err("%s, irq %d out of range, max = %d\n", + __func__, vector, xlnx_irq_cntr.irq_num); + return; + } + + (void)metal_irq_handle(&xlnx_irq_cntr.irqs[vector], (int)vector); +} + static struct remoteproc * platform_create_proc(int proc_index, int rsc_index) { @@ -141,7 +176,7 @@ platform_create_proc(int proc_index, int rsc_index) /* parse resource table to remoteproc */ ret = remoteproc_set_rsc_table(&rproc_inst, rsc_table, rsc_size); if (ret) { - xil_printf("Failed to initialize remoteproc\r\n"); + xil_printf("Failed to initialize remoteproc\n"); remoteproc_remove(&rproc_inst); return NULL; } @@ -150,19 +185,65 @@ platform_create_proc(int proc_index, int rsc_index) return &rproc_inst; } +static int xlnx_machine_init(void) +{ + int ret; + + if (!kick_device.irq_info) { + metal_err("invalid kick dev, irq info not available\n"); + return -EINVAL; + } + + ret = system_interrupt_register((int)kick_device.irq_info, + xlnx_irq_isr, + (void *)kick_device.irq_info); + if (ret) { + metal_err("sys intr %d registration failed %d\n", + (int)kick_device.irq_info, ret); + return ret; + } + + /* Register Xilinx IRQ controller with libmetal */ + ret = metal_irq_register_controller(&xlnx_irq_cntr); + if (ret < 0) { + metal_err("irq controller registration with libmetal failed.\n"); + return ret; + } + + return ret; +} + +static void xlnx_machine_cleanup(void) +{ + metal_finish(); + free_resource_table(); + + Xil_DCacheDisable(); + Xil_ICacheDisable(); + Xil_DCacheInvalidate(); + Xil_ICacheInvalidate(); +} + int platform_init(int argc, char *argv[], void **platform) { + struct metal_init_params init_param = METAL_INIT_DEFAULTS; unsigned long proc_id = 0; unsigned long rsc_id = 0; struct remoteproc *rproc; + int len = 0; + int ret; + + /* + * Ensure resource table resource is set up before any attempts + * are made to cache the table. + */ + get_resource_table(0, &len); + + /* Low level abstraction layer for openamp initialization */ + metal_init(&init_param); - if (!platform) { - xil_printf("Failed to initialize platform," - "NULL pointer to store platform data.\r\n"); + if (!platform) return -EINVAL; - } - /* Initialize HW system components */ - init_system(); if (argc >= 2) { proc_id = strtoul(argv[1], NULL, 0); @@ -172,12 +253,21 @@ int platform_init(int argc, char *argv[], void **platform) rsc_id = strtoul(argv[2], NULL, 0); } + /* Initialize HW machine components */ + ret = xlnx_machine_init(); + if (ret < 0) { + metal_err("failed to init machine err %d\n", ret); + return ret; + } + rproc = platform_create_proc(proc_id, rsc_id); if (!rproc) { xil_printf("Failed to create remoteproc device.\r\n"); return -EINVAL; } + *platform = rproc; + return 0; } @@ -215,8 +305,7 @@ platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index, xil_printf("initializing rpmsg shared buffer pool\r\n"); /* Only RPMsg virtio driver needs to initialize the shared buffers pool */ - rpmsg_virtio_init_shm_pool(&shpool, shbuf, - (SHARED_MEM_SIZE - SHARED_BUF_OFFSET)); + rpmsg_virtio_init_shm_pool(&shpool, shbuf, SHARED_MEM_SIZE); xil_printf("initializing rpmsg vdev\r\n"); /* RPMsg virtio device can set shared buffers pool argument to NULL */ @@ -227,7 +316,9 @@ platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index, xil_printf("failed rpmsg_init_vdev\r\n"); goto err2; } + xil_printf("initializing rpmsg vdev\r\n"); + return rpmsg_virtio_get_rpmsg_device(rpmsg_vdev); err2: remoteproc_remove_virtio(rproc, vdev); @@ -293,5 +384,6 @@ void platform_cleanup(void *platform) if (rproc) remoteproc_remove(rproc); - cleanup_system(); + + xlnx_machine_cleanup(); } diff --git a/examples/legacy_apps/machine/zynqmp_r5/platform_info.h b/examples/legacy_apps/machine/zynqmp_r5/platform_info.h index 0d0678b..07678f6 100644 --- a/examples/legacy_apps/machine/zynqmp_r5/platform_info.h +++ b/examples/legacy_apps/machine/zynqmp_r5/platform_info.h @@ -51,7 +51,7 @@ extern "C" { #endif /* !IPI_IRQ_VECT_ID */ #ifndef POLL_BASE_ADDR -#define POLL_BASE_ADDR 0xFF33100 +#define POLL_BASE_ADDR 0xFF310000 #endif /* !POLL_BASE_ADDR */ #ifndef IPI_CHN_BITMASK diff --git a/examples/legacy_apps/system/freertos/CMakeLists.txt b/examples/legacy_apps/system/freertos/CMakeLists.txt index 3b13c04..8696078 100644 --- a/examples/legacy_apps/system/freertos/CMakeLists.txt +++ b/examples/legacy_apps/system/freertos/CMakeLists.txt @@ -1,7 +1,4 @@ # Required libraries for Demos for linking. -find_library(FIND_FREERTOS freertos) -if (FIND_FREERTOS) - collect(PROJECT_LIB_DEPS freertos) -endif(FIND_FREERTOS) +collect(PROJECT_LIB_DEPS freertos) -collect (APP_COMMON_SOURCES suspend.c) \ No newline at end of file +collect (APP_COMMON_SOURCES suspend.c) diff --git a/examples/legacy_apps/system/freertos/suspend.c b/examples/legacy_apps/system/freertos/suspend.c index b384469..0331cf8 100644 --- a/examples/legacy_apps/system/freertos/suspend.c +++ b/examples/legacy_apps/system/freertos/suspend.c @@ -8,14 +8,14 @@ #include "FreeRTOS.h" #include "task.h" -extern TaskHandle_t rpmsg_task; - void system_suspend(void) { - vTaskSuspend(rpmsg_task); + TaskHandle_t current_task = xTaskGetCurrentTaskHandle(); + vTaskSuspend(current_task); } void system_resume(void) { - xTaskResumeFromISR(rpmsg_task); + TaskHandle_t current_task = xTaskGetCurrentTaskHandle(); + xTaskResumeFromISR(current_task); }