Update demo apps to use new HIL proc APIs
[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"
7 #define SHUTDOWN_MSG    0xEF56A55A
9 /* Internal functions */
10 static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl);
11 static void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl);
12 static void rpmsg_read_cb(struct rpmsg_channel *, void *, int, void *,
13                           unsigned long);
15 /* Globals */
16 static struct rpmsg_endpoint *rp_ept;
17 static struct remote_proc *proc = NULL;
18 static struct rsc_table_info rsc_info;
19 static int evt_chnl_deleted = 0;
20 extern const struct remote_resource_table resources;
22 /* External functions */
23 extern void init_system(void);
24 extern void cleanup_system(void);
25 extern struct hil_proc *platform_create_proc(int proc_index);
27 /* Application entry point */
28 int main(void)
29 {
30         int status = 0;
31         struct hil_proc *hproc;
33         /* Initialize HW system components */
34         init_system();
36         rsc_info.rsc_tab = (struct resource_table *)&resources;
37         rsc_info.size = sizeof(resources);
39         /* Create HIL proc */
40         hproc = platform_create_proc(0);
41         if (!hproc)
42                 return -1;
44         /* Initialize RPMSG framework */
45         status =
46             remoteproc_resource_init(&rsc_info, hproc,
47                                      rpmsg_channel_created,
48                                      rpmsg_channel_deleted, rpmsg_read_cb,
49                                      &proc, 0);
51         if (RPROC_SUCCESS != status) {
52                 return -1;
53         }
55         do {
56                 hil_poll(proc->proc, 0);
57         } while (!evt_chnl_deleted);
59         /* disable interrupts and free resources */
60         remoteproc_resource_deinit(proc);
62         cleanup_system();
64         return 0;
65 }
67 static void rpmsg_channel_created(struct rpmsg_channel *rp_chnl)
68 {
69         rp_ept = rpmsg_create_ept(rp_chnl, rpmsg_read_cb, RPMSG_NULL,
70                                   RPMSG_ADDR_ANY);
71 }
73 static void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl)
74 {
75         (void)rp_chnl;
77         rpmsg_destroy_ept(rp_ept);
78         rp_ept = NULL;
79 }
81 static void rpmsg_read_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
82                           void *priv, unsigned long src)
83 {
84         (void)priv;
85         (void)src;
87         if ((*(unsigned int *)data) == SHUTDOWN_MSG) {
88                 evt_chnl_deleted = 1;
89                 return;
90         } 
92         /* Send data back to master */
93         rpmsg_send(rp_chnl, data, len);
94 }