├── .git-blame-ignore-revs ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake ├── Linux.cmake ├── MCUXSDK │ └── iMX8MM.cmake ├── OsalConfig.cmake.in ├── STM32Cube.cmake ├── STM32Cube │ └── STM32F769I-DISCO.cmake ├── Windows.cmake ├── iMX8MM.cmake └── rt-kernel.cmake ├── include ├── osal.h └── osal_log.h ├── src ├── freertos │ ├── STM32F769I-DISCO │ │ ├── Inc │ │ │ ├── FreeRTOSConfig.h │ │ │ ├── bsp_driver_sd.h │ │ │ ├── ethernetif.h │ │ │ ├── fatfs.h │ │ │ ├── fatfs_platform.h │ │ │ ├── ffconf.h │ │ │ ├── lwip_hooks.h │ │ │ ├── lwipopts.h │ │ │ ├── main.h │ │ │ ├── sd_diskio.h │ │ │ ├── stm32f7xx_hal_conf.h │ │ │ └── stm32f7xx_it.h │ │ ├── STM32F769NIHx_FLASH.ld │ │ └── Src │ │ │ ├── bsp_driver_sd.c │ │ │ ├── ethernetif.c │ │ │ ├── fatfs.c │ │ │ ├── fatfs_platform.c │ │ │ ├── freertos.c │ │ │ ├── lwip.c │ │ │ ├── lwip.h │ │ │ ├── main.c │ │ │ ├── sd_diskio.c │ │ │ ├── startup_stm32f769xx.s │ │ │ ├── stm32f7xx_hal_msp.c │ │ │ ├── stm32f7xx_hal_timebase_tim.c │ │ │ ├── stm32f7xx_it.c │ │ │ ├── stubs.c │ │ │ ├── syscalls.c │ │ │ └── system_stm32f7xx.c │ ├── iMX8MM │ │ ├── Inc │ │ │ ├── FreeRTOSConfig.h │ │ │ ├── lwip_hooks.h │ │ │ ├── lwipopts.h │ │ │ └── pin_mux.h │ │ ├── MIMX8MM6xxxxx_cm4_ddr_ram.ld │ │ └── Src │ │ │ ├── main.c │ │ │ └── pin_mux.c │ ├── osal.c │ ├── osal_log.c │ └── sys │ │ ├── osal_cc.h │ │ └── osal_sys.h ├── linux │ ├── osal.c │ ├── osal_log.c │ └── sys │ │ ├── osal_cc.h │ │ └── osal_sys.h ├── rt-kernel │ ├── osal.c │ ├── osal_log.c │ └── sys │ │ ├── osal_cc.h │ │ └── osal_sys.h └── windows │ ├── osal.c │ ├── osal_log.c │ └── sys │ ├── osal_cc.h │ └── osal_sys.h ├── test ├── CMakeLists.txt ├── osal_test.cpp └── test_osal.cpp └── version.h.in /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # This file contains a list of commits that are not likely what you 2 | # are looking for in a blame, such as mass reformatting or renaming. 3 | # You can set this file as a default ignore file for blame by running 4 | # the following command. 5 | # 6 | # $ git config blame.ignoreRevsFile .git-blame-ignore-revs 7 | 8 | # Run clang-format 9 | 659a44a746a2a6853aed9276587168f7bb86a05d 10 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #******************************************************************** 2 | # _ _ _ 3 | # _ __ | |_ _ | | __ _ | |__ ___ 4 | # | '__|| __|(_)| | / _` || '_ \ / __| 5 | # | | | |_ _ | || (_| || |_) |\__ \ 6 | # |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | # 8 | # www.rt-labs.com 9 | # Copyright 2017 rt-labs AB, Sweden. 10 | # 11 | # This software is licensed under the terms of the BSD 3-clause 12 | # license. See the file LICENSE distributed with this software for 13 | # full license information. 14 | #*******************************************************************/ 15 | 16 | cmake_minimum_required (VERSION 3.14) 17 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 18 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/tools") 19 | project (OSAL VERSION 0.1.0) 20 | 21 | include(GetGitRevision) 22 | 23 | # Default settings if this is the main project 24 | if (CMAKE_PROJECT_NAME STREQUAL OSAL) 25 | include(CTest) 26 | 27 | # Default to release build with debug info 28 | if (NOT CMAKE_BUILD_TYPE) 29 | set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING 30 | "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." 31 | FORCE) 32 | endif (NOT CMAKE_BUILD_TYPE) 33 | 34 | # Default to installing in build directory 35 | if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 36 | set(CMAKE_INSTALL_PREFIX ${OSAL_BINARY_DIR}/install 37 | CACHE PATH "Default install path" FORCE) 38 | endif() 39 | 40 | message(STATUS "Current build type is: ${CMAKE_BUILD_TYPE}") 41 | message(STATUS "Current install path is: ${CMAKE_INSTALL_PREFIX}") 42 | message(STATUS "Building for ${CMAKE_SYSTEM_NAME}") 43 | endif() 44 | 45 | # Always use standard .o suffix 46 | set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1) 47 | set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1) 48 | 49 | # Generate version numbers 50 | configure_file ( 51 | version.h.in 52 | ${OSAL_BINARY_DIR}/src/version.h 53 | ) 54 | 55 | # Add platform-dependent targets early, so they can be configured by 56 | # platform 57 | add_library(osal "") 58 | 59 | # Suppress certain warnings when building with MSVC 60 | if (WINDOWS_MONO) 61 | target_compile_options (osal 62 | PRIVATE 63 | /wd4820 # padding added 64 | ) 65 | endif() 66 | 67 | # Use position independent code if platform supports shared libraries 68 | get_property(SUPPORTS_SHARED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS) 69 | if (SUPPORTS_SHARED) 70 | set_property(TARGET osal PROPERTY POSITION_INDEPENDENT_CODE ON) 71 | endif() 72 | 73 | if (CMAKE_PROJECT_NAME STREQUAL OSAL AND BUILD_TESTING) 74 | add_executable(osal_test "") 75 | endif() 76 | 77 | # Platform configuration 78 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_SYSTEM_NAME}.cmake) 79 | 80 | set_target_properties (osal 81 | PROPERTIES 82 | C_STANDARD 99 83 | ) 84 | 85 | target_compile_features(osal PUBLIC c_std_99) 86 | 87 | target_include_directories(osal 88 | PUBLIC 89 | $ 90 | $ 91 | PRIVATE 92 | src 93 | ${OSAL_BINARY_DIR}/src 94 | ) 95 | 96 | install( 97 | TARGETS osal 98 | EXPORT OsalTargets 99 | ) 100 | 101 | install( 102 | EXPORT OsalTargets 103 | FILE OsalTargets.cmake 104 | DESTINATION cmake 105 | ) 106 | 107 | include(CMakePackageConfigHelpers) 108 | configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/OsalConfig.cmake.in 109 | "${CMAKE_CURRENT_BINARY_DIR}/OsalConfig.cmake" 110 | INSTALL_DESTINATION cmake 111 | NO_SET_AND_CHECK_MACRO 112 | NO_CHECK_REQUIRED_COMPONENTS_MACRO 113 | ) 114 | 115 | install(FILES 116 | ${CMAKE_CURRENT_BINARY_DIR}/OsalConfig.cmake 117 | DESTINATION cmake 118 | ) 119 | 120 | install(FILES 121 | include/osal.h 122 | include/osal_log.h 123 | DESTINATION include 124 | ) 125 | 126 | if (CMAKE_PROJECT_NAME STREQUAL OSAL AND BUILD_TESTING) 127 | add_subdirectory (test) 128 | include(AddGoogleTest) 129 | add_gtest(osal_test) 130 | endif() 131 | 132 | # Doxygen configuration 133 | cmake_policy(SET CMP0057 NEW) 134 | find_package(Doxygen) 135 | if (CMAKE_PROJECT_NAME STREQUAL OSAL AND DOXYGEN_FOUND) 136 | set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES) 137 | set(DOXYGEN_TYPEDEF_HIDES_STRUCT YES) 138 | set(DOXYGEN_EXTRACT_STATIC YES) 139 | set(DOXYGEN_STRIP_CODE_COMMENTS NO) 140 | set(DOXYGEN_MACRO_EXPANSION YES) 141 | set(DOXYGEN_EXPAND_ONLY_PREDEF YES) 142 | set(DOXYGEN_PREDEFINED OSAL_EXPORT) 143 | set(DOXYGEN_EXPAND_AS_DEFINED OSAL_EXPORT) 144 | set(DOXYGEN_COLLABORATION_GRAPH NO) 145 | set(DOXYGEN_INCLUDE_GRAPH NO) 146 | set(DOXYGEN_INCLUDED_BY_GRAPH NO) 147 | set(DOXYGEN_RECURSIVE NO) 148 | set(DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md) 149 | doxygen_add_docs(docs 150 | README.md 151 | include 152 | src 153 | ) 154 | endif() 155 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, rt-labs AB 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OS abstraction layer 2 | ==================== 3 | [![Build Status](https://github.com/rtlabs-com/osal/workflows/Build/badge.svg?branch=master)](https://github.com/rtlabs-com/osal/actions?workflow=Build) 4 | [![CodeQL](https://github.com/rtlabs-com/osal/workflows/CodeQL/badge.svg?branch=master)](https://github.com/rtlabs-com/osal/actions?workflow=CodeQL) 5 | 6 | This repository contains an OS abstraction layer. The goal of the 7 | abstraction layer is to simplify writing software that runs on many 8 | platforms. This abstraction layer is mainly focused on threading 9 | functionality. 10 | 11 | Cloning 12 | ======= 13 | 14 | Clone the source: 15 | 16 | ``` 17 | $ git clone --recurse-submodules https://github.com/rtlabs-com/osal.git 18 | ``` 19 | 20 | This will clone the repository with submodules. If you already cloned 21 | the repository without the `--recurse-submodules` flag then run this 22 | in the osal folder: 23 | 24 | ``` 25 | $ git submodule update --init --recursive 26 | ``` 27 | 28 | Prerequisites for all platforms 29 | =============================== 30 | 31 | * CMake 3.14 or later 32 | 33 | Windows 34 | ======= 35 | 36 | * Visual Studio 2017 or later 37 | 38 | You can use a windows or unix shell as preferred. The following 39 | instructions are for a unix shell. CMake is assumed to be in your 40 | path. 41 | 42 | ``` 43 | $ cmake -B build.win64 -A x64 44 | $ cmake --build build.win64 --config Release 45 | $ cmake --build build.win64 --config Release --target check 46 | ``` 47 | 48 | This builds the project and runs the unit tests. 49 | 50 | Linux 51 | ===== 52 | 53 | * GCC 4.6 or later 54 | 55 | ``` 56 | $ cmake -B build 57 | $ cmake --build build --target all check 58 | ``` 59 | 60 | This builds the project and runs the unit tests. 61 | 62 | rt-kernel 63 | ========= 64 | 65 | * Workbench 2020.1 or later 66 | 67 | You should use a bash shell, such as for instance the Command Line in 68 | your Toolbox installation. Set the BSP variable to the name of the BSP 69 | you wish to build for. Set the RTK variable to the path of your 70 | rt-kernel tree. 71 | 72 | Standalone project 73 | ------------------ 74 | 75 | This creates standalone makefiles. 76 | 77 | ``` 78 | $ RTK=/path/to/rt-kernel BSP=xmc48relax cmake \ 79 | -B build.xmc48relax \ 80 | -DCMAKE_TOOLCHAIN_FILE=cmake/tools/toolchain/rt-kernel.cmake \ 81 | -G "Unix Makefiles" 82 | $ cmake --build build.xmc48relax 83 | ``` 84 | 85 | Workbench project 86 | ----------------- 87 | 88 | This creates a Makefile project that can be imported to Workbench. The 89 | project will be created in the build directory. The build directory 90 | should be located outside of the source tree. 91 | 92 | ``` 93 | $ RTK=/path/to/rt-kernel BSP=xmc48relax cmake \ 94 | -B build.xmc48relax -S /path/to/osal \ 95 | -DCMAKE_TOOLCHAIN_FILE=cmake/tools/toolchain/rt-kernel.cmake \ 96 | -DCMAKE_ECLIPSE_EXECUTABLE=/opt/rt-tools/workbench/Workbench \ 97 | -DCMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=TRUE \ 98 | -G "Eclipse CDT4 - Unix Makefiles" 99 | ``` 100 | 101 | A source project will also be created in the osal tree. This project 102 | can also be imported to Workbench. After importing, right-click on the 103 | project and choose *New* -> *Convert to a C/C++ project*. This will 104 | setup the project so that the indexer works correctly and the 105 | Workbench revision control tools can be used. 106 | 107 | The library and the unit tests will be built. Note that the tests 108 | require a stack of at least 6 kB. You may have to increase 109 | CFG_MAIN_STACK_SIZE in your bsp include/config.h file. 110 | 111 | STM32Cube / FreeRTOS / lwIP 112 | =========================== 113 | 114 | First, clone the relevant STM32Cube repo for your platform. For 115 | instance, to build for STM32F7 (fetching a specific tag only): 116 | 117 | ``` 118 | $ git clone https://github.com/STMicroelectronics/STM32CubeF7.git \ 119 | -b v1.16.1 --single-branch --depth 1 120 | ``` 121 | 122 | Then, when configuring specify CPU, board and path to the cloned git 123 | repository: 124 | 125 | ``` 126 | $ CPU=cortex-m7fd BOARD=STM32F769I-DISCO CUBE_DIR=/path/to/cube cmake \ 127 | -B build.cube \ 128 | -DCMAKE_TOOLCHAIN_FILE=cmake/tools/toolchain/stm32cube.cmake \ 129 | -G "Unix Makefiles" 130 | $ cmake --build build.cube 131 | ``` 132 | 133 | -------------------------------------------------------------------------------- /cmake/Linux.cmake: -------------------------------------------------------------------------------- 1 | #******************************************************************** 2 | # _ _ _ 3 | # _ __ | |_ _ | | __ _ | |__ ___ 4 | # | '__|| __|(_)| | / _` || '_ \ / __| 5 | # | | | |_ _ | || (_| || |_) |\__ \ 6 | # |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | # 8 | # www.rt-labs.com 9 | # Copyright 2017 rt-labs AB, Sweden. 10 | # 11 | # This software is licensed under the terms of the BSD 3-clause 12 | # license. See the file LICENSE distributed with this software for 13 | # full license information. 14 | #*******************************************************************/ 15 | 16 | find_package(Threads) 17 | 18 | option (USE_SCHED_FIFO 19 | "Use SCHED_FIFO policy. May require extra privileges to run" 20 | OFF) 21 | 22 | target_sources(osal PRIVATE 23 | src/linux/osal.c 24 | src/linux/osal_log.c 25 | ) 26 | 27 | target_compile_options(osal 28 | PRIVATE 29 | -Wall 30 | -Wextra 31 | -Werror 32 | -Wno-unused-parameter 33 | $<$:-DUSE_SCHED_FIFO> 34 | INTERFACE 35 | $<$:--coverage> 36 | ) 37 | 38 | target_include_directories(osal PUBLIC 39 | $ 40 | ) 41 | 42 | target_link_libraries(osal PUBLIC 43 | Threads::Threads 44 | rt 45 | INTERFACE 46 | $<$:--coverage> 47 | ) 48 | 49 | install(FILES 50 | src/linux/sys/osal_cc.h 51 | src/linux/sys/osal_sys.h 52 | DESTINATION include/sys 53 | ) 54 | 55 | if (BUILD_TESTING) 56 | set(GOOGLE_TEST_INDIVIDUAL TRUE) 57 | endif() 58 | -------------------------------------------------------------------------------- /cmake/MCUXSDK/iMX8MM.cmake: -------------------------------------------------------------------------------- 1 | #******************************************************************** 2 | # _ _ _ 3 | # _ __ | |_ _ | | __ _ | |__ ___ 4 | # | '__|| __|(_)| | / _` || '_ \ / __| 5 | # | | | |_ _ | || (_| || |_) |\__ \ 6 | # |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | # 8 | # www.rt-labs.com 9 | # Copyright 2021 rt-labs AB, Sweden. 10 | # Copyright 2023 NXP 11 | # 12 | # This software is licensed under the terms of the BSD 3-clause 13 | # license. See the file LICENSE distributed with this software for 14 | # full license information. 15 | #*******************************************************************/ 16 | 17 | set(MCUX_DEVICE "MIMX8MM6") 18 | set(MCUX_SDK_PROJECT_NAME mcuxsdk) 19 | 20 | target_include_directories(${MCUX_SDK_PROJECT_NAME} PUBLIC 21 | $ 22 | $ 23 | 24 | ${MCUXSDK_DIR}/rtos/freertos/freertos_kernel 25 | ${MCUXSDK_DIR}/rtos/freertos/freertos_kernel/include 26 | ${MCUXSDK_DIR}/rtos/freertos/freertos_kernel/portable/GCC/ARM_CM4F 27 | 28 | ${MCUXSDK_DIR}/middleware/lwip/src/include 29 | ${MCUXSDK_DIR}/middleware/lwip/port 30 | ${MCUXSDK_DIR}/middleware/lwip/port/arch 31 | 32 | ${MCUXSDK_DIR}/core/boards/evkmimx8mm 33 | ) 34 | 35 | set(LWIP_DIR ${MCUXSDK_DIR}/middleware/lwip) 36 | 37 | include(${MCUXSDK_DIR}/middleware/lwip/src/Filelists.cmake) 38 | 39 | target_sources(${MCUX_SDK_PROJECT_NAME} PUBLIC 40 | ${MCUXSDK_DIR}/core/CMSIS/Core/Include/cmsis_gcc.h 41 | ${MCUXSDK_DIR}/core/boards/evkmimx8mm/board.c 42 | ${MCUXSDK_DIR}/core/boards/evkmimx8mm/clock_config.c 43 | 44 | ${MCUXSDK_DIR}/rtos/freertos/freertos_kernel/tasks.c 45 | ${MCUXSDK_DIR}/rtos/freertos/freertos_kernel/timers.c 46 | ${MCUXSDK_DIR}/rtos/freertos/freertos_kernel/queue.c 47 | ${MCUXSDK_DIR}/rtos/freertos/freertos_kernel/list.c 48 | ${MCUXSDK_DIR}/rtos/freertos/freertos_kernel/event_groups.c 49 | ${MCUXSDK_DIR}/rtos/freertos/freertos_kernel/portable/GCC/ARM_CM4F/port.c 50 | ${MCUXSDK_DIR}/rtos/freertos/freertos_kernel/portable/MemMang/heap_3.c 51 | 52 | ${lwipnetif_SRCS} 53 | ${lwipapi_SRCS} 54 | ${lwipcore_SRCS} 55 | ${lwipcore4_SRCS} 56 | 57 | ${MCUXSDK_DIR}/middleware/lwip/port/enet_ethernetif.c 58 | ${MCUXSDK_DIR}/middleware/lwip/port/enet_ethernetif_imx.c 59 | ${MCUXSDK_DIR}/middleware/lwip/port/sys_arch.c 60 | ) 61 | 62 | set(CMAKE_MODULE_PATH 63 | ${MCUXSDK_DIR}/core/ 64 | ${MCUXSDK_DIR}/core/drivers/common/ 65 | ${MCUXSDK_DIR}/core/drivers/enet/ 66 | ${MCUXSDK_DIR}/core/drivers/rdc/ 67 | ${MCUXSDK_DIR}/core/drivers/iuart/ 68 | ${MCUXSDK_DIR}/core/drivers/igpio/ 69 | ${MCUXSDK_DIR}/core/components/phy/ 70 | ${MCUXSDK_DIR}/core/components/phy/device/phyar8031/ 71 | ${MCUXSDK_DIR}/core/components/phy/mdio/enet/ 72 | ${MCUXSDK_DIR}/core/utilities/ 73 | ${MCUXSDK_DIR}/core/utilities/utilities/debug_console_lite/ 74 | ${MCUXSDK_DIR}/core/utilities/assert/ 75 | ${MCUXSDK_DIR}/core/utilities/misc_utilities/ 76 | ${MCUXSDK_DIR}/rtos/freertos/freertos_kernel/ 77 | ${MCUXSDK_DIR}/core/components/serial_manager/ 78 | ${MCUXSDK_DIR}/core/components/uart/ 79 | ${MCUXSDK_DIR}/core/components/lists/ 80 | ${MCUXSDK_DIR}/core/CMSIS/Core/Include/ 81 | ) 82 | 83 | #Include Entry cmake component 84 | include(all_devices) 85 | 86 | # include modules 87 | include(driver_mdio-enet) 88 | include(driver_phy-device-ar8031) 89 | include(utility_debug_console_lite) 90 | include(utility_assert_lite) 91 | include(driver_clock) 92 | include(driver_enet) 93 | include(driver_common) 94 | include(driver_rdc) 95 | include(device_CMSIS) 96 | include(component_iuart_adapter) 97 | include(component_lists) 98 | include(driver_iuart) 99 | include(device_startup) 100 | include(driver_igpio) 101 | include(driver_mdio-common) 102 | include(CMSIS_Include_core_cm) 103 | include(driver_phy-common) 104 | include(utilities_misc_utilities) 105 | include(device_system) 106 | include(middleware_freertos-kernel_MIMX8MM6) 107 | include(CMSIS_Include_core_cm) 108 | include(middleware_freertos-kernel_heap_3) 109 | 110 | add_library(mcuxsdk-bsp INTERFACE) 111 | 112 | target_sources(mcuxsdk-bsp INTERFACE 113 | $ 114 | $ 115 | 116 | $ 117 | $ 118 | ) 119 | 120 | target_link_options(mcuxsdk-bsp INTERFACE 121 | -T${OSAL_SOURCE_DIR}/${CORE_DIR}/MIMX8MM6xxxxx_cm4_ddr_ram.ld 122 | ) 123 | 124 | target_link_libraries(mcuxsdk-bsp INTERFACE ${MCUX_SDK_PROJECT_NAME}) 125 | if (CMAKE_PROJECT_NAME STREQUAL OSAL AND BUILD_TESTING) 126 | target_link_libraries(osal_test PRIVATE mcuxsdk-bsp) 127 | endif() 128 | 129 | install(TARGETS mcuxsdk-bsp EXPORT OsalTargets) 130 | install(DIRECTORY ${CORE_DIR}/Src DESTINATION bsp) 131 | install(DIRECTORY ${CORE_DIR}/Inc DESTINATION bsp) 132 | 133 | -------------------------------------------------------------------------------- /cmake/OsalConfig.cmake.in: -------------------------------------------------------------------------------- 1 | 2 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 3 | find_package(Threads REQUIRED) 4 | endif() 5 | 6 | 7 | @PACKAGE_INIT@ 8 | 9 | include ( "${CMAKE_CURRENT_LIST_DIR}/OsalTargets.cmake" ) 10 | -------------------------------------------------------------------------------- /cmake/STM32Cube.cmake: -------------------------------------------------------------------------------- 1 | #******************************************************************** 2 | # _ _ _ 3 | # _ __ | |_ _ | | __ _ | |__ ___ 4 | # | '__|| __|(_)| | / _` || '_ \ / __| 5 | # | | | |_ _ | || (_| || |_) |\__ \ 6 | # |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | # 8 | # www.rt-labs.com 9 | # Copyright 2021 rt-labs AB, Sweden. 10 | # 11 | # This software is licensed under the terms of the BSD 3-clause 12 | # license. See the file LICENSE distributed with this software for 13 | # full license information. 14 | #*******************************************************************/ 15 | 16 | target_sources(osal PRIVATE 17 | src/freertos/osal.c 18 | src/freertos/osal_log.c 19 | ) 20 | 21 | target_compile_options(osal 22 | PRIVATE 23 | -Wall 24 | -Wextra 25 | -Werror 26 | -Wno-unused-parameter 27 | ) 28 | 29 | target_include_directories(osal PUBLIC 30 | $ 31 | ) 32 | 33 | install(FILES 34 | src/freertos/sys/osal_cc.h 35 | src/freertos/sys/osal_sys.h 36 | DESTINATION include/sys 37 | ) 38 | 39 | add_library(cube) 40 | target_link_libraries(osal cube) 41 | install(TARGETS cube EXPORT OsalTargets) 42 | 43 | set(CORE_DIR src/freertos/${BOARD}) 44 | include(STM32Cube/${BOARD}) 45 | -------------------------------------------------------------------------------- /cmake/STM32Cube/STM32F769I-DISCO.cmake: -------------------------------------------------------------------------------- 1 | #******************************************************************** 2 | # _ _ _ 3 | # _ __ | |_ _ | | __ _ | |__ ___ 4 | # | '__|| __|(_)| | / _` || '_ \ / __| 5 | # | | | |_ _ | || (_| || |_) |\__ \ 6 | # |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | # 8 | # www.rt-labs.com 9 | # Copyright 2021 rt-labs AB, Sweden. 10 | # 11 | # This software is licensed under the terms of the BSD 3-clause 12 | # license. See the file LICENSE distributed with this software for 13 | # full license information. 14 | #*******************************************************************/ 15 | 16 | target_compile_options(cube PUBLIC 17 | -DUSE_HAL_DRIVER 18 | -DSTM32F769xx 19 | ) 20 | 21 | target_include_directories(cube PUBLIC 22 | $ 23 | $ 24 | 25 | ${CUBE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/include 26 | ${CUBE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1 27 | ${CUBE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 28 | 29 | ${CUBE_DIR}/Drivers/CMSIS/Device/ST/STM32F7xx/Include 30 | ${CUBE_DIR}/Drivers/CMSIS/Include 31 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Inc 32 | 33 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/include 34 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/system 35 | 36 | ${CUBE_DIR}/Middlewares/Third_Party/FatFs/src 37 | ) 38 | 39 | target_include_directories(cube PRIVATE 40 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/include/compat/posix 41 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/include/compat/posix/arpa 42 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/include/compat/posix/net 43 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/include/compat/posix/sys 44 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/include/compat/stdc 45 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/include/netif 46 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/system/arch 47 | ) 48 | 49 | target_sources(cube PRIVATE 50 | ${CORE_DIR}/Src/bsp_driver_sd.c 51 | ${CORE_DIR}/Src/ethernetif.c 52 | ${CORE_DIR}/Src/fatfs.c 53 | ${CORE_DIR}/Src/fatfs_platform.c 54 | ${CORE_DIR}/Src/lwip.c 55 | ${CORE_DIR}/Src/sd_diskio.c 56 | 57 | ${CUBE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c 58 | ${CUBE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c 59 | ${CUBE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/list.c 60 | ${CUBE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1/port.c 61 | ${CUBE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c 62 | ${CUBE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/queue.c 63 | ${CUBE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/tasks.c 64 | ${CUBE_DIR}/Middlewares/Third_Party/FreeRTOS/Source/timers.c 65 | 66 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/api/api_lib.c 67 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/api/api_msg.c 68 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/api/err.c 69 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/api/if_api.c 70 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/api/netbuf.c 71 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/api/netdb.c 72 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/api/netifapi.c 73 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/api/sockets.c 74 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/api/tcpip.c 75 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/def.c 76 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/init.c 77 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/ip.c 78 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/ipv4/dhcp.c 79 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/ipv4/etharp.c 80 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/ipv4/icmp.c 81 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/ipv4/ip4.c 82 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/ipv4/ip4_addr.c 83 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/ipv4/ip4_frag.c 84 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/mem.c 85 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/memp.c 86 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/netif.c 87 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/pbuf.c 88 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/stats.c 89 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/tcp.c 90 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/tcp_in.c 91 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/tcp_out.c 92 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/timeouts.c 93 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/core/udp.c 94 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/src/netif/ethernet.c 95 | ${CUBE_DIR}/Middlewares/Third_Party/LwIP/system/OS/sys_arch.c 96 | 97 | ${CUBE_DIR}/Middlewares/Third_Party/FatFs/src/diskio.c 98 | ${CUBE_DIR}/Middlewares/Third_Party/FatFs/src/ff.c 99 | ${CUBE_DIR}/Middlewares/Third_Party/FatFs/src/ff_gen_drv.c 100 | ${CUBE_DIR}/Middlewares/Third_Party/FatFs/src/ff_gen_drv.c 101 | ${CUBE_DIR}/Middlewares/Third_Party/FatFs/src/option/ccsbcs.c 102 | ${CUBE_DIR}/Middlewares/Third_Party/FatFs/src/option/syscall.c 103 | 104 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal.c 105 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_cortex.c 106 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dma.c 107 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_eth.c 108 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_gpio.c 109 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_pwr_ex.c 110 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_rcc.c 111 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_rcc_ex.c 112 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_sd.c 113 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_tim.c 114 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_tim_ex.c 115 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_uart.c 116 | ${CUBE_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_sdmmc.c 117 | ) 118 | 119 | add_library(cube-bsp INTERFACE) 120 | target_sources(cube-bsp INTERFACE 121 | $ 122 | $ 123 | $ 124 | $ 125 | $ 126 | $ 127 | $ 128 | $ 129 | $ 130 | 131 | $ 132 | $ 133 | $ 134 | $ 135 | $ 136 | $ 137 | $ 138 | $ 139 | $ 140 | ) 141 | target_link_options(cube-bsp INTERFACE 142 | -specs=nano.specs 143 | -T${OSAL_SOURCE_DIR}/${CORE_DIR}/STM32F769NIHx_FLASH.ld 144 | ) 145 | target_link_libraries(cube-bsp INTERFACE cube) 146 | if (CMAKE_PROJECT_NAME STREQUAL OSAL AND BUILD_TESTING) 147 | target_link_libraries(osal_test PRIVATE cube-bsp) 148 | endif() 149 | 150 | install(TARGETS cube-bsp EXPORT OsalTargets) 151 | install(DIRECTORY ${CORE_DIR}/Src DESTINATION bsp) 152 | install(DIRECTORY ${CORE_DIR}/Inc DESTINATION bsp) 153 | -------------------------------------------------------------------------------- /cmake/Windows.cmake: -------------------------------------------------------------------------------- 1 | #******************************************************************** 2 | # _ _ _ 3 | # _ __ | |_ _ | | __ _ | |__ ___ 4 | # | '__|| __|(_)| | / _` || '_ \ / __| 5 | # | | | |_ _ | || (_| || |_) |\__ \ 6 | # |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | # 8 | # www.rt-labs.com 9 | # Copyright 2017 rt-labs AB, Sweden. 10 | # 11 | # This software is licensed under the terms of the BSD 3-clause 12 | # license. See the file LICENSE distributed with this software for 13 | # full license information. 14 | #*******************************************************************/ 15 | 16 | target_sources(osal PRIVATE 17 | src/windows/osal.c 18 | src/windows/osal_log.c 19 | ) 20 | 21 | target_compile_options(osal 22 | PRIVATE 23 | $<$: 24 | /W4 25 | /WX 26 | /wd4100 27 | /wd4152 28 | > 29 | 30 | $<$: 31 | -Wall 32 | -Wextra 33 | -Werror 34 | -Wno-unused-parameter 35 | > 36 | 37 | PUBLIC 38 | $<$: 39 | /wd4200 40 | > 41 | ) 42 | 43 | target_link_libraries(osal 44 | winmm) 45 | 46 | target_include_directories(osal PUBLIC 47 | $ 48 | ) 49 | 50 | install(FILES 51 | src/windows/sys/osal_cc.h 52 | src/windows/sys/osal_sys.h 53 | DESTINATION include/sys 54 | ) 55 | 56 | if (BUILD_TESTING) 57 | set(GOOGLE_TEST_INDIVIDUAL TRUE) 58 | endif() 59 | -------------------------------------------------------------------------------- /cmake/iMX8MM.cmake: -------------------------------------------------------------------------------- 1 | #******************************************************************** 2 | # _ _ _ 3 | # _ __ | |_ _ | | __ _ | |__ ___ 4 | # | '__|| __|(_)| | / _` || '_ \ / __| 5 | # | | | |_ _ | || (_| || |_) |\__ \ 6 | # |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | # 8 | # www.rt-labs.com 9 | # Copyright 2021 rt-labs AB, Sweden. 10 | # Copyright 2023 NXP 11 | # 12 | # This software is licensed under the terms of the BSD 3-clause 13 | # license. See the file LICENSE distributed with this software for 14 | # full license information. 15 | #*******************************************************************/ 16 | 17 | target_sources(osal PRIVATE 18 | src/freertos/osal.c 19 | src/freertos/osal_log.c 20 | ) 21 | 22 | target_include_directories(osal PUBLIC 23 | $ 24 | ) 25 | 26 | install(FILES 27 | src/freertos/sys/osal_cc.h 28 | src/freertos/sys/osal_sys.h 29 | DESTINATION include/sys 30 | ) 31 | 32 | add_library(mcuxsdk) 33 | target_link_libraries(osal mcuxsdk) 34 | install(TARGETS mcuxsdk EXPORT OsalTargets) 35 | 36 | 37 | set(CORE_DIR src/freertos/${BOARD}) 38 | include(MCUXSDK/${BOARD}) 39 | -------------------------------------------------------------------------------- /cmake/rt-kernel.cmake: -------------------------------------------------------------------------------- 1 | #******************************************************************** 2 | # _ _ _ 3 | # _ __ | |_ _ | | __ _ | |__ ___ 4 | # | '__|| __|(_)| | / _` || '_ \ / __| 5 | # | | | |_ _ | || (_| || |_) |\__ \ 6 | # |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | # 8 | # www.rt-labs.com 9 | # Copyright 2017 rt-labs AB, Sweden. 10 | # 11 | # This software is licensed under the terms of the BSD 3-clause 12 | # license. See the file LICENSE distributed with this software for 13 | # full license information. 14 | #*******************************************************************/ 15 | 16 | target_sources(osal PRIVATE 17 | src/rt-kernel/osal.c 18 | src/rt-kernel/osal_log.c 19 | ) 20 | 21 | target_compile_options(osal 22 | PRIVATE 23 | -Wall 24 | -Wextra 25 | -Werror 26 | -Wno-unused-parameter 27 | ) 28 | 29 | target_link_libraries(osal 30 | kern 31 | ) 32 | 33 | target_include_directories(osal PUBLIC 34 | $ 35 | ) 36 | 37 | install(FILES 38 | src/rt-kernel/sys/osal_cc.h 39 | src/rt-kernel/sys/osal_sys.h 40 | DESTINATION include/sys 41 | ) 42 | -------------------------------------------------------------------------------- /include/osal.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #ifndef OSAL_H 17 | #define OSAL_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "sys/osal_sys.h" 29 | #include "sys/osal_cc.h" 30 | 31 | #ifndef MIN 32 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 33 | #endif 34 | 35 | #ifndef MAX 36 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 37 | #endif 38 | 39 | #ifndef BIT 40 | #define BIT(n) (1U << (n)) 41 | #endif 42 | 43 | #ifndef NELEMENTS 44 | #define NELEMENTS(a) (sizeof (a) / sizeof ((a)[0])) 45 | #endif 46 | 47 | #ifndef OS_WAIT_FOREVER 48 | #define OS_WAIT_FOREVER 0xFFFFFFFF 49 | #endif 50 | 51 | #ifndef OS_MAIN 52 | #define OS_MAIN int main 53 | #endif 54 | 55 | #ifndef OS_MUTEX 56 | typedef void os_mutex_t; 57 | #endif 58 | 59 | #ifndef OS_SEM 60 | typedef void os_sem_t; 61 | #endif 62 | 63 | #ifndef OS_THREAD 64 | typedef void os_thread_t; 65 | #endif 66 | 67 | #ifndef OS_EVENT 68 | typedef void os_event_t; 69 | #endif 70 | 71 | #ifndef OS_MBOX 72 | typedef void os_mbox_t; 73 | #endif 74 | 75 | #ifndef OS_TIMER 76 | typedef void os_timer_t; 77 | #endif 78 | 79 | #ifndef OS_TICK 80 | typedef void os_tick_t; 81 | #endif 82 | 83 | void * os_malloc (size_t size); 84 | void os_free (void * ptr); 85 | 86 | void os_usleep (uint32_t us); 87 | uint32_t os_get_current_time_us (void); 88 | 89 | os_tick_t os_tick_current (void); 90 | os_tick_t os_tick_from_us (uint32_t us); 91 | void os_tick_sleep (os_tick_t tick); 92 | 93 | os_thread_t * os_thread_create ( 94 | const char * name, 95 | uint32_t priority, 96 | size_t stacksize, 97 | void (*entry) (void * arg), 98 | void * arg); 99 | 100 | os_mutex_t * os_mutex_create (void); 101 | void os_mutex_lock (os_mutex_t * mutex); 102 | void os_mutex_unlock (os_mutex_t * mutex); 103 | void os_mutex_destroy (os_mutex_t * mutex); 104 | 105 | os_sem_t * os_sem_create (size_t count); 106 | bool os_sem_wait (os_sem_t * sem, uint32_t time); 107 | void os_sem_signal (os_sem_t * sem); 108 | void os_sem_destroy (os_sem_t * sem); 109 | 110 | os_event_t * os_event_create (void); 111 | bool os_event_wait ( 112 | os_event_t * event, 113 | uint32_t mask, 114 | uint32_t * value, 115 | uint32_t time); 116 | void os_event_set (os_event_t * event, uint32_t value); 117 | void os_event_clr (os_event_t * event, uint32_t value); 118 | void os_event_destroy (os_event_t * event); 119 | 120 | os_mbox_t * os_mbox_create (size_t size); 121 | bool os_mbox_fetch (os_mbox_t * mbox, void ** msg, uint32_t time); 122 | bool os_mbox_post (os_mbox_t * mbox, void * msg, uint32_t time); 123 | void os_mbox_destroy (os_mbox_t * mbox); 124 | 125 | os_timer_t * os_timer_create ( 126 | uint32_t us, 127 | void (*fn) (os_timer_t * timer, void * arg), 128 | void * arg, 129 | bool oneshot); 130 | void os_timer_set (os_timer_t * timer, uint32_t us); 131 | void os_timer_start (os_timer_t * timer); 132 | void os_timer_stop (os_timer_t * timer); 133 | void os_timer_destroy (os_timer_t * timer); 134 | 135 | #ifdef __cplusplus 136 | } 137 | #endif 138 | 139 | #endif /* OSAL_H */ 140 | -------------------------------------------------------------------------------- /include/osal_log.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #ifndef OSAL_LOG_H 17 | #define OSAL_LOG_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "osal.h" 24 | 25 | /* Log levels */ 26 | #define LOG_LEVEL_DEBUG 0x00 27 | #define LOG_LEVEL_INFO 0x01 28 | #define LOG_LEVEL_WARNING 0x02 29 | #define LOG_LEVEL_ERROR 0x03 30 | #define LOG_LEVEL_FATAL 0x04 31 | #define LOG_LEVEL_MASK 0x07 32 | #define LOG_LEVEL_GET(t) (t & LOG_LEVEL_MASK) 33 | 34 | /* Log states */ 35 | #define LOG_STATE_ON 0x80 36 | #define LOG_STATE_OFF 0x00 37 | 38 | #define LOG_ENABLED(type) \ 39 | ((LOG_LEVEL_GET (type) >= LOG_LEVEL) && (type & LOG_STATE_ON)) 40 | 41 | /** Log a message if it is enabled */ 42 | #define LOG(type, ...) \ 43 | do \ 44 | { \ 45 | if (LOG_ENABLED (type)) \ 46 | { \ 47 | os_log (type, __VA_ARGS__); \ 48 | } \ 49 | } while (0) 50 | 51 | /** Log debug messages */ 52 | #define LOG_DEBUG(type, ...) LOG ((LOG_LEVEL_DEBUG | type), __VA_ARGS__) 53 | 54 | /** Log informational messages */ 55 | #define LOG_INFO(type, ...) LOG ((LOG_LEVEL_INFO | type), __VA_ARGS__) 56 | 57 | /** Log warning messages */ 58 | #define LOG_WARNING(type, ...) LOG ((LOG_LEVEL_WARNING | type), __VA_ARGS__) 59 | 60 | /** Log error messages */ 61 | #define LOG_ERROR(type, ...) LOG ((LOG_LEVEL_ERROR | type), __VA_ARGS__) 62 | 63 | /** Log fatal messages */ 64 | #define LOG_FATAL(type, ...) LOG ((LOG_LEVEL_FATAL | type), __VA_ARGS__) 65 | 66 | #define LOG_DEBUG_ENABLED(type) LOG_ENABLED (LOG_LEVEL_DEBUG | type) 67 | #define LOG_INFO_ENABLED(type) LOG_ENABLED (LOG_LEVEL_INFO | type) 68 | #define LOG_WARNING_ENABLED(type) LOG_ENABLED (LOG_LEVEL_WARNING | type) 69 | #define LOG_ERROR_ENABLED(type) LOG_ENABLED (LOG_LEVEL_ERROR | type) 70 | #define LOG_FATAL_ENABLED(type) LOG_ENABLED (LOG_LEVEL_FATAL | type) 71 | 72 | 73 | typedef void (*os_log_t) (uint8_t type, const char * fmt, ...) CC_FORMAT (2, 3); 74 | 75 | extern os_log_t os_log; 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* OSAL_LOG_H */ 82 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Inc/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /* 3 | * FreeRTOS Kernel V10.2.1 4 | * Portion Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 | * Portion Copyright (C) 2019 StMicroelectronics, Inc. All Rights Reserved. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | * 24 | * http://www.FreeRTOS.org 25 | * http://aws.amazon.com/freertos 26 | * 27 | * 1 tab == 4 spaces! 28 | */ 29 | /* USER CODE END Header */ 30 | 31 | #ifndef FREERTOS_CONFIG_H 32 | #define FREERTOS_CONFIG_H 33 | 34 | /*----------------------------------------------------------- 35 | * Application specific definitions. 36 | * 37 | * These definitions should be adjusted for your particular hardware and 38 | * application requirements. 39 | * 40 | * These parameters and more are described within the 'configuration' section of the 41 | * FreeRTOS API documentation available on the FreeRTOS.org web site. 42 | * 43 | * See http://www.freertos.org/a00110.html 44 | *----------------------------------------------------------*/ 45 | 46 | /* USER CODE BEGIN Includes */ 47 | /* Section where include file can be added */ 48 | /* USER CODE END Includes */ 49 | 50 | /* Ensure definitions are only used by the compiler, and not by the assembler. */ 51 | #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) 52 | #include 53 | extern uint32_t SystemCoreClock; 54 | #endif 55 | #define configENABLE_FPU 0 56 | #define configENABLE_MPU 0 57 | 58 | #define configUSE_PREEMPTION 1 59 | #define configSUPPORT_STATIC_ALLOCATION 1 60 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 61 | #define configUSE_IDLE_HOOK 0 62 | #define configUSE_TICK_HOOK 0 63 | #define configCPU_CLOCK_HZ ( SystemCoreClock ) 64 | #define configTICK_RATE_HZ ((TickType_t)1000) 65 | #define configMAX_PRIORITIES ( 56 ) 66 | #define configMINIMAL_STACK_SIZE ((uint16_t)128) 67 | #define configTOTAL_HEAP_SIZE ((size_t)65536) 68 | #define configMAX_TASK_NAME_LEN ( 16 ) 69 | #define configUSE_TRACE_FACILITY 1 70 | #define configUSE_STATS_FORMATTING_FUNCTIONS 1 71 | #define configUSE_16_BIT_TICKS 0 72 | #define configUSE_MUTEXES 1 73 | #define configQUEUE_REGISTRY_SIZE 8 74 | #define configCHECK_FOR_STACK_OVERFLOW 2 75 | #define configUSE_RECURSIVE_MUTEXES 1 76 | #define configUSE_MALLOC_FAILED_HOOK 1 77 | #define configUSE_COUNTING_SEMAPHORES 1 78 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 79 | /* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */ 80 | /* Defaults to size_t for backward compatibility, but can be changed 81 | if lengths will always be less than the number of bytes in a size_t. */ 82 | #define configMESSAGE_BUFFER_LENGTH_TYPE size_t 83 | /* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */ 84 | 85 | /* Co-routine definitions. */ 86 | #define configUSE_CO_ROUTINES 0 87 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 88 | 89 | /* Software timer definitions. */ 90 | #define configUSE_TIMERS 1 91 | #define configTIMER_TASK_PRIORITY ( 2 ) 92 | #define configTIMER_QUEUE_LENGTH 10 93 | #define configTIMER_TASK_STACK_DEPTH 256 94 | 95 | /* Set the following definitions to 1 to include the API function, or zero 96 | to exclude the API function. */ 97 | #define INCLUDE_vTaskPrioritySet 1 98 | #define INCLUDE_uxTaskPriorityGet 1 99 | #define INCLUDE_vTaskDelete 1 100 | #define INCLUDE_vTaskCleanUpResources 0 101 | #define INCLUDE_vTaskSuspend 1 102 | #define INCLUDE_vTaskDelayUntil 1 103 | #define INCLUDE_vTaskDelay 1 104 | #define INCLUDE_xTaskGetSchedulerState 1 105 | #define INCLUDE_xTimerPendFunctionCall 1 106 | #define INCLUDE_xQueueGetMutexHolder 1 107 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 108 | #define INCLUDE_eTaskGetState 1 109 | 110 | /* 111 | * The CMSIS-RTOS V2 FreeRTOS wrapper is dependent on the heap implementation used 112 | * by the application thus the correct define need to be enabled below 113 | */ 114 | #define USE_FreeRTOS_HEAP_4 115 | 116 | /* Cortex-M specific definitions. */ 117 | #ifdef __NVIC_PRIO_BITS 118 | /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ 119 | #define configPRIO_BITS __NVIC_PRIO_BITS 120 | #else 121 | #define configPRIO_BITS 4 122 | #endif 123 | 124 | /* The lowest interrupt priority that can be used in a call to a "set priority" 125 | function. */ 126 | #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 127 | 128 | /* The highest interrupt priority that can be used by any interrupt service 129 | routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL 130 | INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER 131 | PRIORITY THAN THIS! (higher priorities are lower numeric values. */ 132 | #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 133 | 134 | /* Interrupt priorities used by the kernel port layer itself. These are generic 135 | to all Cortex-M ports, and do not rely on any particular library functions. */ 136 | #define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) 137 | /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! 138 | See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ 139 | #define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) 140 | 141 | /* Normal assert() semantics without relying on the provision of an assert.h 142 | header file. */ 143 | /* USER CODE BEGIN 1 */ 144 | #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );} 145 | /* USER CODE END 1 */ 146 | 147 | /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS 148 | standard names. */ 149 | #define vPortSVCHandler SVC_Handler 150 | #define xPortPendSVHandler PendSV_Handler 151 | 152 | /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick, 153 | to prevent overwriting SysTick_Handler defined within STM32Cube HAL */ 154 | 155 | #define xPortSysTickHandler SysTick_Handler 156 | 157 | /* USER CODE BEGIN Defines */ 158 | /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */ 159 | /* USER CODE END Defines */ 160 | 161 | #endif /* FREERTOS_CONFIG_H */ 162 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Inc/bsp_driver_sd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file bsp_driver_sd.h (based on stm32756g_eval_sd.h) 4 | * @brief This file contains the common defines and functions prototypes for 5 | * the bsp_driver_sd.c driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F7_SD_H 22 | #define __STM32F7_SD_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f7xx_hal.h" 30 | #include "fatfs_platform.h" 31 | 32 | /* Exported types --------------------------------------------------------*/ 33 | /** 34 | * @brief SD Card information structure 35 | */ 36 | #define BSP_SD_CardInfo HAL_SD_CardInfoTypeDef 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | /** 40 | * @brief SD status structure definition 41 | */ 42 | #define MSD_OK ((uint8_t)0x00) 43 | #define MSD_ERROR ((uint8_t)0x01) 44 | #define MSD_ERROR_SD_NOT_PRESENT ((uint8_t)0x02) 45 | 46 | /** 47 | * @brief SD transfer state definition 48 | */ 49 | #define SD_TRANSFER_OK ((uint8_t)0x00) 50 | #define SD_TRANSFER_BUSY ((uint8_t)0x01) 51 | 52 | #define SD_PRESENT ((uint8_t)0x01) 53 | #define SD_NOT_PRESENT ((uint8_t)0x00) 54 | #define SD_DATATIMEOUT ((uint32_t)100000000) 55 | 56 | #ifdef OLD_API 57 | /* kept to avoid issue when migrating old projects. */ 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | #else 62 | /* USER CODE BEGIN BSP_H_CODE */ 63 | 64 | /* Exported functions --------------------------------------------------------*/ 65 | uint8_t BSP_SD_Init(void); 66 | uint8_t BSP_SD_ITConfig(void); 67 | uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout); 68 | uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout); 69 | uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks); 70 | uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks); 71 | uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr); 72 | uint8_t BSP_SD_GetCardState(void); 73 | void BSP_SD_GetCardInfo(BSP_SD_CardInfo *CardInfo); 74 | uint8_t BSP_SD_IsDetected(void); 75 | 76 | /* These functions can be modified in case the current settings (e.g. DMA stream) 77 | need to be changed for specific application needs */ 78 | void BSP_SD_AbortCallback(void); 79 | void BSP_SD_WriteCpltCallback(void); 80 | void BSP_SD_ReadCpltCallback(void); 81 | /* USER CODE END BSP_H_CODE */ 82 | #endif 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* __STM32F7_SD_H */ 89 | 90 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 91 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Inc/ethernetif.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : ethernetif.h 4 | * Description : This file provides initialization code for LWIP 5 | * middleWare. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | #ifndef __ETHERNETIF_H__ 21 | #define __ETHERNETIF_H__ 22 | 23 | #include "lwip/err.h" 24 | #include "lwip/netif.h" 25 | #include "cmsis_os.h" 26 | 27 | /* Exported types ------------------------------------------------------------*/ 28 | /* Structure that include link thread parameters */ 29 | struct link_str { 30 | struct netif *netif; 31 | osSemaphoreId semaphore; 32 | }; 33 | 34 | /* Within 'USER CODE' section, code will be kept by default at each generation */ 35 | /* USER CODE BEGIN 0 */ 36 | 37 | /* USER CODE END 0 */ 38 | 39 | /* Exported functions ------------------------------------------------------- */ 40 | err_t ethernetif_init(struct netif *netif); 41 | 42 | void ethernetif_input(void* argument); 43 | void ethernetif_set_link(void* argument); 44 | void ethernetif_update_config(struct netif *netif); 45 | void ethernetif_notify_conn_changed(struct netif *netif); 46 | 47 | u32_t sys_jiffies(void); 48 | u32_t sys_now(void); 49 | 50 | /* USER CODE BEGIN 1 */ 51 | 52 | /* USER CODE END 1 */ 53 | #endif 54 | 55 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 56 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Inc/fatfs.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file fatfs.h 4 | * @brief Header for fatfs applications 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | *

© Copyright (c) 2021 STMicroelectronics. 9 | * All rights reserved.

10 | * 11 | * This software component is licensed by ST under Ultimate Liberty license 12 | * SLA0044, the "License"; You may not use this file except in compliance with 13 | * the License. You may obtain a copy of the License at: 14 | * www.st.com/SLA0044 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __fatfs_H 21 | #define __fatfs_H 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "ff.h" 27 | #include "ff_gen_drv.h" 28 | #include "sd_diskio.h" /* defines SD_Driver as external */ 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern uint8_t retSD; /* Return value for SD */ 35 | extern char SDPath[4]; /* SD logical drive path */ 36 | extern FATFS SDFatFS; /* File system object for SD logical drive */ 37 | extern FIL SDFile; /* File object for SD */ 38 | 39 | void MX_FATFS_Init(void); 40 | 41 | /* USER CODE BEGIN Prototypes */ 42 | 43 | /* USER CODE END Prototypes */ 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /*__fatfs_H */ 48 | 49 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 50 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Inc/fatfs_platform.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : fatfs_platform.h 4 | * @brief : fatfs_platform header file 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | *

© Copyright (c) 2021 STMicroelectronics. 9 | * All rights reserved.

10 | * 11 | * This software component is licensed by ST under Ultimate Liberty license 12 | * SLA0044, the "License"; You may not use this file except in compliance with 13 | * the License. You may obtain a copy of the License at: 14 | * www.st.com/SLA0044 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* Includes ------------------------------------------------------------------*/ 19 | #include "stm32f7xx_hal.h" 20 | /* Defines ------------------------------------------------------------------*/ 21 | #define SD_PRESENT ((uint8_t)0x01) /* also in bsp_driver_sd.h */ 22 | #define SD_NOT_PRESENT ((uint8_t)0x00) /* also in bsp_driver_sd.h */ 23 | #define SD_DETECT_PIN GPIO_PIN_15 24 | #define SD_DETECT_GPIO_PORT GPIOI 25 | /* Prototypes ---------------------------------------------------------------*/ 26 | uint8_t BSP_PlatformIsDetected(void); 27 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Inc/lwip_hooks.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef LWIP_HOOKS_H 3 | #define LWIP_HOOKS_H 4 | 5 | err_enum_t lwip_hook_unknown_eth_protocol (struct pbuf * pbuf, struct netif * netif); 6 | 7 | #endif /* LWIP_HOOKS_H */ 8 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Inc/lwipopts.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | ****************************************************************************** 4 | * File Name : Target/lwipopts.h 5 | * Description : This file overrides LwIP stack default configuration 6 | * done in opt.h file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | /* Define to prevent recursive inclusion --------------------------------------*/ 22 | #ifndef __LWIPOPTS__H__ 23 | #define __LWIPOPTS__H__ 24 | 25 | #include "main.h" 26 | 27 | /*-----------------------------------------------------------------------------*/ 28 | /* Current version of LwIP supported by CubeMx: 2.1.2 -*/ 29 | /*-----------------------------------------------------------------------------*/ 30 | 31 | /* Within 'USER CODE' section, code will be kept by default at each generation */ 32 | /* USER CODE BEGIN 0 */ 33 | 34 | /* USER CODE END 0 */ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /* STM32CubeMX Specific Parameters (not defined in opt.h) ---------------------*/ 41 | /* Parameters set in STM32CubeMX LwIP Configuration GUI -*/ 42 | /*----- WITH_RTOS enabled (Since FREERTOS is set) -----*/ 43 | #define WITH_RTOS 1 44 | /*----- CHECKSUM_BY_HARDWARE enabled -----*/ 45 | #define CHECKSUM_BY_HARDWARE 1 46 | /*-----------------------------------------------------------------------------*/ 47 | 48 | /* LwIP Stack Parameters (modified compared to initialization value in opt.h) -*/ 49 | /* Parameters set in STM32CubeMX LwIP Configuration GUI -*/ 50 | /*----- Value in opt.h for LWIP_DHCP: 0 -----*/ 51 | #define LWIP_DHCP 1 52 | /*----- Default Value for LWIP_TCPIP_CORE_LOCKING: 0 ---*/ 53 | #define LWIP_TCPIP_CORE_LOCKING 1 54 | /*----- Value in opt.h for MEM_ALIGNMENT: 1 -----*/ 55 | #define MEM_ALIGNMENT 4 56 | /*----- Value in opt.h for MEMP_NUM_SYS_TIMEOUT: (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + (PPP_SUPPORT*6*MEMP_NUM_PPP_PCB) + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)) -*/ 57 | #define MEMP_NUM_SYS_TIMEOUT 5 58 | /*----- Default Value for PBUF_POOL_BUFSIZE: 592 ---*/ 59 | #define PBUF_POOL_BUFSIZE 1536 60 | /*----- Value in opt.h for LWIP_ETHERNET: LWIP_ARP || PPPOE_SUPPORT -*/ 61 | #define LWIP_ETHERNET 1 62 | /*----- Value in opt.h for LWIP_DNS_SECURE: (LWIP_DNS_SECURE_RAND_XID | LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING | LWIP_DNS_SECURE_RAND_SRC_PORT) -*/ 63 | #define LWIP_DNS_SECURE 7 64 | /*----- Value in opt.h for TCP_SND_QUEUELEN: (4*TCP_SND_BUF + (TCP_MSS - 1))/TCP_MSS -----*/ 65 | #define TCP_SND_QUEUELEN 9 66 | /*----- Value in opt.h for TCP_SNDLOWAT: LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1) -*/ 67 | #define TCP_SNDLOWAT 1071 68 | /*----- Value in opt.h for TCP_SNDQUEUELOWAT: LWIP_MAX(TCP_SND_QUEUELEN)/2, 5) -*/ 69 | #define TCP_SNDQUEUELOWAT 5 70 | /*----- Value in opt.h for TCP_WND_UPDATE_THRESHOLD: LWIP_MIN(TCP_WND/4, TCP_MSS*4) -----*/ 71 | #define TCP_WND_UPDATE_THRESHOLD 536 72 | /*----- Default Value for LWIP_NETIF_HOSTNAME: 0 ---*/ 73 | #define LWIP_NETIF_HOSTNAME 1 74 | /*----- Value in opt.h for LWIP_NETIF_LINK_CALLBACK: 0 -----*/ 75 | #define LWIP_NETIF_LINK_CALLBACK 1 76 | /*----- Default Value for TCPIP_THREAD_NAME: "tcpip_thread" ---*/ 77 | #define TCPIP_THREAD_NAME "tcpip_thread11" 78 | /*----- Value in opt.h for TCPIP_THREAD_STACKSIZE: 0 -----*/ 79 | #define TCPIP_THREAD_STACKSIZE 4096 80 | /*----- Value in opt.h for TCPIP_THREAD_PRIO: 1 -----*/ 81 | #define TCPIP_THREAD_PRIO 24 82 | /*----- Value in opt.h for TCPIP_MBOX_SIZE: 0 -----*/ 83 | #define TCPIP_MBOX_SIZE 6 84 | /*----- Value in opt.h for SLIPIF_THREAD_STACKSIZE: 0 -----*/ 85 | #define SLIPIF_THREAD_STACKSIZE 1024 86 | /*----- Value in opt.h for SLIPIF_THREAD_PRIO: 1 -----*/ 87 | #define SLIPIF_THREAD_PRIO 3 88 | /*----- Value in opt.h for DEFAULT_THREAD_STACKSIZE: 0 -----*/ 89 | #define DEFAULT_THREAD_STACKSIZE 1024 90 | /*----- Value in opt.h for DEFAULT_THREAD_PRIO: 1 -----*/ 91 | #define DEFAULT_THREAD_PRIO 3 92 | /*----- Value in opt.h for DEFAULT_UDP_RECVMBOX_SIZE: 0 -----*/ 93 | #define DEFAULT_UDP_RECVMBOX_SIZE 6 94 | /*----- Value in opt.h for DEFAULT_TCP_RECVMBOX_SIZE: 0 -----*/ 95 | #define DEFAULT_TCP_RECVMBOX_SIZE 6 96 | /*----- Value in opt.h for DEFAULT_ACCEPTMBOX_SIZE: 0 -----*/ 97 | #define DEFAULT_ACCEPTMBOX_SIZE 6 98 | /*----- Value in opt.h for LWIP_COMPAT_SOCKETS: 1 -----*/ 99 | #define LWIP_COMPAT_SOCKETS 2 100 | /*----- Value in opt.h for RECV_BUFSIZE_DEFAULT: INT_MAX -----*/ 101 | #define RECV_BUFSIZE_DEFAULT 2000000000 102 | /*----- Default Value for SO_REUSE: 0 ---*/ 103 | #define SO_REUSE 1 104 | /*----- Default Value for LWIP_SNMP: 0 ---*/ 105 | #define LWIP_SNMP 1 106 | /*----- Default Value for SNMP_USE_NETCONN: 0 ---*/ 107 | #define SNMP_USE_NETCONN 1 108 | /*----- Default Value for SNMP_USE_RAW: 1 ---*/ 109 | #define SNMP_USE_RAW 0 110 | /*----- Value in opt.h for MIB2_STATS: 0 or SNMP_LWIP_MIB2 -----*/ 111 | #define MIB2_STATS 1 112 | /*----- Value in opt.h for CHECKSUM_GEN_IP: 1 -----*/ 113 | #define CHECKSUM_GEN_IP 0 114 | /*----- Value in opt.h for CHECKSUM_GEN_UDP: 1 -----*/ 115 | #define CHECKSUM_GEN_UDP 0 116 | /*----- Value in opt.h for CHECKSUM_GEN_TCP: 1 -----*/ 117 | #define CHECKSUM_GEN_TCP 0 118 | /*----- Value in opt.h for CHECKSUM_GEN_ICMP: 1 -----*/ 119 | #define CHECKSUM_GEN_ICMP 0 120 | /*----- Value in opt.h for CHECKSUM_GEN_ICMP6: 1 -----*/ 121 | #define CHECKSUM_GEN_ICMP6 0 122 | /*----- Value in opt.h for CHECKSUM_CHECK_IP: 1 -----*/ 123 | #define CHECKSUM_CHECK_IP 0 124 | /*----- Value in opt.h for CHECKSUM_CHECK_UDP: 1 -----*/ 125 | #define CHECKSUM_CHECK_UDP 0 126 | /*----- Value in opt.h for CHECKSUM_CHECK_TCP: 1 -----*/ 127 | #define CHECKSUM_CHECK_TCP 0 128 | /*----- Value in opt.h for CHECKSUM_CHECK_ICMP: 1 -----*/ 129 | #define CHECKSUM_CHECK_ICMP 0 130 | /*----- Value in opt.h for CHECKSUM_CHECK_ICMP6: 1 -----*/ 131 | #define CHECKSUM_CHECK_ICMP6 0 132 | /*-----------------------------------------------------------------------------*/ 133 | /* USER CODE BEGIN 1 */ 134 | #define LWIP_HOOK_FILENAME "lwip_hooks.h" 135 | #define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL lwip_hook_unknown_eth_protocol 136 | /* USER CODE END 1 */ 137 | 138 | #ifdef __cplusplus 139 | } 140 | #endif 141 | #endif /*__LWIPOPTS__H__ */ 142 | 143 | /************************* (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 144 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f7xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | extern int SDFatFSMounted; 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /* USER CODE END EC */ 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN EM */ 50 | 51 | /* USER CODE END EM */ 52 | 53 | /* Exported functions prototypes ---------------------------------------------*/ 54 | void Error_Handler(void); 55 | 56 | /* USER CODE BEGIN EFP */ 57 | 58 | /* USER CODE END EFP */ 59 | 60 | /* Private defines -----------------------------------------------------------*/ 61 | #define LD_USER2_Pin GPIO_PIN_13 62 | #define LD_USER2_GPIO_Port GPIOJ 63 | #define SD_DETECT_Pin GPIO_PIN_15 64 | #define SD_DETECT_GPIO_Port GPIOI 65 | #define LD_USER1_Pin GPIO_PIN_5 66 | #define LD_USER1_GPIO_Port GPIOJ 67 | #define B_USER_Pin GPIO_PIN_0 68 | #define B_USER_GPIO_Port GPIOA 69 | /* USER CODE BEGIN Private defines */ 70 | 71 | /* USER CODE END Private defines */ 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif /* __MAIN_H */ 78 | 79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 80 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Inc/sd_diskio.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file sd_diskio.h 5 | * @brief Header for sd_diskio.c module 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Note: code generation based on sd_diskio_dma_rtos_template.h */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __SD_DISKIO_H 25 | #define __SD_DISKIO_H 26 | 27 | /* USER CODE BEGIN firstSection */ 28 | /* can be used to modify / undefine following code or add new definitions */ 29 | /* USER CODE END firstSection */ 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "bsp_driver_sd.h" 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* Exported constants --------------------------------------------------------*/ 35 | /* Exported functions ------------------------------------------------------- */ 36 | extern const Diskio_drvTypeDef SD_Driver; 37 | 38 | /* USER CODE BEGIN lastSection */ 39 | /* can be used to modify / undefine previous code or add new definitions */ 40 | /* USER CODE END lastSection */ 41 | 42 | #endif /* __SD_DISKIO_H */ 43 | 44 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 45 | 46 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Inc/stm32f7xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f7xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F7xx_IT_H 23 | #define __STM32F7xx_IT_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Private includes ----------------------------------------------------------*/ 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN ET */ 36 | 37 | /* USER CODE END ET */ 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* USER CODE BEGIN EC */ 41 | 42 | /* USER CODE END EC */ 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* USER CODE BEGIN EM */ 46 | 47 | /* USER CODE END EM */ 48 | 49 | /* Exported functions prototypes ---------------------------------------------*/ 50 | void NMI_Handler(void); 51 | void HardFault_Handler(void); 52 | void MemManage_Handler(void); 53 | void BusFault_Handler(void); 54 | void UsageFault_Handler(void); 55 | void DebugMon_Handler(void); 56 | void TIM1_UP_TIM10_IRQHandler(void); 57 | void USART1_IRQHandler(void); 58 | void DMA2_Stream0_IRQHandler(void); 59 | void ETH_IRQHandler(void); 60 | void DMA2_Stream5_IRQHandler(void); 61 | void DMA2_Stream7_IRQHandler(void); 62 | void SDMMC2_IRQHandler(void); 63 | /* USER CODE BEGIN EFP */ 64 | 65 | /* USER CODE END EFP */ 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __STM32F7xx_IT_H */ 72 | 73 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 74 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/STM32F769NIHx_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | 5 | ** File : LinkerScript.ld 6 | ** 7 | ** Author : Auto-generated by System Workbench for STM32 8 | ** 9 | ** Abstract : Linker script for STM32F769NIHx series 10 | ** 2048Kbytes FLASH and 512Kbytes RAM 11 | ** 12 | ** Set heap size, stack size and stack location according 13 | ** to application requirements. 14 | ** 15 | ** Set memory bank area and size if external memory is used. 16 | ** 17 | ** Target : STMicroelectronics STM32 18 | ** 19 | ** Distribution: The file is distributed “as is,” without any warranty 20 | ** of any kind. 21 | ** 22 | ***************************************************************************** 23 | ** @attention 24 | ** 25 | **

© COPYRIGHT(c) 2019 STMicroelectronics

26 | ** 27 | ** Redistribution and use in source and binary forms, with or without modification, 28 | ** are permitted provided that the following conditions are met: 29 | ** 1. Redistributions of source code must retain the above copyright notice, 30 | ** this list of conditions and the following disclaimer. 31 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 32 | ** this list of conditions and the following disclaimer in the documentation 33 | ** and/or other materials provided with the distribution. 34 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 35 | ** may be used to endorse or promote products derived from this software 36 | ** without specific prior written permission. 37 | ** 38 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 39 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 42 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 43 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 44 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 45 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 47 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 48 | ** 49 | ***************************************************************************** 50 | */ 51 | 52 | /* Entry Point */ 53 | ENTRY(Reset_Handler) 54 | 55 | /* Highest address of the user mode stack */ 56 | _estack = 0x20080000; /* end of RAM */ 57 | /* Generate a link error if heap and stack don't fit into RAM */ 58 | _Min_Heap_Size = 0x200; /* required amount of heap */ 59 | _Min_Stack_Size = 0x400; /* required amount of stack */ 60 | 61 | /* Specify the memory areas */ 62 | MEMORY 63 | { 64 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 512K 65 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 2048K 66 | } 67 | 68 | /* Define output sections */ 69 | SECTIONS 70 | { 71 | /* The startup code goes first into FLASH */ 72 | .isr_vector : 73 | { 74 | . = ALIGN(4); 75 | KEEP(*(.isr_vector)) /* Startup code */ 76 | . = ALIGN(4); 77 | } >FLASH 78 | 79 | /* The program code and other data goes into FLASH */ 80 | .text : 81 | { 82 | . = ALIGN(4); 83 | *(.text) /* .text sections (code) */ 84 | *(.text*) /* .text* sections (code) */ 85 | *(.glue_7) /* glue arm to thumb code */ 86 | *(.glue_7t) /* glue thumb to arm code */ 87 | *(.eh_frame) 88 | 89 | KEEP (*(.init)) 90 | KEEP (*(.fini)) 91 | 92 | . = ALIGN(4); 93 | _etext = .; /* define a global symbols at end of code */ 94 | } >FLASH 95 | 96 | /* Constant data goes into FLASH */ 97 | .rodata : 98 | { 99 | . = ALIGN(4); 100 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 101 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 102 | . = ALIGN(4); 103 | } >FLASH 104 | 105 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH 106 | .ARM : { 107 | __exidx_start = .; 108 | *(.ARM.exidx*) 109 | __exidx_end = .; 110 | } >FLASH 111 | 112 | .preinit_array : 113 | { 114 | PROVIDE_HIDDEN (__preinit_array_start = .); 115 | KEEP (*(.preinit_array*)) 116 | PROVIDE_HIDDEN (__preinit_array_end = .); 117 | } >FLASH 118 | .init_array : 119 | { 120 | PROVIDE_HIDDEN (__init_array_start = .); 121 | KEEP (*(SORT(.init_array.*))) 122 | KEEP (*(.init_array*)) 123 | PROVIDE_HIDDEN (__init_array_end = .); 124 | } >FLASH 125 | .fini_array : 126 | { 127 | PROVIDE_HIDDEN (__fini_array_start = .); 128 | KEEP (*(SORT(.fini_array.*))) 129 | KEEP (*(.fini_array*)) 130 | PROVIDE_HIDDEN (__fini_array_end = .); 131 | } >FLASH 132 | 133 | /* used by the startup to initialize data */ 134 | _sidata = LOADADDR(.data); 135 | 136 | /* Initialized data sections goes into RAM, load LMA copy after code */ 137 | .data : 138 | { 139 | . = ALIGN(4); 140 | _sdata = .; /* create a global symbol at data start */ 141 | *(.data) /* .data sections */ 142 | *(.data*) /* .data* sections */ 143 | 144 | . = ALIGN(4); 145 | _edata = .; /* define a global symbol at data end */ 146 | } >RAM AT> FLASH 147 | 148 | 149 | /* Uninitialized data section */ 150 | . = ALIGN(4); 151 | .bss : 152 | { 153 | /* This is used by the startup in order to initialize the .bss secion */ 154 | _sbss = .; /* define a global symbol at bss start */ 155 | __bss_start__ = _sbss; 156 | *(.bss) 157 | *(.bss*) 158 | *(COMMON) 159 | 160 | . = ALIGN(4); 161 | _ebss = .; /* define a global symbol at bss end */ 162 | __bss_end__ = _ebss; 163 | } >RAM 164 | 165 | /* User_heap_stack section, used to check that there is enough RAM left */ 166 | ._user_heap_stack : 167 | { 168 | . = ALIGN(8); 169 | PROVIDE ( end = . ); 170 | PROVIDE ( _end = . ); 171 | . = . + _Min_Heap_Size; 172 | . = . + _Min_Stack_Size; 173 | . = ALIGN(8); 174 | } >RAM 175 | 176 | 177 | 178 | /* Remove information from the standard libraries */ 179 | /DISCARD/ : 180 | { 181 | libc.a ( * ) 182 | libm.a ( * ) 183 | libgcc.a ( * ) 184 | } 185 | 186 | .ARM.attributes 0 : { *(.ARM.attributes) } 187 | } 188 | 189 | 190 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Src/bsp_driver_sd.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file bsp_driver_sd.c for F7 (based on stm32756g_eval_sd.c) 5 | * @brief This file includes a generic uSD card driver. 6 | * To be completed by the user according to the board used for the project. 7 | * @note Some functions generated as weak: they can be overridden by 8 | * - code in user files 9 | * - or BSP code from the FW pack files 10 | * if such files are added to the generated project (by the user). 11 | ****************************************************************************** 12 | * @attention 13 | * 14 | *

© Copyright (c) 2021 STMicroelectronics. 15 | * All rights reserved.

16 | * 17 | * This software component is licensed by ST under Ultimate Liberty license 18 | * SLA0044, the "License"; You may not use this file except in compliance with 19 | * the License. You may obtain a copy of the License at: 20 | * www.st.com/SLA0044 21 | * 22 | ****************************************************************************** 23 | */ 24 | /* USER CODE END Header */ 25 | 26 | #ifdef OLD_API 27 | /* kept to avoid issue when migrating old projects. */ 28 | /* USER CODE BEGIN 0 */ 29 | 30 | /* USER CODE END 0 */ 31 | #else 32 | /* USER CODE BEGIN FirstSection */ 33 | /* can be used to modify / undefine following code or add new definitions */ 34 | /* USER CODE END FirstSection */ 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "bsp_driver_sd.h" 37 | 38 | /* Extern variables ---------------------------------------------------------*/ 39 | 40 | extern SD_HandleTypeDef hsd2; 41 | 42 | /* USER CODE BEGIN BeforeInitSection */ 43 | /* can be used to modify / undefine following code or add code */ 44 | /* USER CODE END BeforeInitSection */ 45 | /** 46 | * @brief Initializes the SD card device. 47 | * @retval SD status 48 | */ 49 | __weak uint8_t BSP_SD_Init(void) 50 | { 51 | uint8_t sd_state = MSD_OK; 52 | /* Check if the SD card is plugged in the slot */ 53 | if (BSP_SD_IsDetected() != SD_PRESENT) 54 | { 55 | return MSD_ERROR_SD_NOT_PRESENT; 56 | } 57 | /* HAL SD initialization */ 58 | sd_state = HAL_SD_Init(&hsd2); 59 | /* Configure SD Bus width (4 bits mode selected) */ 60 | if (sd_state == MSD_OK) 61 | { 62 | /* Enable wide operation */ 63 | if (HAL_SD_ConfigWideBusOperation(&hsd2, SDMMC_BUS_WIDE_4B) != HAL_OK) 64 | { 65 | sd_state = MSD_ERROR; 66 | } 67 | } 68 | 69 | return sd_state; 70 | } 71 | /* USER CODE BEGIN AfterInitSection */ 72 | /* can be used to modify previous code / undefine following code / add code */ 73 | /* USER CODE END AfterInitSection */ 74 | 75 | /* USER CODE BEGIN InterruptMode */ 76 | /** 77 | * @brief Configures Interrupt mode for SD detection pin. 78 | * @retval Returns 0 79 | */ 80 | __weak uint8_t BSP_SD_ITConfig(void) 81 | { 82 | /* Code to be updated by the user or replaced by one from the FW pack (in a stmxxxx_sd.c file) */ 83 | 84 | return (uint8_t)0; 85 | } 86 | 87 | /* USER CODE END InterruptMode */ 88 | 89 | /* USER CODE BEGIN BeforeReadBlocksSection */ 90 | /* can be used to modify previous code / undefine following code / add code */ 91 | /* USER CODE END BeforeReadBlocksSection */ 92 | /** 93 | * @brief Reads block(s) from a specified address in an SD card, in polling mode. 94 | * @param pData: Pointer to the buffer that will contain the data to transmit 95 | * @param ReadAddr: Address from where data is to be read 96 | * @param NumOfBlocks: Number of SD blocks to read 97 | * @param Timeout: Timeout for read operation 98 | * @retval SD status 99 | */ 100 | __weak uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout) 101 | { 102 | uint8_t sd_state = MSD_OK; 103 | 104 | if (HAL_SD_ReadBlocks(&hsd2, (uint8_t *)pData, ReadAddr, NumOfBlocks, Timeout) != HAL_OK) 105 | { 106 | sd_state = MSD_ERROR; 107 | } 108 | 109 | return sd_state; 110 | } 111 | 112 | /* USER CODE BEGIN BeforeWriteBlocksSection */ 113 | /* can be used to modify previous code / undefine following code / add code */ 114 | /* USER CODE END BeforeWriteBlocksSection */ 115 | /** 116 | * @brief Writes block(s) to a specified address in an SD card, in polling mode. 117 | * @param pData: Pointer to the buffer that will contain the data to transmit 118 | * @param WriteAddr: Address from where data is to be written 119 | * @param NumOfBlocks: Number of SD blocks to write 120 | * @param Timeout: Timeout for write operation 121 | * @retval SD status 122 | */ 123 | __weak uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout) 124 | { 125 | uint8_t sd_state = MSD_OK; 126 | 127 | if (HAL_SD_WriteBlocks(&hsd2, (uint8_t *)pData, WriteAddr, NumOfBlocks, Timeout) != HAL_OK) 128 | { 129 | sd_state = MSD_ERROR; 130 | } 131 | 132 | return sd_state; 133 | } 134 | 135 | /* USER CODE BEGIN BeforeReadDMABlocksSection */ 136 | /* can be used to modify previous code / undefine following code / add code */ 137 | /* USER CODE END BeforeReadDMABlocksSection */ 138 | /** 139 | * @brief Reads block(s) from a specified address in an SD card, in DMA mode. 140 | * @param pData: Pointer to the buffer that will contain the data to transmit 141 | * @param ReadAddr: Address from where data is to be read 142 | * @param NumOfBlocks: Number of SD blocks to read 143 | * @retval SD status 144 | */ 145 | __weak uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks) 146 | { 147 | uint8_t sd_state = MSD_OK; 148 | 149 | /* Read block(s) in DMA transfer mode */ 150 | if (HAL_SD_ReadBlocks_DMA(&hsd2, (uint8_t *)pData, ReadAddr, NumOfBlocks) != HAL_OK) 151 | { 152 | sd_state = MSD_ERROR; 153 | } 154 | 155 | return sd_state; 156 | } 157 | 158 | /* USER CODE BEGIN BeforeWriteDMABlocksSection */ 159 | /* can be used to modify previous code / undefine following code / add code */ 160 | /* USER CODE END BeforeWriteDMABlocksSection */ 161 | /** 162 | * @brief Writes block(s) to a specified address in an SD card, in DMA mode. 163 | * @param pData: Pointer to the buffer that will contain the data to transmit 164 | * @param WriteAddr: Address from where data is to be written 165 | * @param NumOfBlocks: Number of SD blocks to write 166 | * @retval SD status 167 | */ 168 | __weak uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks) 169 | { 170 | uint8_t sd_state = MSD_OK; 171 | 172 | /* Write block(s) in DMA transfer mode */ 173 | if (HAL_SD_WriteBlocks_DMA(&hsd2, (uint8_t *)pData, WriteAddr, NumOfBlocks) != HAL_OK) 174 | { 175 | sd_state = MSD_ERROR; 176 | } 177 | 178 | return sd_state; 179 | } 180 | 181 | /* USER CODE BEGIN BeforeEraseSection */ 182 | /* can be used to modify previous code / undefine following code / add code */ 183 | /* USER CODE END BeforeEraseSection */ 184 | /** 185 | * @brief Erases the specified memory area of the given SD card. 186 | * @param StartAddr: Start byte address 187 | * @param EndAddr: End byte address 188 | * @retval SD status 189 | */ 190 | __weak uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr) 191 | { 192 | uint8_t sd_state = MSD_OK; 193 | 194 | if (HAL_SD_Erase(&hsd2, StartAddr, EndAddr) != HAL_OK) 195 | { 196 | sd_state = MSD_ERROR; 197 | } 198 | 199 | return sd_state; 200 | } 201 | 202 | /* USER CODE BEGIN BeforeGetCardStateSection */ 203 | /* can be used to modify previous code / undefine following code / add code */ 204 | /* USER CODE END BeforeGetCardStateSection */ 205 | 206 | /** 207 | * @brief Gets the current SD card data status. 208 | * @param None 209 | * @retval Data transfer state. 210 | * This value can be one of the following values: 211 | * @arg SD_TRANSFER_OK: No data transfer is acting 212 | * @arg SD_TRANSFER_BUSY: Data transfer is acting 213 | */ 214 | __weak uint8_t BSP_SD_GetCardState(void) 215 | { 216 | return ((HAL_SD_GetCardState(&hsd2) == HAL_SD_CARD_TRANSFER ) ? SD_TRANSFER_OK : SD_TRANSFER_BUSY); 217 | } 218 | 219 | /** 220 | * @brief Get SD information about specific SD card. 221 | * @param CardInfo: Pointer to HAL_SD_CardInfoTypedef structure 222 | * @retval None 223 | */ 224 | __weak void BSP_SD_GetCardInfo(HAL_SD_CardInfoTypeDef *CardInfo) 225 | { 226 | /* Get SD card Information */ 227 | HAL_SD_GetCardInfo(&hsd2, CardInfo); 228 | } 229 | 230 | /* USER CODE BEGIN BeforeCallBacksSection */ 231 | /* can be used to modify previous code / undefine following code / add code */ 232 | /* USER CODE END BeforeCallBacksSection */ 233 | /** 234 | * @brief SD Abort callbacks 235 | * @param hsd: SD handle 236 | * @retval None 237 | */ 238 | void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd) 239 | { 240 | BSP_SD_AbortCallback(); 241 | } 242 | 243 | /** 244 | * @brief Tx Transfer completed callback 245 | * @param hsd: SD handle 246 | * @retval None 247 | */ 248 | void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd) 249 | { 250 | BSP_SD_WriteCpltCallback(); 251 | } 252 | 253 | /** 254 | * @brief Rx Transfer completed callback 255 | * @param hsd: SD handle 256 | * @retval None 257 | */ 258 | void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd) 259 | { 260 | BSP_SD_ReadCpltCallback(); 261 | } 262 | 263 | /* USER CODE BEGIN CallBacksSection_C */ 264 | /** 265 | * @brief BSP SD Abort callback 266 | * @retval None 267 | * @note empty (up to the user to fill it in or to remove it if useless) 268 | */ 269 | __weak void BSP_SD_AbortCallback(void) 270 | { 271 | 272 | } 273 | 274 | /** 275 | * @brief BSP Tx Transfer completed callback 276 | * @retval None 277 | * @note empty (up to the user to fill it in or to remove it if useless) 278 | */ 279 | __weak void BSP_SD_WriteCpltCallback(void) 280 | { 281 | 282 | } 283 | 284 | /** 285 | * @brief BSP Rx Transfer completed callback 286 | * @retval None 287 | * @note empty (up to the user to fill it in or to remove it if useless) 288 | */ 289 | __weak void BSP_SD_ReadCpltCallback(void) 290 | { 291 | 292 | } 293 | /* USER CODE END CallBacksSection_C */ 294 | #endif 295 | 296 | /** 297 | * @brief Detects if SD card is correctly plugged in the memory slot or not. 298 | * @param None 299 | * @retval Returns if SD is detected or not 300 | */ 301 | __weak uint8_t BSP_SD_IsDetected(void) 302 | { 303 | __IO uint8_t status = SD_PRESENT; 304 | 305 | if (BSP_PlatformIsDetected() == 0x0) 306 | { 307 | status = SD_NOT_PRESENT; 308 | } 309 | 310 | return status; 311 | } 312 | 313 | /* USER CODE BEGIN AdditionalCode */ 314 | /* user code can be inserted here */ 315 | /* USER CODE END AdditionalCode */ 316 | 317 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 318 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Src/fatfs.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file fatfs.c 4 | * @brief Code for fatfs applications 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | *

© Copyright (c) 2021 STMicroelectronics. 9 | * All rights reserved.

10 | * 11 | * This software component is licensed by ST under Ultimate Liberty license 12 | * SLA0044, the "License"; You may not use this file except in compliance with 13 | * the License. You may obtain a copy of the License at: 14 | * www.st.com/SLA0044 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | #include "fatfs.h" 20 | 21 | uint8_t retSD; /* Return value for SD */ 22 | char SDPath[4]; /* SD logical drive path */ 23 | FATFS SDFatFS; /* File system object for SD logical drive */ 24 | FIL SDFile; /* File object for SD */ 25 | 26 | /* USER CODE BEGIN Variables */ 27 | 28 | /* USER CODE END Variables */ 29 | 30 | void MX_FATFS_Init(void) 31 | { 32 | /*## FatFS: Link the SD driver ###########################*/ 33 | retSD = FATFS_LinkDriver(&SD_Driver, SDPath); 34 | 35 | /* USER CODE BEGIN Init */ 36 | /* additional user code for init */ 37 | /* USER CODE END Init */ 38 | } 39 | 40 | /** 41 | * @brief Gets Time from RTC 42 | * @param None 43 | * @retval Time in DWORD 44 | */ 45 | DWORD get_fattime(void) 46 | { 47 | /* USER CODE BEGIN get_fattime */ 48 | return 0; 49 | /* USER CODE END get_fattime */ 50 | } 51 | 52 | /* USER CODE BEGIN Application */ 53 | 54 | /* USER CODE END Application */ 55 | 56 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 57 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Src/fatfs_platform.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : fatfs_platform.c 4 | * @brief : fatfs_platform source file 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | *

© Copyright (c) 2021 STMicroelectronics. 9 | * All rights reserved.

10 | * 11 | * This software component is licensed by ST under Ultimate Liberty license 12 | * SLA0044, the "License"; You may not use this file except in compliance with 13 | * the License. You may obtain a copy of the License at: 14 | * www.st.com/SLA0044 15 | * 16 | ****************************************************************************** 17 | */ 18 | #include "fatfs_platform.h" 19 | 20 | uint8_t BSP_PlatformIsDetected(void) { 21 | uint8_t status = SD_PRESENT; 22 | /* Check SD card detect pin */ 23 | if(HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != GPIO_PIN_RESET) 24 | { 25 | status = SD_NOT_PRESENT; 26 | } 27 | /* USER CODE BEGIN 1 */ 28 | /* user code can be inserted here */ 29 | /* USER CODE END 1 */ 30 | return status; 31 | } 32 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Src/freertos.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * File Name : freertos.c 5 | * Description : Code for freertos applications 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "FreeRTOS.h" 23 | #include "task.h" 24 | #include "main.h" 25 | 26 | /* Private includes ----------------------------------------------------------*/ 27 | /* USER CODE BEGIN Includes */ 28 | 29 | /* USER CODE END Includes */ 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* USER CODE BEGIN PTD */ 33 | 34 | /* USER CODE END PTD */ 35 | 36 | /* Private define ------------------------------------------------------------*/ 37 | /* USER CODE BEGIN PD */ 38 | 39 | /* USER CODE END PD */ 40 | 41 | /* Private macro -------------------------------------------------------------*/ 42 | /* USER CODE BEGIN PM */ 43 | 44 | /* USER CODE END PM */ 45 | 46 | /* Private variables ---------------------------------------------------------*/ 47 | /* USER CODE BEGIN Variables */ 48 | 49 | /* USER CODE END Variables */ 50 | 51 | /* Private function prototypes -----------------------------------------------*/ 52 | /* USER CODE BEGIN FunctionPrototypes */ 53 | 54 | /* USER CODE END FunctionPrototypes */ 55 | 56 | /* Hook prototypes */ 57 | void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName); 58 | void vApplicationMallocFailedHook(void); 59 | 60 | /* USER CODE BEGIN 4 */ 61 | void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName) 62 | { 63 | configASSERT (0); 64 | } 65 | /* USER CODE END 4 */ 66 | 67 | /* USER CODE BEGIN 5 */ 68 | void vApplicationMallocFailedHook(void) 69 | { 70 | configASSERT (0); 71 | } 72 | /* USER CODE END 5 */ 73 | 74 | /* Private application code --------------------------------------------------*/ 75 | /* USER CODE BEGIN Application */ 76 | 77 | /* USER CODE END Application */ 78 | 79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 80 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Src/lwip.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : LWIP.c 4 | * Description : This file provides initialization code for LWIP 5 | * middleWare. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "lwip.h" 22 | #include "lwip/init.h" 23 | #include "lwip/netif.h" 24 | #if defined ( __CC_ARM ) /* MDK ARM Compiler */ 25 | #include "lwip/sio.h" 26 | #endif /* MDK ARM Compiler */ 27 | #include "ethernetif.h" 28 | #include 29 | 30 | /* USER CODE BEGIN 0 */ 31 | 32 | /* USER CODE END 0 */ 33 | /* Private function prototypes -----------------------------------------------*/ 34 | /* ETH Variables initialization ----------------------------------------------*/ 35 | void Error_Handler(void); 36 | 37 | /* USER CODE BEGIN 1 */ 38 | 39 | /* USER CODE END 1 */ 40 | /* Semaphore to signal Ethernet Link state update */ 41 | osSemaphoreId Netif_LinkSemaphore = NULL; 42 | /* Ethernet link thread Argument */ 43 | struct link_str link_arg; 44 | 45 | /* Variables Initialization */ 46 | struct netif gnetif; 47 | ip4_addr_t ipaddr; 48 | ip4_addr_t netmask; 49 | ip4_addr_t gw; 50 | /* USER CODE BEGIN OS_THREAD_ATTR_CMSIS_RTOS_V2 */ 51 | #define INTERFACE_THREAD_STACK_SIZE ( 2048 ) 52 | osThreadAttr_t attributes; 53 | /* USER CODE END OS_THREAD_ATTR_CMSIS_RTOS_V2 */ 54 | 55 | /* USER CODE BEGIN 2 */ 56 | 57 | /* USER CODE END 2 */ 58 | 59 | /** 60 | * LwIP initialization function 61 | */ 62 | void MX_LWIP_Init(void) 63 | { 64 | /* Initilialize the LwIP stack with RTOS */ 65 | tcpip_init( NULL, NULL ); 66 | 67 | /* IP addresses initialization with DHCP (IPv4) */ 68 | ipaddr.addr = 0; 69 | netmask.addr = 0; 70 | gw.addr = 0; 71 | 72 | /* add the network interface (IPv4/IPv6) with RTOS */ 73 | netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input); 74 | 75 | /* Registers the default network interface */ 76 | netif_set_default(&gnetif); 77 | 78 | if (netif_is_link_up(&gnetif)) 79 | { 80 | /* When the netif is fully configured this function must be called */ 81 | netif_set_up(&gnetif); 82 | } 83 | else 84 | { 85 | /* When the netif link is down this function must be called */ 86 | netif_set_down(&gnetif); 87 | } 88 | 89 | /* Set the link callback function, this function is called on change of link status*/ 90 | netif_set_link_callback(&gnetif, ethernetif_update_config); 91 | 92 | /* create a binary semaphore used for informing ethernetif of frame reception */ 93 | Netif_LinkSemaphore = osSemaphoreNew(1, 1, NULL); 94 | 95 | link_arg.netif = &gnetif; 96 | link_arg.semaphore = Netif_LinkSemaphore; 97 | /* Create the Ethernet link handler thread */ 98 | /* USER CODE BEGIN OS_THREAD_NEW_CMSIS_RTOS_V2 */ 99 | memset(&attributes, 0x0, sizeof(osThreadAttr_t)); 100 | attributes.name = "LinkThr"; 101 | attributes.stack_size = INTERFACE_THREAD_STACK_SIZE; 102 | attributes.priority = osPriorityBelowNormal; 103 | osThreadNew(ethernetif_set_link, &link_arg, &attributes); 104 | /* USER CODE END OS_THREAD_NEW_CMSIS_RTOS_V2 */ 105 | 106 | /* Start DHCP negotiation for a network interface (IPv4) */ 107 | dhcp_start(&gnetif); 108 | 109 | /* USER CODE BEGIN 3 */ 110 | 111 | /* USER CODE END 3 */ 112 | } 113 | 114 | #ifdef USE_OBSOLETE_USER_CODE_SECTION_4 115 | /* Kept to help code migration. (See new 4_1, 4_2... sections) */ 116 | /* Avoid to use this user section which will become obsolete. */ 117 | /* USER CODE BEGIN 4 */ 118 | /* USER CODE END 4 */ 119 | #endif 120 | 121 | #if defined ( __CC_ARM ) /* MDK ARM Compiler */ 122 | /** 123 | * Opens a serial device for communication. 124 | * 125 | * @param devnum device number 126 | * @return handle to serial device if successful, NULL otherwise 127 | */ 128 | sio_fd_t sio_open(u8_t devnum) 129 | { 130 | sio_fd_t sd; 131 | 132 | /* USER CODE BEGIN 7 */ 133 | sd = 0; // dummy code 134 | /* USER CODE END 7 */ 135 | 136 | return sd; 137 | } 138 | 139 | /** 140 | * Sends a single character to the serial device. 141 | * 142 | * @param c character to send 143 | * @param fd serial device handle 144 | * 145 | * @note This function will block until the character can be sent. 146 | */ 147 | void sio_send(u8_t c, sio_fd_t fd) 148 | { 149 | /* USER CODE BEGIN 8 */ 150 | /* USER CODE END 8 */ 151 | } 152 | 153 | /** 154 | * Reads from the serial device. 155 | * 156 | * @param fd serial device handle 157 | * @param data pointer to data buffer for receiving 158 | * @param len maximum length (in bytes) of data to receive 159 | * @return number of bytes actually received - may be 0 if aborted by sio_read_abort 160 | * 161 | * @note This function will block until data can be received. The blocking 162 | * can be cancelled by calling sio_read_abort(). 163 | */ 164 | u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len) 165 | { 166 | u32_t recved_bytes; 167 | 168 | /* USER CODE BEGIN 9 */ 169 | recved_bytes = 0; // dummy code 170 | /* USER CODE END 9 */ 171 | return recved_bytes; 172 | } 173 | 174 | /** 175 | * Tries to read from the serial device. Same as sio_read but returns 176 | * immediately if no data is available and never blocks. 177 | * 178 | * @param fd serial device handle 179 | * @param data pointer to data buffer for receiving 180 | * @param len maximum length (in bytes) of data to receive 181 | * @return number of bytes actually received 182 | */ 183 | u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len) 184 | { 185 | u32_t recved_bytes; 186 | 187 | /* USER CODE BEGIN 10 */ 188 | recved_bytes = 0; // dummy code 189 | /* USER CODE END 10 */ 190 | return recved_bytes; 191 | } 192 | #endif /* MDK ARM Compiler */ 193 | 194 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 195 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Src/lwip.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : LWIP.h 4 | * Description : This file provides code for the configuration 5 | * of the LWIP. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ************************************************************************* 18 | 19 | */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __mx_lwip_H 22 | #define __mx_lwip_H 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "lwip/opt.h" 29 | #include "lwip/mem.h" 30 | #include "lwip/memp.h" 31 | #include "netif/etharp.h" 32 | #include "lwip/dhcp.h" 33 | #include "lwip/netif.h" 34 | #include "lwip/timeouts.h" 35 | #include "ethernetif.h" 36 | 37 | /* Includes for RTOS ---------------------------------------------------------*/ 38 | #if WITH_RTOS 39 | #include "lwip/tcpip.h" 40 | #endif /* WITH_RTOS */ 41 | 42 | /* USER CODE BEGIN 0 */ 43 | 44 | /* USER CODE END 0 */ 45 | 46 | /* Global Variables ----------------------------------------------------------*/ 47 | extern ETH_HandleTypeDef heth; 48 | 49 | /* LWIP init function */ 50 | void MX_LWIP_Init(void); 51 | 52 | #if !WITH_RTOS 53 | /* USER CODE BEGIN 1 */ 54 | /* Function defined in lwip.c to: 55 | * - Read a received packet from the Ethernet buffers 56 | * - Send it to the lwIP stack for handling 57 | * - Handle timeouts if NO_SYS_NO_TIMERS not set 58 | */ 59 | void MX_LWIP_Process(void); 60 | 61 | /* USER CODE END 1 */ 62 | #endif /* WITH_RTOS */ 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | #endif /*__ mx_lwip_H */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Src/stm32f7xx_hal_timebase_tim.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f7xx_hal_timebase_TIM.c 5 | * @brief HAL time base based on the hardware TIM. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "stm32f7xx_hal.h" 23 | #include "stm32f7xx_hal_tim.h" 24 | 25 | /* Private typedef -----------------------------------------------------------*/ 26 | /* Private define ------------------------------------------------------------*/ 27 | /* Private macro -------------------------------------------------------------*/ 28 | /* Private variables ---------------------------------------------------------*/ 29 | TIM_HandleTypeDef htim1; 30 | /* Private function prototypes -----------------------------------------------*/ 31 | /* Private functions ---------------------------------------------------------*/ 32 | 33 | /** 34 | * @brief This function configures the TIM1 as a time base source. 35 | * The time source is configured to have 1ms time base with a dedicated 36 | * Tick interrupt priority. 37 | * @note This function is called automatically at the beginning of program after 38 | * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). 39 | * @param TickPriority: Tick interrupt priority. 40 | * @retval HAL status 41 | */ 42 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) 43 | { 44 | RCC_ClkInitTypeDef clkconfig; 45 | uint32_t uwTimclock = 0; 46 | uint32_t uwPrescalerValue = 0; 47 | uint32_t pFLatency; 48 | /*Configure the TIM1 IRQ priority */ 49 | HAL_NVIC_SetPriority(TIM1_UP_TIM10_IRQn, TickPriority ,0); 50 | 51 | /* Enable the TIM1 global Interrupt */ 52 | HAL_NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn); 53 | 54 | /* Enable TIM1 clock */ 55 | __HAL_RCC_TIM1_CLK_ENABLE(); 56 | 57 | /* Get clock configuration */ 58 | HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); 59 | 60 | /* Compute TIM1 clock */ 61 | uwTimclock = 2*HAL_RCC_GetPCLK2Freq(); 62 | /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ 63 | uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); 64 | 65 | /* Initialize TIM1 */ 66 | htim1.Instance = TIM1; 67 | 68 | /* Initialize TIMx peripheral as follow: 69 | + Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. 70 | + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. 71 | + ClockDivision = 0 72 | + Counter direction = Up 73 | */ 74 | htim1.Init.Period = (1000000U / 1000U) - 1U; 75 | htim1.Init.Prescaler = uwPrescalerValue; 76 | htim1.Init.ClockDivision = 0; 77 | htim1.Init.CounterMode = TIM_COUNTERMODE_UP; 78 | 79 | if(HAL_TIM_Base_Init(&htim1) == HAL_OK) 80 | { 81 | /* Start the TIM time Base generation in interrupt mode */ 82 | return HAL_TIM_Base_Start_IT(&htim1); 83 | } 84 | 85 | /* Return function status */ 86 | return HAL_ERROR; 87 | } 88 | 89 | /** 90 | * @brief Suspend Tick increment. 91 | * @note Disable the tick increment by disabling TIM1 update interrupt. 92 | * @param None 93 | * @retval None 94 | */ 95 | void HAL_SuspendTick(void) 96 | { 97 | /* Disable TIM1 update Interrupt */ 98 | __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); 99 | } 100 | 101 | /** 102 | * @brief Resume Tick increment. 103 | * @note Enable the tick increment by Enabling TIM1 update interrupt. 104 | * @param None 105 | * @retval None 106 | */ 107 | void HAL_ResumeTick(void) 108 | { 109 | /* Enable TIM1 Update interrupt */ 110 | __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); 111 | } 112 | 113 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 114 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Src/stm32f7xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f7xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | #include "stm32f7xx_it.h" 24 | /* Private includes ----------------------------------------------------------*/ 25 | /* USER CODE BEGIN Includes */ 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN PD */ 35 | 36 | /* USER CODE END PD */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN PM */ 40 | 41 | /* USER CODE END PM */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* Private user code ---------------------------------------------------------*/ 54 | /* USER CODE BEGIN 0 */ 55 | 56 | /* USER CODE END 0 */ 57 | 58 | /* External variables --------------------------------------------------------*/ 59 | extern ETH_HandleTypeDef heth; 60 | extern DMA_HandleTypeDef hdma_sdmmc2_rx; 61 | extern DMA_HandleTypeDef hdma_sdmmc2_tx; 62 | extern SD_HandleTypeDef hsd2; 63 | extern DMA_HandleTypeDef hdma_usart1_tx; 64 | extern UART_HandleTypeDef huart1; 65 | extern TIM_HandleTypeDef htim1; 66 | 67 | /* USER CODE BEGIN EV */ 68 | 69 | /* USER CODE END EV */ 70 | 71 | /******************************************************************************/ 72 | /* Cortex-M7 Processor Interruption and Exception Handlers */ 73 | /******************************************************************************/ 74 | /** 75 | * @brief This function handles Non maskable interrupt. 76 | */ 77 | void NMI_Handler(void) 78 | { 79 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 80 | 81 | /* USER CODE END NonMaskableInt_IRQn 0 */ 82 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 83 | while (1) 84 | { 85 | } 86 | /* USER CODE END NonMaskableInt_IRQn 1 */ 87 | } 88 | 89 | /** 90 | * @brief This function handles Hard fault interrupt. 91 | */ 92 | void HardFault_Handler(void) 93 | { 94 | /* USER CODE BEGIN HardFault_IRQn 0 */ 95 | 96 | /* USER CODE END HardFault_IRQn 0 */ 97 | while (1) 98 | { 99 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 100 | /* USER CODE END W1_HardFault_IRQn 0 */ 101 | } 102 | } 103 | 104 | /** 105 | * @brief This function handles Memory management fault. 106 | */ 107 | void MemManage_Handler(void) 108 | { 109 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 110 | 111 | /* USER CODE END MemoryManagement_IRQn 0 */ 112 | while (1) 113 | { 114 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 115 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 116 | } 117 | } 118 | 119 | /** 120 | * @brief This function handles Pre-fetch fault, memory access fault. 121 | */ 122 | void BusFault_Handler(void) 123 | { 124 | /* USER CODE BEGIN BusFault_IRQn 0 */ 125 | 126 | /* USER CODE END BusFault_IRQn 0 */ 127 | while (1) 128 | { 129 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 130 | /* USER CODE END W1_BusFault_IRQn 0 */ 131 | } 132 | } 133 | 134 | /** 135 | * @brief This function handles Undefined instruction or illegal state. 136 | */ 137 | void UsageFault_Handler(void) 138 | { 139 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 140 | 141 | /* USER CODE END UsageFault_IRQn 0 */ 142 | while (1) 143 | { 144 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 145 | /* USER CODE END W1_UsageFault_IRQn 0 */ 146 | } 147 | } 148 | 149 | /** 150 | * @brief This function handles Debug monitor. 151 | */ 152 | void DebugMon_Handler(void) 153 | { 154 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 155 | 156 | /* USER CODE END DebugMonitor_IRQn 0 */ 157 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 158 | 159 | /* USER CODE END DebugMonitor_IRQn 1 */ 160 | } 161 | 162 | /******************************************************************************/ 163 | /* STM32F7xx Peripheral Interrupt Handlers */ 164 | /* Add here the Interrupt Handlers for the used peripherals. */ 165 | /* For the available peripheral interrupt handler names, */ 166 | /* please refer to the startup file (startup_stm32f7xx.s). */ 167 | /******************************************************************************/ 168 | 169 | /** 170 | * @brief This function handles TIM1 update interrupt and TIM10 global interrupt. 171 | */ 172 | void TIM1_UP_TIM10_IRQHandler(void) 173 | { 174 | /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */ 175 | 176 | /* USER CODE END TIM1_UP_TIM10_IRQn 0 */ 177 | HAL_TIM_IRQHandler(&htim1); 178 | /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */ 179 | 180 | /* USER CODE END TIM1_UP_TIM10_IRQn 1 */ 181 | } 182 | 183 | /** 184 | * @brief This function handles USART1 global interrupt. 185 | */ 186 | void USART1_IRQHandler(void) 187 | { 188 | /* USER CODE BEGIN USART1_IRQn 0 */ 189 | 190 | /* USER CODE END USART1_IRQn 0 */ 191 | HAL_UART_IRQHandler(&huart1); 192 | /* USER CODE BEGIN USART1_IRQn 1 */ 193 | 194 | /* USER CODE END USART1_IRQn 1 */ 195 | } 196 | 197 | /** 198 | * @brief This function handles DMA2 stream0 global interrupt. 199 | */ 200 | void DMA2_Stream0_IRQHandler(void) 201 | { 202 | /* USER CODE BEGIN DMA2_Stream0_IRQn 0 */ 203 | 204 | /* USER CODE END DMA2_Stream0_IRQn 0 */ 205 | HAL_DMA_IRQHandler(&hdma_sdmmc2_rx); 206 | /* USER CODE BEGIN DMA2_Stream0_IRQn 1 */ 207 | 208 | /* USER CODE END DMA2_Stream0_IRQn 1 */ 209 | } 210 | 211 | /** 212 | * @brief This function handles Ethernet global interrupt. 213 | */ 214 | void ETH_IRQHandler(void) 215 | { 216 | /* USER CODE BEGIN ETH_IRQn 0 */ 217 | 218 | /* USER CODE END ETH_IRQn 0 */ 219 | HAL_ETH_IRQHandler(&heth); 220 | /* USER CODE BEGIN ETH_IRQn 1 */ 221 | 222 | /* USER CODE END ETH_IRQn 1 */ 223 | } 224 | 225 | /** 226 | * @brief This function handles DMA2 stream5 global interrupt. 227 | */ 228 | void DMA2_Stream5_IRQHandler(void) 229 | { 230 | /* USER CODE BEGIN DMA2_Stream5_IRQn 0 */ 231 | 232 | /* USER CODE END DMA2_Stream5_IRQn 0 */ 233 | HAL_DMA_IRQHandler(&hdma_sdmmc2_tx); 234 | /* USER CODE BEGIN DMA2_Stream5_IRQn 1 */ 235 | 236 | /* USER CODE END DMA2_Stream5_IRQn 1 */ 237 | } 238 | 239 | /** 240 | * @brief This function handles DMA2 stream7 global interrupt. 241 | */ 242 | void DMA2_Stream7_IRQHandler(void) 243 | { 244 | /* USER CODE BEGIN DMA2_Stream7_IRQn 0 */ 245 | 246 | /* USER CODE END DMA2_Stream7_IRQn 0 */ 247 | HAL_DMA_IRQHandler(&hdma_usart1_tx); 248 | /* USER CODE BEGIN DMA2_Stream7_IRQn 1 */ 249 | 250 | /* USER CODE END DMA2_Stream7_IRQn 1 */ 251 | } 252 | 253 | /** 254 | * @brief This function handles SDMMC2 global interrupt. 255 | */ 256 | void SDMMC2_IRQHandler(void) 257 | { 258 | /* USER CODE BEGIN SDMMC2_IRQn 0 */ 259 | 260 | /* USER CODE END SDMMC2_IRQn 0 */ 261 | HAL_SD_IRQHandler(&hsd2); 262 | /* USER CODE BEGIN SDMMC2_IRQn 1 */ 263 | 264 | /* USER CODE END SDMMC2_IRQn 1 */ 265 | } 266 | 267 | /* USER CODE BEGIN 1 */ 268 | 269 | /* USER CODE END 1 */ 270 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 271 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Src/stubs.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2018 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | char *getcwd(char *buf, size_t size) 22 | { 23 | buf[0] = '/'; 24 | buf[1] = 0; 25 | return buf; 26 | } 27 | 28 | int mkdir(const char *pathname, mode_t mode) 29 | { 30 | return -1; 31 | } 32 | 33 | /* int _gettimeofday (struct timeval * ptimeval, void * ptimezone) */ 34 | /* { */ 35 | /* return -1; */ 36 | /* } */ 37 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Src/syscalls.c: -------------------------------------------------------------------------------- 1 | /* Support files for GNU libc. Files in the system namespace go here. 2 | Files in the C namespace (ie those that do not start with an 3 | underscore) go in .c. */ 4 | 5 | #include <_ansi.h> 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | 21 | #define FreeRTOS 22 | #define MAX_STACK_SIZE 0x2000 23 | 24 | extern int __io_putchar(int ch) __attribute__((weak)); 25 | extern int __io_getchar(void) __attribute__((weak)); 26 | 27 | #ifndef FreeRTOS 28 | register char * stack_ptr asm("sp"); 29 | #endif 30 | 31 | 32 | 33 | 34 | caddr_t _sbrk(int incr) 35 | { 36 | extern char end asm("end"); 37 | static char *heap_end; 38 | char *prev_heap_end,*min_stack_ptr; 39 | 40 | if (heap_end == 0) 41 | heap_end = &end; 42 | 43 | prev_heap_end = heap_end; 44 | 45 | #ifdef FreeRTOS 46 | /* Use the NVIC offset register to locate the main stack pointer. */ 47 | min_stack_ptr = (char*)(*(unsigned int *)*(unsigned int *)0xE000ED08); 48 | /* Locate the STACK bottom address */ 49 | min_stack_ptr -= MAX_STACK_SIZE; 50 | 51 | if (heap_end + incr > min_stack_ptr) 52 | #else 53 | if (heap_end + incr > stack_ptr) 54 | #endif 55 | { 56 | // write(1, "Heap and stack collision\n", 25); 57 | // abort(); 58 | errno = ENOMEM; 59 | return (caddr_t) -1; 60 | } 61 | 62 | heap_end += incr; 63 | 64 | return (caddr_t) prev_heap_end; 65 | } 66 | 67 | /* 68 | * _gettimeofday primitive (Stub function) 69 | * */ 70 | int _gettimeofday (struct timeval * tp, struct timezone * tzp) 71 | { 72 | /* Return fixed data for the timezone. */ 73 | if (tzp) 74 | { 75 | tzp->tz_minuteswest = 0; 76 | tzp->tz_dsttime = 0; 77 | } 78 | if (tp) 79 | { 80 | /* Set default value */ 81 | tp->tv_sec = 1230768000; /* 2009-01-01 */ 82 | tp->tv_usec = 0; 83 | } 84 | 85 | return 0; 86 | } 87 | void initialise_monitor_handles() 88 | { 89 | } 90 | 91 | int _getpid(void) 92 | { 93 | return 1; 94 | } 95 | 96 | int _kill(int pid, int sig) 97 | { 98 | errno = EINVAL; 99 | return -1; 100 | } 101 | 102 | void _exit (int status) 103 | { 104 | _kill(status, -1); 105 | while (1) {} 106 | } 107 | 108 | int _write(int file, char *ptr, int len) 109 | { 110 | int DataIdx; 111 | 112 | for (DataIdx = 0; DataIdx < len; DataIdx++) 113 | { 114 | __io_putchar( *ptr++ ); 115 | } 116 | return len; 117 | } 118 | 119 | int _close(int file) 120 | { 121 | return -1; 122 | } 123 | 124 | int _fstat(int file, struct stat *st) 125 | { 126 | st->st_mode = S_IFCHR; 127 | return 0; 128 | } 129 | 130 | int _isatty(int file) 131 | { 132 | return 1; 133 | } 134 | 135 | int _lseek(int file, int ptr, int dir) 136 | { 137 | return 0; 138 | } 139 | 140 | int _read(int file, char *ptr, int len) 141 | { 142 | int DataIdx; 143 | 144 | for (DataIdx = 0; DataIdx < len; DataIdx++) 145 | { 146 | *ptr++ = __io_getchar(); 147 | } 148 | 149 | return len; 150 | } 151 | 152 | int _open(char *path, int flags, ...) 153 | { 154 | /* Pretend like we always fail */ 155 | return -1; 156 | } 157 | 158 | int _wait(int *status) 159 | { 160 | errno = ECHILD; 161 | return -1; 162 | } 163 | 164 | int _unlink(char *name) 165 | { 166 | errno = ENOENT; 167 | return -1; 168 | } 169 | 170 | int _times(struct tms *buf) 171 | { 172 | return -1; 173 | } 174 | 175 | int _stat(char *file, struct stat *st) 176 | { 177 | st->st_mode = S_IFCHR; 178 | return 0; 179 | } 180 | 181 | int _link(char *old, char *new) 182 | { 183 | errno = EMLINK; 184 | return -1; 185 | } 186 | 187 | int _fork(void) 188 | { 189 | errno = EAGAIN; 190 | return -1; 191 | } 192 | 193 | int _execve(char *name, char **argv, char **env) 194 | { 195 | errno = ENOMEM; 196 | return -1; 197 | } 198 | -------------------------------------------------------------------------------- /src/freertos/STM32F769I-DISCO/Src/system_stm32f7xx.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f7xx.c 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M7 Device Peripheral Access Layer System Source File. 6 | * 7 | * This file provides two functions and one global variable to be called from 8 | * user application: 9 | * - SystemInit(): This function is called at startup just after reset and 10 | * before branch to main program. This call is made inside 11 | * the "startup_stm32f7xx.s" file. 12 | * 13 | * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used 14 | * by the user application to setup the SysTick 15 | * timer or configure other parameters. 16 | * 17 | * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must 18 | * be called whenever the core clock is changed 19 | * during program execution. 20 | * 21 | * 22 | ****************************************************************************** 23 | * @attention 24 | * 25 | *

© Copyright (c) 2016 STMicroelectronics. 26 | * All rights reserved.

27 | * 28 | * This software component is licensed by ST under BSD 3-Clause license, 29 | * the "License"; You may not use this file except in compliance with the 30 | * License. You may obtain a copy of the License at: 31 | * opensource.org/licenses/BSD-3-Clause 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /** @addtogroup CMSIS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup stm32f7xx_system 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup STM32F7xx_System_Private_Includes 45 | * @{ 46 | */ 47 | 48 | #include "stm32f7xx.h" 49 | 50 | #if !defined (HSE_VALUE) 51 | #define HSE_VALUE ((uint32_t)25000000) /*!< Default value of the External oscillator in Hz */ 52 | #endif /* HSE_VALUE */ 53 | 54 | #if !defined (HSI_VALUE) 55 | #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ 56 | #endif /* HSI_VALUE */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /** @addtogroup STM32F7xx_System_Private_TypesDefinitions 63 | * @{ 64 | */ 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /** @addtogroup STM32F7xx_System_Private_Defines 71 | * @{ 72 | */ 73 | 74 | /************************* Miscellaneous Configuration ************************/ 75 | 76 | /* Note: Following vector table addresses must be defined in line with linker 77 | configuration. */ 78 | /*!< Uncomment the following line if you need to relocate the vector table 79 | anywhere in Flash or Sram, else the vector table is kept at the automatic 80 | remap of boot address selected */ 81 | /* #define USER_VECT_TAB_ADDRESS */ 82 | 83 | #if defined(USER_VECT_TAB_ADDRESS) 84 | /*!< Uncomment the following line if you need to relocate your vector Table 85 | in Sram else user remap will be done in Flash. */ 86 | /* #define VECT_TAB_SRAM */ 87 | #if defined(VECT_TAB_SRAM) 88 | #define VECT_TAB_BASE_ADDRESS RAMDTCM_BASE /*!< Vector Table base address field. 89 | This value must be a multiple of 0x200. */ 90 | #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. 91 | This value must be a multiple of 0x200. */ 92 | #else 93 | #define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field. 94 | This value must be a multiple of 0x200. */ 95 | #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. 96 | This value must be a multiple of 0x200. */ 97 | #endif /* VECT_TAB_SRAM */ 98 | #endif /* USER_VECT_TAB_ADDRESS */ 99 | /******************************************************************************/ 100 | 101 | /** 102 | * @} 103 | */ 104 | 105 | /** @addtogroup STM32F7xx_System_Private_Macros 106 | * @{ 107 | */ 108 | 109 | /** 110 | * @} 111 | */ 112 | 113 | /** @addtogroup STM32F7xx_System_Private_Variables 114 | * @{ 115 | */ 116 | 117 | /* This variable is updated in three ways: 118 | 1) by calling CMSIS function SystemCoreClockUpdate() 119 | 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 120 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 121 | Note: If you use this function to configure the system clock; then there 122 | is no need to call the 2 first functions listed above, since SystemCoreClock 123 | variable is updated automatically. 124 | */ 125 | uint32_t SystemCoreClock = 16000000; 126 | const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; 127 | const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; 128 | 129 | /** 130 | * @} 131 | */ 132 | 133 | /** @addtogroup STM32F7xx_System_Private_FunctionPrototypes 134 | * @{ 135 | */ 136 | 137 | /** 138 | * @} 139 | */ 140 | 141 | /** @addtogroup STM32F7xx_System_Private_Functions 142 | * @{ 143 | */ 144 | 145 | /** 146 | * @brief Setup the microcontroller system 147 | * Initialize the Embedded Flash Interface, the PLL and update the 148 | * SystemFrequency variable. 149 | * @param None 150 | * @retval None 151 | */ 152 | void SystemInit(void) 153 | { 154 | /* FPU settings ------------------------------------------------------------*/ 155 | #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) 156 | SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */ 157 | #endif 158 | 159 | /* Configure the Vector Table location -------------------------------------*/ 160 | #if defined(USER_VECT_TAB_ADDRESS) 161 | SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ 162 | #endif /* USER_VECT_TAB_ADDRESS */ 163 | } 164 | 165 | /** 166 | * @brief Update SystemCoreClock variable according to Clock Register Values. 167 | * The SystemCoreClock variable contains the core clock (HCLK), it can 168 | * be used by the user application to setup the SysTick timer or configure 169 | * other parameters. 170 | * 171 | * @note Each time the core clock (HCLK) changes, this function must be called 172 | * to update SystemCoreClock variable value. Otherwise, any configuration 173 | * based on this variable will be incorrect. 174 | * 175 | * @note - The system frequency computed by this function is not the real 176 | * frequency in the chip. It is calculated based on the predefined 177 | * constant and the selected clock source: 178 | * 179 | * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) 180 | * 181 | * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) 182 | * 183 | * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) 184 | * or HSI_VALUE(*) multiplied/divided by the PLL factors. 185 | * 186 | * (*) HSI_VALUE is a constant defined in stm32f7xx_hal_conf.h file (default value 187 | * 16 MHz) but the real value may vary depending on the variations 188 | * in voltage and temperature. 189 | * 190 | * (**) HSE_VALUE is a constant defined in stm32f7xx_hal_conf.h file (default value 191 | * 25 MHz), user has to ensure that HSE_VALUE is same as the real 192 | * frequency of the crystal used. Otherwise, this function may 193 | * have wrong result. 194 | * 195 | * - The result of this function could be not correct when using fractional 196 | * value for HSE crystal. 197 | * 198 | * @param None 199 | * @retval None 200 | */ 201 | void SystemCoreClockUpdate(void) 202 | { 203 | uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2; 204 | 205 | /* Get SYSCLK source -------------------------------------------------------*/ 206 | tmp = RCC->CFGR & RCC_CFGR_SWS; 207 | 208 | switch (tmp) 209 | { 210 | case 0x00: /* HSI used as system clock source */ 211 | SystemCoreClock = HSI_VALUE; 212 | break; 213 | case 0x04: /* HSE used as system clock source */ 214 | SystemCoreClock = HSE_VALUE; 215 | break; 216 | case 0x08: /* PLL used as system clock source */ 217 | 218 | /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N 219 | SYSCLK = PLL_VCO / PLL_P 220 | */ 221 | pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22; 222 | pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM; 223 | 224 | if (pllsource != 0) 225 | { 226 | /* HSE used as PLL clock source */ 227 | pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); 228 | } 229 | else 230 | { 231 | /* HSI used as PLL clock source */ 232 | pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); 233 | } 234 | 235 | pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2; 236 | SystemCoreClock = pllvco/pllp; 237 | break; 238 | default: 239 | SystemCoreClock = HSI_VALUE; 240 | break; 241 | } 242 | /* Compute HCLK frequency --------------------------------------------------*/ 243 | /* Get HCLK prescaler */ 244 | tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; 245 | /* HCLK frequency */ 246 | SystemCoreClock >>= tmp; 247 | } 248 | 249 | /** 250 | * @} 251 | */ 252 | 253 | /** 254 | * @} 255 | */ 256 | 257 | /** 258 | * @} 259 | */ 260 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 261 | -------------------------------------------------------------------------------- /src/freertos/iMX8MM/Inc/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.4.3 LTS Patch 2 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef FREERTOS_CONFIG_H 28 | #define FREERTOS_CONFIG_H 29 | 30 | /*----------------------------------------------------------- 31 | * Application specific definitions. 32 | * 33 | * These definitions should be adjusted for your particular hardware and 34 | * application requirements. 35 | * 36 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 37 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 38 | * 39 | * See http://www.freertos.org/a00110.html. 40 | *----------------------------------------------------------*/ 41 | 42 | #define configUSE_PREEMPTION 1 43 | #define configUSE_TICKLESS_IDLE 0 44 | #define configCPU_CLOCK_HZ (SystemCoreClock) 45 | #define configTICK_RATE_HZ ((TickType_t)1000) 46 | #define configMAX_PRIORITIES 56 47 | #define configMINIMAL_STACK_SIZE ((unsigned short)128) 48 | #define configMAX_TASK_NAME_LEN 20 49 | #define configUSE_16_BIT_TICKS 0 50 | #define configIDLE_SHOULD_YIELD 1 51 | #define configUSE_TASK_NOTIFICATIONS 1 52 | #define configUSE_MUTEXES 1 53 | #define configUSE_RECURSIVE_MUTEXES 1 54 | #define configUSE_COUNTING_SEMAPHORES 1 55 | #define configUSE_ALTERNATIVE_API 0 /* Deprecated! */ 56 | #define configQUEUE_REGISTRY_SIZE 8 57 | #define configUSE_QUEUE_SETS 0 58 | #define configUSE_TIME_SLICING 0 59 | #define configUSE_NEWLIB_REENTRANT 0 60 | #define configENABLE_BACKWARD_COMPATIBILITY 0 61 | #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5 62 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 63 | 64 | /* Used memory allocation (heap_x.c) */ 65 | #define configFRTOS_MEMORY_SCHEME 3 66 | /* Tasks.c additions (e.g. Thread Aware Debug capability) */ 67 | #define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 1 68 | 69 | /* Memory allocation related definitions. */ 70 | #define configSUPPORT_STATIC_ALLOCATION 0 71 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 72 | #define configTOTAL_HEAP_SIZE ((size_t)(2000 * 1024)) 73 | #define configAPPLICATION_ALLOCATED_HEAP 0 74 | 75 | /* Hook function related definitions. */ 76 | #define configUSE_IDLE_HOOK 0 77 | #define configUSE_TICK_HOOK 0 78 | #define configCHECK_FOR_STACK_OVERFLOW 0 79 | #define configUSE_MALLOC_FAILED_HOOK 0 80 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 81 | 82 | /* Run time and task stats gathering related definitions. */ 83 | #define configGENERATE_RUN_TIME_STATS 0 84 | #define configUSE_TRACE_FACILITY 1 85 | #define configUSE_STATS_FORMATTING_FUNCTIONS 0 86 | 87 | /* Task aware debugging. */ 88 | #define configRECORD_STACK_HIGH_ADDRESS 1 89 | 90 | /* Co-routine related definitions. */ 91 | #define configUSE_CO_ROUTINES 0 92 | #define configMAX_CO_ROUTINE_PRIORITIES 2 93 | 94 | /* Software timer related definitions. */ 95 | #define configUSE_TIMERS 1 96 | #define configTIMER_TASK_PRIORITY ( 2 ) 97 | #define configTIMER_QUEUE_LENGTH 10 98 | #define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) 99 | 100 | /* Define to trap errors during development. */ 101 | #define configASSERT(x) if(( x) == 0) {taskDISABLE_INTERRUPTS(); for (;;);} 102 | 103 | /* Optional functions - most linkers will remove unused functions anyway. */ 104 | #define INCLUDE_vTaskPrioritySet 1 105 | #define INCLUDE_uxTaskPriorityGet 1 106 | #define INCLUDE_vTaskDelete 1 107 | #define INCLUDE_vTaskSuspend 1 108 | #define INCLUDE_vTaskDelayUntil 1 109 | #define INCLUDE_vTaskDelay 1 110 | #define INCLUDE_xTaskGetSchedulerState 1 111 | #define INCLUDE_xTaskGetCurrentTaskHandle 1 112 | #define INCLUDE_uxTaskGetStackHighWaterMark 0 113 | #define INCLUDE_xTaskGetIdleTaskHandle 0 114 | #define INCLUDE_eTaskGetState 0 115 | #define INCLUDE_xTimerPendFunctionCall 1 116 | #define INCLUDE_xTaskAbortDelay 0 117 | #define INCLUDE_xTaskGetHandle 0 118 | #define INCLUDE_xTaskResumeFromISR 1 119 | 120 | 121 | 122 | #if defined(__ICCARM__)||defined(__CC_ARM)||defined(__GNUC__) 123 | /* in Kinetis SDK, this contains the system core clock frequency */ 124 | #include 125 | extern uint32_t SystemCoreClock; 126 | #endif 127 | 128 | /* Interrupt nesting behaviour configuration. Cortex-M specific. */ 129 | #ifdef __NVIC_PRIO_BITS 130 | /* __NVIC_PRIO_BITS will be specified when CMSIS is being used. */ 131 | #define configPRIO_BITS __NVIC_PRIO_BITS 132 | #else 133 | #define configPRIO_BITS 4 /* 15 priority levels */ 134 | #endif 135 | 136 | /* The lowest interrupt priority that can be used in a call to a "set priority" 137 | function. */ 138 | #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ((1U << (configPRIO_BITS)) - 1U) 139 | 140 | /* The highest interrupt priority that can be used by any interrupt service 141 | routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL 142 | INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER 143 | PRIORITY THAN THIS! (higher priorities are lower numeric values. */ 144 | #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 2 145 | 146 | /* Interrupt priorities used by the kernel port layer itself. These are generic 147 | to all Cortex-M ports, and do not rely on any particular library functions. */ 148 | #define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) 149 | /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! 150 | See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ 151 | #define configMAX_SYSCALL_INTERRUPT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) 152 | 153 | /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS 154 | standard names. */ 155 | #define vPortSVCHandler SVC_Handler 156 | #define xPortPendSVHandler PendSV_Handler 157 | #define xPortSysTickHandler SysTick_Handler 158 | 159 | #endif /* FREERTOS_CONFIG_H */ 160 | -------------------------------------------------------------------------------- /src/freertos/iMX8MM/Inc/lwip_hooks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 NXP 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #ifndef LWIP_HOOKS_H 8 | #define LWIP_HOOKS_H 9 | 10 | err_enum_t lwip_hook_unknown_eth_protocol (struct pbuf * pbuf, struct netif * netif); 11 | 12 | #endif /* LWIP_HOOKS_H */ -------------------------------------------------------------------------------- /src/freertos/iMX8MM/Inc/lwipopts.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file lwipopts.h 4 | * This file is based on \src\include\lwip\opt.h 5 | ****************************************************************************** 6 | * Copyright (c) 2013-2016, Freescale Semiconductor, Inc. 7 | * Copyright 2016-2018, 2023 NXP 8 | * 9 | * SPDX-License-Identifier: BSD-3-Clause 10 | */ 11 | 12 | #ifndef __LWIPOPTS_H__ 13 | #define __LWIPOPTS_H__ 14 | /** 15 | * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain 16 | * critical regions during buffer allocation, deallocation and memory 17 | * allocation and deallocation. 18 | */ 19 | 20 | #define SYS_LIGHTWEIGHT_PROT 1 21 | #define LWIP_TIMERS 1 22 | #define LWIP_NETIF_HOSTNAME 1 23 | 24 | #define IP_SOF_BROADCAST 0 25 | #define IP_SOF_BROADCAST_RECV 0 26 | #define LWIP_BROADCAST_PING 0 27 | #define LWIP_MULTICAST_PING 0 28 | 29 | /** 30 | * NO_SYS==0: Use RTOS 31 | */ 32 | #define NO_SYS 0 33 | 34 | #define LWIP_RAW 0 35 | /** 36 | * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c) 37 | */ 38 | #define LWIP_NETCONN 1 39 | /** 40 | * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) 41 | */ 42 | #define LWIP_SOCKET 1 43 | 44 | /** 45 | * LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and 46 | * SO_RCVTIMEO processing. 47 | */ 48 | #define LWIP_SO_RCVTIMEO 1 49 | 50 | /* ---------- Core locking ---------- */ 51 | 52 | #define LWIP_TCPIP_CORE_LOCKING 1 53 | 54 | void sys_lock_tcpip_core(void); 55 | #define LOCK_TCPIP_CORE() sys_lock_tcpip_core() 56 | 57 | void sys_unlock_tcpip_core(void); 58 | #define UNLOCK_TCPIP_CORE() sys_unlock_tcpip_core() 59 | 60 | void sys_check_core_locking(void); 61 | #define LWIP_ASSERT_CORE_LOCKED() sys_check_core_locking() 62 | 63 | void sys_mark_tcpip_thread(void); 64 | #define LWIP_MARK_TCPIP_THREAD() sys_mark_tcpip_thread() 65 | 66 | /* ---------- Memory options ---------- */ 67 | /** 68 | * MEM_ALIGNMENT: should be set to the alignment of the CPU 69 | * 4 byte alignment -> #define MEM_ALIGNMENT 4 70 | * 2 byte alignment -> #define MEM_ALIGNMENT 2 71 | */ 72 | #ifndef MEM_ALIGNMENT 73 | #define MEM_ALIGNMENT 4 74 | #endif 75 | 76 | /** 77 | * MEM_SIZE: the size of the heap memory. If the application will send 78 | * a lot of data that needs to be copied, this should be set high. 79 | */ 80 | #ifndef MEM_SIZE 81 | #define MEM_SIZE (22 * 1024) 82 | #endif 83 | 84 | /* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application 85 | sends a lot of data out of ROM (or other static memory), this 86 | should be set high. */ 87 | #ifndef MEMP_NUM_PBUF 88 | #define MEMP_NUM_PBUF 15 89 | #endif 90 | /* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One 91 | per active UDP "connection". */ 92 | #ifndef MEMP_NUM_UDP_PCB 93 | #define MEMP_NUM_UDP_PCB 6 94 | #endif 95 | /* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP 96 | connections. */ 97 | #ifndef MEMP_NUM_TCP_PCB 98 | #define MEMP_NUM_TCP_PCB 10 99 | #endif 100 | /* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP 101 | connections. */ 102 | #ifndef MEMP_NUM_TCP_PCB_LISTEN 103 | #define MEMP_NUM_TCP_PCB_LISTEN 6 104 | #endif 105 | /* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP 106 | segments. */ 107 | #ifndef MEMP_NUM_TCP_SEG 108 | #define MEMP_NUM_TCP_SEG 22 109 | #endif 110 | /* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active 111 | timeouts. */ 112 | #ifndef MEMP_NUM_SYS_TIMEOUT 113 | #define MEMP_NUM_SYS_TIMEOUT 10 114 | #endif 115 | 116 | /* ---------- Pbuf options ---------- */ 117 | /* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ 118 | #ifndef PBUF_POOL_SIZE 119 | #define PBUF_POOL_SIZE 16 120 | #endif 121 | 122 | /* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */ 123 | /* Default value is defined in lwip\src\include\lwip\opt.h as 124 | * LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)*/ 125 | 126 | /* ---------- TCP options ---------- */ 127 | #ifndef LWIP_TCP 128 | #define LWIP_TCP 1 129 | #endif 130 | 131 | #ifndef TCP_TTL 132 | #define TCP_TTL 255 133 | #endif 134 | 135 | /* Controls if TCP should queue segments that arrive out of 136 | order. Define to 0 if your device is low on memory. */ 137 | #ifndef TCP_QUEUE_OOSEQ 138 | #define TCP_QUEUE_OOSEQ 1 139 | #endif 140 | 141 | /* TCP Maximum segment size. */ 142 | #ifndef TCP_MSS 143 | #define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */ 144 | #endif 145 | 146 | /* TCP sender buffer space (bytes). */ 147 | #ifndef TCP_SND_BUF 148 | #define TCP_SND_BUF (6 * TCP_MSS) // 2 149 | #endif 150 | 151 | /* TCP sender buffer space (pbufs). This must be at least = 2 * 152 | TCP_SND_BUF/TCP_MSS for things to work. */ 153 | #ifndef TCP_SND_QUEUELEN 154 | #define TCP_SND_QUEUELEN (3 * TCP_SND_BUF) / TCP_MSS // 6 155 | #endif 156 | 157 | /* TCP receive window. */ 158 | #ifndef TCP_WND 159 | #define TCP_WND (2 * TCP_MSS) 160 | #endif 161 | 162 | /* Enable backlog*/ 163 | #ifndef TCP_LISTEN_BACKLOG 164 | #define TCP_LISTEN_BACKLOG 1 165 | #endif 166 | 167 | /* ---------- Network Interfaces options ---------- */ 168 | /* Support netif api (in netifapi.c). */ 169 | #ifndef LWIP_NETIF_API 170 | #define LWIP_NETIF_API 1 171 | #endif 172 | 173 | /* ---------- ICMP options ---------- */ 174 | #ifndef LWIP_ICMP 175 | #define LWIP_ICMP 1 176 | #endif 177 | 178 | /* ---------- DHCP options ---------- */ 179 | /* Enable DHCP module. */ 180 | #ifndef LWIP_DHCP 181 | #define LWIP_DHCP 1 182 | #endif 183 | 184 | /* ---------- UDP options ---------- */ 185 | #ifndef LWIP_UDP 186 | #define LWIP_UDP 1 187 | #endif 188 | #ifndef UDP_TTL 189 | #define UDP_TTL 255 190 | #endif 191 | 192 | /* ---------- Statistics options ---------- */ 193 | #ifndef LWIP_STATS 194 | #define LWIP_STATS 1 195 | #endif 196 | #ifndef LWIP_PROVIDE_ERRNO 197 | #define LWIP_PROVIDE_ERRNO 1 198 | #endif 199 | 200 | #define LWIP_IPV6 0 201 | 202 | 203 | #define MIB2_STATS 1 204 | 205 | /** 206 | * DEFAULT_THREAD_STACKSIZE: The stack size used by any other lwIP thread. 207 | * The stack size value itself is platform-dependent, but is passed to 208 | * sys_thread_new() when the thread is created. 209 | */ 210 | #ifndef DEFAULT_THREAD_STACKSIZE 211 | #define DEFAULT_THREAD_STACKSIZE 1024 212 | #endif 213 | 214 | /** 215 | * DEFAULT_THREAD_PRIO: The priority assigned to any other lwIP thread. 216 | * The priority value itself is platform-dependent, but is passed to 217 | * sys_thread_new() when the thread is created. 218 | */ 219 | #ifndef DEFAULT_THREAD_PRIO 220 | #define DEFAULT_THREAD_PRIO 3 221 | #endif 222 | 223 | /* 224 | ------------------------------------ 225 | ---------- Debugging options ---------- 226 | ------------------------------------ 227 | */ 228 | 229 | #define TCPIP_MBOX_SIZE 6 230 | #define TCPIP_THREAD_STACKSIZE 4096 231 | #define TCPIP_THREAD_PRIO configMAX_PRIORITIES - 1 232 | 233 | /** 234 | * DEFAULT_RAW_RECVMBOX_SIZE: The mailbox size for the incoming packets on a 235 | * NETCONN_RAW. The queue size value itself is platform-dependent, but is passed 236 | * to sys_mbox_new() when the recvmbox is created. 237 | */ 238 | #define DEFAULT_RAW_RECVMBOX_SIZE 6 239 | 240 | /** 241 | * DEFAULT_UDP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a 242 | * NETCONN_UDP. The queue size value itself is platform-dependent, but is passed 243 | * to sys_mbox_new() when the recvmbox is created. 244 | */ 245 | #define DEFAULT_UDP_RECVMBOX_SIZE 6 246 | 247 | /** 248 | * DEFAULT_TCP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a 249 | * NETCONN_TCP. The queue size value itself is platform-dependent, but is passed 250 | * to sys_mbox_new() when the recvmbox is created. 251 | */ 252 | #define DEFAULT_TCP_RECVMBOX_SIZE 6 253 | 254 | /** 255 | * DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections. 256 | * The queue size value itself is platform-dependent, but is passed to 257 | * sys_mbox_new() when the acceptmbox is created. 258 | */ 259 | #define DEFAULT_ACCEPTMBOX_SIZE 6 260 | 261 | #define SO_REUSE 1 262 | 263 | /* -------------------------------------- 264 | ---------- Checksum options ---------- 265 | -------------------------------------- 266 | */ 267 | 268 | /* 269 | Some MCU allow computing and verifying the IP, UDP, TCP and ICMP checksums by hardware: 270 | - To use this feature let the following define uncommented. 271 | - To disable it and process by CPU comment the the checksum. 272 | */ 273 | //#define CHECKSUM_BY_HARDWARE 274 | 275 | #ifdef CHECKSUM_BY_HARDWARE 276 | /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/ 277 | #define CHECKSUM_GEN_IP 0 278 | /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/ 279 | #define CHECKSUM_GEN_UDP 0 280 | /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/ 281 | #define CHECKSUM_GEN_TCP 0 282 | /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/ 283 | #define CHECKSUM_CHECK_IP 0 284 | /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/ 285 | #define CHECKSUM_CHECK_UDP 0 286 | /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/ 287 | #define CHECKSUM_CHECK_TCP 0 288 | #else 289 | /* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/ 290 | #define CHECKSUM_GEN_IP 1 291 | /* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/ 292 | #define CHECKSUM_GEN_UDP 1 293 | /* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/ 294 | #define CHECKSUM_GEN_TCP 1 295 | /* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/ 296 | #define CHECKSUM_CHECK_IP 1 297 | /* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/ 298 | #define CHECKSUM_CHECK_UDP 1 299 | /* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/ 300 | #define CHECKSUM_CHECK_TCP 1 301 | #endif 302 | 303 | 304 | #define LWIP_HOOK_FILENAME "lwip_hooks.h" 305 | #define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL lwip_hook_unknown_eth_protocol 306 | 307 | #if (LWIP_DNS || LWIP_IGMP || LWIP_IPV6) && !defined(LWIP_RAND) 308 | /* When using IGMP or IPv6, LWIP_RAND() needs to be defined to a random-function returning an u32_t random value*/ 309 | #include "lwip/arch.h" 310 | u32_t lwip_rand(void); 311 | #define LWIP_RAND() lwip_rand() 312 | #endif 313 | 314 | #endif /* __LWIPOPTS_H__ */ 315 | 316 | /*****END OF FILE****/ -------------------------------------------------------------------------------- /src/freertos/iMX8MM/Inc/pin_mux.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 NXP 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #ifndef _PIN_MUX_H_ 8 | #define _PIN_MUX_H_ 9 | 10 | #include "board.h" 11 | 12 | #if defined(__cplusplus) 13 | extern "C" { 14 | #endif 15 | 16 | void BOARD_InitBootPins(void); 17 | 18 | void BOARD_InitPins(void); 19 | 20 | #if defined(__cplusplus) 21 | } 22 | #endif 23 | 24 | #endif /* _PIN_MUX_H_ */ 25 | 26 | -------------------------------------------------------------------------------- /src/freertos/iMX8MM/MIMX8MM6xxxxx_cm4_ddr_ram.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ** ################################################################### 3 | ** Processors: MIMX8MM6CVTKZ 4 | ** MIMX8MM6DVTLZ 5 | ** 6 | ** Compiler: GNU C Compiler 7 | ** Reference manual: MX8MMRM, Rev. 0, 02/2019 8 | ** Version: rev. 4.0, 2019-02-18 9 | ** Build: b200330 10 | ** 11 | ** Abstract: 12 | ** Linker file for the GNU C Compiler 13 | ** 14 | ** Copyright 2016 Freescale Semiconductor, Inc. 15 | ** Copyright 2016-2020, 2023 NXP 16 | ** All rights reserved. 17 | ** 18 | ** SPDX-License-Identifier: BSD-3-Clause 19 | ** 20 | ** http: www.nxp.com 21 | ** mail: support@nxp.com 22 | ** 23 | ** ################################################################### 24 | */ 25 | 26 | /* Entry Point */ 27 | ENTRY(Reset_Handler) 28 | 29 | HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 1000*1024; 30 | STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 60*1024; 31 | 32 | /* Specify the memory areas */ 33 | MEMORY 34 | { 35 | m_interrupts (RX) : ORIGIN = 0x80000000, LENGTH = 0x00000240 36 | m_text (RX) : ORIGIN = 0x80000240, LENGTH = 0x001FFDC0 37 | m_data (RW) : ORIGIN = 0x80200000, LENGTH = 0x00200000 38 | m_data2 (RW) : ORIGIN = 0x80400000, LENGTH = 0x00005200 39 | } 40 | 41 | /* Define output sections */ 42 | SECTIONS 43 | { 44 | /* The startup code goes first into internal RAM */ 45 | .interrupts : 46 | { 47 | __VECTOR_TABLE = .; 48 | __Vectors = .; 49 | . = ALIGN(4); 50 | KEEP(*(.isr_vector)) /* Startup code */ 51 | . = ALIGN(4); 52 | } > m_interrupts 53 | 54 | .resource_table : 55 | { 56 | . = ALIGN(8); 57 | KEEP(*(.resource_table)) /* Resource table */ 58 | . = ALIGN(8); 59 | } > m_text 60 | 61 | /* The program code and other data goes into internal RAM */ 62 | .text : 63 | { 64 | . = ALIGN(4); 65 | *(.text) /* .text sections (code) */ 66 | *(.text*) /* .text* sections (code) */ 67 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 68 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 69 | *(.glue_7) /* glue arm to thumb code */ 70 | *(.glue_7t) /* glue thumb to arm code */ 71 | *(.eh_frame) 72 | KEEP (*(.init)) 73 | KEEP (*(.fini)) 74 | . = ALIGN(4); 75 | } > m_text 76 | 77 | .ARM.extab : 78 | { 79 | *(.ARM.extab* .gnu.linkonce.armextab.*) 80 | } > m_text 81 | 82 | .ARM : 83 | { 84 | __exidx_start = .; 85 | *(.ARM.exidx*) 86 | __exidx_end = .; 87 | } > m_text 88 | 89 | .ctors : 90 | { 91 | __CTOR_LIST__ = .; 92 | /* gcc uses crtbegin.o to find the start of 93 | the constructors, so we make sure it is 94 | first. Because this is a wildcard, it 95 | doesn't matter if the user does not 96 | actually link against crtbegin.o; the 97 | linker won't look for a file to match a 98 | wildcard. The wildcard also means that it 99 | doesn't matter which directory crtbegin.o 100 | is in. */ 101 | KEEP (*crtbegin.o(.ctors)) 102 | KEEP (*crtbegin?.o(.ctors)) 103 | /* We don't want to include the .ctor section from 104 | from the crtend.o file until after the sorted ctors. 105 | The .ctor section from the crtend file contains the 106 | end of ctors marker and it must be last */ 107 | KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)) 108 | KEEP (*(SORT(.ctors.*))) 109 | KEEP (*(.ctors)) 110 | __CTOR_END__ = .; 111 | } > m_text 112 | 113 | .dtors : 114 | { 115 | __DTOR_LIST__ = .; 116 | KEEP (*crtbegin.o(.dtors)) 117 | KEEP (*crtbegin?.o(.dtors)) 118 | KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)) 119 | KEEP (*(SORT(.dtors.*))) 120 | KEEP (*(.dtors)) 121 | __DTOR_END__ = .; 122 | } > m_text 123 | 124 | .preinit_array : 125 | { 126 | PROVIDE_HIDDEN (__preinit_array_start = .); 127 | KEEP (*(.preinit_array*)) 128 | PROVIDE_HIDDEN (__preinit_array_end = .); 129 | } > m_text 130 | 131 | .init_array : 132 | { 133 | PROVIDE_HIDDEN (__init_array_start = .); 134 | KEEP (*(SORT(.init_array.*))) 135 | KEEP (*(.init_array*)) 136 | PROVIDE_HIDDEN (__init_array_end = .); 137 | } > m_text 138 | 139 | .fini_array : 140 | { 141 | PROVIDE_HIDDEN (__fini_array_start = .); 142 | KEEP (*(SORT(.fini_array.*))) 143 | KEEP (*(.fini_array*)) 144 | PROVIDE_HIDDEN (__fini_array_end = .); 145 | } > m_text 146 | 147 | __etext = .; /* define a global symbol at end of code */ 148 | __DATA_ROM = .; /* Symbol is used by startup for data initialization */ 149 | 150 | .data : AT(__DATA_ROM) 151 | { 152 | . = ALIGN(4); 153 | __DATA_RAM = .; 154 | __data_start__ = .; /* create a global symbol at data start */ 155 | *(.data) /* .data sections */ 156 | *(.data*) /* .data* sections */ 157 | KEEP(*(.jcr*)) 158 | . = ALIGN(4); 159 | __data_end__ = .; /* define a global symbol at data end */ 160 | } > m_data 161 | 162 | __CACHE_REGION_START = ORIGIN(m_interrupts); 163 | __CACHE_REGION_SIZE = LENGTH(m_interrupts) + LENGTH(m_text) + LENGTH(m_data); 164 | 165 | __NDATA_ROM = __DATA_ROM + SIZEOF(.data); /* Symbol is used by startup for ncache data initialization */ 166 | 167 | .ncache.init : AT(__NDATA_ROM) 168 | { 169 | __noncachedata_start__ = .; /* create a global symbol at ncache data start */ 170 | *(NonCacheable.init) 171 | . = ALIGN(4); 172 | __noncachedata_init_end__ = .; /* create a global symbol at initialized ncache data end */ 173 | } > m_data2 174 | 175 | . = __noncachedata_init_end__; 176 | .ncache : 177 | { 178 | *(NonCacheable) 179 | . = ALIGN(4); 180 | __noncachedata_end__ = .; /* define a global symbol at ncache data end */ 181 | } > m_data2 182 | 183 | __DATA_END = __DATA_ROM + (__data_end__ - __data_start__); 184 | text_end = ORIGIN(m_text) + LENGTH(m_text); 185 | ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data") 186 | 187 | /* Uninitialized data section */ 188 | .bss : 189 | { 190 | /* This is used by the startup in order to initialize the .bss section */ 191 | . = ALIGN(4); 192 | __START_BSS = .; 193 | __bss_start__ = .; 194 | *(.bss) 195 | *(.bss*) 196 | *(COMMON) 197 | . = ALIGN(4); 198 | __bss_end__ = .; 199 | __END_BSS = .; 200 | } > m_data 201 | 202 | .heap : 203 | { 204 | . = ALIGN(8); 205 | __end__ = .; 206 | PROVIDE(end = .); 207 | __HeapBase = .; 208 | . += HEAP_SIZE; 209 | __HeapLimit = .; 210 | __heap_limit = .; /* Add for _sbrk */ 211 | } > m_data 212 | 213 | .stack : 214 | { 215 | . = ALIGN(8); 216 | . += STACK_SIZE; 217 | } > m_data 218 | 219 | /* Initializes stack on the end of block */ 220 | __StackTop = ORIGIN(m_data) + LENGTH(m_data); 221 | __StackLimit = __StackTop - STACK_SIZE; 222 | PROVIDE(__stack = __StackTop); 223 | 224 | .ARM.attributes 0 : { *(.ARM.attributes) } 225 | 226 | ASSERT(__StackLimit >= __HeapLimit, "region m_data overflowed with stack and heap") 227 | } 228 | 229 | -------------------------------------------------------------------------------- /src/freertos/iMX8MM/Src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 NXP 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include "pin_mux.h" 8 | #include "fsl_gpio.h" 9 | #include "board.h" 10 | 11 | #include 12 | #include 13 | 14 | #include "enet_ethernetif.h" 15 | #include "lwip/netifapi.h" 16 | #include "lwip/tcpip.h" 17 | #include "lwip/ip4_addr.h" 18 | 19 | #include "fsl_enet_mdio.h" 20 | #include "fsl_phyar8031.h" 21 | 22 | #define PHY_ADDRESS 0x00u 23 | #define ENET_CLOCK_FREQ 250000000 24 | 25 | #define EXAMPLE_CLOCK_FREQ CLOCK_GetFreq(kCLOCK_IpgClk) 26 | 27 | #define EXAMPLE_PHY_INTERFACE_RGMII 28 | #ifndef PHY_AUTONEGO_TIMEOUT_COUNT 29 | #define PHY_AUTONEGO_TIMEOUT_COUNT (100000) 30 | #endif 31 | #ifndef PHY_STABILITY_DELAY_US 32 | #define PHY_STABILITY_DELAY_US (0U) 33 | #endif 34 | 35 | /*! @brief Stack size of the temporary lwIP initialization thread. */ 36 | #define INIT_THREAD_STACKSIZE 1024 37 | 38 | /*! @brief Priority of the temporary lwIP initialization thread. */ 39 | #define INIT_THREAD_PRIO DEFAULT_THREAD_PRIO 40 | 41 | /* MDIO operations. */ 42 | #define EXAMPLE_MDIO_OPS enet_ops 43 | /* PHY operations. */ 44 | #define EXAMPLE_PHY_OPS phyar8031_ops 45 | 46 | #ifndef EXAMPLE_NETIF_INIT_FN 47 | /*! @brief Network interface initialization function. */ 48 | #define EXAMPLE_NETIF_INIT_FN ethernetif0_init 49 | #endif /* EXAMPLE_NETIF_INIT_FN */ 50 | 51 | /* IP address configuration. */ 52 | #ifndef configIP_ADDR0 53 | #define configIP_ADDR0 192 54 | #endif 55 | #ifndef configIP_ADDR1 56 | #define configIP_ADDR1 168 57 | #endif 58 | #ifndef configIP_ADDR2 59 | #define configIP_ADDR2 11 60 | #endif 61 | #ifndef configIP_ADDR3 62 | #define configIP_ADDR3 3 63 | #endif 64 | 65 | /* Netmask configuration. */ 66 | #ifndef configNET_MASK0 67 | #define configNET_MASK0 255 68 | #endif 69 | #ifndef configNET_MASK1 70 | #define configNET_MASK1 255 71 | #endif 72 | #ifndef configNET_MASK2 73 | #define configNET_MASK2 255 74 | #endif 75 | #ifndef configNET_MASK3 76 | #define configNET_MASK3 0 77 | #endif 78 | 79 | /* Gateway address configuration. */ 80 | #ifndef configGW_ADDR0 81 | #define configGW_ADDR0 192 82 | #endif 83 | #ifndef configGW_ADDR1 84 | #define configGW_ADDR1 168 85 | #endif 86 | #ifndef configGW_ADDR2 87 | #define configGW_ADDR2 11 88 | #endif 89 | #ifndef configGW_ADDR3 90 | #define configGW_ADDR3 1 91 | #endif 92 | 93 | /* MAC address configuration. */ 94 | #define configMAC_ADDR \ 95 | { \ 96 | 0x00, 0x04, 0x9F, 0x05, 0xCF, 0xFC \ 97 | } 98 | 99 | static mdio_handle_t mdioHandle = {.ops = &EXAMPLE_MDIO_OPS}; 100 | static phy_handle_t phyHandle = {.phyAddr = PHY_ADDRESS, .mdioHandle = &mdioHandle, .ops = &EXAMPLE_PHY_OPS}; 101 | 102 | struct netif netif_mini; 103 | 104 | __attribute ((weak)) int _main () 105 | { 106 | printf ("Hello, world\n"); 107 | return 0; 108 | } 109 | 110 | static void stack_init(void *arg) 111 | { 112 | ip4_addr_t netif_ipaddr; 113 | ip4_addr_t netif_netmask; 114 | ip4_addr_t netif_gw; 115 | 116 | ethernetif_config_t enet_config = { 117 | .phyHandle = &phyHandle, 118 | .macAddress = configMAC_ADDR, 119 | }; 120 | 121 | mdioHandle.resource.csrClock_Hz = ENET_CLOCK_FREQ; 122 | 123 | IP4_ADDR(&netif_ipaddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3); 124 | IP4_ADDR(&netif_netmask, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3); 125 | IP4_ADDR(&netif_gw, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3); 126 | 127 | tcpip_init(NULL, NULL); 128 | netifapi_netif_add(&netif_mini, &netif_ipaddr, &netif_netmask, &netif_gw, &enet_config, EXAMPLE_NETIF_INIT_FN, 129 | &tcpip_input); 130 | 131 | netifapi_netif_set_default(&netif_mini); 132 | netifapi_netif_set_up(&netif_mini); 133 | 134 | _main (); 135 | 136 | /* Hang here if _main returns */ 137 | for(;;) 138 | { 139 | } 140 | } 141 | 142 | int main(void) 143 | { 144 | /* Hardware Initialization. */ 145 | BOARD_InitMemory(); 146 | BOARD_RdcInit(); 147 | BOARD_InitPins(); 148 | BOARD_BootClockRUN(); 149 | BOARD_InitDebugConsole(); 150 | 151 | CLOCK_SetRootDivider(kCLOCK_RootEnetAxi, 1U, 1U); 152 | CLOCK_SetRootMux(kCLOCK_RootEnetAxi, kCLOCK_EnetAxiRootmuxSysPll2Div4); /* SYSTEM PLL2 divided by 4: 250Mhz */ 153 | 154 | /* Time stamp clock */ 155 | CLOCK_SetRootDivider(kCLOCK_RootEnetTimer, 1U, 1U); 156 | CLOCK_SetRootMux(kCLOCK_RootEnetTimer, kCLOCK_EnetTimerRootmuxSysPll2Div10); /* SYSTEM PLL2 divided by 10: 100Mhz */ 157 | 158 | /* mii/rgmii interface clock */ 159 | CLOCK_SetRootDivider(kCLOCK_RootEnetRef, 1U, 1U); 160 | CLOCK_SetRootMux(kCLOCK_RootEnetRef, kCLOCK_EnetRefRootmuxSysPll2Div8); /* SYSTEM PLL2 divided by 8: 125MHz */ 161 | 162 | gpio_pin_config_t gpio_reset_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode}; 163 | gpio_pin_config_t gpio_led1_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode}; 164 | gpio_pin_config_t gpio_led2_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode}; 165 | gpio_pin_config_t gpio_button_config = {kGPIO_DigitalInput, 0, kGPIO_NoIntmode}; 166 | 167 | /* Data LED pin */ 168 | GPIO_PinInit(GPIO5, 13, &gpio_led1_config); 169 | /* Signal LED pin */ 170 | GPIO_PinInit(GPIO5, 10, &gpio_led2_config); 171 | /* Botton pin */ 172 | GPIO_PinInit(GPIO5, 12, &gpio_button_config); 173 | /* PHY reset pin */ 174 | GPIO_PinInit(GPIO4, 22, &gpio_reset_config); 175 | 176 | /* PHY reset */ 177 | GPIO_WritePinOutput(GPIO4, 22, 0); 178 | SDK_DelayAtLeastUs(10000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY); 179 | GPIO_WritePinOutput(GPIO4, 22, 1); 180 | SDK_DelayAtLeastUs(30000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY); 181 | 182 | EnableIRQ(ENET_MAC0_Rx_Tx_Done1_IRQn); 183 | EnableIRQ(ENET_MAC0_Rx_Tx_Done2_IRQn); 184 | 185 | /* Initialize lwIP from thread */ 186 | if (sys_thread_new("main", stack_init, NULL, INIT_THREAD_STACKSIZE, INIT_THREAD_PRIO) == NULL) 187 | { 188 | LWIP_ASSERT("main(): Task creation failed.", 0); 189 | } 190 | 191 | vTaskStartScheduler(); 192 | 193 | return 0; 194 | } 195 | -------------------------------------------------------------------------------- /src/freertos/iMX8MM/Src/pin_mux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2023 NXP 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include "fsl_common.h" 8 | #include "fsl_iomuxc.h" 9 | #include "pin_mux.h" 10 | 11 | void BOARD_InitBootPins(void) 12 | { 13 | BOARD_InitPins(); 14 | } 15 | 16 | void BOARD_InitPins(void) { 17 | /* Button pin */ 18 | IOMUXC_SetPinMux(IOMUXC_ECSPI2_MISO_GPIO5_IO12, 5U); 19 | IOMUXC_SetPinConfig(IOMUXC_ECSPI2_MISO_GPIO5_IO12, 20 | IOMUXC_SW_PAD_CTL_PAD_DSE(3U) | 21 | IOMUXC_SW_PAD_CTL_PAD_FSEL(1U) | 22 | IOMUXC_SW_PAD_CTL_PAD_PUE(0U) | 23 | IOMUXC_SW_PAD_CTL_PAD_PE(1U)); 24 | /* Data LED pin */ 25 | IOMUXC_SetPinMux(IOMUXC_ECSPI2_SS0_GPIO5_IO13, 5U); 26 | IOMUXC_SetPinConfig(IOMUXC_ECSPI2_SS0_GPIO5_IO13, 27 | IOMUXC_SW_PAD_CTL_PAD_DSE(6U) | 28 | IOMUXC_SW_PAD_CTL_PAD_FSEL(2U) | 29 | IOMUXC_SW_PAD_CTL_PAD_PUE(0U) | 30 | IOMUXC_SW_PAD_CTL_PAD_PE(1U)); 31 | 32 | /* Signal LED pin */ 33 | IOMUXC_SetPinMux(IOMUXC_ECSPI2_SCLK_GPIO5_IO10, 5U); 34 | IOMUXC_SetPinConfig(IOMUXC_ECSPI2_SCLK_GPIO5_IO10, 35 | IOMUXC_SW_PAD_CTL_PAD_DSE(6U) | 36 | IOMUXC_SW_PAD_CTL_PAD_FSEL(2U) | 37 | IOMUXC_SW_PAD_CTL_PAD_PUE(0U) | 38 | IOMUXC_SW_PAD_CTL_PAD_PE(1U)); 39 | 40 | /* UART pins */ 41 | IOMUXC_SetPinMux(IOMUXC_UART4_RXD_UART4_RX, 0U); 42 | IOMUXC_SetPinConfig(IOMUXC_UART4_RXD_UART4_RX, 43 | IOMUXC_SW_PAD_CTL_PAD_DSE(6U) | 44 | IOMUXC_SW_PAD_CTL_PAD_FSEL(2U)); 45 | IOMUXC_SetPinMux(IOMUXC_UART4_TXD_UART4_TX, 0U); 46 | IOMUXC_SetPinConfig(IOMUXC_UART4_TXD_UART4_TX, 47 | IOMUXC_SW_PAD_CTL_PAD_DSE(6U) | 48 | IOMUXC_SW_PAD_CTL_PAD_FSEL(2U)); 49 | 50 | /* ENET pins */ 51 | IOMUXC_SetPinMux(IOMUXC_ENET_MDIO_ENET1_MDIO, 0U); 52 | IOMUXC_SetPinConfig(IOMUXC_ENET_MDIO_ENET1_MDIO, 53 | IOMUXC_SW_PAD_CTL_PAD_DSE(3U)); 54 | IOMUXC_SetPinMux(IOMUXC_ENET_MDC_ENET1_MDC, 0U); 55 | IOMUXC_SetPinConfig(IOMUXC_ENET_MDC_ENET1_MDC, 56 | IOMUXC_SW_PAD_CTL_PAD_DSE(3U)); 57 | 58 | IOMUXC_SetPinMux(IOMUXC_ENET_TD3_ENET1_RGMII_TD3, 0U); 59 | IOMUXC_SetPinConfig(IOMUXC_ENET_TD3_ENET1_RGMII_TD3, 60 | IOMUXC_SW_PAD_CTL_PAD_DSE(7U) | 61 | IOMUXC_SW_PAD_CTL_PAD_FSEL(3U)); 62 | IOMUXC_SetPinMux(IOMUXC_ENET_TD2_ENET1_RGMII_TD2, 0U); 63 | IOMUXC_SetPinConfig(IOMUXC_ENET_TD2_ENET1_RGMII_TD2, 64 | IOMUXC_SW_PAD_CTL_PAD_DSE(7U) | 65 | IOMUXC_SW_PAD_CTL_PAD_FSEL(3U)); 66 | IOMUXC_SetPinMux(IOMUXC_ENET_TD1_ENET1_RGMII_TD1, 0U); 67 | IOMUXC_SetPinConfig(IOMUXC_ENET_TD1_ENET1_RGMII_TD1, 68 | IOMUXC_SW_PAD_CTL_PAD_DSE(7U) | 69 | IOMUXC_SW_PAD_CTL_PAD_FSEL(3U)); 70 | IOMUXC_SetPinMux(IOMUXC_ENET_TD0_ENET1_RGMII_TD0, 0U); 71 | IOMUXC_SetPinConfig(IOMUXC_ENET_TD0_ENET1_RGMII_TD0, 72 | IOMUXC_SW_PAD_CTL_PAD_DSE(7U) | 73 | IOMUXC_SW_PAD_CTL_PAD_FSEL(3U)); 74 | 75 | IOMUXC_SetPinMux(IOMUXC_ENET_RD3_ENET1_RGMII_RD3, 0U); 76 | IOMUXC_SetPinConfig(IOMUXC_ENET_RD3_ENET1_RGMII_RD3, 77 | IOMUXC_SW_PAD_CTL_PAD_DSE(1U) | 78 | IOMUXC_SW_PAD_CTL_PAD_FSEL(2U) | 79 | IOMUXC_SW_PAD_CTL_PAD_HYS(1U)); 80 | IOMUXC_SetPinMux(IOMUXC_ENET_RD2_ENET1_RGMII_RD2, 0U); 81 | IOMUXC_SetPinConfig(IOMUXC_ENET_RD2_ENET1_RGMII_RD2, 82 | IOMUXC_SW_PAD_CTL_PAD_DSE(1U) | 83 | IOMUXC_SW_PAD_CTL_PAD_FSEL(2U) | 84 | IOMUXC_SW_PAD_CTL_PAD_HYS(1U)); 85 | IOMUXC_SetPinMux(IOMUXC_ENET_RD1_ENET1_RGMII_RD1, 0U); 86 | IOMUXC_SetPinConfig(IOMUXC_ENET_RD1_ENET1_RGMII_RD1, 87 | IOMUXC_SW_PAD_CTL_PAD_DSE(1U) | 88 | IOMUXC_SW_PAD_CTL_PAD_FSEL(2U) | 89 | IOMUXC_SW_PAD_CTL_PAD_HYS(1U)); 90 | IOMUXC_SetPinMux(IOMUXC_ENET_RD0_ENET1_RGMII_RD0, 0U); 91 | IOMUXC_SetPinConfig(IOMUXC_ENET_RD0_ENET1_RGMII_RD0, 92 | IOMUXC_SW_PAD_CTL_PAD_DSE(1U) | 93 | IOMUXC_SW_PAD_CTL_PAD_FSEL(2U) | 94 | IOMUXC_SW_PAD_CTL_PAD_HYS(1U)); 95 | 96 | IOMUXC_SetPinMux(IOMUXC_ENET_TXC_ENET1_RGMII_TXC, 0U); 97 | IOMUXC_SetPinConfig(IOMUXC_ENET_TXC_ENET1_RGMII_TXC, 98 | IOMUXC_SW_PAD_CTL_PAD_DSE(7U) | 99 | IOMUXC_SW_PAD_CTL_PAD_FSEL(3U)); 100 | IOMUXC_SetPinMux(IOMUXC_ENET_RXC_ENET1_RGMII_RXC, 0U); 101 | IOMUXC_SetPinConfig(IOMUXC_ENET_RXC_ENET1_RGMII_RXC, 102 | IOMUXC_SW_PAD_CTL_PAD_DSE(1U) | 103 | IOMUXC_SW_PAD_CTL_PAD_FSEL(2U) | 104 | IOMUXC_SW_PAD_CTL_PAD_HYS(1U)); 105 | 106 | IOMUXC_SetPinMux(IOMUXC_ENET_RX_CTL_ENET1_RGMII_RX_CTL, 0U); 107 | IOMUXC_SetPinConfig(IOMUXC_ENET_RX_CTL_ENET1_RGMII_RX_CTL, 108 | IOMUXC_SW_PAD_CTL_PAD_DSE(1U) | 109 | IOMUXC_SW_PAD_CTL_PAD_FSEL(2U) | 110 | IOMUXC_SW_PAD_CTL_PAD_HYS(1U)); 111 | IOMUXC_SetPinMux(IOMUXC_ENET_TX_CTL_ENET1_RGMII_TX_CTL, 0U); 112 | IOMUXC_SetPinConfig(IOMUXC_ENET_TX_CTL_ENET1_RGMII_TX_CTL, 113 | IOMUXC_SW_PAD_CTL_PAD_DSE(7U) | 114 | IOMUXC_SW_PAD_CTL_PAD_FSEL(3U)); 115 | 116 | /* ENET PHY reset pin */ 117 | IOMUXC_SetPinMux(IOMUXC_SAI2_RXC_GPIO4_IO22, 5U); 118 | IOMUXC_SetPinConfig(IOMUXC_SAI2_RXC_GPIO4_IO22, 119 | IOMUXC_SW_PAD_CTL_PAD_DSE(1U) | 120 | IOMUXC_SW_PAD_CTL_PAD_FSEL(3U)); 121 | } 122 | 123 | -------------------------------------------------------------------------------- /src/freertos/osal.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2021 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #include "osal.h" 17 | 18 | #include 19 | 20 | #define TMO_TO_TICKS(ms) \ 21 | ((ms == OS_WAIT_FOREVER) ? portMAX_DELAY : (ms) / portTICK_PERIOD_MS) 22 | 23 | void * os_malloc (size_t size) 24 | { 25 | return malloc (size); 26 | } 27 | 28 | void os_free (void * ptr) 29 | { 30 | free (ptr); 31 | } 32 | 33 | os_thread_t * os_thread_create ( 34 | const char * name, 35 | uint32_t priority, 36 | size_t stacksize, 37 | void (*entry) (void * arg), 38 | void * arg) 39 | { 40 | TaskHandle_t xHandle = NULL; 41 | BaseType_t status; 42 | 43 | /* stacksize in freertos is not in bytes but in stack depth, it should be 44 | * divided by the stack width */ 45 | configSTACK_DEPTH_TYPE stackdepth = 46 | stacksize / sizeof (StackType_t); 47 | 48 | status = xTaskCreate (entry, name, stackdepth, arg, priority, &xHandle); 49 | CC_UNUSED (status); 50 | CC_ASSERT (status == pdPASS); 51 | CC_ASSERT (xHandle != NULL); 52 | return (os_thread_t *)xHandle; 53 | } 54 | 55 | os_mutex_t * os_mutex_create (void) 56 | { 57 | SemaphoreHandle_t handle = xSemaphoreCreateRecursiveMutex(); 58 | CC_ASSERT (handle != NULL); 59 | return (os_mutex_t *)handle; 60 | } 61 | 62 | void os_mutex_lock (os_mutex_t * mutex) 63 | { 64 | xSemaphoreTakeRecursive ((SemaphoreHandle_t)mutex, portMAX_DELAY); 65 | } 66 | 67 | void os_mutex_unlock (os_mutex_t * mutex) 68 | { 69 | xSemaphoreGiveRecursive ((SemaphoreHandle_t)mutex); 70 | } 71 | 72 | void os_mutex_destroy (os_mutex_t * mutex) 73 | { 74 | vSemaphoreDelete ((SemaphoreHandle_t)mutex); 75 | } 76 | 77 | void os_usleep (uint32_t us) 78 | { 79 | vTaskDelay ((us / portTICK_PERIOD_MS) / 1000); 80 | } 81 | 82 | uint32_t os_get_current_time_us (void) 83 | { 84 | return 1000 * (xTaskGetTickCount() / portTICK_PERIOD_MS); 85 | } 86 | 87 | os_tick_t os_tick_current (void) 88 | { 89 | return xTaskGetTickCount(); 90 | } 91 | 92 | os_tick_t os_tick_from_us (uint32_t us) 93 | { 94 | return us / (1000u * portTICK_PERIOD_MS); 95 | } 96 | 97 | void os_tick_sleep (os_tick_t tick) 98 | { 99 | vTaskDelay (tick); 100 | } 101 | 102 | os_sem_t * os_sem_create (size_t count) 103 | { 104 | SemaphoreHandle_t handle = xSemaphoreCreateCounting (UINT32_MAX, count); 105 | CC_ASSERT (handle != NULL); 106 | return (os_sem_t *)handle; 107 | } 108 | 109 | bool os_sem_wait (os_sem_t * sem, uint32_t time) 110 | { 111 | if (xSemaphoreTake ((SemaphoreHandle_t)sem, TMO_TO_TICKS (time)) == pdTRUE) 112 | { 113 | /* Did not timeout */ 114 | return false; 115 | } 116 | 117 | /* Timed out */ 118 | return true; 119 | } 120 | 121 | void os_sem_signal (os_sem_t * sem) 122 | { 123 | xSemaphoreGive ((SemaphoreHandle_t)sem); 124 | } 125 | 126 | void os_sem_destroy (os_sem_t * sem) 127 | { 128 | vSemaphoreDelete ((SemaphoreHandle_t)sem); 129 | } 130 | 131 | os_event_t * os_event_create (void) 132 | { 133 | EventGroupHandle_t handle = xEventGroupCreate(); 134 | CC_ASSERT (handle); 135 | return (os_event_t *)handle; 136 | } 137 | 138 | bool os_event_wait (os_event_t * event, uint32_t mask, uint32_t * value, uint32_t time) 139 | { 140 | *value = xEventGroupWaitBits ( 141 | (EventGroupHandle_t)event, 142 | mask, 143 | pdFALSE, 144 | pdFALSE, 145 | TMO_TO_TICKS (time)); 146 | 147 | *value &= mask; 148 | return *value == 0; 149 | } 150 | 151 | void os_event_set (os_event_t * event, uint32_t value) 152 | { 153 | xEventGroupSetBits ((EventGroupHandle_t)event, value); 154 | } 155 | 156 | void os_event_clr (os_event_t * event, uint32_t value) 157 | { 158 | xEventGroupClearBits ((EventGroupHandle_t)event, value); 159 | } 160 | 161 | void os_event_destroy (os_event_t * event) 162 | { 163 | vEventGroupDelete ((EventGroupHandle_t)event); 164 | } 165 | 166 | os_mbox_t * os_mbox_create (size_t size) 167 | { 168 | QueueHandle_t handle = xQueueCreate (size, sizeof (void *)); 169 | CC_ASSERT (handle); 170 | return (os_mbox_t *)handle; 171 | } 172 | 173 | bool os_mbox_fetch (os_mbox_t * mbox, void ** msg, uint32_t time) 174 | { 175 | BaseType_t success; 176 | 177 | success = xQueueReceive ((QueueHandle_t)mbox, msg, TMO_TO_TICKS (time)); 178 | return success != pdTRUE; 179 | } 180 | 181 | bool os_mbox_post (os_mbox_t * mbox, void * msg, uint32_t time) 182 | { 183 | BaseType_t success; 184 | 185 | success = xQueueSendToBack ((QueueHandle_t)mbox, &msg, TMO_TO_TICKS (time)); 186 | return success != pdTRUE; 187 | } 188 | 189 | void os_mbox_destroy (os_mbox_t * mbox) 190 | { 191 | vQueueDelete ((QueueHandle_t)mbox); 192 | } 193 | 194 | static void os_timer_callback (TimerHandle_t xTimer) 195 | { 196 | os_timer_t * timer = pvTimerGetTimerID (xTimer); 197 | 198 | if (timer->fn) 199 | timer->fn (timer, timer->arg); 200 | } 201 | 202 | os_timer_t * os_timer_create ( 203 | uint32_t us, 204 | void (*fn) (os_timer_t *, void * arg), 205 | void * arg, 206 | bool oneshot) 207 | { 208 | os_timer_t * timer; 209 | 210 | timer = malloc (sizeof (*timer)); 211 | CC_ASSERT (timer != NULL); 212 | 213 | timer->fn = fn; 214 | timer->arg = arg; 215 | timer->us = us; 216 | 217 | timer->handle = xTimerCreate ( 218 | "os_timer", 219 | (us / portTICK_PERIOD_MS) / 1000, 220 | oneshot ? pdFALSE : pdTRUE, 221 | timer, 222 | os_timer_callback); 223 | CC_ASSERT (timer->handle != NULL); 224 | return timer; 225 | } 226 | 227 | void os_timer_set (os_timer_t * timer, uint32_t us) 228 | { 229 | timer->us = us; 230 | } 231 | 232 | void os_timer_start (os_timer_t * timer) 233 | { 234 | /* Start timer by updating the period */ 235 | BaseType_t status = xTimerChangePeriod ( 236 | timer->handle, 237 | (timer->us / portTICK_PERIOD_MS) / 1000, 238 | portMAX_DELAY); 239 | 240 | CC_UNUSED (status); 241 | CC_ASSERT (status == pdPASS); 242 | } 243 | 244 | void os_timer_stop (os_timer_t * timer) 245 | { 246 | BaseType_t status = xTimerStop (timer->handle, portMAX_DELAY); 247 | CC_UNUSED (status); 248 | CC_ASSERT (status == pdPASS); 249 | } 250 | 251 | void os_timer_destroy (os_timer_t * timer) 252 | { 253 | BaseType_t status = xTimerDelete (timer->handle, portMAX_DELAY); 254 | CC_UNUSED (status); 255 | CC_ASSERT (status == pdPASS); 256 | free (timer); 257 | } 258 | -------------------------------------------------------------------------------- /src/freertos/osal_log.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2021 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #include "osal_log.h" 17 | 18 | #include 19 | #include 20 | 21 | void os_log (uint8_t type, const char * fmt, ...) 22 | { 23 | va_list list; 24 | 25 | switch (LOG_LEVEL_GET (type)) 26 | { 27 | case LOG_LEVEL_DEBUG: 28 | printf ("%10ld [DEBUG] ", xTaskGetTickCount()); 29 | break; 30 | case LOG_LEVEL_INFO: 31 | printf ("%10ld [INFO ] ", xTaskGetTickCount()); 32 | break; 33 | case LOG_LEVEL_WARNING: 34 | printf ("%10ld [WARN ] ", xTaskGetTickCount()); 35 | break; 36 | case LOG_LEVEL_ERROR: 37 | printf ("%10ld [ERROR] ", xTaskGetTickCount()); 38 | break; 39 | case LOG_LEVEL_FATAL: 40 | printf ("%10ld [FATAL] ", xTaskGetTickCount()); 41 | break; 42 | default: 43 | break; 44 | } 45 | 46 | va_start (list, fmt); 47 | vprintf (fmt, list); 48 | va_end (list); 49 | } 50 | -------------------------------------------------------------------------------- /src/freertos/sys/osal_cc.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2021 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #ifndef CC_H 17 | #define CC_H 18 | 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" 23 | { 24 | #endif 25 | 26 | #define CC_PACKED_BEGIN 27 | #define CC_PACKED_END 28 | #define CC_PACKED __attribute__((packed)) 29 | #define CC_ALIGNED(n) __attribute__((aligned (n))) 30 | 31 | #define CC_FORMAT(str,arg) __attribute__((format (printf, str, arg))) 32 | 33 | 34 | #if BYTE_ORDER == LITTLE_ENDIAN 35 | #define CC_TO_LE16(x) ((uint16_t)(x)) 36 | #define CC_TO_LE32(x) ((uint32_t)(x)) 37 | #define CC_TO_LE64(x) ((uint64_t)(x)) 38 | #define CC_FROM_LE16(x) ((uint16_t)(x)) 39 | #define CC_FROM_LE32(x) ((uint32_t)(x)) 40 | #define CC_FROM_LE64(x) ((uint64_t)(x)) 41 | #define CC_TO_BE16(x) ((uint16_t)__builtin_bswap16 (x)) 42 | #define CC_TO_BE32(x) ((uint32_t)__builtin_bswap32 (x)) 43 | #define CC_TO_BE64(x) ((uint64_t)__builtin_bswap64 (x)) 44 | #define CC_FROM_BE16(x) ((uint16_t)__builtin_bswap16 (x)) 45 | #define CC_FROM_BE32(x) ((uint32_t)__builtin_bswap32 (x)) 46 | #define CC_FROM_BE64(x) ((uint64_t)__builtin_bswap64 (x)) 47 | #else 48 | #define CC_TO_LE16(x) ((uint16_t)__builtin_bswap16 (x)) 49 | #define CC_TO_LE32(x) ((uint32_t)__builtin_bswap32 (x)) 50 | #define CC_TO_LE64(x) ((uint64_t)__builtin_bswap64 (x)) 51 | #define CC_FROM_LE16(x) ((uint16_t)__builtin_bswap16 (x)) 52 | #define CC_FROM_LE32(x) ((uint32_t)__builtin_bswap32 (x)) 53 | #define CC_FROM_LE64(x) ((uint64_t)__builtin_bswap64 (x)) 54 | #define CC_TO_BE16(x) ((uint16_t)(x)) 55 | #define CC_TO_BE32(x) ((uint32_t)(x)) 56 | #define CC_TO_BE64(x) ((uint64_t)(x)) 57 | #define CC_FROM_BE16(x) ((uint16_t)(x)) 58 | #define CC_FROM_BE32(x) ((uint32_t)(x)) 59 | #define CC_FROM_BE64(x) ((uint64_t)(x)) 60 | #endif 61 | 62 | #define CC_ATOMIC_GET8(p) (*p) 63 | #define CC_ATOMIC_GET16(p) (*p) 64 | #define CC_ATOMIC_GET32(p) (*p) 65 | #define CC_ATOMIC_GET64(p) \ 66 | ({ \ 67 | uint64_t v; \ 68 | /*int_lock();*/ \ 69 | v = *p; \ 70 | /*int_unlock();*/ \ 71 | v; \ 72 | }) 73 | 74 | #define CC_ATOMIC_SET8(p, v) ((*p) = (v)) 75 | #define CC_ATOMIC_SET16(p, v) ((*p) = (v)) 76 | #define CC_ATOMIC_SET32(p, v) ((*p) = (v)) 77 | #define CC_ATOMIC_SET64(p, v) \ 78 | ({ \ 79 | /*int_lock();*/ \ 80 | *p = v; \ 81 | /*int_unlock();*/ \ 82 | }) 83 | 84 | #define CC_ASSERT(exp) assert (exp) 85 | #define CC_STATIC_ASSERT(exp) _Static_assert (exp, "") 86 | #define CC_UNUSED(var) (void)(var) 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* CC_H */ 93 | -------------------------------------------------------------------------------- /src/freertos/sys/osal_sys.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2021 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #ifndef OSAL_SYS_H 17 | #define OSAL_SYS_H 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #define OS_MAIN extern "C" int _main 29 | 30 | #define OS_THREAD 31 | #define OS_MUTEX 32 | #define OS_SEM 33 | #define OS_EVENT 34 | #define OS_MBOX 35 | #define OS_TIMER 36 | #define OS_TICK 37 | 38 | typedef SemaphoreHandle_t os_mutex_t; 39 | typedef TaskHandle_t os_thread_t; 40 | typedef SemaphoreHandle_t os_sem_t; 41 | typedef EventGroupHandle_t os_event_t; 42 | typedef QueueHandle_t os_mbox_t; 43 | 44 | typedef struct os_timer 45 | { 46 | TimerHandle_t handle; 47 | void(*fn) (struct os_timer *, void * arg); 48 | void * arg; 49 | uint32_t us; 50 | } os_timer_t; 51 | 52 | typedef TickType_t os_tick_t; 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* OSAL_SYS_H */ 59 | -------------------------------------------------------------------------------- /src/linux/osal_log.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #include "osal_log.h" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | static void os_log_impl (uint8_t type, const char * fmt, ...) 23 | { 24 | va_list list; 25 | time_t rawtime; 26 | struct tm timestruct; 27 | char timestamp[10]; 28 | 29 | time (&rawtime); 30 | localtime_r (&rawtime, ×truct); 31 | strftime (timestamp, sizeof (timestamp), "%H:%M:%S", ×truct); 32 | 33 | switch (LOG_LEVEL_GET (type)) 34 | { 35 | case LOG_LEVEL_DEBUG: 36 | printf ("[%s DEBUG] ", timestamp); 37 | break; 38 | case LOG_LEVEL_INFO: 39 | printf ("[%s INFO ] ", timestamp); 40 | break; 41 | case LOG_LEVEL_WARNING: 42 | printf ("[%s WARN ] ", timestamp); 43 | break; 44 | case LOG_LEVEL_ERROR: 45 | printf ("[%s ERROR] ", timestamp); 46 | break; 47 | case LOG_LEVEL_FATAL: 48 | printf ("[%s FATAL] ", timestamp); 49 | break; 50 | default: 51 | break; 52 | } 53 | 54 | va_start (list, fmt); 55 | vprintf (fmt, list); 56 | va_end (list); 57 | fflush (stdout); 58 | } 59 | 60 | os_log_t os_log = os_log_impl; 61 | -------------------------------------------------------------------------------- /src/linux/sys/osal_cc.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #ifndef CC_H 17 | #define CC_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | #if defined(__clang__) 26 | #if !defined(CLANG_ANALYZER_NORETURN) 27 | #if __has_feature(attribute_analyzer_noreturn) 28 | #define CLANG_ANALYZER_NORETURN __attribute__ ((analyzer_noreturn)) 29 | #else 30 | #define CLANG_ANALYZER_NORETURN 31 | #endif 32 | #endif 33 | #else 34 | #define CLANG_ANALYZER_NORETURN 35 | #endif 36 | 37 | static inline void cc_assert (int exp) CLANG_ANALYZER_NORETURN 38 | { 39 | assert (exp); // LCOV_EXCL_LINE 40 | } 41 | 42 | #define CC_PACKED_BEGIN 43 | #define CC_PACKED_END 44 | #define CC_PACKED __attribute__ ((packed)) 45 | #define CC_ALIGNED(n) __attribute__((aligned (n))) 46 | 47 | #define CC_FORMAT(str, arg) __attribute__ ((format (printf, str, arg))) 48 | 49 | #if BYTE_ORDER == LITTLE_ENDIAN 50 | #define CC_TO_LE16(x) ((uint16_t)(x)) 51 | #define CC_TO_LE32(x) ((uint32_t)(x)) 52 | #define CC_TO_LE64(x) ((uint64_t)(x)) 53 | #define CC_FROM_LE16(x) ((uint16_t)(x)) 54 | #define CC_FROM_LE32(x) ((uint32_t)(x)) 55 | #define CC_FROM_LE64(x) ((uint64_t)(x)) 56 | #define CC_TO_BE16(x) ((uint16_t)__builtin_bswap16 (x)) 57 | #define CC_TO_BE32(x) ((uint32_t)__builtin_bswap32 (x)) 58 | #define CC_TO_BE64(x) ((uint64_t)__builtin_bswap64 (x)) 59 | #define CC_FROM_BE16(x) ((uint16_t)__builtin_bswap16 (x)) 60 | #define CC_FROM_BE32(x) ((uint32_t)__builtin_bswap32 (x)) 61 | #define CC_FROM_BE64(x) ((uint64_t)__builtin_bswap64 (x)) 62 | #else 63 | #define CC_TO_LE16(x) ((uint16_t)__builtin_bswap16 (x)) 64 | #define CC_TO_LE32(x) ((uint32_t)__builtin_bswap32 (x)) 65 | #define CC_TO_LE64(x) ((uint64_t)__builtin_bswap64 (x)) 66 | #define CC_FROM_LE16(x) ((uint16_t)__builtin_bswap16 (x)) 67 | #define CC_FROM_LE32(x) ((uint32_t)__builtin_bswap32 (x)) 68 | #define CC_FROM_LE64(x) ((uint64_t)__builtin_bswap64 (x)) 69 | #define CC_TO_BE16(x) ((uint16_t)(x)) 70 | #define CC_TO_BE32(x) ((uint32_t)(x)) 71 | #define CC_TO_BE64(x) ((uint64_t)(x)) 72 | #define CC_FROM_BE16(x) ((uint16_t)(x)) 73 | #define CC_FROM_BE32(x) ((uint32_t)(x)) 74 | #define CC_FROM_BE64(x) ((uint64_t)(x)) 75 | #endif 76 | 77 | #define CC_ATOMIC_GET8(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) 78 | #define CC_ATOMIC_GET16(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) 79 | #define CC_ATOMIC_GET32(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) 80 | #define CC_ATOMIC_GET64(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) 81 | 82 | #define CC_ATOMIC_SET8(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) 83 | #define CC_ATOMIC_SET16(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) 84 | #define CC_ATOMIC_SET32(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) 85 | #define CC_ATOMIC_SET64(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) 86 | 87 | #define CC_ASSERT(exp) cc_assert (exp) 88 | 89 | #ifdef __cplusplus 90 | #define CC_STATIC_ASSERT(exp) static_assert (exp, "") 91 | #else 92 | #define CC_STATIC_ASSERT(exp) _Static_assert(exp, "") 93 | #endif 94 | 95 | #define CC_UNUSED(var) (void)(var) 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* CC_H */ 102 | -------------------------------------------------------------------------------- /src/linux/sys/osal_sys.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #ifndef OSAL_SYS_H 17 | #define OSAL_SYS_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #define OS_THREAD 27 | #define OS_MUTEX 28 | #define OS_SEM 29 | #define OS_EVENT 30 | #define OS_MBOX 31 | #define OS_TIMER 32 | #define OS_TICK 33 | 34 | typedef pthread_t os_thread_t; 35 | typedef pthread_mutex_t os_mutex_t; 36 | 37 | typedef struct os_sem 38 | { 39 | pthread_cond_t cond; 40 | pthread_mutex_t mutex; 41 | size_t count; 42 | } os_sem_t; 43 | 44 | typedef struct os_event 45 | { 46 | pthread_cond_t cond; 47 | pthread_mutex_t mutex; 48 | uint32_t flags; 49 | } os_event_t; 50 | 51 | typedef struct os_mbox 52 | { 53 | pthread_cond_t cond; 54 | pthread_mutex_t mutex; 55 | size_t r; 56 | size_t w; 57 | size_t count; 58 | size_t size; 59 | void * msg[]; 60 | } os_mbox_t; 61 | 62 | typedef struct os_timer 63 | { 64 | timer_t timerid; 65 | os_thread_t * thread; 66 | pid_t thread_id; 67 | bool exit; 68 | void (*fn) (struct os_timer *, void * arg); 69 | void * arg; 70 | uint32_t us; 71 | bool oneshot; 72 | } os_timer_t; 73 | 74 | typedef uint64_t os_tick_t; 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* OSAL_SYS_H */ 81 | -------------------------------------------------------------------------------- /src/rt-kernel/osal.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #include "osal.h" 17 | 18 | void * os_malloc (size_t size) 19 | { 20 | return malloc (size); 21 | } 22 | 23 | void os_free (void * ptr) 24 | { 25 | free (ptr); 26 | } 27 | 28 | os_thread_t * os_thread_create ( 29 | const char * name, 30 | uint32_t priority, 31 | size_t stacksize, 32 | void (*entry) (void * arg), 33 | void * arg) 34 | { 35 | return task_spawn (name, entry, priority, stacksize, arg); 36 | } 37 | 38 | os_mutex_t * os_mutex_create (void) 39 | { 40 | return mtx_create(); 41 | } 42 | 43 | void os_mutex_lock (os_mutex_t * mutex) 44 | { 45 | mtx_lock (mutex); 46 | } 47 | 48 | void os_mutex_unlock (os_mutex_t * mutex) 49 | { 50 | mtx_unlock (mutex); 51 | } 52 | 53 | void os_mutex_destroy (os_mutex_t * mutex) 54 | { 55 | mtx_destroy (mutex); 56 | } 57 | 58 | void os_usleep (uint32_t us) 59 | { 60 | task_delay (tick_from_ms (us / 1000)); 61 | } 62 | 63 | uint32_t os_get_current_time_us (void) 64 | { 65 | return 1000 * tick_to_ms (tick_get()); 66 | } 67 | 68 | os_tick_t os_tick_current (void) 69 | { 70 | return tick_get(); 71 | } 72 | 73 | os_tick_t os_tick_from_us (uint32_t us) 74 | { 75 | return tick_from_ms (us / 1000); 76 | } 77 | 78 | void os_tick_sleep (os_tick_t tick) 79 | { 80 | task_delay (tick); 81 | } 82 | 83 | os_sem_t * os_sem_create (size_t count) 84 | { 85 | return sem_create (count); 86 | } 87 | 88 | bool os_sem_wait (os_sem_t * sem, uint32_t time) 89 | { 90 | int tmo = 0; 91 | 92 | if (time != OS_WAIT_FOREVER) 93 | { 94 | tmo = sem_wait_tmo (sem, tick_from_ms (time)); 95 | } 96 | else 97 | { 98 | sem_wait (sem); 99 | } 100 | 101 | return tmo; 102 | } 103 | 104 | void os_sem_signal (os_sem_t * sem) 105 | { 106 | sem_signal (sem); 107 | } 108 | 109 | void os_sem_destroy (os_sem_t * sem) 110 | { 111 | sem_destroy (sem); 112 | } 113 | 114 | os_event_t * os_event_create (void) 115 | { 116 | return flags_create (0); 117 | } 118 | 119 | bool os_event_wait (os_event_t * event, uint32_t mask, uint32_t * value, uint32_t time) 120 | { 121 | int tmo = 0; 122 | 123 | if (time != OS_WAIT_FOREVER) 124 | { 125 | tmo = flags_wait_any_tmo (event, mask, tick_from_ms (time), value); 126 | } 127 | else 128 | { 129 | flags_wait_any (event, mask, value); 130 | } 131 | 132 | *value = *value & mask; 133 | return tmo; 134 | } 135 | 136 | void os_event_set (os_event_t * event, uint32_t value) 137 | { 138 | flags_set (event, value); 139 | } 140 | 141 | void os_event_clr (os_event_t * event, uint32_t value) 142 | { 143 | flags_clr (event, value); 144 | } 145 | 146 | void os_event_destroy (os_event_t * event) 147 | { 148 | flags_destroy (event); 149 | } 150 | 151 | os_mbox_t * os_mbox_create (size_t size) 152 | { 153 | return mbox_create (size); 154 | } 155 | 156 | bool os_mbox_fetch (os_mbox_t * mbox, void ** msg, uint32_t time) 157 | { 158 | int tmo = 0; 159 | 160 | if (time != OS_WAIT_FOREVER) 161 | { 162 | tmo = mbox_fetch_tmo (mbox, msg, tick_from_ms (time)); 163 | } 164 | else 165 | { 166 | mbox_fetch (mbox, msg); 167 | } 168 | 169 | return tmo; 170 | } 171 | 172 | bool os_mbox_post (os_mbox_t * mbox, void * msg, uint32_t time) 173 | { 174 | int tmo = 0; 175 | 176 | if (time != OS_WAIT_FOREVER) 177 | { 178 | tmo = mbox_post_tmo (mbox, msg, tick_from_ms (time)); 179 | } 180 | else 181 | { 182 | mbox_post (mbox, msg); 183 | } 184 | 185 | return tmo; 186 | } 187 | 188 | void os_mbox_destroy (os_mbox_t * mbox) 189 | { 190 | mbox_destroy (mbox); 191 | } 192 | 193 | os_timer_t * os_timer_create ( 194 | uint32_t us, 195 | void (*fn) (os_timer_t *, void * arg), 196 | void * arg, 197 | bool oneshot) 198 | { 199 | return tmr_create ( 200 | tick_from_ms (us / 1000), 201 | fn, 202 | arg, 203 | (oneshot) ? TMR_ONCE : TMR_CYCL); 204 | } 205 | 206 | void os_timer_set (os_timer_t * timer, uint32_t us) 207 | { 208 | tmr_set (timer, tick_from_ms (us / 1000)); 209 | } 210 | 211 | void os_timer_start (os_timer_t * timer) 212 | { 213 | tmr_start (timer); 214 | } 215 | 216 | void os_timer_stop (os_timer_t * timer) 217 | { 218 | tmr_stop (timer); 219 | } 220 | 221 | void os_timer_destroy (os_timer_t * timer) 222 | { 223 | tmr_destroy (timer); 224 | } 225 | -------------------------------------------------------------------------------- /src/rt-kernel/osal_log.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #include "osal_log.h" 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | void os_log_impl (uint8_t type, const char * fmt, ...) 24 | { 25 | va_list list; 26 | 27 | switch (LOG_LEVEL_GET (type)) 28 | { 29 | case LOG_LEVEL_DEBUG: 30 | rprintf ("%10d [DEBUG] ", tick_get()); 31 | break; 32 | case LOG_LEVEL_INFO: 33 | rprintf ("%10d [INFO ] ", tick_get()); 34 | break; 35 | case LOG_LEVEL_WARNING: 36 | rprintf ("%10d [WARN ] ", tick_get()); 37 | break; 38 | case LOG_LEVEL_ERROR: 39 | rprintf ("%10d [ERROR] ", tick_get()); 40 | break; 41 | case LOG_LEVEL_FATAL: 42 | rprintf ("%10d [FATAL] ", tick_get()); 43 | break; 44 | default: 45 | break; 46 | } 47 | 48 | va_start (list, fmt); 49 | vprintf (fmt, list); 50 | va_end (list); 51 | } 52 | 53 | os_log_t os_log = os_log_impl; 54 | -------------------------------------------------------------------------------- /src/rt-kernel/sys/osal_cc.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #ifndef CC_H 17 | #define CC_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "kern/types.h" 24 | #include "kern/assert.h" 25 | 26 | #define CC_PACKED_BEGIN 27 | #define CC_PACKED_END 28 | #define CC_PACKED __attribute__ ((packed)) 29 | #define CC_ALIGNED(n) __attribute__((aligned (n))) 30 | 31 | #define CC_FORMAT(str, arg) __attribute__ ((format (printf, str, arg))) 32 | 33 | #if BYTE_ORDER == LITTLE_ENDIAN 34 | #define CC_TO_LE16(x) ((uint16_t)(x)) 35 | #define CC_TO_LE32(x) ((uint32_t)(x)) 36 | #define CC_TO_LE64(x) ((uint64_t)(x)) 37 | #define CC_FROM_LE16(x) ((uint16_t)(x)) 38 | #define CC_FROM_LE32(x) ((uint32_t)(x)) 39 | #define CC_FROM_LE64(x) ((uint64_t)(x)) 40 | #define CC_TO_BE16(x) ((uint16_t)__builtin_bswap16 (x)) 41 | #define CC_TO_BE32(x) ((uint32_t)__builtin_bswap32 (x)) 42 | #define CC_TO_BE64(x) ((uint64_t)__builtin_bswap64 (x)) 43 | #define CC_FROM_BE16(x) ((uint16_t)__builtin_bswap16 (x)) 44 | #define CC_FROM_BE32(x) ((uint32_t)__builtin_bswap32 (x)) 45 | #define CC_FROM_BE64(x) ((uint64_t)__builtin_bswap64 (x)) 46 | #else 47 | #define CC_TO_LE16(x) ((uint16_t)__builtin_bswap16 (x)) 48 | #define CC_TO_LE32(x) ((uint32_t)__builtin_bswap32 (x)) 49 | #define CC_TO_LE64(x) ((uint64_t)__builtin_bswap64 (x)) 50 | #define CC_FROM_LE16(x) ((uint16_t)__builtin_bswap16 (x)) 51 | #define CC_FROM_LE32(x) ((uint32_t)__builtin_bswap32 (x)) 52 | #define CC_FROM_LE64(x) ((uint64_t)__builtin_bswap64 (x)) 53 | #define CC_TO_BE16(x) ((uint16_t)(x)) 54 | #define CC_TO_BE32(x) ((uint32_t)(x)) 55 | #define CC_TO_BE64(x) ((uint64_t)(x)) 56 | #define CC_FROM_BE16(x) ((uint16_t)(x)) 57 | #define CC_FROM_BE32(x) ((uint32_t)(x)) 58 | #define CC_FROM_BE64(x) ((uint64_t)(x)) 59 | #endif 60 | 61 | #define CC_ATOMIC_GET8(p) (*p) 62 | #define CC_ATOMIC_GET16(p) (*p) 63 | #define CC_ATOMIC_GET32(p) (*p) 64 | #define CC_ATOMIC_GET64(p) \ 65 | ({ \ 66 | uint64_t v; \ 67 | int_lock(); \ 68 | v = *p; \ 69 | int_unlock(); \ 70 | v; \ 71 | }) 72 | 73 | #define CC_ATOMIC_SET8(p, v) ((*p) = (v)) 74 | #define CC_ATOMIC_SET16(p, v) ((*p) = (v)) 75 | #define CC_ATOMIC_SET32(p, v) ((*p) = (v)) 76 | #define CC_ATOMIC_SET64(p, v) \ 77 | ({ \ 78 | int_lock(); \ 79 | *p = v; \ 80 | int_unlock(); \ 81 | }) 82 | 83 | #define CC_ASSERT(exp) ASSERT (exp) 84 | #define CC_STATIC_ASSERT(exp) _Static_assert(exp, "") 85 | #define CC_UNUSED(var) (void)(var) 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif /* CC_H */ 92 | -------------------------------------------------------------------------------- /src/rt-kernel/sys/osal_sys.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #ifndef OSAL_SYS_H 17 | #define OSAL_SYS_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | #define OS_THREAD 26 | #define OS_MUTEX 27 | #define OS_SEM 28 | #define OS_EVENT 29 | #define OS_MBOX 30 | #define OS_TIMER 31 | #define OS_TICK 32 | 33 | typedef task_t os_thread_t; 34 | typedef mtx_t os_mutex_t; 35 | typedef sem_t os_sem_t; 36 | typedef flags_t os_event_t; 37 | typedef mbox_t os_mbox_t; 38 | typedef tmr_t os_timer_t; 39 | typedef tick_t os_tick_t; 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* OSAL_SYS_H */ 46 | -------------------------------------------------------------------------------- /src/windows/osal.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #include "osal.h" 17 | 18 | #define URESOLUTION 10 19 | 20 | void * os_malloc (size_t size) 21 | { 22 | return malloc (size); 23 | } 24 | 25 | void os_free (void * ptr) 26 | { 27 | free (ptr); 28 | } 29 | 30 | os_mutex_t * os_mutex_create (void) 31 | { 32 | CRITICAL_SECTION * handle; 33 | handle = CreateMutex (NULL, FALSE, NULL); 34 | CC_ASSERT (handle != INVALID_HANDLE_VALUE); 35 | return handle; 36 | } 37 | 38 | void os_mutex_lock (os_mutex_t * mutex) 39 | { 40 | WaitForSingleObject (mutex, INFINITE); 41 | } 42 | 43 | void os_mutex_unlock (os_mutex_t * mutex) 44 | { 45 | ReleaseMutex (mutex); 46 | } 47 | 48 | void os_mutex_destroy (os_mutex_t * mutex) 49 | { 50 | CloseHandle (mutex); 51 | } 52 | 53 | void os_usleep (uint32_t usec) 54 | { 55 | Sleep (usec / 1000); 56 | } 57 | 58 | os_thread_t * os_thread_create ( 59 | const char * name, 60 | uint32_t priority, 61 | size_t stacksize, 62 | void (*entry) (void * arg), 63 | void * arg) 64 | { 65 | HANDLE handle; 66 | handle = 67 | CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)entry, (LPVOID)arg, 0, NULL); 68 | CC_ASSERT (handle != INVALID_HANDLE_VALUE); 69 | 70 | if (priority < 5) 71 | { 72 | SetThreadPriority (handle, THREAD_PRIORITY_BELOW_NORMAL); 73 | } 74 | else if (priority >= 15) 75 | { 76 | SetThreadPriority (handle, THREAD_PRIORITY_TIME_CRITICAL); 77 | } 78 | return handle; 79 | } 80 | 81 | static uint64_t os_get_frequency_tick (void) 82 | { 83 | static uint64_t frequency; 84 | if (frequency == 0) 85 | { 86 | LARGE_INTEGER performanceFrequency; 87 | timeBeginPeriod (URESOLUTION); 88 | QueryPerformanceFrequency (&performanceFrequency); 89 | frequency = performanceFrequency.QuadPart; 90 | } 91 | return frequency; 92 | } 93 | 94 | uint32_t os_get_current_time_us (void) 95 | { 96 | LARGE_INTEGER currentCount; 97 | uint64_t currentTime; 98 | QueryPerformanceCounter (¤tCount); 99 | currentTime = 1000000 * currentCount.QuadPart / os_get_frequency_tick(); 100 | return (uint32_t)(currentTime & UINT32_MAX); 101 | } 102 | 103 | os_tick_t os_tick_current (void) 104 | { 105 | LARGE_INTEGER currentCount; 106 | QueryPerformanceCounter (¤tCount); 107 | return currentCount.QuadPart; 108 | } 109 | 110 | os_tick_t os_tick_from_us (uint32_t us) 111 | { 112 | return os_get_frequency_tick() * us / 1000000; 113 | } 114 | 115 | void os_tick_sleep (os_tick_t tick) 116 | { 117 | Sleep ((DWORD)(1000u * tick / os_get_frequency_tick())); 118 | } 119 | 120 | os_sem_t * os_sem_create (size_t count) 121 | { 122 | os_sem_t * sem; 123 | 124 | sem = (os_sem_t *)malloc (sizeof (*sem)); 125 | CC_ASSERT (sem != NULL); 126 | 127 | InitializeConditionVariable (&sem->condition); 128 | InitializeCriticalSection (&sem->lock); 129 | sem->count = count; 130 | 131 | return sem; 132 | } 133 | 134 | bool os_sem_wait (os_sem_t * sem, uint32_t time) 135 | { 136 | BOOL success = TRUE; 137 | 138 | EnterCriticalSection (&sem->lock); 139 | while (sem->count == 0) 140 | { 141 | /* FIXME - decrease timeout if woken early */ 142 | success = SleepConditionVariableCS (&sem->condition, &sem->lock, time); 143 | if (!success && GetLastError() == ERROR_TIMEOUT) 144 | { 145 | goto timeout; 146 | } 147 | CC_ASSERT (success); 148 | } 149 | 150 | sem->count--; 151 | 152 | timeout: 153 | LeaveCriticalSection (&sem->lock); 154 | return !success; 155 | } 156 | 157 | void os_sem_signal (os_sem_t * sem) 158 | { 159 | EnterCriticalSection (&sem->lock); 160 | sem->count++; 161 | LeaveCriticalSection (&sem->lock); 162 | WakeAllConditionVariable (&sem->condition); 163 | } 164 | 165 | void os_sem_destroy (os_sem_t * sem) 166 | { 167 | EnterCriticalSection (&sem->lock); 168 | free (sem); 169 | } 170 | 171 | os_event_t * os_event_create (void) 172 | { 173 | os_event_t * event; 174 | 175 | event = (os_event_t *)malloc (sizeof (*event)); 176 | CC_ASSERT (event != NULL); 177 | 178 | InitializeConditionVariable (&event->condition); 179 | InitializeCriticalSection (&event->lock); 180 | event->flags = 0; 181 | 182 | return event; 183 | } 184 | 185 | bool os_event_wait (os_event_t * event, uint32_t mask, uint32_t * value, uint32_t time) 186 | { 187 | BOOL success = TRUE; 188 | 189 | EnterCriticalSection (&event->lock); 190 | while ((event->flags & mask) == 0) 191 | { 192 | /* FIXME - decrease timeout if woken early */ 193 | success = SleepConditionVariableCS (&event->condition, &event->lock, time); 194 | if (!success && GetLastError() == ERROR_TIMEOUT) 195 | { 196 | break; 197 | } 198 | } 199 | *value = event->flags & mask; 200 | LeaveCriticalSection (&event->lock); 201 | return !success; 202 | } 203 | 204 | void os_event_set (os_event_t * event, uint32_t value) 205 | { 206 | EnterCriticalSection (&event->lock); 207 | event->flags |= value; 208 | LeaveCriticalSection (&event->lock); 209 | WakeAllConditionVariable (&event->condition); 210 | } 211 | 212 | void os_event_clr (os_event_t * event, uint32_t value) 213 | { 214 | EnterCriticalSection (&event->lock); 215 | event->flags &= ~value; 216 | LeaveCriticalSection (&event->lock); 217 | } 218 | 219 | void os_event_destroy (os_event_t * event) 220 | { 221 | EnterCriticalSection (&event->lock); 222 | free (event); 223 | } 224 | 225 | os_mbox_t * os_mbox_create (size_t size) 226 | { 227 | os_mbox_t * mbox; 228 | 229 | mbox = (os_mbox_t *)malloc (sizeof (*mbox) + size * sizeof (void *)); 230 | CC_ASSERT (mbox != NULL); 231 | 232 | InitializeConditionVariable (&mbox->condition); 233 | InitializeCriticalSection (&mbox->lock); 234 | 235 | mbox->r = 0; 236 | mbox->w = 0; 237 | mbox->count = 0; 238 | mbox->size = size; 239 | 240 | return mbox; 241 | } 242 | 243 | bool os_mbox_fetch (os_mbox_t * mbox, void ** msg, uint32_t time) 244 | { 245 | BOOL success = TRUE; 246 | 247 | EnterCriticalSection (&mbox->lock); 248 | while (mbox->count == 0) 249 | { 250 | /* FIXME - decrease timeout if woken early */ 251 | success = SleepConditionVariableCS (&mbox->condition, &mbox->lock, time); 252 | if (!success && GetLastError() == ERROR_TIMEOUT) 253 | { 254 | goto timeout; 255 | } 256 | CC_ASSERT (success); 257 | } 258 | 259 | *msg = mbox->msg[mbox->r++]; 260 | if (mbox->r == mbox->size) 261 | mbox->r = 0; 262 | 263 | mbox->count--; 264 | 265 | timeout: 266 | LeaveCriticalSection (&mbox->lock); 267 | WakeAllConditionVariable (&mbox->condition); 268 | 269 | return !success; 270 | } 271 | 272 | bool os_mbox_post (os_mbox_t * mbox, void * msg, uint32_t time) 273 | { 274 | BOOL success = TRUE; 275 | 276 | EnterCriticalSection (&mbox->lock); 277 | while (mbox->count == mbox->size) 278 | { 279 | /* FIXME - decrease timeout if woken early */ 280 | success = SleepConditionVariableCS (&mbox->condition, &mbox->lock, time); 281 | if (!success && GetLastError() == ERROR_TIMEOUT) 282 | { 283 | goto timeout; 284 | } 285 | CC_ASSERT (success); 286 | } 287 | 288 | mbox->msg[mbox->w++] = msg; 289 | if (mbox->w == mbox->size) 290 | mbox->w = 0; 291 | 292 | mbox->count++; 293 | 294 | timeout: 295 | LeaveCriticalSection (&mbox->lock); 296 | WakeAllConditionVariable (&mbox->condition); 297 | 298 | return !success; 299 | } 300 | 301 | void os_mbox_destroy (os_mbox_t * mbox) 302 | { 303 | EnterCriticalSection (&mbox->lock); 304 | free (mbox); 305 | } 306 | 307 | static VOID CALLBACK 308 | timer_callback (UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) 309 | { 310 | os_timer_t * timer = (os_timer_t *)dwUser; 311 | 312 | if (timer->fn) 313 | { 314 | timer->fn (timer, timer->arg); 315 | } 316 | } 317 | 318 | os_timer_t * os_timer_create ( 319 | uint32_t us, 320 | void (*fn) (os_timer_t *, void * arg), 321 | void * arg, 322 | bool oneshot) 323 | { 324 | os_timer_t * timer; 325 | 326 | timer = (os_timer_t *)malloc (sizeof (*timer)); 327 | 328 | timer->fn = fn; 329 | timer->arg = arg; 330 | timer->us = us; 331 | timer->oneshot = oneshot; 332 | 333 | return timer; 334 | } 335 | 336 | void os_timer_set (os_timer_t * timer, uint32_t us) 337 | { 338 | timer->us = us; 339 | } 340 | 341 | void os_timer_start (os_timer_t * timer) 342 | { 343 | timeBeginPeriod (URESOLUTION); 344 | 345 | /**************************************************************** 346 | * N.B. The function timeSetEvent is obsolete. * 347 | * The reason for still using it here is that it gives * 348 | * much better resolution (15 ms -> 1 ms) than when * 349 | * using the recommended function CreateTimerQueueTimer. * 350 | ****************************************************************/ 351 | timer->timerID = timeSetEvent ( 352 | timer->us / 1000, 353 | URESOLUTION, 354 | timer_callback, 355 | (DWORD_PTR)timer, 356 | (timer->oneshot) ? TIME_ONESHOT : TIME_PERIODIC); 357 | } 358 | 359 | void os_timer_stop (os_timer_t * timer) 360 | { 361 | timeKillEvent (timer->timerID); 362 | 363 | timeEndPeriod (URESOLUTION); 364 | } 365 | 366 | void os_timer_destroy (os_timer_t * timer) 367 | { 368 | free (timer); 369 | } 370 | -------------------------------------------------------------------------------- /src/windows/osal_log.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #include "osal_log.h" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | static void os_log_impl (uint8_t type, const char * fmt, ...) 23 | { 24 | va_list list; 25 | 26 | switch (LOG_LEVEL_GET (type)) 27 | { 28 | case LOG_LEVEL_DEBUG: 29 | printf ("[DEBUG] "); 30 | break; 31 | case LOG_LEVEL_INFO: 32 | printf ("[INFO ] "); 33 | break; 34 | case LOG_LEVEL_WARNING: 35 | printf ("[WARN ] "); 36 | break; 37 | case LOG_LEVEL_ERROR: 38 | printf ("[ERROR] "); 39 | break; 40 | case LOG_LEVEL_FATAL: 41 | printf ("[FATAL] "); 42 | break; 43 | default: 44 | break; 45 | } 46 | 47 | va_start (list, fmt); 48 | vprintf (fmt, list); 49 | va_end (list); 50 | fflush (stdout); 51 | } 52 | 53 | os_log_t os_log = os_log_impl; 54 | -------------------------------------------------------------------------------- /src/windows/sys/osal_cc.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #ifndef CC_H 17 | #define CC_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #if defined(__GNUC__) || defined(__GNUG__) 24 | 25 | #include 26 | 27 | #define CC_PACKED_BEGIN 28 | #define CC_PACKED_END 29 | #define CC_PACKED __attribute__ ((packed)) 30 | 31 | #define CC_FORMAT(str, arg) __attribute__ ((format (printf, str, arg))) 32 | 33 | #if BYTE_ORDER == LITTLE_ENDIAN 34 | #define CC_TO_LE16(x) ((uint16_t)(x)) 35 | #define CC_TO_LE32(x) ((uint32_t)(x)) 36 | #define CC_TO_LE64(x) ((uint64_t)(x)) 37 | #define CC_FROM_LE16(x) ((uint16_t)(x)) 38 | #define CC_FROM_LE32(x) ((uint32_t)(x)) 39 | #define CC_FROM_LE64(x) ((uint64_t)(x)) 40 | #define CC_TO_BE16(x) ((uint16_t)__builtin_bswap16 (x)) 41 | #define CC_TO_BE32(x) ((uint32_t)__builtin_bswap32 (x)) 42 | #define CC_TO_BE64(x) ((uint64_t)__builtin_bswap64 (x)) 43 | #define CC_FROM_BE16(x) ((uint16_t)__builtin_bswap16 (x)) 44 | #define CC_FROM_BE32(x) ((uint32_t)__builtin_bswap32 (x)) 45 | #define CC_FROM_BE64(x) ((uint64_t)__builtin_bswap64 (x)) 46 | #else 47 | #define CC_TO_LE16(x) ((uint16_t)__builtin_bswap16 (x)) 48 | #define CC_TO_LE32(x) ((uint32_t)__builtin_bswap32 (x)) 49 | #define CC_TO_LE64(x) ((uint64_t)__builtin_bswap64 (x)) 50 | #define CC_FROM_LE16(x) ((uint16_t)__builtin_bswap16 (x)) 51 | #define CC_FROM_LE32(x) ((uint32_t)__builtin_bswap32 (x)) 52 | #define CC_FROM_LE64(x) ((uint64_t)__builtin_bswap64 (x)) 53 | #define CC_TO_BE16(x) ((uint16_t)(x)) 54 | #define CC_TO_BE32(x) ((uint32_t)(x)) 55 | #define CC_TO_BE64(x) ((uint64_t)(x)) 56 | #define CC_FROM_BE16(x) ((uint16_t)(x)) 57 | #define CC_FROM_BE32(x) ((uint32_t)(x)) 58 | #define CC_FROM_BE64(x) ((uint64_t)(x)) 59 | #endif 60 | 61 | #define CC_ATOMIC_GET8(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) 62 | #define CC_ATOMIC_GET16(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) 63 | #define CC_ATOMIC_GET32(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) 64 | #define CC_ATOMIC_GET64(p) __atomic_load_n ((p), __ATOMIC_SEQ_CST) 65 | 66 | #define CC_ATOMIC_SET8(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) 67 | #define CC_ATOMIC_SET16(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) 68 | #define CC_ATOMIC_SET32(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) 69 | #define CC_ATOMIC_SET64(p, v) __atomic_store_n ((p), (v), __ATOMIC_SEQ_CST) 70 | 71 | #define CC_ASSERT(exp) cc_assert (exp) 72 | 73 | #ifdef __cplusplus 74 | #define CC_STATIC_ASSERT(exp) static_assert (exp, "") 75 | #else 76 | #define CC_STATIC_ASSERT(exp) _Static_assert(exp, "") 77 | #endif 78 | 79 | #define CC_UNUSED(var) (void)(var) 80 | 81 | static inline void cc_assert (int exp) 82 | { 83 | assert (exp); // LCOV_EXCL_LINE 84 | } 85 | 86 | #elif defined(_MSC_VER) 87 | 88 | #include 89 | 90 | #define CC_PACKED_BEGIN __pragma (pack (push, 1)) 91 | #define CC_PACKED_END __pragma (pack (pop)) 92 | #define CC_PACKED 93 | 94 | #define CC_FORMAT(str, arg) 95 | 96 | #define CC_TO_LE16(x) ((uint16_t)(x)) 97 | #define CC_TO_LE32(x) ((uint32_t)(x)) 98 | #define CC_TO_LE64(x) ((uint64_t)(x)) 99 | #define CC_FROM_LE16(x) ((uint16_t)(x)) 100 | #define CC_FROM_LE32(x) ((uint32_t)(x)) 101 | #define CC_FROM_LE64(x) ((uint64_t)(x)) 102 | #define CC_TO_BE16(x) ((uint16_t)_byteswap_ushort (x)) 103 | #define CC_TO_BE32(x) ((uint32_t)_byteswap_ulong (x)) 104 | #define CC_TO_BE64(x) ((uint64_t)_byteswap_uint64 (x)) 105 | #define CC_FROM_BE16(x) ((uint16_t)_byteswap_ushort (x)) 106 | #define CC_FROM_BE32(x) ((uint32_t)_byteswap_ulong (x)) 107 | #define CC_FROM_BE64(x) ((uint64_t)_byteswap_uint64 (x)) 108 | 109 | /* TODO */ 110 | #define CC_ATOMIC_GET8(p) (*p) 111 | #define CC_ATOMIC_GET16(p) (*p) 112 | #define CC_ATOMIC_GET32(p) (*p) 113 | #define CC_ATOMIC_GET64(p) (*p) 114 | 115 | /* TODO */ 116 | #define CC_ATOMIC_SET8(p, v) ((*p) = (v)) 117 | #define CC_ATOMIC_SET16(p, v) ((*p) = (v)) 118 | #define CC_ATOMIC_SET32(p, v) ((*p) = (v)) 119 | #define CC_ATOMIC_SET64(p, v) ((*p) = (v)) 120 | 121 | static uint8_t __inline cc_ctz (uint32_t x) 122 | { 123 | DWORD n = 0; 124 | _BitScanForward (&n, x); 125 | return (uint8_t)n; 126 | } 127 | 128 | #define __builtin_ctz(x) cc_ctz (x) 129 | 130 | #define CC_ASSERT(exp) assert (exp) 131 | #define CC_STATIC_ASSERT(exp) static_assert ((exp), "") 132 | 133 | #endif 134 | 135 | #ifdef __cplusplus 136 | } 137 | #endif 138 | 139 | #endif /* CC_H */ 140 | -------------------------------------------------------------------------------- /src/windows/sys/osal_sys.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #ifndef OSAL_SYS_H 17 | #define OSAL_SYS_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #define WIN32_LEAN_AND_MEAN /* Do not include */ 24 | #include 25 | 26 | /* Libraries excluded by WIN32_LEAN_AND_MEAN */ 27 | #include 28 | #include 29 | #include 30 | 31 | #define OS_WAIT_FOREVER INFINITE 32 | 33 | #define OS_THREAD 34 | #define OS_MUTEX 35 | #define OS_SEM 36 | #define OS_EVENT 37 | #define OS_MBOX 38 | #define OS_TIMER 39 | #define OS_TICK 40 | 41 | typedef HANDLE os_thread_t; 42 | typedef CRITICAL_SECTION os_mutex_t; 43 | 44 | typedef struct os_sem 45 | { 46 | CONDITION_VARIABLE condition; 47 | CRITICAL_SECTION lock; 48 | size_t count; 49 | } os_sem_t; 50 | 51 | typedef struct os_event 52 | { 53 | CONDITION_VARIABLE condition; 54 | CRITICAL_SECTION lock; 55 | uint32_t flags; 56 | } os_event_t; 57 | 58 | typedef struct os_mbox 59 | { 60 | CONDITION_VARIABLE condition; 61 | CRITICAL_SECTION lock; 62 | size_t r; 63 | size_t w; 64 | size_t count; 65 | size_t size; 66 | void * msg[]; 67 | } os_mbox_t; 68 | 69 | typedef struct os_timer 70 | { 71 | UINT timerID; 72 | void (*fn) (struct os_timer *, void * arg); 73 | void * arg; 74 | uint32_t us; 75 | bool oneshot; 76 | } os_timer_t; 77 | 78 | typedef uint64_t os_tick_t; 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* OSAL_SYS_H */ 85 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #******************************************************************** 2 | # _ _ _ 3 | # _ __ | |_ _ | | __ _ | |__ ___ 4 | # | '__|| __|(_)| | / _` || '_ \ / __| 5 | # | | | |_ _ | || (_| || |_) |\__ \ 6 | # |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | # 8 | # www.rt-labs.com 9 | # Copyright 2017 rt-labs AB, Sweden. 10 | # 11 | # This software is licensed under the terms of the BSD 3-clause 12 | # license. See the file LICENSE distributed with this software for 13 | # full license information. 14 | #*******************************************************************/ 15 | 16 | # Get osal properties 17 | get_target_property(OSAL_SOURCES osal SOURCES) 18 | get_target_property(OSAL_OPTIONS osal COMPILE_OPTIONS) 19 | get_target_property(OSAL_INCLUDES osal INCLUDE_DIRECTORIES) 20 | get_target_property(OSAL_LIBS osal LINK_LIBRARIES) 21 | 22 | if (OSAL_LIBS STREQUAL "OSAL_LIBS-NOTFOUND") 23 | set(OSAL_LIBS "") 24 | endif() 25 | 26 | # Make source paths absolute 27 | list(TRANSFORM OSAL_SOURCES PREPEND ${OSAL_SOURCE_DIR}/) 28 | 29 | set_target_properties (osal_test 30 | PROPERTIES 31 | C_STANDARD 99 32 | CXX_STANDARD 11 33 | ) 34 | 35 | target_sources(osal_test PRIVATE 36 | # Units to be tested 37 | ${OSAL_SOURCES} 38 | 39 | # Unit tests 40 | test_osal.cpp 41 | 42 | # Testrunner 43 | osal_test.cpp 44 | ) 45 | 46 | target_compile_options(osal_test 47 | PRIVATE 48 | -DUNIT_TEST 49 | ${OSAL_OPTIONS} 50 | ) 51 | 52 | target_include_directories(osal_test 53 | PRIVATE 54 | ${OSAL_SOURCE_DIR}/include 55 | ${OSAL_INCLUDES} 56 | ) 57 | 58 | target_link_libraries(osal_test 59 | PRIVATE 60 | ${OSAL_LIBS} 61 | ) 62 | 63 | # No need for gmock 64 | set(BUILD_GMOCK OFF CACHE BOOL "") 65 | -------------------------------------------------------------------------------- /test/osal_test.cpp: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #include 17 | #include "osal.h" 18 | 19 | OS_MAIN (int argc, char * argv[]) 20 | { 21 | ::testing::InitGoogleTest (&argc, argv); 22 | int result = RUN_ALL_TESTS(); 23 | return result; 24 | } 25 | -------------------------------------------------------------------------------- /test/test_osal.cpp: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #include "osal.h" 17 | #include 18 | 19 | static int expired_calls; 20 | static void * expired_arg; 21 | static void expired (os_timer_t * timer, void * arg) 22 | { 23 | expired_calls++; 24 | expired_arg = arg; 25 | } 26 | 27 | class Osal : public ::testing::Test 28 | { 29 | protected: 30 | virtual void SetUp() 31 | { 32 | expired_calls = 0; 33 | } 34 | }; 35 | 36 | TEST_F (Osal, SemShouldTimeoutWhenCountIsZero) 37 | { 38 | os_sem_t * sem = os_sem_create (2); 39 | bool tmo; 40 | 41 | // Count 2 42 | tmo = os_sem_wait (sem, 100); 43 | EXPECT_FALSE (tmo); 44 | 45 | // Count 1 46 | tmo = os_sem_wait (sem, 100); 47 | EXPECT_FALSE (tmo); 48 | 49 | // Count 0 - timeout 50 | tmo = os_sem_wait (sem, 100); 51 | EXPECT_TRUE (tmo); 52 | 53 | // Count 0 - timeout 54 | tmo = os_sem_wait (sem, 100); 55 | EXPECT_TRUE (tmo); 56 | 57 | // Increase count 58 | os_sem_signal (sem); 59 | 60 | // Count 1 61 | tmo = os_sem_wait (sem, 100); 62 | EXPECT_FALSE (tmo); 63 | 64 | // Count 0 - timeout 65 | tmo = os_sem_wait (sem, 100); 66 | EXPECT_TRUE (tmo); 67 | 68 | os_sem_destroy (sem); 69 | } 70 | 71 | TEST_F (Osal, EventShouldNotTimeout) 72 | { 73 | os_event_t * event = os_event_create(); 74 | uint32_t value = 99; 75 | bool tmo; 76 | 77 | os_event_set (event, 1); 78 | tmo = os_event_wait (event, 1, &value, OS_WAIT_FOREVER); 79 | EXPECT_FALSE (tmo); 80 | EXPECT_EQ (1u, value); 81 | 82 | os_event_destroy (event); 83 | } 84 | 85 | TEST_F (Osal, EventShouldTimeout) 86 | { 87 | os_event_t * event = os_event_create(); 88 | uint32_t value = 99; 89 | bool tmo; 90 | 91 | os_event_set (event, 2); 92 | tmo = os_event_wait (event, 1, &value, 100); 93 | EXPECT_TRUE (tmo); 94 | EXPECT_EQ (0u, value); 95 | 96 | os_event_destroy (event); 97 | } 98 | 99 | TEST_F (Osal, MboxShouldNotTimeout) 100 | { 101 | os_mbox_t * mbox = os_mbox_create (2); 102 | void * msg; 103 | bool tmo; 104 | 105 | os_mbox_post (mbox, (void *)1, OS_WAIT_FOREVER); 106 | tmo = os_mbox_fetch (mbox, &msg, OS_WAIT_FOREVER); 107 | 108 | EXPECT_FALSE (tmo); 109 | EXPECT_EQ (1, (intptr_t)msg); 110 | 111 | os_mbox_destroy (mbox); 112 | } 113 | 114 | TEST_F (Osal, FetchFromEmptyMboxShouldTimeout) 115 | { 116 | os_mbox_t * mbox = os_mbox_create (2); 117 | void * msg; 118 | bool tmo; 119 | 120 | tmo = os_mbox_fetch (mbox, &msg, 100); 121 | EXPECT_TRUE (tmo); 122 | 123 | os_mbox_destroy (mbox); 124 | } 125 | 126 | TEST_F (Osal, PostToFullMBoxShouldTimeout) 127 | { 128 | os_mbox_t * mbox = os_mbox_create (2); 129 | bool tmo; 130 | 131 | os_mbox_post (mbox, (void *)1, 100); 132 | os_mbox_post (mbox, (void *)2, 100); 133 | tmo = os_mbox_post (mbox, (void *)3, 100); 134 | EXPECT_TRUE (tmo); 135 | 136 | os_mbox_destroy (mbox); 137 | } 138 | 139 | #define TEN_MS (10 * 1000) 140 | #define CALLS 39 141 | 142 | TEST_F (Osal, CyclicTimer) 143 | { 144 | int t0, t1; 145 | os_timer_t * timer; 146 | 147 | timer = os_timer_create (TEN_MS, expired, (void *)0x42, false); 148 | os_timer_start (timer); 149 | 150 | t0 = os_get_current_time_us(); 151 | os_usleep (CALLS * TEN_MS); 152 | t1 = os_get_current_time_us(); 153 | os_timer_stop (timer); 154 | 155 | EXPECT_NEAR (CALLS * TEN_MS, t1 - t0, 1000); 156 | EXPECT_NEAR (CALLS, expired_calls, 2); 157 | 158 | EXPECT_EQ ((void *)0x42, expired_arg); 159 | 160 | // Check that timer is stopped 161 | expired_calls = 0; 162 | os_usleep (10 * TEN_MS); 163 | EXPECT_NEAR (0, expired_calls, 1); 164 | 165 | os_timer_destroy (timer); 166 | } 167 | 168 | TEST_F (Osal, OneshotTimer) 169 | { 170 | os_timer_t * timer; 171 | 172 | timer = os_timer_create (TEN_MS, expired, (void *)0x42, true); 173 | 174 | os_timer_start (timer); 175 | os_usleep (10 * TEN_MS); 176 | 177 | EXPECT_EQ (1, expired_calls); 178 | EXPECT_EQ ((void *)0x42, expired_arg); 179 | 180 | os_timer_destroy (timer); 181 | } 182 | 183 | TEST_F (Osal, MultipleTimers) 184 | { 185 | os_timer_t * timer1; 186 | os_timer_t * timer2; 187 | 188 | timer1 = os_timer_create (10 * 1000, expired, (void *)1, true); 189 | timer2 = os_timer_create (20 * 1000, expired, (void *)2, true); 190 | 191 | os_timer_start (timer1); 192 | os_timer_start (timer2); 193 | os_usleep (100 * 1000); 194 | 195 | EXPECT_EQ (2, expired_calls); 196 | EXPECT_EQ ((void *)2, expired_arg); 197 | 198 | os_timer_destroy (timer1); 199 | os_timer_destroy (timer2); 200 | } 201 | 202 | TEST_F (Osal, CurrentTime) 203 | { 204 | uint32_t t0, t1; 205 | 206 | t0 = os_get_current_time_us(); 207 | os_usleep (100 * 1000); 208 | t1 = os_get_current_time_us(); 209 | 210 | EXPECT_NEAR (100 * 1000, t1 - t0, 1000); 211 | } 212 | 213 | 214 | TEST_F (Osal, Tick) 215 | { 216 | os_tick_t t0, t1, sleep; 217 | 218 | sleep = os_tick_from_us (100 * 1000); 219 | t0 = os_tick_current(); 220 | os_tick_sleep (sleep); 221 | t1 = os_tick_current(); 222 | 223 | EXPECT_NEAR ((double)sleep, 224 | (double)(t1 - t0), 225 | (double)os_tick_from_us (1000)); 226 | } 227 | -------------------------------------------------------------------------------- /version.h.in: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * _ _ _ 3 | * _ __ | |_ _ | | __ _ | |__ ___ 4 | * | '__|| __|(_)| | / _` || '_ \ / __| 5 | * | | | |_ _ | || (_| || |_) |\__ \ 6 | * |_| \__|(_)|_| \__,_||_.__/ |___/ 7 | * 8 | * www.rt-labs.com 9 | * Copyright 2017 rt-labs AB, Sweden. 10 | * 11 | * This software is licensed under the terms of the BSD 3-clause 12 | * license. See the file LICENSE distributed with this software for 13 | * full license information. 14 | ********************************************************************/ 15 | 16 | #ifndef VERSION_H 17 | #define VERSION_H 18 | 19 | #cmakedefine OSAL_GIT_REVISION "@OSAL_GIT_REVISION@" 20 | 21 | #if !defined(OSAL_VERSION_BUILD) && defined(OSAL_VERSION_GIT) 22 | #define OSAL_VERSION_BUILD OSAL_VERSION_GIT 23 | #endif 24 | 25 | /* clang-format-off */ 26 | 27 | #define OSAL_VERSION_MAJOR @OSAL_VERSION_MAJOR@ 28 | #define OSAL_VERSION_MINOR @OSAL_VERSION_MINOR@ 29 | #define OSAL_VERSION_PATCH @OSAL_VERSION_PATCH@ 30 | 31 | #if defined(OSAL_VERSION_BUILD) 32 | #define OSAL_VERSION \ 33 | "@OSAL_VERSION_MAJOR@.@OSAL_VERSION_MINOR@.@OSAL_VERSION_PATCH@+"OSAL_VERSION_BUILD 34 | #else 35 | #define OSAL_VERSION \ 36 | "@OSAL_VERSION_MAJOR@.@OSAL_VERSION_MINOR@.@OSAL_VERSION_PATCH@" 37 | #endif 38 | 39 | /* clang-format-on */ 40 | 41 | #endif /* VERSION_H */ 42 | --------------------------------------------------------------------------------