DroneCAN add socketcan support, rename to DroneCAN

Rename canardv1 to OpenCyphal

Apply suggestions from code review

Co-authored-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Peter van der Perk 2023-01-31 16:35:23 +01:00 committed by Xiang Xiao
parent e935f153bc
commit fa26bab6b2
22 changed files with 349 additions and 226 deletions

View file

@ -1 +0,0 @@
/libcanard-*

View file

@ -1,27 +0,0 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config CANUTILS_LIBCANARDV0
bool "libcanard UAVCAN v0 Library"
default n
depends on CAN && CAN_EXTID
---help---
Enable the libcanard UAVCAN v0 library.
if CANUTILS_LIBCANARDV0
config LIBCANARDV0_URL
string "libcanard URL"
default "https://github.com/UAVCAN/libcanard/archive"
---help---
libcanard URL.
config LIBCANARDV0_VERSION
string "libcanard Version"
default "5ad65c6a4efda60cda7a8f0512da0f465822bbb8"
---help---
libcanard version.
endif

View file

@ -1,71 +0,0 @@
############################################################################
# apps/canutils/libcanardv0/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(APPDIR)/Make.defs
UNPACK = unzip
PACKEXT = .zip
LIBCANARDV0_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBCANARDV0_URL)))
LIBCANARDV0_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBCANARDV0_VERSION)))
LIBCANARDV0_UNPACKNAME = libcanard-$(LIBCANARDV0_VERSION)
LIBCANARDV0_PACKNAME = $(LIBCANARDV0_UNPACKNAME)$(PACKEXT)
LIBCANARDV0_SRCDIR = $(LIBCANARDV0_UNPACKNAME)
LIBCANARDV0_DRVDIR = $(LIBCANARDV0_SRCDIR)$(DELIM)drivers$(DELIM)nuttx
APPS_INCDIR = $(APPDIR)$(DELIM)include$(DELIM)canutils
CFLAGS += -std=c99 -DCANARD_ASSERT=DEBUGASSERT
CFLAGS += ${INCDIR_PREFIX}$(APPS_INCDIR)
CSRCS = $(LIBCANARDV0_SRCDIR)$(DELIM)canard.c $(LIBCANARDV0_DRVDIR)$(DELIM)canard_nuttx.c
$(LIBCANARDV0_PACKNAME):
@echo "Downloading: $@"
$(Q) curl -o $@ -L $(LIBCANARDV0_URL)$(DELIM)$(LIBCANARDV0_VERSION)$(PACKEXT)
$(LIBCANARDV0_UNPACKNAME): $(LIBCANARDV0_PACKNAME)
@echo "Unpacking: $< -> $@"
$(call DELDIR, $@)
$(Q) $(UNPACK) $<
$(Q) touch $@
$(LIBCANARDV0_SRCDIR)$(DELIM)canard.h: $(LIBCANARDV0_UNPACKNAME)
$(LIBCANARDV0_DRVDIR)$(DELIM)canard_nuttx.h: $(LIBCANARDV0_UNPACKNAME)
$(APPS_INCDIR)$(DELIM)canard.h: $(LIBCANARDV0_SRCDIR)$(DELIM)canard.h
$(Q) cp $< $@
$(APPS_INCDIR)$(DELIM)canard_nuttx.h: $(LIBCANARDV0_DRVDIR)$(DELIM)canard_nuttx.h
$(Q) cp $< $@
context:: $(APPS_INCDIR)$(DELIM)canard.h $(APPS_INCDIR)$(DELIM)canard_nuttx.h
clean::
$(foreach OBJ, $(OBJS), $(call DELFILE, $(OBJ)))
distclean::
$(call DELFILE, $(APPS_INCDIR)$(DELIM)canard.h)
$(call DELFILE, $(APPS_INCDIR)$(DELIM)canard_nuttx.h)
$(call DELDIR, $(LIBCANARDV0_UNPACKNAME))
$(call DELFILE, $(LIBCANARDV0_PACKNAME))
include $(APPDIR)/Application.mk

View file

@ -1,2 +0,0 @@
/libcanard-*
/o1heap-*

2
canutils/libdronecan/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/libcanard
/*.zip

View file

@ -0,0 +1,37 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config CANUTILS_LIBDRONECAN
bool "libcanard DroneCAN Library"
default n
depends on (CAN && CAN_EXTID) || NET_CAN
---help---
Enable the libcanard DroneCAN library.
if CANUTILS_LIBDRONECAN
config LIBDRONECAN_URL
string "libcanard URL"
default "https://github.com/dronecan/libcanard/archive"
---help---
libcanard URL.
config LIBDRONECAN_VERSION
string "libcanard Version"
default "21f2a73df86886101e254d02cfc2277cd2a15717"
---help---
libcanard version.
config LIBDRONECAN_CANFD
bool "(Experimental) libcanard CAN FD Support"
default n
depends on NET_CAN_CANFD && EXPERIMENTAL
---help---
libcanard CAN FD support.
Adds support for CAN FD, this is still experimental
since libcanard doesn't support runtime switching
between CAN2.0B and CAN FD that well
endif

View file

@ -1,5 +1,5 @@
############################################################################
# apps/canutils/libcanardv0/Make.defs
# apps/canutils/libdronecan/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
@ -18,6 +18,12 @@
#
############################################################################
ifneq ($(CONFIG_CANUTILS_LIBCANARDV0),)
CONFIGURED_APPS += $(APPDIR)/canutils/libcanardv0
ifneq ($(CONFIG_CANUTILS_LIBDRONECAN),)
CONFIGURED_APPS += $(APPDIR)/canutils/libdronecan
ifeq ($(CONFIG_NET_CAN),y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libdronecan/libcanard/drivers/socketcan
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libdronecan/libcanard/drivers/socketcan
endif
endif

View file

@ -0,0 +1,83 @@
############################################################################
# apps/canutils/libdronecan/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(APPDIR)/Make.defs
WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'}
UNPACK = unzip
PACKEXT = .zip
LIBDRONECAN_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBDRONECAN_URL)))
LIBDRONECAN_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBDRONECAN_VERSION)))
LIBDRONECAN_PACKNAME = $(LIBDRONECAN_UNPACKNAME)$(PACKEXT)
LIBDRONECAN_UNPACKNAME = libcanard-$(LIBDRONECAN_VERSION)
LIBDRONECAN_SRCNAME = libcanard
LIBDRONECAN_SRCDIR = $(WD)/$(LIBDRONECAN_SRCNAME)
LIBDRONECAN_DRVDIR = $(LIBDRONECAN_SRCDIR)$(DELIM)drivers$(DELIM)nuttx
LIBDRONECAN_SOCKETCANDIR = $(LIBDRONECAN_SRCDIR)$(DELIM)drivers$(DELIM)socketcan
# Conflict with Cyphal's libcanard
ifeq ($(CONFIG_CANUTILS_LIBOPENCYPHAL),y)
CFLAGS += -DcanardInit=dronecanardInit
endif
CFLAGS += -std=c99 -DCANARD_ASSERT=DEBUGASSERT
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libdronecan/libcanard
ifeq ($(CONFIG_LIBDRONECAN_CANFD),y)
CFLAGS += -DCANARD_ENABLE_CANFD=1
endif
CSRCS = $(LIBDRONECAN_SRCDIR)$(DELIM)canard.c
ifeq ($(CONFIG_NET_CAN),y)
CSRCS += $(LIBDRONECAN_SOCKETCANDIR)$(DELIM)socketcan.c
else
CSRCS += $(LIBDRONECAN_DRVDIR)$(DELIM)canard_nuttx.c
endif
# Download and unpack tarball if no git repo found
ifeq ($(wildcard $(LIBDRONECAN_SRCNAME)/.git),)
$(LIBDRONECAN_PACKNAME):
@echo "Downloading: $@"
$(Q) curl -o $@ -L $(LIBDRONECAN_URL)$(DELIM)$(LIBDRONECAN_VERSION)$(PACKEXT)
$(LIBDRONECAN_SRCNAME): $(LIBDRONECAN_PACKNAME)
@echo "Unpacking: $< -> $@"
$(call DELDIR, $@)
$(Q) $(UNPACK) $<
$(Q) mv $(LIBDRONECAN_UNPACKNAME) $(LIBDRONECAN_SRCNAME)
$(Q) touch $@
$(LIBDRONECAN_SRCDIR)$(DELIM)canard.c: $(LIBDRONECAN_SRCNAME)
endif
context:: $(LIBDRONECAN_SRCNAME)
distclean::
ifeq ($(wildcard $(LIBDRONECAN_SRCNAME)/.git),)
$(call DELDIR, $(LIBDRONECAN_SRCNAME))
$(call DELFILE, $(LIBDRONECAN_PACKNAME))
endif
include $(APPDIR)/Application.mk

3
canutils/libopencyphal/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/libcanard
/o1heap
/*.zip

View file

@ -3,22 +3,22 @@
# see the file kconfig-language.txt in the NuttX tools repository.
#
config CANUTILS_LIBCANARDV1
bool "libcanard UAVCAN v1 Library"
config CANUTILS_LIBOPENCYPHAL
bool "libcanard OpenCyphal Cyphal/CAN Library"
default n
depends on NET_CAN && ALLOW_MIT_COMPONENTS
---help---
Enable the libcanard UAVCAN v1 library.
Enable the OpenCyphal Cyphal/CAN library.
if CANUTILS_LIBCANARDV1
if CANUTILS_LIBOPENCYPHAL
config LIBCANARDV1_URL
config LIBOPENCYPHAL_URL
string "libcanard URL"
default "https://github.com/UAVCAN/libcanard/archive"
default "https://github.com/OpenCyphal/libcanard/archive"
---help---
libcanard URL.
config LIBCANARDV1_VERSION
config LIBOPENCYPHAL_VERSION
string "libcanard Version"
default "cde670347425023480a1417fcd603b27c8eb06c1"
---help---
@ -28,12 +28,12 @@ config O1HEAP_URL
string "O(1) heap URL"
default "https://github.com/pavel-kirienko/o1heap/archive"
---help---
libcanard URL.
O(1) heap allocator URL.
config O1HEAP_VERSION
string "O(1) heap Version"
default "b21b069e4b971d3016dd232784faca6f7d9fd724"
---help---
libcanard version.
O(1) heap allocator version.
endif

View file

@ -1,5 +1,5 @@
############################################################################
# apps/canutils/libcanardv1/Make.defs
# apps/canutils/libopencyphal/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
@ -18,6 +18,10 @@
#
############################################################################
ifneq ($(CONFIG_CANUTILS_LIBCANARDV1),)
CONFIGURED_APPS += $(APPDIR)/canutils/libcanardv1
ifneq ($(CONFIG_CANUTILS_LIBOPENCYPHAL),)
CONFIGURED_APPS += $(APPDIR)/canutils/libopencyphal
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libopencyphal/o1heap/o1heap
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/canutils/libopencyphal/o1heap/o1heap
endif

View file

@ -1,5 +1,5 @@
############################################################################
# apps/canutils/libcanardv1/Makefile
# apps/canutils/libopencyphal/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
@ -20,81 +20,72 @@
include $(APPDIR)/Make.defs
WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'}
UNPACK = unzip
PACKEXT = .zip
LIBCANARDV1_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBCANARDV1_URL)))
LIBCANARDV1_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBCANARDV1_VERSION)))
LIBCANARDV1_UNPACKNAME = libcanard-$(LIBCANARDV1_VERSION)
LIBCANARDV1_PACKNAME = $(LIBCANARDV1_UNPACKNAME)$(PACKEXT)
LIBCANARDV1_SRCDIR = $(LIBCANARDV1_UNPACKNAME)
LIBCANARDV1_DRVDIR = $(LIBCANARDV1_SRCDIR)$(DELIM)libcanard
LIBOPENCYPHAL_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBOPENCYPHAL_URL)))
LIBOPENCYPHAL_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBOPENCYPHAL_VERSION)))
LIBOPENCYPHAL_PACKNAME = $(LIBOPENCYPHAL_UNPACKNAME)$(PACKEXT)
LIBOPENCYPHAL_UNPACKNAME = libcanard-$(LIBOPENCYPHAL_VERSION)
LIBOPENCYPHAL_SRCNAME = libcanard
LIBOPENCYPHAL_SRCDIR = $(WD)/$(LIBOPENCYPHAL_SRCNAME)
LIBOPENCYPHAL_DRVDIR = $(LIBOPENCYPHAL_SRCDIR)$(DELIM)libcanard
O1HEAP_URL = $(patsubst "%",%,$(strip $(CONFIG_O1HEAP_URL)))
O1HEAP_VERSION = $(patsubst "%",%,$(strip $(CONFIG_O1HEAP_VERSION)))
O1HEAP_UNPACKNAME = o1heap-$(O1HEAP_VERSION)
O1HEAP_PACKNAME = $(O1HEAP_UNPACKNAME)$(PACKEXT)
O1HEAP_SRCDIR = $(O1HEAP_UNPACKNAME)
O1HEAP_UNPACKNAME = o1heap-$(O1HEAP_VERSION)
O1HEAP_SRCNAME = o1heap
O1HEAP_SRCDIR = $(WD)/$(O1HEAP_SRCNAME)
O1HEAP_DRVDIR = $(O1HEAP_SRCDIR)$(DELIM)o1heap
APPS_INCDIR = $(APPDIR)$(DELIM)include$(DELIM)canutils
CFLAGS += -std=c11 -DCANARD_ASSERT=DEBUGASSERT -DCANARD_DSDL_CONFIG_LITTLE_ENDIAN=1
CFLAGS += ${INCDIR_PREFIX}$(APPS_INCDIR)
CSRCS = $(LIBCANARDV1_DRVDIR)$(DELIM)canard.c $(LIBCANARDV1_DRVDIR)$(DELIM)canard_dsdl.c
CSRCS = $(LIBOPENCYPHAL_DRVDIR)$(DELIM)canard.c $(LIBOPENCYPHAL_DRVDIR)$(DELIM)canard_dsdl.c
CSRCS += $(O1HEAP_DRVDIR)$(DELIM)o1heap.c
$(LIBCANARDV1_PACKNAME):
ifeq ($(wildcard $(LIBOPENCYPHAL_SRCNAME)/.git),)
$(LIBOPENCYPHAL_PACKNAME):
@echo "Downloading: $@"
$(Q) curl -o $@ -L $(LIBCANARDV1_URL)$(DELIM)$(LIBCANARDV1_VERSION)$(PACKEXT)
$(Q) curl -o $@ -L $(LIBOPENCYPHAL_URL)$(DELIM)$(LIBOPENCYPHAL_VERSION)$(PACKEXT)
$(LIBCANARDV1_UNPACKNAME): $(LIBCANARDV1_PACKNAME)
$(LIBOPENCYPHAL_SRCNAME): $(LIBOPENCYPHAL_PACKNAME)
@echo "Unpacking: $< -> $@"
$(call DELDIR, $@)
$(Q) $(UNPACK) $<
$(Q) mv $(LIBOPENCYPHAL_UNPACKNAME) $(LIBOPENCYPHAL_SRCNAME)
$(Q) touch $@
$(LIBOPENCYPHAL_DRVDIR)$(DELIM)canard.c: $(LIBOPENCYPHAL_SRCNAME)
endif
ifeq ($(wildcard $(O1HEAP_SRCNAME)/.git),)
$(O1HEAP_PACKNAME):
@echo "Downloading: $@"
$(Q) curl -o $@ -L $(O1HEAP_URL)$(DELIM)$(O1HEAP_VERSION)$(PACKEXT)
$(O1HEAP_UNPACKNAME): $(O1HEAP_PACKNAME)
$(O1HEAP_SRCNAME): $(O1HEAP_PACKNAME)
@echo "Unpacking: $< -> $@"
$(call DELDIR, $@)
$(Q) $(UNPACK) $<
$(Q) mv $(O1HEAP_UNPACKNAME) $(O1HEAP_SRCNAME)
$(Q) touch $@
$(LIBCANARDV1_DRVDIR)$(DELIM)canard.h: $(LIBCANARDV1_UNPACKNAME)
$(O1HEAP_DRVDIR)$(DELIM)o1heap.c: $(O1HEAP_SRCNAME)
endif
$(LIBCANARDV1_DRVDIR)$(DELIM)canard_dsdl.h: $(LIBCANARDV1_UNPACKNAME)
$(O1HEAP_DRVDIR)$(DELIM)o1heap.h: $(O1HEAP_UNPACKNAME)
$(APPS_INCDIR)$(DELIM)canard.h: $(LIBCANARDV1_DRVDIR)$(DELIM)canard.h
$(Q) cp $< $@
$(APPS_INCDIR)$(DELIM)canard_dsdl.h: $(LIBCANARDV1_DRVDIR)$(DELIM)canard_dsdl.h
$(Q) cp $< $@
$(APPS_INCDIR)$(DELIM)o1heap.h: $(O1HEAP_DRVDIR)$(DELIM)o1heap.h
$(Q) cp $< $@
context:: $(APPS_INCDIR)$(DELIM)canard.h $(APPS_INCDIR)$(DELIM)canard_dsdl.h $(APPS_INCDIR)$(DELIM)o1heap.h
clean::
$(foreach OBJ, $(OBJS), $(call DELFILE, $(OBJ)))
context:: $(LIBOPENCYPHAL_SRCNAME) $(O1HEAP_SRCNAME)
distclean::
$(call DELFILE, $(APPS_INCDIR)$(DELIM)canard.h)
$(call DELFILE, $(APPS_INCDIR)$(DELIM)canard_dsdl.h)
$(call DELDIR, $(LIBCANARDV1_UNPACKNAME))
$(call DELFILE, $(LIBCANARDV1_PACKNAME))
$(call DELDIR, $(O1HEAP_UNPACKNAME))
$(call DELFILE, $(O1HEAP_PACKNAME))
$(call DELFILE, $(APPS_INCDIR)$(DELIM)o1heap.h)
$(call DELDIR, $(O1HEAP_UNPACKNAME))
$(call DELDIR, $(LIBOPENCYPHAL_SRCNAME))
$(call DELFILE, $(LIBOPENCYPHAL_PACKNAME))
$(call DELDIR, $(O1HEAP_SRCNAME))
$(call DELFILE, $(O1HEAP_PACKNAME))
include $(APPDIR)/Application.mk