945817df338c8ae8c919110674dc934c5adf5083
[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"
11 #include "platform_info.h"
13 #define EPT_ADDR        59
15 /* Application provided callbacks */
16 void rpmsg_channel_created(struct rpmsg_channel *rp_chnl);
17 void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl);
18 void rpmsg_read_default_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
19                            void *pric, unsigned long src);
20 void rpmsg_read_ept_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
21                        void *pric, unsigned long src);
23 static void sleep();
25 /* Globals */
26 static volatile int intr_flag = 0;
27 static struct rpmsg_endpoint *rp_ept;
28 static struct rpmsg_channel *app_rp_chnl;
29 static unsigned int Src;
30 static unsigned int Len;
31 static char firmware_name[] = "baremetal-fn-test-suite-remote-firmware";
32 static char r_buffer[512];
33 static struct rsc_table_info rsc_info;
34 extern const struct remote_resource_table resources;
35 extern struct rproc_info_plat_local proc_table;
37 /* External functions */
38 extern void init_system();
39 extern void cleanup_system();
41 int main()
42 {
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         /* This API creates the virtio devices for this remote node and initializes
54            other relevant resources defined in the resource table */
55         remoteproc_resource_init(&rsc_info, &proc_table,
56                                  rpmsg_channel_created,
57                                  rpmsg_channel_deleted, rpmsg_read_default_cb,
58                                  &proc, 0);
60         for (;;) {
62                 if (intr_flag) {
63                         struct command *cmd = (struct command *)r_buffer;
64                         if (cmd->comm_start == CMD_START) {
65                                 unsigned int cm_code = cmd->comm_code;
66                                 void *data = cmd->data;
68                                 switch (cm_code) {
69                                 case CREATE_EPT:
70                                         ept_data = (struct ept_cmd_data *)data;
71                                         rp_ept =
72                                             rpmsg_create_ept(app_rp_chnl,
73                                                              rpmsg_read_ept_cb,
74                                                              RPMSG_NULL,
75                                                              ept_data->dst);
76                                         if (rp_ept) {
77                                                 /* Send data back to ack. */
78                                                 rpmsg_sendto(app_rp_chnl,
79                                                              r_buffer, Len,
80                                                              Src);
81                                         }
82                                         break;
83                                 case DELETE_EPT:
84                                         rpmsg_destroy_ept(rp_ept);
85                                         rpmsg_sendto(app_rp_chnl, r_buffer, Len,
86                                                      Src);
88                                         break;
89                                 case CREATE_CHNL:
90                                         break;
91                                 case DELETE_CHNL:
92                                         rpmsg_sendto(app_rp_chnl, r_buffer, Len,
93                                                      Src);
94                                         remoteproc_resource_deinit(proc);
95                                         uninit = 1;
96                                         break;
97                                 case QUERY_FW_NAME:
98                                         rpmsg_send(app_rp_chnl,
99                                                    &firmware_name[0],
100                                                    strlen(firmware_name) + 1);
101                                         break;
102                                 default:
103                                         rpmsg_sendto(app_rp_chnl, r_buffer, Len,
104                                                      Src);
105                                         break;
106                                 }
107                         } else {
108                                 rpmsg_sendto(app_rp_chnl, r_buffer, Len, Src);
109                         }
110                         intr_flag = 0;
111                         if (uninit)
112                                 break;
113                 }
115                 hil_poll(proc, 0);
116         }
118         cleanup_system();
119         return 0;
122 /* This callback gets invoked when the remote chanl is created */
123 void rpmsg_channel_created(struct rpmsg_channel *rp_chnl)
125         app_rp_chnl = rp_chnl;
128 /* This callback gets invoked when the remote channel is deleted */
129 void rpmsg_channel_deleted(struct rpmsg_channel *rp_chnl)
134 void rpmsg_read_default_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
135                            void *priv, unsigned long src)
137         memcpy(r_buffer, data, len);
138         Src = src;
139         Len = len;
140         intr_flag = 1;
143 void rpmsg_read_ept_cb(struct rpmsg_channel *rp_chnl, void *data, int len,
144                        void *priv, unsigned long src)
146         rpmsg_send_offchannel(rp_chnl, rp_ept->addr, src, data, len);
149 void sleep()
151         int i;
152         for (i = 0; i < 1000; i++) ;