Skip to content

Commit d42a139

Browse files
Merge pull request #148 from willmann9527/Assert_costumizing_#143
PR to issue #143: Assert costumizing
2 parents 0f1a638 + 3f52e89 commit d42a139

34 files changed

+135
-122
lines changed

erpc_c/config/erpc_config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@
181181
//! Uncomment for using pre post default callback feature.
182182
//#define ERPC_PRE_POST_ACTION_DEFAULT (ERPC_PRE_POST_ACTION_DEFAULT_ENABLED)
183183

184+
//! @name Assert function definition
185+
//@{
186+
//! User custom asser defition. Include header file if needed before bellow line. If assert is not enabled, default will be used.
187+
// #define erpc_assert(condition)
188+
//@}
189+
190+
184191
/*! @} */
185192
#endif // _ERPC_CONFIG_H_
186193
////////////////////////////////////////////////////////////////////////////////

erpc_c/infra/erpc_arbitrated_client_manager.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "erpc_arbitrated_client_manager.h"
1212
#include "erpc_transport_arbitrator.h"
1313

14-
#include "assert.h"
15-
1614
#if ERPC_THREADS_IS(NONE)
1715
#error "Arbitrator code does not work in no-threading configuration."
1816
#endif
@@ -42,7 +40,7 @@ void ArbitratedClientManager::performClientRequest(RequestContext &request)
4240
erpc_status_t err;
4341
TransportArbitrator::client_token_t token = 0;
4442

45-
assert(m_arbitrator && "arbitrator not set");
43+
erpc_assert(m_arbitrator && "arbitrator not set");
4644

4745
// Set up the client receive before we send the request, so if the reply is sent
4846
// before we get to the clientReceive() call below the arbitrator already has the buffer.

erpc_c/infra/erpc_basic_codec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void BasicCodec::writeCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount,
150150
{
151151
uint8_t i;
152152

153-
assert(callbacksCount > 1U);
153+
erpc_assert(callbacksCount > 1U);
154154

155155
// callbacks = callbacks table
156156
for (i = 0; i < callbacksCount; i++)
@@ -352,7 +352,7 @@ void BasicCodec::readCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, f
352352
{
353353
uint8_t _tmp_local;
354354

355-
assert(callbacksCount > 1U);
355+
erpc_assert(callbacksCount > 1U);
356356

357357
// callbacks = callbacks table
358358
read(&_tmp_local);

erpc_c/infra/erpc_client_manager.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#include "erpc_client_manager.h"
1212

13-
#include "assert.h"
14-
1513
using namespace erpc;
1614

1715
////////////////////////////////////////////////////////////////////////////////
@@ -49,7 +47,7 @@ void ClientManager::performRequest(RequestContext &request)
4947
#if ERPC_NESTED_CALLS
5048
if (performRequest)
5149
{
52-
assert(m_serverThreadId && "server thread id was not set");
50+
erpc_assert(m_serverThreadId && "server thread id was not set");
5351
if (Thread::getCurrentThreadId() == m_serverThreadId)
5452
{
5553
performNestedClientRequest(request);
@@ -120,7 +118,7 @@ void ClientManager::performNestedClientRequest(RequestContext &request)
120118
{
121119
erpc_status_t err;
122120

123-
assert(m_transport && "transport/arbitrator not set");
121+
erpc_assert(m_transport && "transport/arbitrator not set");
124122

125123
#if ERPC_MESSAGE_LOGGING
126124
if (request.getCodec()->isStatusOk() == true)
@@ -143,7 +141,7 @@ void ClientManager::performNestedClientRequest(RequestContext &request)
143141
// Receive reply.
144142
if (request.getCodec()->isStatusOk() == true)
145143
{
146-
assert(m_server && "server for nesting calls was not set");
144+
erpc_assert(m_server && "server for nesting calls was not set");
147145
err = m_server->run(request);
148146
request.getCodec()->updateStatus(err);
149147
}

erpc_c/infra/erpc_framed_transport.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "erpc_framed_transport.h"
1212
#include "erpc_message_buffer.h"
1313

14-
#include <cassert>
1514
#include <cstdio>
1615

1716
using namespace erpc;
@@ -34,7 +33,7 @@ FramedTransport::~FramedTransport(void) {}
3433

3534
void FramedTransport::setCrc16(Crc16 *crcImpl)
3635
{
37-
assert(crcImpl);
36+
erpc_assert(crcImpl);
3837
m_crcImpl = crcImpl;
3938
}
4039

@@ -44,7 +43,7 @@ erpc_status_t FramedTransport::receive(MessageBuffer *message)
4443
erpc_status_t retVal;
4544
uint16_t computedCrc;
4645

47-
assert(m_crcImpl && "Uninitialized Crc16 object.");
46+
erpc_assert(m_crcImpl && "Uninitialized Crc16 object.");
4847

4948
{
5049
#if !ERPC_THREADS_IS(NONE)
@@ -102,7 +101,7 @@ erpc_status_t FramedTransport::send(MessageBuffer *message)
102101
uint16_t messageLength;
103102
Header h;
104103

105-
assert(m_crcImpl && "Uninitialized Crc16 object.");
104+
erpc_assert(m_crcImpl && "Uninitialized Crc16 object.");
106105

107106
#if !ERPC_THREADS_IS(NONE)
108107
Mutex::Guard lock(m_sendLock);

erpc_c/infra/erpc_message_buffer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*/
1010

1111
#include "erpc_message_buffer.h"
12+
#include "erpc_config_internal.h"
1213

13-
#include <cassert>
1414
#include <cstring>
1515

1616
using namespace erpc;
@@ -64,7 +64,7 @@ erpc_status_t MessageBuffer::write(uint16_t offset, const void *data, uint32_t l
6464

6565
erpc_status_t MessageBuffer::copy(const MessageBuffer *other)
6666
{
67-
assert(m_len >= other->m_len);
67+
erpc_assert(m_len >= other->m_len);
6868

6969
m_used = other->m_used;
7070
(void)memcpy(m_buf, other->m_buf, m_used);
@@ -74,7 +74,7 @@ erpc_status_t MessageBuffer::copy(const MessageBuffer *other)
7474

7575
void MessageBuffer::swap(MessageBuffer *other)
7676
{
77-
assert(other);
77+
erpc_assert(other);
7878

7979
MessageBuffer temp(*other);
8080

@@ -90,15 +90,15 @@ void MessageBuffer::Cursor::set(MessageBuffer *buffer)
9090
{
9191
m_buffer = buffer;
9292
// RPMSG when nested calls are enabled can set NULL buffer.
93-
// assert(buffer->get() && "Data buffer wasn't set to MessageBuffer.");
93+
// erpc_assert(buffer->get() && "Data buffer wasn't set to MessageBuffer.");
9494
// receive function should return err if it couldn't set data buffer.
9595
m_pos = buffer->get();
9696
m_remaining = buffer->getLength();
9797
}
9898

9999
erpc_status_t MessageBuffer::Cursor::read(void *data, uint32_t length)
100100
{
101-
assert(m_pos && "Data buffer wasn't set to MessageBuffer.");
101+
erpc_assert(m_pos && "Data buffer wasn't set to MessageBuffer.");
102102

103103
erpc_status_t err;
104104

@@ -120,7 +120,7 @@ erpc_status_t MessageBuffer::Cursor::read(void *data, uint32_t length)
120120

121121
erpc_status_t MessageBuffer::Cursor::write(const void *data, uint32_t length)
122122
{
123-
assert(m_pos && "Data buffer wasn't set to MessageBuffer.");
123+
erpc_assert(m_pos && "Data buffer wasn't set to MessageBuffer.");
124124

125125
erpc_status_t err;
126126

erpc_c/infra/erpc_server.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#include "erpc_server.h"
1212

13-
#include "assert.h"
14-
1513
using namespace erpc;
1614

1715
////////////////////////////////////////////////////////////////////////////////

erpc_c/infra/erpc_transport_arbitrator.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
* SPDX-License-Identifier: BSD-3-Clause
99
*/
1010
#include "erpc_transport_arbitrator.h"
11-
11+
#include "erpc_config_internal.h"
1212
#include "erpc_manually_constructed.h"
1313

14-
#include <cassert>
1514
#include <cstdio>
1615
#include <string>
1716

@@ -47,21 +46,21 @@ TransportArbitrator::~TransportArbitrator(void)
4746

4847
void TransportArbitrator::setCrc16(Crc16 *crcImpl)
4948
{
50-
assert(crcImpl);
51-
assert(m_sharedTransport);
49+
erpc_assert(crcImpl);
50+
erpc_assert(m_sharedTransport);
5251
m_sharedTransport->setCrc16(crcImpl);
5352
}
5453

5554
bool TransportArbitrator::hasMessage(void)
5655
{
57-
assert(m_sharedTransport && "shared transport is not set");
56+
erpc_assert(m_sharedTransport && "shared transport is not set");
5857

5958
return m_sharedTransport->hasMessage();
6059
}
6160

6261
erpc_status_t TransportArbitrator::receive(MessageBuffer *message)
6362
{
64-
assert(m_sharedTransport && "shared transport is not set");
63+
erpc_assert(m_sharedTransport && "shared transport is not set");
6564

6665
erpc_status_t err;
6766
message_type_t msgType;
@@ -142,7 +141,7 @@ erpc_status_t TransportArbitrator::receive(MessageBuffer *message)
142141

143142
erpc_status_t TransportArbitrator::send(MessageBuffer *message)
144143
{
145-
assert(m_sharedTransport && "shared transport is not set");
144+
erpc_assert(m_sharedTransport && "shared transport is not set");
146145
return m_sharedTransport->send(message);
147146
}
148147

@@ -159,7 +158,7 @@ TransportArbitrator::client_token_t TransportArbitrator::prepareClientReceive(Re
159158

160159
erpc_status_t TransportArbitrator::clientReceive(client_token_t token)
161160
{
162-
assert((token != 0) && "invalid client token");
161+
erpc_assert((token != 0) && "invalid client token");
163162

164163
// Convert token to pointer to info struct for this client receive request.
165164
PendingClientInfo *info = reinterpret_cast<PendingClientInfo *>(token);

erpc_c/port/erpc_config_internal.h

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@
4949

5050
// Detect allocation policy if not already set.
5151
#if !defined(ERPC_ALLOCATION_POLICY)
52-
#if defined(__has_include) && __has_include("FreeRTOSConfig.h")
52+
#if ERPC_HAS_FREERTOSCONFIG_H
5353
#ifdef __cplusplus
54-
extern "C" {
54+
extern "C" {
5555
#endif
5656
#include "FreeRTOSConfig.h"
5757
#ifdef __cplusplus
58-
}
58+
}
5959
#endif
6060
#if defined(configSUPPORT_STATIC_ALLOCATION) && configSUPPORT_STATIC_ALLOCATION
6161
#define ERPC_ALLOCATION_POLICY (ERPC_ALLOCATION_POLICY_STATIC)
@@ -68,15 +68,15 @@
6868
#endif
6969

7070
#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC
71-
#if !defined(ERPC_CODEC_COUNT)
72-
#define ERPC_CODEC_COUNT (2U)
73-
#endif
74-
#if !defined(ERPC_MESSAGE_LOGGERS_COUNT)
75-
#define ERPC_MESSAGE_LOGGERS_COUNT (0U)
76-
#endif
77-
#if !defined(ERPC_CLIENTS_THREADS_AMOUNT)
78-
#define ERPC_CLIENTS_THREADS_AMOUNT (1U)
79-
#endif
71+
#if !defined(ERPC_CODEC_COUNT)
72+
#define ERPC_CODEC_COUNT (2U)
73+
#endif
74+
#if !defined(ERPC_MESSAGE_LOGGERS_COUNT)
75+
#define ERPC_MESSAGE_LOGGERS_COUNT (0U)
76+
#endif
77+
#if !defined(ERPC_CLIENTS_THREADS_AMOUNT)
78+
#define ERPC_CLIENTS_THREADS_AMOUNT (1U)
79+
#endif
8080
#endif
8181

8282
// Safely detect tx_api.h.
@@ -133,9 +133,9 @@
133133

134134
//NOEXCEPT support
135135
#if defined(__cplusplus) && __cplusplus >= 201103 && ERPC_NOEXCEPT
136-
#define NOEXCEPT noexcept
136+
#define NOEXCEPT noexcept
137137
#else
138-
#define NOEXCEPT
138+
#define NOEXCEPT
139139
#endif // NOEXCEPT
140140

141141
// Disabling nesting calls support as default.
@@ -162,11 +162,11 @@
162162
#endif
163163

164164
#if defined(__CC_ARM) || defined(__ARMCC_VERSION) /* Keil MDK */
165-
#define THROW_BADALLOC throw(std::bad_alloc)
166-
#define THROW throw()
165+
#define THROW_BADALLOC throw(std::bad_alloc)
166+
#define THROW throw()
167167
#else
168-
#define THROW_BADALLOC
169-
#define THROW
168+
#define THROW_BADALLOC
169+
#define THROW
170170
#endif
171171

172172
#ifndef ERPC_TRANSPORT_MU_USE_MCMGR
@@ -195,6 +195,30 @@
195195
#define ERPC_PRE_POST_ACTION_DEFAULT (ERPC_PRE_POST_ACTION_DEFAULT_DISABLED)
196196
#endif
197197

198+
#if !defined(erpc_assert)
199+
#if ERPC_HAS_FREERTOSCONFIG_H
200+
#ifdef __cplusplus
201+
extern "C" {
202+
#endif
203+
#include "FreeRTOS.h"
204+
#include "task.h"
205+
#ifdef __cplusplus
206+
}
207+
#endif
208+
#define erpc_assert(condition) configASSERT(condition)
209+
#elif defined(ERPC_THREADS) && (ERPC_THREADS == ERPC_THREADS_MBED)
210+
#include "platform/mbed_assert.h"
211+
#define erpc_assert(condition) MBED_ASSERT(condition)
212+
#else
213+
#ifdef __cplusplus
214+
#include <cassert>
215+
#else
216+
#include "assert.h"
217+
#endif
218+
#define erpc_assert(condition) assert(condition)
219+
#endif
220+
#endif
221+
198222
/* clang-format on */
199223
#endif // _ERPC_DETECT_H_
200224
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)