【Xilinx】基于MPSoC的OpenAMP实现(二)

本文以前文基于MPSoC的OpenAMP实现测试为基线,介绍如何修改定制相关程序。首先讲述查找echo_test源代码,接着说明创建自己的app,包括新建app和编译代码,编译可采用petalinux - build或创建sdk编译,最后提及需要注意的地方,后续还将讲如何修改image_echo_test。

前言

参考前文
【Xilinx】基于MPSoC的OpenAMP实现(一)

在上一篇文章里面主要是采用Xilinx提供的现成的openamp.dtsi和已经编译好的image_echo_test固件、echo_test应用程序进行快速测试验证,目的是证明软件环境、硬件环境都能够正常运行OpenAMP。

以此作为基线,我们进一步研究如何修改定制image_echo_test、echo_test、openamp.dtsi,以及内部工作原理。

一、修改echo_test

1、查找源代码

首先我们先找到源代码

xlx@u16:/opt/work/p202/xilinx-zcu106-2020.2$ find . -name echo_test.c
./components/yocto/layers/meta-openamp/recipes-openamp/rpmsg-examples/rpmsg-echo-test/echo_test.c

cd ./components/yocto/layers/meta-openamp/recipes-openamp/rpmsg-examples/
xlx@u16:/opt/work/p202/xilinx-zcu106-2020.2/components/yocto/layers/meta-openamp/recipes-openamp/rpmsg-examples$ tree
.
├── rpmsg-echo-test
│   ├── echo_test.c
│   ├── LICENSE
│   └── Makefile
├── rpmsg-echo-test_1.0.bb
├── rpmsg-mat-mul
│   ├── LICENSE
│   ├── Makefile
│   └── mat_mul_demo.c
├── rpmsg-mat-mul_1.0.bb
├── rpmsg-proxy-app
│   ├── LICENSE
│   ├── Makefile
│   ├── proxy_app.c
│   └── proxy_app.h
└── rpmsg-proxy-app_1.0.bb

可以看到3个测试例子都在components/yocto/layers/meta-openamp/recipes-openamp/rpmsg-examples目录下,代码结构很简单,一个makefie加上一个c文件

Makefile如下

APP = echo_test
APP_OBJS = echo_test.o

# Add any other object files to this list below


all: $(APP)

$(APP): $(APP_OBJS)
	$(CC) $(LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS)

clean:
	rm -rf $(APP) *.o

%.o: %.c
	$(CC) -c $(CFLAGS) -o $@ $<

echo_test.c

/*
 * echo_test.c
 *
 *  Created on: Oct 4, 2014
 *      Author: etsam
 */

/*
 * Test application that data integraty of inter processor
 * communication from linux userspace to a remote software
 * context. The application sends chunks of data to the
 * remote processor. The remote side echoes the data back
 * to application which then validates the data returned.
 */

#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <time.h>
#include <fcntl.h>
#include <string.h>
#include <linux/rpmsg.h>

struct _payload {
   
   
	unsigned long num;
	unsigned long size;
	char data[];
};

static int charfd = -1, fd = -1, err_cnt;

struct _payload *i_payload;
struct _payload *r_payload;

#define RPMSG_GET_KFIFO_SIZE 1
#define RPMSG_GET_AVAIL_DATA_SIZE 2
#define RPMSG_GET_FREE_SPACE 3

#define RPMSG_HEADER_LEN 16
#define MAX_RPMSG_BUFF_SIZE (512 - RPMSG_HEADER_LEN)
#define PAYLOAD_MIN_SIZE	1
#define PAYLOAD_MAX_SIZE	(MAX_RPMSG_BUFF_SIZE - 24)
#define NUM_PAYLOADS		(PAYLOAD_MAX_SIZE/PAYLOAD_MIN_SIZE)

#define RPMSG_BUS_SYS "/sys/bus/rpmsg"

static int rpmsg_create_ept(int rpfd, struct rpmsg_endpoint_info *eptinfo)
{
   
   
	int ret;

	ret = ioctl(rpfd, RPMSG_CREATE_EPT_IOCTL, eptinfo);
	if (ret)
		perror("Failed to create endpoint.\n");
	return ret;
}

static char *get_rpmsg_ept_dev_name(const char *rpmsg_char_name,
				    const char *ept_name,
				    char *ept_dev_name)
{
   
   
	char sys_rpmsg_ept_name_path[64];
	char svc_name[64];
	char *sys_rpmsg_path = "/sys/class/rpmsg";
	FILE *fp;
	int i;
	int ept_name_len;

	for (i = 0; i < 128; i++) {
   
   
		sprintf(sys_rpmsg_ept_name_path, "%s/%s/rpmsg%d/name",
			sys_rpmsg_path, rpmsg_char_name, i);
		printf("checking %s\n", sys_rpmsg_ept_name_path);
		if (access(sys_rpmsg_ept_name_path
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值