Skip to content

Commit

Permalink
Change configuration macro checks to use value instead of definedness
Browse files Browse the repository at this point in the history
  • Loading branch information
ssilverman committed Dec 29, 2023
1 parent 8bb4864 commit 4a11da5
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ and this project adheres to
disable DHCP.
* Disabled waiting in `EthernetClient::close()` for altcp clients because it's
not defined.
* Changed configuration macro checks to use value instead of definedness.

### Fixed
* Fixed a `printf` conversion specifier in the _RandomNumbers_ example. This was
Expand Down
2 changes: 1 addition & 1 deletion src/QNEthernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ bool EthernetClass::setMACAddressAllowed(const uint8_t mac[6],
if (netif_ == nullptr) {
return false;
}
#ifndef QNETHERNET_ENABLE_PROMISCUOUS_MODE
#if !QNETHERNET_ENABLE_PROMISCUOUS_MODE
return enet_set_mac_address_allowed(mac, flag);
#else
return flag; // Can't disallow MAC addresses
Expand Down
4 changes: 2 additions & 2 deletions src/QNEthernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class EthernetClass final {

// Returns whether promiscuous mode is enabled.
static constexpr bool isPromiscuousMode() {
#ifdef QNETHERNET_ENABLE_PROMISCUOUS_MODE
#if QNETHERNET_ENABLE_PROMISCUOUS_MODE
return true;
#else
return false;
Expand Down Expand Up @@ -408,7 +408,7 @@ class EthernetClass final {
// Instance for interacting with the library.
STATIC_INIT_DECL(EthernetClass, Ethernet);

#ifdef QNETHERNET_ENABLE_CUSTOM_WRITE
#if QNETHERNET_ENABLE_CUSTOM_WRITE
// stdout output.
extern Print *stdoutPrint;

Expand Down
2 changes: 1 addition & 1 deletion src/QNEthernetFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// QNEthernetFrame.cpp contains an EthernetFrame implementation.
// This file is part of the QNEthernet library.

#ifdef QNETHERNET_ENABLE_RAW_FRAME_SUPPORT
#if QNETHERNET_ENABLE_RAW_FRAME_SUPPORT

#include "QNEthernetFrame.h"

Expand Down
2 changes: 1 addition & 1 deletion src/QNEthernetFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef QNETHERNET_ETHERNETFRAME_H_
#define QNETHERNET_ETHERNETFRAME_H_

#ifdef QNETHERNET_ENABLE_RAW_FRAME_SUPPORT
#if QNETHERNET_ENABLE_RAW_FRAME_SUPPORT

// C++ includes
#include <cstddef>
Expand Down
2 changes: 1 addition & 1 deletion src/arch/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
} while (0)
extern void qnethernet_stdio_flush(int file);

#ifndef QNETHERNET_LWIP_MEMORY_IN_RAM1
#if !QNETHERNET_LWIP_MEMORY_IN_RAM1
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) \
u8_t variable_name[(size)] DMAMEM __attribute__((aligned(MEM_ALIGNMENT)))
#else
Expand Down
4 changes: 2 additions & 2 deletions src/default_altcp_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "lwip/opt.h"

#if LWIP_ALTCP && defined(QNETHERNET_ENABLE_ALTCP_DEFAULT_FUNCTIONS)
#if LWIP_ALTCP && QNETHERNET_ENABLE_ALTCP_DEFAULT_FUNCTIONS

#include <cstdint>
#include <functional>
Expand All @@ -31,4 +31,4 @@ __attribute__((weak))
std::function<void(const altcp_allocator_t &)> qnethernet_altcp_free_allocator =
[](const altcp_allocator_t &allocator) {};

#endif // LWIP_ALTCP && defined(QNETHERNET_ENABLE_ALTCP_DEFAULT_FUNCTIONS)
#endif // LWIP_ALTCP && QNETHERNET_ENABLE_ALTCP_DEFAULT_FUNCTIONS
2 changes: 1 addition & 1 deletion src/lwip_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool phy_link_is_crossover();
// This adds any extra padding bytes given by ETH_PAD_SIZE.
bool enet_output_frame(const uint8_t *frame, size_t len);

#ifndef QNETHERNET_ENABLE_PROMISCUOUS_MODE
#if !QNETHERNET_ENABLE_PROMISCUOUS_MODE

// For joining and leaving multicast groups; these call
// enet_set_mac_address_allowed() with the MAC addresses related to the given
Expand Down
2 changes: 1 addition & 1 deletion src/lwip_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "lwip/netif.h"
#include "lwip/pbuf.h"

#ifdef QNETHERNET_ENABLE_RAW_FRAME_SUPPORT
#if QNETHERNET_ENABLE_RAW_FRAME_SUPPORT

#define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(p, netif) \
unknown_eth_protocol((p), (netif))
Expand Down
24 changes: 12 additions & 12 deletions src/lwip_t41.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
// Payload(1500) + FCS(4)
#define BUF_SIZE (((ETH_PAD_SIZE + 6 + 6 + 2 + 2 + 2 + 1500 + 4) + 63) & ~63)

#ifndef QNETHERNET_BUFFERS_IN_RAM1
#if !QNETHERNET_BUFFERS_IN_RAM1
#define MULTIPLE_OF_32(x) (((x) + 31) & ~31)
#define BUFFER_DMAMEM DMAMEM
#else
Expand Down Expand Up @@ -639,7 +639,7 @@ static void low_level_init() {
| ENET_RCR_PADEN // Padding is removed
| ENET_RCR_RMII_MODE
| ENET_RCR_FCE // Flow control enable
#ifdef QNETHERNET_ENABLE_PROMISCUOUS_MODE
#if QNETHERNET_ENABLE_PROMISCUOUS_MODE
| ENET_RCR_PROM // Promiscuous mode
#endif // QNETHERNET_ENABLE_PROMISCUOUS_MODE
| ENET_RCR_MII_MODE;
Expand Down Expand Up @@ -761,7 +761,7 @@ static struct pbuf *low_level_input(volatile enetbufferdesc_t *pBD) {
} else {
p = pbuf_alloc(PBUF_RAW, pBD->length, PBUF_POOL);
if (p) {
#ifndef QNETHERNET_BUFFERS_IN_RAM1
#if !QNETHERNET_BUFFERS_IN_RAM1
arm_dcache_delete(pBD->buffer, MULTIPLE_OF_32(p->tot_len));
#endif // !QNETHERNET_BUFFERS_IN_RAM1
pbuf_take(p, pBD->buffer, p->tot_len);
Expand Down Expand Up @@ -832,7 +832,7 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) {
LINK_STATS_INC(link.drop);
return ERR_BUF;
}
#ifndef QNETHERNET_BUFFERS_IN_RAM1
#if !QNETHERNET_BUFFERS_IN_RAM1
arm_dcache_flush_delete(pBD->buffer, MULTIPLE_OF_32(copied));
#endif // !QNETHERNET_BUFFERS_IN_RAM1
update_bufdesc(pBD, copied);
Expand Down Expand Up @@ -952,7 +952,7 @@ static inline int check_link_status(int state) {
return 0;
}

#if LWIP_IGMP && !defined(QNETHERNET_ENABLE_PROMISCUOUS_MODE)
#if LWIP_IGMP && !QNETHERNET_ENABLE_PROMISCUOUS_MODE
// Multicast filter for letting the hardware know which packets to let in.
static err_t multicast_filter(struct netif *netif, const ip4_addr_t *group,
enum netif_mac_filter_action action) {
Expand All @@ -973,7 +973,7 @@ static err_t multicast_filter(struct netif *netif, const ip4_addr_t *group,
// ERR_USE seems like the best fit of the choices
// Next best seems to be ERR_IF
}
#endif // LWIP_IGMP && !defined(QNETHERNET_ENABLE_PROMISCUOUS_MODE)
#endif // LWIP_IGMP && !QNETHERNET_ENABLE_PROMISCUOUS_MODE

// --------------------------------------------------------------------------
// Public Interface
Expand Down Expand Up @@ -1013,7 +1013,7 @@ bool enet_has_hardware() {
return (s_initState != kInitStateNoHardware);
}

#ifdef QNETHERNET_INTERNAL_END_STOPS_ALL
#if QNETHERNET_INTERNAL_END_STOPS_ALL
// Removes the current netif, if any.
static void remove_netif() {
if (s_isNetifAdded) {
Expand Down Expand Up @@ -1070,10 +1070,10 @@ bool enet_init(const uint8_t mac[ETH_HWADDR_LEN],
autoip_set_struct(&s_netif, &s_autoip);
#endif // LWIP_AUTOIP

#if LWIP_IGMP && !defined(QNETHERNET_ENABLE_PROMISCUOUS_MODE)
#if LWIP_IGMP && !QNETHERNET_ENABLE_PROMISCUOUS_MODE
// Multicast filtering, to allow desired multicast packets in
netif_set_igmp_mac_filter(&s_netif, &multicast_filter);
#endif // LWIP_IGMP && !defined(QNETHERNET_ENABLE_PROMISCUOUS_MODE)
#endif // LWIP_IGMP && !QNETHERNET_ENABLE_PROMISCUOUS_MODE
} else {
// Just set the MAC address

Expand All @@ -1100,7 +1100,7 @@ void enet_deinit() {
// is restarted after calling end(), so gate the following two blocks with a
// macro for now

#ifdef QNETHERNET_INTERNAL_END_STOPS_ALL
#if QNETHERNET_INTERNAL_END_STOPS_ALL
remove_netif(); // TODO: This also causes issues (see notes in enet_init())

if (s_initState == kInitStateInitialized) {
Expand Down Expand Up @@ -1208,7 +1208,7 @@ bool enet_output_frame(const uint8_t *frame, size_t len) {
volatile enetbufferdesc_t *pBD = get_bufdesc();

memcpy((uint8_t *)pBD->buffer + ETH_PAD_SIZE, frame, len);
#ifndef QNETHERNET_BUFFERS_IN_RAM1
#if !QNETHERNET_BUFFERS_IN_RAM1
arm_dcache_flush_delete(pBD->buffer, MULTIPLE_OF_32(len + ETH_PAD_SIZE));
#endif // !QNETHERNET_BUFFERS_IN_RAM1
update_bufdesc(pBD, len + ETH_PAD_SIZE);
Expand All @@ -1220,7 +1220,7 @@ bool enet_output_frame(const uint8_t *frame, size_t len) {
// MAC Address Filtering
// --------------------------------------------------------------------------

#ifndef QNETHERNET_ENABLE_PROMISCUOUS_MODE
#if !QNETHERNET_ENABLE_PROMISCUOUS_MODE

// CRC-32 routine for computing the 4-byte FCS for multicast lookup.
static uint32_t crc32(uint32_t crc, const uint8_t *data, size_t len) {
Expand Down
2 changes: 1 addition & 1 deletion src/lwip_unsupported.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool enet_output_frame(const uint8_t *frame, size_t len) {
// MAC Address Filtering
// --------------------------------------------------------------------------

#ifndef QNETHERNET_ENABLE_PROMISCUOUS_MODE
#if !QNETHERNET_ENABLE_PROMISCUOUS_MODE

bool enet_set_mac_address_allowed(const uint8_t *mac, bool allow) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/security/RandomDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <pgmspace.h>

#if defined(__IMXRT1062__) && !defined(QNETHERNET_USE_ENTROPY_LIB)
#if defined(__IMXRT1062__) && !QNETHERNET_USE_ENTROPY_LIB

#include "entropy.h"

Expand Down
2 changes: 1 addition & 1 deletion src/security/entropy.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// This file is part of the QNEthernet library.

#if defined(__IMXRT1062__)
#if !defined(QNETHERNET_USE_ENTROPY_LIB)
#if !QNETHERNET_USE_ENTROPY_LIB

#include "entropy.h"

Expand Down
2 changes: 1 addition & 1 deletion src/security/entropy.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define QNETHERNET_SECURITY_ENTROPY_H_

#if defined(__IMXRT1062__)
#if !defined(QNETHERNET_USE_ENTROPY_LIB)
#if !QNETHERNET_USE_ENTROPY_LIB

#ifdef __cplusplus
extern "C" {
Expand Down
8 changes: 4 additions & 4 deletions src/sys_arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <unistd.h>

// C++ includes
#ifdef QNETHERNET_ENABLE_CUSTOM_WRITE
#if QNETHERNET_ENABLE_CUSTOM_WRITE
#include <cerrno>
#endif // QNETHERNET_ENABLE_CUSTOM_WRITE
#include <cstdint>
Expand Down Expand Up @@ -72,7 +72,7 @@ const char *lwip_strerr(err_t err) {
// stdio
// --------------------------------------------------------------------------

#ifdef QNETHERNET_ENABLE_CUSTOM_WRITE
#if QNETHERNET_ENABLE_CUSTOM_WRITE

// The user program can set these to something initialized. For example,
// `&Serial`, after `Serial.begin(speed)`.
Expand All @@ -96,7 +96,7 @@ extern "C" {
// Gets the Print* for the given file descriptor.
static inline Print *getPrint(int file) {
switch (file) {
#ifdef QNETHERNET_ENABLE_CUSTOM_WRITE
#if QNETHERNET_ENABLE_CUSTOM_WRITE
case STDOUT_FILENO:
return ::qindesign::network::stdoutPrint;
case STDERR_FILENO:
Expand All @@ -113,7 +113,7 @@ static inline Print *getPrint(int file) {
}
}

#ifdef QNETHERNET_ENABLE_CUSTOM_WRITE
#if QNETHERNET_ENABLE_CUSTOM_WRITE

// Define this function to provide expanded stdio output behaviour.
// See: https://forum.pjrc.com/threads/28473-Quick-Guide-Using-printf()-on-Teensy-ARM
Expand Down

0 comments on commit 4a11da5

Please sign in to comment.