Skip to content

Commit 46b90df

Browse files
GuEe-GUIRbb666
authored andcommitted
[dm][rpmsg] support Remote Processor Messaging (RPMSG)
Signed-off-by: GuEe-GUI <2991707448@qq.com>
1 parent ecf2409 commit 46b90df

8 files changed

Lines changed: 1042 additions & 0 deletions

File tree

components/drivers/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ rsource "led/Kconfig"
2525
rsource "input/Kconfig"
2626
rsource "mailbox/Kconfig"
2727
rsource "hwspinlock/Kconfig"
28+
rsource "rpmsg/Kconfig"
2829
rsource "phye/Kconfig"
2930
rsource "ata/Kconfig"
3031
rsource "nvme/Kconfig"
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* Copyright (c) 2006-2023, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2023-02-25 GuEe-GUI the first version
9+
*/
10+
11+
#ifndef __RPMSG_H__
12+
#define __RPMSG_H__
13+
14+
#include <rthw.h>
15+
#include <rtthread.h>
16+
17+
#include <drivers/core/dm.h>
18+
#include <drivers/core/driver.h>
19+
#include <drivers/byteorder.h>
20+
21+
#define RT_DEVICE_CTRL_RPMSG_CREATE_EPT (RT_DEVICE_CTRL_BASE(Char) + 'R' + 1)
22+
#define RT_DEVICE_CTRL_RPMSG_DESTROY_EPT (RT_DEVICE_CTRL_BASE(Char) + 'R' + 2)
23+
#define RT_DEVICE_CTRL_RPMSG_DATA_OVERWRITE (RT_DEVICE_CTRL_BASE(Char) + 'R' + 3)
24+
25+
struct rt_rpmsg_device_id
26+
{
27+
#define RT_RPMSG_NAME_SIZE 32
28+
char name[RT_RPMSG_NAME_SIZE];
29+
30+
const void *data;
31+
};
32+
33+
struct rt_rpmsg_ops;
34+
struct rt_rpmsg_endpoint;
35+
struct rt_rpmsg_endpoint_info;
36+
37+
struct rt_rpmsg_device
38+
{
39+
struct rt_device parent;
40+
41+
struct rt_rpmsg_device_id id;
42+
rt_list_t ept_nodes;
43+
struct rt_spinlock lock;
44+
45+
const struct rt_rpmsg_ops *ops;
46+
void *priv;
47+
};
48+
49+
struct rt_rpmsg_driver
50+
{
51+
struct rt_driver parent;
52+
53+
const struct rt_rpmsg_device_id *ids;
54+
55+
rt_err_t (*probe)(struct rt_rpmsg_device *rdev);
56+
rt_err_t (*remove)(struct rt_rpmsg_device *rdev);
57+
rt_err_t (*rx_callback)(struct rt_rpmsg_device *rdev,
58+
rt_uint32_t src, void *data, rt_size_t len);
59+
};
60+
61+
typedef rt_err_t (*rt_rpmsg_rx_callback)(struct rt_rpmsg_device *rdev,
62+
rt_uint32_t src, void *data, rt_size_t len);
63+
64+
struct rt_rpmsg_ops
65+
{
66+
rt_err_t (*create_endpoint)(struct rt_rpmsg_device *, struct rt_rpmsg_endpoint *,
67+
struct rt_rpmsg_endpoint_info *info);
68+
rt_err_t (*destroy_endpoint)(struct rt_rpmsg_device *, struct rt_rpmsg_endpoint *);
69+
rt_err_t (*send)(struct rt_rpmsg_device *, rt_uint32_t src, rt_uint32_t dst,
70+
const void *data, rt_size_t len, rt_int32_t timeout);
71+
};
72+
73+
struct rt_rpmsg_endpoint_info
74+
{
75+
char name[RT_RPMSG_NAME_SIZE];
76+
77+
#define RT_RPMSG_ADDR_ANY 0xffffffff
78+
rt_uint32_t src;
79+
rt_uint32_t dst;
80+
};
81+
82+
struct rt_rpmsg_endpoint
83+
{
84+
rt_list_t list;
85+
struct rt_rpmsg_device *rdev;
86+
87+
struct rt_rpmsg_endpoint_info info;
88+
rt_rpmsg_rx_callback rx_callback;
89+
90+
struct rt_spinlock lock;
91+
void *sysdata;
92+
void *priv;
93+
};
94+
95+
enum rt_rpmsg_ns_flags
96+
{
97+
RT_RPMSG_NS_CREATE = 0,
98+
RT_RPMSG_NS_DESTROY = 1,
99+
};
100+
101+
rt_packed(struct rt_rpmsg_ns_msg
102+
{
103+
char name[RT_RPMSG_NAME_SIZE];
104+
105+
#define RT_RPMSG_NS_ADDR 0x35 /* 0x35 -> 53 */
106+
rt_uint32_t addr;
107+
rt_uint32_t flags;
108+
});
109+
110+
enum
111+
{
112+
RT_RPMSG_MODE_MASTER,
113+
RT_RPMSG_MODE_SLAVE,
114+
115+
RT_RPMSG_MODE_MAX,
116+
};
117+
118+
rt_uint32_t rt_rpmsg_mode(void);
119+
120+
struct rt_rpmsg_endpoint *rt_rpmsg_create_endpoint(struct rt_rpmsg_device *,
121+
struct rt_rpmsg_endpoint_info *info, rt_rpmsg_rx_callback rx_cb);
122+
rt_err_t rt_rpmsg_destroy_endpoint(struct rt_rpmsg_device *,
123+
struct rt_rpmsg_endpoint *);
124+
struct rt_rpmsg_endpoint *rt_rpmsg_find_endpoint(struct rt_rpmsg_device *,
125+
struct rt_rpmsg_endpoint_info *info);
126+
127+
rt_err_t rt_rpmsg_send(struct rt_rpmsg_endpoint *,
128+
const void *data, rt_size_t len);
129+
rt_err_t rt_rpmsg_sendto(struct rt_rpmsg_endpoint *, rt_uint32_t dst,
130+
const void *data, rt_size_t len);
131+
132+
rt_err_t rt_rpmsg_send_wait(struct rt_rpmsg_endpoint *,
133+
const void *data, rt_size_t len, rt_int32_t timeout);
134+
rt_err_t rt_rpmsg_sendto_wait(struct rt_rpmsg_endpoint *, rt_uint32_t dst,
135+
const void *data, rt_size_t len, rt_int32_t timeout);
136+
137+
rt_err_t rt_rpmsg_driver_register(struct rt_rpmsg_driver *rdrv);
138+
rt_err_t rt_rpmsg_device_register(struct rt_rpmsg_device *rdev);
139+
140+
#define RT_RPMSG_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, rpmsg, BUILIN)
141+
142+
#endif /* __RPMSG_H__ */

components/drivers/include/rtdevice.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ extern "C" {
7979
#include "drivers/hwspinlock.h"
8080
#endif /* RT_USING_HWSPINLOCK */
8181

82+
#ifdef RT_USING_RPMSG
83+
#include "drivers/rpmsg.h"
84+
#endif /* RT_USING_RPMSG */
85+
8286
#ifdef RT_USING_BLK
8387
#include "drivers/blk.h"
8488
#endif /* RT_USING_BLK */

components/drivers/rpmsg/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
menuconfig RT_USING_RPMSG
2+
bool "Using Remote Processor Messaging (RPMSG)"
3+
select RT_USING_DEVICE_IPC
4+
select RT_USING_SYSTEM_WORKQUEUE
5+
default n
6+
7+
config RT_RPMSG_CHAR_MSG_MAX
8+
int "Char device message receive max"
9+
depends on RT_USING_RPMSG
10+
default 64
11+
12+
config RT_RPMSG_CHAR_MSG_SIZE_MAX
13+
int "Char device message size max"
14+
depends on RT_USING_RPMSG
15+
default 256
16+
17+
if RT_USING_RPMSG
18+
osource "$(SOC_DM_RPMSG_DIR)/Kconfig"
19+
endif
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from building import *
2+
3+
group = []
4+
5+
if not GetDepend(['RT_USING_RPMSG']):
6+
Return('group')
7+
8+
cwd = GetCurrentDir()
9+
CPPPATH = [cwd + '/../include']
10+
11+
src = ['rpmsg.c', 'rpmsg_char.c', 'rpmsg_ns.c']
12+
13+
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
14+
15+
Return('group')

0 commit comments

Comments
 (0)