Update demo apps to use new HIL proc APIs
[processor-sdk/open-amp.git] / apps / func_test_suite / func_test_suite.c
1 /* This is a test application that runs baremetal code on the remote core 
2  and responds to commands from master core to test the usage of rpmsg APIs. */
4 /* Including required headers */
5 #include  <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include "openamp/open_amp.h"
9 #include "rsc_table.h"
10 #include "test_suite.h"
12 #define EPT_ADDR        59
14 /* Application provided callbacks */
15 void rpmsg_channel_created(struct rpmsg_channel *rp_chnl);
16 void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl);
17 void rpmsg_read_default_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
18                            void *pric, unsigned long src);
19 void rpmsg_read_ept_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
20                        void *pric, unsigned long src);
22 static void sleep();
24 /* Globals */
25 static volatile int intr_flag = 0;
26 static struct rpmsg_endpoint *rp_ept;
27 static struct rpmsg_channel *app_rp_chnl;
28 static unsigned int Src;
29 static unsigned int Len;
30 static char firmware_name[] = "baremetal-fn-test-suite-remote-firmware";
31 static char r_buffer[512];
32 static struct rsc_table_info rsc_info;
33 extern const struct remote_resource_table resources;
35 /* External functions */
36 extern void init_system();
37 extern void cleanup_system();
38 extern struct hil_proc *platform_create_proc(int proc_index);
40 int main()
41 {
42         struct hil_proc *proc;
43         struct remote_proc *proc;
44         int uninit = 0;
45         struct ept_cmd_data *ept_data;
47         /* Initialize HW system components */
48         init_system();
50         rsc_info.rsc_tab = (struct resource_table *)&resources;
51         rsc_info.size = sizeof(resources);
53         /* Create HIL proc */
54         hproc = platform_create_proc(0);
55         if (!hproc)
56                 return -1;
58         /* This API creates the virtio devices for this remote node and initializes
59            other relevant resources defined in the resource table */
60         remoteproc_resource_init(&rsc_info, hproc,
61                                  rpmsg_channel_created,
62                                  rpmsg_channel_deleted, rpmsg_read_default_cb,
63                                  &proc, 0);
65         for (;;) {
67                 if (intr_flag) {
68                         struct command *cmd = (struct command *)r_buffer;
69                         if (cmd->comm_start == CMD_START) {
70                                 unsigned int cm_code = cmd->comm_code;
71                                 void *data = cmd->data;
73                                 switch (cm_code) {
74                                 case CREATE_EPT:
75                                         ept_data = (struct ept_cmd_data *)data;
76                                         rp_ept =
77                                             rpmsg_create_ept(app_rp_chnl,
78                                                              rpmsg_read_ept_cb,
79                                                              RPMSG_NULL,
80                                                              ept_data->dst);
81                                         if (rp_ept) {
82                                                 /* Send data back to ack. */
83                                                 rpmsg_sendto(app_rp_chnl,
84                                                              r_buffer, Len,
85                                                              Src);
86                                         }
87                                         break;
88                                 case DELETE_EPT:
89                                         rpmsg_destroy_ept(rp_ept);
90                                         rpmsg_sendto(app_rp_chnl, r_buffer, Len,
91                                                      Src);
93                                         break;
94                                 case CREATE_CHNL:
95                                         break;
96                                 case DELETE_CHNL:
97                                         rpmsg_sendto(app_rp_chnl, r_buffer, Len,
98                                                      Src);
99                                         remoteproc_resource_deinit(proc);
100                                         uninit = 1;
101                                         break;
102                                 case QUERY_FW_NAME:
103                                         rpmsg_send(app_rp_chnl,
104                                                    &firmware_name[0],
105                                                    strlen(firmware_name) + 1);
106                                         break;
107                                 default:
108                                         rpmsg_sendto(app_rp_chnl, r_buffer, Len,
109                                                      Src);
110                                         break;
111                                 }
112                         } else {
113                                 rpmsg_sendto(app_rp_chnl, r_buffer, Len, Src);
114                         }
115                         intr_flag = 0;
116                         if (uninit)
117                                 break;
118                 }
120                 hil_poll(proc, 0);
121         }
123         cleanup_system();
124         return 0;
127 /* This callback gets invoked when the remote chanl is created */
128 void rpmsg_channel_created(struct rpmsg_channel *rp_chnl)
130         app_rp_chnl = rp_chnl;
133 /* This callback gets invoked when the remote channel is deleted */
134 void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl)
139 void rpmsg_read_default_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
140                            void *priv, unsigned long src)
142         memcpy(r_buffer, data, len);
143         Src = src;
144         Len = len;
145         intr_flag = 1;
148 void rpmsg_read_ept_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
149                        void *priv, unsigned long src)
151         rpmsg_send_offchannel(rp_chnl, rp_ept->addr, src, data, len);
154 void sleep()
156         int i;
157         for (i = 0; i < 1000; i++) ;