summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/NWK/include/private/nwkSystem.h
blob: f001f90f5822fa1ae4c355f9ed7e0f4ed54bfc00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**************************************************************************//**
  \file nwkSystem.h

  \brief Network system header file.

  \author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

  \internal
   History:
    2007-06-20 V. Panov - Created.
    2009-08-16 M. Gekk  - Refactoring.
   Last change:
    $Id: nwkSystem.h 17801 2011-07-04 08:55:01Z mgekk $
 ******************************************************************************/
#if !defined _NWKSYSTEM_H
#define _NWKSYSTEM_H

/******************************************************************************
                               Includes section
 ******************************************************************************/
#include <types.h>
#include <appFramework.h>
#include <mnUtils.h>

 /******************************************************************************
                   Inline static functions prototypes section
 ******************************************************************************/
INLINE bool isCorrectExtPanId(const uint64_t panId)
{
  const uint8_t *p = (const uint8_t *)&panId;
  const uint8_t *const pend = p + sizeof(panId);
  uint16_t sum = 0U;

  do
    sum += *p;
  while (++p < pend);
  return (0U != sum) && ((8U * 0xFFU) != sum);
}

/******************************************************************************
                               Types section
 ******************************************************************************/
typedef  ShortAddr_t  NwkAddrRange_t;

/******************************************************************************
                            Definitions section
 ******************************************************************************/
/** Converting of time value from milliseconds to seconds. */
#define NWK_MSEC_TO_SEC(time) ((time) >> 10)
/** Converting of time value from seconds to milliseconds. */
#define NWK_SEC_TO_MSEC(time) ((time) << 10)

#define IS_CORRECT_BROADCAST_ADDR(A) \
  ((0xFFFFU == (A))||((0xFFFBU <= LE16_TO_CPU(A))&&(LE16_TO_CPU(A) <= 0xFFFDU)))

#define NWK_INVALID_PANID  0xFFFFU

#define CHECK_MEM_OVERLAP(dst, src, len, assert_num)         \
  assert(!(((src) < (dst))                                   \
    && ((uint8_t *)(dst) < (const uint8_t *)(src) + (len))), \
    assert_num)

#if defined UINT64_MEMCMP
  #define IS_EQ_EXT_PANID(A, B) (0 == memcmp(&(A), &(B), sizeof(uint64_t)))
  #define IS_CORRECT_EXT_PANID(P) isCorrectExtPanId(P)
  #define COPY_TO_RAW_EXT_ADDR(DST, SRC) \
    memmove((DST).raw, &(SRC), sizeof(uint64_t))
  #define COPY_FROM_RAW_EXT_ADDR(DST, SRC) \
    memmove(&(DST), (SRC).raw, sizeof(uint64_t))
  #define COPY_EXT_PANID(DST, SRC) memmove(&(DST), &(SRC), sizeof(uint64_t))
#else
  #define IS_EQ_EXT_PANID(A, B) ((A) == (B))
  #define IS_CORRECT_EXT_PANID(P) \
    ((0ULL < (P)) && ((P) < 0xFFFFFFFFFFFFFFFFULL))
  #define COPY_TO_RAW_EXT_ADDR(DST, SRC) (DST).value = (SRC)
  #define COPY_FROM_RAW_EXT_ADDR(DST, SRC) (DST) = (SRC).value
  #define COPY_EXT_PANID(DST, SRC) (DST) = (SRC)
#endif

/* Get address of any NWK table. */
#define NWK_ADDR_OF_TABLE(table) ((void **)&(table))

/* Macros are used for queue operations. */
#define NWK_DEL_QELEM(queue, type) \
  GET_PARENT_BY_FIELD(type, service.qelem, deleteHeadQueueElem(queue))

#define NWK_GET_QELEM(queue, type) \
  GET_PARENT_BY_FIELD(type, service.qelem, getQueueElem(queue))

#define NWK_NEXT_QELEM(parent, type) \
  GET_PARENT_BY_FIELD(type, service.qelem, getNextQueueElem(&(parent)->service.qelem))

#endif /* _NWKSYSTEM_H */
/** eof nwkSystem.h */