commit
3aa72b8208
|
|
@ -4,6 +4,8 @@
|
||||||
*.la
|
*.la
|
||||||
.deps
|
.deps
|
||||||
.libs
|
.libs
|
||||||
|
.ccls-cache
|
||||||
|
compile_commands.json
|
||||||
|
|
||||||
configure
|
configure
|
||||||
libtool
|
libtool
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,8 @@ libj1939_la_SOURCES = \
|
||||||
libj1939.c
|
libj1939.c
|
||||||
|
|
||||||
can_calc_bit_timing_SOURCES = \
|
can_calc_bit_timing_SOURCES = \
|
||||||
calc-bit-timing/can-calc-bit-timing.c
|
calc-bit-timing/can-calc-bit-timing.c \
|
||||||
|
calc-bit-timing/compat.h
|
||||||
|
|
||||||
EXTRA_DIST += \
|
EXTRA_DIST += \
|
||||||
calc-bit-timing/can-calc-bit-timing-v2_6_31.c \
|
calc-bit-timing/can-calc-bit-timing-v2_6_31.c \
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* imported from v2.6.31-rc1~330^2~376
|
* imported from v2.6.31-rc1~330^2~376
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* imported from v3.18-rc1~52^2~248^2~1
|
* imported from v3.18-rc1~52^2~248^2~1
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* imported from v4.8-rc1~140^2~304^2~11
|
* imported from v4.8-rc1~140^2~304^2~11
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* imported from v5.16-rc1~159^2~104^2~13
|
* imported from v5.16-rc1~159^2~104^2~13
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* imported from v5.19-rc1~159^2~286^2~15
|
* imported from v5.19-rc1~159^2~286^2~15
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* imported from v6.3-rc1~162^2~124^2^2~1
|
* imported from v6.3-rc1~162^2~124^2^2~1
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <linux/can/netlink.h>
|
#include "compat.h"
|
||||||
#include <linux/types.h>
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
OPT_TQ = UCHAR_MAX + 1,
|
OPT_TQ = UCHAR_MAX + 1,
|
||||||
|
|
@ -41,144 +40,6 @@ enum {
|
||||||
OPT_ALG,
|
OPT_ALG,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* imported from kernel */
|
|
||||||
|
|
||||||
/* define in-kernel-types */
|
|
||||||
typedef __u64 u64;
|
|
||||||
typedef __u32 u32;
|
|
||||||
|
|
||||||
#define NSEC_PER_SEC 1000000000L
|
|
||||||
|
|
||||||
/**
|
|
||||||
* abs - return absolute value of an argument
|
|
||||||
* @x: the value. If it is unsigned type, it is converted to signed type first.
|
|
||||||
* char is treated as if it was signed (regardless of whether it really is)
|
|
||||||
* but the macro's return type is preserved as char.
|
|
||||||
*
|
|
||||||
* Return: an absolute value of x.
|
|
||||||
*/
|
|
||||||
#define abs(x) __abs_choose_expr(x, long long, \
|
|
||||||
__abs_choose_expr(x, long, \
|
|
||||||
__abs_choose_expr(x, int, \
|
|
||||||
__abs_choose_expr(x, short, \
|
|
||||||
__abs_choose_expr(x, char, \
|
|
||||||
__builtin_choose_expr( \
|
|
||||||
__builtin_types_compatible_p(typeof(x), char), \
|
|
||||||
(char)({ signed char __x = (x); __x < 0 ? -__x:__x; }), \
|
|
||||||
((void)0)))))))
|
|
||||||
|
|
||||||
#define __abs_choose_expr(x, type, other) __builtin_choose_expr( \
|
|
||||||
__builtin_types_compatible_p(typeof(x), signed type) || \
|
|
||||||
__builtin_types_compatible_p(typeof(x), unsigned type), \
|
|
||||||
({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* min()/max()/clamp() macros that also do
|
|
||||||
* strict type-checking.. See the
|
|
||||||
* "unnecessary" pointer comparison.
|
|
||||||
*/
|
|
||||||
#define min(x, y) ({ \
|
|
||||||
typeof(x) _min1 = (x); \
|
|
||||||
typeof(y) _min2 = (y); \
|
|
||||||
(void) (&_min1 == &_min2); \
|
|
||||||
_min1 < _min2 ? _min1 : _min2; })
|
|
||||||
|
|
||||||
#define max(x, y) ({ \
|
|
||||||
typeof(x) _max1 = (x); \
|
|
||||||
typeof(y) _max2 = (y); \
|
|
||||||
(void) (&_max1 == &_max2); \
|
|
||||||
_max1 > _max2 ? _max1 : _max2; })
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clamp - return a value clamped to a given range with strict typechecking
|
|
||||||
* @val: current value
|
|
||||||
* @lo: lowest allowable value
|
|
||||||
* @hi: highest allowable value
|
|
||||||
*
|
|
||||||
* This macro does strict typechecking of lo/hi to make sure they are of the
|
|
||||||
* same type as val. See the unnecessary pointer comparisons.
|
|
||||||
*/
|
|
||||||
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
|
|
||||||
|
|
||||||
#define do_div(n, base) ({ \
|
|
||||||
uint32_t __base = (base); \
|
|
||||||
uint32_t __rem; \
|
|
||||||
__rem = ((uint64_t)(n)) % __base; \
|
|
||||||
(n) = ((uint64_t)(n)) / __base; \
|
|
||||||
__rem; \
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DIV_U64_ROUND_CLOSEST - unsigned 64bit divide with 32bit divisor rounded to nearest integer
|
|
||||||
* @dividend: unsigned 64bit dividend
|
|
||||||
* @divisor: unsigned 32bit divisor
|
|
||||||
*
|
|
||||||
* Divide unsigned 64bit dividend by unsigned 32bit divisor
|
|
||||||
* and round to closest integer.
|
|
||||||
*
|
|
||||||
* Return: dividend / divisor rounded to nearest integer
|
|
||||||
*/
|
|
||||||
#define DIV_U64_ROUND_CLOSEST(dividend, divisor) \
|
|
||||||
({ u32 _tmp = (divisor); div_u64((u64)(dividend) + _tmp / 2, _tmp); })
|
|
||||||
|
|
||||||
/**
|
|
||||||
* div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder
|
|
||||||
* @dividend: unsigned 64bit dividend
|
|
||||||
* @divisor: unsigned 32bit divisor
|
|
||||||
* @remainder: pointer to unsigned 32bit remainder
|
|
||||||
*
|
|
||||||
* Return: sets ``*remainder``, then returns dividend / divisor
|
|
||||||
*
|
|
||||||
* This is commonly provided by 32bit archs to provide an optimized 64bit
|
|
||||||
* divide.
|
|
||||||
*/
|
|
||||||
static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
|
|
||||||
{
|
|
||||||
*remainder = dividend % divisor;
|
|
||||||
return dividend / divisor;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline u64 div_u64(u64 dividend, u32 divisor)
|
|
||||||
{
|
|
||||||
u32 remainder;
|
|
||||||
return div_u64_rem(dividend, divisor, &remainder);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline u64 mul_u32_u32(u32 a, u32 b)
|
|
||||||
{
|
|
||||||
return (u64)a * b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* */
|
|
||||||
|
|
||||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
|
||||||
|
|
||||||
/* we don't want to see these prints */
|
|
||||||
#define netdev_err(dev, format, arg...) do { } while (0)
|
|
||||||
#define netdev_warn(dev, format, arg...) do { } while (0)
|
|
||||||
#define NL_SET_ERR_MSG_FMT(dev, format, arg...) do { } while (0)
|
|
||||||
|
|
||||||
struct calc_ref_clk {
|
|
||||||
__u32 clk; /* CAN system clock frequency in Hz */
|
|
||||||
const char *name;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* minimal structs, just enough to be source level compatible
|
|
||||||
*/
|
|
||||||
struct can_priv {
|
|
||||||
struct can_clock clock;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct net_device {
|
|
||||||
struct can_priv priv;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct netlink_ext_ack {
|
|
||||||
u32 __dummy;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct calc_bittiming_const {
|
struct calc_bittiming_const {
|
||||||
const struct can_bittiming_const bittiming_const;
|
const struct can_bittiming_const bittiming_const;
|
||||||
const struct can_bittiming_const data_bittiming_const;
|
const struct can_bittiming_const data_bittiming_const;
|
||||||
|
|
@ -231,11 +92,6 @@ struct calc_data {
|
||||||
bool fd_mode;
|
bool fd_mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void *netdev_priv(const struct net_device *dev)
|
|
||||||
{
|
|
||||||
return (void *)&dev->priv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void print_usage(char *cmd)
|
static void print_usage(char *cmd)
|
||||||
{
|
{
|
||||||
printf("%s - calculate CAN bit timing parameters.\n", cmd);
|
printf("%s - calculate CAN bit timing parameters.\n", cmd);
|
||||||
|
|
@ -1236,12 +1092,6 @@ static const unsigned int common_data_bitrates[] = {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */
|
|
||||||
#define CAN_CALC_SYNC_SEG 1
|
|
||||||
#define CAN_SYNC_SEG 1
|
|
||||||
#define CAN_KBPS 1000
|
|
||||||
#define KILO 1000UL
|
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0 */
|
||||||
|
|
||||||
|
#ifndef _COMPAT_H
|
||||||
|
#define _COMPAT_H
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <linux/can/netlink.h>
|
||||||
|
#include <linux/types.h>
|
||||||
|
|
||||||
|
/* imported from kernel */
|
||||||
|
|
||||||
|
/* define in-kernel-types */
|
||||||
|
typedef __u64 u64;
|
||||||
|
typedef __u32 u32;
|
||||||
|
|
||||||
|
#define NSEC_PER_SEC 1000000000L
|
||||||
|
|
||||||
|
#define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */
|
||||||
|
#define CAN_CALC_SYNC_SEG 1
|
||||||
|
#define CAN_SYNC_SEG 1
|
||||||
|
#define CAN_KBPS 1000
|
||||||
|
#define KILO 1000UL
|
||||||
|
|
||||||
|
/**
|
||||||
|
* abs - return absolute value of an argument
|
||||||
|
* @x: the value. If it is unsigned type, it is converted to signed type first.
|
||||||
|
* char is treated as if it was signed (regardless of whether it really is)
|
||||||
|
* but the macro's return type is preserved as char.
|
||||||
|
*
|
||||||
|
* Return: an absolute value of x.
|
||||||
|
*/
|
||||||
|
#define abs(x) __abs_choose_expr(x, long long, \
|
||||||
|
__abs_choose_expr(x, long, \
|
||||||
|
__abs_choose_expr(x, int, \
|
||||||
|
__abs_choose_expr(x, short, \
|
||||||
|
__abs_choose_expr(x, char, \
|
||||||
|
__builtin_choose_expr( \
|
||||||
|
__builtin_types_compatible_p(typeof(x), char), \
|
||||||
|
(char)({ signed char __x = (x); __x < 0 ? -__x:__x; }), \
|
||||||
|
((void)0)))))))
|
||||||
|
|
||||||
|
#define __abs_choose_expr(x, type, other) __builtin_choose_expr( \
|
||||||
|
__builtin_types_compatible_p(typeof(x), signed type) || \
|
||||||
|
__builtin_types_compatible_p(typeof(x), unsigned type), \
|
||||||
|
({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* min()/max()/clamp() macros that also do
|
||||||
|
* strict type-checking.. See the
|
||||||
|
* "unnecessary" pointer comparison.
|
||||||
|
*/
|
||||||
|
#define min(x, y) ({ \
|
||||||
|
typeof(x) _min1 = (x); \
|
||||||
|
typeof(y) _min2 = (y); \
|
||||||
|
(void) (&_min1 == &_min2); \
|
||||||
|
_min1 < _min2 ? _min1 : _min2; })
|
||||||
|
|
||||||
|
#define max(x, y) ({ \
|
||||||
|
typeof(x) _max1 = (x); \
|
||||||
|
typeof(y) _max2 = (y); \
|
||||||
|
(void) (&_max1 == &_max2); \
|
||||||
|
_max1 > _max2 ? _max1 : _max2; })
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clamp - return a value clamped to a given range with strict typechecking
|
||||||
|
* @val: current value
|
||||||
|
* @lo: lowest allowable value
|
||||||
|
* @hi: highest allowable value
|
||||||
|
*
|
||||||
|
* This macro does strict typechecking of lo/hi to make sure they are of the
|
||||||
|
* same type as val. See the unnecessary pointer comparisons.
|
||||||
|
*/
|
||||||
|
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
|
||||||
|
|
||||||
|
#define do_div(n, base) ({ \
|
||||||
|
uint32_t __base = (base); \
|
||||||
|
uint32_t __rem; \
|
||||||
|
__rem = ((uint64_t)(n)) % __base; \
|
||||||
|
(n) = ((uint64_t)(n)) / __base; \
|
||||||
|
__rem; \
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DIV_U64_ROUND_CLOSEST - unsigned 64bit divide with 32bit divisor rounded to nearest integer
|
||||||
|
* @dividend: unsigned 64bit dividend
|
||||||
|
* @divisor: unsigned 32bit divisor
|
||||||
|
*
|
||||||
|
* Divide unsigned 64bit dividend by unsigned 32bit divisor
|
||||||
|
* and round to closest integer.
|
||||||
|
*
|
||||||
|
* Return: dividend / divisor rounded to nearest integer
|
||||||
|
*/
|
||||||
|
#define DIV_U64_ROUND_CLOSEST(dividend, divisor) \
|
||||||
|
({ u32 _tmp = (divisor); div_u64((u64)(dividend) + _tmp / 2, _tmp); })
|
||||||
|
|
||||||
|
/**
|
||||||
|
* div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder
|
||||||
|
* @dividend: unsigned 64bit dividend
|
||||||
|
* @divisor: unsigned 32bit divisor
|
||||||
|
* @remainder: pointer to unsigned 32bit remainder
|
||||||
|
*
|
||||||
|
* Return: sets ``*remainder``, then returns dividend / divisor
|
||||||
|
*
|
||||||
|
* This is commonly provided by 32bit archs to provide an optimized 64bit
|
||||||
|
* divide.
|
||||||
|
*/
|
||||||
|
static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
|
||||||
|
{
|
||||||
|
*remainder = dividend % divisor;
|
||||||
|
return dividend / divisor;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u64 div_u64(u64 dividend, u32 divisor)
|
||||||
|
{
|
||||||
|
u32 remainder;
|
||||||
|
return div_u64_rem(dividend, divisor, &remainder);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u64 mul_u32_u32(u32 a, u32 b)
|
||||||
|
{
|
||||||
|
return (u64)a * b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
|
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||||
|
|
||||||
|
/* we don't want to see these prints */
|
||||||
|
#define netdev_err(dev, format, arg...) do { } while (0)
|
||||||
|
#define netdev_warn(dev, format, arg...) do { } while (0)
|
||||||
|
#define NL_SET_ERR_MSG_FMT(dev, format, arg...) do { } while (0)
|
||||||
|
|
||||||
|
struct calc_ref_clk {
|
||||||
|
__u32 clk; /* CAN system clock frequency in Hz */
|
||||||
|
const char *name;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* minimal structs, just enough to be source level compatible
|
||||||
|
*/
|
||||||
|
struct can_priv {
|
||||||
|
struct can_clock clock;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct net_device {
|
||||||
|
struct can_priv priv;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct netlink_ext_ack {
|
||||||
|
u32 __dummy;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void *netdev_priv(const struct net_device *dev)
|
||||||
|
{
|
||||||
|
return (void *)&dev->priv;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /*_COMPAT_H */
|
||||||
Loading…
Reference in New Issue