99450fbbd2122d703399e214a84fa48070281713
[processor-sdk/open-amp.git] / apps / echo_test / echo_testd.c
1 /* This is a sample demonstration application that showcases usage of rpmsg 
2 This application is meant to run on the remote CPU running baremetal code. 
3 This application echoes back data that was sent to it by the master core. */
5 #include "rsc_table.h"
6 #include "platform_info.h"
8 #define SHUTDOWN_MSG    0xEF56A55A
10 /* Internal functions */
11 static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl);
12 static void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl);
13 static void rpmsg_read_cb(struct rpmsg_channel *, void *, int, void *,
14                           unsigned long);
16 /* Globals */
17 static struct rpmsg_endpoint *rp_ept;
18 static struct remote_proc *proc = NULL;
19 static struct rsc_table_info rsc_info;
20 static int evt_chnl_deleted = 0;
21 extern const struct remote_resource_table resources;
22 extern struct rproc_info_plat_local proc_table;
24 /* External functions */
25 extern void init_system(void);
26 extern void cleanup_system(void);
28 /* Application entry point */
29 int main(void)
30 {
31         int status = 0;
33         /* Initialize HW system components */
34         init_system();
36         rsc_info.rsc_tab = (struct resource_table *)&resources;
37         rsc_info.size = sizeof(resources);
39         /* Initialize RPMSG framework */
40         status =
41             remoteproc_resource_init(&rsc_info, &proc_table,
42                                      rpmsg_channel_created,
43                                      rpmsg_channel_deleted, rpmsg_read_cb,
44                                      &proc, 0);
46         if (RPROC_SUCCESS != status) {
47                 return -1;
48         }
50         do {
51                 hil_poll(proc->proc, 0);
52         } while (!evt_chnl_deleted);
54         /* disable interrupts and free resources */
55         remoteproc_resource_deinit(proc);
57         cleanup_system();
59         return 0;
60 }
62 static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl)
63 {
64         rp_ept = rpmsg_create_ept(rp_chnl, rpmsg_read_cb, RPMSG_NULL,
65                                   RPMSG_ADDR_ANY);
66 }
68 static void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl)
69 {
70         (void)rp_chnl;
72         rpmsg_destroy_ept(rp_ept);
73         rp_ept = NULL;
74 }
76 static void rpmsg_read_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
77                           void *priv, unsigned long src)
78 {
79         (void)priv;
80         (void)src;
82         if ((*(unsigned int *)data) == SHUTDOWN_MSG) {
83                 evt_chnl_deleted = 1;
84                 return;
85         } 
87         /* Send data back to master */
88         rpmsg_send(rp_chnl, data, len);
89 }