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

Improve Zephyr version detection #230

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extra_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"-<system/mbed/>",
"-<system/unix/>",
"-<system/windows/>"]
CPPDEFINES = ["ZENOH_ZEPHYR", "ZENOH_PIO"]
CPPDEFINES = ["ZENOH_ZEPHYR"]

elif FRAMEWORK == 'arduino':
PLATFORM = env.get("PIOPLATFORM")
Expand Down
7 changes: 6 additions & 1 deletion include/zenoh-pico/system/platform/zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
#ifndef ZENOH_PICO_SYSTEM_ZEPHYR_TYPES_H
#define ZENOH_PICO_SYSTEM_ZEPHYR_TYPES_H

#if defined(ZENOH_PIO)
#include <version.h>

#if KERNEL_VERSION_MAJOR == 2
#include <kernel.h>
#elif KERNEL_VERSION_MAJOR == 3
#include <zephyr/kernel.h>
#else
#pragma "This Zephyr version might not be supported."
#include <zephyr/kernel.h>
#endif

Expand Down
22 changes: 20 additions & 2 deletions src/system/zephyr/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#if defined(ZENOH_PIO)
#include <version.h>

#if KERNEL_VERSION_MAJOR == 2
#include <drivers/uart.h>
#else
#include <zephyr/drivers/uart.h>
Expand Down Expand Up @@ -404,14 +406,22 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo
if (!mcast) {
ret = _Z_ERR_GENERIC;
}
#if KERNEL_VERSION_MAJOR == 3 && KERNEL_VERSION_MINOR > 3
net_if_ipv4_maddr_join(net_if_get_default(), mcast);
cguimaraes marked this conversation as resolved.
Show resolved Hide resolved
#else
net_if_ipv4_maddr_join(mcast);
#endif
} else if (rep._iptcp->ai_family == AF_INET6) {
struct net_if_mcast_addr *mcast = NULL;
mcast = net_if_ipv6_maddr_add(ifa, &((struct sockaddr_in6 *)rep._iptcp->ai_addr)->sin6_addr);
if (!mcast) {
ret = _Z_ERR_GENERIC;
}
#if KERNEL_VERSION_MAJOR == 3 && KERNEL_VERSION_MINOR > 3
net_if_ipv6_maddr_join(net_if_get_default(), mcast);
#else
net_if_ipv6_maddr_join(mcast);
#endif
} else {
ret = _Z_ERR_GENERIC;
}
Expand Down Expand Up @@ -439,15 +449,23 @@ void _z_close_udp_multicast(_z_sys_net_socket_t *sockrecv, _z_sys_net_socket_t *
if (rep._iptcp->ai_family == AF_INET) {
mcast = net_if_ipv4_maddr_add(ifa, &((struct sockaddr_in *)rep._iptcp->ai_addr)->sin_addr);
if (mcast != NULL) {
#if KERNEL_VERSION_MAJOR == 3 && KERNEL_VERSION_MINOR > 3
net_if_ipv4_maddr_leave(net_if_get_default(), mcast);
#else
net_if_ipv4_maddr_leave(mcast);
#endif
net_if_ipv4_maddr_rm(ifa, &((struct sockaddr_in *)rep._iptcp->ai_addr)->sin_addr);
} else {
// Do nothing. The socket will be closed in any case.
}
} else if (rep._iptcp->ai_family == AF_INET6) {
mcast = net_if_ipv6_maddr_add(ifa, &((struct sockaddr_in6 *)rep._iptcp->ai_addr)->sin6_addr);
if (mcast != NULL) {
#if KERNEL_VERSION_MAJOR == 3 && KERNEL_VERSION_MINOR > 3
net_if_ipv6_maddr_leave(net_if_get_default(), mcast);
#else
net_if_ipv6_maddr_leave(mcast);
#endif
net_if_ipv6_maddr_rm(ifa, &((struct sockaddr_in6 *)rep._iptcp->ai_addr)->sin6_addr);
} else {
// Do nothing. The socket will be closed in any case.
Expand Down Expand Up @@ -531,7 +549,7 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr,
_z_sys_net_endpoint_t rep) {
return sendto(sock._fd, ptr, len, 0, rep._iptcp->ai_addr, rep._iptcp->ai_addrlen);
}
#endif
#endif // Z_LINK_UDP_MULTICAST == 1

#if Z_LINK_SERIAL == 1
int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) {
Expand Down
6 changes: 3 additions & 3 deletions src/system/zephyr/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#if defined(ZENOH_PIO)
#include <kernel.h>
#include <version.h>

#if KERNEL_VERSION_MAJOR == 2
#include <random/rand32.h>
#else
#include <zephyr/kernel.h>
#include <zephyr/random/rand32.h>
#endif

Expand Down
Loading