Skip to content
Open
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
70 changes: 70 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
cmake_minimum_required(VERSION 3.20)

# Define project name and supported languages
project(mixer-tutorial LANGUAGES C ASM)

# Specify the ARM toolchain
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)
set(ARM_TOOLCHAIN_PATH /usr/local/gcc-arm-none-eabi/gcc-arm-none-eabi-9-2020-q2-update)
set(CMAKE_C_COMPILER ${ARM_TOOLCHAIN_PATH}/bin/arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER ${ARM_TOOLCHAIN_PATH}/bin/arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER ${ARM_TOOLCHAIN_PATH}/bin/arm-none-eabi-gcc)

# Define build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

# Compiler flags for Cortex-M4F (nRF52840)
set(CPU_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CPU_FLAGS} -Wall -Werror -Wno-unused-variable -Wno-unused-function")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${CPU_FLAGS}")

add_compile_definitions(
NRF52840_XXAA
__nRF_FAMILY
ARM_MATH_CM4
FLASH_PLACEMENT=1
CONFIG_GPIO_AS_PINRESET
ASSERT_WARN_CT=0
MX_CONFIG_FILE=${CMAKE_CURRENT_SOURCE_DIR}/tutorial/nRF52840/mixer_config.h
GPI_ARCH_PLATFORM=GPI_ARCH_BOARD_TUDNES_SHEPHERD_NRF52840FRAM_V13
GPI_TRACE_MODE=GPI_TRACE_MODE_NO_TRACE
GPI_TRACE_BASE_SELECTION=GPI_TRACE_LOG_STANDARD
GPI_TRACE_BUFFER_ELEMENTS=64
)

# Include directories
include_directories(
src
src/mixer
src/gpi
tutorial/nRF52840/CMSIS_4/CMSIS/Include
tutorial/nRF52840/nRF/CMSIS/Device/Include
)

# Source files
file(GLOB_RECURSE SOURCES
"src/gpi/*.c"
"src/gpi/arm/nordic/shepherd_nrf52/*.c"
"src/mixer/*.c"
"tutorial/nRF52840/main.c"
)

# Add executable target
add_executable(${PROJECT_NAME}.elf ${SOURCES}
#tutorial/nRF52840/node_utils.h
#tutorial/nRF52840/leader.h
#tutorial/nRF52840/leader.c
#tutorial/nRF52840/follower.h
#tutorial/nRF52840/follower.c
src/gpi/arm/nordic/shepherd_nrf52/platform.c
#src/gpi/arm/nordic/shepherd_nrf52/stdio.c
)

# Post-build commands to generate HEX and BIN files
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND arm-none-eabi-objcopy -O ihex ${PROJECT_NAME}.elf ${PROJECT_NAME}.hex
COMMAND arm-none-eabi-objcopy -O binary ${PROJECT_NAME}.elf ${PROJECT_NAME}.bin
)
7 changes: 7 additions & 0 deletions src/gpi/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# see here for details:
# http://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes

# replace $Id$ in source files
*.h ident
*.c ident
13 changes: 13 additions & 0 deletions src/gpi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# GPI

NES Lab's Generic Platform Interface component (GPI) ATTENTION: This (nes-tud/gpi) is an internal project. Do not add new users without care!

Main Repo: <https://github.com/nes-lab/gpi>

GitLab Mirror: <https://gitlab.com/nes-tud/gpi>

Tutorials: <https://github.com/nes-lab/gpi-tutorial>

Example Usage: [Mixer](https://github.com/nes-lab/Mixer) or [TrafficBench](https://github.com/nes-lab/TrafficBench)

---
23 changes: 16 additions & 7 deletions src/gpi/arm/armv7-m/interrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @brief basic interrupt handling
*
* @version $Id: 2d2a1e6041b1edd60a76c899bcfb346f3ff4c1c9 $
* @version $Id$
* @date TODO
*
* @author Carsten Herrmann
Expand Down Expand Up @@ -70,12 +70,21 @@

// gpi_int_lock() locks all interrupts with priority >= GPI_ARM_INTLOCK_PRIORITY
// (use NVIC_SetPriority() to define priorities). Use 0 to lock all interrupts.
// Setting GPI_ARM_INTLOCK_PRIORITY = 0x100 causes gpi_int_lock() to have no effect.
// Setting GPI_ARM_INTLOCK_PRIORITY = 1 << __NVIC_PRIO_BITS (i.e. _GPI_ARM_INTLOCK_PRIOMASK = 0x100)
// causes gpi_int_lock() to have no effect.
// NOTE: We distinguish between GPI_ARM_INTLOCK_PRIORITY and (internal) _GPI_ARM_INTLOCK_PRIOMASK
// because CMSIS' NVIC_SetPriority() use priority values 0, 1, ..., (1 << __NVIC_PRIO_BITS) - 1,
// i.e. the shift to the MSBs is hidden internally. GPI_ARM_INTLOCK_PRIORITY should use the same
// interpretation as NVIC_SetPriority().
#ifndef GPI_ARM_INTLOCK_PRIORITY
#define GPI_ARM_INTLOCK_PRIORITY 0
#else
ASSERT_CT_STATIC(GPI_ARM_INTLOCK_PRIORITY <= 0x100, GPI_ARM_INTLOCK_PRIORITY_is_invalid);
#endif
#ifndef __NVIC_PRIO_BITS
#error "__NVIC_PRIO_BITS not defined (should come from CMSIS device header file)"
#endif
#define _GPI_ARM_INTLOCK_PRIOMASK (GPI_ARM_INTLOCK_PRIORITY << (8 - __NVIC_PRIO_BITS))

ASSERT_CT_STATIC(_GPI_ARM_INTLOCK_PRIOMASK <= 0x100, GPI_ARM_INTLOCK_PRIORITY_is_invalid);

// Since ARMv7-M there are specific instructions (load/store exclusive) to support unblocking
// synchronization. However, due to some implementation dependent details the usage of these
Expand Down Expand Up @@ -148,11 +157,11 @@ static ALWAYS_INLINE int gpi_int_lock()
// This is a matter of taste (it is not absolutely necessary if performance is secondary).
__asm__ volatile
(
#if (GPI_ARM_INTLOCK_PRIORITY > 0)
#if (_GPI_ARM_INTLOCK_PRIOMASK > 0)
"mrs %0, BASEPRI \n" // ie = __get_BASEPRI()
"msr BASEPRI, %1 \n" // __set_BASEPRI(...)
: "=&r"(ie)
: "r"(GPI_ARM_INTLOCK_PRIORITY & 0xFF)
: "r"(_GPI_ARM_INTLOCK_PRIOMASK & 0xFF)
#else
"mrs %0, PRIMASK \n" // ie = __get_PRIMASK()
"cpsid i \n" // __set_PRIMASK(0) / __disable_irq()
Expand All @@ -174,7 +183,7 @@ static ALWAYS_INLINE void gpi_int_unlock(int ie)
__DMB();

// NOTE: we expect ie as it has been returned by gpi_int_lock()
#if (GPI_ARM_INTLOCK_PRIORITY > 0)
#if (_GPI_ARM_INTLOCK_PRIOMASK > 0)
__set_BASEPRI(ie);
#else
__set_PRIMASK(ie);
Expand Down
2 changes: 1 addition & 1 deletion src/gpi/arm/armv7-m/olf.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @brief optimized low-level functions, tuned for ARMv7-M
*
* @version $Id: f302c8fdb1a77a3c191593ecee65161a30bec7de $
* @version $Id$
* @date TODO
*
* @author Carsten Herrmann
Expand Down
8 changes: 5 additions & 3 deletions src/gpi/arm/armv7-m/olf.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************************************************************************************
***************************************************************************************************
*
* Copyright (c) 2019, Networked Embedded Systems Lab, TU Dresden
* Copyright (c) 2019 - 2022, Networked Embedded Systems Lab, TU Dresden
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,7 +32,7 @@
*
* @brief optimized low-level functions, tuned for ARMv7-M
*
* @version $Id: bc9ba0cdc35b85fc49fd6ed91e213d2c7afbf9c1 $
* @version $Id$
* @date TODO
*
* @author Carsten Herrmann
Expand Down Expand Up @@ -194,6 +194,8 @@ static ALWAYS_INLINE int_fast8_t gpi_get_lsb_32_core(uint32_t x, const int test_
// has no semantics when inline asm is used.
if (test_zero)
{
//ASSERT_CT_WARN(IS_CONST_EXPRESSION(return_if_zero));

// NOTE: sub %0, %1, %2 (third line) is equivalent to mov %0, -%2
// implementing it this way allows arbitrary negative values for return_if_zero
// (remember the limited possibilities for immediate constants at operand2)
Expand All @@ -205,7 +207,7 @@ static ALWAYS_INLINE int_fast8_t gpi_get_lsb_32_core(uint32_t x, const int test_
"rbitne %0, %1 \n"
"clzne %0, %0 \n"
: "=r"(y)
: "r"(x), "i"((uint8_t)-return_if_zero)
: "r"(x), "ir"((uint8_t)-return_if_zero)
: "cc"
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gpi/arm/armv7-m/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @brief support for program execution time profiling
*
* @version $Id: 968217f20f6c8a7f83f806cd0a4a46d26216fb72 $
* @version $Id$
* @date TODO
*
* @author Carsten Herrmann
Expand Down
2 changes: 1 addition & 1 deletion src/gpi/arm/armv7-m/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @brief support for program execution time profiling
*
* @version $Id: 00dae4aff2e1ddf362028560630a3778b7a0ecad $
* @version $Id$
* @date TODO
*
* @author Carsten Herrmann
Expand Down
33 changes: 28 additions & 5 deletions src/gpi/arm/armv7-m/trace.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************************************************************************************
***************************************************************************************************
*
* Copyright (c) 2019, Networked Embedded Systems Lab, TU Dresden
* Copyright (c) 2019 - 2022, Networked Embedded Systems Lab, TU Dresden
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,7 +32,7 @@
*
* @brief generic ARMv7-M TRACE implementation
*
* @version $Id: 69639c9304e789482f4cdf38a256b94162bf27e6 $
* @version $Id$
* @date TODO
*
* @author Carsten Herrmann
Expand Down Expand Up @@ -81,7 +81,7 @@
//**************************************************************************************************
//***** Local (Static) Variables *******************************************************************

static Gpi_Trace_Msg s_msg_queue[GPI_TRACE_BUFFER_ELEMENTS];
static Gpi_Trace_Msg s_msg_queue[GPI_TRACE_BUFFER_NUM_ENTRIES];
static volatile unsigned int s_msg_queue_num_written = 0;
static volatile unsigned int s_msg_queue_num_writing = 0;
static volatile unsigned int s_msg_queue_num_read = 0;
Expand Down Expand Up @@ -319,21 +319,44 @@ void gpi_trace_print_all_msgs()
#endif

#if !GPI_TRACE_OVERFLOW_ON_WRITE

static Gpi_Trace_Msg s_msg;
msg = &s_msg;

#if (0 != GPI_TRACE_FLUSH_MAX_ENTRIES_PER_CALL)

unsigned int num_read_max;

#if (GPI_TRACE_FLUSH_MAX_ENTRIES_PER_CALL > 0)
num_read_max = num_read + GPI_TRACE_FLUSH_MAX_ENTRIES_PER_CALL;
#else
num_read_max = num_read + MIN(-GPI_TRACE_FLUSH_MAX_ENTRIES_PER_CALL, s_msg_queue_num_written - num_read);
#endif

#endif

#endif

while (num_read != s_msg_queue_num_written)
{
#if !GPI_TRACE_OVERFLOW_ON_WRITE

#if (0 != GPI_TRACE_FLUSH_MAX_ENTRIES_PER_CALL)
if (num_read == num_read_max)
break;
#endif

gpi_memcpy_dma_aligned(msg, &s_msg_queue[num_read % NUM_ELEMENTS(s_msg_queue)], sizeof(Gpi_Trace_Msg));

unsigned int num_open = s_msg_queue_num_writing - num_read;
if (num_open > NUM_ELEMENTS(s_msg_queue))
{
num_open -= NUM_ELEMENTS(s_msg_queue);
num_open = s_msg_queue_num_written - num_read;
num_read += num_open;

#if (0 != GPI_TRACE_FLUSH_MAX_ENTRIES_PER_CALL)
num_read_max = num_read;
#endif

msg->msg = "!!! TRACE buffer overflow, %u message(s) lost !!!\n";
msg->var_args[0] = num_open;
msg->timestamp = 0;
Expand Down
30 changes: 26 additions & 4 deletions src/gpi/arm/armv7-m/trace.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************************************************************************************
***************************************************************************************************
*
* Copyright (c) 2019, Networked Embedded Systems Lab, TU Dresden
* Copyright (c) 2019 - 2022, Networked Embedded Systems Lab, TU Dresden
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,7 +32,7 @@
*
* @brief ARM specific TRACE settings
*
* @version $Id: bf0cd24f27d85b9d5ca0f0f2fb84b617b37ec529 $
* @version $Id$
* @date TODO
*
* @author Carsten Herrmann
Expand Down Expand Up @@ -68,8 +68,8 @@
#define GPI_TRACE_VA_SIZE_MAX FIELD_SIZEOF(Gpi_Trace_Msg, var_args)

// size of TRACE buffer (number of elements)
#ifndef GPI_TRACE_BUFFER_ELEMENTS
#define GPI_TRACE_BUFFER_ELEMENTS 16
#ifndef GPI_TRACE_BUFFER_NUM_ENTRIES
#define GPI_TRACE_BUFFER_NUM_ENTRIES 16
#endif

// TRACE buffer entry size
Expand All @@ -89,6 +89,28 @@
// select whether TRACE buffer overflow detection is done on read or write side
#define GPI_TRACE_OVERFLOW_ON_WRITE 0

// maximum number of messages flushed by a single GPI_TRACE_FLUSH() call, 0 = unlimited
// @details
// In a single-threaded environment, each GPI_TRACE_FLUSH() call flushes at most
// GPI_TRACE_BUFFER_NUM_ENTRIES messages, as this is the maximum number of messages in the
// buffer (older messages get lost in case). In a multi-threaded environment, it is possible
// that new messages arrive while GPI_TRACE_FLUSH() is running, which can lead to the situation
// that a single GPI_TRACE_FLUSH() call outputs more than GPI_TRACE_BUFFER_NUM_ENTRIES messages
// (in the extreme case, GPI_TRACE_FLUSH() can run forever). This is critical as it can render
// it impossible to estimate the runtime of GPI_TRACE_FLUSH().
// To overcome this problem, GPI_TRACE_FLUSH_MAX_ENTRIES_PER_CALL can be used to limit the
// maximum number of messages that are output by a single GPI_TRACE_FLUSH() call. Further,
// if GPI_TRACE_FLUSH_MAX_ENTRIES_PER_CALL is set to a negative value -N then it limits the
// number of messages to N and, additionally, processes only those messages that have already
// been in the buffer when GPI_TRACE_FLUSH() was entered (so messages arriving in parallel to
// GPI_TRACE_FLUSH() are not handled in the current call).
// NOTE: GPI_TRACE_FLUSH_MAX_ENTRIES_PER_CALL is not considered if GPI_TRACE_OVERFLOW_ON_WRITE
// is active (TODO: change this).
// TODO: this macro may be of interest for multiple platforms, so maybe move it to gpi/trace.h
#ifndef GPI_TRACE_FLUSH_MAX_ENTRIES_PER_CALL
#define GPI_TRACE_FLUSH_MAX_ENTRIES_PER_CALL GPI_TRACE_BUFFER_NUM_ENTRIES
#endif

// select if and how path part gets filtered out from file names
#ifndef GPI_TRACE_FILTER_PATH
#define GPI_TRACE_FILTER_PATH 1
Expand Down
2 changes: 1 addition & 1 deletion src/gpi/arm/nordic/dpp2com/clocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @brief general-purpose slow, fast, and hybrid clock
*
* @version $Id: 30e35eeb818af1c7a767d64261fc0b8c47f06f74 $
* @version $Id$
* @date TODO
*
* @author Fabian Mager
Expand Down
10 changes: 5 additions & 5 deletions src/gpi/arm/nordic/dpp2com/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @brief platform interface functions
*
* @version $Id: ec37c2eac77ba05e9bf52731d0c5864a14056e67 $
* @version $Id$
* @date TODO
*
* @author Fabian Mager
Expand Down Expand Up @@ -477,13 +477,13 @@ void gpi_platform_init()
// if VHT: use PPI to connect RTC->EVENTS_TICK to TIMER->TASKS_CAPTURE
#if GPI_HYBRID_CLOCK_USE_VHT

NRF_PPI->CH[GPI_HYBRID_CLOCK_NRF_PPI_CHANNEL].EEP =
NRF_PPI->CH[GPI_ARM_NRF_HYBRID_CLOCK_PPI_CHANNEL].EEP =
(uintptr_t)&(_gpi_clocks_rtc->EVENTS_TICK);

NRF_PPI->CH[GPI_HYBRID_CLOCK_NRF_PPI_CHANNEL].TEP =
(uintptr_t)&(_gpi_clocks_fast_timer->TASKS_CAPTURE[GPI_HYBRID_CLOCK_NRF_CAPTURE_REG]);
NRF_PPI->CH[GPI_ARM_NRF_HYBRID_CLOCK_PPI_CHANNEL].TEP =
(uintptr_t)&(_gpi_clocks_fast_timer->TASKS_CAPTURE[GPI_ARM_NRF_HYBRID_CLOCK_CAPTURE_REG]);

NRF_PPI->CHENSET = BV(GPI_HYBRID_CLOCK_NRF_PPI_CHANNEL);
NRF_PPI->CHENSET = BV(GPI_ARM_NRF_HYBRID_CLOCK_PPI_CHANNEL);

#endif

Expand Down
2 changes: 1 addition & 1 deletion src/gpi/arm/nordic/dpp2com/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @brief platform interface functions, specific for DPP2 Com board based on nRF52840
*
* @version $Id: 34ee348a1963feb4d7f0b188a5c9de69873f744a $
* @version $Id$
* @date TODO
*
* @author Fabian Mager
Expand Down
Loading