diff --git a/ports/zephyr/main.c b/ports/zephyr/main.c new file mode 100644 index 00000000..0b313826 --- /dev/null +++ b/ports/zephyr/main.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2020 Legrand North America, Inc. + * + * SPDX-License-Identifier: MIT + */ + +/* Standard includes */ +#include + +/* Zephyr includes */ +#include +#include +#include +#include +#include + +#include +LOG_MODULE_REGISTER(bacnet); + +/* To do: init() + +static int init(struct device *unused) +{ + ARG_UNUSED(unused); + + return 0; +} + +SYS_INIT(init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); + +*/ diff --git a/west.yml b/west.yml index f0a96fb0..a4bee39f 100644 --- a/west.yml +++ b/west.yml @@ -8,7 +8,7 @@ # # west config manifest.path # -# e.g. west config manifest.path zephyr/manifests/nrf5 +# e.g. west config manifest.path bacnet-stack/zephyr/manifests/zp/zephyr # NOTE: Since the schema requires at least one project name, # the mapping of this repository must be described as a project diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt new file mode 100644 index 00000000..7a46cbde --- /dev/null +++ b/zephyr/CMakeLists.txt @@ -0,0 +1,103 @@ +cmake_minimum_required(VERSION 3.10 FATAL_ERROR) + +# Detect the platform reliably +if(ZEPHYR_BASE) + if (NOT CONFIG_BACNETSTACK) + return() + endif() + set(ZEPHYR YES) +else() + message(FATAL_ERROR "ZEPHYR_BASE needs to be defined for Zephyr builds") +endif() + +# +# options managed through Kconfig and use names CONFIG_* +# + +set(BACNET_PROTOCOL_REVISION 19) + +message(STATUS "BACNETSTACK: using cmake ${CMAKE_VERSION}") +message(STATUS "BACNETSTACK: CMAKE_C_COMPILER_ID \"${CMAKE_C_COMPILER_ID}\"") +message(STATUS "BACNETSTACK: CMAKE_C_COMPILER_VERSION \"${CMAKE_C_COMPILER_VERSION}\"") +message(STATUS "BACNETSTACK: CMAKE_CXX_COMPILER_ID \"${CMAKE_CXX_COMPILER_ID}\"") +message(STATUS "BACNETSTACK: CMAKE_CXX_COMPILER_VERSION \"${CMAKE_CXX_COMPILER_VERSION}\"") +message(STATUS "BACNETSTACK: CMAKE_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\"") +message(STATUS "BACNETSTACK: BACNET_PROTOCOL_REVISION \"${BACNET_PROTOCOL_REVISION}\"") +message(STATUS "BACNETSTACK: BACDL_BIP6 \"${CONFIG_BACDL_BIP6}\"") +message(STATUS "BACNETSTACK: BACDL_BIP \"${CONFIG_BACDL_BIP}\"") +message(STATUS "BACNETSTACK: BACDL_ARCNET \"${CONFIG_BACDL_ARCNET}\"") +message(STATUS "BACNETSTACK: BACDL_MSTP \"${CONFIG_BACDL_MSTP}\"") +message(STATUS "BACNETSTACK: BACDL_ETHERNET \"${CONFIG_BACDL_ETHERNET}\"") +message(STATUS "BACNETSTACK: BACDL_NONE \"${CONFIG_BACDL_NONE}\"") + +#Do not allow in source builds +set(CMAKE_DISABLE_SOURCE_CHANGES ON) +set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) + +# +# sources +# +set(BACNETSTACK_SRCS + ) + +# +# add ports +# + +set(BACNETSTACK_PORT_DIRECTORY_PATH "") + +message(STATUS "BACNETSTACK: building for Zephyr") +set(BACNETSTACK_PORT ${CMAKE_CURRENT_LIST_DIR}/../ports/zephyr) + +list( + APPEND BACNETSTACK_SRCS + ${BACNETSTACK_PORT}/main.c + ) + + + +# +# library +# + +zephyr_library() + +zephyr_library_compile_definitions( + $<$:BACDL_BIP> + $<$:BACDL_BIP6> + $<$:BACDL_ARCNET> + $<$:BACDL_MSTP> + $<$:BACDL_ETHERNET> + $<$:BACDL_NONE> + $<$:BACNET_PROPERTY_LISTS=1> + $<$:BACNET_ROUTING> + $<$:BACAPP_PRINT_ENABLED=1> + $<$:BACAPP_SNPRINTF_ENABLED=1> + ) + +zephyr_library_sources( + ${BACNETSTACK_SRCS} + ) + +zephyr_include_directories( + ${BACNETSTACK_PORT} + ${BACNETSTACK_SRC} + ) + +target_compile_definitions( + app PRIVATE + BACNET_PROTOCOL_REVISION=${BACNET_PROTOCOL_REVISION} + $<$:BACDL_BIP> + $<$:BACDL_BIP6> + $<$:BACDL_ARCNET> + $<$:BACDL_MSTP> + $<$:BACDL_ETHERNET> + $<$:BACDL_NONE> + $<$:BACNET_PROPERTY_LISTS=1> + $<$:BACNET_ROUTING> + $<$:BACAPP_PRINT_ENABLED=1> + $<$:BACAPP_SNPRINTF_ENABLED=1> + BACNET_STACK_STATIC_DEFINE + PRINT_ENABLED=1 + ) + diff --git a/zephyr/Kconfig b/zephyr/Kconfig new file mode 100644 index 00000000..ed34d5e0 --- /dev/null +++ b/zephyr/Kconfig @@ -0,0 +1,105 @@ +# Feature configuration options for BACnet-Stack + +# Copyright (c) 2020 Legrand North America, LLC. +# SPDX-License-Identifier: MIT + +menuconfig BACNETSTACK + bool "BACnet-Stack Support" + help + This option enables the BACnet-Stack BACnet library. + +if BACNETSTACK + +module = BACNET +module-str = Log level for BACnet +module-help = Enable BACnet library to output debug messages +source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config" + +config BAC_ROUTING + bool "BACnet Routing" + help + Enable BACnet routing + +config BACNET_PROPERTY_LISTS + bool "BACnet Property Lists" + help + Enable BACnet Property Lists + +config BACDL_ETHERNET + bool "BACnet Ethernet datalink" + help + Enable BACnet Ethernet datalink + +config BACDL_MSTP + bool "BACnet MSTP datalink" + help + Enable BACnet MSTP datalink + +config BACDL_ARCNET + bool "BACnet ARCNET datalink" + help + Enable BACnet ARCNET datalink + +config BACDL_BIP + bool "BACnet BIP datalink" + help + Enable BACnet BIP datalink + +config BACDL_NONE + bool "BACnet without datalink" + help + Enable BACnet without datalink + +config BACAPP_PRINT_ENABLED + bool "BACnet app print" + help + Enable BACnet app print + +config BACAPP_SNPRINTF_ENABLED + bool "BACnet app snprintf" + help + Enable BACnet app snprintf + +config BACDL_BIP_PORT + int "BACnet IPv4 UDP port" + default 47808 + depends on BACDL_BIP + help + UDP port to listen on (default=47808) + +config BACDL_BIP_ADDRESS_INDEX + int "Address index" + depends on BACDL_BIP + default 0 + help + Select IPv4 address + +config BACDL_BIP6 + bool "BACnet BIP6" + help + Enable BACnet BIP6 + +config BACDL_BIP6_ADDRESS_INDEX + int "Unicast address index" + depends on BACDL_BIP6 + default 0 + help + Select IPv6 unicast address + +config BACDL_BIP6_MCAST_ADDRESS + string "IPv6 multicast destination" + default "FF0E::BAC0" + depends on BACDL_BIP6 + help + IPv6 multicast group address for BACNET. + +config BACDL_BIP6_PORT + int "BACnet IPv6 UDP port" + default 47808 + depends on BACDL_BIP6 + help + UDP port to listen on (default=47808) + +#rsource "subsys/Kconfig" + +endif # BACNETSTACK diff --git a/zephyr/manifests/zp/zephyr/west.yml b/zephyr/manifests/zp/zephyr/west.yml new file mode 100644 index 00000000..fa7ce6b8 --- /dev/null +++ b/zephyr/manifests/zp/zephyr/west.yml @@ -0,0 +1,22 @@ +# +# Copyright (c) 2020 Legrand North America, LLC. +# +# SPDX-License-Identifier: MIT + +# The west manifest file for upstream Zephyr Project's Zephyr repo. +# +# Usage: +# west init -m https://github.com/bacnet-stack/bacnet-stack +# west config manifest.path zephyr/manifests/zp/zephyr +# west update + +manifest: + remotes: + - name: zephyrproject-rtos + url-base: https://github.com/zephyrproject-rtos + projects: + - name: zephyr + remote: zephyrproject-rtos + revision: v2.3.0 # Latest integrated release + import: true + path: zephyr diff --git a/zephyr/module.yml b/zephyr/module.yml new file mode 100644 index 00000000..e0ec1dcd --- /dev/null +++ b/zephyr/module.yml @@ -0,0 +1,10 @@ +# +# Copyright (c) 2020 Legrand North America, LLC. +# +# SPDX-License-Identifier: MIT + +build: + cmake: zephyr + kconfig: zephyr/Kconfig +samples: + - zephyr/samples diff --git a/zephyr/samples/hello_bacnet_stack/CMakeLists.txt b/zephyr/samples/hello_bacnet_stack/CMakeLists.txt new file mode 100644 index 00000000..152d45b9 --- /dev/null +++ b/zephyr/samples/hello_bacnet_stack/CMakeLists.txt @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: MIT + +cmake_minimum_required(VERSION 3.13.1) + +get_filename_component(MY_PROJECT_BASENAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +# Find the directory of the Zephyr module +string(REGEX REPLACE + "\/zephyr\/samples\/[a-zA-Z_\-]*${MY_PROJECT_BASENAME}$" "" + MY_ZEPHYR_MODULE_SOURCE_DIR + ${CMAKE_CURRENT_SOURCE_DIR}) + +list(APPEND ZEPHYR_EXTRA_MODULES + ${MY_ZEPHYR_MODULE_SOURCE_DIR} + ) + +# Add an absolute directory path to the CMake variable +# SYSCALL_INCLUDE_DIRS. This ensures that the syscall machinery will +# be able to find the module's syscalls. +#TODO: list(APPEND SYSCALL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(${MY_PROJECT_BASENAME}) + +target_sources(app PRIVATE src/main.c) diff --git a/zephyr/samples/hello_bacnet_stack/README.rst b/zephyr/samples/hello_bacnet_stack/README.rst new file mode 100644 index 00000000..f04b817b --- /dev/null +++ b/zephyr/samples/hello_bacnet_stack/README.rst @@ -0,0 +1,33 @@ +.. _hello_bacnet_stack: + +Hello BACnet-Stack +################## + +Overview +******** + +A simple sample that can be used with any :ref:`supported board ` and +prints "Hello BACnet-Stack" to the console. + +Building and Running +******************** + +This application can be built and executed on QEMU as follows: + +.. zephyr-app-commands:: + :zephyr-app: samples/hello_bacnet_stack + :host-os: unix + :board: qemu_x86 + :goals: run + :compact: + +To build for another board, change "qemu_x86" above to that board's name. + +Sample Output +============= + +.. code-block:: console + + Hello BACnet-Stack! x86 + +Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`. diff --git a/zephyr/samples/hello_bacnet_stack/prj.conf b/zephyr/samples/hello_bacnet_stack/prj.conf new file mode 100644 index 00000000..575aeddb --- /dev/null +++ b/zephyr/samples/hello_bacnet_stack/prj.conf @@ -0,0 +1,2 @@ +# nothing here +CONFIG_BACNETSTACK=y diff --git a/zephyr/samples/hello_bacnet_stack/sample.yaml b/zephyr/samples/hello_bacnet_stack/sample.yaml new file mode 100644 index 00000000..7b6da6de --- /dev/null +++ b/zephyr/samples/hello_bacnet_stack/sample.yaml @@ -0,0 +1,15 @@ +sample: + description: Hello BACnet-Stack sample, the simplest BACnet-Stack + application + name: hello BACnet-Stack +common: + tags: introduction + harness: console + harness_config: + type: one_line + regex: + - "Hello BACnet-Stack! (.*)" +tests: + sample.basic.hello_bacnet_stack: + platform_whitelist: native_posix + tags: introduction diff --git a/zephyr/samples/hello_bacnet_stack/src/main.c b/zephyr/samples/hello_bacnet_stack/src/main.c new file mode 100644 index 00000000..cffea605 --- /dev/null +++ b/zephyr/samples/hello_bacnet_stack/src/main.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2020 Legrand North America, LLC. + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +void main(void) +{ + printk("Hello BACnet-Stack! %s\n", CONFIG_BOARD); +}