Skip to content

Commit

Permalink
FreeRTOS support for two targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Jörg Walter committed Jun 4, 2024
1 parent 1b4bf04 commit 1a7c5a1
Show file tree
Hide file tree
Showing 41 changed files with 5,342 additions and 0 deletions.
31 changes: 31 additions & 0 deletions configurations/test/test-freertos-raspi3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ********************************************************************************
// Copyright (c) 2018, 2024 OFFIS e.V.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// SPDX-License-Identifier: EPL-2.0
//
// Contributors:
// Jörg Walter - initial implementation
// *******************************************************************************/
//

include=test-minimal.txt

ARCH=arm-none-eabi

CMAKE_BUILD_TYPE=Debug
FORTE_LOGLEVEL=LOGDEBUG

MODULE=FREERTOS_STANDALONE

FORTE_ARCHITECTURE=FreeRTOSLwIP
FORTE_FREERTOS_PLUS_TCP:BOOL=ON
DEPS=freertos-cpp11

FREERTOS_CONFIG=bcm2837
TOOLCHAIN_EXTRA_C_FLAGS:STRING=-mcpu=cortex-a7 -mfpu=vfpv3 -mthumb -mfloat-abi=hard -fexceptions -fasynchronous-unwind-tables
TOOLCHAIN_EXTRA_ASM_FLAGS:STRING=-mcpu=cortex-a7 -mfpu=vfpv3 -mthumb -mfloat-abi=hard -fexceptions -fasynchronous-unwind-tables
TOOLCHAIN_EXTRA_LINKER_FLAGS:STRING=-mcpu=cortex-a7 -mfpu=vfpv3 -mthumb -mfloat-abi=hard -fexceptions -fasynchronous-unwind-tables
31 changes: 31 additions & 0 deletions configurations/test/test-freertos-zynq.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ********************************************************************************
// Copyright (c) 2018, 2024 OFFIS e.V.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// SPDX-License-Identifier: EPL-2.0
//
// Contributors:
// Jörg Walter - initial implementation
// *******************************************************************************/
//

include=test-minimal.txt

ARCH=arm-none-eabi

CMAKE_BUILD_TYPE=Debug
FORTE_LOGLEVEL=LOGDEBUG

MODULE=FREERTOS_STANDALONE
COM=ETH

FORTE_ARCHITECTURE=FreeRTOSLwIP
DEPS=freertos-cpp11

FREERTOS_CONFIG=zynq7000
TOOLCHAIN_EXTRA_C_FLAGS:STRING=-mcpu=cortex-a9 -mfpu=vfpv3 -mthumb -mfloat-abi=hard -fexceptions -fasynchronous-unwind-tables
TOOLCHAIN_EXTRA_ASM_FLAGS:STRING=-mcpu=cortex-a9 -mfpu=vfpv3 -mthumb -mfloat-abi=hard -fexceptions -fasynchronous-unwind-tables
TOOLCHAIN_EXTRA_LINKER_FLAGS:STRING=-mcpu=cortex-a9 -mfpu=vfpv3 -mthumb -mfloat-abi=hard -fexceptions -fasynchronous-unwind-tables
132 changes: 132 additions & 0 deletions dependencies/recipes/freertos-cpp11/bugfix.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
diff --git a/newlib/libc/include/limits.h b/newlib/libc/include/limits.h
index e05a6795f..dc26e2870 100644
--- a/newlib/libc/include/limits.h
+++ b/newlib/libc/include/limits.h
@@ -128,6 +128,35 @@

#endif /* !_LIBC_LIMITS_H_ */

+# ifndef __LONG_LONG_MAX__
+# define __LONG_LONG_MAX__ 9223372036854775807LL
+# endif
+
+# if __ISO_C_VISIBLE >= 1999
+/* Minimum and maximum values a `signed long long int' can hold. */
+# undef LLONG_MIN
+# define LLONG_MIN (-LLONG_MAX-1)
+# undef LLONG_MAX
+# define LLONG_MAX __LONG_LONG_MAX__
+
+/* Maximum value an `unsigned long long int' can hold. (Minimum is 0). */
+# undef ULLONG_MAX
+# define ULLONG_MAX (LLONG_MAX * 2ULL + 1)
+# endif
+
+# if __GNU_VISIBLE
+/* Minimum and maximum values a `signed long long int' can hold. */
+# undef LONG_LONG_MIN
+# define LONG_LONG_MIN (-LONG_LONG_MAX-1)
+# undef LONG_LONG_MAX
+# define LONG_LONG_MAX __LONG_LONG_MAX__
+
+/* Maximum value an `unsigned long long int' can hold. (Minimum is 0). */
+# undef ULONG_LONG_MAX
+# define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1)
+# endif
+
+
#if defined __GNUC__ && !defined _GCC_LIMITS_H_
/* `_GCC_LIMITS_H_' is what GCC's file defines. */
#ifdef __clang__
diff --git a/newlib/libc/include/sys/_types.h b/newlib/libc/include/sys/_types.h
index 76ac27fd1..5bb076e5a 100644
--- a/newlib/libc/include/sys/_types.h
+++ b/newlib/libc/include/sys/_types.h
@@ -204,7 +204,7 @@ typedef struct
int __count;
union
{
- wint_t __wch;
+ unsigned __wch;
unsigned char __wchb[4];
} __value; /* Value so far. */
} _mbstate_t;
diff --git a/newlib/libc/include/wchar.h b/newlib/libc/include/wchar.h
index 8a9c4b0fe..461b2a767 100644
--- a/newlib/libc/include/wchar.h
+++ b/newlib/libc/include/wchar.h
@@ -96,6 +96,12 @@ struct tm;
typedef _mbstate_t mbstate_t;
#endif /* _MBSTATE_T */

+#ifndef _WINT_T
+#define _WINT_T
+typedef unsigned wint_t;
+#endif
+
+
wint_t btowc (int);
int wctob (wint_t);
size_t mbrlen (const char *__restrict, size_t, mbstate_t *__restrict);
@@ -223,7 +223,7 @@
long double wcstold_l (const wchar_t *, wchar_t **, locale_t);
#endif

-#ifndef TINY_STDIO
+#ifndef __libstdcpp_needs_these_declarations_even_with_TINY_STDIO

wint_t fgetwc (__FILE *);
wchar_t *fgetws (wchar_t *__restrict, int, __FILE *__restrict);
diff --git a/newlib/libc/include/wctype.h b/newlib/libc/include/wctype.h
index 74f7ce08a..6ab8c9422 100644
--- a/newlib/libc/include/wctype.h
+++ b/newlib/libc/include/wctype.h
@@ -28,6 +28,11 @@ typedef int wctype_t;
typedef int wctrans_t;
#endif

+#ifndef _WINT_T
+#define _WINT_T
+typedef unsigned wint_t;
+#endif
+
int iswalpha (wint_t);
int iswalnum (wint_t);
#if __ISO_C_VISIBLE >= 1999
diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-mallocr.c
index f9f443eff..273e86352 100644
--- a/newlib/libc/stdlib/nano-mallocr.c
+++ b/newlib/libc/stdlib/nano-mallocr.c
@@ -370,7 +370,6 @@ void * malloc(size_t s)
if (r == (void *)-1)
{
errno = ENOMEM;
- MALLOC_UNLOCK;
return NULL;
}
r->size = alloc_size;
diff --git a/scripts/duplicate-names b/scripts/duplicate-names
index 9cb9a3a35..bfb44825b 100755
--- a/scripts/duplicate-names
+++ b/scripts/duplicate-names
@@ -3,7 +3,7 @@ NM="$1"
FILE="$2"
OUTPUT="$3"

-"$NM" -g "$FILE" 2>/dev/null | grep ' [A-TV-Z] ' | grep -v '__x86' | sort | uniq -d > "$OUTPUT"
+"$NM" -g "$FILE" 2>/dev/null | grep ' [A-TV-Z] ' | grep -v '__x86' | grep -v '__gnu_lto' | sort | uniq -d > "$OUTPUT"
if [ -e "$OUTPUT" -a -s "$OUTPUT" ]; then
echo "Duplicate names in ${FILE}"
cat "$OUTPUT"
--- a/newlib/libc/tinystdio/stdio.h 2021-03-10 00:18:06.988604044 +0100
+++ b/newlib/libc/tinystdio/stdio.h 2021-04-15 14:04:32.013831368 +0200
@@ -857,6 +857,9 @@
*/
extern int sscanf(const char *__buf, const char *__fmt, ...) __FORMAT_ATTRIBUTE__(scanf, 2, 3);

+/* dummy declaration for libstdc++, not actually implemented */
+extern int vsscanf(const char *__buf, const char *__fmt, va_list __ap) __FORMAT_ATTRIBUTE__(scanf, 2, 0);
+
/**
Flush \c stream.

40 changes: 40 additions & 0 deletions dependencies/recipes/freertos-cpp11/build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#********************************************************************************
# Copyright (c) 2018, 2024 OFFIS e.V.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Jörg Walter - initial implementation
# *******************************************************************************/
#

cmake_minimum_required(VERSION 3.13)
project(freertos-cpp11 LANGUAGES C CXX VERSION 0.0.20210419)

include(toolchain-utils)

find_package(freertos REQUIRED)

add_library(freertos-cpp11
FreeRTOS/cpp11_gcc/freertos_time.cpp
FreeRTOS/cpp11_gcc/gthr_key.cpp
FreeRTOS/cpp11_gcc/thread.cpp

${CGET_RECIPE_DIR}/extra.cpp
)
target_link_libraries(freertos-cpp11 PUBLIC freertos::freertos-core)
target_link_options(freertos-cpp11 INTERFACE -Wl,--undefined=__override_libstdcpp_hack)
target_compile_definitions(freertos-cpp11 PUBLIC -D_GLIBCXX_HAS_GTHREADS=1)
target_compile_definitions(freertos-cpp11 PUBLIC -DpdTICKS_TO_MS=)
target_include_directories(freertos-cpp11 PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/FreeRTOS/cpp11_gcc)

install(TARGETS freertos-cpp11
EXPORT freertos-cpp11
DESTINATION lib)

install_export_config()
16 changes: 16 additions & 0 deletions dependencies/recipes/freertos-cpp11/extra.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <FreeRTOS.h>
#include <task.h>
#include <debug-printf.h>

int __override_libstdcpp_hack;

/* libstdc++ adaption, prevent using the version that uses newlib's puts(),
* because that cannot be overridden by any other libc (like picolibc) */
namespace __gnu_cxx {
void __verbose_terminate_handler() {
taskENTER_CRITICAL_FROM_ISR();
debug_printf("*** TERMINATE CALLED ***\n");

for(;;);
}
}
1 change: 1 addition & 0 deletions dependencies/recipes/freertos-cpp11/package.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grygorek/FreeRTOS_cpp11@21300eb04c7598da4d06b6bfc373ffc027aef5c3 -X build.cmake -H sha256:9f0ec488d6845f491e614c3ddd2f06adede64adbf9f91ba0c955c20aed5b4f28
1 change: 1 addition & 0 deletions dependencies/recipes/freertos-cpp11/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
freertos
57 changes: 57 additions & 0 deletions dependencies/recipes/freertos/bcm2837/bcm2837-setup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/********************************************************************************
# Copyright (c) 2020, 2024 OFFIS e.V.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Jörg Walter - initial implementation
# *******************************************************************************/

#include <stdint.h>
#include <FreeRTOS.h>
#include <interrupts.h>

#define qa7reg(x) (*((volatile int32_t*)(((uintptr_t)(0x40000000))+(x))))

#define qa7route qa7reg(0x24)
#define qa7control qa7reg(0x34)
#define qa7clear qa7reg(0x38)
#define qa7c0control qa7reg(0x40)

#define qa7hz_to_cnt(x) (38400000/(x))
#define qa7control_timer_enable (1<<28)
#define qa7control_int_enable (1<<29)

#define qa7clear_int (1<<31)
#define qa7clear_cnt (1<<30)

#define qa7ccontrol_nCNTPSIRQ (1<<0)
#define qa7ccontrol_nCNTPNSIRQ (1<<1)
#define qa7ccontrol_nCNTPSIRQ_FIQ (1<<4)
#define qa7ccontrol_nCNTPNSIRQ_FIQ (1<<5)

int ulPortYieldRequired = 0;

__attribute__((no_instrument_function))
void vLocalTickISR()
{
ulPortYieldRequired = xTaskIncrementTick();

qa7clear = qa7clear_int;
}


void prvSetupLocalTimerInterrupt( void ) {
qa7route = 0; // core 0
qa7control = qa7hz_to_cnt(1000) | qa7control_timer_enable | qa7control_int_enable;

qa7clear = qa7clear_int | qa7clear_cnt;

qa7c0control &= ~qa7ccontrol_nCNTPNSIRQ_FIQ;
qa7c0control |= qa7ccontrol_nCNTPNSIRQ;
}
/*-----------------------------------------------------------*/
Loading

0 comments on commit 1a7c5a1

Please sign in to comment.