Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularization Experiments with LLEXT #112

Draft
wants to merge 3 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 70 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,75 @@
# SPDX-License-Identifier: Apache-2.0

if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${BOARD})
set(variant_dir variants/${BOARD})
elseif (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS})
set(variant_dir variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS})
else()
message(FATAL_ERROR "Variant dir not found: variants/${BOARD}, variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}")
endif()

if (CONFIG_ARDUINO_API)
add_subdirectory(cores)
add_subdirectory(libraries)
zephyr_include_directories(${variant_dir})
if (CONFIG_ARDUINO_CORE)

function(arduino_sources)
if (IS_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/variants/${BOARD})
set(variant_dir variants/${BOARD})
elseif (IS_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS})
set(variant_dir variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS})
else()
message(FATAL_ERROR "Variant dir not found: variants/${BOARD}, variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}")
endif()

set(ext_name arduino)
set(ext_bin ${ZEPHYR_BINARY_DIR}/${ext_name}.llext)
set(ext_inc ${ZEPHYR_BINARY_DIR}/include/generated/${ext_name}_ext.inc)

set(core_srcs
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/module_export.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/zephyrPrint.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/zephyrSerial.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/zephyrCommon.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/main.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/String.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/Stream.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/Common.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/Print.cpp
)

if (CONFIG_SPI)
list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/SPI/SPI.cpp)
endif()

if (CONFIG_I2C)
list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/Wire/Wire.cpp)
endif()

if (CONFIG_CAN)
list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/CanMsgRingbuffer.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/CanMsg.cpp)
endif()

if (CONFIG_USB)
list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/PluggableUSB.cpp)
endif()

if (CONFIG_NET_IP)
list(APPEND core_srcs ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/IPAddress.cpp)
endif()

add_llext_target(${ext_name}_ext
OUTPUT ${ext_bin}
SOURCES
${core_srcs}
${ARGV}
)

llext_include_directories(${ext_name}_ext
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cores/arduino/api/
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/SPI/
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/libraries/Wire/
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${variant_dir}
)

generate_inc_file_for_target(app ${ext_bin} ${ext_inc})
endfunction()

if(DEFINED CONFIG_ARDUINO_ENTRY)
target_sources(app PRIVATE cores/arduino/main_loader.c)
endif()

endif()

15 changes: 10 additions & 5 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,30 @@
# SPDX-License-Identifier: Apache-2.0
#

config ARDUINO_API
bool "ARDUINO_API"
config ARDUINO_CORE
bool "ARDUINO_CORE"
imply CPP
imply GPIO
imply I2C
imply NEWLIB_LIBC_FLOAT_PRINTF
imply CBPRINTF_FP_SUPPORT
imply RING_BUFFER
select UART_INTERRUPT_DRIVEN
default n
select LLEXT
select MODULES

if ARDUINO_CORE

if ARDUINO_API
choice LLEXT_BINARY_TYPE
default LLEXT_TYPE_ELF_RELOCATABLE
endchoice

config QEMU_ICOUNT
bool "QEMU icount mode"
default n
depends on QEMU_TARGET

config ARDUINO_API_SERIAL_BUFFER_SIZE
config ARDUINO_CORE_SERIAL_BUFFER_SIZE
int "Buffer size for Arduino Serial API"
default 64

Expand Down
3 changes: 0 additions & 3 deletions cores/CMakeLists.txt

This file was deleted.

16 changes: 0 additions & 16 deletions cores/arduino/CMakeLists.txt

This file was deleted.

57 changes: 57 additions & 0 deletions cores/arduino/api/ArduinoAPI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Arduino API main include

Check failure on line 2 in cores/arduino/api/ArduinoAPI.h

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: Block comments use * on subsequent lines
Copyright (c) 2016 Arduino LLC. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software

Check failure on line 16 in cores/arduino/api/ArduinoAPI.h

View workflow job for this annotation

GitHub Actions / checkpatch review

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Check failure on line 17 in cores/arduino/api/ArduinoAPI.h

View workflow job for this annotation

GitHub Actions / checkpatch review

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
*/

#ifndef ARDUINO_API_H
#define ARDUINO_API_H

// version 1.5.1
#define ARDUINO_API_VERSION 10501

#include "Binary.h"

#ifdef __cplusplus
#include "Interrupts.h"
#include "IPAddress.h"
#include "Print.h"
#include "Printable.h"
#include "PluggableUSB.h"
#include "Server.h"
#include "String.h"
#include "Stream.h"
#include "Udp.h"
#include "USBAPI.h"
#include "WCharacter.h"
#endif

/* Standard C library includes */
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>

// Misc Arduino core functions
#include "Common.h"

#ifdef __cplusplus
// Compatibility layer for older code
#include "Compat.h"
#endif

#endif
Loading
Loading