Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move examples dir from the libmetal repository #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/libmetal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
collect(PROJECT_LIB_DEPS metal)

add_subdirectory (system)

# vim: expandtab:ts=2:sw=2:smartindent
4 changes: 4 additions & 0 deletions examples/libmetal/system/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_SYSTEM})
add_subdirectory(${PROJECT_SYSTEM})
endif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_SYSTEM})
4 changes: 4 additions & 0 deletions examples/libmetal/system/freertos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE})
add_subdirectory(${PROJECT_MACHINE})
endif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE})
18 changes: 18 additions & 0 deletions examples/libmetal/system/freertos/zynqmp_r5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

collect(PROJECT_LIB_DEPS freertos)
collect(PROJECT_LIB_DEPS metal)
collect(PROJECT_LIB_DEPS xil)
collect(PROJECT_LIB_DEPS c)
collect(PROJECT_LIB_DEPS m)

set (_lib "xil")
find_library (_lib_path ${_lib})
if (NOT _lib_path)
message ( "external library ${_lib_path} not found" )
message ( "hint: you may need to pass -DCMAKE_LIBRARY_PATH=<path>" )
message ( FATAL_ERROR "library ${_lib} is required to build the examples" )
endif (NOT _lib_path)
get_filename_component (_lib_path ${_lib_path} DIRECTORY)
collect (PROJECT_LIB_DIRS ${_lib_path})

add_subdirectory(zynqmp_amp_demo)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
collector_list (_list PROJECT_INC_DIRS)
include_directories (${_list} ${CMAKE_CURRENT_SOURCE_DIR})

collector_list (_list PROJECT_LIB_DIRS)
link_directories (${_list})

collector_list (_deps PROJECT_LIB_DEPS)

set (_linker_script ${CMAKE_CURRENT_SOURCE_DIR}/lscript.ld)

set (_src_common ${CMAKE_CURRENT_SOURCE_DIR}/init_${PROJECT_SYSTEM}.c)
set (_app0 libmetal_amp_demod)
set (_src0 ${CMAKE_CURRENT_SOURCE_DIR}/${_app0}.c)
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/sys_init.c)
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_demod.c)
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_atomic_demod.c)
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/ipi_shmem_demod.c)
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/ipi_latency_demod.c)
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_latency_demod.c)
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_throughput_demod.c)

get_property (_linker_options GLOBAL PROPERTY TEST_LINKER_OPTIONS)
add_executable (${_app0}.elf ${_src0})
get_property (_ec_flgs GLOBAL PROPERTY "PROJECT_EC_FLAGS")
target_compile_options (${_app0}.elf PUBLIC ${_ec_flgs})
target_link_libraries(${_app0}.elf -Wl,-Map=${_app0}.map -Wl,--gc-sections -T\"${_linker_script}\" -Wl,--start-group ${_deps} -Wl,--end-group)
install (TARGETS ${_app0}.elf RUNTIME DESTINATION bin)

# vim: expandtab:ts=2:sw=2:smartindent
163 changes: 163 additions & 0 deletions examples/libmetal/system/freertos/zynqmp_r5/zynqmp_amp_demo/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Copyright (c) 2017, Xilinx Inc. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#ifndef __COMMON_H__
#define __COMMON_H__

#include <unistd.h>
#include <stdio.h>
#include <string.h>

#include <metal/atomic.h>
#include <metal/alloc.h>
#include <metal/irq.h>
#include <metal/errno.h>
#include <metal/sys.h>
#include <metal/cpu.h>
#include <metal/io.h>
#include <metal/device.h>
#include <sys/types.h>
#include "sys_init.h"

/* Devices names */
#define BUS_NAME "generic"
#define IPI_DEV_NAME "ff310000.ipi"
#define SHM_DEV_NAME "3ed80000.shm"
#define TTC_DEV_NAME "ff110000.ttc"

/* IPI registers offset */
#define IPI_TRIG_OFFSET 0x0 /* IPI trigger reg offset */
#define IPI_OBS_OFFSET 0x4 /* IPI observation reg offset */
#define IPI_ISR_OFFSET 0x10 /* IPI interrupt status reg offset */
#define IPI_IMR_OFFSET 0x14 /* IPI interrupt mask reg offset */
#define IPI_IER_OFFSET 0x18 /* IPI interrupt enable reg offset */
#define IPI_IDR_OFFSET 0x1C /* IPI interrupt disable reg offset */

#define IPI_MASK 0x1000000 /* IPI mask for kick from APU.
We use PL0 IPI in this demo. */

/* TTC counter offsets */
#define XTTCPS_CLK_CNTRL_OFFSET 0x0 /* TTC counter clock control reg offset */
#define XTTCPS_CNT_CNTRL_OFFSET 0xC /* TTC counter control reg offset */
#define XTTCPS_CNT_VAL_OFFSET 0x18 /* TTC counter val reg offset */
#define XTTCPS_CNT_OFFSET(ID) ((ID) == 1 ? 0 : 1 << (ID)) /* TTC counter offset
ID is from 1 to 3 */

/* TTC counter control masks */
#define XTTCPS_CNT_CNTRL_RST_MASK 0x10U /* TTC counter control reset mask */
#define XTTCPS_CNT_CNTRL_DIS_MASK 0x01U /* TTC counter control disable mask */

#define LPRINTF(format, ...) \
xil_printf("\r\nSERVER> " format, ##__VA_ARGS__)

#define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__)

extern struct metal_device *ipi_dev; /* IPI metal device */
extern struct metal_device *shm_dev; /* SHM metal device */
extern struct metal_device *ttc_dev; /* TTC metal device */

/**
* @brief atomic_shmem_demod() - Shared memory atomic operation demo
* This task will:
* * Wait for the remote to write to shared memory.
* * Once it receives the notification via polling, start atomic add by
* 1 for 1000 times to first 32 bits of memory in the
* shared memory location at 3ed00000 which is pointed to by shm_io.
* * Write to shared mem to notify the remote once it finishes
* calculation.
*
* @return - If setup failed, return the corresponding error number. Otherwise
* return 0 on success.
*/
int atomic_shmem_demod();

/**
* @brief ipi_latency_demod() - Show performance of IPI with Libmetal.
* Loop until APU tells RPU to stop via shared memory.
* In loop, wait for interrupt (interrupt handler stops APU to
* RPU timer). Then reset count on RPU to APU timer to 0, start
* counting and send interrupt to notify APU.
*
* @return - 0 on success, error code if failure.
*/
int ipi_latency_demod();

/**
* @brief ipi_shmem_demod() - shared memory IPI demo
* This task will:
* * Wait for IPI interrupt from the remote
* * Once it received the interrupt, copy the content from
* the ping buffer to the pong buffer.
* * Update the shared memory descriptor for the new available
* pong buffer.
* * Trigger IPI to notifty the remote.
*
* @return - 0 on success, error code if failure.
*/
int ipi_shmem_demod();

/**
* @brief shmem_demod() - Show use of shared memory with Libmetal.
* Until KEEP_GOING signal is stopped, keep looping.
* In the loop, read message from remote, add one to message and
* then respond. After the loop, cleanup resources.
*
* @return - return 0 on success, otherwise return error number indicating
* type of error
*/
int shmem_demod();

/**
* @brief shmem_latency_demod() - Show performance of shared mem.
* Loop until APU tells RPU to stop via shared memory.
* In loop, wait for interrupt (interrupt handler stops APU to
* RPU timer). Then reset count on RPU to APU timer to 0, start
* counting and send interrupt to notify APU.
*
* @return - 0 on success, error code if failure.
*/
int shmem_latency_demod();

/**
* @brief shmem_throughput_demod() - Show throughput of shared mem.
* At signal of remote, record total time to do block read and write
* operation Loop until APU tells RPU to stop via shared memory.
* In loop, wait for interrupt (interrupt handler stops APU to
* RPU timer). Then reset count on RPU to APU timer to 0, start
* counting and send interrupt to notify APU.
*
* @return - 0 on success, error code if failure.
*/
int shmem_throughput_demod();

static inline void wait_for_interrupt()
{
metal_asm volatile("wfi");
}

/**
* @brief wait_for_notified() - Loop until notified bit
* in channel is set.
*
* @param[in] notified - pointer to the notified variable
*/
static inline void wait_for_notified(atomic_int *notified)
{
while (atomic_flag_test_and_set(notified));
}

/**
* @brief print_demo() - print demo string
*
* @param[in] name - demo name
*/
static inline void print_demo(char *name)
{
LPRINTF("====== libmetal demo: %s ======\n", name);
}

#endif /* __COMMON_H__ */