Skip to content

Commit 8e85b55

Browse files
committed
examples: cleanup Zynq MP SoC AMP examples
Clean up the following Zynq MP SoC AMP examples: * shared memory demo * atomic operation over shared memory demo * shared memory with IPI demo * IPI latency measurement demo * shared memory with IPI latency measurement demo * shared memory with IPI throughput measurement demo Signed-off-by: Wendy Liang <jliang@xilinx.com>
1 parent 02a0646 commit 8e85b55

38 files changed

+4387
-3192
lines changed

examples/system/generic/zynqmp_r5/zynqmp_amp_demo/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ collector_list (_deps PROJECT_LIB_DEPS)
99
set (_linker_script ${CMAKE_CURRENT_SOURCE_DIR}/lscript.ld)
1010

1111
set (_src_common ${CMAKE_CURRENT_SOURCE_DIR}/init_${PROJECT_SYSTEM}.c)
12-
set (_app0 libmetal_amp_demo)
12+
set (_app0 libmetal_amp_demod)
1313
set (_src0 ${CMAKE_CURRENT_SOURCE_DIR}/${_app0}.c)
1414
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/sys_init.c)
15-
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_atomic_task.c)
16-
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/ipi_latency_task.c)
17-
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/ipi_shmem_task.c)
18-
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_task.c)
19-
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_latency_task.c)
20-
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_throughput_task.c)
15+
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_demod.c)
16+
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_atomic_demod.c)
17+
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/ipi_shmem_demod.c)
18+
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/ipi_latency_demod.c)
19+
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_latency_demod.c)
20+
list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_throughput_demod.c)
2121

2222
get_property (_linker_options GLOBAL PROPERTY TEST_LINKER_OPTIONS)
2323
add_executable (${_app0}.elf ${_src0})
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
/*
2+
* Copyright (c) 2017, Xilinx Inc. and Contributors. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
*
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* 3. Neither the name of Xilinx nor the names of its contributors may be used
15+
* to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#ifndef __COMMON_H__
32+
#define __COMMON_H__
33+
34+
#include <unistd.h>
35+
#include <stdio.h>
36+
#include <string.h>
37+
38+
#include <metal/atomic.h>
39+
#include <metal/alloc.h>
40+
#include <metal/irq.h>
41+
#include <errno.h>
42+
#include <metal/sys.h>
43+
#include <metal/cpu.h>
44+
#include <metal/io.h>
45+
#include <metal/device.h>
46+
#include <sys/types.h>
47+
#include "sys_init.h"
48+
49+
/* Devices names */
50+
#define BUS_NAME "generic"
51+
#define IPI_DEV_NAME "ff310000.ipi"
52+
#define SHM_DEV_NAME "3ed80000.shm"
53+
#define TTC_DEV_NAME "ff110000.ttc"
54+
55+
/* IPI registers offset */
56+
#define IPI_TRIG_OFFSET 0x0 /* IPI trigger reg offset */
57+
#define IPI_OBS_OFFSET 0x4 /* IPI observation reg offset */
58+
#define IPI_ISR_OFFSET 0x10 /* IPI interrupt status reg offset */
59+
#define IPI_IMR_OFFSET 0x14 /* IPI interrupt mask reg offset */
60+
#define IPI_IER_OFFSET 0x18 /* IPI interrupt enable reg offset */
61+
#define IPI_IDR_OFFSET 0x1C /* IPI interrup disable reg offset */
62+
63+
#define IPI_MASK 0x1000000 /* IPI mask for kick from APU.
64+
We use PL0 IPI in this demo. */
65+
66+
/* TTC counter offsets */
67+
#define XTTCPS_CLK_CNTRL_OFFSET 0x0 /* TTC counter clock control reg offset */
68+
#define XTTCPS_CNT_CNTRL_OFFSET 0xC /* TTC counter control reg offset */
69+
#define XTTCPS_CNT_VAL_OFFSET 0x18 /* TTC counter val reg offset */
70+
#define XTTCPS_CNT_OFFSET(ID) (2 << (ID - 1)) /* TTC counter offset
71+
ID is from 1 to 3 */
72+
73+
/* TTC counter control masks */
74+
#define XTTCPS_CNT_CNTRL_RST_MASK 0x10U /* TTC counter constrol reset mask */
75+
#define XTTCPS_CNT_CNTRL_DIS_MASK 0x01U /* TTC counter control disable mask */
76+
77+
#define LPRINTF(format, ...) \
78+
xil_printf("\r\nSERVER> " format, ##__VA_ARGS__)
79+
80+
#define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__)
81+
82+
extern struct metal_device *ipi_dev; /* IPI metal device */
83+
extern struct metal_device *shm_dev; /* IPI metal device */
84+
extern struct metal_device *ttc_dev; /* IPI metal device */
85+
86+
/**
87+
* @brief atomic_shmem_demod() - Shared memory atomic operation demo
88+
* This task will:
89+
* * Wait for the remote to write to shared memory.
90+
* * Once it receives the notification via polling, start atomic add by
91+
* 1 for 1000 times to first 32 bits of memory in the
92+
* shared memory location at 3ed00000 which is pointed to by shm_io.
93+
* * Write to shared mem to notify the remote once it finishes
94+
* calculation.
95+
*
96+
* @return - If setup failed, return the corresponding error number. Otherwise
97+
* return 0 on success.
98+
*/
99+
int atomic_shmem_demod();
100+
101+
/**
102+
* @brief ipi_latency_demod() - Show performance of IPI with Libmetal.
103+
* Loop until APU tells RPU to stop via shared memory.
104+
* In loop, wait for interrupt (interrupt handler stops APU to
105+
* RPU timer). Then reset count on RPU to APU timer to 0, start
106+
* counting and send interrupt to notify APU.
107+
*
108+
* @return - 0 on success, error code if failure.
109+
*/
110+
int ipi_latency_demod();
111+
112+
/**
113+
* @brief ipi_shmem_demod() - shared memory IPI demo
114+
* This task will:
115+
* * Wait for IPI interrupt from the remote
116+
* * Once it received the interrupt, copy the content from
117+
* the ping buffer to the pong buffer.
118+
* * Update the shared memory descriptor for the new available
119+
* pong buffer.
120+
* * Trigger IPI to notifty the remote.
121+
*
122+
* @return - 0 on success, error code if failure.
123+
*/
124+
int ipi_shmem_demod();
125+
126+
/**
127+
* @brief shmem_demod() - Show use of shared memory with Libmetal.
128+
* Until KEEP_GOING signal is stopped, keep looping.
129+
* In the loop, read message from remote, add one to message and
130+
* then respond. After the loop, cleanup resources.
131+
*
132+
* @return - return 0 on success, otherwise return error number indicating
133+
* type of error
134+
*/
135+
int shmem_demod();
136+
137+
/**
138+
* @brief shmem_latency_demod() - Show performance of shared mem.
139+
* Loop until APU tells RPU to stop via shared memory.
140+
* In loop, wait for interrupt (interrupt handler stops APU to
141+
* RPU timer). Then reset count on RPU to APU timer to 0, start
142+
* counting and send interrupt to notify APU.
143+
*
144+
* @return - 0 on success, error code if failure.
145+
*/
146+
int shmem_latency_demod();
147+
148+
/**
149+
* @brief shmem_throughput_demod() - Show throughput of shared mem.
150+
* At signal of remote, record total time to do block read and write
151+
* operation Loop until APU tells RPU to stop via shared memory.
152+
* In loop, wait for interrupt (interrupt handler stops APU to
153+
* RPU timer). Then reset count on RPU to APU timer to 0, start
154+
* counting and send interrupt to notify APU.
155+
*
156+
* @return - 0 on success, error code if failure.
157+
*/
158+
int shmem_throughput_demod();
159+
160+
inline void wait_for_interrupt()
161+
{
162+
asm volatile("wfi");
163+
}
164+
165+
/**
166+
* @breif wait_for_notified() - Loop until notified bit
167+
* in channel is set.
168+
*
169+
* @param[in] notified - pointer to the notified variable
170+
*/
171+
inline void wait_for_notified(atomic_int *notified)
172+
{
173+
unsigned int flags;
174+
175+
do {
176+
flags = metal_irq_save_disable();
177+
if (!atomic_flag_test_and_set(notified)) {
178+
metal_irq_restore_enable(flags);
179+
break;
180+
}
181+
wait_for_interrupt();
182+
metal_irq_restore_enable(flags);
183+
} while(1);
184+
}
185+
186+
/**
187+
* @brief print_demo() - print demo string
188+
*
189+
* @param[in] name - demo name
190+
*/
191+
inline void print_demo(char *name)
192+
{
193+
LPRINTF("====== libmetal demo: %s ======\n", name);
194+
}
195+
196+
#endif /* __COMMON_H__ */
197+

0 commit comments

Comments
 (0)