.. | .. |
---|
6 | 6 | * Author: Hongming Zou <hongming.zou@rock-chips.com> |
---|
7 | 7 | */ |
---|
8 | 8 | |
---|
| 9 | +#include <linux/delay.h> |
---|
9 | 10 | #include <linux/kernel.h> |
---|
10 | 11 | #include <linux/module.h> |
---|
11 | 12 | #include <linux/rpmsg.h> |
---|
12 | 13 | #include <linux/rpmsg/rockchip_rpmsg.h> |
---|
| 14 | +#include <linux/time.h> |
---|
13 | 15 | #include <linux/virtio.h> |
---|
14 | 16 | |
---|
15 | 17 | #define LINUX_TEST_MSG_1 "Announce master ept id!" |
---|
16 | 18 | #define LINUX_TEST_MSG_2 "Rockchip rpmsg linux test pingpong!" |
---|
17 | | -#define MSG_LIMIT 100 |
---|
| 19 | +#define MSG_LIMIT 10000 |
---|
18 | 20 | |
---|
19 | | -struct instance_data { |
---|
| 21 | +/* different processor cores may need to adjust the value of this definition */ |
---|
| 22 | +#define LINUX_RPMSG_COMPENSATION (1) //ms |
---|
| 23 | + |
---|
| 24 | +struct rpmsg_info_t { |
---|
20 | 25 | int rx_count; |
---|
21 | 26 | }; |
---|
22 | 27 | |
---|
.. | .. |
---|
25 | 30 | { |
---|
26 | 31 | int ret; |
---|
27 | 32 | uint32_t remote_ept_id; |
---|
28 | | - struct instance_data *idata = dev_get_drvdata(&rp->dev); |
---|
| 33 | + struct rpmsg_info_t *info = dev_get_drvdata(&rp->dev); |
---|
29 | 34 | |
---|
30 | 35 | remote_ept_id = src; |
---|
31 | 36 | dev_info(&rp->dev, "rx msg %s rx_count %d(remote_ept_id: 0x%x)\n", |
---|
32 | | - (char *)payload, ++idata->rx_count, remote_ept_id); |
---|
| 37 | + (char *)payload, ++info->rx_count, remote_ept_id); |
---|
33 | 38 | |
---|
34 | 39 | /* test should not live forever */ |
---|
35 | | - if (idata->rx_count >= MSG_LIMIT) { |
---|
| 40 | + if (info->rx_count >= MSG_LIMIT) { |
---|
36 | 41 | dev_info(&rp->dev, "Rockchip rpmsg test exit!\n"); |
---|
37 | 42 | return 0; |
---|
38 | 43 | } |
---|
39 | 44 | |
---|
| 45 | + mdelay(LINUX_RPMSG_COMPENSATION); |
---|
40 | 46 | /* send a new message now */ |
---|
41 | 47 | ret = rpmsg_sendto(rp->ept, LINUX_TEST_MSG_2, strlen(LINUX_TEST_MSG_2), remote_ept_id); |
---|
42 | 48 | if (ret) |
---|
.. | .. |
---|
48 | 54 | { |
---|
49 | 55 | int ret; |
---|
50 | 56 | uint32_t master_ept_id, remote_ept_id; |
---|
51 | | - struct instance_data *idata; |
---|
| 57 | + struct rpmsg_info_t *info; |
---|
52 | 58 | |
---|
53 | 59 | master_ept_id = rp->src; |
---|
54 | 60 | remote_ept_id = rp->dst; |
---|
55 | 61 | dev_info(&rp->dev, "new channel: 0x%x -> 0x%x!\n", master_ept_id, remote_ept_id); |
---|
56 | 62 | |
---|
57 | | - idata = devm_kzalloc(&rp->dev, sizeof(*idata), GFP_KERNEL); |
---|
58 | | - if (!idata) |
---|
| 63 | + info = devm_kzalloc(&rp->dev, sizeof(*info), GFP_KERNEL); |
---|
| 64 | + if (!info) |
---|
59 | 65 | return -ENOMEM; |
---|
60 | 66 | |
---|
61 | | - dev_set_drvdata(&rp->dev, idata); |
---|
| 67 | + dev_set_drvdata(&rp->dev, info); |
---|
62 | 68 | |
---|
63 | 69 | /* |
---|
64 | 70 | * send a message to our remote processor, and tell remote |
---|
.. | .. |
---|
69 | 75 | dev_err(&rp->dev, "rpmsg_send failed: %d\n", ret); |
---|
70 | 76 | return ret; |
---|
71 | 77 | } |
---|
72 | | - |
---|
| 78 | + mdelay(LINUX_RPMSG_COMPENSATION); |
---|
73 | 79 | ret = rpmsg_sendto(rp->ept, LINUX_TEST_MSG_2, strlen(LINUX_TEST_MSG_2), remote_ept_id); |
---|
74 | 80 | if (ret) { |
---|
75 | 81 | dev_err(&rp->dev, "rpmsg_send failed: %d\n", ret); |
---|
.. | .. |
---|
86 | 92 | |
---|
87 | 93 | static struct rpmsg_device_id rockchip_rpmsg_test_id_table[] = { |
---|
88 | 94 | { .name = "rpmsg-ap3-ch0" }, |
---|
| 95 | + { .name = "rpmsg-mcu0-test" }, |
---|
89 | 96 | { /* sentinel */ }, |
---|
90 | 97 | }; |
---|
91 | 98 | |
---|