summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 420fa3f)
raw | patch | inline | side by side (parent: 420fa3f)
author | Sam Sortais <sam.sortais@xilinx.com> | |
Fri, 27 Jan 2017 03:17:32 +0000 (19:17 -0800) | ||
committer | Wendy Liang <jliang@xilinx.com> | |
Wed, 8 Feb 2017 05:18:50 +0000 (21:18 -0800) |
fix apps logic in main to return proper value
fix rpc_demo buffer initialization when calling rpmsg_retarget_send
reformat code and add debug prints
Signed-off-by: Sam Sortais <sam.sortais@xilinx.com>
Signed-off-by: Wendy Liang <jliang@xilinx.com>
fix rpc_demo buffer initialization when calling rpmsg_retarget_send
reformat code and add debug prints
Signed-off-by: Sam Sortais <sam.sortais@xilinx.com>
Signed-off-by: Wendy Liang <jliang@xilinx.com>
apps/echo_test/echo_testd.c | patch | blob | history | |
apps/matrix_multiply/matrix_multiplyd.c | patch | blob | history | |
apps/rpc_demo/rpc_demo.c | patch | blob | history |
index 14971e428ef14975c8c77dc6c57ac4c10e656b54..9c1cec14a62a3b58ad79ef61865b07395b822eb2 100644 (file)
This application is meant to run on the remote CPU running baremetal code.
This application echoes back data that was sent to it by the master core. */
-#include "rsc_table.h"
#include <stdio.h>
+#include "openamp/open_amp.h"
+#include "rsc_table.h"
+#include "platform_info.h"
#define SHUTDOWN_MSG 0xEF56A55A
#define REMOTE_RESETTING 1
#define REMOTE_RESETTED 2
-/* Internal functions */
-static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl);
-static void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl);
-static void rpmsg_read_cb(struct rpmsg_channel *, void *, int, void *,
- unsigned long);
-static void virtio_rst_cb(struct hil_proc *hproc, int id);
+/* External functions */
+extern int init_system(void);
+extern void cleanup_system(void);
/* Globals */
static struct rpmsg_endpoint *rp_ept;
static int evt_chnl_deleted = 0;
static int remote_proc_state;
-/* External functions */
-extern void init_system(void);
-extern void cleanup_system(void);
-extern struct hil_proc *platform_create_proc(int proc_index);
-extern void *get_resource_table (int rsc_id, int *len);
-
static void virtio_rst_cb(struct hil_proc *hproc, int id)
{
/* hil_proc only supports single virtio device */
LPRINTF("RPMsg resetted\n");
}
+static void rpmsg_read_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
+ void *priv, unsigned long src)
+{
+ (void)priv;
+ (void)src;
+
+ if ((*(unsigned int *)data) == SHUTDOWN_MSG) {
+ evt_chnl_deleted = 1;
+ return;
+ }
+
+ /* Send data back to master */
+ rpmsg_send(rp_chnl, data, len);
+}
+
+static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl)
+{
+ rp_ept = rpmsg_create_ept(rp_chnl, rpmsg_read_cb, RPMSG_NULL,
+ RPMSG_ADDR_ANY);
+}
+
+static void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl)
+{
+ (void)rp_chnl;
+
+ rpmsg_destroy_ept(rp_ept);
+ rp_ept = NULL;
+ evt_chnl_deleted = 1;
+}
+
/* Application entry point */
int app(struct hil_proc *hproc)
{
int status = 0;
- //rsc_info.rsc_tab = (struct resource_table *)&resources;
- //rsc_info.size = sizeof(resources);
-
/* Initialize RPMSG framework */
LPRINTF("Try to init remoteproc resource\n");
status =
out:
/* disable interrupts and free resources */
+ LPRINTF("De-initializating remoteproc resource\n");
remoteproc_resource_deinit(proc);
cleanup_system();
return 0;
}
-static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl)
-{
- rp_ept = rpmsg_create_ept(rp_chnl, rpmsg_read_cb, RPMSG_NULL,
- RPMSG_ADDR_ANY);
-}
-
-static void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl)
-{
- (void)rp_chnl;
-
- rpmsg_destroy_ept(rp_ept);
- rp_ept = NULL;
- evt_chnl_deleted = 1;
-}
-
-static void rpmsg_read_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
- void *priv, unsigned long src)
-{
- (void)priv;
- (void)src;
-
- if ((*(unsigned int *)data) == SHUTDOWN_MSG) {
- evt_chnl_deleted = 1;
- return;
- }
-
- /* Send data back to master */
- rpmsg_send(rp_chnl, data, len);
-}
-
int main(int argc, char *argv[])
{
unsigned long proc_id = 0;
unsigned long rsc_id = 0;
struct hil_proc *hproc;
+ int status = -1;
+
+ LPRINTF("Starting application...\n");
/* Initialize HW system components */
init_system();
hproc = platform_create_proc(proc_id);
if (!hproc) {
- LPRINTF("Failed to create proc platform data.\n");
- return -1;
- }
- rsc_info.rsc_tab = get_resource_table(
- (int)rsc_id, &rsc_info.size);
- if (!rsc_info.rsc_tab) {
- LPRINTF("Failed to get resource table data.\n");
- return -1;
+ LPERROR("Failed to create proc platform data.\n");
+ } else {
+ rsc_info.rsc_tab = get_resource_table(
+ (int)rsc_id, &rsc_info.size);
+ if (!rsc_info.rsc_tab) {
+ LPERROR("Failed to get resource table data.\n");
+ } else {
+ status = app(hproc);
+ }
}
- return app(hproc);
+ return status;
}
index ded3ff7283be3314be2e6332a38f576094407dd4..15827eba1f8bf688745e4f5881c1d5f575267999 100644 (file)
#include <string.h>
#include "openamp/open_amp.h"
#include "rsc_table.h"
+#include "platform_info.h"
-#define MAX_SIZE 6
-#define NUM_MATRIX 2
-#define SHUTDOWN_MSG 0xEF56A55A
+#define MAX_SIZE 6
+#define NUM_MATRIX 2
+
+#define SHUTDOWN_MSG 0xEF56A55A
//#define LPRINTF(format, ...) printf(format, ##__VA_ARGS__)
#define LPRINTF(format, ...)
unsigned int elements[MAX_SIZE][MAX_SIZE];
} matrix;
-/* Internal functions */
-static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl);
-static void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl);
-static void rpmsg_read_cb(struct rpmsg_channel *, void *, int, void *,
- unsigned long);
-static void Matrix_Multiply(const matrix * m, const matrix * n, matrix * r);
-
-/* Globals */
-static struct rpmsg_channel *app_rp_chnl;
-static struct rpmsg_endpoint *rp_ept;
+/* Local variables */
static matrix matrix_array[NUM_MATRIX];
static matrix matrix_result;
+
+static struct rpmsg_endpoint *rp_ept;
static struct remote_proc *proc = NULL;
static struct rsc_table_info rsc_info;
-static int evt_chnl_deleted = 0;
-extern struct hil_proc *platform_create_proc(int proc_index);
-extern void *get_resource_table (int rsc_id, int *len);
+static int evt_chnl_deleted = 0;
/* External functions */
-extern void init_system();
-extern void cleanup_system();
+extern int init_system(void);
+extern void cleanup_system(void);
-/* Application entry point */
-int app (struct hil_proc *hproc)
+/*-----------------------------------------------------------------------------*
+ * Calculate the Matrix
+ *-----------------------------------------------------------------------------*/
+static void Matrix_Multiply(const matrix *m, const matrix *n, matrix *r)
{
+ unsigned int i, j, k;
- int status = 0;
+ memset(r, 0x0, sizeof(matrix));
+ r->size = m->size;
- /* Initialize RPMSG framework */
- status =
- remoteproc_resource_init(&rsc_info, hproc,
- rpmsg_channel_created,
- rpmsg_channel_deleted, rpmsg_read_cb,
- &proc, 0);
- if (RPROC_SUCCESS != status) {
- return -1;
+ for (i = 0; i < m->size; ++i) {
+ for (j = 0; j < n->size; ++j) {
+ for (k = 0; k < r->size; ++k) {
+ r->elements[i][j] +=
+ m->elements[i][k] * n->elements[k][j];
+ }
+ }
}
+}
- do {
- hil_poll(proc->proc, 0);
- } while (!evt_chnl_deleted);
+/*-----------------------------------------------------------------------------*
+ * RPMSG callbacks setup by remoteproc_resource_init()
+ *-----------------------------------------------------------------------------*/
+static void rpmsg_read_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
+ void *priv, unsigned long src)
+{
+ (void)priv;
+ (void)src;
- remoteproc_resource_deinit(proc);
- cleanup_system();
+ if ((*(unsigned int *)data) == SHUTDOWN_MSG) {
+ evt_chnl_deleted = 1;
+ return;
+ }
- return 0;
-}
+ memcpy(matrix_array, data, len);
+ /* Process received data and multiple matrices. */
+ Matrix_Multiply(&matrix_array[0], &matrix_array[1], &matrix_result);
+ /* Send the result of matrix multiplication back to master. */
+ if (RPMSG_SUCCESS !=
+ rpmsg_send(rp_chnl, &matrix_result, sizeof(matrix))) {
+ LPERROR("rpmsg_send failed\n");
+ }
+}
static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl)
{
- app_rp_chnl = rp_chnl;
rp_ept = rpmsg_create_ept(rp_chnl, rpmsg_read_cb, RPMSG_NULL,
RPMSG_ADDR_ANY);
}
rpmsg_destroy_ept(rp_ept);
rp_ept = NULL;
- app_rp_chnl = NULL;
}
-static void rpmsg_read_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
- void *priv, unsigned long src)
+int app(struct hil_proc *hproc)
{
- (void)rp_chnl;
- (void)priv;
- (void)src;
+ int status = 0;
- if ((*(unsigned int *)data) == SHUTDOWN_MSG) {
- evt_chnl_deleted = 1;
- } else {
- memcpy(matrix_array, data, len);
- /* Process received data and multiple matrices. */
- Matrix_Multiply(&matrix_array[0], &matrix_array[1],
- &matrix_result);
+ /* Initialize framework */
+ LPRINTF("Try to init remoteproc resource\n");
+ status = remoteproc_resource_init(&rsc_info, hproc,
+ rpmsg_channel_created,
+ rpmsg_channel_deleted, rpmsg_read_cb,
+ &proc, 0);
- /* Send the result of matrix multiplication back to master. */
- rpmsg_send(app_rp_chnl, &matrix_result, sizeof(matrix));
+ if (RPROC_SUCCESS != status) {
+ LPERROR("Failed to initialize remoteproc resource.\n");
+ return -1;
}
-}
-static void Matrix_Multiply(const matrix * m, const matrix * n, matrix * r)
-{
- unsigned int i, j, k;
+ LPRINTF("Init remoteproc resource done\n");
- memset(r, 0x0, sizeof(matrix));
- r->size = m->size;
+ LPRINTF("Waiting for events...\n");
+ do {
+ hil_poll(proc->proc, 0);
+ } while (!evt_chnl_deleted);
- for (i = 0; i < m->size; ++i) {
- for (j = 0; j < n->size; ++j) {
- for (k = 0; k < r->size; ++k) {
- r->elements[i][j] +=
- m->elements[i][k] * n->elements[k][j];
- }
- }
- }
+ /* disable interrupts and free resources */
+ LPRINTF("De-initializating remoteproc resource\n");
+ remoteproc_resource_deinit(proc);
+
+ return 0;
}
+/*-----------------------------------------------------------------------------*
+ * Application entry point
+ *-----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
unsigned long proc_id = 0;
unsigned long rsc_id = 0;
struct hil_proc *hproc;
+ int status = -1;
+
+ LPRINTF("Starting application...\n");
/* Initialize HW system components */
init_system();
hproc = platform_create_proc(proc_id);
if (!hproc) {
LPERROR("Failed to create hil proc.\n");
- return -1;
- }
- rsc_info.rsc_tab = get_resource_table(
- (int)rsc_id, &rsc_info.size);
- if (!rsc_info.rsc_tab) {
- LPRINTF("Failed to get resource table data.\n");
- return -1;
+ } else {
+ rsc_info.rsc_tab =
+ get_resource_table((int)rsc_id, &rsc_info.size);
+ if (!rsc_info.rsc_tab) {
+ LPERROR("Failed to get resource table data.\n");
+ } else {
+ status = app(hproc);
+ }
}
- return app(hproc);
-}
+ LPRINTF("Stopping application...\n");
+
+ cleanup_system();
+ return status;
+}
index b6354832a01034f43bc2618969e2b7558fb17dd7..3d943ee7a12fee2ad79eb53b3c672f4a63a26f9f 100755 (executable)
--- a/apps/rpc_demo/rpc_demo.c
+++ b/apps/rpc_demo/rpc_demo.c
#include <fcntl.h>
#include <unistd.h>
#include "openamp/open_amp.h"
-#include "rsc_table.h"
#include "openamp/rpmsg_retarget.h"
-
-/* Internal functions */
-static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl);
-static void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl);
-static void rpmsg_read_cb(struct rpmsg_channel *, void *, int, void *,
- unsigned long);
-static void shutdown_cb(struct rpmsg_channel *rp_chnl);
-
-/* Globals */
-static struct rpmsg_channel *app_rp_chnl;
-static volatile int chnl_is_alive = 0;
-static struct remote_proc *proc = NULL;
-static struct rsc_table_info rsc_info;
-
-/* External functions */
-extern void init_system();
-extern void cleanup_system();
-extern struct hil_proc *platform_create_proc(int proc_index);
-extern void *get_resource_table (int rsc_id, int *len);
+#include "rsc_table.h"
+#include "platform_info.h"
#define REDEF_O_CREAT 100
#define REDEF_O_EXCL 200
#define LPRINTF(format, ...)
#define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__)
-/* Application entry point */
+/* Global functions and variables */
+extern int init_system(void);
+extern void cleanup_system(void);
+
+/* Local variables */
+static struct rpmsg_channel *app_rp_chnl;
+static volatile int chnl_is_alive = 0;
+static struct remote_proc *proc = NULL;
+static struct rsc_table_info rsc_info;
+
+/*-----------------------------------------------------------------------------*
+ * RPMSG callbacks setup by remoteproc_resource_init()
+ *-----------------------------------------------------------------------------*/
+static void rpmsg_read_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
+ void *priv, unsigned long src)
+{
+ (void)rp_chnl;
+ (void)data;
+ (void)len;
+ (void)priv;
+ (void)src;
+}
+
+static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl)
+{
+ app_rp_chnl = rp_chnl;
+ chnl_is_alive = 1;
+}
+
+static void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl)
+{
+ (void)rp_chnl;
+ app_rp_chnl = NULL;
+}
+
+static void shutdown_cb(struct rpmsg_channel *rp_chnl)
+{
+ (void)rp_chnl;
+ chnl_is_alive = 0;
+}
+
+/*-----------------------------------------------------------------------------*
+ * Application specific
+ *-----------------------------------------------------------------------------*/
int app (struct hil_proc *hproc)
{
int fd, bytes_written, bytes_read;
int ret;
int status;
- /* Initialize RPMSG framework */
+ /* Initialize framework */
+ LPRINTF("Try to init remoteproc resource\n");
status = remoteproc_resource_init(&rsc_info, hproc,
rpmsg_channel_created,
rpmsg_channel_deleted, rpmsg_read_cb,
&proc, 0);
if (RPROC_SUCCESS != status) {
+ LPERROR("Failed to initialize remoteproc resource.\n");
return -1;
}
+ LPRINTF("Init remoteproc resource done\n");
+
+ LPRINTF("Waiting for channel creation...\n");
while (!chnl_is_alive) {
hil_poll(proc->proc, 0);
}
/* redirect I/Os */
+ LPRINTF("Initializating I/Os redirection...\n");
rpmsg_retarget_init(app_rp_chnl, shutdown_cb);
printf("\r\nRemote>Baremetal Remote Procedure Call (RPC) Demonstration\r\n");
bytes_read = read(fd, rbuff, 1024);
*(char *)(&rbuff[0] + bytes_read + 1) = 0;
printf("\r\nRemote>Read from fd = %d, size = %d, printing contents below .. %s\r\n",
- fd, bytes_read, rbuff);
+ fd, bytes_read, rbuff);
close(fd);
printf("\r\nRemote>Closed fd = %d\r\n", fd);
ret = scanf("%f", &fdata);
if (ret) {
printf("\r\nRemote>User name = '%s'\r\n", ubuff);
- printf("\r\nRemote>User age = '%d'\r\n", idata);
+ printf("\r\nRemote>User age = '%d'\r\n",
+ idata);
printf("\r\nRemote>User entered value of pi = '%f'\r\n", fdata);
}
}
printf("\r\nRemote>Invalid option. Starting again....\r\n");
} else if ((!strcmp(ubuff, "no"))) {
printf("\r\nRemote>RPC retargetting quitting ...\r\n");
- sprintf(wbuff, RPC_CHANNEL_READY_TO_CLOSE);
break;
}
}
printf("\r\nRemote> Firmware's rpmsg-openamp-demo-channel going down! \r\n");
+ sprintf(wbuff, RPC_CHANNEL_READY_TO_CLOSE);
rpmsg_retarget_send(wbuff, sizeof (RPC_CHANNEL_READY_TO_CLOSE) + 1);
- while (chnl_is_alive)
+ LPRINTF("Waiting for channel deletion...\n");
+ while (chnl_is_alive) {
hil_poll(proc->proc, 0);
+ }
+ LPRINTF("De-initializating rpmsg_retarget\n");
rpmsg_retarget_deinit(app_rp_chnl);
+ /* disable interrupts and free resources */
+ LPRINTF("De-initializating remoteproc resource\n");
remoteproc_resource_deinit(proc);
- cleanup_system();
- return 0;
-}
-
-static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl)
-{
- app_rp_chnl = rp_chnl;
- chnl_is_alive = 1;
-}
-
-static void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl)
-{
- (void)rp_chnl;
- app_rp_chnl = NULL;
-}
-
-static void rpmsg_read_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
- void *priv, unsigned long src)
-{
- (void)rp_chnl;
- (void)data;
- (void)len;
- (void)priv;
- (void)src;
-}
-static void shutdown_cb(struct rpmsg_channel *rp_chnl)
-{
- (void)rp_chnl;
- chnl_is_alive = 0;
+ return 0;
}
+/*-----------------------------------------------------------------------------*
+ * Application entry point
+ *-----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
unsigned long proc_id = 0;
unsigned long rsc_id = 0;
struct hil_proc *hproc;
+ int status = -1;
+
+ LPRINTF("Starting application...\n");
/* Initialize HW system components */
init_system();
hproc = platform_create_proc(proc_id);
if (!hproc) {
LPERROR("Failed to create hil proc.\n");
- return -1;
- }
- rsc_info.rsc_tab = get_resource_table(
- (int)rsc_id, &rsc_info.size);
- if (!rsc_info.rsc_tab) {
- LPRINTF("Failed to get resource table data.\n");
- return -1;
+ } else {
+ rsc_info.rsc_tab =
+ get_resource_table((int)rsc_id, &rsc_info.size);
+ if (!rsc_info.rsc_tab) {
+ LPERROR("Failed to get resource table data.\n");
+ } else {
+ status = app(hproc);
+ }
}
- return app(hproc);
+
+ LPRINTF("Stopping application...\n");
+
+ cleanup_system();
+ return status;
}