Skip to content

Commit 034ec82

Browse files
committed
Merge branch 'develop' of github.com:EmbeddedRPC/erpc into feature/staticRPMSGApi
2 parents 4c625f8 + b94a617 commit 034ec82

15 files changed

Lines changed: 228 additions & 67 deletions

.github/workflows/greetings.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on: [pull_request, issues]
55
jobs:
66
greeting:
77
runs-on: ubuntu-latest
8+
permissions:
9+
issues: write
10+
pull-requests: write
811
steps:
912
- uses: actions/first-interaction@v1
1013
with:

LICENSE

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,36 @@ Copyright 2014-2016 Freescale Semiconductor, Inc.
22
Copyright 2016-2021 NXP
33
All rights reserved.
44

5-
SPDX-License-Identifier: BSD-3-Clause
5+
The BSD 3 Clause License
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
10+
1. Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
13+
2. Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
3. Neither the name of the copyright holder nor the names of its contributors
18+
may be used to endorse or promote products derived from this software without
19+
specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37+
SOFTWARE.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ To get the board list with multicore support (eRPC included) use filtering based
9292
<MCUXpressoSDK_install_dir>/boards/<board_name>/multiprocessor_examples for eRPC multiprocessor examples (UART or SPI transports used).<br>
9393
eRPC examples use 'erpc_' name prefix.
9494

95+
## References
96+
97+
This section provides links to interesting erpc-based projects, articles, blogs or guides:
98+
99+
* [erpc (EmbeddedRPC) getting started notes](https://programmersought.com/article/37585084512/)
100+
* [ERPC Linux Local Environment Construction and Use](https://programmersought.com/article/88827920353/)
101+
* [The New Wio Terminal eRPC Firmware](https://www.hackster.io/Salmanfarisvp/the-new-wio-terminal-erpc-firmware-bfd8bd)
102+
95103
## Directories
96104

97105
`doc` - Documentation.

erpc_c/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ SOURCES += $(ERPC_C_ROOT)/infra/erpc_arbitrated_client_manager.cpp \
7070
$(ERPC_C_ROOT)/setup/erpc_setup_mbf_static.cpp \
7171
$(ERPC_C_ROOT)/setup/erpc_server_setup.cpp \
7272
$(ERPC_C_ROOT)/setup/erpc_setup_serial.cpp \
73+
$(ERPC_C_ROOT)/setup/erpc_setup_tcp.cpp \
7374
$(ERPC_C_ROOT)/transports/erpc_inter_thread_buffer_transport.cpp \
7475
$(ERPC_C_ROOT)/transports/erpc_serial_transport.cpp \
7576
$(ERPC_C_ROOT)/transports/erpc_tcp_transport.cpp

erpc_c/infra/erpc_manually_constructed.h

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) 2014, Freescale Semiconductor, Inc.
33
* Copyright 2016 NXP
4+
* Copyright 2021 ACRIOS Systems s.r.o.
45
* All rights reserved.
56
*
67
*
@@ -49,53 +50,93 @@ class ManuallyConstructed
4950
public:
5051
//! @name Object access
5152
//@{
52-
T *get(void) { return reinterpret_cast<T *>(&m_storage); }
53-
const T *get(void) const { return reinterpret_cast<const T *>(&m_storage); }
53+
T *get(void) { return (m_isConstructed) ? reinterpret_cast<T *>(&m_storage) : nullptr; }
54+
const T *get(void) const { return (m_isConstructed) ? reinterpret_cast<const T *>(&m_storage) : nullptr; }
5455
T *operator->(void) { return get(); }
5556
const T *operator->(void) const { return get(); }
56-
T &operator*(void) { return *get(); }
57-
const T &operator*(void) const { return *get(); }
57+
T &operator*(void)
58+
{
59+
if (m_isConstructed)
60+
{
61+
return *get();
62+
}
63+
else
64+
{
65+
memset(&m_storage, 0, sizeof(m_storage) * 8);
66+
return reinterpret_cast<T &>(m_storage);
67+
};
68+
}
69+
const T &operator*(void) const
70+
{
71+
if (m_isConstructed)
72+
{
73+
return *get();
74+
}
75+
else
76+
{
77+
memset(&m_storage, 0, sizeof(m_storage) * 8);
78+
return reinterpret_cast<const T &>(m_storage);
79+
};
80+
}
5881
operator T *(void) { return get(); }
5982
operator const T *(void) const { return get(); }
6083
//@}
6184

6285
//! @name Explicit construction methods
6386
//@{
64-
void construct(void) { new (m_storage) T; }
87+
void construct(void)
88+
{
89+
destroy();
90+
new (m_storage) T;
91+
m_isConstructed = true;
92+
}
93+
6594
template <typename A1>
6695
void construct(const A1 &a1)
6796
{
97+
destroy();
6898
new (m_storage) T(a1);
99+
m_isConstructed = true;
69100
}
70101

71102
template <typename A1, typename A2>
72103
void construct(const A1 &a1, const A2 &a2)
73104
{
105+
destroy();
74106
new (m_storage) T(a1, a2);
107+
m_isConstructed = true;
75108
}
76109

77110
template <typename A1, typename A2, typename A3>
78111
void construct(const A1 &a1, const A2 &a2, const A3 &a3)
79112
{
113+
destroy();
80114
new (m_storage) T(a1, a2, a3);
115+
m_isConstructed = true;
81116
}
82117

83118
template <typename A1, typename A2, typename A3, typename A4>
84119
void construct(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
85120
{
121+
destroy();
86122
new (m_storage) T(a1, a2, a3, a4);
123+
m_isConstructed = true;
87124
}
88125

89126
template <typename A1, typename A2, typename A3, typename A4, typename A5>
90127
void construct(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5)
91128
{
129+
destroy();
92130
new (m_storage) T(a1, a2, a3, a4, a5);
131+
m_isConstructed = true;
93132
}
94133

95134
template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
96135
void construct(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6)
97136
{
137+
destroy();
98138
new (m_storage) T(a1, a2, a3, a4, a5, a6);
139+
m_isConstructed = true;
99140
}
100141
//@}
101142

@@ -104,7 +145,14 @@ class ManuallyConstructed
104145
*
105146
* Behavior is undefined if the objected was not previously initialized.
106147
*/
107-
void destroy(void) { get()->~T(); }
148+
void destroy(void)
149+
{
150+
if (m_isConstructed)
151+
{
152+
get()->~T();
153+
m_isConstructed = false;
154+
}
155+
}
108156

109157
protected:
110158
/*!
@@ -113,6 +161,13 @@ class ManuallyConstructed
113161
* An array of uint64 is used to get 8-byte alignment.
114162
*/
115163
uint64_t m_storage[(sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t)];
164+
165+
/*!
166+
* @brief Track construct/destruct calls.
167+
*
168+
* Based on this variable we can allow or forbid construct/destruct calls.
169+
*/
170+
bool m_isConstructed = false;
116171
};
117172

118173
} // namespace erpc

erpc_c/setup/erpc_arbitrated_client_setup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ using namespace erpc;
3232

3333
// global client variables
3434
static ManuallyConstructed<ArbitratedClientManager> s_client;
35-
extern ClientManager *g_client;
36-
ClientManager *g_client = NULL;
35+
ClientManager *g_client;
36+
#pragma weak g_client
3737

3838
static ManuallyConstructed<BasicCodecFactory> s_codecFactory;
3939
static ManuallyConstructed<TransportArbitrator> s_arbitrator;

erpc_c/setup/erpc_client_setup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ using namespace erpc;
3030

3131
// global client variables
3232
static ManuallyConstructed<ClientManager> s_client;
33-
extern ClientManager *g_client;
34-
ClientManager *g_client = NULL;
33+
ClientManager *g_client;
34+
#pragma weak g_client
3535
static ManuallyConstructed<BasicCodecFactory> s_codecFactory;
3636
static ManuallyConstructed<Crc16> s_crc16;
3737

erpc_c/setup/erpc_setup_mbf_static.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
using namespace erpc;
2424

25-
#define ERPC_BUFFER_SIZE_UINT8 ((ERPC_DEFAULT_BUFFER_SIZE + sizeof(uint64_t) - 1))
26-
#define ERPC_BUFFER_SIZE_UINT64 (ERPC_BUFFER_SIZE_UINT8 / sizeof(uint64_t))
25+
#define ERPC_BUFFER_SIZE_UINT64 \
26+
((ERPC_DEFAULT_BUFFER_SIZE + sizeof(uint64_t) - 1) / sizeof(uint64_t))
2727

2828
////////////////////////////////////////////////////////////////////////////////
2929
// Classes
@@ -43,8 +43,8 @@ class StaticMessageBufferFactory : public MessageBufferFactory
4343
: m_semaphore(1)
4444
#endif
4545
{
46-
(void)memset(m_freeBufferBitmap, 0xff, ERPC_DEFAULT_BUFFERS_COUNT >> 3);
47-
(void)memset(m_buffers, 0, ERPC_DEFAULT_BUFFERS_COUNT * ERPC_BUFFER_SIZE_UINT8);
46+
(void)memset(m_freeBufferBitmap, 0xff, sizeof(m_freeBufferBitmap));
47+
(void)memset(m_buffers, 0, sizeof(m_buffers));
4848
}
4949

5050
/*!
@@ -112,8 +112,12 @@ class StaticMessageBufferFactory : public MessageBufferFactory
112112
}
113113

114114
protected:
115-
uint8_t m_freeBufferBitmap[(ERPC_DEFAULT_BUFFERS_COUNT >> 3U) + 1U]; /*!< Bitmat of used/not used buffers. */
116-
uint64_t m_buffers[ERPC_DEFAULT_BUFFERS_COUNT][ERPC_BUFFER_SIZE_UINT64]; /*!< Static buffers. */
115+
//! Bitmap representing which buffers are in use. A bit value of 1 means free and 0 means in
116+
//! use.
117+
uint8_t m_freeBufferBitmap[(ERPC_DEFAULT_BUFFERS_COUNT >> 3U) +
118+
(ERPC_DEFAULT_BUFFERS_COUNT % 8 ? 1U : 0U)];
119+
//! Static buffers
120+
uint64_t m_buffers[ERPC_DEFAULT_BUFFERS_COUNT][ERPC_BUFFER_SIZE_UINT64];
117121
#if !ERPC_THREADS_IS(NONE)
118122
Semaphore m_semaphore; /*!< Semaphore.*/
119123
#endif

erpc_c/transports/erpc_i2c_slave_transport.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ using namespace erpc;
2626
#error "Please define the ERPC_BOARD_I2C_INT_GPIO used to notify when the I2C Slave is ready to transmit"
2727
#endif
2828

29+
#define I2C_SLAVE_TRANSPORT_ADDR_7BIT (0x7EU)
30+
2931
////////////////////////////////////////////////////////////////////////////////
3032
// Variables
3133
////////////////////////////////////////////////////////////////////////////////
@@ -41,7 +43,7 @@ typedef struct i2c_clb_user_data
4143
uint8_t *rx_buffer;
4244
uint32_t rx_size;
4345
} I2C_CLB_USER_DATA, *I2C_CLB_USER_DATA_PTR;
44-
static I2C_CLB_USER_DATA volatile s_callback_user_data = { NULL, 0 };
46+
static volatile I2C_CLB_USER_DATA s_callback_user_data = { NULL, 0, NULL, 0 };
4547

4648
////////////////////////////////////////////////////////////////////////////////
4749
// Code
@@ -112,18 +114,26 @@ static void I2C_SlaveUserCallback(I2C_Type *base, volatile i2c_slave_transfer_t
112114
/* Update information for transmit process */
113115
transfer->txData = ((I2C_CLB_USER_DATA *)userData)->tx_buffer;
114116
transfer->txSize = ((I2C_CLB_USER_DATA *)userData)->tx_size;
117+
transfer->rxData = NULL;
118+
transfer->rxSize = 0;
115119
break;
116120

117121
/* Setup the slave receive buffer */
118122
case kI2C_SlaveReceiveEvent:
119123
/* Update information for received process */
120124
transfer->rxData = ((I2C_CLB_USER_DATA *)userData)->rx_buffer;
121125
transfer->rxSize = ((I2C_CLB_USER_DATA *)userData)->rx_size;
126+
transfer->txData = NULL;
127+
transfer->txSize = 0;
122128
break;
123129

124130
/* The master has sent a stop transition on the bus */
125131
case kI2C_SlaveCompletionEvent:
126132
transport->transfer_cb();
133+
transfer->rxData = NULL;
134+
transfer->rxSize = 0;
135+
transfer->txData = NULL;
136+
transfer->txSize = 0;
127137
break;
128138

129139
default:
@@ -159,7 +169,7 @@ erpc_status_t I2cSlaveTransport::init(void)
159169
i2c_slave_config_t i2cConfig;
160170

161171
I2C_SlaveGetDefaultConfig(&i2cConfig);
162-
i2cConfig.address0.address = (0x7EU); // I2C_MASTER_SLAVE_ADDR_7BIT
172+
i2cConfig.address0.address = (I2C_SLAVE_TRANSPORT_ADDR_7BIT);
163173

164174
I2C_SlaveInit(m_i2cBaseAddr, &i2cConfig, m_srcClock_Hz);
165175
I2C_SlaveTransferCreateHandle(m_i2cBaseAddr, &s_handle, I2C_SlaveUserCallback, (void *)&s_callback_user_data);
@@ -177,6 +187,8 @@ erpc_status_t I2cSlaveTransport::underlyingReceive(uint8_t *data, uint32_t size)
177187

178188
s_callback_user_data.rx_buffer = data;
179189
s_callback_user_data.rx_size = size;
190+
s_callback_user_data.tx_buffer = NULL;
191+
s_callback_user_data.tx_size = 0;
180192

181193
status =
182194
I2C_SlaveTransferNonBlocking(m_i2cBaseAddr, &s_handle, kI2C_SlaveAddressMatchEvent | kI2C_SlaveCompletionEvent);
@@ -205,6 +217,8 @@ erpc_status_t I2cSlaveTransport::underlyingSend(const uint8_t *data, uint32_t si
205217
status_t status;
206218
s_isTransferCompleted = false;
207219

220+
s_callback_user_data.rx_buffer = NULL;
221+
s_callback_user_data.rx_size = 0;
208222
s_callback_user_data.tx_buffer = (uint8_t *)data;
209223
s_callback_user_data.tx_size = size;
210224

erpc_c/transports/erpc_mu_transport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ void MUTransport::rx_cb(void)
150150
if (m_rxCntBytes >= m_rxMsgSize)
151151
{
152152
m_rxBuffer = NULL;
153-
MU_DisableInterrupts(m_muBase, (1U << (MU_CR_RIEn_SHIFT + MU_RR_COUNT - MU_REG_COUNT)));
154153
#if !ERPC_THREADS_IS(NONE)
154+
MU_DisableInterrupts(m_muBase, (1U << (MU_CR_RIEn_SHIFT + MU_RR_COUNT - MU_REG_COUNT)));
155155
m_rxSemaphore.putFromISR();
156156
#endif
157157
}

0 commit comments

Comments
 (0)