Skip to content

Commit a138c88

Browse files
sumanannaandersson
authored andcommitted
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> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
1 parent 211e3a9 commit a138c88

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

samples/rpmsg/rpmsg_client_sample.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,24 @@
2424
#define MSG "hello world!"
2525
#define MSG_LIMIT 100
2626

27+
struct instance_data {
28+
int rx_count;
29+
};
30+
2731
static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len,
2832
void *priv, u32 src)
2933
{
3034
int ret;
31-
static int rx_count;
35+
struct instance_data *idata = dev_get_drvdata(&rpdev->dev);
3236

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);
3439

3540
print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1,
3641
data, len, true);
3742

3843
/* samples should not live forever */
39-
if (rx_count >= MSG_LIMIT) {
44+
if (idata->rx_count >= MSG_LIMIT) {
4045
dev_info(&rpdev->dev, "goodbye!\n");
4146
return;
4247
}
@@ -50,10 +55,17 @@ static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len,
5055
static int rpmsg_sample_probe(struct rpmsg_channel *rpdev)
5156
{
5257
int ret;
58+
struct instance_data *idata;
5359

5460
dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
5561
rpdev->src, rpdev->dst);
5662

63+
idata = devm_kzalloc(&rpdev->dev, sizeof(*idata), GFP_KERNEL);
64+
if (!idata)
65+
return -ENOMEM;
66+
67+
dev_set_drvdata(&rpdev->dev, idata);
68+
5769
/* send a message to our remote processor */
5870
ret = rpmsg_send(rpdev, MSG, strlen(MSG));
5971
if (ret) {

0 commit comments

Comments
 (0)