Commit 4479855b6aadf3dc7ad69e68ed5e9b7ec1232989
1 parent
bb928e5074
Exists in
smarc-ti-linux-3.14.y
and in
1 other branch
samples/rpmsg: add support for multiple instances
The current rpmsg_client_sample is a very simple example and is not designed to handle multiple instances. Add support for multiple instances, so that the same number of pings are sent to each instance. The instances can be on one or multiple remote processors. Signed-off-by: Suman Anna <s-anna@ti.com>
Showing 1 changed file with 16 additions and 3 deletions Side-by-side Diff
samples/rpmsg/rpmsg_client_sample.c
... | ... | @@ -24,19 +24,24 @@ |
24 | 24 | #define MSG "hello world!" |
25 | 25 | #define MSG_LIMIT 100 |
26 | 26 | |
27 | +struct instance_data { | |
28 | + int rx_count; | |
29 | +}; | |
30 | + | |
27 | 31 | static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len, |
28 | 32 | void *priv, u32 src) |
29 | 33 | { |
30 | 34 | int ret; |
31 | - static int rx_count; | |
35 | + struct instance_data *idata = dev_get_drvdata(&rpdev->dev); | |
32 | 36 | |
33 | - dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n", ++rx_count, src); | |
37 | + dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n", | |
38 | + ++idata->rx_count, src); | |
34 | 39 | |
35 | 40 | print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1, |
36 | 41 | data, len, true); |
37 | 42 | |
38 | 43 | /* samples should not live forever */ |
39 | - if (rx_count >= MSG_LIMIT) { | |
44 | + if (idata->rx_count >= MSG_LIMIT) { | |
40 | 45 | dev_info(&rpdev->dev, "goodbye!\n"); |
41 | 46 | return; |
42 | 47 | } |
43 | 48 | |
... | ... | @@ -50,9 +55,17 @@ |
50 | 55 | static int rpmsg_sample_probe(struct rpmsg_channel *rpdev) |
51 | 56 | { |
52 | 57 | int ret; |
58 | + struct instance_data *idata; | |
53 | 59 | |
54 | 60 | dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n", |
55 | 61 | rpdev->src, rpdev->dst); |
62 | + | |
63 | + idata = devm_kzalloc(&rpdev->dev, sizeof(*idata), GFP_KERNEL); | |
64 | + if (!idata) { | |
65 | + dev_err(&rpdev->dev, "channel data memory allocation failed\n"); | |
66 | + return -ENOMEM; | |
67 | + } | |
68 | + dev_set_drvdata(&rpdev->dev, idata); | |
56 | 69 | |
57 | 70 | /* send a message to our remote processor */ |
58 | 71 | ret = rpmsg_send(rpdev, MSG, strlen(MSG)); |