• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  * 	http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * See the Mulan PSL v2 for more details.
11  * Create: 2022-12-05
12  * Description: openamp configuration
13  */
14 
15 #include "rpmsg_backend.h"
16 
17 static struct virtio_device vdev;
18 static struct rpmsg_virtio_device rvdev;
19 static struct metal_io_region *io;
20 struct rpmsg_device *g_rdev;
21 struct rpmsg_endpoint g_ept;
22 U32 g_receivedMsg;
23 bool g_openampFlag = false;
24 #define RPMSG_ENDPOINT_NAME "console"
25 
rpmsg_service_unbind(struct rpmsg_endpoint * ep)26 void rpmsg_service_unbind(struct rpmsg_endpoint *ep)
27 {
28     rpmsg_destroy_ept(ep);
29 }
30 
send_message(unsigned char * message,int len)31 int send_message(unsigned char *message, int len)
32 {
33     return rpmsg_send(&g_ept, message, len);
34 }
35 
36 char *g_s1 = "Hello, UniProton! \r\n";
rpmsg_endpoint_cb(struct rpmsg_endpoint * ept,void * data,size_t len,uint32_t src,void * priv)37 int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, uint32_t src, void *priv)
38 {
39     g_openampFlag = true;
40     send_message((void *)g_s1, strlen(g_s1) * sizeof(char));
41 
42     return OS_OK;
43 }
44 
openamp_init(void)45 int openamp_init(void)
46 {
47     int32_t err;
48 
49     err = rpmsg_backend_init(&io, &vdev);
50     if (err) {
51         return err;
52     }
53 
54     err = rpmsg_init_vdev(&rvdev, &vdev, NULL, io, NULL);
55     if (err) {
56         return err;
57     }
58 
59     g_rdev = rpmsg_virtio_get_rpmsg_device(&rvdev);
60 
61 
62     err = rpmsg_create_ept(&g_ept, g_rdev, RPMSG_ENDPOINT_NAME,
63                            0xF, RPMSG_ADDR_ANY,
64                            rpmsg_endpoint_cb, rpmsg_service_unbind);
65     if (err) {
66         return err;
67     }
68 
69     return OS_OK;
70 }
71 
openamp_deinit(void)72 void openamp_deinit(void)
73 {
74     rpmsg_deinit_vdev(&rvdev);
75     if (io) {
76         free(io);
77     }
78 }
79 
rpmsg_service_init(void)80 int rpmsg_service_init(void)
81 {
82     int32_t err;
83     err = openamp_init();
84     if (err) {
85         return err;
86     }
87 
88     send_message((void *)&g_receivedMsg, sizeof(U32));
89 
90     while (!g_openampFlag);
91 
92     return OS_OK;
93 }
94