-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathgptpcommon.h
88 lines (77 loc) · 3.02 KB
/
gptpcommon.h
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
/*
* Excelfore gptp - Implementation of gPTP(IEEE 802.1AS)
* Copyright (C) 2019 Excelfore Corporation (https://excelfore.com)
*
* This file is part of Excelfore-gptp.
*
* Excelfore-gptp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Excelfore-gptp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Excelfore-gptp. If not, see
* <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>.
*/
#ifndef __GPTPCOMMON_H_
#define __GPTPCOMMON_H_
#include "gptpbasetypes.h"
#include "gptp_config.h"
/****************************************
* plaform specific definitions
****************************************/
#if defined(GHINTEGRITY)
extern int gptpClockShmUpdateFlag;
#define GH_SET_GPTP_SHM gptpClockShmUpdateFlag=1
#define GH_UNSET_GPTP_SHM gptpClockShmUpdateFlag=0
#define IS_GPTP_SHM_SET (gptpClockShmUpdateFlag==1)
#else
#define GH_SET_GPTP_SHM
#define GH_UNSET_GPTP_SHM
#define IS_GPTP_SHM_SET
#endif
/***** end of platform specific definitions *****/
void eui48to64(const uint8_t *eui48, uint8_t *eui64, const uint8_t *insert);
#define LOG_TO_NSEC(x) (((x)>=0)?UB_SEC_NS*(1<<(x)):UB_SEC_NS/(1<<-(x)))
#define GET_FLAG_BIT(x,b) ((x) & (1<<(b)))
#define SET_FLAG_BIT(x,b) x |= (1<<(b))
#define RESET_FLAG_BIT(x,b) x &= ~(1<<(b))
#define SET_RESET_FLAG_BIT(c,x,b) if(c) SET_FLAG_BIT(x,b); else RESET_FLAG_BIT(x,b)
#define SM_CLOSE(f,x) if(x) f(&x)
/* allocate typed in *sm, then allocate typesm in (*sm)->thisSM */
#define INIT_SM_DATA(typed, typesm, sm) \
if(!*sm){ \
*sm=malloc(sizeof(typed)); \
ub_assert(*sm, __func__, "malloc1"); \
} \
memset(*sm, 0, sizeof(typed)); \
(*sm)->thisSM=malloc(sizeof(typesm)); \
ub_assert((*sm)->thisSM, __func__, "malloc2"); \
memset((*sm)->thisSM, 0, sizeof(typesm)); \
/* free the above allocations */
#define CLOSE_SM_DATA(sm) \
if(!*sm) return 0; \
free((*sm)->thisSM); \
free(*sm); \
*sm=NULL;
/* check for portPriority vector, any non-zero value is sufficient */
#define HAS_PORT_PRIORITY(pp) \
(((pp).rootSystemIdentity.priority1 !=0) || \
((pp).rootSystemIdentity.clockClass != 0) || \
((pp).rootSystemIdentity.clockAccuracy != 0) || \
((pp).rootSystemIdentity.offsetScaledLogVariance != 0) || \
((pp).rootSystemIdentity.priority2 != 0) || \
((pp).stepsRemoved != 0))
typedef enum {
SAME_PRIORITY,
SUPERIOR_PRIORITY,
INFERIOR_PRIORITY,
} bmcs_priority_comparison_result;
void print_priority_vector(ub_dbgmsg_level_t level, const char *identifier, UInteger224 *priorityVector);
uint8_t compare_priority_vectors(UInteger224 *priorityA, UInteger224 *priorityB);
#endif