Skip to content

Commit f8dd076

Browse files
stanislav-poborilgalak
authored andcommitted
ext: Add RPMsg-Lite
Add RPMsg-Lite version 1.2.0 to ext. Origin: RPMsg-Lite License: BSD 3-Clause URL: https://github.com/codeauroraforum/rpmsg-lite commit: 3ed2d34376a2d1ec04f59e4a89e201d820b5d5e5 Purpose: Introduction of lightweight implementation of the Remote Processor Messaging (RPMsg) protocol to Zephyr. Maintained-by: External Signed-off-by: Stanislav Poboril <[email protected]>
1 parent 16780b0 commit f8dd076

34 files changed

+7746
-0
lines changed

ext/Kconfig

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ source "ext/lib/crypto/Kconfig"
1414

1515
source "ext/lib/encoding/Kconfig"
1616

17+
source "ext/lib/ipc/Kconfig"
18+
1719
source "ext/lib/mgmt/Kconfig"
1820

1921
source "ext/debug/Kconfig"

ext/lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_subdirectory(crypto)
22
add_subdirectory(encoding)
3+
add_subdirectory(ipc)
34
add_subdirectory(mgmt)

ext/lib/ipc/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory_ifdef(IPC_RPMSG_LITE rpmsg_lite)

ext/lib/ipc/Kconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Kconfig - Shell configuration options
2+
3+
#
4+
# Copyright 2018 NXP
5+
#
6+
# SPDX-License-Identifier: Apache-2.0
7+
#
8+
9+
menu "Inter-Process Communication"
10+
11+
source "ext/lib/ipc/rpmsg_lite/Kconfig"
12+
13+
endmenu

ext/lib/ipc/rpmsg_lite/Kconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Kconfig - Shell configuration options
2+
3+
#
4+
# Copyright 2018 NXP
5+
#
6+
# SPDX-License-Identifier: Apache-2.0
7+
#
8+
9+
config IPC_RPMSG_LITE
10+
bool
11+
prompt "Enable Remote Processor Messaging Lite library"
12+
default n
13+
help
14+
Remote Processor Messaging Lite library implementation.
15+
16+
17+

ext/lib/ipc/rpmsg_lite/LICENSE

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Copyright (c) 2014-2016 Freescale Semiconductor, Inc.
2+
Copyright (c) 2014, Mentor Graphics Corporation
3+
Copyright (c) 2015 Xilinx, Inc. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification,
6+
are permitted provided that the following conditions are met:
7+
8+
o Redistributions of source code must retain the above copyright notice, this list
9+
of conditions and the following disclaimer.
10+
11+
o Redistributions in binary form must reproduce the above copyright notice, this
12+
list of conditions and the following disclaimer in the documentation and/or
13+
other materials provided with the distribution.
14+
15+
o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16+
contributors may be used to endorse or promote products derived from this
17+
software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

ext/lib/ipc/rpmsg_lite/README

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
RPMsg-Lite
2+
##########
3+
4+
Origin:
5+
https://github.com/codeauroraforum/rpmsg-lite
6+
7+
Status:
8+
1.2.0
9+
10+
Purpose:
11+
Lightweight implementation of the Remote Processor Messaging (RPMsg) protocol
12+
13+
Description:
14+
Enables asymmetric multiprocessing (AMP) on memory constrained devices like the NXP LPC54114 multicore MCU. RPMsg-Lite is a lightweight implementation of the Remote Processor Messaging (RPMsg) protocol. The RPMsg protocol defines a standardized binary interface used to communicate between multiple cores in a heterogeneous multicore system.
15+
16+
Dependencies:
17+
None
18+
19+
URL:
20+
https://github.com/codeauroraforum/rpmsg-lite
21+
22+
commit:
23+
3ed2d34376a2d1ec04f59e4a89e201d820b5d5e5
24+
25+
Maintained-by:
26+
External
27+
28+
License:
29+
SPDX-License-Identifier: BSD-3-Clause
30+
31+
License Link:
32+
https://github.com/codeauroraforum/rpmsg-lite/blob/master/LICENSE

ext/lib/ipc/rpmsg_lite/README.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
RPMsg Component
2+
===============
3+
4+
This documentation describes the RPMsg-Lite component which is a lightweight implementation of the Remote Processor Messaging (RPMsg) protocol. The RPMsg protocol defines a standardized binary interface used to communicate between multiple cores in a heterogeneous multicore system.
5+
6+
Compared to the RPMsg implementation of the Open Asymmetric Multi Processing (OpenAMP) framework (https://github.com/OpenAMP/open-amp), the RPMsg-Lite offers a code size reduction, API simplification and improved modularity. On smaller Cortex-M0+ based systems, it is recommended to use RPMsg-Lite.
7+
8+
The RPMsg-Lite is an open-source component developed by NXP Semiconductor and released under the BSD compatible license.
9+
10+
For Further documentation, please look at doxygen documentation at: https://nxpmicro.github.io/rpmsg-lite/
11+
12+
# Motivation to create RPMsg-Lite
13+
14+
There are multiple reasons why RPMsg-Lite was developed. One of them is the need for small footprint RPMsg protocol compatible communication component, another is a simplification of extensive API of OpenAMP RPMsg implementation.
15+
16+
Until recently, RPMsg protocol was not documented and its only definition was given by the Linux Kernel and legacy OpenAMP implementations. This changed with [1] which is a standardization protocol, allowing multiple different implementations to coexist and still be compatible mutually.
17+
18+
Small MCU-based systems often do not implement dynamic memory allocation. The creation of static API in RPMsg-Lite enables another reduction of resource usage. Not only the dynamic allocation adds another 5kB of code size, but also the communication is slower and less deterministic, which is a property introduced by dynamic memory. Following table shows some rough comparison data between the OpenAMP RPMsg implementation and new RPMsg-Lite implementation:
19+
20+
|Component / Configuration | Flash [B] |RAM [B] |
21+
|---------------------------------------------|-----------|---------------|
22+
|OpenAMP RPMSG / Release (reference) | 5547 | 456 + dynamic |
23+
|RPMSG-Lite / Dynamic API, Release | 3462 | 56 + dynamic |
24+
|Relative Difference [%] | ~62.4% | ~12.3% |
25+
|RPMSG-Lite / Static API (no malloc), Release | 2926 | 352 |
26+
|Relative Difference [%] | ~52.7% | ~77.2% |
27+
28+
# Implementation
29+
30+
The implementation of RPMsg-Lite can be divided into three sub-components, from which two are optional. The core component is situated in <i>rpmsg_lite.c</i>. Two optional components are used to implement a blocking receive API (in <i>rpmsg_queue.c</i>) and dynamic "named" endpoint creation and deletion announcement service (in <i>rpmsg_ns.c</i>).
31+
32+
The actual "media access" layer is implemented in <i>virtqueue.c</i>, which is one of few files shared with the OpenAMP implementation. This layer mainly defines the shared memory model and defines internally used components such as vring or virtqueue.
33+
34+
The porting layer is split into two sub-layers: the environment layer and the platform layer. The first one is to be implemented separately for each environment. (There already exist the bare-metal environment implemented in <i>env_bm.c</i> and the FreeRTOS environment implemented in <i>env_freertos.c</i> etc.) Only the source file which matches the used environment is included in the target application project. The second sublayer is implemented in <i>platform.c</i> and it defines low-level functions for interrupt enabling, disabling and triggering mainly. The situation is described in the following figure:
35+
36+
![RPMsg-Lite Architecture](./doxygen/images/rpmsg_lite_arch.png)
37+
38+
## RPMsg-Lite core sub-component
39+
40+
This sub-component implements a blocking send API and callback-based receive API. RPMsg protocol is part of the transport layer. This is realized by using so-called endpoints. Each endpoint can be assigned a different receive callback function. It is however important to notice, that the callback is executed in an interrupt environment in current design. Certain actions like memory allocation is therefore discouraged to execute in the callback. Following figure shows the role of RPMsg in an ISO/OSI-like layered model:
41+
42+
![RPMsg ISO/OSI Layered Model](./doxygen/images/rpmsg_isoosi.png)
43+
44+
## Queue sub-component (optional)
45+
46+
This sub-component is optional and it requires to implement env_*_queue() functions in the environment porting layer. It brings a blocking receive API which is common in RTOS-environments. It supports both copy and no-copy blocking receive functions.
47+
48+
## Name Service sub-component (optional)
49+
50+
This sub-component is a minimum implementation of the name service which is present in the Linux Kernel implementation of RPMsg. It allows the communicating node both to send announcements about "named" endpoint (a.k.a channel) creation or deletion and to receive these announcement taking any user-defined action in an application callback. The endpoint address used to receive name service announcements is arbitrarily fixed to be 53 (0x35).
51+
52+
# Usage
53+
54+
Your application should put the /rpmsg_lite/lib/include directory to the include path and then, in the application include either just rpmsg_lite.h header file, or optionally also rpmsg_queue.h and/or rpmsg_ns.h. Both porting sub-layers should be provided for you by NXP, but if you plan to use your own RTOS, all you need to do is to implement your own environment layer (i.e. env_myrtos.c) and to include it in the project build.
55+
56+
The initialization of the stack is done by calling the rpmsg_lite_master_init() on the master side and the rpmsg_lite_remote_init() on the remote side. This initialization function must be called prior to any RPMsg-Lite API call. After the init, it is wise to create a communication endpoint, otherwise the communication is not possible. This can be done by calling rpmsg_lite_create_ept() function. It accepts optionally a last argument, where an internal context of the endpoint is created – just in case the RL_USE_STATIC_API option is set to 1. If not, the stack calls internally env_alloc() to allocate dynamic memory for it. In case a callback-based receiving is to be used, an ISR-callback is registered to each new endpoint with user-defined callback data pointer. If a blocking receive is desired (in case of RTOS environment), rpmsg_queue_create() function must be called before calling rpmsg_lite_create_ept(). The queue handle is passed to the endpoint creation function as a callback data argument and the callback function is set to rpmsg_queue_rx_cb(). Then, it is possible to use rpmsg_queue_receive() function to listen on a queue object for incoming messages. rpmsg_lite_send() function is used to send messages to the other side.
57+
58+
The RPMsg-Lite also implements no-copy mechanisms for both sending and receiving operations. These methods require
59+
specifics that have to be considered when used in an application.
60+
61+
<b>no-copy-send mechanism:</b> This mechanism allows sending messages without the cost for copying data from the application
62+
buffer to the RPMsg/virtio buffer in the shared memory. The sequence of no-copy sending steps to be performed is as follows:
63+
- Call the rpmsg_lite_alloc_tx_buffer() function to get the virtio buffer and provide the buffer pointer to the application.
64+
- Fill the data to be sent into the pre-allocated virtio buffer. Ensure that the filled data does not exceed the buffer size
65+
(provided as the rpmsg_lite_alloc_tx_buffer() <i>size</i> output parameter).
66+
- Call the rpmsg_lite_send_nocopy() function to send the message to the destination endpoint. Consider the cache
67+
functionality and the virtio buffer alignment. See the rpmsg_lite_send_nocopy() function description below.
68+
69+
<b>no-copy-receive mechanism:</b> This mechanism allows reading messages without the cost for copying data from the virtio
70+
buffer in the shared memory to the application buffer. The sequence of no-copy receiving steps to be performed is as follows:
71+
- Call the rpmsg_queue_recv_nocopy() function to get the virtio buffer pointer to the received data.
72+
- Read received data directly from the shared memory.
73+
- Call the rpmsg_queue_nocopy_free() function to release the virtio buffer and to make it available for the next data transfer.
74+
75+
The user is responsible for destroying any RPMsg-Lite objects he has created in case of deinitialization. For this, the function rpmsg_queue_destroy() is used to destroy a queue, rpmsg_lite_destroy_ept() is used to destroy an endpoint and finally, rpmsg_lite_deinit() is used to deinitialize the RPMsg-Lite intercore communication stack. Please take care to deinitialize all endpoints using a queue before deinitializing the queue, otherwise you are invalidating actively used queue handle, which is not allowed. RPMsg-Lite does not check this internally, since its main aim is to be lightweight.
76+
77+
![RPMsg Lite copy and no-copy interface, multiple scenarios](./doxygen/images/rpmsg_lite_send_receive.png)
78+
79+
80+
# References
81+
[1] M. Novak, M. Cingel, Lockless Shared Memory Based Multicore Communication Protocol
82+
83+
---
84+
Copyright © 2016 Freescale Semiconductor, Inc.
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2014, Mentor Graphics Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of Mentor Graphics Corporation nor the names of its
14+
* contributors may be used to endorse or promote products derived from this
15+
* software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
/**************************************************************************
31+
* FILE NAME
32+
*
33+
* llist.c
34+
*
35+
* COMPONENT
36+
*
37+
* OpenAMP stack.
38+
*
39+
* DESCRIPTION
40+
*
41+
* Source file for basic linked list service.
42+
*
43+
**************************************************************************/
44+
#include "llist.h"
45+
46+
#define LIST_NULL ((void *)0)
47+
/*!
48+
* add_to_list
49+
*
50+
* Places new element at the start of the list.
51+
*
52+
* @param head - list head
53+
* @param node - new element to add
54+
*
55+
*/
56+
void add_to_list(struct llist **head, struct llist *node)
57+
{
58+
if (!node)
59+
return;
60+
61+
if (*head)
62+
{
63+
/* Place the new element at the start of list. */
64+
node->next = *head;
65+
node->prev = LIST_NULL;
66+
(*head)->prev = node;
67+
*head = node;
68+
}
69+
else
70+
{
71+
/* List is empty - assign new element to list head. */
72+
*head = node;
73+
(*head)->next = LIST_NULL;
74+
(*head)->prev = LIST_NULL;
75+
}
76+
}
77+
78+
/*!
79+
* remove_from_list
80+
*
81+
* Removes the given element from the list.
82+
*
83+
* @param head - list head
84+
* @param element - element to remove from list
85+
*
86+
*/
87+
void remove_from_list(struct llist **head, struct llist *node)
88+
{
89+
if (!(*head) || !(node))
90+
return;
91+
92+
if (node == *head)
93+
{
94+
/* First element has to be removed. */
95+
*head = (*head)->next;
96+
}
97+
else if (node->next == LIST_NULL)
98+
{
99+
/* Last element has to be removed. */
100+
node->prev->next = node->next;
101+
}
102+
else
103+
{
104+
/* Intermediate element has to be removed. */
105+
node->prev->next = node->next;
106+
node->next->prev = node->prev;
107+
}
108+
}
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2014, Mentor Graphics Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of Mentor Graphics Corporation nor the names of its
14+
* contributors may be used to endorse or promote products derived from this
15+
* software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
/**************************************************************************
31+
* FILE NAME
32+
*
33+
* llist.h
34+
*
35+
* COMPONENT
36+
*
37+
* OpenAMP stack.
38+
*
39+
* DESCRIPTION
40+
*
41+
* Header file for linked list service.
42+
*
43+
**************************************************************************/
44+
45+
#ifndef LLIST_H_
46+
#define LLIST_H_
47+
48+
struct llist
49+
{
50+
void *data;
51+
unsigned int attr;
52+
struct llist *next;
53+
struct llist *prev;
54+
};
55+
56+
void add_to_list(struct llist **head, struct llist *node);
57+
void remove_from_list(struct llist **head, struct llist *node);
58+
59+
#endif /* LLIST_H_ */

0 commit comments

Comments
 (0)