Skip to content

Commit

Permalink
Merge pull request contiki-os#883 from cmorty/pull/global-macros
Browse files Browse the repository at this point in the history
Move MAX, MIN and ABS to contiki-macros
  • Loading branch information
adamdunkels committed May 18, 2015
2 parents b8ff325 + 0dab692 commit 730bda2
Show file tree
Hide file tree
Showing 33 changed files with 41 additions and 93 deletions.
1 change: 1 addition & 0 deletions apps/er-coap/er-coap-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* Matthias Kovatsch <[email protected]>
*/

#include "sys/cc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
1 change: 1 addition & 0 deletions apps/er-coap/er-coap-separate.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* Matthias Kovatsch <[email protected]>
*/

#include "sys/cc.h"
#include <stdio.h>
#include <string.h>
#include "er-coap-separate.h"
Expand Down
1 change: 1 addition & 0 deletions apps/er-coap/er-coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <string.h>
#include <stdio.h>
#include "contiki.h"
#include "sys/cc.h"
#include "contiki-net.h"

#include "er-coap.h"
Expand Down
4 changes: 0 additions & 4 deletions apps/er-coap/er-coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ enum { OPTION_MAP_SIZE = sizeof(uint8_t) * 8 };
#define SET_OPTION(packet, opt) ((packet)->options[opt / OPTION_MAP_SIZE] |= 1 << (opt % OPTION_MAP_SIZE))
#define IS_OPTION(packet, opt) ((packet)->options[opt / OPTION_MAP_SIZE] & (1 << (opt % OPTION_MAP_SIZE)))

#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif /* MIN */

/* parsed message struct */
typedef struct {
uint8_t *buffer; /* pointer to CoAP header / incoming packet buffer / memory to serialize packet */
Expand Down
3 changes: 1 addition & 2 deletions apps/mqtt/mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@

#include "lib/assert.h"
#include "lib/list.h"
#include "sys/cc.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
#define MIN(a, b) ((a) < (b) ? (a) : (b))
/*---------------------------------------------------------------------------*/
#define DEBUG 0
#if DEBUG
#define PRINTF(...) PRINTF(__VA_ARGS__)
Expand Down
4 changes: 0 additions & 4 deletions apps/rest-engine/rest-engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
#define REST_MAX_CHUNK_SIZE 64
#endif

#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif /* MIN */

struct resource_s;
struct periodic_resource_s;

Expand Down
1 change: 1 addition & 0 deletions apps/shell/shell-power.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "sys/energest.h"

#include <stdio.h>
#include "sys/cc.h"

struct power_msg {
uint16_t len;
Expand Down
3 changes: 1 addition & 2 deletions apps/shell/shell-sky.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
*/

#include "contiki.h"
#include "sys/cc.h"
#include "shell-sky.h"

#include "dev/watchdog.h"
Expand Down Expand Up @@ -84,8 +85,6 @@ SHELL_COMMAND(rfchannel_command,
"rfchannel <channel>: change CC2420 radio channel (11 - 26)",
&shell_rfchannel_process);
/*---------------------------------------------------------------------------*/
#define MAX(a, b) ((a) > (b)? (a): (b))
#define MIN(a, b) ((a) < (b)? (a): (b))
struct spectrum {
int channel[16];
};
Expand Down
5 changes: 1 addition & 4 deletions apps/shell/shell-tcpsend.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@
#include <stddef.h>

#include "contiki.h"
#include "sys/cc.h"
#include "shell.h"
#include "telnet.h"

#ifndef MIN
#define MIN(a, b) ((a) < (b)? (a) : (b))
#endif /* MIN */

/*---------------------------------------------------------------------------*/
PROCESS(shell_tcpsend_process, "tcpsend");
SHELL_COMMAND(tcpsend_command,
Expand Down
6 changes: 1 addition & 5 deletions apps/shell/shell-time.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
*/

#include "contiki.h"
#include "sys/cc.h"
#include "shell-time.h"

#include "sys/clock.h"
Expand All @@ -51,11 +52,6 @@
#define MAX_COMMANDLENGTH 64
#define PERIOD_INTERVAL 60

#ifndef MIN
#define MIN(a, b) ((a) < (b)? (a) : (b))
#endif /* MIN */


/*---------------------------------------------------------------------------*/
PROCESS(shell_time_process, "time");
SHELL_COMMAND(time_command,
Expand Down
2 changes: 1 addition & 1 deletion apps/telnetd/telnetd.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <string.h>

#include "sys/cc.h"
#include "contiki-lib.h"
#include "contiki-net.h"
#include "lib/petsciiconv.h"
Expand Down Expand Up @@ -103,7 +104,6 @@ static uint8_t connected;

#define MAX_SILENCE_TIME (CLOCK_SECOND * 30)

#define MIN(a, b) ((a) < (b)? (a): (b))
/*---------------------------------------------------------------------------*/
static void
buf_init(struct telnetd_buf *buf)
Expand Down
4 changes: 0 additions & 4 deletions core/lib/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@
#define SETTINGS_BOTTOM_ADDR (SETTINGS_TOP_ADDR + 1 - SETTINGS_MAX_SIZE)
#endif

#ifndef MIN
#define MIN(a,b) ((a)<(b)?a:b)
#endif

typedef struct {
#if SETTINGS_CONF_SUPPORT_LARGE_VALUES
uint8_t size_extra;
Expand Down
2 changes: 1 addition & 1 deletion core/net/ip/tcp-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/

#include "contiki.h"
#include "sys/cc.h"
#include "contiki-net.h"

#include "lib/list.h"
Expand All @@ -39,7 +40,6 @@
#include <stdio.h>
#include <string.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))

static void relisten(struct tcp_socket *s);

Expand Down
3 changes: 2 additions & 1 deletion core/net/ipv4/uip.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
#include "net/ipv4/uip-neighbor.h"

#include <string.h>
#include "sys/cc.h"

/*---------------------------------------------------------------------------*/
/* Variable definitions. */

Expand Down Expand Up @@ -1953,7 +1955,6 @@ void
uip_send(const void *data, int len)
{
int copylen;
#define MIN(a,b) ((a) < (b)? (a): (b))
copylen = MIN(len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN -
(int)((char *)uip_sappdata - (char *)&uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN]));
if(copylen > 0) {
Expand Down
2 changes: 1 addition & 1 deletion core/net/ipv6/uip6.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
* the packet back to the peer.
*/

#include "sys/cc.h"
#include "net/ip/uip.h"
#include "net/ip/uipopt.h"
#include "net/ipv6/uip-icmp6.h"
Expand Down Expand Up @@ -2332,7 +2333,6 @@ void
uip_send(const void *data, int len)
{
int copylen;
#define MIN(a,b) ((a) < (b)? (a): (b))

if(uip_sappdata != NULL) {
copylen = MIN(len, UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN -
Expand Down
4 changes: 0 additions & 4 deletions core/net/mac/contikimac/contikimac.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ static struct compower_activity current_packet;

#define DEFAULT_STREAM_TIME (4 * CYCLE_TIME)

#ifndef MIN
#define MIN(a, b) ((a) < (b)? (a) : (b))
#endif /* MIN */

#if CONTIKIMAC_CONF_BROADCAST_RATE_LIMIT
static struct timer broadcast_rate_timer;
static int broadcast_rate_counter;
Expand Down
5 changes: 1 addition & 4 deletions core/net/mac/cxmac/cxmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "sys/rtimer.h"

#include "contiki-conf.h"
#include "sys/cc.h"

#ifdef EXPERIMENT_SETUP
#include "experiment-setup.h"
Expand Down Expand Up @@ -215,10 +216,6 @@ static linkaddr_t is_streaming_to, is_streaming_to_too;
static rtimer_clock_t stream_until;
#define DEFAULT_STREAM_TIME (RTIMER_ARCH_SECOND)

#ifndef MIN
#define MIN(a, b) ((a) < (b)? (a) : (b))
#endif /* MIN */

/*---------------------------------------------------------------------------*/
static void
on(void)
Expand Down
2 changes: 0 additions & 2 deletions core/net/rime/broadcast-announcement.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ static struct broadcast_announcement_state {
#define PRINTF(...)
#endif

#define MIN(a, b) ((a)<(b)?(a):(b))

/*---------------------------------------------------------------------------*/
static void
send_adv(void *ptr)
Expand Down
9 changes: 1 addition & 8 deletions core/net/rime/ipolite.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,13 @@
* @{
*/

#include "sys/cc.h"
#include "net/rime/rime.h"
#include "net/rime/ipolite.h"
#include "lib/random.h"

#include <string.h>

#ifndef MAX
#define MAX(a, b) ((a) > (b)? (a) : (b))
#endif /* MAX */

#ifndef MIN
#define MIN(a, b) ((a) < (b)? (a) : (b))
#endif /* MIN */

#define DEBUG 0
#if DEBUG
#include <stdio.h>
Expand Down
4 changes: 1 addition & 3 deletions core/net/rime/polite-announcement.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/

#include "contiki.h"

#include "sys/cc.h"
#include "lib/list.h"
#include "net/rime/rime.h"
#include "net/rime/announcement.h"
Expand Down Expand Up @@ -90,8 +90,6 @@ static struct polite_announcement_state {
#define PRINTF(...)
#endif

#define MIN(a, b) ((a)<(b)?(a):(b))

/*---------------------------------------------------------------------------*/
static void
send_adv(clock_time_t interval)
Expand Down
10 changes: 1 addition & 9 deletions core/net/rime/polite.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,13 @@
* @{
*/

#include "sys/cc.h"
#include "net/rime/rime.h"
#include "net/rime/polite.h"
#include "lib/random.h"

#include <string.h>

#ifndef MAX
#define MAX(a,b) ((a) > (b)? (a) : (b))
#endif /* MAX */

#ifndef MIN
#define MIN(a, b) ((a) < (b)? (a) : (b))
#endif /* MIN */


/*---------------------------------------------------------------------------*/
static void
recv(struct abc_conn *abc)
Expand Down
13 changes: 13 additions & 0 deletions core/sys/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@
#define NULL 0
#endif /* NULL */

#ifndef MAX
#define MAX(n, m) (((n) < (m)) ? (m) : (n))
#endif

#ifndef MIN
#define MIN(n, m) (((n) < (m)) ? (n) : (m))
#endif

#ifndef ABS
#define ABS(n) (((n) < 0) ? -(n) : (n))
#endif


#define CC_CONCAT2(s1, s2) s1##s2
/**
* A C preprocessing macro for concatenating two preprocessor tokens.
Expand Down
3 changes: 0 additions & 3 deletions cpu/avr/dev/usb/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,6 @@ typedef char r_uart_ptchar;
#define OUT_X(addrx,value) (*addrx = value)
#define IN_X(addrx) (*addrx)

# define Max(a, b) ( (a)>(b) ? (a) : (b) ) // Take the max between a and b
# define Min(a, b) ( (a)<(b) ? (a) : (b) ) // Take the min between a and b

// Align on the upper value <val> on a <n> boundary
// i.e. Upper(0, 4)= 4
// Upper(1, 4)= 4
Expand Down
5 changes: 1 addition & 4 deletions cpu/cc26xx/dev/cc26xx-rf.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "sys/energest.h"
#include "sys/clock.h"
#include "sys/rtimer.h"
#include "sys/cc.h"
#include "lpm.h"
#include "ti-lib.h"
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -78,10 +79,6 @@
while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))); \
} while(0)
/*---------------------------------------------------------------------------*/
#ifndef MIN
#define MIN(n, m) (((n) < (m)) ? (n) : (m))
#endif
/*---------------------------------------------------------------------------*/
#ifdef __GNUC__
#define CC_ALIGN_ATTR(n) __attribute__ ((aligned(n)))
#else
Expand Down
4 changes: 1 addition & 3 deletions cpu/rl78/adf7023/ADF7023.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "sfrs-ext.h"

#include "contiki.h" /* for clock_wait() and CLOCK_SECOND. */
#include "sys/cc.h"

/******************************************************************************/
/*************************** Macros Definitions *******************************/
Expand Down Expand Up @@ -91,9 +92,6 @@
while(condition) { body; break_loop(); } \
} while(0)

#undef MIN
#define MIN(x, y) (((x) < (y)) ? (x) : (y))

/******************************************************************************/
/************************ Variables Definitions *******************************/
/******************************************************************************/
Expand Down
5 changes: 1 addition & 4 deletions examples/cc26xx/cc26xx-web-demo/net-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "net/ip/uiplib.h"
#include "net-uart.h"
#include "httpd-simple.h"
#include "sys/cc.h"

#include "ti-lib.h"

Expand All @@ -86,10 +87,6 @@
#define ADDRESS_CONVERSION_OK 1
#define ADDRESS_CONVERSION_ERROR 0
/*---------------------------------------------------------------------------*/
#ifndef MIN
#define MIN(n, m) (((n) < (m)) ? (n) : (m))
#endif
/*---------------------------------------------------------------------------*/
static struct uip_udp_conn *udp_conn = NULL;

static uint8_t buffer[MAX_MSG_SIZE];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/

#include <string.h>
#include "sys/cc.h"
#include "rest-engine.h"
#include "er-coap.h"
#include "er-plugtest.h"
Expand Down
Loading

0 comments on commit 730bda2

Please sign in to comment.