Digi XBee(R) ANSI C Host Library
platform.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2013 Digi International Inc.,
3  * All rights not expressly granted are reserved.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
7  * You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
10  * =======================================================================
11  */
12 
24 #ifndef __XBEE_PLATFORM
25 #define __XBEE_PLATFORM
26 
37 #if defined(__cplusplus)
38  #define XBEE_BEGIN_DECLS extern "C" {
39  #define XBEE_END_DECLS }
40 #else
41  #define XBEE_BEGIN_DECLS
42  #define XBEE_END_DECLS
43 #endif
44 
45 #include <errno.h>
46 #include <stddef.h>
47 
93 #ifndef ENODATA
94  #define ENODATA 20000
95 #endif
96 #ifndef EINVAL
97  #define EINVAL 20001
98 #endif
99 #ifndef EIO
100  #define EIO 20002
101 #endif
102 #ifndef EBUSY
103  #define EBUSY 20003
104 #endif
105 #ifndef EEXIST
106  #define EEXIST 20004
107 #endif
108 #ifndef ENOSPC
109  #define ENOSPC 20005
110 #endif
111 #ifndef ENOENT
112  #define ENOENT 20006
113 #endif
114 #ifndef E2BIG
115  #define E2BIG 20007
116 #endif
117 #ifndef EBADMSG
118  #define EBADMSG 20010
119 #endif
120 #ifndef ENOTSUP
121  #define ENOTSUP 20011
122 #endif
123 #ifndef ETIMEDOUT
124  #define ETIMEDOUT 20012
125 #endif
126 #ifndef EILSEQ
127  #define EILSEQ 20013
128 #endif
129 #ifndef EAGAIN
130  #define EAGAIN 20014
131 #endif
132 #ifndef ENOSYS
133  #define ENOSYS 20015
134 #endif
135 #ifndef EACCES
136  #define EACCES 20016
137 #endif
138 #ifndef ECANCELED
139  #define ECANCELED 20017
140 #endif
141 #ifndef EMSGSIZE
142  #define EMSGSIZE 20018
143 #endif
144 #ifndef EPERM
145  #define EPERM 20019
146 #endif
147 // Note to developers: if possible, only add POSIX.1-2001 macros to this list.
148 
149 
338 #define ZCL_TIME_EPOCH_DELTA_1980 ((UINT32_C(20) * 365 + 5) * 24 * 60 * 60)
341 
344 #define ZCL_TIME_EPOCH_DELTA_1970 ((UINT32_C(30) * 365 + 7) * 24 * 60 * 60)
345 
346 #ifdef XBEE_PLATFORM_HEADER
347  #include XBEE_PLATFORM_HEADER
348 #elif defined __DC__
349  #include "../ports/rabbit/platform_config.h"
350 #elif defined POSIX
351  #include "../ports/posix/platform_config.h"
352 #elif defined __DOS__
353  // Note: at present, only Open Watcom compiler supported
354  // (can test for __WATCOMC__ preprocessor symbol, or
355  // __BORLANDC__ for Borland C++)
356  #include "../ports/dos/platform_config.h"
357 #elif defined WIN32 || defined _WIN32 || defined _WIN32_ || defined __WIN32__ \
358  || defined __CYGWIN32__ || defined MINGW32
359  #include "../ports/win32/platform_config.h"
360 #elif defined __MWERKS__ && defined __HC08__
361  #include "../ports/hcs08/platform_config.h"
362 #else
363  #error "Unknown target"
364 #endif
365 
366 #ifndef TRUE
367  #define TRUE 1
368 #endif
369 #ifndef FALSE
370  #define FALSE 0
371 #endif
372 
373 #ifndef PACKED_STRUCT
374  #define PACKED_STRUCT struct
375 #endif
376 #ifndef XBEE_PACKED
377  #define XBEE_PACKED(name, decl) PACKED_STRUCT name decl
378 #endif
379 
380 // Most platforms don't have alignment requirements, and we can just use casts.
381 #ifndef xbee_get_unaligned16
382  #define xbee_get_unaligned16( p) (*(uint16_t FAR *)(p))
383 #endif
384 #ifndef xbee_get_unaligned32
385  #define xbee_get_unaligned32( p) (*(uint32_t FAR *)(p))
386 #endif
387 #ifndef xbee_set_unaligned16
388  #define xbee_set_unaligned16( p, v) *(uint16_t FAR *)(p) = (v)
389 #endif
390 #ifndef xbee_set_unaligned32
391  #define xbee_set_unaligned32( p, v) *(uint32_t FAR *)(p) = (v)
392 #endif
393 
394 // default is for FAR to be ignored
395 #ifndef FAR
396  #define FAR
397 #endif
398 // on platforms without the concept of "FAR", cast to near is unnecessary
399 #ifndef CAST_FAR_TO_NEAR
400  #define CAST_FAR_TO_NEAR(p) (p)
401 #endif
402 #ifndef INTERRUPT_ENABLE
403  #define INTERRUPT_ENABLE
404 #endif
405 
406 #ifndef INTERRUPT_DISABLE
407  #define INTERRUPT_DISABLE
408 #endif
409 
410 #if defined(XBEE_WIFI_ENABLE) || defined(XBEE_WIFI_DISABLE)
411  #error "The XBEE_WIFI_ENABLE and XBEE_WIFI_DISABLE macros " \
412  "are deprecated. Please use XBEE_WIFI_ENABLED instead."
413 #endif
414 
415 // assume platforms support up to 115200bps
416 #ifndef XBEE_SERIAL_MAX_BAUDRATE
417  #define XBEE_SERIAL_MAX_BAUDRATE 115200
418 #endif
419 
420 // Default method for specifying an unused parameter (to avoid compiler
421 // warnings) is to cast it to void. If this method doesn't work for a platform
422 // or actually generates code, that platform's header file should define it
423 // as nothing.
424 #ifndef XBEE_UNUSED_PARAMETER
425  #define XBEE_UNUSED_PARAMETER(p) (void) p
426 #endif
427 
428 // Following in the standard set by inttypes.h, use fprintf macro PRIsFAR for
429 // printing far strings (will be just "s" on most platforms).
430 // default settings for various macros
431 #ifndef PRIsFAR
432  #define PRIsFAR "s"
433 #endif
434 #ifndef PRIpFAR
435  #define PRIpFAR "p"
436 #endif
437 #ifndef PRId16
438  #define PRId16 "hd"
439 #endif
440 #ifndef PRId32
441  #define PRId32 "ld"
442 #endif
443 #ifndef PRIu16
444  #define PRIu16 "hu"
445 #endif
446 #ifndef PRIu32
447  #define PRIu32 "lu"
448 #endif
449 #ifndef PRIx16
450  #define PRIx16 "hx"
451 #endif
452 #ifndef PRIx32
453  #define PRIx32 "lx"
454 #endif
455 #ifndef PRIX16
456  #define PRIX16 "hX"
457 #endif
458 #ifndef PRIX32
459  #define PRIX32 "lX"
460 #endif
461 
462 
463 #ifndef XBEE_RESET_FN
464  #define XBEE_RESET_FN NULL
465 #endif
466 #ifndef XBEE_IS_AWAKE_FN
467  #define XBEE_IS_AWAKE_FN NULL
468 #endif
469 
471 #define _TABLE_ENTRIES(array) ((sizeof (array)) / (sizeof (*array)))
472 
474 
496 
516 
532 int hexstrtobyte( const char FAR *p);
533 
534 
555 int xbee_readline( char *buffer, int length);
556 
572 void hex_dump( const void FAR *address, uint16_t length, uint16_t flags);
578 #define HEX_DUMP_FLAG_NONE 0x0000
580 #define HEX_DUMP_FLAG_OFFSET 0x0001
582 #define HEX_DUMP_FLAG_ADDRESS 0x0002
584 #define HEX_DUMP_FLAG_TAB 0x0004
586 
588 
604 int memcheck( const void FAR *src, int c, size_t length);
605 
629 #define XBEE_TIMER_COMPARE( a, op, b) \
630  ( ((int16_t)((uint16_t)(a) - (uint16_t)(b))) op 0 )
631 
661 #define XBEE_SET_TIMEOUT_MS(delay) \
662  ((uint16_t)xbee_millisecond_timer() + (delay))
663 
677 #define XBEE_CHECK_TIMEOUT_MS(timer) \
678  ((int16_t)((uint16_t)xbee_millisecond_timer() - (timer)) >= 0)
679 
680 
710 #define XBEE_SET_TIMEOUT_SEC(delay) ((uint16_t)xbee_seconds_timer() + (delay))
711 
725 #define XBEE_CHECK_TIMEOUT_SEC(timer) \
726  ((int16_t)((uint16_t)xbee_seconds_timer() - (timer)) >= 0)
727 
728 // include support for 64-bit integers
729 #include "xbee/jslong_glue.h"
730 
732 
733 #endif
734 
unsigned long uint32_t
32-bit unsigned integer
Definition: platform_config.h:43
#define FAR
On platforms with "far" pointers, define to the proper keyword; empty definition if not required...
Definition: platform.h:396
void hex_dump(const void FAR *address, uint16_t length, uint16_t flags)
Helper function for printing a hex dump of memory to stdout.
Definition: hexdump.c:28
int xbee_readline(char *buffer, int length)
This function is a non-blocking version of gets(), used to read a line of input from the user...
Definition: xbee_readline.c:92
#define XBEE_BEGIN_DECLS
Macro defined to.
Definition: platform.h:41
unsigned short uint16_t
16-bit unsigned integer
Definition: platform_config.h:41
int hexstrtobyte(const char FAR *p)
Converts two hex characters (0-9A-Fa-f) to a byte.
#define XBEE_END_DECLS
Macro defined to.
Definition: platform.h:42
uint32_t() xbee_millisecond_timer(void)
Platform-specific function to return the number of elapsed milliseconds.
Definition: xbee_platform_digiapix.c:45
uint32_t() xbee_seconds_timer(void)
Platform-specific function to return the number of elapsed seconds.
Definition: xbee_platform_digiapix.c:37
int memcheck(const void FAR *src, int c, size_t length)
Test whether a block of memory is set to a single byte value.
Definition: memcheck.c:21