feat: Draft architecture for incp hub
This commit is contained in:
101
app/CMakeLists.txt
Normal file
101
app/CMakeLists.txt
Normal file
@@ -0,0 +1,101 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
# ===========================
|
||||
# === Configs and Options ===
|
||||
# ===========================
|
||||
|
||||
# Project name for CMake
|
||||
set(FW_PROJECT_NAME freertos-incp-handler-app)
|
||||
|
||||
# Linker script
|
||||
set(FW_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/STM32F411XX_FLASH.ld)
|
||||
|
||||
# OpenOCD target for flashing
|
||||
set(FW_OPENOCD_TARGET stm32f4x.cfg)
|
||||
|
||||
|
||||
|
||||
# ========================
|
||||
# === Project building ===
|
||||
# ========================
|
||||
project(${FW_PROJECT_NAME}
|
||||
VERSION 0.1.0
|
||||
LANGUAGES C)
|
||||
|
||||
set(CMAKE_C_STANDARD 17)
|
||||
set(CMAKE_C_STANDARD_REQUIRED True)
|
||||
|
||||
set(EXECUTABLE ${FW_PROJECT_NAME})
|
||||
add_executable(${EXECUTABLE} "")
|
||||
|
||||
# Set compiler/linker options
|
||||
target_compile_definitions(${EXECUTABLE} PRIVATE
|
||||
${COMPILER_DEFINES}
|
||||
INCPHUB_LOCAL_NIL_ADDR=1
|
||||
)
|
||||
target_compile_options(${EXECUTABLE} PRIVATE
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-O0
|
||||
-g
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-flto
|
||||
)
|
||||
target_link_options(${EXECUTABLE} PRIVATE
|
||||
-T ${FW_LINKER_SCRIPT}
|
||||
--specs=nano.specs
|
||||
-Wl,--gc-sections
|
||||
-flto
|
||||
)
|
||||
|
||||
# Recurse subdirectories
|
||||
add_subdirectory(src)
|
||||
|
||||
# Add libraries
|
||||
target_link_libraries(${EXECUTABLE} PRIVATE cubemx)
|
||||
|
||||
|
||||
|
||||
# =============================
|
||||
# === Dependency management ===
|
||||
# =============================
|
||||
|
||||
# Add CPM
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake)
|
||||
|
||||
# Add FetchContent
|
||||
include(FetchContent)
|
||||
|
||||
|
||||
|
||||
# ==========================
|
||||
# === External libraries ===
|
||||
# ==========================
|
||||
|
||||
# == CPM Packages ==
|
||||
#CPMAddPackage(...)
|
||||
|
||||
# == FetchContent Packages ==
|
||||
#FetchContent_Declare(...)
|
||||
#FetchContent_MakeAvailable(...)
|
||||
|
||||
# Add FreeRTOS
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FreeRTOS.cmake)
|
||||
|
||||
# == Library linking ==
|
||||
#target_link_libraries(${EXECUTABLE} ...)
|
||||
target_link_libraries(${EXECUTABLE} PRIVATE freertos_kernel)
|
||||
|
||||
|
||||
|
||||
# =====================
|
||||
# === Flashing code ===
|
||||
# =====================
|
||||
|
||||
find_program(OPENOCD openocd)
|
||||
|
||||
add_custom_target(flash
|
||||
COMMAND ${OPENOCD} -f interface/stlink.cfg -f target/${FW_OPENOCD_TARGET} -c "program $<TARGET_FILE:${EXECUTABLE}> verify reset exit"
|
||||
)
|
||||
674
app/FreeRTOS/FreeRTOSConfig.h
Normal file
674
app/FreeRTOS/FreeRTOSConfig.h
Normal file
@@ -0,0 +1,674 @@
|
||||
/*
|
||||
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
|
||||
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* This file provides an example FreeRTOSConfig.h header file, inclusive of an
|
||||
* abbreviated explanation of each configuration item. Online and reference
|
||||
* documentation provides more information.
|
||||
* https://www.freertos.org/a00110.html
|
||||
*
|
||||
* Constant values enclosed in square brackets ('[' and ']') must be completed
|
||||
* before this file will build.
|
||||
*
|
||||
* Use the FreeRTOSConfig.h supplied with the RTOS port in use rather than this
|
||||
* generic file, if one is available.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef FREERTOS_CONFIG_H
|
||||
#define FREERTOS_CONFIG_H
|
||||
|
||||
/******************************************************************************/
|
||||
/* Hardware description related definitions. **********************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* In most cases, configCPU_CLOCK_HZ must be set to the frequency of the clock
|
||||
* that drives the peripheral used to generate the kernels periodic tick
|
||||
* interrupt. The default value is set to 20MHz and matches the QEMU demo
|
||||
* settings. Your application will certainly need a different value so set this
|
||||
* correctly. This is very often, but not always, equal to the main system clock
|
||||
* frequency. */
|
||||
#define configCPU_CLOCK_HZ ( ( unsigned long ) 100000000 )
|
||||
|
||||
/* configSYSTICK_CLOCK_HZ is an optional parameter for ARM Cortex-M ports only.
|
||||
*
|
||||
* By default ARM Cortex-M ports generate the RTOS tick interrupt from the
|
||||
* Cortex-M SysTick timer. Most Cortex-M MCUs run the SysTick timer at the same
|
||||
* frequency as the MCU itself - when that is the case configSYSTICK_CLOCK_HZ is
|
||||
* not needed and should be left undefined. If the SysTick timer is clocked at a
|
||||
* different frequency to the MCU core then set configCPU_CLOCK_HZ to the MCU
|
||||
* clock frequency, as normal, and configSYSTICK_CLOCK_HZ to the SysTick clock
|
||||
* frequency. Not used if left undefined.
|
||||
* The default value is undefined (commented out). If you need this value bring
|
||||
* it back and set it to a suitable value. */
|
||||
|
||||
/*
|
||||
#define configSYSTICK_CLOCK_HZ [Platform specific]
|
||||
*/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Scheduling behaviour related definitions. **********************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* configTICK_RATE_HZ sets frequency of the tick interrupt in Hz, normally
|
||||
* calculated from the configCPU_CLOCK_HZ value. */
|
||||
#define configTICK_RATE_HZ 100
|
||||
|
||||
/* Set configUSE_PREEMPTION to 1 to use pre-emptive scheduling. Set
|
||||
* configUSE_PREEMPTION to 0 to use co-operative scheduling.
|
||||
* See https://www.freertos.org/single-core-amp-smp-rtos-scheduling.html. */
|
||||
#define configUSE_PREEMPTION 1
|
||||
|
||||
/* Set configUSE_TIME_SLICING to 1 to have the scheduler switch between Ready
|
||||
* state tasks of equal priority on every tick interrupt. Set
|
||||
* configUSE_TIME_SLICING to 0 to prevent the scheduler switching between Ready
|
||||
* state tasks just because there was a tick interrupt. See
|
||||
* https://freertos.org/single-core-amp-smp-rtos-scheduling.html. */
|
||||
#define configUSE_TIME_SLICING 0
|
||||
|
||||
/* Set configUSE_PORT_OPTIMISED_TASK_SELECTION to 1 to select the next task to
|
||||
* run using an algorithm optimised to the instruction set of the target
|
||||
* hardware - normally using a count leading zeros assembly instruction. Set to
|
||||
* 0 to select the next task to run using a generic C algorithm that works for
|
||||
* all FreeRTOS ports. Not all FreeRTOS ports have this option. Defaults to 0
|
||||
* if left undefined. */
|
||||
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
|
||||
|
||||
/* Set configUSE_TICKLESS_IDLE to 1 to use the low power tickless mode. Set to
|
||||
* 0 to keep the tick interrupt running at all times. Not all FreeRTOS ports
|
||||
* support tickless mode. See
|
||||
* https://www.freertos.org/low-power-tickless-rtos.html Defaults to 0 if left
|
||||
* undefined. */
|
||||
#define configUSE_TICKLESS_IDLE 0
|
||||
|
||||
/* configMAX_PRIORITIES Sets the number of available task priorities. Tasks can
|
||||
* be assigned priorities of 0 to (configMAX_PRIORITIES - 1). Zero is the
|
||||
* lowest priority. */
|
||||
#define configMAX_PRIORITIES 5
|
||||
|
||||
/* configMINIMAL_STACK_SIZE defines the size of the stack used by the Idle task
|
||||
* (in words, not in bytes!). The kernel does not use this constant for any
|
||||
* other purpose. Demo applications use the constant to make the demos somewhat
|
||||
* portable across hardware architectures. */
|
||||
#define configMINIMAL_STACK_SIZE 128
|
||||
//REVIEW: Can lower work?
|
||||
|
||||
/* configMAX_TASK_NAME_LEN sets the maximum length (in characters) of a task's
|
||||
* human readable name. Includes the NULL terminator. */
|
||||
#define configMAX_TASK_NAME_LEN 8
|
||||
|
||||
/* Time is measured in 'ticks' - which is the number of times the tick interrupt
|
||||
* has executed since the RTOS kernel was started.
|
||||
* The tick count is held in a variable of type TickType_t.
|
||||
*
|
||||
* configTICK_TYPE_WIDTH_IN_BITS controls the type (and therefore bit-width) of
|
||||
* TickType_t:
|
||||
*
|
||||
* Defining configTICK_TYPE_WIDTH_IN_BITS as TICK_TYPE_WIDTH_16_BITS causes
|
||||
* TickType_t to be defined (typedef'ed) as an unsigned 16-bit type.
|
||||
*
|
||||
* Defining configTICK_TYPE_WIDTH_IN_BITS as TICK_TYPE_WIDTH_32_BITS causes
|
||||
* TickType_t to be defined (typedef'ed) as an unsigned 32-bit type.
|
||||
*
|
||||
* Defining configTICK_TYPE_WIDTH_IN_BITS as TICK_TYPE_WIDTH_64_BITS causes
|
||||
* TickType_t to be defined (typedef'ed) as an unsigned 64-bit type. */
|
||||
#define configTICK_TYPE_WIDTH_IN_BITS TICK_TYPE_WIDTH_32_BITS
|
||||
|
||||
/* Set configIDLE_SHOULD_YIELD to 1 to have the Idle task yield to an
|
||||
* application task if there is an Idle priority (priority 0) application task
|
||||
* that can run. Set to 0 to have the Idle task use all of its timeslice.
|
||||
* Default to 1 if left undefined. */
|
||||
#define configIDLE_SHOULD_YIELD 1
|
||||
|
||||
/* Each task has an array of task notifications.
|
||||
* configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
|
||||
* array. See https://www.freertos.org/RTOS-task-notifications.html Defaults to
|
||||
* 1 if left undefined. */
|
||||
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 2
|
||||
|
||||
/* configQUEUE_REGISTRY_SIZE sets the maximum number of queues and semaphores
|
||||
* that can be referenced from the queue registry. Only required when using a
|
||||
* kernel aware debugger. Defaults to 0 if left undefined. */
|
||||
#define configQUEUE_REGISTRY_SIZE 0
|
||||
|
||||
/* Set configENABLE_BACKWARD_COMPATIBILITY to 1 to map function names and
|
||||
* datatypes from old version of FreeRTOS to their latest equivalent. Defaults
|
||||
* to 1 if left undefined. */
|
||||
#define configENABLE_BACKWARD_COMPATIBILITY 0
|
||||
|
||||
/* Each task has its own array of pointers that can be used as thread local
|
||||
* storage. configNUM_THREAD_LOCAL_STORAGE_POINTERS set the number of indexes
|
||||
* in the array. See
|
||||
* https://www.freertos.org/thread-local-storage-pointers.html Defaults to 0 if
|
||||
* left undefined. */
|
||||
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 0
|
||||
|
||||
/* When configUSE_MINI_LIST_ITEM is set to 0, MiniListItem_t and ListItem_t are
|
||||
* both the same. When configUSE_MINI_LIST_ITEM is set to 1, MiniListItem_t
|
||||
* contains 3 fewer fields than ListItem_t which saves some RAM at the cost of
|
||||
* violating strict aliasing rules which some compilers depend on for
|
||||
* optimization. Defaults to 1 if left undefined. */
|
||||
#define configUSE_MINI_LIST_ITEM 1
|
||||
|
||||
/* Sets the type used by the parameter to xTaskCreate() that specifies the stack
|
||||
* size of the task being created. The same type is used to return information
|
||||
* about stack usage in various other API calls. Defaults to size_t if left
|
||||
* undefined. */
|
||||
#define configSTACK_DEPTH_TYPE size_t
|
||||
|
||||
/* configMESSAGE_BUFFER_LENGTH_TYPE sets the type used to store the length of
|
||||
* each message written to a FreeRTOS message buffer (the length is also written
|
||||
* to the message buffer. Defaults to size_t if left undefined - but that may
|
||||
* waste space if messages never go above a length that could be held in a
|
||||
* uint8_t. */
|
||||
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
|
||||
|
||||
/* If configHEAP_CLEAR_MEMORY_ON_FREE is set to 1, then blocks of memory
|
||||
* allocated using pvPortMalloc() will be cleared (i.e. set to zero) when freed
|
||||
* using vPortFree(). Defaults to 0 if left undefined. */
|
||||
#define configHEAP_CLEAR_MEMORY_ON_FREE 0
|
||||
|
||||
/* vTaskList and vTaskGetRunTimeStats APIs take a buffer as a parameter and
|
||||
* assume that the length of the buffer is configSTATS_BUFFER_MAX_LENGTH.
|
||||
* Defaults to 0xFFFF if left undefined. New applications are recommended to use
|
||||
* vTaskListTasks and vTaskGetRunTimeStatistics APIs instead and supply the
|
||||
* length of the buffer explicitly to avoid memory corruption. */
|
||||
#define configSTATS_BUFFER_MAX_LENGTH 0xFFFF
|
||||
|
||||
/* Set configUSE_NEWLIB_REENTRANT to 1 to have a newlib reent structure
|
||||
* allocated for each task. Set to 0 to not support newlib reent structures.
|
||||
* Default to 0 if left undefined.
|
||||
*
|
||||
* Note Newlib support has been included by popular demand, but is not used or
|
||||
* tested by the FreeRTOS maintainers themselves. FreeRTOS is not responsible
|
||||
* for resulting newlib operation. User must be familiar with newlib and must
|
||||
* provide system-wide implementations of the necessary stubs. Note that (at the
|
||||
* time of writing) the current newlib design implements a system-wide malloc()
|
||||
* that must be provided with locks. */
|
||||
#define configUSE_NEWLIB_REENTRANT 0
|
||||
|
||||
/******************************************************************************/
|
||||
/* Software timer related definitions. ****************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* Set configUSE_TIMERS to 1 to include software timer functionality in the
|
||||
* build. Set to 0 to exclude software timer functionality from the build. The
|
||||
* FreeRTOS/source/timers.c source file must be included in the build if
|
||||
* configUSE_TIMERS is set to 1. Default to 0 if left undefined. See
|
||||
* https://www.freertos.org/RTOS-software-timer.html. */
|
||||
#define configUSE_TIMERS 0
|
||||
|
||||
/* configTIMER_TASK_PRIORITY sets the priority used by the timer task. Only
|
||||
* used if configUSE_TIMERS is set to 1. The timer task is a standard FreeRTOS
|
||||
* task, so its priority is set like any other task. See
|
||||
* https://www.freertos.org/RTOS-software-timer-service-daemon-task.html Only
|
||||
* used if configUSE_TIMERS is set to 1. */
|
||||
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
|
||||
|
||||
/* configTIMER_TASK_STACK_DEPTH sets the size of the stack allocated to the
|
||||
* timer task (in words, not in bytes!). The timer task is a standard FreeRTOS
|
||||
* task. See
|
||||
* https://www.freertos.org/RTOS-software-timer-service-daemon-task.html Only
|
||||
* used if configUSE_TIMERS is set to 1. */
|
||||
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
|
||||
|
||||
/* configTIMER_QUEUE_LENGTH sets the length of the queue (the number of discrete
|
||||
* items the queue can hold) used to send commands to the timer task. See
|
||||
* https://www.freertos.org/RTOS-software-timer-service-daemon-task.html Only
|
||||
* used if configUSE_TIMERS is set to 1. */
|
||||
#define configTIMER_QUEUE_LENGTH 10
|
||||
|
||||
/******************************************************************************/
|
||||
/* Event Group related definitions. *******************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* Set configUSE_EVENT_GROUPS to 1 to include event group functionality in the
|
||||
* build. Set to 0 to exclude event group functionality from the build. The
|
||||
* FreeRTOS/source/event_groups.c source file must be included in the build if
|
||||
* configUSE_EVENT_GROUPS is set to 1. Defaults to 1 if left undefined. */
|
||||
|
||||
#define configUSE_EVENT_GROUPS 0
|
||||
|
||||
/******************************************************************************/
|
||||
/* Stream Buffer related definitions. *****************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* Set configUSE_STREAM_BUFFERS to 1 to include stream buffer functionality in
|
||||
* the build. Set to 0 to exclude event group functionality from the build. The
|
||||
* FreeRTOS/source/stream_buffer.c source file must be included in the build if
|
||||
* configUSE_STREAM_BUFFERS is set to 1. Defaults to 1 if left undefined. */
|
||||
|
||||
#define configUSE_STREAM_BUFFERS 1
|
||||
|
||||
/******************************************************************************/
|
||||
/* Memory allocation related definitions. *************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* Set configSUPPORT_STATIC_ALLOCATION to 1 to include FreeRTOS API functions
|
||||
* that create FreeRTOS objects (tasks, queues, etc.) using statically allocated
|
||||
* memory in the build. Set to 0 to exclude the ability to create statically
|
||||
* allocated objects from the build. Defaults to 0 if left undefined. See
|
||||
* https://www.freertos.org/Static_Vs_Dynamic_Memory_Allocation.html. */
|
||||
#define configSUPPORT_STATIC_ALLOCATION 1
|
||||
|
||||
/* Set configSUPPORT_DYNAMIC_ALLOCATION to 1 to include FreeRTOS API functions
|
||||
* that create FreeRTOS objects (tasks, queues, etc.) using dynamically
|
||||
* allocated memory in the build. Set to 0 to exclude the ability to create
|
||||
* dynamically allocated objects from the build. Defaults to 1 if left
|
||||
* undefined. See
|
||||
* https://www.freertos.org/Static_Vs_Dynamic_Memory_Allocation.html. */
|
||||
#define configSUPPORT_DYNAMIC_ALLOCATION 0
|
||||
|
||||
/* Sets the total size of the FreeRTOS heap, in bytes, when heap_1.c, heap_2.c
|
||||
* or heap_4.c are included in the build. This value is defaulted to 4096 bytes
|
||||
* but it must be tailored to each application. Note the heap will appear in
|
||||
* the .bss section. See https://www.freertos.org/a00111.html. */
|
||||
#define configTOTAL_HEAP_SIZE 4096
|
||||
|
||||
/* Set configAPPLICATION_ALLOCATED_HEAP to 1 to have the application allocate
|
||||
* the array used as the FreeRTOS heap. Set to 0 to have the linker allocate
|
||||
* the array used as the FreeRTOS heap. Defaults to 0 if left undefined. */
|
||||
#define configAPPLICATION_ALLOCATED_HEAP 0
|
||||
|
||||
/* Set configSTACK_ALLOCATION_FROM_SEPARATE_HEAP to 1 to have task stacks
|
||||
* allocated from somewhere other than the FreeRTOS heap. This is useful if you
|
||||
* want to ensure stacks are held in fast memory. Set to 0 to have task stacks
|
||||
* come from the standard FreeRTOS heap. The application writer must provide
|
||||
* implementations for pvPortMallocStack() and vPortFreeStack() if set to 1.
|
||||
* Defaults to 0 if left undefined. */
|
||||
#define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP 0
|
||||
|
||||
/* Set configENABLE_HEAP_PROTECTOR to 1 to enable bounds checking and
|
||||
* obfuscation to internal heap block pointers in heap_4.c and heap_5.c to help
|
||||
* catch pointer corruptions. Defaults to 0 if left undefined. */
|
||||
#define configENABLE_HEAP_PROTECTOR 0
|
||||
|
||||
/******************************************************************************/
|
||||
/* Interrupt nesting behaviour configuration. *********************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* configKERNEL_INTERRUPT_PRIORITY sets the priority of the tick and context
|
||||
* switch performing interrupts. Not supported by all FreeRTOS ports. See
|
||||
* https://www.freertos.org/RTOS-Cortex-M3-M4.html for information specific to
|
||||
* ARM Cortex-M devices. */
|
||||
#define configKERNEL_INTERRUPT_PRIORITY 0
|
||||
//REVIEW: Study this
|
||||
|
||||
/* configMAX_SYSCALL_INTERRUPT_PRIORITY sets the interrupt priority above which
|
||||
* FreeRTOS API calls must not be made. Interrupts above this priority are
|
||||
* never disabled, so never delayed by RTOS activity. The default value is set
|
||||
* to the highest interrupt priority (0). Not supported by all FreeRTOS ports.
|
||||
* See https://www.freertos.org/RTOS-Cortex-M3-M4.html for information specific
|
||||
* to ARM Cortex-M devices. */
|
||||
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 0x10
|
||||
//REVIEW: Study this
|
||||
|
||||
/* Another name for configMAX_SYSCALL_INTERRUPT_PRIORITY - the name used depends
|
||||
* on the FreeRTOS port. */
|
||||
#define configMAX_API_CALL_INTERRUPT_PRIORITY 0
|
||||
|
||||
/******************************************************************************/
|
||||
/* Hook and callback function related definitions. ****************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* Set the following configUSE_* constants to 1 to include the named hook
|
||||
* functionality in the build. Set to 0 to exclude the hook functionality from
|
||||
* the build. The application writer is responsible for providing the hook
|
||||
* function for any set to 1. See https://www.freertos.org/a00016.html. */
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configUSE_MALLOC_FAILED_HOOK 0
|
||||
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
|
||||
|
||||
/* Set configUSE_SB_COMPLETED_CALLBACK to 1 to have send and receive completed
|
||||
* callbacks for each instance of a stream buffer or message buffer. When the
|
||||
* option is set to 1, APIs xStreamBufferCreateWithCallback() and
|
||||
* xStreamBufferCreateStaticWithCallback() (and likewise APIs for message
|
||||
* buffer) can be used to create a stream buffer or message buffer instance
|
||||
* with application provided callbacks. Defaults to 0 if left undefined. */
|
||||
#define configUSE_SB_COMPLETED_CALLBACK 0
|
||||
|
||||
/* Set configCHECK_FOR_STACK_OVERFLOW to 1 or 2 for FreeRTOS to check for a
|
||||
* stack overflow at the time of a context switch. Set to 0 to not look for a
|
||||
* stack overflow. If configCHECK_FOR_STACK_OVERFLOW is 1 then the check only
|
||||
* looks for the stack pointer being out of bounds when a task's context is
|
||||
* saved to its stack - this is fast but somewhat ineffective. If
|
||||
* configCHECK_FOR_STACK_OVERFLOW is 2 then the check looks for a pattern
|
||||
* written to the end of a task's stack having been overwritten. This is
|
||||
* slower, but will catch most (but not all) stack overflows. The application
|
||||
* writer must provide the stack overflow callback when
|
||||
* configCHECK_FOR_STACK_OVERFLOW is set to 1. See
|
||||
* https://www.freertos.org/Stacks-and-stack-overflow-checking.html Defaults to
|
||||
* 0 if left undefined. */
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 2
|
||||
|
||||
/******************************************************************************/
|
||||
/* Run time and task stats gathering related definitions. *********************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* Set configGENERATE_RUN_TIME_STATS to 1 to have FreeRTOS collect data on the
|
||||
* processing time used by each task. Set to 0 to not collect the data. The
|
||||
* application writer needs to provide a clock source if set to 1. Defaults to
|
||||
* 0 if left undefined. See https://www.freertos.org/rtos-run-time-stats.html.
|
||||
*/
|
||||
#define configGENERATE_RUN_TIME_STATS 0
|
||||
|
||||
/* Set configUSE_TRACE_FACILITY to include additional task structure members
|
||||
* are used by trace and visualisation functions and tools. Set to 0 to exclude
|
||||
* the additional information from the structures. Defaults to 0 if left
|
||||
* undefined. */
|
||||
#define configUSE_TRACE_FACILITY 0
|
||||
|
||||
/* Set to 1 to include the vTaskList() and vTaskGetRunTimeStats() functions in
|
||||
* the build. Set to 0 to exclude these functions from the build. These two
|
||||
* functions introduce a dependency on string formatting functions that would
|
||||
* otherwise not exist - hence they are kept separate. Defaults to 0 if left
|
||||
* undefined. */
|
||||
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
|
||||
|
||||
/******************************************************************************/
|
||||
/* Co-routine related definitions. ********************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* Set configUSE_CO_ROUTINES to 1 to include co-routine functionality in the
|
||||
* build, or 0 to omit co-routine functionality from the build. To include
|
||||
* co-routines, croutine.c must be included in the project. Defaults to 0 if
|
||||
* left undefined. */
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
|
||||
/* configMAX_CO_ROUTINE_PRIORITIES defines the number of priorities available
|
||||
* to the application co-routines. Any number of co-routines can share the same
|
||||
* priority. Defaults to 0 if left undefined. */
|
||||
#define configMAX_CO_ROUTINE_PRIORITIES 1
|
||||
|
||||
/******************************************************************************/
|
||||
/* Debugging assistance. ******************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* configASSERT() has the same semantics as the standard C assert(). It can
|
||||
* either be defined to take an action when the assertion fails, or not defined
|
||||
* at all (i.e. comment out or delete the definitions) to completely remove
|
||||
* assertions. configASSERT() can be defined to anything you want, for example
|
||||
* you can call a function if an assert fails that passes the filename and line
|
||||
* number of the failing assert (for example, "vAssertCalled( __FILE__, __LINE__
|
||||
* )" or it can simple disable interrupts and sit in a loop to halt all
|
||||
* execution on the failing line for viewing in a debugger. */
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
#define configASSERT( x ) \
|
||||
if( ( x ) == 0 ) \
|
||||
{ \
|
||||
taskDISABLE_INTERRUPTS(); \
|
||||
for( ; ; ) \
|
||||
; \
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/******************************************************************************/
|
||||
/* FreeRTOS MPU specific definitions. *****************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* If configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS is set to 1 then
|
||||
* the application writer can provide functions that execute in privileged mode.
|
||||
* See:
|
||||
* https://www.freertos.org/a00110.html#configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS
|
||||
* Defaults to 0 if left undefined. Only used by the FreeRTOS Cortex-M MPU
|
||||
* ports, not the standard ARMv7-M Cortex-M port. */
|
||||
#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0
|
||||
|
||||
/* Set configTOTAL_MPU_REGIONS to the number of MPU regions implemented on your
|
||||
* target hardware. Normally 8 or 16. Only used by the FreeRTOS Cortex-M MPU
|
||||
* ports, not the standard ARMv7-M Cortex-M port. Defaults to 8 if left
|
||||
* undefined. */
|
||||
#define configTOTAL_MPU_REGIONS 8
|
||||
|
||||
/* configTEX_S_C_B_FLASH allows application writers to override the default
|
||||
* values for the for TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits
|
||||
* for the MPU region covering Flash. Defaults to 0x07UL (which means TEX=000,
|
||||
* S=1, C=1, B=1) if left undefined. Only used by the FreeRTOS Cortex-M MPU
|
||||
* ports, not the standard ARMv7-M Cortex-M port. */
|
||||
#define configTEX_S_C_B_FLASH 0x07UL
|
||||
|
||||
/* configTEX_S_C_B_SRAM allows application writers to override the default
|
||||
* values for the for TEX, Shareable (S), Cacheable (C) and Bufferable (B) bits
|
||||
* for the MPU region covering RAM. Defaults to 0x07UL (which means TEX=000,
|
||||
* S=1, C=1, B=1) if left undefined. Only used by the FreeRTOS Cortex-M MPU
|
||||
* ports, not the standard ARMv7-M Cortex-M port. */
|
||||
#define configTEX_S_C_B_SRAM 0x07UL
|
||||
|
||||
/* Set configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY to 0 to prevent any privilege
|
||||
* escalations originating from outside of the kernel code itself. Set to 1 to
|
||||
* allow application tasks to raise privilege. Defaults to 1 if left undefined.
|
||||
* Only used by the FreeRTOS Cortex-M MPU ports, not the standard ARMv7-M
|
||||
* Cortex-M port. */
|
||||
#define configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY 1
|
||||
|
||||
/* Set configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS to 1 to allow unprivileged
|
||||
* tasks enter critical sections (effectively mask interrupts). Set to 0 to
|
||||
* prevent unprivileged tasks entering critical sections. Defaults to 1 if left
|
||||
* undefined. Only used by the FreeRTOS Cortex-M MPU ports, not the standard
|
||||
* ARMv7-M Cortex-M port. */
|
||||
#define configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS 0
|
||||
|
||||
/* FreeRTOS Kernel version 10.6.0 introduced a new v2 MPU wrapper, namely
|
||||
* mpu_wrappers_v2.c. Set configUSE_MPU_WRAPPERS_V1 to 0 to use the new v2 MPU
|
||||
* wrapper. Set configUSE_MPU_WRAPPERS_V1 to 1 to use the old v1 MPU wrapper
|
||||
* (mpu_wrappers.c). Defaults to 0 if left undefined. */
|
||||
#define configUSE_MPU_WRAPPERS_V1 0
|
||||
|
||||
/* When using the v2 MPU wrapper, set configPROTECTED_KERNEL_OBJECT_POOL_SIZE to
|
||||
* the total number of kernel objects, which includes tasks, queues, semaphores,
|
||||
* mutexes, event groups, timers, stream buffers and message buffers, in your
|
||||
* application. The application will not be able to have more than
|
||||
* configPROTECTED_KERNEL_OBJECT_POOL_SIZE kernel objects at any point of
|
||||
* time. */
|
||||
#define configPROTECTED_KERNEL_OBJECT_POOL_SIZE 10
|
||||
//REVIEW: Study this
|
||||
|
||||
/* When using the v2 MPU wrapper, set configSYSTEM_CALL_STACK_SIZE to the size
|
||||
* of the system call stack in words. Each task has a statically allocated
|
||||
* memory buffer of this size which is used as the stack to execute system
|
||||
* calls. For example, if configSYSTEM_CALL_STACK_SIZE is defined as 128 and
|
||||
* there are 10 tasks in the application, the total amount of memory used for
|
||||
* system call stacks is 128 * 10 = 1280 words. */
|
||||
#define configSYSTEM_CALL_STACK_SIZE 128
|
||||
//REVIEW: Keep at default value?
|
||||
|
||||
/* When using the v2 MPU wrapper, set configENABLE_ACCESS_CONTROL_LIST to 1 to
|
||||
* enable Access Control List (ACL) feature. When ACL is enabled, an
|
||||
* unprivileged task by default does not have access to any kernel object other
|
||||
* than itself. The application writer needs to explicitly grant the
|
||||
* unprivileged task access to the kernel objects it needs using the APIs
|
||||
* provided for the same. Defaults to 0 if left undefined. */
|
||||
#define configENABLE_ACCESS_CONTROL_LIST 0
|
||||
//REVIEW: Study this
|
||||
|
||||
/******************************************************************************/
|
||||
/* SMP( Symmetric MultiProcessing ) Specific Configuration definitions. *******/
|
||||
/******************************************************************************/
|
||||
|
||||
/* Set configNUMBER_OF_CORES to the number of available processor cores.
|
||||
* Defaults to 1 if left undefined. */
|
||||
|
||||
/*
|
||||
#define configNUMBER_OF_CORES [Num of available cores]
|
||||
*/
|
||||
|
||||
/* When using SMP (i.e. configNUMBER_OF_CORES is greater than one), set
|
||||
* configRUN_MULTIPLE_PRIORITIES to 0 to allow multiple tasks to run
|
||||
* simultaneously only if they do not have equal priority, thereby maintaining
|
||||
* the paradigm of a lower priority task never running if a higher priority task
|
||||
* is able to run. If configRUN_MULTIPLE_PRIORITIES is set to 1, multiple tasks
|
||||
* with different priorities may run simultaneously - so a higher and lower
|
||||
* priority task may run on different cores at the same time. */
|
||||
#define configRUN_MULTIPLE_PRIORITIES 0
|
||||
|
||||
/* When using SMP (i.e. configNUMBER_OF_CORES is greater than one), set
|
||||
* configUSE_CORE_AFFINITY to 1 to enable core affinity feature. When core
|
||||
* affinity feature is enabled, the vTaskCoreAffinitySet and
|
||||
* vTaskCoreAffinityGet APIs can be used to set and retrieve which cores a task
|
||||
* can run on. If configUSE_CORE_AFFINITY is set to 0 then the FreeRTOS
|
||||
* scheduler is free to run any task on any available core. */
|
||||
#define configUSE_CORE_AFFINITY 0
|
||||
|
||||
/* When using SMP with core affinity feature enabled, set
|
||||
* configTASK_DEFAULT_CORE_AFFINITY to change the default core affinity mask for
|
||||
* tasks created without an affinity mask specified. Setting the define to 1
|
||||
* would make such tasks run on core 0 and setting it to (1 <<
|
||||
* portGET_CORE_ID()) would make such tasks run on the current core. This config
|
||||
* value is useful, if swapping tasks between cores is not supported (e.g.
|
||||
* Tricore) or if legacy code should be controlled. Defaults to tskNO_AFFINITY
|
||||
* if left undefined. */
|
||||
#define configTASK_DEFAULT_CORE_AFFINITY tskNO_AFFINITY
|
||||
|
||||
/* When using SMP (i.e. configNUMBER_OF_CORES is greater than one), if
|
||||
* configUSE_TASK_PREEMPTION_DISABLE is set to 1, individual tasks can be set to
|
||||
* either pre-emptive or co-operative mode using the vTaskPreemptionDisable and
|
||||
* vTaskPreemptionEnable APIs. */
|
||||
#define configUSE_TASK_PREEMPTION_DISABLE 0
|
||||
|
||||
/* When using SMP (i.e. configNUMBER_OF_CORES is greater than one), set
|
||||
* configUSE_PASSIVE_IDLE_HOOK to 1 to allow the application writer to use
|
||||
* the passive idle task hook to add background functionality without the
|
||||
* overhead of a separate task. Defaults to 0 if left undefined. */
|
||||
#define configUSE_PASSIVE_IDLE_HOOK 0
|
||||
|
||||
/* When using SMP (i.e. configNUMBER_OF_CORES is greater than one),
|
||||
* configTIMER_SERVICE_TASK_CORE_AFFINITY allows the application writer to set
|
||||
* the core affinity of the RTOS Daemon/Timer Service task. Defaults to
|
||||
* tskNO_AFFINITY if left undefined. */
|
||||
#define configTIMER_SERVICE_TASK_CORE_AFFINITY tskNO_AFFINITY
|
||||
|
||||
/******************************************************************************/
|
||||
/* ARMv8-M secure side port related definitions. ******************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* secureconfigMAX_SECURE_CONTEXTS define the maximum number of tasks that can
|
||||
* call into the secure side of an ARMv8-M chip. Not used by any other ports.
|
||||
*/
|
||||
#define secureconfigMAX_SECURE_CONTEXTS 5
|
||||
|
||||
/* Defines the kernel provided implementation of
|
||||
* vApplicationGetIdleTaskMemory() and vApplicationGetTimerTaskMemory()
|
||||
* to provide the memory that is used by the Idle task and Timer task
|
||||
* respectively. The application can provide it's own implementation of
|
||||
* vApplicationGetIdleTaskMemory() and vApplicationGetTimerTaskMemory() by
|
||||
* setting configKERNEL_PROVIDED_STATIC_MEMORY to 0 or leaving it undefined. */
|
||||
#define configKERNEL_PROVIDED_STATIC_MEMORY 0
|
||||
|
||||
/******************************************************************************/
|
||||
/* ARMv8-M port Specific Configuration definitions. ***************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* Set configENABLE_TRUSTZONE to 1 when running FreeRTOS on the non-secure side
|
||||
* to enable the TrustZone support in FreeRTOS ARMv8-M ports which allows the
|
||||
* non-secure FreeRTOS tasks to call the (non-secure callable) functions
|
||||
* exported from secure side. */
|
||||
#define configENABLE_TRUSTZONE 1
|
||||
|
||||
/* If the application writer does not want to use TrustZone, but the hardware
|
||||
* does not support disabling TrustZone then the entire application (including
|
||||
* the FreeRTOS scheduler) can run on the secure side without ever branching to
|
||||
* the non-secure side. To do that, in addition to setting
|
||||
* configENABLE_TRUSTZONE to 0, also set configRUN_FREERTOS_SECURE_ONLY to 1. */
|
||||
#define configRUN_FREERTOS_SECURE_ONLY 1
|
||||
|
||||
/* Set configENABLE_MPU to 1 to enable the Memory Protection Unit (MPU), or 0
|
||||
* to leave the Memory Protection Unit disabled. */
|
||||
#define configENABLE_MPU 0
|
||||
|
||||
/* Set configENABLE_FPU to 1 to enable the Floating Point Unit (FPU), or 0
|
||||
* to leave the Floating Point Unit disabled. */
|
||||
#define configENABLE_FPU 1
|
||||
|
||||
/* Set configENABLE_MVE to 1 to enable the M-Profile Vector Extension (MVE)
|
||||
* support, or 0 to leave the MVE support disabled. This option is only
|
||||
* applicable to Cortex-M52, Cortex-M55 and Cortex-M85 ports as M-Profile
|
||||
* Vector Extension (MVE) is available only on these architectures.
|
||||
* configENABLE_MVE must be left undefined, or defined to 0 for the
|
||||
* Cortex-M23,Cortex-M33 and Cortex-M35P ports. */
|
||||
#define configENABLE_MVE 0
|
||||
|
||||
/******************************************************************************/
|
||||
/* ARMv7-M and ARMv8-M port Specific Configuration definitions. ***************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* Set configCHECK_HANDLER_INSTALLATION to 1 to enable additional asserts to
|
||||
* verify that the application has correctly installed FreeRTOS interrupt
|
||||
* handlers.
|
||||
*
|
||||
* An application can install FreeRTOS interrupt handlers in one of the
|
||||
* following ways:
|
||||
* 1. Direct Routing - Install the functions vPortSVCHandler and
|
||||
* xPortPendSVHandler for SVC call and PendSV interrupts respectively.
|
||||
* 2. Indirect Routing - Install separate handlers for SVC call and PendSV
|
||||
* interrupts and route program control from those
|
||||
* handlers to vPortSVCHandler and xPortPendSVHandler functions. The
|
||||
* applications that use Indirect Routing must set
|
||||
* configCHECK_HANDLER_INSTALLATION to 0.
|
||||
*
|
||||
* Defaults to 1 if left undefined. */
|
||||
#define configCHECK_HANDLER_INSTALLATION 1
|
||||
|
||||
/******************************************************************************/
|
||||
/* Definitions that include or exclude functionality. *************************/
|
||||
/******************************************************************************/
|
||||
|
||||
/* Set the following configUSE_* constants to 1 to include the named feature in
|
||||
* the build, or 0 to exclude the named feature from the build. */
|
||||
#define configUSE_TASK_NOTIFICATIONS 1
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configUSE_RECURSIVE_MUTEXES 0
|
||||
#define configUSE_COUNTING_SEMAPHORES 0
|
||||
#define configUSE_QUEUE_SETS 0
|
||||
#define configUSE_APPLICATION_TASK_TAG 0
|
||||
|
||||
/* USE_POSIX_ERRNO enables the task global FreeRTOS_errno variable which will
|
||||
* contain the most recent error for that task. */
|
||||
#define configUSE_POSIX_ERRNO 0
|
||||
|
||||
/* Set the following INCLUDE_* constants to 1 to include the named API function,
|
||||
* or 0 to exclude the named API function. Most linkers will remove unused
|
||||
* functions even when the constant is 1. */
|
||||
#define INCLUDE_vTaskPrioritySet 1
|
||||
#define INCLUDE_uxTaskPriorityGet 1
|
||||
#define INCLUDE_vTaskDelete 1
|
||||
#define INCLUDE_vTaskSuspend 1
|
||||
#define INCLUDE_xTaskDelayUntil 1
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_xTaskGetSchedulerState 1
|
||||
#define INCLUDE_xTaskGetCurrentTaskHandle 1
|
||||
#define INCLUDE_uxTaskGetStackHighWaterMark 0
|
||||
#define INCLUDE_xTaskGetIdleTaskHandle 0
|
||||
#define INCLUDE_eTaskGetState 0
|
||||
#define INCLUDE_xTimerPendFunctionCall 0
|
||||
#define INCLUDE_xTaskAbortDelay 0
|
||||
#define INCLUDE_xTaskGetHandle 0
|
||||
#define INCLUDE_xTaskResumeFromISR 1
|
||||
|
||||
#endif /* FREERTOS_CONFIG_H */
|
||||
250
app/STM32F411XX_FLASH.ld
Normal file
250
app/STM32F411XX_FLASH.ld
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
**
|
||||
|
||||
** File : LinkerScript.ld
|
||||
**
|
||||
** Author : STM32CubeMX
|
||||
**
|
||||
** Abstract : Linker script for STM32F411RETx series
|
||||
** 512Kbytes FLASH and 128Kbytes RAM
|
||||
**
|
||||
** Set heap size, stack size and stack location according
|
||||
** to application requirements.
|
||||
**
|
||||
** Set memory bank area and size if external memory is used.
|
||||
**
|
||||
** Target : STMicroelectronics STM32
|
||||
**
|
||||
** Distribution: The file is distributed “as is,” without any warranty
|
||||
** of any kind.
|
||||
**
|
||||
*****************************************************************************
|
||||
** @attention
|
||||
**
|
||||
** <h2><center>© COPYRIGHT(c) 2025 STMicroelectronics</center></h2>
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without modification,
|
||||
** are permitted provided that the following conditions are met:
|
||||
** 1. Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
** this list of conditions and the following disclaimer in the documentation
|
||||
** and/or other materials provided with the distribution.
|
||||
** 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
** may be used to endorse or promote products derived from this software
|
||||
** without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
|
||||
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
|
||||
}
|
||||
|
||||
/* Highest address of the user mode stack */
|
||||
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of RAM */
|
||||
_sstack = _estack - _Min_Stack_Size;
|
||||
/* Generate a link error if heap and stack don't fit into RAM */
|
||||
_Min_Heap_Size = 0x200; /* required amount of heap */
|
||||
_Min_Stack_Size = 0x400; /* required amount of stack */
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into FLASH */
|
||||
.isr_vector :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
/* The program code and other data goes into FLASH */
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
} >FLASH
|
||||
|
||||
/* Constant data goes into FLASH */
|
||||
.rodata :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.ARM.extab (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.ARM (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.preinit_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.init_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.fini_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
|
||||
{
|
||||
. = ALIGN(4);
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
KEEP (*(.fini_array*))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
/* used by the startup to initialize data */
|
||||
_sidata = LOADADDR(.data);
|
||||
|
||||
/* Initialized data sections goes into RAM, load LMA copy after code */
|
||||
.data :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sdata = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
*(.RamFunc) /* .RamFunc sections */
|
||||
*(.RamFunc*) /* .RamFunc* sections */
|
||||
|
||||
. = ALIGN(4);
|
||||
} >RAM AT> FLASH
|
||||
|
||||
/* Initialized TLS data section */
|
||||
.tdata : ALIGN(4)
|
||||
{
|
||||
*(.tdata .tdata.* .gnu.linkonce.td.*)
|
||||
. = ALIGN(4);
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
PROVIDE(__data_end = .);
|
||||
PROVIDE(__tdata_end = .);
|
||||
} >RAM AT> FLASH
|
||||
|
||||
PROVIDE( __tdata_start = ADDR(.tdata) );
|
||||
PROVIDE( __tdata_size = __tdata_end - __tdata_start );
|
||||
|
||||
PROVIDE( __data_start = ADDR(.data) );
|
||||
PROVIDE( __data_size = __data_end - __data_start );
|
||||
|
||||
PROVIDE( __tdata_source = LOADADDR(.tdata) );
|
||||
PROVIDE( __tdata_source_end = LOADADDR(.tdata) + SIZEOF(.tdata) );
|
||||
PROVIDE( __tdata_source_size = __tdata_source_end - __tdata_source );
|
||||
|
||||
PROVIDE( __data_source = LOADADDR(.data) );
|
||||
PROVIDE( __data_source_end = __tdata_source_end );
|
||||
PROVIDE( __data_source_size = __data_source_end - __data_source );
|
||||
/* Uninitialized data section */
|
||||
.tbss (NOLOAD) : ALIGN(4)
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_sbss = .; /* define a global symbol at bss start */
|
||||
__bss_start__ = _sbss;
|
||||
*(.tbss .tbss.*)
|
||||
. = ALIGN(4);
|
||||
PROVIDE( __tbss_end = . );
|
||||
} >RAM
|
||||
|
||||
PROVIDE( __tbss_start = ADDR(.tbss) );
|
||||
PROVIDE( __tbss_size = __tbss_end - __tbss_start );
|
||||
PROVIDE( __tbss_offset = ADDR(.tbss) - ADDR(.tdata) );
|
||||
|
||||
PROVIDE( __tls_base = __tdata_start );
|
||||
PROVIDE( __tls_end = __tbss_end );
|
||||
PROVIDE( __tls_size = __tls_end - __tls_base );
|
||||
PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) );
|
||||
PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1) );
|
||||
PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) );
|
||||
PROVIDE( __arm64_tls_tcb_offset = MAX(16, __tls_align) );
|
||||
|
||||
.bss (NOLOAD) : ALIGN(4)
|
||||
{
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
_ebss = .; /* define a global symbol at bss end */
|
||||
__bss_end__ = _ebss;
|
||||
PROVIDE( __bss_end = .);
|
||||
} >RAM
|
||||
PROVIDE( __non_tls_bss_start = ADDR(.bss) );
|
||||
|
||||
PROVIDE( __bss_start = __tbss_start );
|
||||
PROVIDE( __bss_size = __bss_end - __bss_start );
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||
._user_heap_stack (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE ( end = . );
|
||||
PROVIDE ( _end = . );
|
||||
. = . + _Min_Heap_Size;
|
||||
. = . + _Min_Stack_Size;
|
||||
. = ALIGN(8);
|
||||
} >RAM
|
||||
|
||||
|
||||
|
||||
/* Remove information from the standard libraries */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a:* ( * )
|
||||
libm.a:* ( * )
|
||||
libgcc.a:* ( * )
|
||||
}
|
||||
|
||||
}
|
||||
24
app/cmake/CPM.cmake
Normal file
24
app/cmake/CPM.cmake
Normal file
@@ -0,0 +1,24 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
|
||||
|
||||
set(CPM_DOWNLOAD_VERSION 0.42.0)
|
||||
set(CPM_HASH_SUM "2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a")
|
||||
|
||||
if(CPM_SOURCE_CACHE)
|
||||
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
|
||||
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
else()
|
||||
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
endif()
|
||||
|
||||
# Expand relative path. This is important if the provided path contains a tilde (~)
|
||||
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
|
||||
|
||||
file(DOWNLOAD
|
||||
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
|
||||
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
|
||||
)
|
||||
|
||||
include(${CPM_DOWNLOAD_LOCATION})
|
||||
31
app/cmake/FreeRTOS.cmake
Normal file
31
app/cmake/FreeRTOS.cmake
Normal file
@@ -0,0 +1,31 @@
|
||||
# Add FetchContent
|
||||
include(FetchContent)
|
||||
|
||||
# Add FreeRTOS
|
||||
FetchContent_Declare(freertos_kernel
|
||||
GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git
|
||||
GIT_TAG V11.2.0
|
||||
)
|
||||
|
||||
add_library(freertos_config INTERFACE)
|
||||
|
||||
target_compile_definitions(freertos_config INTERFACE ${definitions})
|
||||
target_compile_options(freertos_config INTERFACE ${options})
|
||||
|
||||
target_include_directories(freertos_config SYSTEM
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/FreeRTOS
|
||||
)
|
||||
|
||||
target_compile_definitions(freertos_config
|
||||
INTERFACE
|
||||
projCOVERAGE_TEST=0
|
||||
)
|
||||
|
||||
# Set FreeRTOS port
|
||||
set(FREERTOS_PORT "GCC_ARM_CM4F" CACHE STRING "" FORCE)
|
||||
|
||||
FetchContent_MakeAvailable(freertos_kernel)
|
||||
|
||||
target_compile_options(freertos_kernel PRIVATE -g)
|
||||
target_compile_options(freertos_kernel_port PRIVATE -g)
|
||||
10
app/src/CMakeLists.txt
Normal file
10
app/src/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
add_subdirectory(tasks)
|
||||
add_subdirectory(incphub)
|
||||
add_subdirectory(nil)
|
||||
add_subdirectory(ntl)
|
||||
|
||||
target_sources(${EXECUTABLE} PRIVATE
|
||||
main.c
|
||||
)
|
||||
|
||||
target_include_directories(${EXECUTABLE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
11
app/src/incp_fake/messages.h
Normal file
11
app/src/incp_fake/messages.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef INCP_FAKE_MESSAGES_H_
|
||||
#define INCP_FAKE_MESSAGES_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
void *content;
|
||||
size_t len;
|
||||
} incp_any_msg_t;
|
||||
|
||||
#endif
|
||||
7
app/src/incphub/CMakeLists.txt
Normal file
7
app/src/incphub/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
target_sources(${EXECUTABLE} PRIVATE
|
||||
src/incphub_client.c
|
||||
src/incphub_task.c
|
||||
src/incphub_shared.c
|
||||
)
|
||||
|
||||
target_include_directories(${EXECUTABLE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
19
app/src/incphub/README.md
Normal file
19
app/src/incphub/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# INCPHUB
|
||||
|
||||
## FreeRTOS requirements
|
||||
|
||||
- INCLUDE_xTaskGetCurrentTaskHandle set to 1
|
||||
- INCLUDE_vTaskSuspend set to 1
|
||||
- configUSE_TASK_NOTIFICATIONS set to 1
|
||||
- configTASK_NOTIFICATION_ARRAY_ENTRIES set to >= 2 (0 is for stream/message buffers, 1(configurable) is used by incphub)
|
||||
- configUSE_MUTEXES set to 1
|
||||
|
||||
## Configuration
|
||||
|
||||
Set as a macro in compile flags if wishing to override the defaults
|
||||
|
||||
- INCPHUB_TASKINDEX_MAILBOX, defaults to 1 (avoid using 0)
|
||||
|
||||
## Setup
|
||||
|
||||
- incphub_task_preinit MUST be run before any calls to the client, likely even before the scheduler is started
|
||||
22
app/src/incphub/include/incphub/incphub.h
Normal file
22
app/src/incphub/include/incphub/incphub.h
Normal file
@@ -0,0 +1,22 @@
|
||||
// incphub.h - Public definitions common to incphub and incphub client
|
||||
|
||||
#ifndef INCPHUB_H_
|
||||
#define INCPHUB_H_
|
||||
|
||||
#include "ntl/ntl.h"
|
||||
#include "nil/nil.h"
|
||||
|
||||
#define INCPHUB_OK (0)
|
||||
#define INCPHUB_ERR (1)
|
||||
#define INCPHUB_EINVAL (2)
|
||||
#define INCPHUB_ENOTFOUND (3)
|
||||
#define INCPHUB_EBUSY (4)
|
||||
#define INCPHUB_EAGAIN (5)
|
||||
#define INCPHUB_ENOMEM (6)
|
||||
|
||||
typedef struct {
|
||||
nil_addr_t addr;
|
||||
ntl_port_t port;
|
||||
} incphub_addr_t;
|
||||
|
||||
#endif
|
||||
47
app/src/incphub/include/incphub/incphub_client.h
Normal file
47
app/src/incphub/include/incphub/incphub_client.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// incphub_client.h - Public interface of incphub client side
|
||||
|
||||
#ifndef INCPHUB_CLIENT_H_
|
||||
#define INCPHUB_CLIENT_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "incphub/incphub.h"
|
||||
|
||||
#include "nil/nil.h"
|
||||
#include "ntl/ntl.h"
|
||||
|
||||
|
||||
|
||||
typedef struct incphub_cli_t incphub_cli_t;
|
||||
|
||||
|
||||
|
||||
/// @brief Initializes an incphub client
|
||||
/// @param port The port number to assign to the caller
|
||||
/// @return INCPHUB_OK on success, an error otherwise
|
||||
int incphub_init_client(incphub_cli_t **cli, ntl_port_t port);
|
||||
|
||||
/// @brief Attempts to get a free message buffer from the central storage space
|
||||
/// @param cli Current client handle
|
||||
/// @param buffer_ptr Location to return the buffer
|
||||
/// @param length The minimum size, in bytes, of the buffer get
|
||||
/// @return INCPHUB_OK on success, an error otherwise
|
||||
int incphub_get_msg_buffer(incphub_cli_t *cli, uint8_t **buffer_ptr, size_t length);
|
||||
|
||||
/// @brief Attempts to send a message to the local interface
|
||||
/// @param cli Current client handle
|
||||
/// @param buffer The message buffer
|
||||
/// @param length The message length
|
||||
/// @param dst_port The destination NTL port
|
||||
/// @return INCPHUB_OK on success, an error otherwise
|
||||
int incphub_send_local(incphub_cli_t *cli, uint8_t *buffer, size_t length, ntl_port_t dst_port);
|
||||
|
||||
/// @brief Awaits the receival of a message
|
||||
/// @param cli Current client handle
|
||||
/// @param buffer_ptr Location to return the buffer
|
||||
/// @param length_ptr Location to return the length
|
||||
/// @param sender_ptr Location to return the message length
|
||||
/// @return INCPHUB_OK on success, an error otherwise
|
||||
int incphub_await_msg(incphub_cli_t *cli, uint8_t **buffer_ptr, size_t *length_ptr, incphub_addr_t *sender_ptr);
|
||||
|
||||
#endif
|
||||
25
app/src/incphub/include/incphub/incphub_task.h
Normal file
25
app/src/incphub/include/incphub/incphub_task.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef INCPHUB_TASK_H_
|
||||
#define INCPHUB_TASK_H_
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "FreeRTOSConfig.h"
|
||||
|
||||
#define INCPHUB_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
|
||||
#define INCPHUB_TASK_PRIORITY (configMAX_PRIORITIES - 1)
|
||||
|
||||
extern StackType_t _incphub_task_stack[INCPHUB_TASK_STACK_DEPTH];
|
||||
extern StaticTask_t _incphub_task;
|
||||
|
||||
void incphub_task_preinit();
|
||||
void incphub_task_main(void *params);
|
||||
|
||||
|
||||
|
||||
// === For IncpHub client ===
|
||||
|
||||
#include "queue.h"
|
||||
|
||||
extern QueueHandle_t incphub_ingest_queue;
|
||||
|
||||
#endif
|
||||
74
app/src/incphub/src/incphub_client.c
Normal file
74
app/src/incphub/src/incphub_client.c
Normal file
@@ -0,0 +1,74 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "incphub/incphub_client.h"
|
||||
#include "incphub/incphub_task.h"
|
||||
#include "incphub/incphub.h"
|
||||
#include "incphub_config.h"
|
||||
#include "incphub_shared.h"
|
||||
|
||||
#include "ntl/ntl.h"
|
||||
#include "nil/nil.h"
|
||||
|
||||
#include "message_buffer.h"
|
||||
|
||||
|
||||
|
||||
int incphub_init_client(incphub_cli_t **cli, ntl_port_t port)
|
||||
{
|
||||
return register_client(cli, port, xTaskGetCurrentTaskHandle());
|
||||
}
|
||||
|
||||
int incphub_get_msg_buffer(incphub_cli_t *cli, uint8_t **buffer_ptr, size_t length)
|
||||
{
|
||||
if (cli == NULL)
|
||||
return INCPHUB_EINVAL;
|
||||
if (buffer_ptr == NULL)
|
||||
return INCPHUB_EINVAL;
|
||||
|
||||
// Request extra space for NTL header
|
||||
size_t extended_len = sizeof(nil_header_t) + sizeof(ntl_header_t) + length;
|
||||
uint8_t *buf;
|
||||
|
||||
int status = get_msg_buffer(&buf, extended_len);
|
||||
if (status != INCPHUB_OK)
|
||||
return status;
|
||||
|
||||
// Return buffer
|
||||
*buffer_ptr = buf;
|
||||
|
||||
return INCPHUB_OK;
|
||||
}
|
||||
|
||||
int incphub_send_local(incphub_cli_t *cli, uint8_t *buffer, size_t length, ntl_port_t dst_port)
|
||||
{
|
||||
if (cli == NULL)
|
||||
return INCPHUB_EINVAL;
|
||||
if (buffer == NULL)
|
||||
return INCPHUB_EINVAL;
|
||||
if (dst_port == NTL_PORT_EMPTY)
|
||||
return INCPHUB_EINVAL;
|
||||
|
||||
// Unwind pointer
|
||||
ntl_packet_t *ntl_packet = (ntl_packet_t*)(buffer - sizeof(ntl_header_t));
|
||||
nil_packet_t *nil_packet = (nil_packet_t*)(ntl_packet - sizeof(ntl_header_t));
|
||||
size_t extended_len = sizeof(nil_header_t) + sizeof(ntl_header_t) + length;
|
||||
|
||||
// Populate NTL header
|
||||
ntl_build_header(&ntl_packet->header, dst_port, cli->port, length);
|
||||
|
||||
// Populate NIL header
|
||||
nil_build_header(&nil_packet->header, NIL_ADDR_LOCALHOST, INCPHUB_LOCAL_NIL_ADDR, length + sizeof(ntl_header_t));
|
||||
|
||||
// Pass to ingest
|
||||
return enqueue_message_ingest((uint8_t *)nil_packet, extended_len);
|
||||
}
|
||||
|
||||
int incphub_await_msg(incphub_cli_t *cli, uint8_t **buffer_ptr, size_t *length_ptr, incphub_addr_t *sender_ptr)
|
||||
{
|
||||
(void)cli;
|
||||
(void)buffer_ptr;
|
||||
(void)length_ptr;
|
||||
(void)sender_ptr;
|
||||
//TODO: Implement
|
||||
return INCPHUB_ERR;
|
||||
}
|
||||
30
app/src/incphub/src/incphub_config.h
Normal file
30
app/src/incphub/src/incphub_config.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// incphub_config.h - Default configurations for incphub
|
||||
|
||||
#ifndef INCPHUB_CONFIG_H_
|
||||
#define INCPHUB_CONFIG_H_
|
||||
|
||||
#ifndef INCPHUB_TASKINDEX_MAILBOX
|
||||
/// @brief Index of direct-to-task notification for mailbox to use
|
||||
#define INCPHUB_TASKINDEX_MAILBOX 1
|
||||
#endif
|
||||
|
||||
#ifndef INCPHUB_MAX_CLIENTS
|
||||
/// @brief Number of client slots to allocate
|
||||
#define INCPHUB_MAX_CLIENTS 16
|
||||
#endif
|
||||
|
||||
#ifndef INCPHUB_MSG_BUFFER_SIZE
|
||||
/// @brief Message buffer size in bytes. Must allow space for NIL and NTL headers
|
||||
#define INCPHUB_MSG_BUFFER_SIZE 32
|
||||
#endif
|
||||
|
||||
#ifndef INCPHUB_MSG_BUFFER_COUNT
|
||||
/// @brief Number of message buffers to allocate
|
||||
#define INCPHUB_MSG_BUFFER_COUNT 8
|
||||
#endif
|
||||
|
||||
#ifndef INCPHUB_LOCAL_NIL_ADDR
|
||||
#error "Local NIL address must be specified with INCPHUB_LOCAL_NIL_ADDR"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
201
app/src/incphub/src/incphub_shared.c
Normal file
201
app/src/incphub/src/incphub_shared.c
Normal file
@@ -0,0 +1,201 @@
|
||||
#include "incphub_shared.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "incphub/incphub.h"
|
||||
#include "incphub_config.h"
|
||||
|
||||
#include "nil/nil.h"
|
||||
|
||||
|
||||
// === Private variables ===
|
||||
|
||||
// Global lock
|
||||
static SemaphoreHandle_t _incphub_lock;
|
||||
static StaticSemaphore_t _incphub_lock_store;
|
||||
|
||||
// Clients
|
||||
static incphub_cli_t _clients[INCPHUB_MAX_CLIENTS];
|
||||
|
||||
// Message buffers
|
||||
// INCPHUB_MSG_BUFFER_COUNT buffers of INCPHUB_MSG_BUFFER_SIZE bytes
|
||||
static uint8_t _msg_buffers[INCPHUB_MSG_BUFFER_COUNT][INCPHUB_MSG_BUFFER_SIZE];
|
||||
static bool _msg_buffer_used[INCPHUB_MSG_BUFFER_COUNT];
|
||||
|
||||
|
||||
|
||||
// === Private function declarations ===
|
||||
static bool public_enter(TickType_t maxDelay);
|
||||
static void public_exit();
|
||||
static incphub_cli_t *find_empty_client();
|
||||
static incphub_cli_t *find_client_with_port(ntl_port_t port);
|
||||
static uint8_t *find_unused_buffer();
|
||||
|
||||
|
||||
|
||||
// === Public functions ===
|
||||
int internal_init()
|
||||
{
|
||||
_incphub_lock = xSemaphoreCreateMutexStatic(&_incphub_lock_store);
|
||||
memset(_clients, 0, sizeof(_clients));
|
||||
memset(_msg_buffer_used, 0, sizeof(_msg_buffer_used));
|
||||
return INCPHUB_OK;
|
||||
}
|
||||
|
||||
int register_client(incphub_cli_t **cli_ptr, ntl_port_t port, TaskHandle_t task)
|
||||
{
|
||||
if (port == NTL_PORT_EMPTY)
|
||||
return INCPHUB_EINVAL;
|
||||
|
||||
if (cli_ptr == NULL)
|
||||
return INCPHUB_EINVAL;
|
||||
|
||||
// == Enter ==
|
||||
if (!public_enter(portMAX_DELAY))
|
||||
return INCPHUB_EAGAIN;
|
||||
|
||||
// Prevent double binding of ports
|
||||
if (find_client_with_port(port) != NULL)
|
||||
{
|
||||
public_exit();
|
||||
return INCPHUB_EBUSY;
|
||||
}
|
||||
|
||||
incphub_cli_t *client = find_empty_client();
|
||||
if (client == NULL)
|
||||
{
|
||||
public_exit();
|
||||
return INCPHUB_EBUSY;
|
||||
}
|
||||
|
||||
// Populate client data
|
||||
client->port = port;
|
||||
client->task = task;
|
||||
|
||||
// Save to passed pointer
|
||||
*cli_ptr = client;
|
||||
|
||||
public_exit();
|
||||
return INCPHUB_OK;
|
||||
}
|
||||
|
||||
int get_msg_buffer(uint8_t **buffer_ptr, size_t len)
|
||||
{
|
||||
if (buffer_ptr == NULL)
|
||||
return INCPHUB_EINVAL;
|
||||
|
||||
// Ensure space for NIL header and payload
|
||||
if ((sizeof(nil_header_t) + len) > INCPHUB_MSG_BUFFER_SIZE)
|
||||
return INCPHUB_ENOMEM;
|
||||
|
||||
// == Enter ==
|
||||
if (!public_enter(portMAX_DELAY))
|
||||
return INCPHUB_EAGAIN;
|
||||
|
||||
//TODO: Allow buffer to be given by another layer (below NIL)
|
||||
uint8_t *buf = find_unused_buffer();
|
||||
if (buf == NULL)
|
||||
{
|
||||
public_exit();
|
||||
return INCPHUB_ENOMEM;
|
||||
}
|
||||
|
||||
// Reserve space for NIL header
|
||||
buf += sizeof(nil_header_t);
|
||||
|
||||
// Return buffer
|
||||
*buffer_ptr = buf;
|
||||
|
||||
public_exit();
|
||||
return INCPHUB_OK;
|
||||
}
|
||||
|
||||
int get_client_with_port(ntl_port_t port, incphub_cli_t **client_ptr)
|
||||
{
|
||||
if (port == NTL_PORT_EMPTY)
|
||||
return INCPHUB_EINVAL;
|
||||
|
||||
if (client_ptr == NULL)
|
||||
return INCPHUB_EINVAL;
|
||||
|
||||
// == Enter ==
|
||||
if (!public_enter(portMAX_DELAY))
|
||||
return INCPHUB_EAGAIN;
|
||||
|
||||
// Map port to client
|
||||
incphub_cli_t *client = find_client_with_port(port);
|
||||
if (client == NULL)
|
||||
{
|
||||
public_exit();
|
||||
return INCPHUB_ENOTFOUND;
|
||||
}
|
||||
|
||||
// Return client
|
||||
*client_ptr = client;
|
||||
|
||||
public_exit();
|
||||
return INCPHUB_OK;
|
||||
}
|
||||
|
||||
int enqueue_message_ingest(uint8_t *buffer, size_t length)
|
||||
{
|
||||
(void)buffer;
|
||||
(void)length;
|
||||
//TODO: Implement
|
||||
return INCPHUB_ERR;
|
||||
}
|
||||
|
||||
int dequeue_message_ingest(uint8_t **buffer_ptr, size_t *length_ptr)
|
||||
{
|
||||
(void)buffer_ptr;
|
||||
(void)length_ptr;
|
||||
//TODO: Implement
|
||||
return INCPHUB_ERR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// === Private function definitions ===
|
||||
static bool public_enter(TickType_t maxDelay)
|
||||
{
|
||||
return xSemaphoreTake(_incphub_lock, maxDelay) == pdTRUE;
|
||||
}
|
||||
|
||||
static void public_exit()
|
||||
{
|
||||
xSemaphoreGive(_incphub_lock);
|
||||
}
|
||||
|
||||
static incphub_cli_t *find_empty_client()
|
||||
{
|
||||
return find_client_with_port(NTL_PORT_EMPTY);
|
||||
}
|
||||
|
||||
static incphub_cli_t *find_client_with_port(ntl_port_t port)
|
||||
{
|
||||
for (int i = 0; i < INCPHUB_MAX_CLIENTS; ++i)
|
||||
{
|
||||
incphub_cli_t *client = &_clients[i];
|
||||
|
||||
if (client->port == port)
|
||||
return client;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint8_t *find_unused_buffer()
|
||||
{
|
||||
for (int i = 0; i < INCPHUB_MSG_BUFFER_COUNT; ++i)
|
||||
{
|
||||
if (!_msg_buffer_used[i])
|
||||
return _msg_buffers[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
61
app/src/incphub/src/incphub_shared.h
Normal file
61
app/src/incphub/src/incphub_shared.h
Normal file
@@ -0,0 +1,61 @@
|
||||
// incphub_sharedl.h - Internal mechanisms shared by incphub and incphub_client
|
||||
|
||||
#ifndef INCPHUB_SHARED_H_
|
||||
#define INCPHUB_SHARED_H_
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "nil/nil.h"
|
||||
#include "ntl/ntl.h"
|
||||
|
||||
|
||||
|
||||
struct incphub_cli_t {
|
||||
/// @remark If set to NTL_PORT_EMPTY denotes an empty client
|
||||
ntl_port_t port;
|
||||
TaskHandle_t task;
|
||||
};
|
||||
|
||||
#ifndef INCPHUB_CLIENT_H_
|
||||
typedef struct incphub_cli_t incphub_cli_t;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/// @brief Initializes the internal state of incphub
|
||||
/// @return INCPHUB_OK on success, an error otherwise
|
||||
int internal_init();
|
||||
|
||||
/// @brief Registers a task as an incphub client
|
||||
/// @param cli_ptr Location to return client
|
||||
/// @param port The port to register to
|
||||
/// @param task The task to register as the handler
|
||||
/// @return INCPHUB_OK on success, an error otherwise
|
||||
int register_client(incphub_cli_t **cli_ptr, ntl_port_t port, TaskHandle_t task);
|
||||
|
||||
/// @brief Attempts to get a free message buffer from the central storage space
|
||||
/// @param buffer_ptr Location to return the buffer
|
||||
/// @param len The minimum size, in bytes, of the buffer get
|
||||
/// @return INCPHUB_OK on success, an error otherwise
|
||||
int get_msg_buffer(uint8_t **buffer_ptr, size_t len);
|
||||
|
||||
/// @brief Attempts to get the client assigned to the given port
|
||||
/// @param port The port to look for
|
||||
/// @param client_ptr Location to return the client
|
||||
/// @return INCPHUB_OK on success, an error otherwise
|
||||
int get_client_with_port(ntl_port_t port, incphub_cli_t **client_ptr);
|
||||
|
||||
/// @brief Enqueues a message for ingest by the incphub task
|
||||
/// @param buffer The buffer to enqueue
|
||||
/// @param length The message length
|
||||
/// @return INCPHUB_OK on success, an error otherwise
|
||||
int enqueue_message_ingest(uint8_t *buffer, size_t length);
|
||||
|
||||
/// @brief Dequeues a message for ingest
|
||||
/// @param buffer_ptr Location to return the buffer
|
||||
/// @param length_ptr Location to store the message length
|
||||
/// @return INCPHUB_OK on success, an error otherwise
|
||||
int dequeue_message_ingest(uint8_t **buffer_ptr, size_t *length_ptr);
|
||||
|
||||
#endif
|
||||
138
app/src/incphub/src/incphub_task.c
Normal file
138
app/src/incphub/src/incphub_task.c
Normal file
@@ -0,0 +1,138 @@
|
||||
#include "incphub/incphub_task.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "queue.h"
|
||||
|
||||
#include "incphub/incphub.h"
|
||||
#include "incphub_config.h"
|
||||
#include "incphub_shared.h"
|
||||
|
||||
#include "ntl/ntl.h"
|
||||
#include "nil/nil.h"
|
||||
|
||||
|
||||
|
||||
// === Static task space ===
|
||||
StackType_t _incphub_task_stack[INCPHUB_TASK_STACK_DEPTH];
|
||||
StaticTask_t _incphub_task;
|
||||
|
||||
|
||||
|
||||
// === Public variables ===
|
||||
|
||||
// Queue<nil_packet_t*> Packets awaiting to be accepted by incphub
|
||||
QueueHandle_t incphub_ingest_queue;
|
||||
|
||||
|
||||
|
||||
// === Private variables ===
|
||||
#define INGEST_QUEUE_LENGTH (16)
|
||||
#define INGEST_QUEUE_ITEM_SIZE (sizeof(ntl_packet_t *))
|
||||
static uint8_t _ingest_queue_store[INGEST_QUEUE_LENGTH * INGEST_QUEUE_ITEM_SIZE];
|
||||
static StaticQueue_t _ingest_queue_static;
|
||||
|
||||
|
||||
|
||||
// === Private functions ===
|
||||
static nil_packet_t *extract_nil_packet(uint8_t *buffer, size_t length);
|
||||
static ntl_packet_t *extract_ntl_packet(nil_packet_t *nil);
|
||||
static void handle_nil_packet(nil_packet_t *nil);
|
||||
static void handle_ntl_packet(ntl_packet_t *ntl);
|
||||
|
||||
|
||||
|
||||
// === Public functions ===
|
||||
void incphub_task_preinit()
|
||||
{
|
||||
internal_init();
|
||||
incphub_ingest_queue =
|
||||
xQueueCreateStatic(INGEST_QUEUE_LENGTH, INGEST_QUEUE_ITEM_SIZE, _ingest_queue_store, &_ingest_queue_static);
|
||||
}
|
||||
|
||||
void incphub_task_main(void *params)
|
||||
{
|
||||
(void)params;
|
||||
|
||||
while (1)
|
||||
{
|
||||
uint8_t *buffer;
|
||||
size_t length;
|
||||
dequeue_message_ingest(&buffer, &length);
|
||||
|
||||
nil_packet_t *nil = extract_nil_packet(buffer, length);
|
||||
if (nil == NULL)
|
||||
{
|
||||
//TODO: Error
|
||||
continue;
|
||||
}
|
||||
|
||||
handle_nil_packet(nil);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// === Private functions ===
|
||||
static nil_packet_t *extract_nil_packet(uint8_t *buffer, size_t length)
|
||||
{
|
||||
if (length < sizeof(nil_packet_t))
|
||||
{
|
||||
//TODO: Error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nil_packet_t *nil = (nil_packet_t *)buffer;
|
||||
if (length < sizeof(nil_packet_t) + nil->header.len )
|
||||
{
|
||||
//TODO: Error
|
||||
return NULL;;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
static ntl_packet_t *extract_ntl_packet(nil_packet_t *nil)
|
||||
{
|
||||
if (nil->header.len < sizeof(ntl_packet_t))
|
||||
{
|
||||
//TODO: Error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ntl_packet_t *ntl = (ntl_packet_t *)nil->payload;
|
||||
|
||||
if (nil->header.len < sizeof(ntl_packet_t) + ntl->header.len)
|
||||
{
|
||||
//TODO: Error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ntl;
|
||||
}
|
||||
|
||||
static void handle_nil_packet(nil_packet_t *nil)
|
||||
{
|
||||
if (nil->header.dst_addr == INCPHUB_LOCAL_NIL_ADDR)
|
||||
{
|
||||
ntl_packet_t *ntl = extract_ntl_packet(nil);
|
||||
if (ntl == NULL)
|
||||
{
|
||||
//TODO: Error
|
||||
return;
|
||||
}
|
||||
|
||||
handle_ntl_packet(ntl);
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO: Route to external interface
|
||||
return;
|
||||
}
|
||||
|
||||
static void handle_ntl_packet(ntl_packet_t *ntl)
|
||||
{
|
||||
(void)ntl;
|
||||
//TODO: Implement
|
||||
}
|
||||
0
app/src/incphub/src/incphub_task_internal.h
Normal file
0
app/src/incphub/src/incphub_task_internal.h
Normal file
22
app/src/main.c
Normal file
22
app/src/main.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "main.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "tasks/heartbeat_task.h"
|
||||
#include "incphub/incphub_task.h"
|
||||
|
||||
int my_main()
|
||||
{
|
||||
// Init
|
||||
incphub_task_preinit();
|
||||
|
||||
// Create tasks
|
||||
xTaskCreateStatic(heartbeat_task_main, "heartbeat", HEARTBEAT_TASK_STACK_DEPTH, NULL, HEARTBEAT_TASK_PRIORITY, _heartbeat_task_stack, &_heartbeat_task);
|
||||
xTaskCreateStatic(incphub_task_main, "incphub", INCPHUB_TASK_STACK_DEPTH, NULL, INCPHUB_TASK_PRIORITY, _incphub_task_stack, &_incphub_task);
|
||||
|
||||
// Run
|
||||
vTaskStartScheduler();
|
||||
|
||||
return 0;
|
||||
}
|
||||
1
app/src/nil/CMakeLists.txt
Normal file
1
app/src/nil/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
target_include_directories(${EXECUTABLE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
3
app/src/nil/README.md
Normal file
3
app/src/nil/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# NIL
|
||||
|
||||
Nanosatlab Internet Layer (from IP model)
|
||||
87
app/src/nil/include/nil/nil.h
Normal file
87
app/src/nil/include/nil/nil.h
Normal file
@@ -0,0 +1,87 @@
|
||||
#ifndef NIL_H_
|
||||
#define NIL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
// === Type Aliases ===
|
||||
|
||||
typedef uint8_t nil_addr_t;
|
||||
typedef uint32_t ntl_chk_t;
|
||||
|
||||
|
||||
|
||||
// === Special Port Values ===
|
||||
|
||||
#define NIL_ADDR_LOCALHOST ((nil_addr_t)0)
|
||||
|
||||
|
||||
|
||||
// === Special Check Values ===
|
||||
|
||||
/// @brief Denotes no check value to validate
|
||||
#define NIL_CHK_EMPTY ((ntl_chk_t)0)
|
||||
|
||||
|
||||
|
||||
// === Struct Definitions ===
|
||||
|
||||
/// @brief Packed header format
|
||||
typedef struct __attribute__((packed, aligned(4))) {
|
||||
nil_addr_t dst_addr;
|
||||
nil_addr_t src_addr;
|
||||
uint16_t len;
|
||||
ntl_chk_t chk;
|
||||
} nil_header_t;
|
||||
|
||||
/// @brief An NIL packet (packed) with header and payload
|
||||
typedef struct __attribute__((packed, aligned(4))) {
|
||||
nil_header_t header;
|
||||
uint8_t payload[];
|
||||
} nil_packet_t;
|
||||
|
||||
|
||||
|
||||
// === Convenience Functions ===
|
||||
|
||||
/// @brief Convert uint16 value from host to network byte order
|
||||
/// @param value The value in host order
|
||||
/// @return The value in network order
|
||||
static inline uint16_t nil_htons(uint16_t value)
|
||||
{
|
||||
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \
|
||||
defined(__BIG_ENDIAN__) || \
|
||||
defined(__ARMEB__) || \
|
||||
defined(__THUMBEB__) || \
|
||||
defined(__AARCH64EB__) || \
|
||||
defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__)
|
||||
return ((value << 8) & 0xFF) | ((value & 0xFF) << 8);
|
||||
#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \
|
||||
defined(__LITTLE_ENDIAN__) || \
|
||||
defined(__ARMEL__) || \
|
||||
defined(__THUMBEL__) || \
|
||||
defined(__AARCH64EL__) || \
|
||||
defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
|
||||
return value;
|
||||
#else
|
||||
#error "Unable to detect byte endianness of platform."
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/// @brief Populates an NIL header from the provided fields
|
||||
/// @param hdr The header to pupulate
|
||||
/// @param dst The destination address
|
||||
/// @param src The source address
|
||||
/// @param len The length of the NIL payload in bytes
|
||||
static inline void nil_build_header(volatile nil_header_t *hdr, nil_addr_t dst, nil_addr_t src, uint16_t len)
|
||||
{
|
||||
hdr->dst_addr = dst;
|
||||
hdr->src_addr = src;
|
||||
hdr->len = nil_htons(len);
|
||||
//REVIEW: Disabled for now, add a flag to set this to an actual check?
|
||||
hdr->chk = NIL_CHK_EMPTY;
|
||||
}
|
||||
|
||||
#endif
|
||||
1
app/src/ntl/CMakeLists.txt
Normal file
1
app/src/ntl/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
target_include_directories(${EXECUTABLE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
7
app/src/ntl/README.md
Normal file
7
app/src/ntl/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# NTL
|
||||
|
||||
Nanosatlab Transport Layer (from IP model)
|
||||
|
||||
## Byte ordering
|
||||
|
||||
Multi-byte fields are sent in little-endian order. (Natural order for x86 and arm)
|
||||
96
app/src/ntl/include/ntl/ntl.h
Normal file
96
app/src/ntl/include/ntl/ntl.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#ifndef NTL_H_
|
||||
#define NTL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
// === Type Aliases ===
|
||||
|
||||
/// @brief An NTL port number
|
||||
typedef uint8_t ntl_port_t;
|
||||
/// @brief An NTL check value
|
||||
typedef uint32_t ntl_chk_t;
|
||||
|
||||
|
||||
|
||||
// === Special Port Values ===
|
||||
|
||||
/// @brief Denotes an invalid port number
|
||||
#define NTL_PORT_EMPTY ((ntl_port_t)0)
|
||||
/// @brief The highest valid port number
|
||||
#define NTL_MAX_PORT (~(ntl_port_t)0)
|
||||
|
||||
|
||||
|
||||
// === Special Check Values ===
|
||||
|
||||
/// @brief Denotes no check value to validate
|
||||
#define NTL_CHK_EMPTY ((ntl_chk_t)0)
|
||||
|
||||
|
||||
|
||||
// === Struct Definitions ===
|
||||
|
||||
/// @brief Packed header format
|
||||
typedef struct __attribute__((packed, aligned(4))) {
|
||||
ntl_port_t dst_port;
|
||||
ntl_port_t src_port;
|
||||
uint16_t len;
|
||||
ntl_chk_t chk;
|
||||
} ntl_header_t;
|
||||
|
||||
/// @brief An NTL packet (packed) with header and payload
|
||||
typedef struct __attribute__((packed, aligned(4))) {
|
||||
ntl_header_t header;
|
||||
uint8_t payload[];
|
||||
} ntl_packet_t;
|
||||
|
||||
|
||||
|
||||
// === Convenience Functions ===
|
||||
|
||||
/// @brief Convert uint16 value from host to network byte order
|
||||
/// @param value The value in host order
|
||||
/// @return The value in network order
|
||||
static inline uint16_t ntl_htons(uint16_t value)
|
||||
{
|
||||
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \
|
||||
defined(__BIG_ENDIAN__) || \
|
||||
defined(__ARMEB__) || \
|
||||
defined(__THUMBEB__) || \
|
||||
defined(__AARCH64EB__) || \
|
||||
defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__)
|
||||
return ((value << 8) & 0xFF) | ((value & 0xFF) << 8);
|
||||
#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \
|
||||
defined(__LITTLE_ENDIAN__) || \
|
||||
defined(__ARMEL__) || \
|
||||
defined(__THUMBEL__) || \
|
||||
defined(__AARCH64EL__) || \
|
||||
defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
|
||||
return value;
|
||||
#else
|
||||
#error "Unable to detect byte endianness of platform."
|
||||
#endif
|
||||
}
|
||||
|
||||
/// @brief Populates an NTL header from the provided fields
|
||||
/// @param hdr The header to pupulate
|
||||
/// @param dst The destination port
|
||||
/// @param src The source port
|
||||
/// @param len The length of the NTL payload in bytes
|
||||
static inline void ntl_build_header(volatile ntl_header_t *hdr, ntl_port_t dst, ntl_port_t src, uint16_t len)
|
||||
{
|
||||
hdr->dst_port = dst;
|
||||
hdr->src_port = src;
|
||||
hdr->len = ntl_htons(len);
|
||||
//REVIEW: Disabled for now, add a flag to set this to an actual check?
|
||||
hdr->chk = NTL_CHK_EMPTY;
|
||||
}
|
||||
|
||||
static inline ntl_port_t ntl_get_dst(const ntl_header_t *hdr) { return hdr->dst_port; }
|
||||
static inline ntl_port_t ntl_get_src(const ntl_header_t *hdr) { return hdr->src_port; }
|
||||
static inline ntl_port_t ntl_get_len(const ntl_header_t *hdr) { return ntl_htons(hdr->len); }
|
||||
static inline ntl_port_t ntl_get_chk(const ntl_header_t *hdr) { return hdr->chk; }
|
||||
|
||||
#endif
|
||||
4
app/src/tasks/CMakeLists.txt
Normal file
4
app/src/tasks/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
target_sources(${EXECUTABLE} PRIVATE
|
||||
tasks.c
|
||||
heartbeat_task.c
|
||||
)
|
||||
27
app/src/tasks/heartbeat_task.c
Normal file
27
app/src/tasks/heartbeat_task.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "heartbeat_task.h"
|
||||
|
||||
#include "stm32f4xx_hal.h"
|
||||
#include "stm32f4xx_hal_gpio.h"
|
||||
#include "gpio.h"
|
||||
|
||||
|
||||
|
||||
StackType_t _heartbeat_task_stack[HEARTBEAT_TASK_STACK_DEPTH];
|
||||
StaticTask_t _heartbeat_task;
|
||||
|
||||
|
||||
|
||||
void heartbeat_task_main(void *params)
|
||||
{
|
||||
(void)params;
|
||||
|
||||
TickType_t last_wake = xTaskGetTickCount();
|
||||
|
||||
while (1)
|
||||
{
|
||||
xTaskDelayUntil(&last_wake, 298);
|
||||
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
|
||||
xTaskDelayUntil(&last_wake, 2);
|
||||
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
16
app/src/tasks/heartbeat_task.h
Normal file
16
app/src/tasks/heartbeat_task.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _HEARTBEAT_TASK_H_
|
||||
#define _HEARTBEAT_TASK_H_
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "FreeRTOSConfig.h"
|
||||
|
||||
#define HEARTBEAT_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
|
||||
#define HEARTBEAT_TASK_PRIORITY (configMAX_PRIORITIES - 1)
|
||||
|
||||
extern StackType_t _heartbeat_task_stack[HEARTBEAT_TASK_STACK_DEPTH];
|
||||
extern StaticTask_t _heartbeat_task;
|
||||
|
||||
void heartbeat_task_main(void *params);
|
||||
|
||||
#endif
|
||||
21
app/src/tasks/tasks.c
Normal file
21
app/src/tasks/tasks.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
static StaticTask_t xIdleTaskTCB;
|
||||
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
|
||||
|
||||
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
|
||||
StackType_t **ppxIdleTaskStackBuffer,
|
||||
size_t *pulIdleTaskStackSize)
|
||||
{
|
||||
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
|
||||
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
|
||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
||||
}
|
||||
|
||||
void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName)
|
||||
{
|
||||
(void)pxTask;
|
||||
(void)pcTaskName;
|
||||
while (1); //TODO: Better handling (external feedback?)
|
||||
}
|
||||
Reference in New Issue
Block a user