Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zephyr support #1615

Merged
merged 9 commits into from
Mar 24, 2023
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
option(BUILD_IDLC "Build IDL preprocessor" ${not_crosscompiling})
option(BUILD_DDSPERF "Build ddsperf tool" ${not_crosscompiling})

option(WITH_ZEPHYR "Build for Zephyr RTOS" OFF)

set(CMAKE_C_STANDARD 99)
if(CMAKE_SYSTEM_NAME STREQUAL "VxWorks")
add_definitions(-std=c99)
Expand Down Expand Up @@ -127,7 +129,12 @@ if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
endif()
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
#message(STATUS gcc)
add_compile_options(-Wall -Wextra -Wconversion -Wmissing-prototypes)
if(WITH_ZEPHYR)
# Suppress false warnings from system includes
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes)
else()
add_compile_options(-Wall -Wextra -Wconversion -Wmissing-prototypes)
endif()
if(${WERROR})
add_compile_options(-Werror)
endif()
Expand Down
6 changes: 3 additions & 3 deletions examples/roundtrip/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static bool CtrlHandler (DWORD fdwCtrlType)
dds_waitset_set_trigger (waitSet, true);
return true; //Don't let other handlers handle this key
}
#elif !DDSRT_WITH_FREERTOS
#elif !DDSRT_WITH_FREERTOS && !__ZEPHYR__
static void CtrlHandler (int sig)
{
(void)sig;
Expand Down Expand Up @@ -253,7 +253,7 @@ int main (int argc, char *argv[])
DDSRT_WARNING_GNUC_OFF(cast-function-type)
SetConsoleCtrlHandler ((PHANDLER_ROUTINE)CtrlHandler, TRUE);
DDSRT_WARNING_GNUC_ON(cast-function-type)
#elif !DDSRT_WITH_FREERTOS
#elif !DDSRT_WITH_FREERTOS && !__ZEPHYR__
struct sigaction sat, oldAction;
sat.sa_handler = CtrlHandler;
sigemptyset (&sat.sa_mask);
Expand Down Expand Up @@ -415,7 +415,7 @@ int main (int argc, char *argv[])

#ifdef _WIN32
SetConsoleCtrlHandler (0, FALSE);
#elif !DDSRT_WITH_FREERTOS
#elif !DDSRT_WITH_FREERTOS && !__ZEPHYR__
sigaction (SIGINT, &oldAction, 0);
#endif

Expand Down
6 changes: 3 additions & 3 deletions examples/roundtrip/pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static bool CtrlHandler (DWORD fdwCtrlType)
dds_waitset_set_trigger (waitSet, true);
return true; //Don't let other handlers handle this key
}
#elif !DDSRT_WITH_FREERTOS
#elif !DDSRT_WITH_FREERTOS && !__ZEPHYR__
static void CtrlHandler (int sig)
{
(void)sig;
Expand Down Expand Up @@ -91,7 +91,7 @@ int main (int argc, char *argv[])
DDSRT_WARNING_GNUC_OFF(cast-function-type)
SetConsoleCtrlHandler ((PHANDLER_ROUTINE)CtrlHandler, TRUE);
DDSRT_WARNING_GNUC_ON(cast-function-type)
#elif !DDSRT_WITH_FREERTOS
#elif !DDSRT_WITH_FREERTOS && !__ZEPHYR__
struct sigaction sat, oldAction;
sat.sa_handler = CtrlHandler;
sigemptyset (&sat.sa_mask);
Expand Down Expand Up @@ -134,7 +134,7 @@ int main (int argc, char *argv[])

#ifdef _WIN32
SetConsoleCtrlHandler (0, FALSE);
#elif !DDSRT_WITH_FREERTOS
#elif !DDSRT_WITH_FREERTOS && !__ZEPHYR__
sigaction (SIGINT, &oldAction, 0);
#endif

Expand Down
4 changes: 4 additions & 0 deletions examples/throughput/publisher.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ static int parse_args(int argc, char **argv, uint32_t *payloadSize, int *burstIn
static dds_entity_t prepare_dds(dds_entity_t *writer, const char *partitionName);
static void finalize_dds(dds_entity_t participant, dds_entity_t writer, ThroughputModule_DataType sample);

#if !DDSRT_WITH_FREERTOS && !__ZEPHYR__
static void sigint (int sig)
{
(void)sig;
done = true;
}
#endif

int main (int argc, char **argv)
{
Expand Down Expand Up @@ -73,7 +75,9 @@ int main (int argc, char **argv)
}

/* Register handler for Ctrl-C */
#if !DDSRT_WITH_FREERTOS && !__ZEPHYR__
signal (SIGINT, sigint);
#endif

/* Register the sample instance and write samples repeatedly or until time out */
start_writing(writer, &sample, burstInterval, burstSize, timeOut);
Expand Down
15 changes: 13 additions & 2 deletions examples/throughput/subscriber.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ static dds_sample_info_t info[MAX_SAMPLES];

static dds_entity_t waitSet;

#if !DDSRT_WITH_FREERTOS && !__ZEPHYR__
static volatile sig_atomic_t done = false;
#else
static bool done = false;
#endif

/* Forward declarations */
static HandleMap * HandleMap__alloc (void);
Expand All @@ -62,11 +66,13 @@ static void process_samples(dds_entity_t reader, unsigned long long maxCycles);
static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName);
static void finalize_dds(dds_entity_t participant);

#if !DDSRT_WITH_FREERTOS && !__ZEPHYR__
static void sigint (int sig)
{
(void) sig;
done = true;
}
#endif

int main (int argc, char **argv)
{
Expand All @@ -91,7 +97,9 @@ int main (int argc, char **argv)

/* Process samples until Ctrl-C is pressed or until maxCycles */
/* has been reached (0 = infinite) */
#if !DDSRT_WITH_FREERTOS && !__ZEPHYR__
signal (SIGINT, sigint);
#endif
process_samples(reader, maxCycles);

(void) dds_set_status_mask (reader, 0);
Expand Down Expand Up @@ -341,12 +349,13 @@ static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName)
DDS_FATAL("dds_create_subscriber: %s\n", dds_strretcode(-subscriber));
dds_delete_qos (subQos);

/* A Reader is created on the Subscriber & Topic with a modified Qos. */
/* A Listener is created which is triggered when data is available to read */

rd_listener = dds_create_listener(NULL);
dds_lset_data_available(rd_listener, data_available_handler);

/* A Read Condition is created which is triggered when data is available to read */
/* A Waitset is created which is triggered when data is available to read */

waitSet = dds_create_waitset (participant);
if (waitSet < 0)
DDS_FATAL("dds_create_waitset: %s\n", dds_strretcode(-waitSet));
Expand All @@ -363,6 +372,8 @@ static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName)
samples[i] = &data[i];
}

/* A Reader is created on the Subscriber & Topic and attached to Waitset */

*reader = dds_create_reader (subscriber, topic, NULL, pollingDelay < 0 ? rd_listener : NULL);
if (*reader < 0)
DDS_FATAL("dds_create_reader: %s\n", dds_strretcode(-*reader));
Expand Down
2 changes: 1 addition & 1 deletion src/core/ddsi/src/ddsi__plist_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum ddsi_pserop {
XSTOP,
XO, /* octet sequence */
XS, /* string */
XE1, XE2, XE3, /* enum 0..1, 0..2, 0..3 */
XE1, XE2, XE3, /* enum 0..1, 0..2, 0..3; mapping to integral type assumed to be the same for all three */
Xs, /* int16_t */
Xi, Xix2, Xix3, Xix4, /* int32_t, 1 .. 4 in a row */
Xu, Xux2, Xux3, Xux4, Xux5, /* uint32_t, 1 .. 5 in a row */
Expand Down
5 changes: 4 additions & 1 deletion src/core/ddsi/src/ddsi_mcgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ static int cmp_group_membership (const void *va, const void *vb)
const struct ddsi_mcgroup_membership_node *a = va;
const struct ddsi_mcgroup_membership_node *b = vb;
int c;

#if !defined(DDSRT_MCGROUP_JOIN_ONCE)
if (a->conn < b->conn)
return -1;
else if (a->conn > b->conn)
return 1;
else if ((c = locator_compare_no_port (&a->srcloc, &b->srcloc)) != 0)
#endif
if ((c = locator_compare_no_port (&a->srcloc, &b->srcloc)) != 0)
return c;
else if ((c = locator_compare_no_port (&a->mcloc, &b->mcloc)) != 0)
return c;
Expand Down
Loading